完善了用户登录

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

View File

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