AuthClubApi.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package com.caimei.controller.admin.auth;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.caimei.annotation.CurrentUser;
  4. import com.caimei.model.ResponseJson;
  5. import com.caimei.model.po.SysUser;
  6. import com.caimei.model.vo.ClubUserVo;
  7. import com.caimei.model.vo.ClubVo;
  8. import com.caimei.service.auth.AuthClubService;
  9. import com.github.pagehelper.PageInfo;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiImplicitParam;
  12. import io.swagger.annotations.ApiImplicitParams;
  13. import io.swagger.annotations.ApiOperation;
  14. import lombok.RequiredArgsConstructor;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.web.bind.annotation.*;
  18. import java.util.Map;
  19. /**
  20. * 供应商API
  21. *
  22. * @author : Aslee
  23. * @date : 2021/5/11
  24. */
  25. @Api(tags = "机构用户API")
  26. @Slf4j
  27. @RestController
  28. @RequiredArgsConstructor
  29. @RequestMapping("/club")
  30. public class AuthClubApi {
  31. private final AuthClubService authClubService;
  32. @ApiOperation("机构列表")
  33. @ApiImplicitParams({
  34. @ApiImplicitParam(name = "authParty", required = false, value = "机构名称"),
  35. @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
  36. @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
  37. })
  38. @GetMapping("/list")
  39. public ResponseJson<PageInfo<ClubVo>> getClubList(@CurrentUser SysUser sysUser, String authParty,
  40. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  41. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  42. if (null == sysUser) {
  43. return ResponseJson.error("用户信息异常", null);
  44. }
  45. // 获取供应商用户id
  46. Integer userIdentity = sysUser.getUserIdentity();
  47. Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
  48. if (null == authUserId) {
  49. return ResponseJson.error("供应商用户id不能为空", null);
  50. }
  51. return authClubService.getClubList(authUserId, authParty, pageNum, pageSize);
  52. }
  53. @ApiOperation("机构用户列表")
  54. @GetMapping("/user/list")
  55. @ApiImplicitParams({
  56. @ApiImplicitParam(name = "mobile", required = false, value = "手机号"),
  57. @ApiImplicitParam(name = "name", required = false, value = "姓名"),
  58. @ApiImplicitParam(name = "status", required = false, value = "状态:0停用,1启用"),
  59. @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
  60. @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
  61. })
  62. public ResponseJson<PageInfo<ClubUserVo>> getClubUserList(@CurrentUser SysUser sysUser, String mobile, String name, Integer status,
  63. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  64. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  65. if (null == sysUser) {
  66. return ResponseJson.error("用户信息异常", null);
  67. }
  68. // 获取供应商用户id
  69. Integer userIdentity = sysUser.getUserIdentity();
  70. Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
  71. if (null == authUserId) {
  72. return ResponseJson.error("供应商用户id不能为空", null);
  73. }
  74. return authClubService.getClubUserList(authUserId, mobile, name, status, pageNum, pageSize);
  75. }
  76. @ApiOperation("添加/编辑机构用户")
  77. @PostMapping("/user/save")
  78. @ApiImplicitParam(name = "params", value = "clubUserId:机构用户id;mobile:手机号", required = true)
  79. public ResponseJson saveClubUser(@CurrentUser SysUser sysUser, @RequestBody String params) {
  80. if (null == sysUser) {
  81. return ResponseJson.error("用户信息异常", null);
  82. }
  83. // 获取供应商用户id
  84. Integer userIdentity = sysUser.getUserIdentity();
  85. Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
  86. if (null == authUserId) {
  87. return ResponseJson.error("供应商用户id不能为空", null);
  88. }
  89. JSONObject paramsMap = JSONObject.parseObject(params);
  90. Integer clubUserId = paramsMap.getInteger("clubUserId");
  91. String mobile = paramsMap.getString("mobile");
  92. if (StringUtils.isEmpty(mobile)) {
  93. return ResponseJson.error("参数异常,请输入手机号");
  94. }
  95. return authClubService.saveClubUser(clubUserId, authUserId, mobile);
  96. }
  97. @ApiOperation("删除机构用户")
  98. @PostMapping("/user/delete")
  99. @ApiImplicitParam(name = "params", value = "clubUserId:机构用户id", required = true)
  100. public ResponseJson deleteClubUser(@RequestBody String params) {
  101. JSONObject paramsMap = JSONObject.parseObject(params);
  102. Integer clubUserId = paramsMap.getInteger("clubUserId");
  103. if (null == clubUserId) {
  104. return ResponseJson.error("参数异常,机构用户id不能为空");
  105. }
  106. return authClubService.deleteClubUser(clubUserId);
  107. }
  108. @ApiOperation("更新用户状态")
  109. @PostMapping("/user/status/update")
  110. @ApiImplicitParam(name = "params", value = "clubUserId:机构用户id;status:状态:0停用,1启用", required = true)
  111. public ResponseJson updateStatus(@RequestBody String params) {
  112. JSONObject paramsMap = JSONObject.parseObject(params);
  113. Integer clubUserId = paramsMap.getInteger("clubUserId");
  114. Integer status = paramsMap.getInteger("status");
  115. if (null == clubUserId) {
  116. return ResponseJson.error("参数异常,机构用户id不能为空");
  117. }
  118. if (null == status) {
  119. return ResponseJson.error("参数异常,状态不能为空");
  120. }
  121. return authClubService.updateStatus(clubUserId, status);
  122. }
  123. @ApiOperation("重置密码")
  124. @ApiImplicitParam(name = "params", value = "clubUserId:机构用户id", required = true)
  125. @PostMapping("/user/reset/password")
  126. public ResponseJson resetShopPassword(@RequestBody Map<String,Integer> params) {
  127. Integer clubUserId = params.get("clubUserId");
  128. return authClubService.resetClubUserPassword(clubUserId);
  129. }
  130. }