Selaa lähdekoodia

fix:指标库添加/删除手工指标时,标记状态

Roc 9 kuukautta sitten
vanhempi
commit
d915c20728
5 muutettua tiedostoa jossa 60 lisäystä ja 56 poistoa
  1. 0 42
      controllers/manual_edb.go
  2. 16 1
      models/manual_edb.go
  3. 1 0
      models/target.go
  4. 2 8
      services/data/edb_classify.go
  5. 41 5
      services/data/edb_info.go

+ 0 - 42
controllers/manual_edb.go

@@ -4,7 +4,6 @@ import (
 	"encoding/json"
 	"eta/eta_api/models"
 	"eta/eta_api/models/data_manage"
-	"eta/eta_api/models/system"
 	"eta/eta_api/utils"
 	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
@@ -85,12 +84,6 @@ func (this *TargetController) EdbDetail() {
 		}
 	}
 
-	// 录入的用户名称
-	adminInfo, err := system.GetSysAdminById(manualEdbInfo.UserId)
-	if err == nil {
-		manualEdbInfo.UserName = adminInfo.RealName
-	}
-
 	// 明细数据
 	{
 		dataList, err := models.GetEdbDataListByCode(manualEdbInfo.TradeCode)
@@ -389,41 +382,6 @@ func (this *TargetController) EdbList() {
 		return
 	}
 
-	edbCodeMap := make(map[string]bool)
-	listNum := len(list)
-	if listNum > 0 {
-		tradeCodeList := make([]string, 0)
-		for _, v := range list {
-			v.UniqueCode = utils.MD5(v.TradeCode)
-			tradeCodeList = append(tradeCodeList, v.TradeCode)
-		}
-
-		// 查找是否加入到指标库
-		{
-			var edbCondition string
-			var edbPars []interface{}
-			edbCondition = ` AND source = ? AND edb_code in (` + utils.GetOrmInReplace(listNum) + `) `
-			edbPars = append(edbPars, utils.DATA_SOURCE_MANUAL, tradeCodeList)
-
-			edbInfoList, err := data_manage.GetEdbInfoListByCond(edbCondition, edbPars)
-			if err != nil {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取失败,Err:" + err.Error()
-				return
-			}
-			for _, v := range edbInfoList {
-				edbCodeMap[v.EdbCode] = true
-			}
-		}
-
-		for _, v := range list {
-			// 如果能通过指标编码下标找到,那么说明是加到指标库中
-			if _, ok := edbCodeMap[v.TradeCode]; ok {
-				v.EdbExist = 1
-			}
-		}
-	}
-
 	resp := models.EdbListResp{
 		List:   list,
 		Paging: paging.GetPaging(currentIndex, pageSize, total),

+ 16 - 1
models/manual_edb.go

@@ -79,7 +79,8 @@ type EdbInfoListItem struct {
 	ModifyDate   string `description:"待更新日期"`
 	Status       string `description:"状态:未完成/完成"`
 	UniqueCode   string
-	EdbExist     int `description:"指标库是否已添加:0-否;1-是"`
+	IsJoinEdb    int8   `description:"指标库是否已添加:0-否;1-是"`
+	UserName     string `description:"录入用户名称"`
 }
 
 // EdbListResp 指标数据结构体
@@ -166,3 +167,17 @@ func DelEdbdataByCodeAndDateList(tradeCode string, dateList []string) (err error
 
 	return
 }
+
+// UpdateManualIsJoinEdbStatus
+// @Description: 根据手工数据加入指标的状态
+// @author: Roc
+// @datetime 2024-07-22 11:29:13
+// @param edbCode string
+// @param isJoinEdb int 是否加入指标库
+// @return err error
+func UpdateManualIsJoinEdbStatus(edbCode string, isJoinEdb int8) (err error) {
+	o := orm.NewOrmUsingDB("edb")
+	sql := ` UPDATE edbinfo SET is_join_edb = ? WHERE TRADE_CODE =? `
+	_, err = o.Raw(sql, isJoinEdb, edbCode).Exec()
+	return
+}

+ 1 - 0
models/target.go

@@ -150,6 +150,7 @@ type Edbinfo struct {
 	NoticeTime string `description:"通知时间"`
 	Mobile     string `description:"录入者手机号"`
 	ModifyTime string `description:"最近一次更新时间"`
+	IsJoinEdb  int8   `description:"指标库是否已添加:0-否;1-是"`
 }
 
 func GetEdbinfoListCount(condition string, pars []interface{}, mobile string, roleType int) (count int, err error) {

+ 2 - 8
services/data/edb_classify.go

@@ -7,7 +7,6 @@ import (
 	"eta/eta_api/models/data_manage/cross_variety"
 	"eta/eta_api/models/data_manage/excel"
 	"eta/eta_api/models/system"
-	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/services/data/data_manage_permission"
 	"eta/eta_api/services/data_stat"
 	"eta/eta_api/utils"
@@ -906,13 +905,8 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 
 		go data_stat.AddEdbDeleteLog(edbInfo, sysUser)
 
-		// 如果删除的指标是自定义分析的来源,那么还需要删除指标与excel的关系
-		if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_ZDYFX {
-			tmpErr = excel.DeleteCustomAnalysisExcelEdbMappingByEdbInfoId(edbInfo.EdbInfoId)
-			if tmpErr != nil {
-				alarm_msg.SendAlarmMsg(fmt.Sprintf("删除指标时,需要删除与自定义分析的关系失败,指标ID:%d,Err:%s", edbInfo.EdbInfoId, tmpErr.Error()), 3)
-			}
-		}
+		// 删除指标后的操作
+		go handleByDelEdbInfo(edbInfo)
 
 		// 返回下一个表格的信息
 		{

+ 41 - 5
services/data/edb_info.go

@@ -6,6 +6,7 @@ import (
 	"eta/eta_api/cache"
 	"eta/eta_api/models"
 	"eta/eta_api/models/data_manage"
+	"eta/eta_api/models/data_manage/excel"
 	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/services/data/data_manage_permission"
 	"eta/eta_api/services/elastic"
@@ -1909,11 +1910,7 @@ func EdbInfoAdd(source, subSource, classifyId int, edbCode, edbName, frequency,
 	//添加es
 	AddOrEditEdbInfoToEs(int(edbInfoId))
 
-	// 更新钢联化工状态为启用
-	if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
-		// 启动钢联的刷新
-		_ = data_manage.UpdateMysteelChemicalRefreshStatus(edbCode, 0)
-	}
+	go handleByAddEdbInfo(edbInfo)
 
 	return
 }
@@ -2924,3 +2921,42 @@ func GetEdbTerminalCodeBySource(source int, edbCode, stockCode string) (terminal
 	}
 	return
 }
+
+// handleByAddEdbInfo
+// @Description: 添加指标后的处理操作
+// @author: Roc
+// @datetime 2024-07-22 13:06:36
+// @param edbInfo *data_manage.EdbInfo
+func handleByAddEdbInfo(edbInfo *data_manage.EdbInfo) {
+	// 更新钢联化工状态为启用
+	if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
+		// 启动钢联的刷新
+		_ = data_manage.UpdateMysteelChemicalRefreshStatus(edbInfo.EdbCode, 0)
+	}
+
+	// 如果是手工数据,那么需要标记手工数据为已加入指标库
+	if edbInfo.Source == utils.DATA_SOURCE_MANUAL {
+		_ = models.UpdateManualIsJoinEdbStatus(edbInfo.EdbCode, 1)
+	}
+
+}
+
+// handleByDelEdbInfo
+// @Description: 删除指标后的处理操作
+// @author: Roc
+// @datetime 2024-07-22 13:06:36
+// @param edbInfo *data_manage.EdbInfo
+func handleByDelEdbInfo(edbInfo *data_manage.EdbInfo) {
+	// 如果删除的指标是自定义分析的来源,那么还需要删除指标与excel的关系
+	if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_ZDYFX {
+		err := excel.DeleteCustomAnalysisExcelEdbMappingByEdbInfoId(edbInfo.EdbInfoId)
+		if err != nil {
+			utils.FileLog.Error(fmt.Sprintf("删除指标时,需要删除与自定义分析的关系失败,指标ID:%d,Err:%s", edbInfo.EdbInfoId, err.Error()), 3)
+		}
+	}
+
+	// 如果是手工数据,那么需要标记手工数据为未加入指标库
+	if edbInfo.Source == utils.DATA_SOURCE_MANUAL {
+		_ = models.UpdateManualIsJoinEdbStatus(edbInfo.EdbCode, 0)
+	}
+}