Browse Source

Merge branch 'feature/eta_1.9.3' into debug

hsun 9 months ago
parent
commit
070046fa8f
4 changed files with 40 additions and 8 deletions
  1. 23 6
      controllers/base_from_ths_hf.go
  2. 1 1
      models/base_from_ths_hf_data.go
  3. 1 1
      models/edb_data_ths_hf.go
  4. 15 0
      utils/common.go

+ 23 - 6
controllers/base_from_ths_hf.go

@@ -281,9 +281,6 @@ func (this *ThsHfController) BaseAdd() {
 	indexItem.EndDate = endTime
 	indexItem.SysUserId = params.SysAdminId
 	indexItem.SysUserRealName = params.SysAdminName
-	if params.EndTime == "" {
-		indexItem.EndDate = time.Now().Local()
-	}
 	terminal, e := services.GetFirstTerminal(utils.DATA_SOURCE_THS, "")
 	if e != nil {
 		br.Msg = "终端未配置"
@@ -301,7 +298,15 @@ func (this *ThsHfController) BaseAdd() {
 	}
 	indexItem.ApiPars = string(b)
 	if len(indexWithData.IndexData) > 0 {
-		indexItem.LatestValue = indexWithData.IndexData[0].Value
+		indexItem.StartDate = indexWithData.IndexData[0].DataTime
+		indexItem.EndDate = indexWithData.IndexData[len(indexWithData.IndexData)-1].DataTime
+		lastVal, e := utils.FormatFloatPlaces(indexWithData.IndexData[0].Value, 4)
+		if e != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = fmt.Sprintf("格式化最新值失败, val: %v, err: %v", indexWithData.IndexData[0].Value, e)
+			return
+		}
+		indexItem.LatestValue = lastVal
 	}
 	indexItem.CreateTime = time.Now().Local()
 	indexItem.ModifyTime = time.Now().Local()
@@ -317,11 +322,17 @@ func (this *ThsHfController) BaseAdd() {
 	if utils.UseMongo {
 		dataList := make([]interface{}, 0)
 		for _, v := range indexWithData.IndexData {
+			newVal, e := utils.FormatFloatPlaces(v.Value, 4)
+			if e != nil {
+				utils.FileLog.Info(fmt.Sprintf("FormatFloatPlaces err: %v", e))
+				continue
+			}
+
 			dataList = append(dataList, &mgo.BaseFromThsHfData{
 				BaseFromThsHfIndexId: int64(indexItem.BaseFromThsHfIndexId),
 				IndexCode:            indexItem.IndexCode,
 				DataTime:             v.DataTime,
-				Value:                v.Value,
+				Value:                newVal,
 				UniqueCode:           utils.MD5(fmt.Sprint(indexItem.IndexCode, v.DataTime.Format(utils.FormatDateTimeMinute))),
 				CreateTime:           time.Now().Local(),
 				ModifyTime:           time.Now().Local(),
@@ -338,11 +349,17 @@ func (this *ThsHfController) BaseAdd() {
 		dataOb := new(models.BaseFromThsHfData)
 		itemData := make([]*models.BaseFromThsHfData, 0)
 		for _, v := range indexWithData.IndexData {
+			newVal, e := utils.FormatFloatPlaces(v.Value, 4)
+			if e != nil {
+				utils.FileLog.Info(fmt.Sprintf("FormatFloatPlaces err: %v", e))
+				continue
+			}
+
 			t := new(models.BaseFromThsHfData)
 			t.BaseFromThsHfIndexId = indexItem.BaseFromThsHfIndexId
 			t.IndexCode = indexItem.IndexCode
 			t.DataTime = v.DataTime
-			t.Value = v.Value
+			t.Value = newVal
 			t.UniqueCode = utils.MD5(fmt.Sprint(indexItem.IndexCode, v.DataTime.Format(utils.FormatDateTimeMinute)))
 			t.CreateTime = time.Now().Local()
 			t.ModifyTime = time.Now().Local()

+ 1 - 1
models/base_from_ths_hf_data.go

@@ -66,7 +66,7 @@ func (m *BaseFromThsHfData) CreateMulti(items []*BaseFromThsHfData) (err error)
 		return
 	}
 	o := orm.NewOrm()
-	_, err = o.InsertMulti(len(items), items)
+	_, err = o.InsertMulti(500, items)
 	return
 }
 

+ 1 - 1
models/edb_data_ths_hf.go

@@ -63,7 +63,7 @@ func (m *EdbDataThsHf) CreateMulti(items []*EdbDataThsHf) (err error) {
 		return
 	}
 	o := orm.NewOrm()
-	_, err = o.InsertMulti(200, items)
+	_, err = o.InsertMulti(500, items)
 	return
 }
 

+ 15 - 0
utils/common.go

@@ -1310,3 +1310,18 @@ func InsertStr2StrIdx(str, sep string, idx int, value string) string {
 	slice = append(slice[:idx], append([]string{value}, slice[idx:]...)...)
 	return strings.Join(slice, sep)
 }
+
+// FormatFloatPlaces 格式化浮点数位数
+func FormatFloatPlaces(val float64, places int32) (newVal float64, err error) {
+	if places <= 0 {
+		places = 4
+	}
+	strNewVal := decimal.NewFromFloat(val).Round(places).String()
+	di, e := decimal.NewFromString(strNewVal)
+	if e != nil {
+		err = fmt.Errorf("NewFromString err: %v", e)
+		return
+	}
+	newVal, _ = di.Float64()
+	return
+}