Procházet zdrojové kódy

批量设置指标启用接口

xyxie před 4 měsíci
rodič
revize
0b90b0174c

+ 148 - 0
controllers/edb_refresh.go

@@ -0,0 +1,148 @@
+package controllers
+
+import (
+	"encoding/json"
+	"eta/eta_hub/models"
+	"eta/eta_hub/models/data_manage"
+	"eta/eta_hub/services/data"
+	"eta/eta_hub/utils"
+)
+
+// SaveRelationEdbRefreshStatus
+// @Title 批量设置被引用的指标刷新状态接口
+// @Description 批量设置被引用的指标刷新状态接口
+// @Param	request	body data_manage.SaveEdbRefreshStatusReq true "type json string"
+// @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
+// @router /refresh/set [post]
+func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+
+	var req data_manage.SaveRelationEdbRefreshStatusReq
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	condition := ``
+	pars := make([]interface{}, 0)
+
+	edbType := 1 //基础指标
+	switch req.Source {
+	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND: // wind
+		condition += ` AND source = ? `
+		pars = append(pars, req.Source)
+	case 0:
+		req.Source = 0
+		edbType = 2
+		condition += ` AND edb_type = ? AND edb_info_type = 0`
+		pars = append(pars, edbType)
+	default:
+		br.Msg = "暂不支持设置其他来源的指标"
+		return
+	}
+	edbIdList := make([]int, 0)
+	edbCodeList := make([]string, 0)
+	edbIdList = req.EdbSelectIdList
+	if len(edbIdList) <= 0 {
+		br.Msg = "指标不能为空"
+		return
+	}
+	condition += ` AND edb_info_id IN (` + utils.GetOrmInReplace(len(edbIdList)) + `) `
+	pars = append(pars, edbIdList)
+	//查询指标信息
+	edbObj := new(data_manage.EdbInfo)
+	edbList, e := edbObj.GetItemsByCondition(condition, pars, []string{}, "")
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据失败,Err:" + e.Error()
+		return
+	}
+
+	if len(edbList) == 0 {
+		br.Msg = "未查到对应的指标"
+		return
+	}
+
+	// 如果是钢联化工,那么需要过滤供应商暂停的指标
+	if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
+		// 获取未被供应商暂停的指标
+		tmpEdbCodeList := make([]string, 0)
+		for _, v := range edbList {
+			tmpEdbCodeList = append(tmpEdbCodeList, v.EdbCode)
+		}
+		notIsSupplierStopIndexList, e := data_manage.GetNotIsSupplierStopIndexByCodeList(tmpEdbCodeList, 0)
+		if e != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + e.Error()
+			return
+		}
+
+		// 未被供应商暂停的指标编码
+		notIsSupplierStopIndexCodeList := make([]string, 0)
+		for _, v := range notIsSupplierStopIndexList {
+			notIsSupplierStopIndexCodeList = append(notIsSupplierStopIndexCodeList, v.IndexCode)
+		}
+
+		//查询未被供应商暂停的指标信息
+		edbList, err = data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, notIsSupplierStopIndexCodeList)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+
+		if len(edbList) <= 0 {
+			br.Ret = 200
+			br.Msg = "保存成功"
+			return
+		}
+	}
+
+	fromEdbIdList := make([]int, 0)
+	for _, v := range edbList {
+		if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
+			edbCodeList = append(edbCodeList, v.EdbCode)
+		}
+		if v.EdbInfoType == 0 {
+			fromEdbIdList = append(fromEdbIdList, v.EdbInfoId)
+		}
+	}
+
+	isStop := 0
+	if req.ModifyStatus == `暂停` {
+		isStop = 1
+	}
+
+	// 查询计算指标ID
+	// 查询相关的计算指标
+	calculateEdbIdList := make([]int, 0)
+	if isStop == 1 {
+		hasFind := make(map[int]struct{})
+		calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo(fromEdbIdList, calculateEdbIdList, hasFind)
+		if err != nil {
+			br.Msg = "查询计算指标信息失败"
+			br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
+			return
+		}
+	}
+
+	switch req.Source {
+	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联化工
+		err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoIds(edbIdList, isStop, edbCodeList, calculateEdbIdList)
+	default:
+		err = data_manage.EdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop, calculateEdbIdList)
+	}
+	if err != nil {
+		br.Msg = `操作失败`
+		br.ErrMsg = "操作失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Msg = "操作成功"
+}

+ 93 - 0
models/data_manage/base_from_mysteel_chemical_index.go

@@ -0,0 +1,93 @@
+package data_manage
+
+import (
+	"eta/eta_hub/utils"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// BaseFromMysteelChemicalIndex 钢联化工指标表
+type BaseFromMysteelChemicalIndex struct {
+	BaseFromMysteelChemicalIndexId    int       `orm:"column(base_from_mysteel_chemical_index_id);pk"`
+	BaseFromMysteelChemicalClassifyId int       `orm:"column(base_from_mysteel_chemical_classify_id)" description:"钢联化工指标分类id"`
+	IndexCode                         string    `description:"指标编码"`
+	IndexName                         string    `description:"指标名称"`
+	Unit                              string    `description:"单位"`
+	Source                            string    `description:"数据来源"`
+	Frequency                         string    `description:"频度"`
+	StartDate                         string    `description:"开始日期"`
+	EndDate                           string    `description:"结束日期"`
+	Describe                          string    `description:"指标描述"`
+	UpdateWeek                        string    `description:"更新周期"`
+	UpdateTime                        string    `description:"更新时间1"`
+	UpdateTime2                       string    `description:"更新时间2"`
+	SysUserId                         int       `description:"创建人id"`
+	SysUserRealName                   string    `description:"创建人姓名"`
+	ModifyTime                        time.Time `description:"修改时间"`
+	CreateTime                        time.Time `description:"创建时间"`
+	Sort                              int       `description:"排序字段"`
+	MergeFilePath                     string    `description:"合并文件"`
+	TerminalCode                      string    `description:"终端编码"`
+	IsStop                            int       `description:"是否停更:1:停更,0:未停更"`
+	EndValue                          float64   `description:"指标的最新值"`
+	IsSupplierStop                    int       `description:"是否供应商停更:1:停更,0:未停更"`
+}
+
+// GetNotIsSupplierStopIndexByCodeList
+// @Description: 获取未被供应商停更的指标
+// @author: Roc
+// @datetime 2024-08-28 18:15:03
+// @param codeList []string
+// @param isStop int
+// @return items []*BaseFromMysteelChemicalIndex
+// @return err error
+func GetNotIsSupplierStopIndexByCodeList(codeList []string, isStop int) (items []*BaseFromMysteelChemicalIndex, err error) {
+	num := len(codeList)
+	if num <= 0 {
+		return
+	}
+
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM base_from_mysteel_chemical_index WHERE is_supplier_stop = ? AND index_code in (` + utils.GetOrmInReplace(num) + `) `
+	_, err = o.Raw(sql, isStop, codeList).QueryRows(&items)
+
+	return
+}
+
+func ModifyMysteelChemicalUpdateStatusByEdbInfoIds(edbInfoIds []int, isStop int, edbCodes []string, calculateEdbInfoIds []int) (err error) {
+	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 index_code IN (` + utils.GetOrmInReplace(len(edbCodes)) + `) `
+	_, err = o.Raw(sql, isStop, edbCodes).Exec()
+	if err != nil {
+		return
+	}
+
+	// 更改指标的更新状态
+	sql = ` UPDATE edb_info SET no_update = ? WHERE source = ? AND edb_info_id IN (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
+	_, err = o.Raw(sql, isStop, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, edbInfoIds).Exec()
+	if err != nil {
+		return
+	}
+	if len(calculateEdbInfoIds) > 0 {
+		// 批量更新相关联的指标ID
+		sql = ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
+		_, err = o.Raw(sql, isStop, calculateEdbInfoIds).Exec()
+		if err != nil {
+			return
+		}
+	}
+
+	return
+}

+ 46 - 0
models/data_manage/edb_data_wind.go

@@ -0,0 +1,46 @@
+package data_manage
+
+import (
+	"eta/eta_hub/utils"
+	"github.com/beego/beego/v2/client/orm"
+)
+
+func EdbInfoUpdateStatusByEdbInfoId(edbInfoIds []int, isStop int, calculateEdbInfoIds []int) (err error) {
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+			return
+		}
+		_ = o.Commit()
+	}()
+
+	// 更改指标的更新状态
+	if len(edbInfoIds) == 1 {
+		sql := ` UPDATE edb_info SET no_update = ? WHERE edb_info_id=? `
+		_, err = o.Raw(sql, isStop, edbInfoIds[0]).Exec()
+		if err != nil {
+			return
+		}
+	} else {
+		sql := ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
+		_, err = o.Raw(sql, isStop, edbInfoIds).Exec()
+		if err != nil {
+			return
+		}
+	}
+
+	if len(calculateEdbInfoIds) > 0 {
+		// 批量更新相关联的指标ID
+		sql := ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
+		_, err = o.Raw(sql, isStop, calculateEdbInfoIds).Exec()
+		if err != nil {
+			return
+		}
+	}
+
+	return
+}

+ 12 - 0
models/data_manage/edb_info.go

@@ -210,3 +210,15 @@ func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
 	_, err = o.Raw(sql, edbInfoIdList).QueryRows(&items)
 	return
 }
+
+// GetEdbInfoByEdbCodeList 根据指标code集合获取指标列表
+func GetEdbInfoByEdbCodeList(source int, edbCodeList []string) (items []*EdbInfo, err error) {
+	num := len(edbCodeList)
+	if num <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code in (` + utils.GetOrmInReplace(num) + `) `
+	_, err = o.Raw(sql, source, edbCodeList).QueryRows(&items)
+	return
+}

+ 11 - 0
models/data_manage/edb_info_calculate_mapping.go

@@ -99,3 +99,14 @@ func GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId int) (items []*EdbInfoC
 	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
 	return
 }
+
+func GetRelationEdbInfoListMappingByCondition(condition string, pars []interface{}) (item []*ChartEdbInfoMapping, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT a.* FROM edb_info AS a 
+	JOIN edb_info_calculate_mapping AS b on a.edb_info_id = b.edb_info_id WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}

+ 59 - 0
models/data_manage/edb_info_refresh.go

@@ -0,0 +1,59 @@
+package data_manage
+
+// SaveRelationEdbRefreshStatusReq
+// @Description: 设置被引用的指标的刷新状态
+type SaveRelationEdbRefreshStatusReq struct {
+	Source int `description:"来源"`
+	/*ClassifyId      string `description:"分类id,支持多选,用英文,隔开"`
+	SysUserId       string `description:"操作人id,支持多选,用英文,隔开"`
+	Frequency       string `description:"频度,支持多选,用英文,隔开"`
+	Status          string `description:"状态,枚举值:启用、暂停"`
+	EdbInfoType     int    `description:"1计算指标,2预测指标"`
+	Keyword         string `description:"关键字"`
+	IsSelectAll     bool   `description:"是否选择所有指标"`*/
+	EdbSelectIdList []int  `description:"选择的指标id列表"`
+	ModifyStatus    string `description:"需要更改的状态,枚举值:启用、暂停"`
+}
+
+// 查询指标引用列表
+/*func GetEdbInfoRelationList(condition string, pars []interface{}, addFieldStr, joinTableStr, orderBy string, startSize, pageSize int) (total int, items []*BaseRelationEdbInfo, err error) {
+	o := orm.NewOrmUsingDB("data")
+	// 数量汇总
+	totalSql := ` SELECT count(1) FROM edb_info e LEFT JOIN (
+SELECT count(edb_info_id) as relation_num, edb_info_id, max(relation_time) as relation_time FROM edb_info_relation GROUP BY edb_info_id) r on e.edb_info_id=r.edb_info_id  `
+
+	if joinTableStr != "" {
+		totalSql += joinTableStr
+	}
+	totalSql += ` WHERE 1=1 `
+	if condition != "" {
+		totalSql += condition
+	}
+	err = o.Raw(totalSql, pars).QueryRow(&total)
+	if err != nil {
+		return
+	}
+
+	fieldStr := ` e.edb_info_id, e.classify_id,e.edb_code,e.edb_name,e.sys_user_id,e.sys_user_real_name,e.frequency,e.no_update as is_stop, r.relation_num, r.relation_time ` + addFieldStr
+	// 列表数据
+	sql := ` SELECT ` + fieldStr + ` from edb_info e LEFT JOIN (
+SELECT count(edb_info_id) as relation_num, edb_info_id, max(relation_time) as relation_time FROM edb_info_relation GROUP BY edb_info_id) r on e.edb_info_id=r.edb_info_id  `
+	if joinTableStr != "" {
+		sql += joinTableStr
+	}
+	sql += ` WHERE 1=1 `
+
+	if condition != "" {
+		sql += condition
+	}
+
+	if orderBy != "" {
+		sql += ` ORDER BY ` + orderBy
+	} else {
+		sql += ` ORDER BY edb_info_id ASC `
+	}
+	sql += `  LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+
+	return
+}*/

+ 9 - 0
routers/commentsRouter.go

@@ -205,6 +205,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:EdbInfoController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:EdbInfoController"],
+        beego.ControllerComments{
+            Method: "SaveRelationEdbRefreshStatus",
+            Router: `/refresh/set`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_hub/controllers:EnglishReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:EnglishReportController"],
         beego.ControllerComments{
             Method: "Approve",

+ 161 - 0
services/data/edb_refresh.go

@@ -0,0 +1,161 @@
+package data
+
+import (
+	"eta/eta_hub/models/data_manage"
+	"eta/eta_hub/utils"
+	"fmt"
+)
+
+/*// GetEdbRelationList 获取指标引用列表
+func GetEdbRelationList(source, edbType int, classifyId, sysUserId, frequency, keyword, status string, startSize, pageSize int, sortParam, sortType string) (total int, list []*data_manage.BaseRelationEdbInfo, err error) {
+	var pars []interface{}
+	var condition string
+
+	list = make([]*data_manage.BaseRelationEdbInfo, 0)
+
+	isStop := -1
+	switch status {
+	case `暂停`:
+		isStop = 1
+	case `启用`:
+		isStop = 0
+	case `供应商停用`:
+		isStop = 3
+	}
+
+	// 关联表语句
+	var addFieldStr, joinTableStr string
+
+	switch source {
+	case 0: // 计算指标,不校验source
+	default:
+		condition += ` AND e.source = ? `
+		pars = append(pars, source)
+	}
+
+	if edbType == 2 { //计算指标
+		condition += ` AND e.edb_type = ? AND e.edb_info_type = 0`
+		pars = append(pars, edbType)
+	}
+	switch isStop {
+	case -1:
+		// 供应商停用
+		if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
+			joinTableStr = ` LEFT JOIN base_from_mysteel_chemical_index z ON e.edb_code = z.index_code `
+			addFieldStr = ` ,z.is_supplier_stop `
+		}
+	case 0, 1:
+		condition += " AND e.no_update = ? "
+		pars = append(pars, isStop)
+
+		// 供应商停用
+		if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
+			condition += " AND z.is_supplier_stop = ? "
+			pars = append(pars, 0)
+			joinTableStr = ` LEFT JOIN base_from_mysteel_chemical_index z ON e.edb_code = z.index_code `
+			addFieldStr = ` ,z.is_supplier_stop `
+		}
+	case 3:
+		// 供应商停用
+		if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
+			condition += " AND z.is_supplier_stop = ? "
+			pars = append(pars, 1)
+			joinTableStr = ` LEFT JOIN base_from_mysteel_chemical_index z ON e.edb_code = z.index_code `
+			addFieldStr = ` ,z.is_supplier_stop `
+		}
+	}
+
+	if classifyId != `` {
+		classifyIdSlice := strings.Split(classifyId, ",")
+		condition += ` AND e.classify_id IN (` + utils.GetOrmInReplace(len(classifyIdSlice)) + `)`
+		pars = append(pars, classifyIdSlice)
+	}
+	if sysUserId != `` {
+		sysUserIdSlice := strings.Split(sysUserId, ",")
+		condition += ` AND e.sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)`
+		pars = append(pars, sysUserIdSlice)
+	}
+	if frequency != `` {
+		frequencySlice := strings.Split(frequency, ",")
+		condition += ` AND e.frequency IN (` + utils.GetOrmInReplace(len(frequencySlice)) + `)`
+		pars = append(pars, frequencySlice)
+	}
+	if keyword != `` {
+		keywordSlice := strings.Split(keyword, " ")
+		if len(keywordSlice) > 0 {
+			tmpConditionSlice := make([]string, 0)
+			tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
+			pars = utils.GetLikeKeywordPars(pars, keyword, 2)
+
+			for _, v := range keywordSlice {
+				if v == ` ` || v == `` {
+					continue
+				}
+				tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
+				pars = utils.GetLikeKeywordPars(pars, v, 2)
+			}
+			condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
+
+		} else {
+			condition += ` AND (e.edb_name like ? or e.edb_code like ? )`
+			pars = utils.GetLikeKeywordPars(pars, keyword, 2)
+		}
+	}
+
+	sortStr := ``
+	if sortParam != `` {
+		sortStr = fmt.Sprintf("%s %s,e.edb_info_id desc ", sortParam, sortType)
+	}
+
+	total, list, err = data_manage.GetEdbInfoRelationList(condition, pars, addFieldStr, joinTableStr, sortStr, startSize, pageSize)
+
+	return
+}
+*/
+// GetCalculateEdbByFromEdbInfo 找到依赖于该基础指标的所有计算指标
+func GetCalculateEdbByFromEdbInfo(edbInfoIds []int, calculateEdbIds []int, hasFind map[int]struct{}) (newCalculateEdbIds []int, err error) {
+	if len(edbInfoIds) == 0 {
+		return
+	}
+	newCalculateEdbIds = calculateEdbIds
+	newEdbInfoIds := make([]int, 0)
+	for _, v := range edbInfoIds {
+		if _, ok := hasFind[v]; ok {
+			continue
+		}
+		newEdbInfoIds = append(newEdbInfoIds, v)
+	}
+	if len(newEdbInfoIds) == 0 {
+		return
+	}
+	var condition string
+	var pars []interface{}
+	// 关联指标
+	condition += ` AND b.from_edb_info_id in (` + utils.GetOrmInReplace(len(newEdbInfoIds)) + `)`
+	pars = append(pars, newEdbInfoIds)
+
+	//获取关联图表列表
+	list, err := data_manage.GetRelationEdbInfoListMappingByCondition(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		err = fmt.Errorf("获取关联指标信息失败,Err:%s", err.Error())
+		return
+	}
+	calculateEdbIdsTmp := make([]int, 0)
+	for _, mapping := range list {
+		if mapping.EdbType == 2 && mapping.EdbInfoType == 0 { // 如果指标库里的计算指标,则加入,否则继续找
+			newCalculateEdbIds = append(newCalculateEdbIds, mapping.EdbInfoId)
+			calculateEdbIdsTmp = append(calculateEdbIdsTmp, mapping.EdbInfoId)
+		}
+	}
+	for _, v := range newEdbInfoIds {
+		hasFind[v] = struct{}{}
+	}
+	if len(calculateEdbIdsTmp) > 0 {
+		newCalculateEdbIds, err = GetCalculateEdbByFromEdbInfo(calculateEdbIdsTmp, newCalculateEdbIds, hasFind)
+		if err != nil {
+			return
+		}
+	}
+
+	return
+}