package services import ( "errors" "eta_gn/eta_api/models" "eta_gn/eta_api/services/alarm_msg" "fmt" ) func UpdateParentClassifyHasTel(classifyId, parentId, hasTeleconference int) (err error) { if classifyId <= 0 || parentId <= 0 { return } defer func() { if err != nil { alarm_msg.SendAlarmMsg("编辑分类后-修改父级分类电话会信息失败, ErrMsg: "+err.Error(), 3) } }() parentClassify, e := models.GetClassifyById(parentId) if e != nil { err = fmt.Errorf("获取父级分类信息失败, Err: %s", e.Error()) return } updateParent := false updateCols := make([]string, 0) updateCols = append(updateCols, "HasTeleconference") if hasTeleconference == 1 { if parentClassify.HasTeleconference == 0 { parentClassify.HasTeleconference = 1 updateParent = true } } else { if parentClassify.HasTeleconference == 1 { child, e := models.GetClassifyChild(parentClassify.Id, "") if e != nil { err = fmt.Errorf("获取子分类失败, Err: %s", e.Error()) return } hasTel := false for i := 0; i < len(child); i++ { if child[i].HasTeleconference == 1 && child[i].Id != classifyId { hasTel = true break } } if !hasTel { parentClassify.HasTeleconference = 0 updateParent = true } } } if updateParent { if e = parentClassify.UpdateClassify(updateCols); e != nil { err = fmt.Errorf("更新父级分类失败, Err: %s", e.Error()) return } } return } func AfterUpdateClassifyNameOrParent(classifyId, parentId, originParentId int, originName, classifyName string, classifyLevel int) (err error) { if classifyId == 0 { return } defer func() { if err != nil { alarm_msg.SendAlarmMsg("更改分类名称后-同步更新报告表字段及权限表关键词失败, ErrMsg: "+err.Error(), 3) } }() if originName != classifyName { switch classifyLevel { case 1: // 一级分类 if e := models.UpdateReportFirstClassifyNameByClassifyId(classifyId, classifyName); e != nil { err = fmt.Errorf("更新报告表一级分类名称失败, Err: %s", e.Error()) return } case 2: // 二级分类 if e := models.UpdateReportSecondClassifyNameByClassifyId(classifyId, classifyName); e != nil { err = fmt.Errorf("更新报告表二级分类名称失败, Err: %s", e.Error()) return } case 3: // 三级分类 if e := models.UpdateReportThirdClassifyNameByClassifyId(classifyId, classifyName); e != nil { err = fmt.Errorf("更新报告表三级分类名称失败, Err: %s", e.Error()) return } default: err = errors.New(fmt.Sprint("错误的分类级别,ClassifyId:", classifyId, ";层级:", classifyLevel)) return } if e := models.UpdateChartPermissionNameFromMappingByKeyword(classifyName, classifyId, "rddp"); e != nil { err = fmt.Errorf("更新二级分类关键词失败, Err: %s", e.Error()) return } _ = EditKeywordPermissionSync(classifyName, classifyId) } return }