chart_permission.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package crm
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/go-playground/validator/v10"
  5. "hongze/hz_crm_eta/controller/resp"
  6. "hongze/hz_crm_eta/global"
  7. "hongze/hz_crm_eta/models/crm"
  8. "hongze/hz_crm_eta/models/eta"
  9. crmService "hongze/hz_crm_eta/services/crm"
  10. )
  11. type ChartPermissionController struct{}
  12. // SyncClassifyChartPermission
  13. // @Description 同步分类权限
  14. // @Success 200 {string} string "操作成功"
  15. // @Router /crm/chart_permission/classify/sync [post]
  16. func (cp *ChartPermissionController) SyncClassifyChartPermission(c *gin.Context) {
  17. var req crm.ClassifyPermissionEditReq
  18. err := c.Bind(&req)
  19. if err != nil {
  20. errs, ok := err.(validator.ValidationErrors)
  21. if !ok {
  22. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  23. return
  24. }
  25. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  26. return
  27. }
  28. if req.Keyword == "" {
  29. resp.Fail("分类名称不能为空", c)
  30. return
  31. }
  32. if req.ClassifyId <= 0 {
  33. resp.Fail("分类ID不能为空", c)
  34. return
  35. }
  36. etaOb := new(eta.ChartPermissionSearchKeyWordMapping)
  37. mappingList, err := etaOb.GetPermissionByKeyword(req.ClassifyId)
  38. if err != nil {
  39. resp.FailData("查询分类权限失败", err.Error(), c)
  40. return
  41. }
  42. finalList := make([]*crm.ChartPermissionSearchKeyWordMapping, 0)
  43. for _, v := range mappingList {
  44. tmp := &crm.ChartPermissionSearchKeyWordMapping{
  45. Id: v.Id,
  46. ChartPermissionId: v.ChartPermissionId,
  47. KeyWord: v.KeyWord,
  48. From: v.From,
  49. TacticType: v.TacticType,
  50. TeleconferenceSort: v.TeleconferenceSort,
  51. ClassifyId: v.ClassifyId,
  52. }
  53. finalList = append(finalList, tmp)
  54. }
  55. ob := new(crm.ChartPermissionSearchKeyWordMapping)
  56. e := ob.EditChartPermissionSearchKeyWordMappingMulti(req.Keyword, finalList, req.ClassifyId)
  57. if e != nil {
  58. resp.FailData("设置分类权限失败", e.Error(), c)
  59. return
  60. }
  61. resp.Ok("操作成功", c)
  62. }
  63. // Sync
  64. // @Title 同步chart_permission数据
  65. // @Description 启用/禁用品种
  66. // @Param request body crm.PermissionEnabledReq true "type json string"
  67. // @Success 200 新增成功
  68. // @router /crm/chart_permission/sync [post]
  69. func (this *ChartPermissionController) Sync(c *gin.Context) {
  70. e, msg := crmService.SyncChartPermission()
  71. if e != nil {
  72. resp.FailData(msg, e.Error(), c)
  73. return
  74. }
  75. resp.Ok("操作成功", c)
  76. }
  77. // SyncReportMapping
  78. // @Title 同步chart_permission_chapter_mapping数据
  79. // @Description 启用/禁用品种
  80. // @Param request body crm.PermissionEnabledReq true "type json string"
  81. // @Success 200 新增成功
  82. // @router /crm/chart_permission/report/sync [post]
  83. func (this *ChartPermissionController) SyncReportMapping(c *gin.Context) {
  84. var req crm.PermissionReportReq
  85. err := c.Bind(&req)
  86. if err != nil {
  87. errs, ok := err.(validator.ValidationErrors)
  88. if !ok {
  89. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  90. return
  91. }
  92. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  93. return
  94. }
  95. if req.ReportId <= 0 {
  96. resp.Fail("报告ID不能为空", c)
  97. return
  98. }
  99. if req.ClassifyIdSecond <= 0 {
  100. resp.Fail("分类ID不能为空", c)
  101. return
  102. }
  103. e, msg := crmService.SyncChartPermissionReportMapping(req)
  104. if e != nil {
  105. resp.FailData(msg, e.Error(), c)
  106. return
  107. }
  108. resp.Ok("操作成功", c)
  109. }
  110. // SyncKeywordMapping
  111. // @Title 同步chart_permission_search_key_word_mapping数据
  112. // @Description 同步chart_permission_search_key_word_mapping数据
  113. // @Param request body crm.PermissionKeywordReq true "type json string"
  114. // @Success 200 新增成功
  115. // @router /crm/chart_permission/keyword/sync [post]
  116. func (this *ChartPermissionController) SyncKeywordMapping(c *gin.Context) {
  117. var req crm.PermissionKeywordReq
  118. err := c.Bind(&req)
  119. if err != nil {
  120. errs, ok := err.(validator.ValidationErrors)
  121. if !ok {
  122. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  123. return
  124. }
  125. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  126. return
  127. }
  128. if req.NewKeyword == "" {
  129. resp.Fail("新报告分类名称不能为空", c)
  130. return
  131. }
  132. if req.ClassifyId <= 0 {
  133. resp.Fail("分类ID不能为空", c)
  134. return
  135. }
  136. e := crm.UpdateChartPermissionNameFromMappingByKeyword(req.NewKeyword, req.ClassifyId, "rddp")
  137. if e != nil {
  138. resp.FailData("更新权限中的报告分类名称失败", e.Error(), c)
  139. return
  140. }
  141. resp.Ok("操作成功", c)
  142. }