浏览代码

Merge remote-tracking branch 'origin/eta/1.5.1' into debug

Roc 1 年之前
父节点
当前提交
bd5406d8aa

+ 106 - 5
controllers/data_manage/edb_info_refresh.go

@@ -271,6 +271,7 @@ func (c *EdbInfoController) RefreshEdbList() {
 	sysUserId := c.GetString("SysUserId")
 	frequency := c.GetString("Frequency")
 	keyword := c.GetString("Keyword")
+	status := c.GetString("Status")
 
 	pageSize, _ := c.GetInt("PageSize")
 	currentIndex, _ := c.GetInt("CurrentIndex")
@@ -284,7 +285,7 @@ func (c *EdbInfoController) RefreshEdbList() {
 	}
 	startSize = utils.StartIndex(currentIndex, pageSize)
 
-	total, list, err := getList(source, subSource, classifyId, terminalCode, sysUserId, frequency, keyword, startSize, pageSize)
+	total, list, err := getList(source, subSource, classifyId, terminalCode, sysUserId, frequency, keyword, status, startSize, pageSize)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
@@ -489,7 +490,7 @@ func (c *EdbInfoController) SaveEdbRefreshConfig() {
 	// 指标id列表
 	if req.IsSelectAll {
 		// 如果是列表全选
-		_, edbList, err := getList(req.Source, req.SubSource, req.ClassifyId, req.TerminalCode, req.SysUserId, req.Frequency, req.Keyword, 0, 100000)
+		_, edbList, err := getList(req.Source, req.SubSource, req.ClassifyId, req.TerminalCode, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000)
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
@@ -576,6 +577,96 @@ func (c *EdbInfoController) SaveEdbRefreshConfig() {
 	br.Msg = "保存成功"
 }
 
+// SaveEdbRefreshStatus
+// @Title 单独设置指标刷新状态接口
+// @Description 单独设置指标刷新状态接口
+// @Param	request	body data_manage.SaveEdbRefreshStatusReq true "type json string"
+// @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
+// @router /edb_info/refresh/status/save [post]
+func (c *EdbInfoController) SaveEdbRefreshStatus() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+
+	var req request.SaveEdbRefreshStatusReq
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.Source <= 0 {
+		br.Msg = "来源不能为空"
+		br.IsSendEmail = false
+		return
+	}
+
+	edbIdList := make([]int, 0)
+	edbCodeList := make([]string, 0)
+	// 指标id列表
+	if req.IsSelectAll {
+		// 如果是列表全选
+		_, edbList, err := getList(req.Source, req.SubSource, req.ClassifyId, req.TerminalCode, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+
+		// 不配置的指标id
+		notIdMap := make(map[int]int, 0)
+		for _, v := range req.EdbSelectIdList {
+			notIdMap[v] = v
+		}
+
+		for _, v := range edbList {
+			_, ok := notIdMap[v.EdbInfoId]
+			// 在不配置的指标id列表内的话,那就过滤
+			if ok {
+				continue
+			}
+
+			// 加入到待配置的指标列表id
+			edbIdList = append(edbIdList, v.EdbInfoId)
+			edbCodeList = append(edbCodeList, v.IndexCode)
+		}
+	} else {
+		edbIdList = req.EdbSelectIdList
+	}
+
+	if len(edbIdList) <= 0 {
+		br.Msg = "指标不能为空"
+		br.IsSendEmail = false
+		return
+	}
+
+	isStop := 0
+	if req.ModifyStatus == `禁用` {
+		isStop = 1
+	}
+
+	switch req.Source {
+	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
+		err = data_manage.ModifyMysteelChemicalUpdateStatus(edbIdList, edbCodeList, isStop)
+	case utils.DATA_SOURCE_YS: // 有色
+		err = data_manage.ModifySmmUpdateStatus(edbIdList, edbCodeList, isStop)
+	default:
+		err = data_manage.ModifyEdbInfoUpdateStatus(edbIdList, isStop)
+	}
+	if err != nil {
+		br.Msg = `保存失败`
+		br.ErrMsg = "保存失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+}
+
 // getList
 // @Description: 获取指标列表
 // @author: Roc
@@ -592,12 +683,17 @@ func (c *EdbInfoController) SaveEdbRefreshConfig() {
 // @return total int
 // @return list []*data_manage.BaseEdbInfo
 // @return err error
-func getList(source, subSource, classifyId int, terminalCode, sysUserId, frequency, keyword string, startSize, pageSize int) (total int, list []*data_manage.BaseEdbInfo, err error) {
+func getList(source, subSource, classifyId int, terminalCode, sysUserId, frequency, keyword, status string, startSize, pageSize int) (total int, list []*data_manage.BaseEdbInfo, err error) {
 	var pars []interface{}
 	var condition string
 
 	list = make([]*data_manage.BaseEdbInfo, 0)
 
+	isStop := 0
+	if status == `禁用` {
+		isStop = 1
+	}
+
 	switch source {
 	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
 		if classifyId > 0 {
@@ -635,6 +731,8 @@ func getList(source, subSource, classifyId int, terminalCode, sysUserId, frequen
 				pars = utils.GetLikeKeywordPars(pars, keyword, 2)
 			}
 		}
+		condition += " AND is_stop = ? "
+		pars = append(pars, isStop)
 
 		total, list, err = data_manage.GetMysteelChemicalBaseInfo(condition, pars, startSize, pageSize)
 	case utils.DATA_SOURCE_YS: // 有色
@@ -669,10 +767,13 @@ func getList(source, subSource, classifyId int, terminalCode, sysUserId, frequen
 			}
 		}
 
+		condition += " AND is_stop = ? "
+		pars = append(pars, isStop)
+
 		total, list, err = data_manage.GetSmmBaseInfo(condition, pars, startSize, pageSize)
 	default:
-		condition += ` AND source = ? AND sub_source = ? `
-		pars = append(pars, source, subSource)
+		condition += ` AND source = ? AND sub_source = ? AND no_update = ?`
+		pars = append(pars, source, subSource, isStop)
 
 		if classifyId > 0 {
 			condition += " AND classify_id = ? "

+ 35 - 0
models/data_manage/edb_info.go

@@ -1758,3 +1758,38 @@ func GetEdbBaseInfo(condition string, pars []interface{}, startSize, pageSize in
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
+
+// ModifyEdbInfoUpdateStatus
+// @Description:  修改指标库停更状态
+// @author: Roc
+// @datetime 2024-01-08 16:23:31
+// @param edbIdList []int
+// @param indexCodeList []string
+// @param isStop int
+// @return err error
+func ModifyEdbInfoUpdateStatus(edbIdList []int, isStop int) (err error) {
+	idNum := len(edbIdList)
+	if idNum <= 0 {
+		return
+	}
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+			return
+		}
+		_ = o.Commit()
+	}()
+
+	// 更改指标的更新状态
+	sql := ` UPDATE edb_info SET no_update = ? WHERE  edb_info_id IN (` + utils.GetOrmInReplace(idNum) + `) `
+	_, err = o.Raw(sql, isStop, edbIdList).Exec()
+	if err != nil {
+		return
+	}
+
+	return
+}

+ 17 - 0
models/data_manage/edb_refresh/request/edb_info_refresh.go

@@ -29,7 +29,24 @@ type SaveEdbRefreshConfigReq struct {
 	SysUserId       string             `description:"操作人id"`
 	Frequency       string             `description:"频度"`
 	Keyword         string             `description:"关键字"`
+	Status          string             `description:"状态,枚举值:启用、暂停"`
 	IsSelectAll     bool               `description:"是否选择所有指标"`
 	EdbSelectIdList []int              `description:"选择的指标id列表"`
 	List            []RefreshConfigReq `description:"刷新配置项"`
 }
+
+// SaveEdbRefreshStatusReq
+// @Description: 设置指标的刷新状态
+type SaveEdbRefreshStatusReq struct {
+	Source          int    `description:"来源"`
+	SubSource       int    `description:"子来源"`
+	ClassifyId      int    `description:"分类id"`
+	TerminalCode    string `description:"终端编码"`
+	SysUserId       string `description:"操作人id"`
+	Frequency       string `description:"频度"`
+	Keyword         string `description:"关键字"`
+	Status          string `description:"状态,枚举值:启用、暂停"`
+	IsSelectAll     bool   `description:"是否选择所有指标"`
+	EdbSelectIdList []int  `description:"选择的指标id列表"`
+	ModifyStatus    string `description:"需要更改的状态,枚举值:启用、暂停"`
+}

+ 58 - 0
models/data_manage/mysteel_chemical_index.go

@@ -384,3 +384,61 @@ func GetMysteelChemicalBaseInfo(condition string, pars []interface{}, startSize,
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
+
+// ModifyMysteelChemicalUpdateStatus
+// @Description:  修改钢联化工数据停更状态
+// @author: Roc
+// @datetime 2024-01-08 16:23:31
+// @param edbIdList []int
+// @param indexCodeList []string
+// @param isStop int
+// @return err error
+func ModifyMysteelChemicalUpdateStatus(edbIdList []int, indexCodeList []string, isStop int) (err error) {
+	idNum := len(edbIdList)
+	if idNum <= 0 {
+		return
+	}
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+			return
+		}
+		_ = o.Commit()
+	}()
+
+	// 更改数据源的更新状态
+	sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = ? WHERE base_from_mysteel_chemical_index_id IN (` + utils.GetOrmInReplace(idNum) + `) `
+	_, err = o.Raw(sql, isStop, edbIdList).Exec()
+	if err != nil {
+		return
+	}
+
+	codeNum := len(indexCodeList)
+	if codeNum <= 0 {
+		// 需要通过指标id列表查找code列表
+		sql := ` SELECT index_code FROM base_from_mysteel_chemical_index WHERE base_from_mysteel_chemical_index_id IN (` + utils.GetOrmInReplace(idNum) + `) `
+		_, err = o.Raw(sql, edbIdList).QueryRows(&indexCodeList)
+		if err != nil {
+			return
+		}
+	}
+
+	codeNum = len(indexCodeList)
+	// 查出来的编码是空的话,那么就直接返回了
+	if codeNum <= 0 {
+		return
+	}
+
+	// 更改指标的更新状态
+	sql = ` UPDATE edb_info SET no_update = ? WHERE source = ? AND sub_source= ? AND edb_code IN (` + utils.GetOrmInReplace(codeNum) + `) `
+	_, err = o.Raw(sql, isStop, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, indexCodeList).Exec()
+	if err != nil {
+		return
+	}
+
+	return
+}

+ 58 - 0
models/data_manage/smm_data.go

@@ -254,3 +254,61 @@ func GetSmmBaseInfo(condition string, pars []interface{}, startSize, pageSize in
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
+
+// ModifySmmUpdateStatus
+// @Description:  修改有色数据停更状态
+// @author: Roc
+// @datetime 2024-01-08 16:23:31
+// @param edbIdList []int
+// @param indexCodeList []string
+// @param isStop int
+// @return err error
+func ModifySmmUpdateStatus(edbIdList []int, indexCodeList []string, isStop int) (err error) {
+	idNum := len(edbIdList)
+	if idNum <= 0 {
+		return
+	}
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+			return
+		}
+		_ = o.Commit()
+	}()
+
+	// 更改数据源的更新状态
+	sql := ` UPDATE base_from_smm_index SET is_stop = ? WHERE base_from_smm_index_id IN (` + utils.GetOrmInReplace(idNum) + `) `
+	_, err = o.Raw(sql, isStop, edbIdList).Exec()
+	if err != nil {
+		return
+	}
+
+	codeNum := len(indexCodeList)
+	if codeNum <= 0 {
+		// 需要通过指标id列表查找code列表
+		sql := ` SELECT index_code FROM base_from_smm_index WHERE base_from_smm_index_id IN (` + utils.GetOrmInReplace(idNum) + `) `
+		_, err = o.Raw(sql, edbIdList).QueryRows(&indexCodeList)
+		if err != nil {
+			return
+		}
+	}
+
+	codeNum = len(indexCodeList)
+	// 查出来的编码是空的话,那么就直接返回了
+	if codeNum <= 0 {
+		return
+	}
+
+	// 更改指标的更新状态
+	sql = ` UPDATE edb_info SET no_update = ? WHERE source = ? AND sub_source= ? AND edb_code IN (` + utils.GetOrmInReplace(codeNum) + `) `
+	_, err = o.Raw(sql, isStop, utils.DATA_SOURCE_YS, 0, indexCodeList).Exec()
+	if err != nil {
+		return
+	}
+
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -3004,6 +3004,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoController"],
+        beego.ControllerComments{
+            Method: "SaveEdbRefreshStatus",
+            Router: `/edb_info/refresh/status/save`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInfoController"],
         beego.ControllerComments{
             Method: "RelationChartList",