package data import ( "encoding/json" "errors" "eta/eta_api/models" "eta/eta_api/models/data_manage" "eta/eta_api/models/system" "eta/eta_api/services/alarm_msg" "eta/eta_api/utils" "fmt" "strings" "time" "github.com/rdlucklib/rdluck_tools/http" ) // AddMysteelChemicalClassify 添加钢联化工分类 func AddMysteelChemicalClassify(classifyName string, parentId, level, sysUserId int, sysUserName, lange string) (classifyInfo *data_manage.BaseFromMysteelChemicalClassify, err error, errMsg string) { // 校验分类名称相同的数量 { var count int switch lange { case utils.EnLangVersion: count, err = data_manage.GetBaseFromMysteelChemicalClassifyEnCount(classifyName, parentId) default: count, err = data_manage.GetBaseFromMysteelChemicalClassifyCount(classifyName, parentId) } if err != nil { errMsg = `判断名称是否已存在失败` return } if count > 0 { errMsg = `分类名称:` + classifyName + ` 已存在,请重新输入` err = errors.New(errMsg) return } } //获取该层级下最大的排序数 maxSort, err := data_manage.GetBaseFromMysteelChemicalClassifyMaxSort(parentId) classifyInfo = &data_manage.BaseFromMysteelChemicalClassify{ //BaseFromMysteelChemicalClassifyId: 0, ClassifyName: classifyName, ClassifyNameEn: classifyName, ParentId: parentId, SysUserId: sysUserId, SysUserRealName: sysUserName, Sort: maxSort + 1, Level: level + 1, ModifyTime: time.Now(), CreateTime: time.Now(), } classifyId, err := data_manage.AddBaseFromMysteelChemicalClassify(classifyInfo) if err != nil { errMsg = "保存分类失败" } classifyInfo.BaseFromMysteelChemicalClassifyId = int(classifyId) return } // EditMysteelChemicalClassify 编辑钢联化工分类 func EditMysteelChemicalClassify(classifyId int, classifyName, lang string, sysUser *system.Admin) (err error, errMsg string) { item, err := data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId) if err != nil { errMsg = `保存失败` return } // 操作权限校验 button := GetMysteelChemicalOpButton(sysUser, item.SysUserId) if !button.OpButton { errMsg = "无权限操作" return } switch lang { case utils.EnLangVersion: // 名字相同,那么就直接返回 if item.ClassifyNameEn == classifyName { return } // 判断名称是否已存在 count, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyEnCount(classifyName, item.ParentId) if tmpErr != nil { err = tmpErr errMsg = "判断名称是否已存在失败" return } if count > 0 { errMsg = "分类名称已存在,请重新输入" err = errors.New(errMsg) return } // 修改数据 err = data_manage.EditBaseFromMysteelChemicalClassifyEn(classifyId, classifyName) if err != nil { errMsg = "保存失败" } default: // 名字相同,那么就直接返回 if item.ClassifyName == classifyName { return } // 判断名称是否已存在 count, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyCount(classifyName, item.ParentId) if tmpErr != nil { err = tmpErr errMsg = "判断名称是否已存在失败" return } if count > 0 { errMsg = "分类名称已存在,请重新输入" err = errors.New(errMsg) return } // 修改数据 err = data_manage.EditBaseFromMysteelChemicalClassify(classifyId, classifyName) if err != nil { errMsg = "保存失败" } } return } // MoveMysteelChemicalClassify 移动钢联化工分类 func MoveMysteelChemicalClassify(classifyId, parentClassifyId, prevClassifyId, nextClassifyId int, sysUser *system.Admin) (err error, errMsg string) { //判断分类是否存在 classifyInfo, err := data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId) if err != nil { errMsg = "移动失败" err = errors.New("获取分类信息失败,Err:" + err.Error()) return } // 操作权限校验 button := GetMysteelChemicalOpButton(sysUser, classifyInfo.SysUserId) if !button.MoveButton { errMsg = "无权限操作" return } updateCol := make([]string, 0) //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级 if classifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 { parentClassifyInfo, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyById(parentClassifyId) if tmpErr != nil { errMsg = "移动失败" err = errors.New("获取上级分类信息失败,Err:" + tmpErr.Error()) return } classifyInfo.ParentId = parentClassifyInfo.BaseFromMysteelChemicalClassifyId classifyInfo.Level = parentClassifyInfo.Level + 1 classifyInfo.ModifyTime = time.Now() updateCol = append(updateCol, "ParentId", "Level", "ModifyTime") } //如果有传入 上一个兄弟节点分类id if prevClassifyId > 0 { prevClassify, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyById(prevClassifyId) if tmpErr != nil { errMsg = "移动失败" err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + tmpErr.Error()) return } //如果是移动在两个兄弟节点之间 if nextClassifyId > 0 { //下一个兄弟节点 nextClassify, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyById(nextClassifyId) if tmpErr != nil { errMsg = "移动失败" err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + tmpErr.Error()) return } //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1 if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == classifyInfo.Sort { //变更兄弟节点的排序 updateSortStr := `sort + 2` _ = data_manage.UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentClassifyId, prevClassify.BaseFromMysteelChemicalClassifyId, prevClassify.Sort, updateSortStr) } else { //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了 if nextClassify.Sort-prevClassify.Sort == 1 { //变更兄弟节点的排序 updateSortStr := `sort + 1` _ = data_manage.UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentClassifyId, 0, prevClassify.Sort, updateSortStr) } } } classifyInfo.Sort = prevClassify.Sort + 1 classifyInfo.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } else { firstClassify, tmpErr := data_manage.GetFirstBaseFromMysteelChemicalClassify() if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() { errMsg = "移动失败" err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error()) return } //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序 if firstClassify != nil && firstClassify.Sort == 0 { updateSortStr := ` sort + 1 ` _ = data_manage.UpdateBaseFromMysteelChemicalClassifySortByClassifyId(parentClassifyId, firstClassify.BaseFromMysteelChemicalClassifyId-1, 0, updateSortStr) } classifyInfo.Sort = 0 //那就是排在第一位 classifyInfo.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } //更新 if len(updateCol) > 0 { err = classifyInfo.Update(updateCol) if err != nil { errMsg = "移动失败" err = errors.New("修改失败,Err:" + err.Error()) return } } return } // DelMysteelChemicalClassify 删除钢联化工分类 func DelMysteelChemicalClassify(classifyId int, sysUser *system.Admin) (err error, errMsg string) { //判断分类是否存在 classifyInfo, err := data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId) if err != nil { errMsg = "删除失败" err = errors.New("获取分类信息失败,Err:" + err.Error()) return } // 操作权限校验 button := GetMysteelChemicalOpButton(sysUser, classifyInfo.SysUserId) if !button.DeleteButton { errMsg = "无权限操作" return } // 需要删除的分类id集合 classifyIdList := make([]int, 0) classifyIdList = append(classifyIdList, classifyId) mysteelChemicalIndexIdList := make([]int, 0) indexCodeList := make([]string, 0) // 查找所有的子集id if classifyInfo.ParentId <= 0 { childrenClassifyInfoList, tmpErr := data_manage.GetBaseFromMysteelChemicalClassifyByParentId(classifyId) if tmpErr != nil { errMsg = "删除失败" err = errors.New("获取分类信息失败,Err:" + tmpErr.Error()) return } for _, v := range childrenClassifyInfoList { classifyIdList = append(classifyIdList, v.BaseFromMysteelChemicalClassifyId) } } // 获取分类下的所有指标 baseFromMysteelChemicalIndexList, err := data_manage.GetBaseFromMysteelChemicalIndexListByClassifyIdList(classifyIdList) if err != nil { errMsg = "删除失败" err = errors.New("获取分类下的指标信息失败,Err:" + err.Error()) return } for _, v := range baseFromMysteelChemicalIndexList { mysteelChemicalIndexIdList = append(mysteelChemicalIndexIdList, v.BaseFromMysteelChemicalIndexId) indexCodeList = append(indexCodeList, v.IndexCode) } // 获取已经加入到EDB指标库的钢联化工指标 edbInfoList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, indexCodeList) if err != nil { errMsg = "删除失败" err = errors.New("获取分类下的指标信息失败,Err:" + err.Error()) return } if len(edbInfoList) > 0 { errMsg = "该分类下存在指标加入到ETA图库,无法删除" return } // 删除对应的分类和指标 err = data_manage.DeleteMysteelChemicalByClassifyId(classifyIdList, mysteelChemicalIndexIdList) if err != nil { return } // 删除指标服务的excel表 go func(list []*data_manage.BaseFromMysteelChemicalIndex) { for _, v := range list { CurlDelMysteelChemicalData(v.IndexCode, v.UpdateWeek) } }(baseFromMysteelChemicalIndexList) return } // BatchAddMysteelChemicalIndex 批量添加钢联化工指标 func BatchAddMysteelChemicalIndex(items []*data_manage.BaseFromMysteelChemicalIndex, lang string) (baseFromMysteelChemicalIndexs []*data_manage.BaseFromMysteelChemicalIndex, err error, errMsg string) { indexCodeList := make([]string, 0) for _, v := range items { indexCodeList = append(indexCodeList, v.IndexCode) } baseFromMysteelChemicalIndexs, err = data_manage.GetBaseFromMysteelChemicalIndexByCodeList(indexCodeList) if err != nil && err.Error() != utils.ErrNoRow() { errMsg = `获取数据失败` return } err = nil // 过滤已存在的指标 filterMap := make(map[string]struct{}) if len(baseFromMysteelChemicalIndexs) > 0 { existIndexCodeList := make([]string, 0) for _, v := range baseFromMysteelChemicalIndexs { existIndexCodeList = append(existIndexCodeList, v.IndexCode) filterMap[v.IndexCode] = struct{}{} } if lang == utils.EnLangVersion { errMsg = fmt.Sprintf(`Metric ID: %s already exists, please re-enter.`, strings.Join(existIndexCodeList, ",")) } else { errMsg = fmt.Sprintf(`指标ID: %s 已存在,请重新输入`, strings.Join(existIndexCodeList, ",")) } return } terminal := getEdbTerminal(utils.DATA_SOURCE_MYSTEEL_CHEMICAL) addItems := make([]*data_manage.BaseFromMysteelChemicalIndex, 0) preAddIndexCodeItems := make([]string, 0) for _, v := range items { if _, ok := filterMap[v.IndexCode]; ok { continue } v.TerminalCode = terminal.TerminalCode addItems = append(addItems, v) preAddIndexCodeItems = append(preAddIndexCodeItems, v.IndexCode) } _, err = data_manage.BatchAddBaseFromMysteelChemicalIndex(addItems) if err != nil { errMsg = "保存分类失败" return } baseFromMysteelChemicalIndexs, err = data_manage.GetBaseFromMysteelChemicalIndexByCodeList(preAddIndexCodeItems) if err != nil { errMsg = "获取数据失败" return } return } type HandleMysteelChemicalIndexReq struct { List []*data_manage.BaseFromMysteelChemicalIndex } func BatchAddMysteelChemicalData(items []*data_manage.BaseFromMysteelChemicalIndex, lang string) (resp *models.BaseResponse, err error) { url := utils.EDB_LIB_URL + "mysteel_chemical/handle/api/mysteel/index" req := new(HandleMysteelChemicalIndexReq) req.List = items postData, err := json.Marshal(req) if err != nil { return } body, err := HttpPost(url, string(postData), lang) if err != nil { return } if err = json.Unmarshal(body, &resp); err != nil { return } return } type MysteelChemicalIndexSource2EdbReq struct { EdbCode string EdbName string Frequency string Unit string ClassifyId int AdminId int AdminRealName string } // MysteelChemicalIndexSource2Edb 新增钢联化工数据源到指标库 func MysteelChemicalIndexSource2Edb(req MysteelChemicalIndexSource2EdbReq, lang string) (edb *data_manage.EdbInfo, err error, errMsg string, skip bool) { if req.EdbCode == "" { err = fmt.Errorf("指标ID为空") return } defer func() { if err != nil { tips := fmt.Sprintf("MysteelChemicalIndexSource2Edb新增失败, Err: %s", err.Error()) fmt.Println(tips) utils.FileLog.Info(tips) } }() source := utils.DATA_SOURCE_MYSTEEL_CHEMICAL // 是否新增过指标 exist, e := data_manage.GetEdbInfoByEdbCode(source, req.EdbCode) if e != nil && e.Error() != utils.ErrNoRow() { err = fmt.Errorf("获取指标是否存在失败, err: %s", e.Error()) return } if exist != nil { skip = true return } // 开始结束时间 var startDate, endDate string // 新增指标库 edbInfo, e, msg, _ := EdbInfoAdd(source, utils.DATA_SUB_SOURCE_EDB, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, startDate, endDate, req.AdminId, req.AdminRealName, lang) if e != nil { errMsg = msg err = fmt.Errorf("EdbInfo: 新增指标失败, err: %s", e.Error()) return } edb = edbInfo return } // AddMysteelChemicalIndex 添加钢联化工指标 func AddMysteelChemicalIndex(classifyId int, indexCode, updateWeek, updateTimeStr string, sysUserId int, sysUserName, lang string) (baseFromMysteelChemicalIndex *data_manage.BaseFromMysteelChemicalIndex, err error, errMsg string) { baseFromMysteelChemicalIndex, err = data_manage.GetBaseFromMysteelChemicalIndexByCode(indexCode) if err != nil && err.Error() != utils.ErrNoRow() { errMsg = `获取数据失败` return } if baseFromMysteelChemicalIndex != nil { if lang == utils.EnLangVersion { errMsg = `Metric ID:` + indexCode + ` already exists, please re-enter.` } else { errMsg = `指标ID:` + indexCode + ` 已存在,请重新输入` } return } // 更新时间切割 var updateTime1, updateTime2 string if updateTimeStr != `` { updateTimeList := strings.Split(updateTimeStr, ",") updateTime1 = updateTimeList[0] if len(updateTimeList) > 1 { updateTime2 = updateTimeList[1] } } edbTerminal := getEdbTerminal(utils.DATA_SOURCE_MYSTEEL_CHEMICAL) if edbTerminal == nil { errMsg = `钢联终端信息未配置` err = errors.New(errMsg) return } baseFromMysteelChemicalIndex = &data_manage.BaseFromMysteelChemicalIndex{ //BaseFromMysteelChemicalIndexId: 0, BaseFromMysteelChemicalClassifyId: classifyId, IndexCode: indexCode, IndexName: "", Unit: "", Source: "", Frequency: "", StartDate: "", EndDate: "", Describe: "", UpdateWeek: updateWeek, UpdateTime: updateTime1, UpdateTime2: updateTime2, SysUserId: sysUserId, SysUserRealName: sysUserName, ModifyTime: time.Now(), CreateTime: time.Now(), TerminalCode: edbTerminal.TerminalCode, // 终端编码 } _, err = data_manage.AddBaseFromMysteelChemicalIndex(baseFromMysteelChemicalIndex) if err != nil { errMsg = "保存分类失败" } return } // EditMysteelChemicalIndex 编辑钢联化工指标 func EditMysteelChemicalIndex(indexId, classifyId int, updateWeek, updateTimeStr string, sysUser *system.Admin) (baseFromMysteelChemicalIndex *data_manage.BaseFromMysteelChemicalIndex, err error, errMsg string) { baseFromMysteelChemicalIndex, err = data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId) if err != nil { errMsg = `获取数据失败` if err.Error() == utils.ErrNoRow() { errMsg = `该指标未入库` err = nil } return } // 操作权限校验 button := GetMysteelChemicalOpButton(sysUser, baseFromMysteelChemicalIndex.SysUserId) if !button.OpButton { errMsg = "无权限操作" return } oldUpdateWeek := baseFromMysteelChemicalIndex.UpdateWeek // 更新时间切割 var updateTime1, updateTime2 string if updateTimeStr != `` { updateTimeList := strings.Split(updateTimeStr, ",") updateTime1 = updateTimeList[0] if len(updateTimeList) > 1 { updateTime2 = updateTimeList[1] } } baseFromMysteelChemicalIndex.BaseFromMysteelChemicalClassifyId = classifyId baseFromMysteelChemicalIndex.UpdateWeek = updateWeek baseFromMysteelChemicalIndex.UpdateTime = updateTime1 baseFromMysteelChemicalIndex.UpdateTime2 = updateTime2 baseFromMysteelChemicalIndex.ModifyTime = time.Now() err = baseFromMysteelChemicalIndex.Update([]string{"BaseFromMysteelChemicalClassifyId", "UpdateWeek", "UpdateTime", "UpdateTime2", "ModifyTime"}) if err != nil { errMsg = "保存分类失败" } go func(oldUpdateWeek string, indexInfo *data_manage.BaseFromMysteelChemicalIndex) { // 先删除excel表 CurlDelMysteelChemicalData(indexInfo.IndexCode, oldUpdateWeek) }(oldUpdateWeek, baseFromMysteelChemicalIndex) return } // DelMysteelChemical 删除钢联化工指标 func DelMysteelChemical(indexId int, sysUser *system.Admin) (err error, errMsg string) { baseFromMysteelChemicalIndex, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId) if err != nil { errMsg = `获取数据失败` if err.Error() == utils.ErrNoRow() { errMsg = `该指标未入库` err = nil } return } // 操作权限校验 button := GetMysteelChemicalOpButton(sysUser, baseFromMysteelChemicalIndex.SysUserId) if !button.DeleteButton { errMsg = "无权限操作" return } // 获取已经加入到EDB指标库的钢联化工指标 edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, baseFromMysteelChemicalIndex.IndexCode) if err != nil && err.Error() != utils.ErrNoRow() { errMsg = "删除失败" err = errors.New("获取分类下的指标信息失败,Err:" + err.Error()) return } if edbInfo != nil { errMsg = "当前指标已被引用,不可删除" err = nil return } // 删除对应的分类和指标 err = data_manage.DeleteMysteelChemical(indexId) if err != nil { return } // 删除指标服务的excel表 go CurlDelMysteelChemicalData(baseFromMysteelChemicalIndex.IndexCode, baseFromMysteelChemicalIndex.UpdateWeek) return } // MoveMysteelChemical 移动钢联化工指标 func MoveMysteelChemical(indexId, classifyId, prevIndexId, nextIndexId int, sysUser *system.Admin) (err error, errMsg string) { //分类信息 baseFromMysteelChemicalIndex, err := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId) if err != nil { errMsg = `获取数据失败` if err.Error() == utils.ErrNoRow() { errMsg = `该指标未入库` err = nil } return } // 操作权限校验 button := GetMysteelChemicalOpButton(sysUser, baseFromMysteelChemicalIndex.SysUserId) if !button.MoveButton { errMsg = "无权限操作" return } //判断分类是否存在 _, err = data_manage.GetBaseFromMysteelChemicalClassifyById(classifyId) if err != nil { errMsg = "移动失败" err = errors.New("获取分类信息失败,Err:" + err.Error()) if err.Error() == utils.ErrNoRow() { errMsg = "找不到该分类" err = nil } return } //如果改变了分类,那么移动该图表数据 if baseFromMysteelChemicalIndex.BaseFromMysteelChemicalClassifyId != classifyId { tmpErr := data_manage.MoveBaseFromMysteelChemicalIndex(indexId, classifyId) if err != nil { errMsg = "移动失败" err = errors.New("移动失败,Err:" + tmpErr.Error()) return } } //移动排序 updateCol := make([]string, 0) //如果有传入 上一个兄弟节点分类id if prevIndexId > 0 { prevIndex, tmpErr := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(prevIndexId) if err != nil { errMsg = "移动失败" err = errors.New("获取上一个兄弟节点指标信息失败,Err:" + tmpErr.Error()) return } //如果是移动在两个兄弟节点之间 if nextIndexId > 0 { //下一个兄弟节点 nextIndex, tmpErr := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(nextIndexId) if err != nil { errMsg = "移动失败" err = errors.New("获取下一个兄弟节点指标信息失败,Err:" + tmpErr.Error()) return } //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1 if prevIndex.Sort == nextIndex.Sort || prevIndex.Sort == baseFromMysteelChemicalIndex.Sort { //变更兄弟节点的排序 updateSortStr := `sort + 2` _ = data_manage.UpdateBaseFromMysteelChemicalIndexByClassifyId(prevIndex.BaseFromMysteelChemicalClassifyId, prevIndex.Sort, prevIndex.BaseFromMysteelChemicalIndexId, updateSortStr) } else { //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了 if nextIndex.Sort-prevIndex.Sort == 1 { //变更兄弟节点的排序 updateSortStr := `sort + 1` _ = data_manage.UpdateBaseFromMysteelChemicalIndexByClassifyId(prevIndex.BaseFromMysteelChemicalClassifyId, prevIndex.Sort, prevIndex.BaseFromMysteelChemicalIndexId, updateSortStr) } } } baseFromMysteelChemicalIndex.Sort = prevIndex.Sort + 1 baseFromMysteelChemicalIndex.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } else { firstClassify, tmpErr := data_manage.GetFirstBaseFromMysteelChemicalIndexByClassifyId(classifyId) if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() { errMsg = "移动失败" err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error()) return } //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序 if firstClassify != nil && firstClassify.Sort == 0 { updateSortStr := ` sort + 1 ` _ = data_manage.UpdateBaseFromMysteelChemicalIndexByClassifyId(firstClassify.BaseFromMysteelChemicalClassifyId, 0, firstClassify.BaseFromMysteelChemicalIndexId-1, updateSortStr) } baseFromMysteelChemicalIndex.Sort = 0 //那就是排在第一位 baseFromMysteelChemicalIndex.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } //更新 if len(updateCol) > 0 { err = baseFromMysteelChemicalIndex.Update(updateCol) if err != nil { errMsg = "移动失败" err = errors.New("修改失败,Err:" + err.Error()) return } } if err != nil { errMsg = "移动失败" err = errors.New("修改失败,Err:" + err.Error()) return } return } // GetMysteelChemicalOpButton 获取钢联化工的操作权限 func GetMysteelChemicalOpButton(sysUser *system.Admin, belongUserId int) (button data_manage.BaseFromMysteelChemicalClassifyItemsButton) { // 统一跟随角色权限进行管理分类, 不对特定角色进行权限控制 button.AddButton = true button.OpButton = true button.DeleteButton = true button.MoveButton = true return } // func GetMysteelChemicalOpButton(sysUser *system.Admin, belongUserId int) (button data_manage.BaseFromMysteelChemicalClassifyItemsButton) { // //2、用户对于自己添加的分类,有权限编辑、移动和删除该分类; // //3、ficc管理员和超管对所有分类有编辑、移动和删除权限; // if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.MysteelChemicalPermission == 1 { // button.AddButton = true // button.OpButton = true // button.DeleteButton = true // button.MoveButton = true // } // return // } // CurlDelMysteelChemicalData 请求钢联服务器删除指标 func CurlDelMysteelChemicalData(indexCode, updateWeek string) { postUrl := utils.MySteelPostUrl + `/api/index/delete` //type IndexAddReq struct { // IndexCode string `json:"IndexCode" binding:"required"` //指标编码 // UpdateWeek string `json:"UpdateWeek"` //更新周期 // RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期 //} paramsMap := make(map[string]interface{}) updateWeek = WeekMap[updateWeek] paramsMap["IndexCode"] = indexCode paramsMap["UpdateWeek"] = updateWeek paramsMap["RunMode"] = utils.RunMode paramJson, err := json.Marshal(paramsMap) if err != nil { fmt.Println("param json.Marshal Err:" + err.Error()) err = errors.New("param json.Marshal Err:" + err.Error()) return } utils.FileLog.Info(fmt.Sprintf("CurlDelMysteelChemicalData parms:%s", string(paramJson))) result, err := http.Post(postUrl, string(paramJson), "application/json") if err != nil { fmt.Println("post err:" + err.Error()) err = errors.New("post Err:" + err.Error()) return } utils.FileLog.Info("CurlDelMysteelChemicalData Result:%s", string(result)) } // WeekMap 中英文日期转换 var WeekMap = map[string]string{ "": "", "周一": "monday", "周二": "tuesday", "周三": "wednesday", "周四": "thursday", "周五": "friday", "周六": "saturday", "周日": "sunday", } // CurlRefreshMysteelChemicalData 请求钢联服务器添加指标 func CurlRefreshMysteelChemicalData(mergeFilePath string) { postUrl := utils.MySteelPostUrl + `/api/index/refresh` //type IndexAddReq struct { // IndexCode string `json:"IndexCode" binding:"required"` //指标编码 // UpdateWeek string `json:"UpdateWeek"` //更新周期 // RunMode string `description:"运行环境:debug:测试(默认),release:生产" json:"UpdateWeek"` //更新周期 //} paramsMap := make(map[string]interface{}) paramsMap["MergeFilePath"] = mergeFilePath paramJson, err := json.Marshal(paramsMap) if err != nil { fmt.Println("param json.Marshal Err:" + err.Error()) err = errors.New("param json.Marshal Err:" + err.Error()) return } utils.FileLog.Info(fmt.Sprintf("CurlRefreshMysteelChemicalData parms:%s", string(paramJson))) result, err := http.Post(postUrl, string(paramJson), "application/json") if err != nil { fmt.Println("post err:" + err.Error()) err = errors.New("post Err:" + err.Error()) return } utils.FileLog.Info("CurlRefreshMysteelChemicalData Result:%s", string(result)) } // getEdbTerminal 根据指标来源获取可用指标终端信息 func getEdbTerminal(source int) (edbTerminal *data_manage.EdbTerminal) { terminalNumList, err := data_manage.GetMysteelChemicalGroupTerminalNum() if err != nil { return } terminalNumMap := make(map[string]int) for _, v := range terminalNumList { terminalNumMap[v.TerminalCode] = v.Num } terminalList, err := data_manage.GetEdbTerminalListBySource(source) if err != nil { return } num := 0 for _, v := range terminalList { tmpNum := terminalNumMap[v.TerminalCode] if edbTerminal == nil { edbTerminal = v num = tmpNum } else if tmpNum < num { edbTerminal = v num = tmpNum } } return } // RefreshMysteelChemicalData 根据手工指标code刷新手工指标数据 func RefreshMysteelChemicalData(edbCode string) { var err error var errMsg string defer func() { if err != nil { go alarm_msg.SendAlarmMsg("根据钢联化工的code刷新指标数据失败提醒,Err"+err.Error(), 3) //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"导入手工数据后,根据手工指标code刷新手工指标数据失败提醒", "errmsg:"+err.Error(), utils.EmailSendToUsers) } if errMsg != "" { go alarm_msg.SendAlarmMsg("根据钢联化工的code刷新指标数据失败提醒,errMsg"+errMsg, 3) } }() baseFromMysteelChemicalIndexs, err := data_manage.GetBaseFromMysteelChemicalIndexByCodeList([]string{edbCode}) if err != nil && err.Error() != utils.ErrNoRow() { return } resp, err := BatchAddMysteelChemicalData(baseFromMysteelChemicalIndexs, "zh") if err != nil { return } if !resp.Success { errMsg = resp.ErrMsg } } // RefreshMysteelChemicalData 根据手工指标code刷新手工指标数据 func HealthCheckMysteelChemicalApi() (isEnable bool, ErrMsg string, err error) { url := utils.EDB_LIB_URL + "mysteel_chemical/handle/mysteel/api/check" body, err := HttpPost(url, "", utils.ZhLangVersion) if err != nil { return } var resp models.BaseResponse if err = json.Unmarshal(body, &resp); err != nil { return } apiCheck, ok := resp.Data.(map[string]interface{}) if ok { isEnable = apiCheck["IsEnable"].(bool) ErrMsg = apiCheck["ErrMsg"].(string) } else { err = errors.New("钢联api接口不可用") } return }