|
@@ -861,3 +861,64 @@ func (obj EdbThsHf) HandleConfigInsertEdbDataByMongo(realDataMaxDate time.Time,
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+func (obj EdbThsHf) UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error) {
|
|
|
+ if utils.UseMongo {
|
|
|
+ edbInfoMaxAndMinInfo, tmpErr := obj.getEdbInfoMaxAndMinInfoByMongo(edbInfo.EdbCode)
|
|
|
+ // 如果正常获取到了,那就去修改指标的最大最小值
|
|
|
+ if tmpErr == nil && edbInfoMaxAndMinInfo != nil {
|
|
|
+ err = ModifyEdbInfoMaxAndMinInfo(edbInfo.EdbInfoId, edbInfoMaxAndMinInfo)
|
|
|
+ } else {
|
|
|
+ // 清空的目的是为了避免异常返回
|
|
|
+ err = nil
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ err, _ = UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (obj EdbThsHf) getEdbInfoMaxAndMinInfoByMongo(edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
|
|
|
+ mogDataObj := new(mgo.EdbDataThsHf)
|
|
|
+ pipeline := []bson.M{
|
|
|
+ {"$match": bson.M{"edb_code": edbCode}},
|
|
|
+ {"$group": bson.M{
|
|
|
+ "_id": nil,
|
|
|
+ "min_date": bson.M{"$min": "$data_time"},
|
|
|
+ "max_date": bson.M{"$max": "$data_time"},
|
|
|
+ "min_value": bson.M{"$min": "$value"},
|
|
|
+ "max_value": bson.M{"$max": "$value"},
|
|
|
+ }},
|
|
|
+ {"$project": bson.M{"_id": 0}}, // 可选,如果不需要_id字段
|
|
|
+ }
|
|
|
+ result, err := mogDataObj.GetEdbInfoMaxAndMinInfo(pipeline)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("EdbDataBusiness getEdbDataBusinessList Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if !result.MaxDate.IsZero() {
|
|
|
+ whereQuery := bson.M{"edb_code": edbCode, "data_time": result.MaxDate}
|
|
|
+ selectParam := bson.D{{"value", 1}, {"_id", 0}}
|
|
|
+ latestValue, tmpErr := mogDataObj.GetLatestValue(whereQuery, selectParam)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result.LatestValue = latestValue.Value
|
|
|
+ result.EndValue = latestValue.Value
|
|
|
+ }
|
|
|
+
|
|
|
+ item = &EdbInfoMaxAndMinInfo{
|
|
|
+ MinDate: result.MinDate.Format(utils.FormatDate),
|
|
|
+ MaxDate: result.MaxDate.Format(utils.FormatDate),
|
|
|
+ MinValue: result.MinValue,
|
|
|
+ MaxValue: result.MaxValue,
|
|
|
+ LatestValue: result.LatestValue,
|
|
|
+ LatestDate: result.LatestDate.Format(utils.FormatDate),
|
|
|
+ EndValue: result.EndValue,
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|