|
@@ -2,10 +2,12 @@ package data_manage
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
+ "eta/eta_api/models/mgo"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -380,8 +382,40 @@ type EdbDataList struct {
|
|
|
Value float64 `description:"数据值"`
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func GetEdbDataList(source, subSource, endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func GetEdbDataList(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
|
|
|
+
|
|
|
+
|
|
|
+ if source == utils.DATA_SOURCE_BUSINESS {
|
|
|
+ return getEdbDataListByMongo(source, subSource, edbInfoId, startDate, endDate)
|
|
|
+ }
|
|
|
+
|
|
|
+ return getEdbDataListByMysql(source, subSource, edbInfoId, startDate, endDate)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func getEdbDataListByMysql(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
if tableName == "" {
|
|
|
err = errors.New("无效的渠道:" + strconv.Itoa(source))
|
|
@@ -402,7 +436,64 @@ func GetEdbDataList(source, subSource, endInfoId int, startDate, endDate string)
|
|
|
sql += ` ORDER BY data_time ASC `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
|
|
|
+ _, err = o.Raw(sql, edbInfoId, pars).QueryRows(&list)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func getEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
|
|
|
+ list = make([]*EdbDataList, 0)
|
|
|
+
|
|
|
+ mogDataObj := mgo.EdbDataBusiness{}
|
|
|
+
|
|
|
+ queryConditions := bson.M{
|
|
|
+ "edb_info_id": edbInfoId,
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if startDate != `` {
|
|
|
+ startDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ queryConditions["data_time"] = bson.M{"$gte": startDateTime}
|
|
|
+ }
|
|
|
+
|
|
|
+ if endDate != "" {
|
|
|
+ endDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ queryConditions["data_time"] = bson.M{"$lte": endDateTime}
|
|
|
+ }
|
|
|
+
|
|
|
+ tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for k, v := range tmpDataList {
|
|
|
+ list = append(list, &EdbDataList{
|
|
|
+ EdbDataId: k + 1,
|
|
|
+ EdbInfoId: v.EdbInfoId,
|
|
|
+ DataTime: v.DataTime.Format(utils.FormatDate),
|
|
|
+ DataTimestamp: v.DataTimestamp,
|
|
|
+ Value: v.Value,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|