123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package data_manage
- import (
- "eta/eta_task/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type EdbInfoCalculateMapping struct {
- EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
- EdbInfoId int `description:"计算指标id"`
- Source int `description:"计算指标来源"`
- SourceName string `description:"计算指标来源名称"`
- EdbCode string `description:"计算指标编码"`
- FromEdbInfoId int `description:"基础指标id"`
- FromEdbCode string `description:"基础指标编码"`
- FromEdbName string `description:"基础指标名称"`
- FromSource int `description:"基础指标来源"`
- FromSourceName string `description:"基础指标来源名称"`
- FromTag string `description:"来源指标标签"`
- Sort int `description:"计算指标名称排序"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- func AddEdbInfoCalculateMappingMulti(items []*EdbInfoCalculateMapping) (err error) {
- o := orm.NewOrm()
- _, err = o.InsertMulti(1, items)
- return
- }
- func FixEdbInfoCalculateMapping() {
- o := orm.NewOrm()
- tx, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
- edbInfoList := make([]*EdbInfoList, 0)
- sql := `SELECT * FROM edb_info WHERE edb_type=2 `
- _, err = o.Raw(sql).QueryRows(&edbInfoList)
- if err != nil {
- return
- }
- for k, v := range edbInfoList {
- fmt.Println(k, v.EdbInfoId)
- calculateList := make([]*EdbInfoCalculateDetail, 0)
- calculateTableName := GetEdbInfoCalculateTableName(v.Source)
- sql := ` SELECT * FROM %s
- WHERE edb_info_id=? ORDER BY sort ASC `
- sql = fmt.Sprintf(sql, calculateTableName)
- _, err = tx.Raw(sql, v.EdbInfoId).QueryRows(&calculateList)
- if err != nil {
- fmt.Println("query calculate err:" + err.Error())
- return
- }
- for _, cv := range calculateList {
- //关联关系
- calculateMappingItem := new(EdbInfoCalculateMapping)
- calculateMappingItem.CreateTime = time.Now()
- calculateMappingItem.ModifyTime = time.Now()
- calculateMappingItem.Sort = 1
- calculateMappingItem.EdbCode = v.EdbCode
- calculateMappingItem.EdbInfoId = v.EdbInfoId
- calculateMappingItem.FromEdbInfoId = cv.FromEdbInfoId
- calculateMappingItem.FromEdbCode = cv.FromEdbCode
- calculateMappingItem.FromEdbName = cv.FromEdbName
- calculateMappingItem.FromSource = cv.FromSource
- calculateMappingItem.FromSourceName = cv.FromSourceName
- calculateMappingItem.FromTag = cv.FromTag
- calculateMappingItem.Source = v.Source
- calculateMappingItem.SourceName = v.SourceName
- tx.Insert(calculateMappingItem)
- }
- }
- }
- type EdbInfoCalculateMappingView struct {
- EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
- EdbInfoId int `description:"计算指标id"`
- Source int `description:"计算指标来源"`
- SourceName string `description:"计算指标来源名称"`
- EdbCode string `description:"计算指标编码"`
- FromEdbInfoId int `description:"基础指标id"`
- FromEdbCode string `description:"基础指标编码"`
- FromEdbName string `description:"基础指标名称"`
- FromSource int `description:"基础指标来源"`
- FromSourceName string `description:"基础指标来源名称"`
- FromTag string `description:"来源指标标签"`
- Sort int `description:"计算指标名称排序"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- CalculateFormula string `description:"N值"`
- MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
- MoveFrequency string `description:"移动频度"`
- }
- func GetEdbInfoCalculateMappingDetail(edbInfoId int) (item *EdbInfoCalculateMappingView, err error) {
- o := orm.NewOrm()
- sql := ` SELECT a.*,b.start_date,b.end_date,b.calculate_formula,b.move_type,b.move_frequency FROM edb_info_calculate_mapping AS a
- INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
- WHERE a.edb_info_id=? `
- err = o.Raw(sql, edbInfoId).QueryRow(&item)
- return
- }
- // GetAllCalculateEdbIdsByEdbInfoIds 所依赖计算指标
- func GetAllCalculateEdbIdsByEdbInfoIds(edbInfoIds []int) (edbIds []int, err error) {
- o := orm.NewOrmUsingDB("data")
- msql := ` SELECT edb_info_id FROM edb_info_calculate_mapping WHERE from_edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) GROUP BY edb_info_id `
- _, err = o.Raw(msql, edbInfoIds).QueryRows(&edbIds)
- if err != nil {
- return
- }
- return
- }
- // EdbInfoCalculateMappingInfo
- // @Description: 计算指标与基础指标关系表
- type EdbInfoCalculateMappingInfo struct {
- EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
- EdbInfoId int `description:"计算指标id"`
- Source int `description:"计算指标来源"`
- SourceName string `description:"计算指标来源名称"`
- EdbCode string `description:"计算指标编码"`
- FromEdbInfoId int `description:"基础指标id"`
- FromEdbCode string `description:"基础指标编码"`
- FromEdbName string `description:"基础指标名称"`
- FromSource int `description:"基础指标来源"`
- FromSourceName string `description:"基础指标来源名称"`
- MoveValue int `description:"领先值"`
- FromTag string `description:"来源指标标签"`
- Sort int `description:"计算指标名称排序"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- FromEdbType int `description:"来源指标类型:1:基础指标,2:计算指标"`
- FromEdbInfoType int `description:"来源指标类型: 0-基础指标; 1-预测指标"`
- FromClassifyId int `description:"来源指标分类ID"`
- FromUniqueCode string `description:"来源指标唯一编码"`
- NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
- }
- // GetEdbInfoCalculateMappingListByEdbInfoId 根据生成的指标id获取来源的指标id列表
- func GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId int) (items []*EdbInfoCalculateMappingInfo, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT a.*,b.edb_type as from_edb_type,b.edb_info_type as from_edb_info_type, b.unique_code AS from_unique_code, b.classify_id AS from_classify_id,b.no_update FROM edb_info_calculate_mapping AS a
- INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
- WHERE a.edb_info_id=? `
- _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
- return
- }
- // GetEdbInfoCalculateMappingListByEdbInfoIds 根据生成的指标id获取来源的指标id列表
- func GetEdbInfoCalculateMappingListByEdbInfoIds(edbInfoIds []int) (items []*EdbInfoCalculateMappingInfo, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT a.*,b.edb_type as from_edb_type,b.edb_info_type as from_edb_info_type, b.unique_code AS from_unique_code, b.classify_id AS from_classify_id,b.no_update FROM edb_info_calculate_mapping AS a
- INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
- WHERE a.edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
- _, err = o.Raw(sql, edbInfoIds).QueryRows(&items)
- return
- }
- func GetEdbInfoCalculateMappingCountByCondition(condition string, pars []interface{}) (total int64, err error) {
- o := orm.NewOrm()
- sql := ` SELECT count(*) FROM edb_info_calculate_mapping WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&total)
- return
- }
- func GetEdbInfoCalculateMappingPageByCondition(condition string, pars []interface{}, startPage, pageSize int) (item []*EdbInfoCalculateMapping, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM edb_info_calculate_mapping WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` LIMIT ?,? `
- _, err = o.Raw(sql, pars, startPage, pageSize).QueryRows(&item)
- return
- }
|