system_user.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-applete-gateway/errors"
  10. param_v1 "property-applete-gateway/param/v1"
  11. "property-applete-gateway/pb"
  12. "property-applete-gateway/pb/v1"
  13. "property-applete-gateway/utils"
  14. )
  15. //
  16. // @Summary 用户列表
  17. // @Description 用户列表
  18. // @Tags 用户管理
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "token"
  22. // @Param page query int true " "
  23. // @Param page_size query int false " "
  24. // @Param group_id query int false "权限组id"
  25. // @Param user_name query string false "用户名"
  26. // @Param phone query string false "电话号"
  27. // @Success 200 {object} v1.UserListResponse
  28. // @Failure 500 {object} base.HTTPError
  29. // @Router /api/v1/system_user [get]
  30. func (c *Controller) UserList(ctx *gin.Context) {
  31. // 解析参数
  32. req := &param_v1.UserListRequest{}
  33. parseParamTask := func() error {
  34. err := util.ShouldBind(ctx, &req.Header, nil, &req.UserListQuery, nil)
  35. if err != nil {
  36. logger.Error("func",
  37. zap.String("call", "util.ShouldBind"),
  38. zap.String("error", err.Error()))
  39. return errors.ParamsError
  40. }
  41. return nil
  42. }
  43. // 业务处理
  44. handleServiceTask := func() error {
  45. tokenInfo, err := utils.GetSubjectValue(ctx)
  46. if err != nil {
  47. return err
  48. }
  49. // 响应数据
  50. resp := param_v1.UserListResponse{}
  51. rpcReq := &v1.UserListRequest{
  52. UserName:req.UserName,
  53. Phone:req.Phone,
  54. Cid:tokenInfo.Cid,
  55. GardenId:tokenInfo.GardenId,
  56. GroupId:req.GroupId,
  57. }
  58. rpcRsp, err := pb.System.UserList(ctx, rpcReq)
  59. if err != nil {
  60. s, _ := json.MarshalToString(req)
  61. logger.Error("func",
  62. zap.String("call", "pb.System.UserList"),
  63. zap.String("params", s),
  64. zap.String("error", err.Error()))
  65. return errors.ErrorTransForm(err)
  66. }
  67. if rpcRsp.List == nil {
  68. rpcRsp.List = make([]*v1.UserItem, 0)
  69. }
  70. resp.Data = *rpcRsp
  71. ctx.JSON(http.StatusOK, resp)
  72. return nil
  73. }
  74. // 执行任务
  75. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  76. }