chart_edb_mapping.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/utils"
  6. "time"
  7. )
  8. type ChartEdbMapping struct {
  9. ChartEdbMappingId int `orm:"column(chart_edb_mapping_id);pk"`
  10. ChartInfoId int `description:"图表id"`
  11. EdbInfoId int `description:"指标id"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"修改时间"`
  14. UniqueCode string `description:"唯一编码"`
  15. MaxData float64 `description:"上限"`
  16. MinData float64 `description:"下限"`
  17. IsOrder bool `description:"true:正序,false:逆序"`
  18. IsAxis int `description:"true:左轴,false:右轴"`
  19. EdbInfoType int `description:"true:标准指标,false:领先指标"`
  20. LeadValue int `description:"领先值"`
  21. LeadUnit string `description:"领先单位"`
  22. ChartStyle string `description:"图表类型"`
  23. ChartColor string `description:"颜色"`
  24. PredictChartColor string `description:"预测数据的颜色"`
  25. ChartWidth float64 `description:"线条大小"`
  26. Source int `description:"1:ETA图库;2:商品价格曲线"`
  27. }
  28. func AddChartEdbMapping(items []*ChartEdbMapping) (err error) {
  29. o := orm.NewOrmUsingDB("data")
  30. _, err = o.InsertMulti(1, items)
  31. return
  32. }
  33. func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
  34. o := orm.NewOrmUsingDB("data")
  35. sql := ` SELECT a.*,b.source_name,b.source,b.classify_id,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.edb_type
  36. FROM chart_edb_mapping AS a
  37. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  38. WHERE chart_info_id=?
  39. ORDER BY chart_edb_mapping_id ASC `
  40. _, err = o.Raw(sql, chartInfoId).QueryRows(&list)
  41. return
  42. }
  43. func GetChartEdbMappingListByChartInfoIds(chartInfoIds string) (list []*ChartEdbInfoMapping, err error) {
  44. o := orm.NewOrmUsingDB("data")
  45. sql := ` SELECT a.*,b.source_name,b.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.edb_type
  46. FROM chart_edb_mapping AS a
  47. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  48. WHERE chart_info_id in (` + chartInfoIds + `)
  49. ORDER BY chart_edb_mapping_id ASC `
  50. _, err = o.Raw(sql).QueryRows(&list)
  51. return
  52. }
  53. func GetChartEdbMappingListByEdbInfoId(edbInfoStr string) (list []*ChartEdbInfoMapping, err error) {
  54. o := orm.NewOrmUsingDB("data")
  55. sql := ` SELECT edb_info_id,source_name,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
  56. FROM edb_info
  57. WHERE edb_info_id IN(` + edbInfoStr + `)
  58. ORDER BY FIELD(edb_info_id,` + edbInfoStr + `)
  59. `
  60. _, err = o.Raw(sql).QueryRows(&list)
  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,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. }
  78. // GetChartEdbMappingListByIdList 通过图表id列表获取
  79. func GetChartEdbMappingListByIdList(chartInfoIdList []int) (list []*ChartEdbInfoMapping, err error) {
  80. num := len(chartInfoIdList)
  81. if num <= 0 {
  82. return
  83. }
  84. o := orm.NewOrmUsingDB("data")
  85. sql := ` SELECT a.*,b.source_name,b.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,b.edb_type AS edb_info_category_type
  86. FROM chart_edb_mapping AS a
  87. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  88. WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `)
  89. ORDER BY chart_edb_mapping_id ASC `
  90. _, err = o.Raw(sql, chartInfoIdList).QueryRows(&list)
  91. return
  92. }
  93. // RelationEdbInfoListResp 关联指标列表数据返回
  94. type RelationEdbInfoListResp struct {
  95. Paging *paging.PagingItem
  96. List []*ChartEdbInfoMapping
  97. }
  98. func GetRelationEdbInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (item []*ChartEdbInfoMapping, err error) {
  99. o := orm.NewOrmUsingDB("data")
  100. sql := ` SELECT a.* FROM edb_info AS a
  101. JOIN edb_info_calculate_mapping AS b on a.edb_info_id = b.edb_info_id WHERE 1=1 `
  102. if condition != "" {
  103. sql += condition
  104. }
  105. //sql += " ORDER BY sort ASC,chart_info_id DESC LIMIT ?,? "
  106. sql += " ORDER BY a.create_time DESC LIMIT ?,? "
  107. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&item)
  108. return
  109. }
  110. func GetRelationEdbInfoListCountByCondition(condition string, pars []interface{}) (count int, err error) {
  111. o := orm.NewOrmUsingDB("data")
  112. sql := ` SELECT COUNT(1) AS count FROM edb_info AS a
  113. JOIN edb_info_calculate_mapping AS b on a.edb_info_id = b.edb_info_id WHERE 1=1 `
  114. if condition != "" {
  115. sql += condition
  116. }
  117. err = o.Raw(sql, pars).QueryRow(&count)
  118. return
  119. }
  120. // GetEtaEdbChartEdbMapping 商品曲线图查询对应的普通指标
  121. func GetEtaEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
  122. o := orm.NewOrmUsingDB("data")
  123. 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`
  124. sql := ` SELECT ` + aField + `,b.source_name,b.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
  125. FROM chart_edb_mapping AS a
  126. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  127. WHERE a.chart_info_id=? AND a.source = ?
  128. ORDER BY chart_edb_mapping_id ASC `
  129. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_DEFAULT).QueryRow(&item)
  130. return
  131. }
  132. // GetFutureGoodEdbChartEdbMapping 商品曲线图查询对应的商品指标
  133. func GetFutureGoodEdbChartEdbMapping(chartInfoId int) (item *ChartEdbInfoMapping, err error) {
  134. o := orm.NewOrmUsingDB("data")
  135. 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`
  136. 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
  137. FROM chart_edb_mapping AS a
  138. INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
  139. WHERE a.chart_info_id=? AND a.source = ?
  140. ORDER BY chart_edb_mapping_id ASC `
  141. err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).QueryRow(&item)
  142. return
  143. }
  144. // GetFutureGoodEdbChartEdbMappingList 商品曲线图查询对应的商品指标
  145. func GetFutureGoodEdbChartEdbMappingList(chartInfoId int) (items []*ChartEdbInfoMapping, err error) {
  146. o := orm.NewOrmUsingDB("data")
  147. 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`
  148. 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
  149. FROM chart_edb_mapping AS a
  150. INNER JOIN future_good_edb_info AS b ON a.edb_info_id=b.future_good_edb_info_id
  151. WHERE a.chart_info_id=? AND a.source = ?
  152. ORDER BY chart_edb_mapping_id ASC `
  153. _, err = o.Raw(sql, chartInfoId, utils.CHART_SOURCE_FUTURE_GOOD).QueryRows(&items)
  154. return
  155. }
  156. // GetChartEdbMappingListV2 根据图表id获取指标信息,不连表查询指标表
  157. func GetChartEdbMappingListV2(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
  158. o := orm.NewOrmUsingDB("data")
  159. sql := ` SELECT a.* FROM chart_edb_mapping AS a
  160. WHERE chart_info_id=?
  161. ORDER BY chart_edb_mapping_id ASC `
  162. _, err = o.Raw(sql, chartInfoId).QueryRows(&list)
  163. return
  164. }
  165. // GetChartEdbMappingByEdbInfoId 根据指标id获取edb_mapping
  166. func GetChartEdbMappingByEdbInfoId(edbInfoId int) (item *ChartEdbInfoMapping, err error) {
  167. o := orm.NewOrmUsingDB("data")
  168. sql := ` SELECT edb_info_id,source_name,classify_id,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
  169. FROM edb_info
  170. WHERE edb_info_id = ? limit 1`
  171. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  172. return
  173. }
  174. // GetChartEdbMappingByFutureGoodEdbInfoId 根据指标id获取edb_mapping
  175. func GetChartEdbMappingByFutureGoodEdbInfoId(edbInfoId int) (item *ChartEdbInfoMapping, err error) {
  176. o := orm.NewOrmUsingDB("data")
  177. sql := ` SELECT future_good_edb_info_id as edb_info_id,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,b.region_type
  178. FROM future_good_edb_info b
  179. WHERE future_good_edb_info_id = ? limit 1 `
  180. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  181. return
  182. }