浏览代码

Merge branch 'debug' of http://8.136.199.33:3000/eta_server/eta_api into debug

xyxie 8 月之前
父节点
当前提交
d0f95badc3
共有 2 个文件被更改,包括 141 次插入20 次删除
  1. 68 20
      controllers/data_manage/base_from_ths_hf.go
  2. 73 0
      services/data/base_from_ths_hf.go

+ 68 - 20
controllers/data_manage/base_from_ths_hf.go

@@ -523,9 +523,6 @@ func (this *BaseFromThsHfController) Add() {
 			return
 		}
 	}
-	if params.EndTime == "" {
-		params.EndTime = time.Now().Local().Format(utils.FormatDateTime)
-	}
 	if !utils.InArrayByInt(data_manage.ThsHfPeriodArr, params.Interval) {
 		br.Msg = "时间周期有误"
 		br.ErrMsg = fmt.Sprintf("时间周期有误, Interval: %d", params.Interval)
@@ -883,19 +880,26 @@ func (this *BaseFromThsHfController) Refresh() {
 		return
 	}
 
-	//indexOb := new(data_manage.BaseFromThsHfIndex)
-	//item, e := indexOb.GetItemById(params.IndexId)
-	//if e != nil {
-	//	if e.Error() == utils.ErrNoRow() {
-	//		br.Msg = "指标不存在, 请刷新页面"
-	//		return
-	//	}
-	//	br.Msg = "操作失败"
-	//	br.ErrMsg = fmt.Sprintf("获取指标失败, %v", e)
-	//	return
-	//}
+	indexOb := new(data_manage.BaseFromThsHfIndex)
+	_, e := indexOb.GetItemById(params.IndexId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			br.Msg = "指标不存在, 请刷新页面"
+			return
+		}
+		br.Msg = "操作失败"
+		br.ErrMsg = fmt.Sprintf("获取指标失败, %v", e)
+		return
+	}
 
-	// TODO:指标刷新逻辑
+	// 指标刷新逻辑
+	indexIds := []int{params.IndexId}
+	_, e = data.RefreshBaseThsHfIndex(indexIds, 1)
+	if e != nil {
+		br.Msg = "刷新失败"
+		br.ErrMsg = fmt.Sprintf("刷新指标失败, %v", e)
+		return
+	}
 
 	br.Ret = 200
 	br.Success = true
@@ -950,7 +954,23 @@ func (this *BaseFromThsHfController) Remove() {
 		return
 	}
 
-	// TODO:删除校验, 生成了指标就不可删除
+	// 删除校验, 指标库存在不可删除
+	edbMappingOb := new(data_manage.BaseFromEdbMapping)
+	{
+		cond := fmt.Sprintf(" AND %s = ?", edbMappingOb.Cols().BaseIndexCode)
+		pars := make([]interface{}, 0)
+		pars = append(pars, item.IndexCode)
+		count, e := edbMappingOb.GetCountByCondition(cond, pars)
+		if e != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = fmt.Sprintf("获取源指标关联失败, %v", e)
+			return
+		}
+		if count > 0 {
+			br.Msg = "指标已被引用, 不允许删除"
+			return
+		}
+	}
 
 	// TODO:同步Mongo
 	if e = item.Remove(); e != nil {
@@ -1221,14 +1241,31 @@ func (this *BaseFromThsHfController) MultiOpt() {
 	}
 
 	// 批量删除
-	dataOb := new(data_manage.BaseFromThsHfData)
 	if params.OptType == 2 {
-		// TODO: 删除前的校验
+		// 校验是否被引用
+		edbMappingOb := new(data_manage.BaseFromEdbMapping)
+		{
+			cond := fmt.Sprintf(" AND %s IN (%s)", edbMappingOb.Cols().BaseFromIndexId, utils.GetOrmInReplace(len(params.IndexIds)))
+			pars := make([]interface{}, 0)
+			pars = append(pars, params.IndexIds)
+			count, e := edbMappingOb.GetCountByCondition(cond, pars)
+			if e != nil {
+				br.Msg = "删除失败"
+				br.ErrMsg = fmt.Sprintf("获取源指标关联失败, %v", e)
+				return
+			}
+			if count > 0 {
+				br.Msg = "存在指标被引用, 不允许删除"
+				return
+			}
+		}
+
 		if e := indexOb.MultiRemove(params.IndexIds); e != nil {
 			br.Msg = "删除失败"
 			br.ErrMsg = fmt.Sprintf("批量删除指标失败, %v", e)
 			return
 		}
+		dataOb := new(data_manage.BaseFromThsHfData)
 		cond := fmt.Sprintf(" %s IN (%s)", dataOb.Cols().BaseFromThsHfIndexId, utils.GetOrmInReplace(len(params.IndexIds)))
 		pars := make([]interface{}, 0)
 		pars = append(pars, params.IndexIds)
@@ -1239,9 +1276,20 @@ func (this *BaseFromThsHfController) MultiOpt() {
 		}
 	}
 
-	// TODO:批量刷新
+	// 批量刷新
 	if params.OptType == 3 {
-
+		isAsync, e := data.RefreshBaseThsHfIndex(params.IndexIds, params.RefreshType)
+		if e != nil {
+			br.Msg = "刷新失败"
+			br.ErrMsg = fmt.Sprintf("批量刷新指标失败, %v", e)
+			return
+		}
+		if isAsync {
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "操作成功, 刷新指标较多, 请10分钟后查看"
+			return
+		}
 	}
 
 	br.Ret = 200

+ 73 - 0
services/data/base_from_ths_hf.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"eta/eta_api/models"
 	"eta/eta_api/models/data_manage"
+	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/utils"
 	"fmt"
 )
@@ -123,3 +124,75 @@ func BaseAddThsHf(req data_manage.ThsHfBaseAddReq) (resp *models.BaseResponse, e
 	resp = res
 	return
 }
+
+// RefreshBaseThsHfIndex 刷新源指标
+func RefreshBaseThsHfIndex(indexIds []int, refreshType int) (isAsync bool, err error) {
+	if len(indexIds) == 0 {
+		return
+	}
+	defer func() {
+		if err != nil {
+			tips := fmt.Sprintf("RefreshBaseThsHfIndex-刷新同花顺高频指标失败, %v", err)
+			utils.FileLog.Info(tips)
+			go alarm_msg.SendAlarmMsg(tips, 3)
+		}
+	}()
+
+	indexes := make([]*data_manage.BaseFromThsHfIndex, 0)
+	{
+		ob := new(data_manage.BaseFromThsHfIndex)
+		cond := fmt.Sprintf(" AND %s IN (%s)", ob.Cols().PrimaryId, utils.GetOrmInReplace(len(indexIds)))
+		pars := make([]interface{}, 0)
+		pars = append(pars, indexIds)
+		list, e := ob.GetItemsByCondition(cond, pars, []string{}, "")
+		if e != nil {
+			err = fmt.Errorf("获取源指标失败, %v", e)
+			return
+		}
+		if len(list) == 0 {
+			return
+		}
+		indexes = list
+	}
+
+	refreshUrl := "ths/hf/base/refresh"
+	// 异步刷新
+	if len(indexes) > 10 {
+		isAsync = true
+
+		go func() {
+			for _, v := range indexes {
+				param := make(map[string]interface{})
+				param["BaseIndexCode"] = v.IndexCode
+				param["RefreshType"] = refreshType
+				resp, e := postRefreshEdbData(param, refreshUrl)
+				if e != nil {
+					utils.FileLog.Info(fmt.Sprintf("thsHf-postRefreshEdbData, code: %s, err: %v", v.IndexCode, e))
+					continue
+				}
+				if resp != nil && resp.Ret != 200 {
+					utils.FileLog.Info(fmt.Sprintf("thsHf-postRefreshEdbData, code: %s, Ret: %d, ErrMsg: %s", v.IndexCode, resp.Ret, resp.ErrMsg))
+					continue
+				}
+			}
+		}()
+		return
+	}
+
+	// 同步刷新
+	for _, v := range indexes {
+		param := make(map[string]interface{})
+		param["BaseIndexCode"] = v.IndexCode
+		param["RefreshType"] = refreshType
+		resp, e := postRefreshEdbData(param, refreshUrl)
+		if e != nil {
+			utils.FileLog.Info(fmt.Sprintf("thsHf-postRefreshEdbData, code: %s, err: %v", v.IndexCode, e))
+			continue
+		}
+		if resp.Ret != 200 {
+			utils.FileLog.Info(fmt.Sprintf("thsHf-postRefreshEdbData, code: %s, Ret: %d, ErrMsg: %s", v.IndexCode, resp.Ret, resp.ErrMsg))
+			continue
+		}
+	}
+	return
+}