浏览代码

睿姿得数据保存

gmy 1 月之前
父节点
当前提交
a4e970c028
共有 3 个文件被更改,包括 50 次插入2 次删除
  1. 41 1
      controllers/base_from_rzd.go
  2. 8 0
      models/edb_data_rzd.go
  3. 1 1
      utils/constants.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()

+ 1 - 1
utils/constants.go

@@ -116,7 +116,7 @@ const (
 	DATA_SOURCE_LY                                   = 91 // 粮油商务网
 	DATA_SOURCE_TRADE_ANALYSIS                       = 92 // 持仓分析
 	DATA_SOURCE_HISUGAR                              = 93 // 泛糖科技 -> 93
-	DATA_SOURCE_RZD                                  = 97 // 睿咨得科技 -> 93
+	DATA_SOURCE_RZD                                  = 97 // 睿咨得数据 -> 93
 )
 
 // 指标来源的中文展示