excel_edb_mapping.go 3.6 KB

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