package com.caimei.controller.admin.auth; import com.alibaba.fastjson.JSONObject; import com.caimei.annotation.CurrentUser; import com.caimei.model.ResponseJson; import com.caimei.model.po.SysUser; import com.caimei.model.vo.ClubUserVo; import com.caimei.model.vo.ClubVo; import com.caimei.service.auth.AuthClubService; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.*; import java.util.Map; /** * 供应商API * * @author : Aslee * @date : 2021/5/11 */ @Api(tags = "机构用户API") @Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/club") public class AuthClubApi { private final AuthClubService authClubService; @ApiOperation("机构列表") @ApiImplicitParams({ @ApiImplicitParam(name = "authParty", required = false, value = "机构名称"), @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"), @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条") }) @GetMapping("/list") public ResponseJson> getClubList(@CurrentUser SysUser sysUser, String authParty, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { if (null == sysUser) { return ResponseJson.error("用户信息异常", null); } // 获取供应商用户id Integer userIdentity = sysUser.getUserIdentity(); Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null; if (null == authUserId) { return ResponseJson.error("供应商用户id不能为空", null); } return authClubService.getClubList(authUserId, authParty, pageNum, pageSize); } @ApiOperation("机构用户列表") @GetMapping("/user/list") @ApiImplicitParams({ @ApiImplicitParam(name = "mobile", required = false, value = "手机号"), @ApiImplicitParam(name = "name", required = false, value = "姓名"), @ApiImplicitParam(name = "status", required = false, value = "状态:0停用,1启用"), @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"), @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条") }) public ResponseJson> getClubUserList(@CurrentUser SysUser sysUser, String mobile, String name, Integer status, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { if (null == sysUser) { return ResponseJson.error("用户信息异常", null); } // 获取供应商用户id Integer userIdentity = sysUser.getUserIdentity(); Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null; if (null == authUserId) { return ResponseJson.error("供应商用户id不能为空", null); } return authClubService.getClubUserList(authUserId, mobile, name, status, pageNum, pageSize); } @ApiOperation("添加/编辑机构用户") @PostMapping("/user/save") @ApiImplicitParam(name = "params", value = "clubUserId:机构用户id;mobile:手机号", required = true) public ResponseJson saveClubUser(@CurrentUser SysUser sysUser, @RequestBody String params) { if (null == sysUser) { return ResponseJson.error("用户信息异常", null); } // 获取供应商用户id Integer userIdentity = sysUser.getUserIdentity(); Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null; if (null == authUserId) { return ResponseJson.error("供应商用户id不能为空", null); } JSONObject paramsMap = JSONObject.parseObject(params); Integer clubUserId = paramsMap.getInteger("clubUserId"); String mobile = paramsMap.getString("mobile"); if (StringUtils.isEmpty(mobile)) { return ResponseJson.error("参数异常,请输入手机号"); } return authClubService.saveClubUser(clubUserId, authUserId, mobile); } @ApiOperation("删除机构用户") @PostMapping("/user/delete") @ApiImplicitParam(name = "params", value = "clubUserId:机构用户id", required = true) public ResponseJson deleteClubUser(@RequestBody String params) { JSONObject paramsMap = JSONObject.parseObject(params); Integer clubUserId = paramsMap.getInteger("clubUserId"); if (null == clubUserId) { return ResponseJson.error("参数异常,机构用户id不能为空"); } return authClubService.deleteClubUser(clubUserId); } @ApiOperation("更新用户状态") @PostMapping("/user/status/update") @ApiImplicitParam(name = "params", value = "clubUserId:机构用户id;status:状态:0停用,1启用", required = true) public ResponseJson updateStatus(@RequestBody String params) { JSONObject paramsMap = JSONObject.parseObject(params); Integer clubUserId = paramsMap.getInteger("clubUserId"); Integer status = paramsMap.getInteger("status"); if (null == clubUserId) { return ResponseJson.error("参数异常,机构用户id不能为空"); } if (null == status) { return ResponseJson.error("参数异常,状态不能为空"); } return authClubService.updateStatus(clubUserId, status); } @ApiOperation("重置密码") @ApiImplicitParam(name = "params", value = "clubUserId:机构用户id", required = true) @PostMapping("/user/reset/password") public ResponseJson resetShopPassword(@RequestBody Map params) { Integer clubUserId = params.get("clubUserId"); return authClubService.resetClubUserPassword(clubUserId); } }