chart_info.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package data_manage
  2. import (
  3. "eta/eta_task/global"
  4. "eta/eta_task/utils"
  5. "gorm.io/gorm"
  6. "time"
  7. )
  8. type ChartInfo struct {
  9. ChartInfoId int `gorm:"column:chart_info_id;primaryKey;autoIncrement"`
  10. ChartName string `description:"来源名称"`
  11. ChartClassifyId int `description:"图表分类id"`
  12. SysUserId int
  13. SysUserRealName string
  14. UniqueCode string `description:"图表唯一编码"`
  15. CreateTime time.Time
  16. ModifyTime time.Time
  17. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  18. StartDate string `description:"自定义开始日期"`
  19. EndDate string `description:"自定义结束日期"`
  20. IsSetName int `description:"设置名称"`
  21. EdbInfoIds string `description:"指标id"`
  22. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  23. Calendar string `description:"公历/农历"`
  24. SeasonStartDate string `description:"季节性图开始日期"`
  25. SeasonEndDate string `description:"季节性图开始日期"`
  26. ChartImage string `description:"图表图片"`
  27. Sort int `description:"排序字段,数字越小越排前面"`
  28. EdbEndDate string `description:"指标最后更新日期"`
  29. Source int `description:"1:ETA图库;2:商品价格曲线"`
  30. ExtraConfig string `description:"图表额外配置,json数据"`
  31. }
  32. func (m *ChartInfo) AfterFind(db *gorm.DB) (err error) {
  33. m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
  34. m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
  35. m.SeasonStartDate = utils.GormDateStrToDateStr(m.SeasonStartDate)
  36. m.SeasonEndDate = utils.GormDateStrToDateStr(m.SeasonEndDate)
  37. return
  38. }
  39. func GetAllChartInfo() (list []*ChartInfo, err error) {
  40. o := global.DbMap[utils.DbNameIndex]
  41. sql := ` SELECT * FROM chart_info `
  42. err = o.Raw(sql).Find(&list).Error
  43. return
  44. }
  45. func GetChartInfoEdbEndDate() (list []*ChartInfo, err error) {
  46. o := global.DbMap[utils.DbNameIndex]
  47. sql := ` SELECT a.*,max(c.end_date) AS edb_end_date FROM chart_info AS a
  48. INNER JOIN chart_edb_mapping AS b ON a.chart_info_id=b.chart_info_id
  49. INNER JOIN edb_info AS c ON b.edb_info_id=c.edb_info_id
  50. GROUP BY a.chart_info_id `
  51. err = o.Raw(sql).Find(&list).Error
  52. return
  53. }
  54. func ModifyChartInfoEdbEndDate(chartInfoId int, edbEndDate string) (err error) {
  55. o := global.DbMap[utils.DbNameIndex]
  56. sql := ` UPDATE chart_info SET edb_end_date=? WHERE chart_info_id=? `
  57. err = o.Exec(sql, edbEndDate, chartInfoId).Error
  58. return
  59. }
  60. // 根据chart_info_id数组获取图表信息
  61. func GetChartInfoByChartInfoIds(chartInfoIds []int) (list []*ChartInfo, err error) {
  62. o := global.DbMap[utils.DbNameIndex]
  63. sql := ` SELECT * FROM chart_info WHERE chart_info_id IN (` + utils.GetOrmInReplace(len(chartInfoIds)) + `) `
  64. err = o.Raw(sql, chartInfoIds).Find(&list).Error
  65. return
  66. }