chart_edb_mapping.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package models
  2. import (
  3. "eta_gn/eta_chart_lib/global"
  4. "eta_gn/eta_chart_lib/utils"
  5. )
  6. func GetEtaEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
  7. o := global.DmSQL["data"]
  8. 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`
  9. 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
  10. FROM chart_edb_mapping AS a
  11. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  12. WHERE a.chart_info_id=? AND a.source = ?
  13. ORDER BY chart_edb_mapping_id ASC `
  14. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_DEFAULT).First(&item).Error
  15. return
  16. }
  17. func GetEtaEdbChartEdbMappingList(chartInfoId int) (items []*ChartEdbInfoMapping, err error) {
  18. o := global.DmSQL["data"]
  19. 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`
  20. 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
  21. FROM chart_edb_mapping AS a
  22. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  23. WHERE a.chart_info_id=? AND a.source = ?
  24. ORDER BY chart_edb_mapping_id ASC `
  25. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_DEFAULT).Scan(&items).Error
  26. return
  27. }
  28. func GetFutureGoodEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
  29. o := global.DmSQL["data"]
  30. 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`
  31. 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
  32. FROM chart_edb_mapping AS a
  33. INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
  34. WHERE a.chart_info_id=? AND a.source = ?
  35. ORDER BY chart_edb_mapping_id ASC `
  36. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).First(&item).Error
  37. return
  38. }
  39. func GetFutureGoodEdbChartEdbMappingList(chartInfoId int) (items []*ChartEdbInfoMapping, err error) {
  40. o := global.DmSQL["data"]
  41. 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`
  42. 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
  43. FROM chart_edb_mapping AS a
  44. INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
  45. WHERE a.chart_info_id=? AND a.source = ?
  46. ORDER BY chart_edb_mapping_id ASC `
  47. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).Scan(&items).Error
  48. return
  49. }
  50. func GetChartEdbMappingByEdbInfoId(edbInfoId int) (item *ChartEdbInfoMapping, err error) {
  51. o := global.DmSQL["data"]
  52. 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
  53. FROM edb_info
  54. WHERE edb_info_id = ? limit 1`
  55. err = o.Raw(sql, edbInfoId).First(&item).Error
  56. return
  57. }
  58. func GetChartEdbMappingListByEdbInfoIdList(edbIdList []int) (list []*ChartEdbInfoMapping, err error) {
  59. num := len(edbIdList)
  60. if num <= 0 {
  61. return
  62. }
  63. o := global.DmSQL["data"]
  64. 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
  65. FROM edb_info
  66. WHERE edb_info_id IN(` + utils.GetGormInReplace(num) + `)
  67. ORDER BY FIELD(edb_info_id,` + utils.GetOrmInReplace(num) + `)
  68. `
  69. var pars []interface{}
  70. pars = append(pars, edbIdList)
  71. for _, v := range edbIdList {
  72. pars = append(pars, v)
  73. }
  74. err = o.Raw(sql, pars...).Scan(&list).Error
  75. return
  76. }