base_from_mysteel_chemical_index.go 5.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package data_manage
  2. import (
  3. "eta/eta_task/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. type BaseFromMysteelChemicalIndexItem struct {
  7. BaseFromMysteelChemicalIndexId int32 `json:"base_from_mysteel_chemical_index_id"`
  8. BaseFromMysteelChemicalClassifyId int32 `json:"base_from_mysteel_chemical_classify_id"` // 钢联化工指标分类id
  9. IndexCode string `json:"index_code"` // 指标编码
  10. IndexName string `json:"index_name"` // 指标名称
  11. Unit string `json:"unit"` // 单位
  12. Source string `json:"source"` // 数据来源
  13. Frequency string `json:"frequency"` // 频度
  14. StartDate string `json:"start_date"` // 开始日期
  15. EndDate string `json:"end_date"` // 结束日期
  16. Describe string `json:"describe"` // 指标描述
  17. UpdateWeek string `json:"update_week"` // 更新周期
  18. UpdateTime string `json:"update_time"` // 更新时间,多个时间点用英文,隔开
  19. UpdateTime2 string `json:"update_time2"` // 更新时间2
  20. SysUserId int32 `json:"sys_user_id"` // 创建人id
  21. SysUserRealName string `json:"sys_user_real_name"` // 创建人姓名
  22. CreateTime string `json:"create_time"` // 创建时间
  23. ModifyTime string `json:"modify_time"` // 修改时间
  24. FilePath string `json:"file_path"` // 文件存储路径
  25. Sort int32 `json:"sort"` // 排序
  26. MergeFilePath string `json:"merge_file_path"`
  27. FileIndex int32 `json:"file_index"`
  28. MergeUpdateWeek string `json:"merge_update_week"` // 合并文件的更新周
  29. MergeFilePathWeek string `json:"merge_file_path_week"` // 更新文件
  30. UpdateDate string `json:"update_date"` // 更新日期
  31. IsRefresh int32 `json:"is_refresh"` // 0:不需要及时刷新,1:需要及时刷新
  32. IsStop int32 `json:"is_stop"` // 是否停更:1:停更,0:未停更
  33. TerminalCode string `json:"terminal_code"` // 所属终端编码
  34. EndValue float64 `json:"end_value"` // 指标的最新值
  35. EdbInfoId int `json:"edb_info_id"`
  36. }
  37. // GetBaseFromMysteelChemicalIndexItemByCode
  38. // @Description: 根据指标编码获取钢联指标详情
  39. // @author: Roc
  40. // @datetime 2024-03-11 16:42:56
  41. // @param edbCode string
  42. // @return item *BaseFromMysteelChemicalIndexItem
  43. // @return err error
  44. func GetBaseFromMysteelChemicalIndexItemByCode(edbCode string) (item *BaseFromMysteelChemicalIndexItem, err error) {
  45. o := orm.NewOrmUsingDB("data")
  46. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE index_code = ?`
  47. err = o.Raw(sql, edbCode).QueryRow(&item)
  48. return
  49. }
  50. func GetBaseFromMysteelChemicalIndexItems(frequencyList []string) (items []*BaseFromMysteelChemicalIndexItem, err error) {
  51. num := len(frequencyList)
  52. if num == 0 {
  53. return
  54. }
  55. o := orm.NewOrmUsingDB("data")
  56. sql := ` SELECT b.*, e.edb_info_id FROM base_from_mysteel_chemical_index AS b
  57. LEFT JOIN edb_info AS e
  58. ON b.index_code = e.edb_code
  59. WHERE b.source='api' AND b.frequency IN (` + utils.GetOrmInReplace(len(frequencyList)) + `)`
  60. _, err = o.Raw(sql, frequencyList).QueryRows(&items)
  61. return
  62. }
  63. // GetRefreshBaseFromMysteelChemicalIndexItemByCreateTime 获取正常刷新的钢联化工指标
  64. func GetRefreshBaseFromMysteelChemicalIndexItemByCreateTime(endDate string, startPage, pageSize int) (items []*BaseFromMysteelChemicalIndexItem, err error) {
  65. o := orm.NewOrmUsingDB("data")
  66. sql := ` SELECT * FROM base_from_mysteel_chemical_index WHERE is_stop = 0 and create_time < ? Limit ?,?`
  67. _, err = o.Raw(sql, endDate, startPage, pageSize).QueryRows(&items)
  68. return
  69. }
  70. // GetCountRefreshBaseFromMysteelChemicalIndexItemByCreateTime 获取正常刷新的钢联化工指标
  71. func GetCountRefreshBaseFromMysteelChemicalIndexItemByCreateTime(endDate string) (total int64, err error) {
  72. o := orm.NewOrmUsingDB("data")
  73. sql := ` SELECT count(*) FROM base_from_mysteel_chemical_index WHERE is_stop = 0 and create_time < ?`
  74. err = o.Raw(sql, endDate).QueryRow(&total)
  75. return
  76. }
  77. func SetStopRefreshMysteelChemicalIndex(ids []int32) (err error) {
  78. o := orm.NewOrmUsingDB("data")
  79. sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 1 WHERE base_from_mysteel_chemical_index_id IN (` + utils.GetOrmInReplace(len(ids)) + `) and is_stop=0`
  80. _, err = o.Raw(sql, ids).Exec()
  81. return
  82. }