excel_edb_mapping.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package excel
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // ExcelEdbMapping excel与指标的关系表
  8. type ExcelEdbMapping struct {
  9. ExcelEdbMappingId int `orm:"column(excel_edb_mapping_id);pk"`
  10. ExcelInfoId int `description:"excel的id"`
  11. Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
  12. EdbInfoId int `description:"计算指标id"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"修改时间"`
  15. }
  16. // AddExcelEdbMappingMulti 批量添加excel与指标的关系
  17. func AddExcelEdbMappingMulti(items []*ExcelEdbMapping) (err error) {
  18. o := orm.NewOrmUsingDB("data")
  19. _, err = o.InsertMulti(len(items), items)
  20. return
  21. }
  22. // Add 添加excel与指标的关系
  23. func (e *ExcelEdbMapping) Add() (err error) {
  24. o := orm.NewOrmUsingDB("data")
  25. _, err = o.Insert(e)
  26. return
  27. }
  28. // GetExcelEdbMappingByEdbInfoId 根据指标id获取配置关系
  29. func GetExcelEdbMappingByEdbInfoId(edbInfoId int) (item *ExcelEdbMapping, err error) {
  30. o := orm.NewOrmUsingDB("data")
  31. sql := ` SELECT * FROM excel_edb_mapping WHERE 1=1 AND edb_info_id = ? `
  32. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  33. return
  34. }
  35. // GetExcelEdbMappingByExcelInfoId 根据excel的id获取配置关系
  36. func GetExcelEdbMappingByExcelInfoId(excelInfoId int) (items []*ExcelEdbMapping, err error) {
  37. o := orm.NewOrmUsingDB("data")
  38. sql := ` SELECT * FROM excel_edb_mapping AS a
  39. join edb_info as b on a.edb_info_id = b.edb_info_id
  40. WHERE 1=1 AND a.excel_info_id = ? `
  41. _, err = o.Raw(sql, excelInfoId).QueryRows(&items)
  42. return
  43. }
  44. type ExcelEdbMappingItem struct {
  45. EdbInfoId int `description:"指标id"`
  46. UniqueCode string `description:"唯一编码"`
  47. EdbName string `description:"指标名称"`
  48. ClassifyId int `description:"分类id"`
  49. Frequency string `description:"频度"`
  50. Unit string `description:"单位"`
  51. CalculateFormula string `json:"-"`
  52. DateSequenceStr string `description:"日期序列公式"`
  53. DataSequenceStr string `description:"数据序列公式"`
  54. }
  55. // CalculateFormula 计算公式
  56. type CalculateFormula struct {
  57. DateSequenceStr string `json:"DateSequenceStr"`
  58. DataSequenceStr string `json:"DataSequenceStr"`
  59. }
  60. // GetAllExcelEdbMappingItemByExcelInfoId 根据品种id获取所有的指标结果集
  61. func GetAllExcelEdbMappingItemByExcelInfoId(excelInfoId int) (items []*ExcelEdbMappingItem, err error) {
  62. o := orm.NewOrmUsingDB("data")
  63. sql := `SELECT a.edb_info_id,a.unique_code,a.edb_name,a.classify_id,a.frequency,a.unit,calculate_formula FROM edb_info AS a
  64. JOIN excel_edb_mapping AS b ON a.edb_info_id=b.edb_info_id
  65. WHERE b.excel_info_id = ? ORDER BY b.excel_edb_mapping_id ASC `
  66. _, err = o.Raw(sql, excelInfoId).QueryRows(&items)
  67. return
  68. }
  69. // GetNoCustomAnalysisExcelEdbMappingCount 根据指标id获取非自定义分析的关联关系
  70. func GetNoCustomAnalysisExcelEdbMappingCount(edbInfoId int) (count int, err error) {
  71. o := orm.NewOrmUsingDB("data")
  72. sql := ` SELECT COUNT(1) AS count FROM excel_edb_mapping a
  73. join excel_info b on a.excel_info_id=b.excel_info_id
  74. WHERE edb_info_id=? AND a.source != 4 AND b.is_delete = 0`
  75. err = o.Raw(sql, edbInfoId).QueryRow(&count)
  76. return
  77. }
  78. // GetAllExcelEdbMappingByExcelInfoId 根据品种id获取所有的指标
  79. func GetAllExcelEdbMappingByExcelInfoId(excelInfoId int) (items []*ExcelEdbMapping, err error) {
  80. o := orm.NewOrmUsingDB("data")
  81. sql := `SELECT b.* FROM excel_edb_mapping a
  82. WHERE a.excel_info_id = ? ORDER BY a.excel_edb_mapping_id ASC `
  83. _, err = o.Raw(sql, excelInfoId).QueryRows(&items)
  84. return
  85. }
  86. // DeleteCustomAnalysisExcelEdbMappingByEdbInfoId
  87. // @Description: 根据指标id删除与自定义分析表格的关系
  88. // @author: Roc
  89. // @datetime2023-11-02 13:20:02
  90. // @param excelInfoId int
  91. // @return err error
  92. func DeleteCustomAnalysisExcelEdbMappingByEdbInfoId(excelInfoId int) (err error) {
  93. o := orm.NewOrmUsingDB("data")
  94. sql := `DELETE FROM excel_edb_mapping WHERE source = ? AND edb_info_id = ? LIMIT 1`
  95. _, err = o.Raw(sql, utils.CUSTOM_ANALYSIS_TABLE, excelInfoId).Exec()
  96. return
  97. }