predict_edb_conf_calculate_mapping.go 5.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. // PredictEdbConfCalculateMapping 预测基础指标规则 与 计算预测指标关联关系表
  8. type PredictEdbConfCalculateMapping struct {
  9. PredictEdbConfCalculateMappingId int `orm:"column(predict_edb_conf_calculate_mapping_id);pk"`
  10. EdbInfoId int `description:"指标id"`
  11. ConfigId int `description:"配置id"`
  12. FromEdbInfoId int `description:"基础指标id"`
  13. FromEdbCode string `description:"基础指标编码"`
  14. FromEdbName string `description:"基础指标名称"`
  15. FromSource int `description:"基础指标来源"`
  16. FromSourceName string `description:"基础指标来源名称"`
  17. FromTag string `description:"来源指标标签"`
  18. Sort int `description:"计算指标名称排序"`
  19. CreateTime time.Time `description:"创建时间"`
  20. ModifyTime time.Time `description:"修改时间"`
  21. }
  22. // GetPredictEdbConfCalculateMappingListById 根据预测指标id获取预测指标配置的关联指标信息列表
  23. func GetPredictEdbConfCalculateMappingListById(edbInfoId int) (items []*PredictEdbConf, err error) {
  24. o := orm.NewOrmUsingDB("data")
  25. sql := ` SELECT * FROM predict_edb_conf_calculate_mapping WHERE edb_info_id=? ORDER BY predict_edb_conf_calculate_mapping_id ASC`
  26. _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
  27. return
  28. }
  29. // GetPredictEdbConfCalculateMappingListByConfigId 根据预测指标配置id获取预测指标配置的关联指标信息列表
  30. func GetPredictEdbConfCalculateMappingListByConfigId(edbInfoId, configId int) (items []*PredictEdbConf, err error) {
  31. o := orm.NewOrmUsingDB("data")
  32. sql := ` SELECT * FROM predict_edb_conf_calculate_mapping WHERE edb_info_id=? AND config_id=? ORDER BY predict_edb_conf_calculate_mapping_id ASC`
  33. _, err = o.Raw(sql, edbInfoId, configId).QueryRows(&items)
  34. return
  35. }
  36. type PredictEdbConfCalculateMappingDetail struct {
  37. PredictEdbConfCalculateMappingId int `orm:"column(predict_edb_conf_calculate_mapping_id);pk"`
  38. EdbInfoId int `description:"指标id"`
  39. ConfigId int `description:"配置id"`
  40. FromEdbInfoId int `description:"基础指标id"`
  41. FromEdbCode string `description:"基础指标编码"`
  42. FromEdbName string `description:"基础指标名称"`
  43. FromSource int `description:"基础指标来源"`
  44. FromSourceName string `description:"基础指标来源名称"`
  45. FromTag string `description:"来源指标标签"`
  46. Sort int `description:"计算指标名称排序"`
  47. CreateTime time.Time `description:"创建时间"`
  48. ModifyTime time.Time `description:"修改时间"`
  49. StartDate string `description:"开始日期"`
  50. EndDate string `description:"结束日期"`
  51. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  52. EdbCode string `description:"指标code"`
  53. }
  54. // GetPredictEdbConfCalculateMappingDetailListById 根据配置id获取 配置关联指标信息
  55. func GetPredictEdbConfCalculateMappingDetailListById(edbInfoId int) (list []*PredictEdbConfCalculateMappingDetail, err error) {
  56. o := orm.NewOrmUsingDB("data")
  57. sql := ` SELECT a.predict_edb_conf_calculate_mapping_id,a.edb_info_id,a.from_edb_info_id,a.from_edb_code,a.from_source,a.from_source_name,a.sort,a.create_time,a.modify_time,a.from_tag,b.edb_name_source as from_edb_name,b.start_date,b.end_date,b.edb_type FROM predict_edb_conf_calculate_mapping AS a
  58. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  59. WHERE a.edb_info_id=? ORDER BY sort ASC `
  60. _, err = o.Raw(sql, edbInfoId).QueryRows(&list)
  61. return
  62. }
  63. // GetPredictEdbConfCalculateMappingDetailListByConfigId 根据配置id和指标id获取 配置关联指标信息
  64. func GetPredictEdbConfCalculateMappingDetailListByConfigId(edbInfoId, configId int) (list []*PredictEdbConfCalculateMappingDetail, err error) {
  65. o := orm.NewOrmUsingDB("data")
  66. sql := ` SELECT a.predict_edb_conf_calculate_mapping_id,a.edb_info_id,a.from_edb_info_id,a.from_edb_code,a.from_source,a.from_source_name,a.sort,a.create_time,a.modify_time,a.from_tag,b.edb_name_source as from_edb_name,b.start_date,b.end_date,b.edb_type FROM predict_edb_conf_calculate_mapping AS a
  67. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  68. WHERE a.edb_info_id=? AND a.config_id=? ORDER BY sort ASC `
  69. _, err = o.Raw(sql, edbInfoId, configId).QueryRows(&list)
  70. return
  71. }
  72. // GetPredictEdbConfCalculateMappingDetailListByEdbInfoId 根据 关联指标id列表 来 获取 相关联的配置关联指标信息
  73. func GetPredictEdbConfCalculateMappingDetailListByEdbInfoId(fromEdbInfoIdList []int) (list []*PredictEdbConfCalculateMappingDetail, err error) {
  74. num := len(fromEdbInfoIdList)
  75. if num <= 0 {
  76. return
  77. }
  78. o := orm.NewOrmUsingDB("data")
  79. sql := ` SELECT a.predict_edb_conf_calculate_mapping_id,a.edb_info_id,a.from_edb_info_id,a.from_edb_code,a.from_source,a.from_source_name,a.sort,a.create_time,a.modify_time,a.from_tag,b.edb_name_source as from_edb_name,b.start_date,b.end_date,b.edb_type,b.edb_code FROM predict_edb_conf_calculate_mapping AS a
  80. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  81. WHERE a.edb_info_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY a.edb_info_id ORDER BY sort ASC `
  82. _, err = o.Raw(sql, fromEdbInfoIdList).QueryRows(&list)
  83. return
  84. }