ソースを参照

Merge branch 'eta_2.2.5_rzd_1012@guomengyuan'

# Conflicts:
#	utils/constants.go
gmy 4 週間 前
コミット
92e4b7e430
2 ファイル変更49 行追加1 行削除
  1. 41 1
      controllers/base_from_rzd.go
  2. 8 0
      models/edb_data_rzd.go

+ 41 - 1
controllers/base_from_rzd.go

@@ -76,7 +76,7 @@ func (this *BaseFromRzdController) Refresh() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	source := utils.DATA_SOURCE_LY
+	source := utils.DATA_SOURCE_RZD
 	var req models.RefreshEdbInfoReq
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
@@ -262,6 +262,32 @@ func (this *BaseFromRzdController) AddBatchRzdData() {
 		br.ErrMsg = "新增指标数据失败,Err:" + err.Error()
 		return
 	}
+	// 同步新增指标库数据
+	// 判断是否存在于指标库
+	// 获取指标详情
+	var dataList []models.EdbDataRzd
+	for _, data := range req {
+		edbInfo, err := models.GetEdbInfoByEdbCode(utils.DATA_SOURCE_RZD, data.IndexCode)
+		if err != nil {
+			br.Msg = "指标不存在!"
+			br.ErrMsg = "指标不存在"
+			return
+		}
+		if edbInfo.EdbInfoId == 0 {
+			continue
+		}
+		dataRzd := models.EdbDataRzd{
+			EdbInfoId:     data.BaseFromRzdIndexId,
+			DataTime:      data.DataTime,
+			Value:         data.Value,
+			EdbCode:       data.IndexCode,
+			CreateTime:    utils.GetCurrentTime(),
+			ModifyTime:    utils.GetCurrentTime(),
+			DataTimestamp: uint64(time.Now().UnixNano() / int64(time.Millisecond)),
+		}
+		dataList = append(dataList, dataRzd)
+	}
+	_ = models.AddRzdEdbDataList(dataList)
 
 	br.Ret = 200
 	br.Success = true
@@ -662,6 +688,20 @@ func (this *BaseFromRzdController) UpdateRzdEdbData() {
 		return
 	}
 
+	// 同步更新指标库数据
+	edbInfo, err := models.GetEdbInfoByEdbCode(utils.DATA_SOURCE_RZD, req.IndexCode)
+	if err != nil {
+		br.Msg = "指标不存在!"
+		br.ErrMsg = "指标不存在"
+		return
+	}
+	if edbInfo.EdbInfoId > 0 {
+		err = models.UpdateRzdEdbDataByIndexCodeAndDataTime(req.BaseFromRzdIndexId, req.DataTime, req.Value)
+		if err != nil {
+			return
+		}
+	}
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "处理成功"

+ 8 - 0
models/edb_data_rzd.go

@@ -45,6 +45,14 @@ func UpdateRzdEdbDataById(id int, value float64) (err error) {
 	return
 }
 
+// UpdateRzdEdbDataByIndexCodeAndDataTime 根据指标编码和时间更新数据
+func UpdateRzdEdbDataByIndexCodeAndDataTime(indexCode int, dataTime string, value float64) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE edb_data_rzd SET value=? WHERE edb_info_id=? AND data_time=?`
+	_, err = o.Raw(sql, value, indexCode, dataTime).Exec()
+	return
+}
+
 // AddRzdEdbDataList 新增指标库数据
 func AddRzdEdbDataList(items []EdbDataRzd) (err error) {
 	o := orm.NewOrm()