浏览代码

Merge branch 'hotfix/manual_save_1009' into debug

hsun 1 年之前
父节点
当前提交
6021e65162
共有 2 个文件被更改,包括 33 次插入11 次删除
  1. 23 9
      models/edb_info.go
  2. 10 2
      services/base_from_ths_http.go

+ 23 - 9
models/edb_info.go

@@ -238,6 +238,14 @@ func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err
 	return
 }
 
+// ModifyEdbTimeAndLastInfo 修改指标的最新数据信息(除上下限)
+func ModifyEdbTimeAndLastInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE edb_info SET start_date = ?, end_date = ?, is_update = 2,latest_date = ?, latest_value = ?, modify_time = NOW() WHERE edb_info_id = ?`
+	_, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MaxDate, item.LatestValue, edbInfoId).Exec()
+	return
+}
+
 // GetEdbDataCount 获取edb指标数据的数量; order:1升序,其余值为降序
 func GetEdbDataCount(condition string, pars []interface{}, source int) (count int, err error) {
 	o := orm.NewOrm()
@@ -373,10 +381,6 @@ func GetEdbInfoByCondition(condition string, pars []interface{}, order int) (ite
 
 // UnifiedModifyEdbInfoMaxAndMinInfo 统一修改指标的最大最小值
 func UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error, errMsg string) {
-	// ETA1.0.3改-如果指标有手动保存过, 那么就不更新指标的最大最小值
-	if edbInfo.ManualSave == 1 {
-		return
-	}
 	// 修改最大最小值
 	maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.EdbCode)
 	if err != nil {
@@ -391,11 +395,21 @@ func UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error, errMsg stri
 	}
 
 	if maxAndMinItem != nil {
-		err = ModifyEdbInfoMaxAndMinInfo(edbInfo.EdbInfoId, maxAndMinItem)
-		if err != nil {
-			errMsg = "刷新指标失败!"
-			err = errors.New("修改指标最大最小值失败,err:" + err.Error())
-			return
+		// ETA1.0.3改-如果指标有手动保存过, 那么就不更新指标的最大最小值
+		if edbInfo.ManualSave == 1 {
+			err = ModifyEdbTimeAndLastInfo(edbInfo.EdbInfoId, maxAndMinItem)
+			if err != nil {
+				errMsg = "刷新指标失败!"
+				err = errors.New("修改指标最新日期和数据失败,err:" + err.Error())
+				return
+			}
+		} else {
+			err = ModifyEdbInfoMaxAndMinInfo(edbInfo.EdbInfoId, maxAndMinItem)
+			if err != nil {
+				errMsg = "刷新指标失败!"
+				err = errors.New("修改指标最大最小值失败,err:" + err.Error())
+				return
+			}
 		}
 	}
 	// 修改关联的预测指标

+ 10 - 2
services/base_from_ths_http.go

@@ -186,8 +186,12 @@ func postCurl(urlStr string, dataMap map[string]interface{}, num int) (body []by
 	req.Header.Add("Content-Type", "application/json")
 	req.Header.Add("access_token", token)
 
-	res, _ := netHttp.DefaultClient.Do(req)
+	res, err := netHttp.DefaultClient.Do(req)
+	if err != nil {
+		return
+	}
 	defer res.Body.Close()
+
 	//解析resp并且存入关联表
 	body, err = io.ReadAll(res.Body)
 	if err != nil {
@@ -301,8 +305,12 @@ func getAccessToken() (tokenData TokenData, err error) {
 	req.Header.Add("Content-Type", "application/json")
 	req.Header.Add("refresh_token", utils.ThsRefreshToken)
 
-	res, _ := netHttp.DefaultClient.Do(req)
+	res, err := netHttp.DefaultClient.Do(req)
+	if err != nil {
+		return
+	}
 	defer res.Body.Close()
+
 	body, err := io.ReadAll(res.Body)
 	if err != nil {
 		err = errors.New("NewRequest Err:" + err.Error())