123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package data_manage
- import (
- "errors"
- "fmt"
- "hongze/hongze_task/utils"
- "rdluck_tools/orm"
- "strconv"
- "time"
- )
- type EdbInfoList struct {
- EdbInfoId int `orm:"column(edb_info_id);pk"`
- SourceName string `description:"来源名称"`
- Source int `description:"来源id"`
- EdbCode string `description:"指标编码"`
- EdbName string `description:"指标名称"`
- Frequency string `description:"频率"`
- Unit string `description:"单位"`
- StartDate time.Time `description:"起始日期"`
- EndDate time.Time `description:"终止日期"`
- ClassifyId int `description:"分类id"`
- UniqueCode string `description:"指标唯一编码"`
- }
- func GetEdbInfoByCondition(condition string, pars []interface{}) (item []*EdbInfoList, err error) {
- o := orm.NewOrm()
- o.Using("data")
- sql := ` SELECT * FROM edb_info WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- _,err = o.Raw(sql, pars).QueryRows(&item)
- return
- }
- func ModifyEdbDataInfoDate(edbInfoId int, maxDate string) (err error) {
- o := orm.NewOrm()
- o.Using("data")
- sql := ` UPDATE edb_info SET end_date=?,modify_time=NOW() WHERE edb_info_id=? `
- _, err = o.Raw(sql, maxDate, edbInfoId).Exec()
- return
- }
- type EdbInfoMaxAndMinInfo struct {
- MinDate string `description:"最小日期"`
- MaxDate string `description:"最大日期"`
- MinValue float64 `description:"最小值"`
- MaxValue float64 `description:"最大值"`
- }
- func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
- o := orm.NewOrm()
- o.Using("data")
- sql := ``
- tableName := ``
- if source == utils.DATA_SOURCE_THS {
- tableName = `edb_data_ths`
- } else if source == utils.DATA_SOURCE_WIND {
- tableName = `edb_data_wind`
- } else if source == utils.DATA_SOURCE_PB {
- tableName = `edb_data_pb`
- } else {
- errors.New("无效的渠道:" + strconv.Itoa(source))
- return
- }
- sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM %s WHERE edb_code=? `
- sql = fmt.Sprintf(sql, tableName)
- fmt.Println("sql:", sql)
- err = o.Raw(sql, edbCode).QueryRow(&item)
- return
- }
- func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
- o := orm.NewOrm()
- o.Using("data")
- sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,modify_time=NOW() WHERE edb_info_id=? `
- _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, edbInfoId).Exec()
- return
- }
|