chart_edb_mapping.go 6.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package models
  2. import (
  3. "eta/eta_chart_lib/global"
  4. "eta/eta_chart_lib/utils"
  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. err = global.DbMap[utils.DbNameIndex].Raw(sql, chartInfoId, utils.CHART_SOURCE_DEFAULT).First(&item).Error
  17. return
  18. }
  19. // GetEtaEdbChartEdbMappingList 商品曲线图查询对应的普通指标
  20. func GetEtaEdbChartEdbMappingList(chartInfoId int) (items []*ChartEdbInfoMapping, err error) {
  21. //o := orm.NewOrmUsingDB("data")
  22. 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`
  23. 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
  24. FROM chart_edb_mapping AS a
  25. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  26. WHERE a.chart_info_id=? AND a.source = ?
  27. ORDER BY chart_edb_mapping_id ASC `
  28. //_, err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_DEFAULT).QueryRows(&items)
  29. err = global.DbMap[utils.DbNameIndex].Raw(sql, chartInfoId, utils.CHART_SOURCE_DEFAULT).Find(&items).Error
  30. return
  31. }
  32. // GetFutureGoodEdbChartEdbMapping 商品曲线图查询对应的商品指标
  33. func GetFutureGoodEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
  34. //o := orm.NewOrmUsingDB("data")
  35. 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`
  36. 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
  37. FROM chart_edb_mapping AS a
  38. INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
  39. WHERE a.chart_info_id=? AND a.source = ?
  40. ORDER BY chart_edb_mapping_id ASC `
  41. //err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).QueryRow(&item)
  42. err = global.DbMap[utils.DbNameIndex].Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).First(&item).Error
  43. return
  44. }
  45. // GetFutureGoodEdbChartEdbMappingList 商品曲线图查询对应的商品指标
  46. func GetFutureGoodEdbChartEdbMappingList(chartInfoId int) (items []*ChartEdbInfoMapping, err error) {
  47. //o := orm.NewOrmUsingDB("data")
  48. 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`
  49. 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
  50. FROM chart_edb_mapping AS a
  51. INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
  52. WHERE a.chart_info_id=? AND a.source = ?
  53. ORDER BY chart_edb_mapping_id ASC `
  54. //_, err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).QueryRows(&items)
  55. err = global.DbMap[utils.DbNameIndex].Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).Find(&items).Error
  56. return
  57. }
  58. // GetChartEdbMappingByEdbInfoId 根据指标id获取edb_mapping
  59. func GetChartEdbMappingByEdbInfoId(edbInfoId int) (item *ChartEdbInfoMapping, err error) {
  60. //o := orm.NewOrmUsingDB("data")
  61. 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
  62. FROM edb_info
  63. WHERE edb_info_id = ? limit 1`
  64. //err = o.Raw(sql, edbInfoId).QueryRow(&item)
  65. err = global.DbMap[utils.DbNameIndex].Raw(sql, edbInfoId).First(&item).Error
  66. return
  67. }
  68. // GetChartEdbMappingListByEdbInfoIdList 根据指标id列表获取关联关系
  69. func GetChartEdbMappingListByEdbInfoIdList(edbIdList []int) (list []*ChartEdbInfoMapping, err error) {
  70. num := len(edbIdList)
  71. if num <= 0 {
  72. return
  73. }
  74. //o := orm.NewOrmUsingDB("data")
  75. 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
  76. FROM edb_info
  77. WHERE edb_info_id IN ?
  78. ORDER BY FIELD(edb_info_id,` + utils.GetOrmInReplace(num) + `)
  79. `
  80. //_, err = o.Raw(sql, edbIdList, edbIdList).QueryRows(&list)
  81. var pars []interface{}
  82. pars = append(pars, edbIdList)
  83. for i := 0; i < num; i++ {
  84. pars = append(pars, edbIdList[i])
  85. }
  86. err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&list).Error
  87. return
  88. }