base_from_mysteel_chemical.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. package models
  2. import (
  3. "eta/eta_index_lib/utils"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "github.com/beego/beego/v2/client/orm"
  9. )
  10. //钢联
  11. type MysteelChemicalData struct {
  12. InputValue float64 `orm:"column(value)" description:"值"`
  13. DataTime string `orm:"column(data_time)" description:"日期"`
  14. }
  15. func GetMysteelChemicalDataByCondition(condition string, pars []interface{}) (item []*MysteelChemicalData, err error) {
  16. sql1 := ` SELECT * FROM base_from_mysteel_chemical_data WHERE 1=1 `
  17. o := orm.NewOrm()
  18. if condition != "" {
  19. sql1 += condition
  20. }
  21. sql := `select * from (` + sql1 + ` having 1 order by modify_time DESC ) tmp GROUP BY data_time ORDER BY data_time DESC `
  22. _, err = o.Raw(sql, pars).QueryRows(&item)
  23. return
  24. }
  25. // AddEdbDataFromMysteelChemical 新增钢联指标数据
  26. func AddEdbDataFromMysteelChemical(edbCode string) (err error) {
  27. o := orm.NewOrm()
  28. var condition string
  29. var pars []interface{}
  30. if edbCode != "" {
  31. condition += " AND index_code = ? "
  32. pars = append(pars, edbCode)
  33. }
  34. mysteelChemicalDataList, err := GetMysteelChemicalDataByCondition(condition, pars)
  35. if err != nil {
  36. return
  37. }
  38. dataLen := len(mysteelChemicalDataList)
  39. existMap := make(map[string]string)
  40. if dataLen > 0 {
  41. var isAdd bool
  42. addSql := ` INSERT INTO edb_data_mysteel_chemical (edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
  43. for i := 0; i < dataLen; i++ {
  44. item := mysteelChemicalDataList[i]
  45. eDate := item.DataTime
  46. sValue := utils.SubFloatToString(item.InputValue, 30)
  47. if sValue != "" {
  48. if _, ok := existMap[eDate]; !ok {
  49. dataTime, err := time.ParseInLocation(utils.FormatDate, eDate, time.Local)
  50. if err != nil {
  51. return err
  52. }
  53. timestamp := dataTime.UnixNano() / 1e6
  54. timeStr := fmt.Sprintf("%d", timestamp)
  55. addSql += GetAddSql("0", edbCode, eDate, timeStr, sValue)
  56. isAdd = true
  57. }
  58. }
  59. existMap[eDate] = eDate
  60. }
  61. if isAdd {
  62. addSql = strings.TrimRight(addSql, ",")
  63. utils.FileLog.Info("addSql:" + addSql)
  64. _, err = o.Raw(addSql).Exec()
  65. if err != nil {
  66. return err
  67. }
  68. }
  69. }
  70. return
  71. }
  72. // RefreshEdbDataFromMysteelChemical 刷新钢联指标数据
  73. func RefreshEdbDataFromMysteelChemical(edbInfoId int, edbCode, startDate string) (err error) {
  74. source := utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  75. subSource := utils.DATA_SUB_SOURCE_EDB
  76. o := orm.NewOrm()
  77. if err != nil {
  78. return
  79. }
  80. edbInfoIdStr := strconv.Itoa(edbInfoId)
  81. //计算数据
  82. var condition string
  83. var pars []interface{}
  84. if edbCode != "" {
  85. condition += " AND index_code=? "
  86. pars = append(pars, edbCode)
  87. }
  88. if startDate != "" {
  89. condition += " AND data_time>=? "
  90. pars = append(pars, startDate)
  91. }
  92. mysteelChemicalDataList, err := GetMysteelChemicalDataByCondition(condition, pars)
  93. if err != nil {
  94. return
  95. }
  96. // 真实数据的最大日期 , 插入规则配置的日期
  97. var realDataMaxDate, edbDataInsertConfigDate time.Time
  98. var edbDataInsertConfig *EdbDataInsertConfig
  99. var isFindConfigDateRealData bool //是否找到配置日期的实际数据的值
  100. {
  101. edbDataInsertConfig, err = GetEdbDataInsertConfigByEdbId(edbInfoId)
  102. if err != nil && err.Error() != utils.ErrNoRow() {
  103. return
  104. }
  105. if edbDataInsertConfig != nil {
  106. edbDataInsertConfigDate = edbDataInsertConfig.Date
  107. }
  108. }
  109. var existCondition string
  110. var existPars []interface{}
  111. existCondition += " AND edb_info_id=? "
  112. existPars = append(existPars, edbInfoId)
  113. if startDate != "" {
  114. existCondition += " AND data_time>=? "
  115. existPars = append(existPars, startDate)
  116. }
  117. //获取指标所有数据
  118. existList, err := GetEdbDataByCondition(source, subSource, existCondition, existPars)
  119. if err != nil {
  120. return err
  121. }
  122. existMap := make(map[string]*EdbInfoSearchData)
  123. for _, v := range existList {
  124. existMap[v.DataTime] = v
  125. }
  126. addSql := ` INSERT INTO edb_data_mysteel_chemical(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
  127. var isAdd bool
  128. addMap := make(map[string]string)
  129. for _, v := range mysteelChemicalDataList {
  130. item := v
  131. eDate := item.DataTime
  132. sValue := utils.SubFloatToString(item.InputValue, 30)
  133. dataTime, err := time.ParseInLocation(utils.FormatDate, eDate, time.Local)
  134. if err != nil {
  135. return err
  136. }
  137. if findItem, ok := existMap[v.DataTime]; !ok {
  138. if sValue != "" {
  139. timestamp := dataTime.UnixNano() / 1e6
  140. timeStr := fmt.Sprintf("%d", timestamp)
  141. saveValue := sValue
  142. if _, addOk := addMap[eDate]; !addOk {
  143. addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
  144. isAdd = true
  145. }
  146. }
  147. } else {
  148. if findItem != nil && utils.SubFloatToString(findItem.Value, 30) != sValue {
  149. err = ModifyEdbDataById(source, subSource, findItem.EdbDataId, sValue)
  150. if err != nil {
  151. return err
  152. }
  153. }
  154. }
  155. addMap[v.DataTime] = v.DataTime
  156. // 下面代码主要目的是处理掉手动插入的数据判断
  157. {
  158. if realDataMaxDate.IsZero() || dataTime.After(realDataMaxDate) {
  159. realDataMaxDate = dataTime
  160. }
  161. if edbDataInsertConfigDate.IsZero() || dataTime.Equal(edbDataInsertConfigDate) {
  162. isFindConfigDateRealData = true
  163. }
  164. }
  165. }
  166. // 处理手工数据补充的配置
  167. HandleConfigInsertEdbData(realDataMaxDate, edbDataInsertConfig, edbInfoId, source, subSource, existMap, isFindConfigDateRealData)
  168. if isAdd {
  169. addSql = strings.TrimRight(addSql, ",")
  170. _, err = o.Raw(addSql).Exec()
  171. if err != nil {
  172. return err
  173. }
  174. }
  175. return
  176. }
  177. // 钢联化工指标数据
  178. type BaseFromMysteelChemicalIndex struct {
  179. BaseFromMysteelChemicalIndexId int64 `orm:"column(base_from_mysteel_chemical_index_id);pk"`
  180. BaseFromMysteelChemicalClassifyId int `description:"分类id"`
  181. IndexCode string `description:"指标编码"`
  182. IndexName string `description:"指标名称"`
  183. Unit string `description:"单位"`
  184. Source string `description:"数据来源"`
  185. Frequency string `description:"频度"`
  186. StartDate time.Time `description:"开始日期"`
  187. EndDate time.Time `description:"结束日期"`
  188. Describe string `description:"指标描述"`
  189. UpdateWeek string `description:"更新周期"`
  190. UpdateTime string `description:"更新时间,多个时间点用英文,隔开"`
  191. UpdateTime2 string `description:"更新时间2"`
  192. SysUserId int `description:"创建人id"`
  193. SysUserRealName string `description:"创建人姓名"`
  194. FilePath string `description:"文件存储路径"`
  195. MergeFilePath string `description:"更新文件"`
  196. FileIndex int `description:"文件索引"`
  197. MergeUpdateWeek string `description:"合并文件的更新周"`
  198. UpdateDate string `description:"更新日期"`
  199. CreateTime time.Time `description:"创建时间"`
  200. ModifyTime time.Time `description:"修改时间"`
  201. IsStop int `description:"是否停更:1:停更,0:未停更"`
  202. TerminalCode string `description:"终端编码"`
  203. }
  204. type MysteelChemicalAPiCheck struct {
  205. IsEnable bool
  206. ErrMsg string
  207. }
  208. // GetIndexRefreshAllByMergeFile 根据合并文件去分组查询需要刷新的文件
  209. func (m *BaseFromMysteelChemicalIndex) GetIndexRefreshAllByMergeFile() (items []*BaseFromMysteelChemicalIndex, err error) {
  210. o := orm.NewOrm()
  211. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE merge_file_path <>'' AND base_from_mysteel_chemical_classify_id NOT IN(54,55,56,57) GROUP BY merge_file_path`
  212. _, err = o.Raw(sql).QueryRows(&items)
  213. return
  214. }
  215. func (m *BaseFromMysteelChemicalIndex) GetIndexItem(indexCode string) (item *BaseFromMysteelChemicalIndex, err error) {
  216. o := orm.NewOrm()
  217. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE index_code = ? `
  218. err = o.Raw(sql, indexCode).QueryRow(&item)
  219. return
  220. }
  221. func (m *BaseFromMysteelChemicalIndex) GetBatchIndexItem(indexCodes []string) (items []*BaseFromMysteelChemicalIndex, err error) {
  222. if len(indexCodes) <= 0 {
  223. return
  224. }
  225. o := orm.NewOrm()
  226. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE index_code IN (%s) `
  227. holder := make([]string, 0, len(indexCodes))
  228. for range indexCodes {
  229. holder = append(holder, "?")
  230. }
  231. sql = fmt.Sprintf(sql, strings.Join(holder, ","))
  232. _, err = o.Raw(sql, indexCodes).QueryRows(&items)
  233. return
  234. }
  235. func (m *BaseFromMysteelChemicalIndex) GetIndexCreate(terminalCode string) (items []*BaseFromMysteelChemicalIndex, err error) {
  236. o := orm.NewOrm()
  237. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE index_name = '' AND terminal_code = ? `
  238. _, err = o.Raw(sql, terminalCode).QueryRows(&items)
  239. return
  240. }
  241. // Add 新增
  242. func (m *BaseFromMysteelChemicalIndex) Add() (err error) {
  243. o := orm.NewOrm()
  244. _, err = o.Insert(m)
  245. return
  246. }
  247. func (m *BaseFromMysteelChemicalIndex) Update(cols []string) (err error) {
  248. o := orm.NewOrm()
  249. _, err = o.Update(m, cols...)
  250. return
  251. }
  252. // GetNoMergeIndexByFrequencyCount 获取未合并的指标总数量
  253. func (m *BaseFromMysteelChemicalIndex) GetNoMergeIndexByFrequencyCount(frequency string) (total int64, err error) {
  254. o := orm.NewOrm()
  255. sql := `SELECT count(1) AS total FROM base_from_mysteel_chemical_index WHERE frequency = ? AND merge_file_path = '' AND index_name NOT LIKE "%停%" `
  256. err = o.Raw(sql, frequency).QueryRow(&total)
  257. return
  258. }
  259. // GetMaxFileIndexReq 获取最大文件数请求
  260. type GetMaxFileIndexReq struct {
  261. Frequency string
  262. EndDate string
  263. TerminalCode string `description:"终端编码"`
  264. }
  265. // GetMaxFileIndex 获取最大文件的
  266. func (m *BaseFromMysteelChemicalIndex) GetMaxFileIndex(frequency string) (item *BaseFromMysteelChemicalIndex, err error) {
  267. o := orm.NewOrm()
  268. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE frequency=? AND index_name NOT LIKE "%停%" ORDER BY file_index DESC `
  269. err = o.Raw(sql, frequency).QueryRow(&item)
  270. return
  271. }
  272. // GetNoMergeIndexByFrequencyPageReq 获取未合并的指标列表
  273. type GetNoMergeIndexByFrequencyPageReq struct {
  274. Frequency string
  275. Limit int
  276. }
  277. // GetNoMergeIndexByFrequencyPage 获取未合并的指标列表
  278. func (m *BaseFromMysteelChemicalIndex) GetNoMergeIndexByFrequencyPage(frequency string, limit int) (items []*BaseFromMysteelChemicalIndex, err error) {
  279. o := orm.NewOrm()
  280. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE frequency=? AND merge_file_path = '' limit ? `
  281. _, err = o.Raw(sql, frequency, limit).QueryRows(&items)
  282. return
  283. }
  284. type GetIndexCountByMergeFilePathReq struct {
  285. MergeFilePath string
  286. }
  287. func (m *BaseFromMysteelChemicalIndex) GetIndexCountByMergeFilePath(mergeFilePath string) (total int64, err error) {
  288. o := orm.NewOrm()
  289. sql := `SELECT count(1) AS total FROM base_from_mysteel_chemical_index WHERE merge_file_path = ?`
  290. err = o.Raw(sql, mergeFilePath).QueryRow(&total)
  291. return
  292. }
  293. // GetIndexRefreshMethanolByMergeFile 根据合并文件去分组查询需要刷新的甲醇文件
  294. func (m *BaseFromMysteelChemicalIndex) GetIndexRefreshMethanolByMergeFile() (items []*BaseFromMysteelChemicalIndex, err error) {
  295. o := orm.NewOrm()
  296. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE merge_file_path <> '' AND base_from_mysteel_chemical_classify_id IN(54,55,56,57) GROUP BY merge_file_path`
  297. _, err = o.Raw(sql).QueryRows(&items)
  298. return
  299. }
  300. // GetIndexRefreshMethanolByTimely 获取需要及时刷新的文件
  301. func (m *BaseFromMysteelChemicalIndex) GetIndexRefreshMethanolByTimely() (items []*BaseFromMysteelChemicalIndex, err error) {
  302. o := orm.NewOrm()
  303. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE merge_file_path <> '' AND is_refresh = 1 GROUP BY merge_file_path`
  304. _, err = o.Raw(sql).QueryRows(&items)
  305. return
  306. }
  307. type GetIndexByFrequencyReq struct {
  308. Frequency string
  309. }
  310. // GetIndexByFrequency 根据频率获取指标
  311. func (m *BaseFromMysteelChemicalIndex) GetIndexByFrequency(frequency string) (items []*BaseFromMysteelChemicalIndex, err error) {
  312. o := orm.NewOrm()
  313. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE frequency = ? AND merge_file_path = '' `
  314. _, err = o.Raw(sql, frequency).QueryRows(&items)
  315. return
  316. }
  317. type GetIndexRefreshWeekReq struct {
  318. NowWeekZn string
  319. StartTime string
  320. EndTime string
  321. }
  322. func (m *BaseFromMysteelChemicalIndex) GetIndexRefreshWeek(nowWeekZn, startTime, endTime string) (items []*BaseFromMysteelChemicalIndex, err error) {
  323. where := `update_week = ? AND ((update_time >= ? AND update_time <= ?) OR (update_time2 >= ? AND update_time2 <= ?)) `
  324. o := orm.NewOrm()
  325. sql := fmt.Sprintf(`SELECT * FROM base_from_mysteel_chemical_index WHERE %s `, where)
  326. _, err = o.Raw(sql, nowWeekZn, startTime, endTime, startTime, endTime).QueryRows(&items)
  327. return
  328. }
  329. // UpdateIndexReq 根据编码更新指标请求体
  330. type UpdateIndexReq struct {
  331. Item *BaseFromMysteelChemicalIndex
  332. UpdateCols []string
  333. }
  334. func (m *BaseFromMysteelChemicalIndex) UpdateIndex(item *BaseFromMysteelChemicalIndex, updateCols []string) (err error) {
  335. if item == nil {
  336. return
  337. }
  338. if len(updateCols) == 0 {
  339. return
  340. }
  341. o := orm.NewOrm()
  342. _, err = o.Update(item, updateCols...)
  343. return
  344. }
  345. // MultiUpdateIndex 批量更新指标
  346. func (m *BaseFromMysteelChemicalIndex) MultiUpdateIndex(items []UpdateIndexReq) (err error) {
  347. if len(items) == 0 {
  348. return
  349. }
  350. o := orm.NewOrm()
  351. for _, v := range items {
  352. if len(v.UpdateCols) == 0 {
  353. continue
  354. }
  355. if v.Item == nil {
  356. continue
  357. }
  358. if _, e := o.Update(v.Item, v.UpdateCols...); e != nil {
  359. err = fmt.Errorf("update err: %s", e.Error())
  360. return
  361. }
  362. }
  363. return
  364. }
  365. type HandleMysteelIndex struct {
  366. IndexName string `description:"指标名称"`
  367. IndexCode string `description:"指标编码"`
  368. Unit string `description:"单位"`
  369. Source string `description:"数据来源"`
  370. Frequency string `description:"频度"`
  371. StartDate string `description:"开始日期"`
  372. EndDate string `description:"结束日期"`
  373. Describe string `description:"指标描述"`
  374. UpdateDate string `description:"更新日期"`
  375. ExcelDataMap map[string]string
  376. }
  377. type HandleMysteelIndexResp struct {
  378. List []*HandleMysteelIndex
  379. }
  380. // 钢联化工指标数据
  381. type BaseFromMysteelChemicalData struct {
  382. BaseFromMysteelChemicalDataId int64 `orm:"column(base_from_mysteel_chemical_data_id);pk"`
  383. BaseFromMysteelChemicalIndexId int64
  384. IndexCode string
  385. DataTime time.Time
  386. Value string
  387. UpdateDate string
  388. CreateTime time.Time `description:"创建时间"`
  389. ModifyTime time.Time `description:"修改时间"`
  390. }
  391. // GetIndexDataList 根据指标编码获取数据
  392. func (d *BaseFromMysteelChemicalData) GetIndexDataList(indexCode string) (item []*BaseFromMysteelChemicalData, err error) {
  393. o := orm.NewOrm()
  394. sql := `SELECT * FROM base_from_mysteel_chemical_data WHERE index_code = ? `
  395. _, err = o.Raw(sql, indexCode).QueryRows(&item)
  396. return
  397. }
  398. // Update 修改
  399. func (r *BaseFromMysteelChemicalData) Update(updateCols []string) (err error) {
  400. o := orm.NewOrm()
  401. _, err = o.Update(r, updateCols...)
  402. return
  403. }
  404. // Add 新增
  405. func (r *BaseFromMysteelChemicalData) Add(list []BaseFromMysteelChemicalData) (err error) {
  406. o := orm.NewOrm()
  407. _, err = o.InsertMulti(500, list)
  408. return
  409. }
  410. // AddV2 新增
  411. func (r *BaseFromMysteelChemicalData) AddV2(list []*BaseFromMysteelChemicalData) (err error) {
  412. if len(list) == 0 {
  413. return
  414. }
  415. o := orm.NewOrm()
  416. _, err = o.InsertMulti(500, list)
  417. return
  418. }
  419. type AddMysteelIndexResp struct {
  420. EdbCode string `description:"指标编码"`
  421. TerminalCode string `description:"指标终端编码"`
  422. BaseFromMysteelChemicalClassifyId int `description:"指标分类"`
  423. SysUserId int `description:"操作人id"`
  424. SysUserRealName string `description:"操作人真实名称"`
  425. }
  426. type GetIndexDetailReq struct {
  427. IndexCode string `description:"指标编码"`
  428. }
  429. // GetIndexCountByFrequency 获取未合并的指标总数量
  430. func (m *BaseFromMysteelChemicalIndex) GetIndexCountByFrequency(condition string, pars []interface{}) (total int64, err error) {
  431. o := orm.NewOrm()
  432. sql := `SELECT count(1) AS total FROM base_from_mysteel_chemical_index WHERE 1=1 `
  433. if condition != "" {
  434. sql += condition
  435. }
  436. err = o.Raw(sql, pars).QueryRow(&total)
  437. return
  438. }
  439. // GetNoMergeIndexByFrequencyPage 获取未合并的指标列表
  440. func (m *BaseFromMysteelChemicalIndex) GetIndexLimitByFrequency(frequency string, limit int) (items []*BaseFromMysteelChemicalIndex, err error) {
  441. o := orm.NewOrm()
  442. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE frequency=? limit ? `
  443. _, err = o.Raw(sql, frequency, limit).QueryRows(&items)
  444. return
  445. }
  446. type GetIndexPageByFrequencyPageReq struct {
  447. Frequency string
  448. EndDate string
  449. StartSize int
  450. PageSize int
  451. TerminalCode string `description:"终端编码"`
  452. }
  453. // GetNoMergeIndexByFrequencyPage 获取未合并的指标列表
  454. func (m *BaseFromMysteelChemicalIndex) GetIndexPageByFrequency(condition string, pars []interface{}, startSize, pageSize int) (items []*BaseFromMysteelChemicalIndex, err error) {
  455. o := orm.NewOrm()
  456. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE 1=1 `
  457. if condition != "" {
  458. sql += condition
  459. }
  460. sql += ` LIMIT ?,? `
  461. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  462. return
  463. }
  464. func (d *BaseFromMysteelChemicalData) GetMysteelIndexInfoMaxAndMinInfo(indexCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  465. o := orm.NewOrm()
  466. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM base_from_mysteel_chemical_data WHERE index_code=? `
  467. err = o.Raw(sql, indexCode).QueryRow(&item)
  468. if err != nil {
  469. return
  470. }
  471. // 获取最新值
  472. var latest_value float64
  473. sql = ` SELECT value AS latest_value FROM base_from_mysteel_chemical_data WHERE index_code=? ORDER BY data_time DESC LIMIT 1 `
  474. err = o.Raw(sql, indexCode).QueryRow(&latest_value)
  475. if err != nil {
  476. return
  477. }
  478. item.LatestValue = latest_value
  479. return
  480. }
  481. func (d *BaseFromMysteelChemicalData) ModifyMysteelIndexMaxAndMinInfo(indexCode string, item *EdbInfoMaxAndMinInfo) (err error) {
  482. o := orm.NewOrm()
  483. sql := ` UPDATE base_from_mysteel_chemical_index SET start_date=?,end_date=?,end_value=?,modify_time=NOW() WHERE index_code=? `
  484. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.LatestValue, indexCode).Exec()
  485. return
  486. }
  487. // GetIndexByCondition 获取指标
  488. func (m *BaseFromMysteelChemicalIndex) GetIndexByCondition(condition string, pars []interface{}) (items []*BaseFromMysteelChemicalIndex, err error) {
  489. o := orm.NewOrm()
  490. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE 1=1 `
  491. if condition != "" {
  492. sql += condition
  493. }
  494. _, err = o.Raw(sql, pars).QueryRows(&items)
  495. return
  496. }
  497. type BaseFromMysteelChemicalRecord struct {
  498. BaseFromMysteelChemicalRecordId int64 `orm:"column(base_from_mysteel_chemical_record_id);pk"`
  499. BaseFromMysteelChemicalIndexId int64
  500. OldIndexName string `description:"原始名称"`
  501. NewIndexName string `description:"新的名称"`
  502. CreateTime time.Time `description:"记录创建时间"`
  503. Timestamp int64 `description:"记录创建时间戳"`
  504. }
  505. func (m *BaseFromMysteelChemicalRecord) AddBaseFromMysteelChemicalRecord() (err error) {
  506. o := orm.NewOrm()
  507. _, err = o.Insert(m)
  508. return
  509. }
  510. type MySteelChemicalApiResp struct {
  511. Code string `json:"code" description:"200成功,其他失败"`
  512. Success bool `json:"success" description:"true 成功,false 失败"`
  513. Timestamp int64 `json:"timestamp" description:"时间戳"`
  514. Message string `json:"message" description:"显示执行信息"`
  515. Data []*MySteelChemicalApiData `json:"data" description:"数据"`
  516. }
  517. type MySteelChemicalApiInfoResp struct {
  518. Code string `json:"code" description:"200成功,其他失败"`
  519. Success bool `json:"success" description:"true 成功,false 失败"`
  520. Timestamp int64 `json:"timestamp" description:"时间戳"`
  521. Message string `json:"message" description:"显示执行信息"`
  522. Data *MySteelChemicalApiInfo `json:"data" description:"数据"`
  523. }
  524. type MySteelChemicalApiInfo struct {
  525. Total int `json:"total" description:"总条数"`
  526. Pages int `json:"pages" description:"总页数"`
  527. List []*MySteelChemicalApiInfoItem `json:"list" description:"数据列表"`
  528. }
  529. type MySteelChemicalApiInfoItem struct {
  530. IndexCode string `json:"INDEX_CODE"`
  531. IndexName string `json:"INDEX_NAME"`
  532. FrequencyName string `json:"FREQUENCY_NAME"`
  533. UnitName string `json:"UNIT_NAME"`
  534. }
  535. type MySteelChemicalApiData struct {
  536. IndexCode string `json:"INDEX_CODE"`
  537. DataList []*MySteelChemicalApiDataList `json:"dataList"`
  538. }
  539. type MySteelChemicalApiDataList struct {
  540. PublishTime int64 `json:"PUBLISH_TIME"`
  541. IndexCode string `json:"INDEX_CODE"`
  542. DataDate string `json:"DATA_DATE"`
  543. DataValue float64 `json:"DATA_VALUE"`
  544. }