report_classify.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package services
  2. import (
  3. "errors"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/services/alarm_msg"
  6. "fmt"
  7. )
  8. func UpdateParentClassifyHasTel(classifyId, parentId, hasTeleconference int) (err error) {
  9. if classifyId <= 0 || parentId <= 0 {
  10. return
  11. }
  12. defer func() {
  13. if err != nil {
  14. alarm_msg.SendAlarmMsg("编辑分类后-修改父级分类电话会信息失败, ErrMsg: "+err.Error(), 3)
  15. }
  16. }()
  17. parentClassify, e := models.GetClassifyById(parentId)
  18. if e != nil {
  19. err = fmt.Errorf("获取父级分类信息失败, Err: %s", e.Error())
  20. return
  21. }
  22. updateParent := false
  23. updateCols := make([]string, 0)
  24. updateCols = append(updateCols, "HasTeleconference")
  25. if hasTeleconference == 1 {
  26. if parentClassify.HasTeleconference == 0 {
  27. parentClassify.HasTeleconference = 1
  28. updateParent = true
  29. }
  30. } else {
  31. if parentClassify.HasTeleconference == 1 {
  32. child, e := models.GetClassifyChild(parentClassify.Id, "")
  33. if e != nil {
  34. err = fmt.Errorf("获取子分类失败, Err: %s", e.Error())
  35. return
  36. }
  37. hasTel := false
  38. for i := 0; i < len(child); i++ {
  39. if child[i].HasTeleconference == 1 && child[i].Id != classifyId {
  40. hasTel = true
  41. break
  42. }
  43. }
  44. if !hasTel {
  45. parentClassify.HasTeleconference = 0
  46. updateParent = true
  47. }
  48. }
  49. }
  50. if updateParent {
  51. if e = parentClassify.UpdateClassify(updateCols); e != nil {
  52. err = fmt.Errorf("更新父级分类失败, Err: %s", e.Error())
  53. return
  54. }
  55. }
  56. return
  57. }
  58. func AfterUpdateClassifyNameOrParent(classifyId, parentId, originParentId int, originName, classifyName string, classifyLevel int) (err error) {
  59. if classifyId == 0 {
  60. return
  61. }
  62. defer func() {
  63. if err != nil {
  64. alarm_msg.SendAlarmMsg("更改分类名称后-同步更新报告表字段及权限表关键词失败, ErrMsg: "+err.Error(), 3)
  65. }
  66. }()
  67. if originName != classifyName {
  68. switch classifyLevel {
  69. case 1: // 一级分类
  70. if e := models.UpdateReportFirstClassifyNameByClassifyId(classifyId, classifyName); e != nil {
  71. err = fmt.Errorf("更新报告表一级分类名称失败, Err: %s", e.Error())
  72. return
  73. }
  74. case 2: // 二级分类
  75. if e := models.UpdateReportSecondClassifyNameByClassifyId(classifyId, classifyName); e != nil {
  76. err = fmt.Errorf("更新报告表二级分类名称失败, Err: %s", e.Error())
  77. return
  78. }
  79. case 3: // 三级分类
  80. if e := models.UpdateReportThirdClassifyNameByClassifyId(classifyId, classifyName); e != nil {
  81. err = fmt.Errorf("更新报告表三级分类名称失败, Err: %s", e.Error())
  82. return
  83. }
  84. default:
  85. err = errors.New(fmt.Sprint("错误的分类级别,ClassifyId:", classifyId, ";层级:", classifyLevel))
  86. return
  87. }
  88. if e := models.UpdateChartPermissionNameFromMappingByKeyword(classifyName, classifyId, "rddp"); e != nil {
  89. err = fmt.Errorf("更新二级分类关键词失败, Err: %s", e.Error())
  90. return
  91. }
  92. _ = EditKeywordPermissionSync(classifyName, classifyId)
  93. }
  94. return
  95. }