完善了用户登录

This commit is contained in:
chen-xin-zhi 2024-11-04 12:45:26 +08:00
parent 70b59a5bc7
commit 92de3d4da4
3 changed files with 34 additions and 10 deletions

View File

@ -10,6 +10,7 @@ import com.cultural.heritage.model.dto.address.AddressAddRequest;
import com.cultural.heritage.model.dto.address.AddressUpdateRequest; import com.cultural.heritage.model.dto.address.AddressUpdateRequest;
import com.cultural.heritage.model.entity.Address; import com.cultural.heritage.model.entity.Address;
import com.cultural.heritage.service.address.AddressService; import com.cultural.heritage.service.address.AddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -24,7 +25,7 @@ import java.util.List;
@RestController @RestController
@RequestMapping("/address") @RequestMapping("/address")
@Slf4j @Slf4j
@Tag(name = "地址接口") @Tag(name = "地址管理模块")
public class AddressController { public class AddressController {
@ -38,6 +39,7 @@ public class AddressController {
* @return 是否添加成功 * @return 是否添加成功
*/ */
@PostMapping("/add") @PostMapping("/add")
@Operation(summary = "小程序端用户添加地址信息", description = "参数地址添加请求体权限所有人方法名addAddress")
public BaseResponse<Boolean> addAddress(@RequestBody AddressAddRequest addressAddRequest) { public BaseResponse<Boolean> addAddress(@RequestBody AddressAddRequest addressAddRequest) {
if (addressAddRequest == null) { if (addressAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -58,6 +60,7 @@ public class AddressController {
* @return 是否成功删除 * @return 是否成功删除
*/ */
@PostMapping("/delete") @PostMapping("/delete")
@Operation(summary = "小程序端用户删除地址信息", description = "参数地址删除请求体权限所有人方法名delAddress")
public BaseResponse<Boolean> delAddress(@RequestBody CommonRequest deleteRequest) { public BaseResponse<Boolean> delAddress(@RequestBody CommonRequest deleteRequest) {
if (deleteRequest == null || deleteRequest.getId() <= 0) { if (deleteRequest == null || deleteRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -77,6 +80,7 @@ public class AddressController {
* @return 是否更新成功 * @return 是否更新成功
*/ */
@PostMapping("/update") @PostMapping("/update")
// @Operation(summary = "小程序端用户更新地址信息", )
public BaseResponse<Boolean> updateAddress(@RequestBody AddressUpdateRequest addressUpdateRequest) { public BaseResponse<Boolean> updateAddress(@RequestBody AddressUpdateRequest addressUpdateRequest) {
if (addressUpdateRequest == null || addressUpdateRequest.getId() <= 0) { if (addressUpdateRequest == null || addressUpdateRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);

View File

@ -20,7 +20,10 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;

View File

@ -5,10 +5,12 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cultural.heritage.annotation.AuthCheck;
import com.cultural.heritage.common.BaseResponse; import com.cultural.heritage.common.BaseResponse;
import com.cultural.heritage.common.ErrorCode; import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.common.ResultUtils; import com.cultural.heritage.common.ResultUtils;
import com.cultural.heritage.config.WxOpenConfig; import com.cultural.heritage.config.WxOpenConfig;
import com.cultural.heritage.constant.UserConstant;
import com.cultural.heritage.exception.BusinessException; import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.CommonRequest; import com.cultural.heritage.model.dto.CommonRequest;
@ -16,6 +18,7 @@ import com.cultural.heritage.model.dto.user.*;
import com.cultural.heritage.model.entity.User; import com.cultural.heritage.model.entity.User;
import com.cultural.heritage.model.vo.UserVO; import com.cultural.heritage.model.vo.UserVO;
import com.cultural.heritage.service.user.UserService; import com.cultural.heritage.service.user.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -36,7 +39,7 @@ import static com.cultural.heritage.constant.UserConstant.SALT;
*/ */
@Slf4j @Slf4j
@RestController @RestController
@Tag(name = "用户接口") @Tag(name = "用户管理模块")
@RequestMapping("/user") @RequestMapping("/user")
public class UserController { public class UserController {
@ -56,6 +59,8 @@ public class UserController {
* @return 登录用户信息 * @return 登录用户信息
*/ */
@PostMapping("/login") @PostMapping("/login")
@Operation(summary = "Web端用户登录", description = "参数:{账号,密码}, 权限:管理员(admin, boss), 方法名userLogin")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<UserVO> userLogin(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request){ public BaseResponse<UserVO> userLogin(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request){
if(userLoginRequest == null) { if(userLoginRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -79,6 +84,7 @@ public class UserController {
* @return 用户登录信息 * @return 用户登录信息
*/ */
@GetMapping("/login/wx_open") @GetMapping("/login/wx_open")
@Operation(summary = "微信小程序用户登录", description = "参数code(用户登录凭证), 权限:所有人, 方法名userLoginByWxOpen")
public BaseResponse<UserVO> userLoginByWxOpen(@RequestParam("code") String code, HttpServletRequest request) { public BaseResponse<UserVO> userLoginByWxOpen(@RequestParam("code") String code, HttpServletRequest request) {
WxMaJscode2SessionResult sessionInfo; WxMaJscode2SessionResult sessionInfo;
try { try {
@ -103,6 +109,8 @@ public class UserController {
* @return 是否退出登录成功 * @return 是否退出登录成功
*/ */
@PostMapping("/logout") @PostMapping("/logout")
@Operation(summary = "Web端管理员退出登录", description = "参数:无,权限:管理员(admin, boss)方法名userLogout")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> userLogout(HttpServletRequest request) { public BaseResponse<Boolean> userLogout(HttpServletRequest request) {
boolean result = userService.userLogout(request); boolean result = userService.userLogout(request);
return ResultUtils.success(result); return ResultUtils.success(result);
@ -114,6 +122,7 @@ public class UserController {
* @return 用户登录信息 * @return 用户登录信息
*/ */
@GetMapping("/get/login") @GetMapping("/get/login")
@Operation(summary = "小程序端获取登录信息", description = "参数:无,权限:所有人, 方法名getLoginUser")
public BaseResponse<UserVO> getLoginUser(HttpServletRequest request) { public BaseResponse<UserVO> getLoginUser(HttpServletRequest request) {
User user = userService.getLoginUser(request); User user = userService.getLoginUser(request);
return ResultUtils.success(userService.getUserVO(user)); return ResultUtils.success(userService.getUserVO(user));
@ -128,6 +137,7 @@ public class UserController {
* @return 是否更新成功 * @return 是否更新成功
*/ */
@PostMapping("/update/my") @PostMapping("/update/my")
@Operation(summary = "小程序端更新用户信息", description = "参数:用户更新请求体,权限:所有人, 方法名updateMyUser")
public BaseResponse<Boolean> updateMyUser(@RequestBody UserUpdateMyRequest userUpdateMyRequest, HttpServletRequest request) { public BaseResponse<Boolean> updateMyUser(@RequestBody UserUpdateMyRequest userUpdateMyRequest, HttpServletRequest request) {
if (userUpdateMyRequest == null) { if (userUpdateMyRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -148,7 +158,8 @@ public class UserController {
* @return 添加用户的信息 * @return 添加用户的信息
*/ */
@PostMapping("/add") @PostMapping("/add")
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) @Operation(summary = "Web端管理员创建用户", description = "参数:用户添加请求体, 权限:管理员(admin, boss), 方法名addUser")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<User> addUser(@RequestBody UserAddRequest userAddRequest) { public BaseResponse<User> addUser(@RequestBody UserAddRequest userAddRequest) {
if (userAddRequest == null) { if (userAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -171,7 +182,8 @@ public class UserController {
* @return 是否删除 * @return 是否删除
*/ */
@PostMapping("/delete") @PostMapping("/delete")
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) @Operation(summary = "Web端管理员删除用户", description = "参数:用户删除请求体, 权限:管理员(admin, boss), 方法名deleteUser")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> deleteUser(@RequestBody CommonRequest deleteRequest) { public BaseResponse<Boolean> deleteUser(@RequestBody CommonRequest deleteRequest) {
if (deleteRequest == null || deleteRequest.getId() <= 0) { if (deleteRequest == null || deleteRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -188,7 +200,8 @@ public class UserController {
* @return 是否更新成功 * @return 是否更新成功
*/ */
@PostMapping("/update") @PostMapping("/update")
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) @Operation(summary = "Web端管理员更新用户", description = "参数:用户更新请求体, 权限:管理员(admin, boss), 方法名updateUser")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> updateUser(@RequestBody UserUpdateRequest userUpdateRequest) { public BaseResponse<Boolean> updateUser(@RequestBody UserUpdateRequest userUpdateRequest) {
if (userUpdateRequest == null || userUpdateRequest.getId() <= 0) { if (userUpdateRequest == null || userUpdateRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -207,7 +220,8 @@ public class UserController {
* @return 用户信息 * @return 用户信息
*/ */
@GetMapping("/get") @GetMapping("/get")
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) @Operation(summary = "Web端管理员根据id获取用户信息", description = "参数用户id, 权限:管理员(admin, boss), 方法名getUserById")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<User> getUserById(long id) { public BaseResponse<User> getUserById(long id) {
if (id <= 0) { if (id <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -222,7 +236,8 @@ public class UserController {
* 获取用户数量 * 获取用户数量
*/ */
@GetMapping("/count") @GetMapping("/count")
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) @Operation(summary = "Web端管理员获取用户数量", description = "参数:无, 权限:管理员(admin, boss), 方法名getUserCount")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Long> getUserCount() { public BaseResponse<Long> getUserCount() {
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userRole", "user"); queryWrapper.eq("userRole", "user");
@ -238,7 +253,8 @@ public class UserController {
* @return 用户信息列表 * @return 用户信息列表
*/ */
@PostMapping("/list/page") @PostMapping("/list/page")
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) @Operation(summary = "Web端管理员分页获取用户信息", description = "参数:用户查询请求体, 权限:管理员(admin, boss), 方法名listUserByPage")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Page<User>> listUserByPage(@RequestBody UserQueryRequest userQueryRequest) { public BaseResponse<Page<User>> listUserByPage(@RequestBody UserQueryRequest userQueryRequest) {
long current = userQueryRequest.getCurrent(); long current = userQueryRequest.getCurrent();
long pageSize = userQueryRequest.getPageSize(); long pageSize = userQueryRequest.getPageSize();
@ -256,7 +272,8 @@ public class UserController {
* @return 脱敏用户信息列表 * @return 脱敏用户信息列表
*/ */
@PostMapping("/list/page/vo") @PostMapping("/list/page/vo")
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) @Operation(summary = "Web端管理员分页获取脱敏用户信息", description = "参数:用户查询请求体, 权限:管理员(admin, boss), 方法名listUserVOByPage")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Page<UserVO>> listUserVOByPage(@RequestBody UserQueryRequest userQueryRequest) { public BaseResponse<Page<UserVO>> listUserVOByPage(@RequestBody UserQueryRequest userQueryRequest) {
if (userQueryRequest == null) { if (userQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR); throw new BusinessException(ErrorCode.PARAMS_ERROR);