chart_permission.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package controllers
  2. import (
  3. "eta/eta_mini_crm/models"
  4. "eta/eta_mini_crm/models/response"
  5. "eta/eta_mini_crm/services"
  6. )
  7. type ChartPermissionController struct {
  8. BaseAuthController
  9. }
  10. // List
  11. // @Title 系统品种列表
  12. // @Description 系统品种列表
  13. // @Param UserId query int true "角色ID"
  14. // @Success 200 {object} models.LoginResp
  15. // @router /list [get]
  16. func (this *ChartPermissionController) List() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. userId, _ := this.GetInt("UserId")
  23. publicMap, privateMap, err := services.GetChartPermissionList()
  24. if err != nil {
  25. br.Msg = "权限列表获取失败"
  26. br.ErrMsg = "权限列表获取失败,系统错误,Err:" + err.Error()
  27. return
  28. }
  29. resp := new(response.ChartPermissionListresp)
  30. if userId > 0 {
  31. ids, err := models.GetChartPermissionIdByUserId(userId)
  32. if err != nil {
  33. br.Msg = "权限列表获取失败"
  34. br.ErrMsg = "权限列表获取失败,系统错误,Err:" + err.Error()
  35. }
  36. resp.SelectedList = ids
  37. }
  38. for _, per := range publicMap {
  39. resp.PublicList = append(resp.PublicList, per)
  40. }
  41. for _, per := range privateMap {
  42. resp.PrivateList = append(resp.PrivateList, per)
  43. }
  44. br.Ret = 200
  45. br.Data = resp
  46. br.Msg = "列表获取成功"
  47. br.Success = true
  48. }