123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- package crm
- import (
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "hongze/hz_crm_eta/controller/resp"
- "hongze/hz_crm_eta/global"
- "hongze/hz_crm_eta/models/crm"
- "hongze/hz_crm_eta/models/request"
- crmService "hongze/hz_crm_eta/services/crm"
- )
- type ChartPermissionController struct{}
- // GetChartPermission
- // @Description 获取品种列表
- // @Success 200 {string} string "操作成功"
- // @Router /crm/chart_permission/list [post]
- func (cp *ChartPermissionController) GetChartPermission(c *gin.Context) {
- var req request.ChartPermissionReq
- err := c.Bind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- cond := ` 1=1`
- pars := make([]interface{}, 0)
- if req.ProductId > 0 {
- cond += " and product_id = ?"
- pars = append(pars, req.ProductId)
- }
- if req.ChartPermissionId > 0 {
- cond += " and chart_permission_id = ?"
- pars = append(pars, req.ChartPermissionId)
- }
- list, e := crmService.GetChartPermissionList(cond, pars)
- if e != nil {
- resp.FailData("查询失败", e.Error(), c)
- return
- }
- data := request.ChartPermissionResp{List: list}
- resp.OkData("操作成功", data, c)
- }
- // AddChartPermission
- // @Description 新增品种
- // @Success 200 {string} string "操作成功"
- // @Router /crm/chart_permission/add [post]
- func (cp *ChartPermissionController) AddChartPermission(c *gin.Context) {
- var req crm.PermissionAddReq
- err := c.Bind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- if req.PermissionName == "" {
- resp.Fail("请输入品种名称", c)
- return
- }
- e, msg := crmService.AddChartPermission(req)
- if e != nil {
- resp.FailData(msg, e.Error(), c)
- return
- }
- resp.Ok("操作成功", c)
- }
- // EditChartPermission
- // @Description 编辑品种
- // @Success 200 {string} string "操作成功"
- // @Router /crm/chart_permission/edit [post]
- func (cp *ChartPermissionController) EditChartPermission(c *gin.Context) {
- var req crm.PermissionEditReq
- err := c.Bind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- if req.PermissionName == "" {
- resp.Fail("请输入品种名称", c)
- return
- }
- if req.ChartPermissionId <= 0 {
- resp.Fail("请选择品种", c)
- return
- }
- e, msg := crmService.EditChartPermission(req)
- if e != nil {
- resp.FailData(msg, e.Error(), c)
- return
- }
- resp.Ok("操作成功", c)
- }
- // MoveChartPermission
- // @Description 移动品种
- // @Success 200 {string} string "操作成功"
- // @Router /crm/chart_permission/move [post]
- func (cp *ChartPermissionController) MoveChartPermission(c *gin.Context) {
- var req crm.PermissionMoveReq
- err := c.Bind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- if req.ChartPermissionId <= 0 {
- resp.Fail("请选择品种", c)
- return
- }
- e, msg := crmService.MoveChartPermission(req)
- if e != nil {
- resp.FailData(msg, e.Error(), c)
- return
- }
- resp.Ok("操作成功", c)
- }
- // GetClassifyChartPermission
- // @Description 获取报告分类绑定的品种
- // @Success 200 {string} string "查询成功"
- // @Router /crm/chart_permission/classify [post]
- func (cp *ChartPermissionController) GetClassifyChartPermission(c *gin.Context) {
- var req crm.ClassifyPermissionReq
- err := c.Bind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- ob := new(crm.ChartPermissionSearchKeyWordMapping)
- list := make([]*crm.ChartPermissionSearchKeyWordMapping, 0)
- if req.Keyword == "" {
- list, err = ob.GetPermission()
- } else {
- list, err = ob.GetPermissionByKeyword(req.Keyword)
- }
- if err != nil {
- resp.FailData("查询分类权限失败", err.Error(), c)
- return
- }
- data := crm.ClassifyPermissionResp{List: list}
- resp.OkData("查询成功", data, c)
- }
- // EditClassifyChartPermission
- // @Description 编辑分类权限
- // @Success 200 {string} string "操作成功"
- // @Router /crm/chart_permission/classify/edit [post]
- func (cp *ChartPermissionController) EditClassifyChartPermission(c *gin.Context) {
- var req crm.ClassifyPermissionEditReq
- err := c.Bind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- if req.Keyword == "" {
- resp.Fail("分类名称不能为空", c)
- return
- }
- if req.NewKeyword == "" {
- resp.Fail("分类名称不能为空", c)
- return
- }
- if len(req.ChartPermissionIdList) == 0 {
- resp.Fail("请选择权限", c)
- return
- }
- ob := new(crm.ChartPermissionSearchKeyWordMapping)
- e := ob.EditChartPermissionSearchKeyWordMappingMulti(req.Keyword, req.NewKeyword, req.ChartPermissionIdList)
- if e != nil {
- resp.FailData("设置分类权限失败", e.Error(), c)
- return
- }
- resp.Ok("操作成功", c)
- }
|