123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- 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_THS, 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 = "操作成功"
- }
|