chart_edb_mapping.go 5.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package models
  2. import (
  3. "eta/eta_chart_lib/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. // GetEtaEdbChartEdbMapping 商品曲线图查询对应的普通指标
  7. func GetEtaEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
  8. o := orm.NewOrmUsingDB("data")
  9. aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
  10. sql := ` SELECT ` + aField + `,b.source_name,b.source,b.sub_source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type
  11. FROM chart_edb_mapping AS a
  12. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  13. WHERE a.chart_info_id=? AND a.source = ?
  14. ORDER BY chart_edb_mapping_id ASC `
  15. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_DEFAULT).QueryRow(&item)
  16. return
  17. }
  18. // GetEtaEdbChartEdbMappingList 商品曲线图查询对应的普通指标
  19. func GetEtaEdbChartEdbMappingList(chartInfoId int) (items []*ChartEdbInfoMapping, err error) {
  20. o := orm.NewOrmUsingDB("data")
  21. aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
  22. sql := ` SELECT ` + aField + `,b.source_name,b.source,b.sub_source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type,b.classify_id,b.is_join_permission
  23. FROM chart_edb_mapping AS a
  24. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  25. WHERE a.chart_info_id=? AND a.source = ?
  26. ORDER BY chart_edb_mapping_id ASC `
  27. _, err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_DEFAULT).QueryRows(&items)
  28. return
  29. }
  30. // GetFutureGoodEdbChartEdbMapping 商品曲线图查询对应的商品指标
  31. func GetFutureGoodEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
  32. o := orm.NewOrmUsingDB("data")
  33. aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
  34. sql := ` SELECT ` + aField + `,b.future_good_edb_info_id,b.future_good_edb_code as edb_code,b.future_good_edb_name as edb_name,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value
  35. FROM chart_edb_mapping AS a
  36. INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
  37. WHERE a.chart_info_id=? AND a.source = ?
  38. ORDER BY chart_edb_mapping_id ASC `
  39. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).QueryRow(&item)
  40. return
  41. }
  42. // GetFutureGoodEdbChartEdbMappingList 商品曲线图查询对应的商品指标
  43. func GetFutureGoodEdbChartEdbMappingList(chartInfoId int) (items []*ChartEdbInfoMapping, err error) {
  44. o := orm.NewOrmUsingDB("data")
  45. aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source`
  46. sql := ` SELECT ` + aField + `,b.future_good_edb_info_id,b.future_good_edb_code as edb_code,b.future_good_edb_name as edb_name,b.start_date,b.end_date,b.modify_time,b.latest_date,b.latest_value
  47. FROM chart_edb_mapping AS a
  48. INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
  49. WHERE a.chart_info_id=? AND a.source = ?
  50. ORDER BY chart_edb_mapping_id ASC `
  51. _, err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).QueryRows(&items)
  52. return
  53. }
  54. // GetChartEdbMappingByEdbInfoId 根据指标id获取edb_mapping
  55. func GetChartEdbMappingByEdbInfoId(edbInfoId int) (item *ChartEdbInfoMapping, err error) {
  56. o := orm.NewOrmUsingDB("data")
  57. sql := ` SELECT edb_info_id,source_name,source,sub_source,edb_code,edb_name,edb_name_en,frequency,unit,unit_en,start_date,end_date,modify_time,latest_date,latest_value,unique_code,edb_info_type AS edb_info_category_type,max_value,min_value
  58. FROM edb_info
  59. WHERE edb_info_id = ? limit 1`
  60. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  61. return
  62. }
  63. // GetChartEdbMappingListByEdbInfoIdList 根据指标id列表获取关联关系
  64. func GetChartEdbMappingListByEdbInfoIdList(edbIdList []int) (list []*ChartEdbInfoMapping, err error) {
  65. num := len(edbIdList)
  66. if num <= 0 {
  67. return
  68. }
  69. o := orm.NewOrmUsingDB("data")
  70. sql := ` SELECT edb_info_id,source_name,source,sub_source,edb_code,edb_name,edb_name_en,frequency,unit,unit_en,start_date,end_date,modify_time,latest_date,latest_value,unique_code,edb_info_type AS edb_info_category_type,max_value,min_value,edb_type
  71. FROM edb_info
  72. WHERE edb_info_id IN(` + utils.GetOrmInReplace(num) + `)
  73. ORDER BY FIELD(edb_info_id,` + utils.GetOrmInReplace(num) + `)
  74. `
  75. _, err = o.Raw(sql, edbIdList, edbIdList).QueryRows(&list)
  76. return
  77. }