base_from_mysteel_chemical.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. IsSupplierStop int `description:"是否供应商停更:1:停更,0:未停更"`
  204. }
  205. type MysteelChemicalAPiCheck struct {
  206. IsEnable bool
  207. ErrMsg string
  208. }
  209. // GetIndexRefreshAllByMergeFile 根据合并文件去分组查询需要刷新的文件
  210. func (m *BaseFromMysteelChemicalIndex) GetIndexRefreshAllByMergeFile() (items []*BaseFromMysteelChemicalIndex, err error) {
  211. o := orm.NewOrm()
  212. 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`
  213. _, err = o.Raw(sql).QueryRows(&items)
  214. return
  215. }
  216. func (m *BaseFromMysteelChemicalIndex) GetIndexItem(indexCode string) (item *BaseFromMysteelChemicalIndex, err error) {
  217. o := orm.NewOrm()
  218. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE index_code = ? `
  219. err = o.Raw(sql, indexCode).QueryRow(&item)
  220. return
  221. }
  222. func (m *BaseFromMysteelChemicalIndex) GetBatchIndexItem(indexCodes []string) (items []*BaseFromMysteelChemicalIndex, err error) {
  223. if len(indexCodes) <= 0 {
  224. return
  225. }
  226. o := orm.NewOrm()
  227. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE index_code IN (%s) `
  228. holder := make([]string, 0, len(indexCodes))
  229. for range indexCodes {
  230. holder = append(holder, "?")
  231. }
  232. sql = fmt.Sprintf(sql, strings.Join(holder, ","))
  233. _, err = o.Raw(sql, indexCodes).QueryRows(&items)
  234. return
  235. }
  236. func (m *BaseFromMysteelChemicalIndex) GetIndexCreate(terminalCode string) (items []*BaseFromMysteelChemicalIndex, err error) {
  237. o := orm.NewOrm()
  238. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE index_name = '' AND terminal_code = ? `
  239. _, err = o.Raw(sql, terminalCode).QueryRows(&items)
  240. return
  241. }
  242. // Add 新增
  243. func (m *BaseFromMysteelChemicalIndex) Add() (err error) {
  244. o := orm.NewOrm()
  245. _, err = o.Insert(m)
  246. return
  247. }
  248. func (m *BaseFromMysteelChemicalIndex) Update(cols []string) (err error) {
  249. o := orm.NewOrm()
  250. _, err = o.Update(m, cols...)
  251. return
  252. }
  253. // GetNoMergeIndexByFrequencyCount 获取未合并的指标总数量
  254. func (m *BaseFromMysteelChemicalIndex) GetNoMergeIndexByFrequencyCount(frequency string) (total int64, err error) {
  255. o := orm.NewOrm()
  256. sql := `SELECT count(1) AS total FROM base_from_mysteel_chemical_index WHERE frequency = ? AND merge_file_path = '' AND index_name NOT LIKE "%停%" `
  257. err = o.Raw(sql, frequency).QueryRow(&total)
  258. return
  259. }
  260. // GetMaxFileIndexReq 获取最大文件数请求
  261. type GetMaxFileIndexReq struct {
  262. Frequency string
  263. EndDate string
  264. TerminalCode string `description:"终端编码"`
  265. }
  266. // GetMaxFileIndex 获取最大文件的
  267. func (m *BaseFromMysteelChemicalIndex) GetMaxFileIndex(frequency string) (item *BaseFromMysteelChemicalIndex, err error) {
  268. o := orm.NewOrm()
  269. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE frequency=? AND index_name NOT LIKE "%停%" ORDER BY file_index DESC `
  270. err = o.Raw(sql, frequency).QueryRow(&item)
  271. return
  272. }
  273. // GetNoMergeIndexByFrequencyPageReq 获取未合并的指标列表
  274. type GetNoMergeIndexByFrequencyPageReq struct {
  275. Frequency string
  276. Limit int
  277. }
  278. // GetNoMergeIndexByFrequencyPage 获取未合并的指标列表
  279. func (m *BaseFromMysteelChemicalIndex) GetNoMergeIndexByFrequencyPage(frequency string, limit int) (items []*BaseFromMysteelChemicalIndex, err error) {
  280. o := orm.NewOrm()
  281. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE frequency=? AND merge_file_path = '' limit ? `
  282. _, err = o.Raw(sql, frequency, limit).QueryRows(&items)
  283. return
  284. }
  285. type GetIndexCountByMergeFilePathReq struct {
  286. MergeFilePath string
  287. }
  288. func (m *BaseFromMysteelChemicalIndex) GetIndexCountByMergeFilePath(mergeFilePath string) (total int64, err error) {
  289. o := orm.NewOrm()
  290. sql := `SELECT count(1) AS total FROM base_from_mysteel_chemical_index WHERE merge_file_path = ?`
  291. err = o.Raw(sql, mergeFilePath).QueryRow(&total)
  292. return
  293. }
  294. // GetIndexRefreshMethanolByMergeFile 根据合并文件去分组查询需要刷新的甲醇文件
  295. func (m *BaseFromMysteelChemicalIndex) GetIndexRefreshMethanolByMergeFile() (items []*BaseFromMysteelChemicalIndex, err error) {
  296. o := orm.NewOrm()
  297. 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`
  298. _, err = o.Raw(sql).QueryRows(&items)
  299. return
  300. }
  301. // GetIndexRefreshMethanolByTimely 获取需要及时刷新的文件
  302. func (m *BaseFromMysteelChemicalIndex) GetIndexRefreshMethanolByTimely() (items []*BaseFromMysteelChemicalIndex, err error) {
  303. o := orm.NewOrm()
  304. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE merge_file_path <> '' AND is_refresh = 1 GROUP BY merge_file_path`
  305. _, err = o.Raw(sql).QueryRows(&items)
  306. return
  307. }
  308. type GetIndexByFrequencyReq struct {
  309. Frequency string
  310. }
  311. // GetIndexByFrequency 根据频率获取指标
  312. func (m *BaseFromMysteelChemicalIndex) GetIndexByFrequency(frequency string) (items []*BaseFromMysteelChemicalIndex, err error) {
  313. o := orm.NewOrm()
  314. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE frequency = ? AND merge_file_path = '' `
  315. _, err = o.Raw(sql, frequency).QueryRows(&items)
  316. return
  317. }
  318. type GetIndexRefreshWeekReq struct {
  319. NowWeekZn string
  320. StartTime string
  321. EndTime string
  322. }
  323. func (m *BaseFromMysteelChemicalIndex) GetIndexRefreshWeek(nowWeekZn, startTime, endTime string) (items []*BaseFromMysteelChemicalIndex, err error) {
  324. where := `update_week = ? AND ((update_time >= ? AND update_time <= ?) OR (update_time2 >= ? AND update_time2 <= ?)) `
  325. o := orm.NewOrm()
  326. sql := fmt.Sprintf(`SELECT * FROM base_from_mysteel_chemical_index WHERE %s `, where)
  327. _, err = o.Raw(sql, nowWeekZn, startTime, endTime, startTime, endTime).QueryRows(&items)
  328. return
  329. }
  330. // UpdateIndexReq 根据编码更新指标请求体
  331. type UpdateIndexReq struct {
  332. Item *BaseFromMysteelChemicalIndex
  333. UpdateCols []string
  334. }
  335. func (m *BaseFromMysteelChemicalIndex) UpdateIndex(item *BaseFromMysteelChemicalIndex, updateCols []string) (err error) {
  336. if item == nil {
  337. return
  338. }
  339. if len(updateCols) == 0 {
  340. return
  341. }
  342. o := orm.NewOrm()
  343. _, err = o.Update(item, updateCols...)
  344. return
  345. }
  346. // MultiUpdateIndex 批量更新指标
  347. func (m *BaseFromMysteelChemicalIndex) MultiUpdateIndex(items []UpdateIndexReq) (err error) {
  348. if len(items) == 0 {
  349. return
  350. }
  351. o := orm.NewOrm()
  352. for _, v := range items {
  353. if len(v.UpdateCols) == 0 {
  354. continue
  355. }
  356. if v.Item == nil {
  357. continue
  358. }
  359. if _, e := o.Update(v.Item, v.UpdateCols...); e != nil {
  360. err = fmt.Errorf("update err: %s", e.Error())
  361. return
  362. }
  363. }
  364. return
  365. }
  366. type HandleMysteelIndex struct {
  367. IndexName string `description:"指标名称"`
  368. IndexCode string `description:"指标编码"`
  369. Unit string `description:"单位"`
  370. Source string `description:"数据来源"`
  371. Frequency string `description:"频度"`
  372. StartDate string `description:"开始日期"`
  373. EndDate string `description:"结束日期"`
  374. Describe string `description:"指标描述"`
  375. UpdateDate string `description:"更新日期"`
  376. ExcelDataMap map[string]string
  377. }
  378. type HandleMysteelIndexResp struct {
  379. List []*HandleMysteelIndex
  380. }
  381. // 钢联化工指标数据
  382. type BaseFromMysteelChemicalData struct {
  383. BaseFromMysteelChemicalDataId int64 `orm:"column(base_from_mysteel_chemical_data_id);pk"`
  384. BaseFromMysteelChemicalIndexId int64
  385. IndexCode string
  386. DataTime time.Time
  387. Value string
  388. UpdateDate string
  389. CreateTime time.Time `description:"创建时间"`
  390. ModifyTime time.Time `description:"修改时间"`
  391. }
  392. // GetIndexDataList 根据指标编码获取数据
  393. func (d *BaseFromMysteelChemicalData) GetIndexDataList(indexCode string) (item []*BaseFromMysteelChemicalData, err error) {
  394. o := orm.NewOrm()
  395. sql := `SELECT * FROM base_from_mysteel_chemical_data WHERE index_code = ? `
  396. _, err = o.Raw(sql, indexCode).QueryRows(&item)
  397. return
  398. }
  399. // Update 修改
  400. func (r *BaseFromMysteelChemicalData) Update(updateCols []string) (err error) {
  401. o := orm.NewOrm()
  402. _, err = o.Update(r, updateCols...)
  403. return
  404. }
  405. // Add 新增
  406. func (r *BaseFromMysteelChemicalData) Add(list []BaseFromMysteelChemicalData) (err error) {
  407. o := orm.NewOrm()
  408. _, err = o.InsertMulti(500, list)
  409. return
  410. }
  411. // AddV2 新增
  412. func (r *BaseFromMysteelChemicalData) AddV2(list []*BaseFromMysteelChemicalData) (err error) {
  413. if len(list) == 0 {
  414. return
  415. }
  416. o := orm.NewOrm()
  417. _, err = o.InsertMulti(500, list)
  418. return
  419. }
  420. type AddMysteelIndexResp struct {
  421. EdbCode string `description:"指标编码"`
  422. TerminalCode string `description:"指标终端编码"`
  423. BaseFromMysteelChemicalClassifyId int `description:"指标分类"`
  424. SysUserId int `description:"操作人id"`
  425. SysUserRealName string `description:"操作人真实名称"`
  426. }
  427. type GetIndexDetailReq struct {
  428. IndexCode string `description:"指标编码"`
  429. }
  430. // GetIndexCountByFrequency 获取未合并的指标总数量
  431. func (m *BaseFromMysteelChemicalIndex) GetIndexCountByFrequency(condition string, pars []interface{}) (total int64, err error) {
  432. o := orm.NewOrm()
  433. sql := `SELECT count(1) AS total FROM base_from_mysteel_chemical_index WHERE 1=1 `
  434. if condition != "" {
  435. sql += condition
  436. }
  437. err = o.Raw(sql, pars).QueryRow(&total)
  438. return
  439. }
  440. // GetNoMergeIndexByFrequencyPage 获取未合并的指标列表
  441. func (m *BaseFromMysteelChemicalIndex) GetIndexLimitByFrequency(frequency string, limit int) (items []*BaseFromMysteelChemicalIndex, err error) {
  442. o := orm.NewOrm()
  443. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE frequency=? limit ? `
  444. _, err = o.Raw(sql, frequency, limit).QueryRows(&items)
  445. return
  446. }
  447. type GetIndexPageByFrequencyPageReq struct {
  448. Frequency string
  449. EndDate string
  450. StartSize int
  451. PageSize int
  452. TerminalCode string `description:"终端编码"`
  453. }
  454. // GetNoMergeIndexByFrequencyPage 获取未合并的指标列表
  455. func (m *BaseFromMysteelChemicalIndex) GetIndexPageByFrequency(condition string, pars []interface{}, startSize, pageSize int) (items []*BaseFromMysteelChemicalIndex, err error) {
  456. o := orm.NewOrm()
  457. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE 1=1 `
  458. if condition != "" {
  459. sql += condition
  460. }
  461. sql += ` LIMIT ?,? `
  462. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  463. return
  464. }
  465. func (d *BaseFromMysteelChemicalData) GetMysteelIndexInfoMaxAndMinInfo(indexCode string) (item *EdbInfoMaxAndMinInfo, err error) {
  466. o := orm.NewOrm()
  467. 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=? `
  468. err = o.Raw(sql, indexCode).QueryRow(&item)
  469. if err != nil {
  470. return
  471. }
  472. // 获取最新值
  473. var latest_value float64
  474. sql = ` SELECT value AS latest_value FROM base_from_mysteel_chemical_data WHERE index_code=? ORDER BY data_time DESC LIMIT 1 `
  475. err = o.Raw(sql, indexCode).QueryRow(&latest_value)
  476. if err != nil {
  477. return
  478. }
  479. item.LatestValue = latest_value
  480. return
  481. }
  482. func (d *BaseFromMysteelChemicalData) ModifyMysteelIndexMaxAndMinInfo(indexCode string, item *EdbInfoMaxAndMinInfo) (err error) {
  483. o := orm.NewOrm()
  484. sql := ` UPDATE base_from_mysteel_chemical_index SET start_date=?,end_date=?,end_value=?,modify_time=NOW() WHERE index_code=? `
  485. _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.LatestValue, indexCode).Exec()
  486. return
  487. }
  488. // GetIndexByCondition 获取指标
  489. func (m *BaseFromMysteelChemicalIndex) GetIndexByCondition(condition string, pars []interface{}) (items []*BaseFromMysteelChemicalIndex, err error) {
  490. o := orm.NewOrm()
  491. sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE 1=1 `
  492. if condition != "" {
  493. sql += condition
  494. }
  495. _, err = o.Raw(sql, pars).QueryRows(&items)
  496. return
  497. }
  498. type BaseFromMysteelChemicalRecord struct {
  499. BaseFromMysteelChemicalRecordId int64 `orm:"column(base_from_mysteel_chemical_record_id);pk"`
  500. BaseFromMysteelChemicalIndexId int64
  501. OldIndexName string `description:"原始名称"`
  502. NewIndexName string `description:"新的名称"`
  503. CreateTime time.Time `description:"记录创建时间"`
  504. Timestamp int64 `description:"记录创建时间戳"`
  505. }
  506. func (m *BaseFromMysteelChemicalRecord) AddBaseFromMysteelChemicalRecord() (err error) {
  507. o := orm.NewOrm()
  508. _, err = o.Insert(m)
  509. return
  510. }
  511. type MySteelChemicalApiResp struct {
  512. Code string `json:"code" description:"200成功,其他失败"`
  513. Success bool `json:"success" description:"true 成功,false 失败"`
  514. Timestamp int64 `json:"timestamp" description:"时间戳"`
  515. Message string `json:"message" description:"显示执行信息"`
  516. Data []*MySteelChemicalApiData `json:"data" description:"数据"`
  517. }
  518. type MySteelChemicalApiInfoResp struct {
  519. Code string `json:"code" description:"200成功,其他失败"`
  520. Success bool `json:"success" description:"true 成功,false 失败"`
  521. Timestamp int64 `json:"timestamp" description:"时间戳"`
  522. Message string `json:"message" description:"显示执行信息"`
  523. Data *MySteelChemicalApiInfo `json:"data" description:"数据"`
  524. }
  525. type MySteelChemicalApiInfo struct {
  526. Total int `json:"total" description:"总条数"`
  527. Pages int `json:"pages" description:"总页数"`
  528. List []*MySteelChemicalApiInfoItem `json:"list" description:"数据列表"`
  529. }
  530. type MySteelChemicalApiInfoItem struct {
  531. IndexCode string `json:"INDEX_CODE"`
  532. IndexName string `json:"INDEX_NAME"`
  533. FrequencyName string `json:"FREQUENCY_NAME"`
  534. UnitName string `json:"UNIT_NAME"`
  535. }
  536. type MySteelChemicalApiData struct {
  537. IndexCode string `json:"INDEX_CODE"`
  538. DataList []*MySteelChemicalApiDataList `json:"dataList"`
  539. }
  540. type MySteelChemicalApiDataList struct {
  541. PublishTime int64 `json:"PUBLISH_TIME"`
  542. IndexCode string `json:"INDEX_CODE"`
  543. DataDate string `json:"DATA_DATE"`
  544. DataValue float64 `json:"DATA_VALUE"`
  545. }