chart_permission.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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/request"
  9. crmService "hongze/hz_crm_eta/services/crm"
  10. )
  11. type ChartPermissionController struct{}
  12. // GetChartPermission
  13. // @Description 获取品种列表
  14. // @Success 200 {string} string "操作成功"
  15. // @Router /crm/chart_permission/list [post]
  16. func (cp *ChartPermissionController) GetChartPermission(c *gin.Context) {
  17. var req request.ChartPermissionReq
  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. cond := ` 1=1`
  29. pars := make([]interface{}, 0)
  30. if req.ProductId > 0 {
  31. cond += " and product_id = ?"
  32. pars = append(pars, req.ProductId)
  33. }
  34. if req.ChartPermissionId > 0 {
  35. cond += " and chart_permission_id = ?"
  36. pars = append(pars, req.ChartPermissionId)
  37. }
  38. list, e := crmService.GetChartPermissionList(cond, pars)
  39. if e != nil {
  40. resp.FailData("查询失败", e.Error(), c)
  41. return
  42. }
  43. data := request.ChartPermissionResp{List: list}
  44. resp.OkData("操作成功", data, c)
  45. }
  46. // AddChartPermission
  47. // @Description 新增品种
  48. // @Success 200 {string} string "操作成功"
  49. // @Router /crm/chart_permission/add [post]
  50. func (cp *ChartPermissionController) AddChartPermission(c *gin.Context) {
  51. var req crm.PermissionAddReq
  52. err := c.Bind(&req)
  53. if err != nil {
  54. errs, ok := err.(validator.ValidationErrors)
  55. if !ok {
  56. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  57. return
  58. }
  59. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  60. return
  61. }
  62. if req.PermissionName == "" {
  63. resp.Fail("请输入品种名称", c)
  64. return
  65. }
  66. e, msg := crmService.AddChartPermission(req)
  67. if e != nil {
  68. resp.FailData(msg, e.Error(), c)
  69. return
  70. }
  71. resp.Ok("操作成功", c)
  72. }
  73. // EditChartPermission
  74. // @Description 编辑品种
  75. // @Success 200 {string} string "操作成功"
  76. // @Router /crm/chart_permission/edit [post]
  77. func (cp *ChartPermissionController) EditChartPermission(c *gin.Context) {
  78. var req crm.PermissionEditReq
  79. err := c.Bind(&req)
  80. if err != nil {
  81. errs, ok := err.(validator.ValidationErrors)
  82. if !ok {
  83. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  84. return
  85. }
  86. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  87. return
  88. }
  89. if req.PermissionName == "" {
  90. resp.Fail("请输入品种名称", c)
  91. return
  92. }
  93. if req.ChartPermissionId <= 0 {
  94. resp.Fail("请选择品种", c)
  95. return
  96. }
  97. e, msg := crmService.EditChartPermission(req)
  98. if e != nil {
  99. resp.FailData(msg, e.Error(), c)
  100. return
  101. }
  102. resp.Ok("操作成功", c)
  103. }
  104. // MoveChartPermission
  105. // @Description 移动品种
  106. // @Success 200 {string} string "操作成功"
  107. // @Router /crm/chart_permission/move [post]
  108. func (cp *ChartPermissionController) MoveChartPermission(c *gin.Context) {
  109. var req crm.PermissionMoveReq
  110. err := c.Bind(&req)
  111. if err != nil {
  112. errs, ok := err.(validator.ValidationErrors)
  113. if !ok {
  114. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  115. return
  116. }
  117. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  118. return
  119. }
  120. if req.ChartPermissionId <= 0 {
  121. resp.Fail("请选择品种", c)
  122. return
  123. }
  124. e, msg := crmService.MoveChartPermission(req)
  125. if e != nil {
  126. resp.FailData(msg, e.Error(), c)
  127. return
  128. }
  129. resp.Ok("操作成功", c)
  130. }
  131. // GetClassifyChartPermission
  132. // @Description 获取报告分类绑定的品种
  133. // @Success 200 {string} string "查询成功"
  134. // @Router /crm/chart_permission/classify [post]
  135. func (cp *ChartPermissionController) GetClassifyChartPermission(c *gin.Context) {
  136. var req crm.ClassifyPermissionReq
  137. err := c.Bind(&req)
  138. if err != nil {
  139. errs, ok := err.(validator.ValidationErrors)
  140. if !ok {
  141. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  142. return
  143. }
  144. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  145. return
  146. }
  147. ob := new(crm.ChartPermissionSearchKeyWordMapping)
  148. list := make([]*crm.ChartPermissionSearchKeyWordMapping, 0)
  149. if req.Keyword == "" {
  150. list, err = ob.GetPermission()
  151. } else {
  152. list, err = ob.GetPermissionByKeyword(req.Keyword)
  153. }
  154. if err != nil {
  155. resp.FailData("查询分类权限失败", err.Error(), c)
  156. return
  157. }
  158. data := crm.ClassifyPermissionResp{List: list}
  159. resp.OkData("查询成功", data, c)
  160. }
  161. // EditClassifyChartPermission
  162. // @Description 编辑分类权限
  163. // @Success 200 {string} string "操作成功"
  164. // @Router /crm/chart_permission/classify/edit [post]
  165. func (cp *ChartPermissionController) EditClassifyChartPermission(c *gin.Context) {
  166. var req crm.ClassifyPermissionEditReq
  167. err := c.Bind(&req)
  168. if err != nil {
  169. errs, ok := err.(validator.ValidationErrors)
  170. if !ok {
  171. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  172. return
  173. }
  174. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  175. return
  176. }
  177. if req.Keyword == "" {
  178. resp.Fail("分类名称不能为空", c)
  179. return
  180. }
  181. if req.NewKeyword == "" {
  182. resp.Fail("分类名称不能为空", c)
  183. return
  184. }
  185. if len(req.ChartPermissionIdList) == 0 {
  186. resp.Fail("请选择权限", c)
  187. return
  188. }
  189. ob := new(crm.ChartPermissionSearchKeyWordMapping)
  190. e := ob.EditChartPermissionSearchKeyWordMappingMulti(req.Keyword, req.NewKeyword, req.ChartPermissionIdList)
  191. if e != nil {
  192. resp.FailData("设置分类权限失败", e.Error(), c)
  193. return
  194. }
  195. resp.Ok("操作成功", c)
  196. }