excel_edb_mapping.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.NewOrm()
  18. _, err = o.InsertMulti(len(items), items)
  19. return
  20. }
  21. // Add 添加excel与指标的关系
  22. func (e *ExcelEdbMapping) Add() (err error) {
  23. o := orm.NewOrm()
  24. _, err = o.Insert(e)
  25. return
  26. }
  27. // GetExcelEdbMappingByEdbInfoId 根据指标id获取配置关系
  28. func GetExcelEdbMappingByEdbInfoId(edbInfoId int) (item *ExcelEdbMapping, err error) {
  29. o := orm.NewOrm()
  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.NewOrm()
  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. }