123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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
- }
|