|
@@ -3,10 +3,12 @@ package models
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
+ "eta/eta_index_lib/models/mgo"
|
|
|
"eta/eta_index_lib/utils"
|
|
|
"fmt"
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
"github.com/shopspring/decimal"
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
@@ -180,10 +182,12 @@ func (edbInfo *EdbInfo) Update(cols []string) (err error) {
|
|
|
|
|
|
// EdbInfoSearchData
|
|
|
type EdbInfoSearchData struct {
|
|
|
- EdbDataId int `description:"数据ID"`
|
|
|
- DataTime string `description:"数据日期"`
|
|
|
- Value float64 `description:"数据"`
|
|
|
- EdbCode string `description:"指标编码"`
|
|
|
+ EdbDataId int `description:"数据ID"`
|
|
|
+ EdbInfoId int `description:"指标ID"`
|
|
|
+ DataTime string `description:"数据日期"`
|
|
|
+ Value float64 `description:"数据"`
|
|
|
+ EdbCode string `description:"指标编码"`
|
|
|
+ DataTimestamp int64 `description:"时间戳"`
|
|
|
}
|
|
|
|
|
|
// GetEdbDataListAll 获取指标数据列表 order:1升序,其余值为降序
|
|
@@ -207,12 +211,48 @@ func GetEdbDataListAll(condition string, pars []interface{}, source, subSource,
|
|
|
}
|
|
|
|
|
|
// GetEdbDataListAllByTo 根据事务链接获取指标数据列表 order:1升序,其余值为降序
|
|
|
-func GetEdbDataListAllByTo(to orm.TxOrmer, condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
+func GetEdbDataListAllByTo(to orm.TxOrmer, source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
+ if source == utils.DATA_SOURCE_BUSINESS {
|
|
|
+ return GetEdbDataListAllByMongo(source, subSource, findEdbDataListAllCond, order)
|
|
|
+ }
|
|
|
+
|
|
|
+ return GetEdbDataListAllByMysqlTo(to, source, subSource, findEdbDataListAllCond, order)
|
|
|
+}
|
|
|
+
|
|
|
+type FindEdbDataListAllCond struct {
|
|
|
+ EdbInfoId int
|
|
|
+ StartDataTime string
|
|
|
+ StartDataTimeCond string
|
|
|
+ EndDataTime string
|
|
|
+ EndDataTimeCond string
|
|
|
+}
|
|
|
+
|
|
|
+// GetEdbDataListAllByTo 根据事务链接获取指标数据列表 order:1升序,其余值为降序
|
|
|
+func GetEdbDataListAllByMysqlTo(to orm.TxOrmer, source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
+ if findEdbDataListAllCond.EdbInfoId <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition += " AND edb_info_id=? "
|
|
|
+ pars = append(pars, findEdbDataListAllCond.EdbInfoId)
|
|
|
+
|
|
|
+ // 开始日期
|
|
|
+ if findEdbDataListAllCond.StartDataTime != "" && findEdbDataListAllCond.StartDataTimeCond != `` {
|
|
|
+ condition += fmt.Sprintf(" AND data_time %s ? ", findEdbDataListAllCond.StartDataTimeCond)
|
|
|
+ pars = append(pars, findEdbDataListAllCond.StartDataTime)
|
|
|
+ }
|
|
|
+ // 结束日期
|
|
|
+ if findEdbDataListAllCond.EndDataTime != "" && findEdbDataListAllCond.EndDataTimeCond != `` {
|
|
|
+ condition += fmt.Sprintf(" AND data_time %s ? ", findEdbDataListAllCond.EndDataTimeCond)
|
|
|
+ pars = append(pars, findEdbDataListAllCond.EndDataTime)
|
|
|
+ }
|
|
|
+
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
@@ -225,6 +265,69 @@ func GetEdbDataListAllByTo(to orm.TxOrmer, condition string, pars []interface{},
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// GetEdbDataListAllByTo 根据事务链接获取指标数据列表 order:1升序,其余值为降序
|
|
|
+func GetEdbDataListAllByMongo(source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (dataList []*EdbInfoSearchData, err error) {
|
|
|
+ dataList = make([]*EdbInfoSearchData, 0)
|
|
|
+ if findEdbDataListAllCond.EdbInfoId <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mogDataObj := mgo.EdbDataBusiness{}
|
|
|
+ // 构建查询条件
|
|
|
+ queryConditions := bson.M{
|
|
|
+ "edb_info_id": findEdbDataListAllCond.EdbInfoId,
|
|
|
+ }
|
|
|
+ // 开始日期
|
|
|
+ if findEdbDataListAllCond.StartDataTime != "" {
|
|
|
+ startDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, findEdbDataListAllCond.StartDataTime, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 日期比较符
|
|
|
+ cond := utils.DateConvMysqlConvMongo(findEdbDataListAllCond.StartDataTimeCond)
|
|
|
+ if cond != `` {
|
|
|
+ queryConditions["data_time"] = bson.M{cond: startDateTime}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 结束日期
|
|
|
+ if findEdbDataListAllCond.EndDataTime != "" {
|
|
|
+ endDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, findEdbDataListAllCond.EndDataTime, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 日期比较符
|
|
|
+ cond := utils.DateConvMysqlConvMongo(findEdbDataListAllCond.EndDataTimeCond)
|
|
|
+ if cond != `` {
|
|
|
+ queryConditions["data_time"] = bson.M{cond: endDateTime}
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sortList := make([]string, 0)
|
|
|
+ if order == 1 {
|
|
|
+ sortList = append(sortList, "-data_time")
|
|
|
+ } else {
|
|
|
+ sortList = append(sortList, "data_time")
|
|
|
+ }
|
|
|
+ // 获取列表数据
|
|
|
+ tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, sortList)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for k, v := range tmpDataList {
|
|
|
+ dataList = append(dataList, &EdbInfoSearchData{
|
|
|
+ EdbDataId: k + 1,
|
|
|
+ EdbCode: v.EdbCode,
|
|
|
+ DataTime: v.DataTime.Format(utils.FormatDate),
|
|
|
+ Value: v.Value,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// EdbInfoMaxAndMinInfo 指标最新数据记录结构体
|
|
|
type EdbInfoMaxAndMinInfo struct {
|
|
|
MinDate string `description:"最小日期" bson:"min_date"`
|