12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package excel
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- // ExcelEdbMapping excel与指标的关系表
- type ExcelEdbMapping struct {
- ExcelEdbMappingId int `orm:"column(excel_edb_mapping_id);pk"`
- ExcelInfoId int `description:"excel的id"`
- Source int `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
- EdbInfoId int `description:"计算指标id"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- // AddExcelEdbMappingMulti 批量添加excel与指标的关系
- func AddExcelEdbMappingMulti(items []*ExcelEdbMapping) (err error) {
- o := orm.NewOrm()
- _, err = o.InsertMulti(len(items), items)
- return
- }
- // Add 添加excel与指标的关系
- func (e *ExcelEdbMapping) Add() (err error) {
- o := orm.NewOrm()
- _, err = o.Insert(e)
- return
- }
- // GetExcelEdbMappingByEdbInfoId 根据指标id获取配置关系
- func GetExcelEdbMappingByEdbInfoId(edbInfoId int) (item *ExcelEdbMapping, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM excel_edb_mapping WHERE 1=1 AND edb_info_id = ? `
- err = o.Raw(sql, edbInfoId).QueryRow(&item)
- return
- }
- // GetExcelEdbMappingByExcelInfoId 根据excel的id获取配置关系
- func GetExcelEdbMappingByExcelInfoId(excelInfoId int) (items []*ExcelEdbMapping, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM excel_edb_mapping WHERE 1=1 AND excel_info_id = ? `
- _, err = o.Raw(sql, excelInfoId).QueryRows(&items)
- return
- }
- type ExcelEdbMappingItem struct {
- EdbInfoId int `description:"指标id"`
- UniqueCode string `description:"唯一编码"`
- EdbName string `description:"指标名称"`
- ClassifyId int `description:"分类id"`
- Frequency string `description:"频度"`
- Unit string `description:"单位"`
- CalculateFormula string `json:"-"`
- DateSequenceStr string `description:"日期序列公式"`
- DataSequenceStr string `description:"数据序列公式"`
- }
- // CalculateFormula 计算公式
- type CalculateFormula struct {
- DateSequenceStr string `json:"DateSequenceStr"`
- DataSequenceStr string `json:"DataSequenceStr"`
- }
- // GetAllExcelEdbMappingItemByExcelInfoId 根据品种id获取所有的指标
- func GetAllExcelEdbMappingItemByExcelInfoId(excelInfoId int) (items []*ExcelEdbMappingItem, err error) {
- o := orm.NewOrmUsingDB("data")
- 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
- JOIN excel_edb_mapping AS b ON a.edb_info_id=b.edb_info_id
- WHERE b.excel_info_id = ? ORDER BY b.excel_edb_mapping_id ASC `
- _, err = o.Raw(sql, excelInfoId).QueryRows(&items)
- return
- }
|