chart.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package models
  2. import (
  3. "encoding/json"
  4. "eta/eta_index_lib/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "time"
  8. )
  9. type EdbInfoReq struct {
  10. EdbInfoId int `description:"图表id,新增时传0"`
  11. }
  12. // DeleteChartInfoDataRedis 清除图表缓存
  13. func DeleteChartInfoDataRedis(bodyByte []byte) (err error) {
  14. var req EdbInfoReq
  15. err = json.Unmarshal(bodyByte, &req)
  16. if err != nil {
  17. return
  18. }
  19. if req.EdbInfoId > 0 {
  20. list, tmpErr := GetChartEdbMappingListByEdbInfoId(req.EdbInfoId)
  21. if tmpErr != nil {
  22. err = tmpErr
  23. return
  24. }
  25. // 删除图表的id
  26. for _, v := range list {
  27. _ = utils.Rc.Delete(GetChartInfoDataKey(v.ChartInfoId))
  28. }
  29. }
  30. return
  31. }
  32. // GetChartInfoDataKey 获取图表缓存的key
  33. func GetChartInfoDataKey(chartInfoId int) string {
  34. key := fmt.Sprint(utils.CACHE_CHART_INFO_DATA, chartInfoId)
  35. return key
  36. }
  37. type ChartInfo struct {
  38. ChartInfoId int `orm:"column(chart_info_id);pk"`
  39. ChartName string `description:"来源名称"`
  40. ChartNameEn string `description:"英文图表名称"`
  41. ChartClassifyId int `description:"图表分类id"`
  42. SysUserId int
  43. SysUserRealName string
  44. UniqueCode string `description:"图表唯一编码"`
  45. CreateTime time.Time
  46. ModifyTime time.Time
  47. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  48. StartDate string `description:"自定义开始日期"`
  49. EndDate string `description:"自定义结束日期"`
  50. IsSetName int `description:"设置名称"`
  51. EdbInfoIds string `description:"指标id"`
  52. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图"`
  53. Calendar string `description:"公历/农历"`
  54. SeasonStartDate string `description:"季节性图开始日期"`
  55. SeasonEndDate string `description:"季节性图开始日期"`
  56. ChartImage string `description:"图表图片"`
  57. Sort int `description:"排序字段,数字越小越排前面"`
  58. LeftMin string `description:"图表左侧最小值"`
  59. LeftMax string `description:"图表左侧最大值"`
  60. RightMin string `description:"图表右侧最小值"`
  61. RightMax string `description:"图表右侧最大值"`
  62. Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
  63. BarConfig string `description:"柱方图的配置,json数据"`
  64. Source int `description:"1:ETA图库;2:商品价格曲线"`
  65. ExtraConfig string `description:"图表额外配置,json数据"`
  66. }
  67. // GetChartInfoById 通过id获取图表信息
  68. func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
  69. o := orm.NewOrm()
  70. sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
  71. err = o.Raw(sql, chartInfoId).QueryRow(&item)
  72. return
  73. }