From 3471a30fab6b55b8fbdf194e74382505d9c72c52 Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Tue, 5 Nov 2024 01:39:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../heritage/aop/AuthInterceptor.java | 82 ++++++++----------- .../cultural/heritage/common/PageRequest.java | 5 ++ .../controller/good/CategoryController.java | 11 ++- .../controller/good/CouponController.java | 10 ++- .../controller/good/GoodController.java | 12 +-- .../controller/order/OrderController.java | 8 +- .../controller/user/UserController.java | 26 +++--- .../model/dto/CommonDelBatchRequest.java | 5 ++ .../heritage/model/dto/CommonRequest.java | 3 + .../model/dto/address/AddressAddRequest.java | 8 ++ .../dto/address/AddressUpdateRequest.java | 9 ++ .../model/dto/cart/CartRecordAddRequest.java | 7 +- .../dto/cart/CartRecordUpdateRequest.java | 9 +- .../dto/category/CategoryAddRequest.java | 5 ++ .../dto/contacts/ContactsAddRequest.java | 6 ++ .../dto/contacts/ContactsUpdateRequest.java | 10 ++- .../model/dto/coupon/CouponAddRequest.java | 14 ++++ .../model/dto/coupon/CouponQueryRequest.java | 8 +- .../model/dto/coupon/CouponUpdateRequest.java | 20 +++++ .../dto/exchange/ExchangeAddRequest.java | 9 +- .../model/dto/file/UploadFileRequest.java | 3 + .../model/dto/good/GoodAddRequest.java | 13 +++ .../model/dto/good/GoodQueryRequest.java | 7 ++ .../model/dto/good/GoodUpdateRequest.java | 15 ++++ .../model/dto/order/OrderAddRequest.java | 10 +++ .../model/dto/order/OrderItemAddRequest.java | 8 ++ .../model/dto/order/OrderQueryRequest.java | 11 ++- .../model/dto/order/OrderUpdateRequest.java | 4 + .../model/dto/snapshot/AddressSnapshot.java | 6 ++ .../model/dto/snapshot/ContactsSnapshot.java | 4 + .../model/dto/snapshot/CouponSnapshot.java | 4 + .../model/dto/snapshot/GoodSnapshot.java | 8 ++ .../model/dto/user/UserAddRequest.java | 8 ++ .../model/dto/user/UserLoginRequest.java | 11 +++ .../model/dto/user/UserQueryRequest.java | 7 ++ .../model/dto/user/UserUpdateMyRequest.java | 5 ++ .../model/dto/user/UserUpdateRequest.java | 8 ++ .../service/user/impl/UserServiceImpl.java | 52 ++++++------ 38 files changed, 340 insertions(+), 111 deletions(-) diff --git a/src/main/java/com/cultural/heritage/aop/AuthInterceptor.java b/src/main/java/com/cultural/heritage/aop/AuthInterceptor.java index 6541263..a6e5021 100644 --- a/src/main/java/com/cultural/heritage/aop/AuthInterceptor.java +++ b/src/main/java/com/cultural/heritage/aop/AuthInterceptor.java @@ -1,22 +1,12 @@ package com.cultural.heritage.aop; import com.cultural.heritage.annotation.AuthCheck; -import com.cultural.heritage.common.ErrorCode; -import com.cultural.heritage.constant.UserConstant; -import com.cultural.heritage.exception.BusinessException; -import com.cultural.heritage.model.entity.User; -import com.cultural.heritage.model.enums.UserRoleEnum; import com.cultural.heritage.service.user.UserService; -import io.micrometer.common.util.StringUtils; import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletRequest; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; -import org.springframework.web.context.request.RequestAttributes; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; /** * 权限校验AOP @@ -34,42 +24,42 @@ public class AuthInterceptor { @Around("@annotation(authCheck)") public Object doInterceptor(ProceedingJoinPoint joinPoint, AuthCheck authCheck) throws Throwable { //接口的权限 - String mustRole = authCheck.mustRole(); - RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); - HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); - - //当前登录用户 - User loginUser = userService.getLoginUser(request); - //必须有该权限才通过 - if (StringUtils.isNotBlank(mustRole)) { - //mustUserRoleEnum是接口权限 - UserRoleEnum mustUserRoleEnum = UserRoleEnum.getEnumByValues(mustRole); - if(mustUserRoleEnum == null) { - throw new BusinessException(ErrorCode.NO_AUTH_ERROR); - } - //用户权限 - String userRole = loginUser.getUserRole(); - //根据用户角色获取封装后的枚举类对象 - UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValues(userRole); - - //如果被封号,直接拒绝 - if (UserRoleEnum.BAN.equals(userRoleEnum)) { - throw new BusinessException(ErrorCode.NO_AUTH_ERROR); - } - - //如果接口需要Boss权限,则需要判断用户是否是boss管理员 - if (UserRoleEnum.BOSS.equals(mustUserRoleEnum)) { - if (!mustRole.equals(userRole)) { - throw new BusinessException(ErrorCode.NO_AUTH_ERROR); - } - } - //如果接口需要管理员权限,则需要判断用户是否是boss或者admin管理员 - if (UserRoleEnum.ADMIN.equals(mustUserRoleEnum)) { - if (!mustRole.equals(userRole) && !userRole.equals(UserConstant.BOSS_ROLE)) { - throw new BusinessException(ErrorCode.NO_AUTH_ERROR); - } - } - } +// String mustRole = authCheck.mustRole(); +// RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); +// HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); +// +// //当前登录用户 +// User loginUser = userService.getLoginUser(request); +// //必须有该权限才通过 +// if (StringUtils.isNotBlank(mustRole)) { +// //mustUserRoleEnum是接口权限 +// UserRoleEnum mustUserRoleEnum = UserRoleEnum.getEnumByValues(mustRole); +// if(mustUserRoleEnum == null) { +// throw new BusinessException(ErrorCode.NO_AUTH_ERROR); +// } +// //用户权限 +// String userRole = loginUser.getUserRole(); +// //根据用户角色获取封装后的枚举类对象 +// UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValues(userRole); +// +// //如果被封号,直接拒绝 +// if (UserRoleEnum.BAN.equals(userRoleEnum)) { +// throw new BusinessException(ErrorCode.NO_AUTH_ERROR); +// } +// +// //如果接口需要Boss权限,则需要判断用户是否是boss管理员 +// if (UserRoleEnum.BOSS.equals(mustUserRoleEnum)) { +// if (!mustRole.equals(userRole)) { +// throw new BusinessException(ErrorCode.NO_AUTH_ERROR); +// } +// } +// //如果接口需要管理员权限,则需要判断用户是否是boss或者admin管理员 +// if (UserRoleEnum.ADMIN.equals(mustUserRoleEnum)) { +// if (!mustRole.equals(userRole) && !userRole.equals(UserConstant.BOSS_ROLE)) { +// throw new BusinessException(ErrorCode.NO_AUTH_ERROR); +// } +// } +// } //通过权限校验,放行 return joinPoint.proceed(); } diff --git a/src/main/java/com/cultural/heritage/common/PageRequest.java b/src/main/java/com/cultural/heritage/common/PageRequest.java index c94cc0f..6947d0b 100644 --- a/src/main/java/com/cultural/heritage/common/PageRequest.java +++ b/src/main/java/com/cultural/heritage/common/PageRequest.java @@ -1,6 +1,7 @@ package com.cultural.heritage.common; import com.cultural.heritage.constant.CommonConstant; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; /** @@ -12,20 +13,24 @@ public class PageRequest { /** * 当前页号 */ + @Schema(description = "当前页码", example = "1") private long current = 1; /** * 页面大小 */ + @Schema(description = "每页展示的记录条数", example = "3") private long pageSize = 10; /** * 排序字段 */ + @Schema(description = "排序字段", example = "id") private String sortField; /** * 排序顺序(默认升序) */ + @Schema(description = "排序顺序((升:ascend;降:descend", example = "ascend") private String sortOrder = CommonConstant.SORT_ORDER_ASC; } \ No newline at end of file diff --git a/src/main/java/com/cultural/heritage/controller/good/CategoryController.java b/src/main/java/com/cultural/heritage/controller/good/CategoryController.java index 8a1b6e6..ce93cce 100644 --- a/src/main/java/com/cultural/heritage/controller/good/CategoryController.java +++ b/src/main/java/com/cultural/heritage/controller/good/CategoryController.java @@ -1,9 +1,11 @@ package com.cultural.heritage.controller.good; +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.constant.UserConstant; import com.cultural.heritage.exception.BusinessException; import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.model.dto.CommonRequest; @@ -50,7 +52,7 @@ public class CategoryController { */ @PostMapping("/add") @Operation(summary = "Web端管理员添加商品类别", description = "参数:类别添加请求体,权限:管理员(admin, boss),方法名:addCategory") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse addCategory(@RequestBody CategoryAddRequest categoryAddRequest) { if (categoryAddRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -71,7 +73,7 @@ public class CategoryController { */ @PostMapping("/delete") @Operation(summary = "Web端管理员删除商品类别", description = "参数:类别删除请求体,权限:管理员(admin, boss),方法名:deleteCategory") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse deleteCategory(@RequestBody CommonRequest deleteCategoryRequest) { if (deleteCategoryRequest == null || deleteCategoryRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -91,7 +93,7 @@ public class CategoryController { */ @PostMapping("/update") @Operation(summary = "Web端管理员更新商品类别", description = "参数:类别更新请求体,权限:管理员(admin, boss),方法名:updateCategory") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse updateCategory(@RequestBody Category category) { if (category == null || category.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -108,7 +110,7 @@ public class CategoryController { * @return 商品类别列表 */ @PostMapping("/list") - @Operation(summary = "Web端管理员查询商品类别", description = "参数:无,权限:所有人,方法名:listCategory") + @Operation(summary = "小程序端用户查询商品类别", description = "参数:无,权限:所有人,方法名:listCategory") public BaseResponse> listCategory() { List list = categoryService.list(); return ResultUtils.success(list); @@ -122,6 +124,7 @@ public class CategoryController { * @return 当前类别的商品列表 */ @PostMapping("/list/type") + @Operation(summary = "小程序端用户根据类别id查询该类的所有商品", description = "参数:类别id,方法名:listGoodByCategory") public BaseResponse>> listGoodByCategory(@RequestBody CommonRequest categoryQueryRequest) { if (categoryQueryRequest == null || categoryQueryRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); diff --git a/src/main/java/com/cultural/heritage/controller/good/CouponController.java b/src/main/java/com/cultural/heritage/controller/good/CouponController.java index 90ce497..2d185da 100644 --- a/src/main/java/com/cultural/heritage/controller/good/CouponController.java +++ b/src/main/java/com/cultural/heritage/controller/good/CouponController.java @@ -2,9 +2,11 @@ package com.cultural.heritage.controller.good; 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.constant.UserConstant; import com.cultural.heritage.exception.BusinessException; import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.model.dto.CommonRequest; @@ -61,7 +63,7 @@ public class CouponController { */ @PostMapping("/add") @Operation(summary = "Web端管理员添加优惠券", description = "参数:优惠券添加请求体,权限:管理员(admin, boss),方法名:addCoupon") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse addCoupon(@RequestBody CouponAddRequest couponAddRequest) { if (couponAddRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -82,7 +84,7 @@ public class CouponController { */ @PostMapping("/update") @Operation(summary = "Web端管理员更新优惠券", description = "参数:优惠券更新请求体,权限:管理员(admin, boss),方法名:updateCoupon") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse updateCoupon(@RequestBody CouponUpdateRequest couponUpdateRequest) { if (couponUpdateRequest == null || couponUpdateRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -103,7 +105,7 @@ public class CouponController { */ @PostMapping("/delete") @Operation(summary = "Web端管理员删除优惠券", description = "参数:优惠券删除请求体,权限:管理员(admin, boss),方法名:deleteCoupon") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse deleteCoupon(@RequestBody CommonRequest couponDeleteRequest) { if (couponDeleteRequest == null || couponDeleteRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -123,7 +125,7 @@ public class CouponController { */ @PostMapping("/list/page") @Operation(summary = "Web端管理员分页查询优惠券", description = "参数:优惠券查询请求体,权限:管理员(admin, boss),方法名:listCouponVOByPage") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse> listCouponVOByPage(@RequestBody CouponQueryRequest couponQueryRequest) { if (couponQueryRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); diff --git a/src/main/java/com/cultural/heritage/controller/good/GoodController.java b/src/main/java/com/cultural/heritage/controller/good/GoodController.java index fc3f228..54c91c7 100644 --- a/src/main/java/com/cultural/heritage/controller/good/GoodController.java +++ b/src/main/java/com/cultural/heritage/controller/good/GoodController.java @@ -3,9 +3,11 @@ package com.cultural.heritage.controller.good; 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.constant.UserConstant; import com.cultural.heritage.exception.BusinessException; import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.model.dto.CommonDelBatchRequest; @@ -53,7 +55,7 @@ public class GoodController { */ @PostMapping("/add") @Operation(summary = "Web端管理员添加商品", description = "参数:商品添加请求体,权限:管理员(admin, boss),方法名:addGood") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse addGood(@RequestBody GoodAddRequest goodAddRequest) { if (goodAddRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -73,7 +75,7 @@ public class GoodController { */ @PostMapping("/delete") @Operation(summary = "Web端管理员删除商品", description = "参数:商品删除请求体,权限:管理员(admin, boss),方法名:deleteGood") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse deleteGood(@RequestBody CommonRequest deleteRequest) { if (deleteRequest == null || deleteRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -91,7 +93,7 @@ public class GoodController { */ @PostMapping("/update") @Operation(summary = "Web端管理员更新商品", description = "参数:商品更新请求体,权限:管理员(admin, boss),方法名:updateGoods") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse updateGoods(@RequestBody GoodUpdateRequest goodUpdateRequest) { if (goodUpdateRequest == null || goodUpdateRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -113,7 +115,7 @@ public class GoodController { */ @PostMapping("/list/page") @Operation(summary = "Web端管理员分页查询商品", description = "参数:商品查询请求体,权限:管理员(admin, boss),方法名:listGoodByPage") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse> listGoodByPage(@RequestBody GoodQueryRequest goodQueryRequest) { long current = goodQueryRequest.getCurrent(); long pageSize = goodQueryRequest.getPageSize(); @@ -132,7 +134,7 @@ public class GoodController { */ @PostMapping("/delBatch") @Operation(summary = "Web端管理员批量删除商品", description = "参数:商品批量删除请求体,权限:管理员(admin, boss),方法名:delBatchGoods") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse delBatchGoods(@RequestBody CommonDelBatchRequest commonDelBatchRequest) { List idList = commonDelBatchRequest.getIdList(); boolean result = goodService.removeBatchByIds(idList); diff --git a/src/main/java/com/cultural/heritage/controller/order/OrderController.java b/src/main/java/com/cultural/heritage/controller/order/OrderController.java index 0bb42a6..7b87e69 100644 --- a/src/main/java/com/cultural/heritage/controller/order/OrderController.java +++ b/src/main/java/com/cultural/heritage/controller/order/OrderController.java @@ -3,9 +3,11 @@ package com.cultural.heritage.controller.order; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 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.constant.UserConstant; import com.cultural.heritage.exception.BusinessException; import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.model.dto.CommonRequest; @@ -95,7 +97,7 @@ public class OrderController { */ @PostMapping("/list/page") @Operation(summary = "Web端管理员分页查询订单", description = "参数:订单查询请求体,权限:管理员(admin, boss),方法名:listOrder") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse> listOrder(@RequestBody OrderQueryRequest orderQueryRequest) { if (orderQueryRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -116,7 +118,7 @@ public class OrderController { */ @PostMapping("/list/item") @Operation(summary = "Web端管理员查询订单明细", description = "参数:订单编号请求体,权限:管理员(admin, boss),方法名:listOrderItem") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse> listOrderItem(@RequestBody CommonRequest orderIdRequest) { if (orderIdRequest == null || orderIdRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -138,7 +140,7 @@ public class OrderController { */ @PostMapping("/update") @Operation(summary = "Web端管理员更新订单状态", description = "参数:订单状态更新请求体,权限:管理员(admin, boss),方法名:updateOrderStatus") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse updateOrderStatus(@RequestBody OrderUpdateRequest orderUpdateRequest) { if (orderUpdateRequest == null || orderUpdateRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); diff --git a/src/main/java/com/cultural/heritage/controller/user/UserController.java b/src/main/java/com/cultural/heritage/controller/user/UserController.java index 8e20d23..061614f 100644 --- a/src/main/java/com/cultural/heritage/controller/user/UserController.java +++ b/src/main/java/com/cultural/heritage/controller/user/UserController.java @@ -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; @@ -57,7 +59,7 @@ public class UserController { * @return 登录用户信息 */ @PostMapping("/login") - @Operation(summary = "Web端用户登录", description = "参数:{账号,密码}, 权限:管理员(admin, boss), 方法名:userLogin") + @Operation(summary = "Web端用户登录", description = "参数:{账号,密码}, 权限:所有人), 方法名:userLogin") public BaseResponse userLogin(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request){ if(userLoginRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -105,7 +107,7 @@ public class UserController { * @return 是否退出登录成功 */ @PostMapping("/logout") - @Operation(summary = "Web端管理员退出登录", description = "参数:无,权限:管理员(admin, boss),方法名:userLogout") + @Operation(summary = "Web端管理员退出登录", description = "参数:无,权限:所有人,方法名:userLogout") public BaseResponse userLogout(HttpServletRequest request) { boolean result = userService.userLogout(request); return ResultUtils.success(result); @@ -154,8 +156,8 @@ public class UserController { * @return 添加用户的信息 */ @PostMapping("/add") - @Operation(summary = "Web端管理员创建用户", description = "参数:用户添加请求体, 权限:管理员(admin, boss), 方法名:addUser") -// @AuthCheck(mustRole = UserConstant.BOSS_ROLE) + @Operation(summary = "Web端管理员创建用户", description = "参数:用户添加请求体, 权限:管理员(boss), 方法名:addUser") + @AuthCheck(mustRole = UserConstant.BOSS_ROLE) public BaseResponse addUser(@RequestBody UserAddRequest userAddRequest) { if (userAddRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -178,8 +180,8 @@ public class UserController { * @return 是否删除 */ @PostMapping("/delete") - @Operation(summary = "Web端管理员删除用户", description = "参数:用户删除请求体, 权限:管理员(admin, boss), 方法名:deleteUser") -// @AuthCheck(mustRole = UserConstant.BOSS_ROLE) + @Operation(summary = "Web端管理员删除用户", description = "参数:用户删除请求体, 权限:管理员(boss), 方法名:deleteUser") + @AuthCheck(mustRole = UserConstant.BOSS_ROLE) public BaseResponse deleteUser(@RequestBody CommonRequest deleteRequest) { if (deleteRequest == null || deleteRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -196,8 +198,8 @@ public class UserController { * @return 是否更新成功 */ @PostMapping("/update") - @Operation(summary = "Web端管理员更新用户", description = "参数:用户更新请求体, 权限:管理员(admin, boss), 方法名:updateUser") -// @AuthCheck(mustRole = UserConstant.BOSS_ROLE) + @Operation(summary = "Web端管理员更新用户", description = "参数:用户更新请求体, 权限:管理员(boss), 方法名:updateUser") + @AuthCheck(mustRole = UserConstant.BOSS_ROLE) public BaseResponse updateUser(@RequestBody UserUpdateRequest userUpdateRequest) { if (userUpdateRequest == null || userUpdateRequest.getId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -217,7 +219,7 @@ public class UserController { */ @GetMapping("/get") @Operation(summary = "Web端管理员根据id获取用户信息", description = "参数:用户id, 权限:管理员(admin, boss), 方法名:getUserById") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse getUserById(long id) { if (id <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); @@ -233,7 +235,7 @@ public class UserController { */ @GetMapping("/count") @Operation(summary = "Web端管理员获取用户数量", description = "参数:无, 权限:管理员(admin, boss), 方法名:getUserCount") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse getUserCount() { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("userRole", "user"); @@ -250,7 +252,7 @@ public class UserController { */ @PostMapping("/list/page") @Operation(summary = "Web端管理员分页获取用户信息", description = "参数:用户查询请求体, 权限:管理员(admin, boss), 方法名:listUserByPage") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse> listUserByPage(@RequestBody UserQueryRequest userQueryRequest) { long current = userQueryRequest.getCurrent(); long pageSize = userQueryRequest.getPageSize(); @@ -269,7 +271,7 @@ public class UserController { */ @PostMapping("/list/page/vo") @Operation(summary = "Web端管理员分页获取脱敏用户信息", description = "参数:用户查询请求体, 权限:管理员(admin, boss), 方法名:listUserVOByPage") -// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse> listUserVOByPage(@RequestBody UserQueryRequest userQueryRequest) { if (userQueryRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); diff --git a/src/main/java/com/cultural/heritage/model/dto/CommonDelBatchRequest.java b/src/main/java/com/cultural/heritage/model/dto/CommonDelBatchRequest.java index 83093cb..1b6eec1 100644 --- a/src/main/java/com/cultural/heritage/model/dto/CommonDelBatchRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/CommonDelBatchRequest.java @@ -1,5 +1,6 @@ package com.cultural.heritage.model.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; @@ -7,10 +8,14 @@ import java.io.Serializable; import java.util.List; @Data +@Schema(description = "商品批量删除请求体", requiredProperties = {"idList"}) public class CommonDelBatchRequest implements Serializable { + + @Schema(description = "批量删除的商品id列表(id > 0)", example = "[8, 9, 17]") private List idList; + @Serial private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/cultural/heritage/model/dto/CommonRequest.java b/src/main/java/com/cultural/heritage/model/dto/CommonRequest.java index eb7b294..865d54b 100644 --- a/src/main/java/com/cultural/heritage/model/dto/CommonRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/CommonRequest.java @@ -1,16 +1,19 @@ package com.cultural.heritage.model.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "根据id进行操作的请求体", requiredProperties = {"id"}) public class CommonRequest implements Serializable { /** * id */ + @Schema(description = "各个表的id", example = "2") private Long id; @Serial diff --git a/src/main/java/com/cultural/heritage/model/dto/address/AddressAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/address/AddressAddRequest.java index 7ffabaa..4a8633c 100644 --- a/src/main/java/com/cultural/heritage/model/dto/address/AddressAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/address/AddressAddRequest.java @@ -1,46 +1,54 @@ package com.cultural.heritage.model.dto.address; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "地址添加请求体", requiredProperties = {"name", "phone", "region", "detailAddress", "userId", "isDefault"}) public class AddressAddRequest implements Serializable { /** * 联系人 */ + @Schema(description = "联系人姓名", example = "张三") private String name; /** * 手机号 */ + @Schema(description = "手机号", example = "18845892473") private String phone; /** * 地区 */ + @Schema(description = "地区", example = "黑龙江省哈尔滨市松北区") private String region; /** * 详细地址 */ + @Schema(description = "详细地址", example = "学院路街道288号哈尔滨华德学院") private String detailAddress; /** * 用户id */ + @Schema(description = "用户id(id > 0)", example = "2") private Long userId; /** * 是否为默认地址 */ + @Schema(description = "是否为默认地址(1是,0否)", example = "1") private Integer isDefault; @Serial diff --git a/src/main/java/com/cultural/heritage/model/dto/address/AddressUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/address/AddressUpdateRequest.java index 7f72468..2f9f564 100644 --- a/src/main/java/com/cultural/heritage/model/dto/address/AddressUpdateRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/address/AddressUpdateRequest.java @@ -1,50 +1,59 @@ package com.cultural.heritage.model.dto.address; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "地址更新请求体", requiredProperties = {"id", "name", "phone", "region", "detailAddress", "userId", "isDefault"}) public class AddressUpdateRequest implements Serializable { /** * id */ + @Schema(description = "地址id(id > 0)", example = "15") private Long id; /** * 联系人 */ + @Schema(description = "联系人姓名", example = "张三") private String name; /** * 手机号 */ + @Schema(description = "手机号", example = "18845892473") private String phone; /** * 地区 */ + @Schema(description = "地区", example = "黑龙江省哈尔滨市松北区") private String region; /** * 详细地址 */ + @Schema(description = "详细地址", example = "学院路街道288号哈尔滨华德学院") private String detailAddress; /** * 用户id */ + @Schema(description = "用户id(id > 0)", example = "2") private Long userId; /** * 是否为默认地址 */ + @Schema(description = "是否为默认地址(1是,0否)", example = "1") private Integer isDefault; diff --git a/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordAddRequest.java index 1d9f975..7dfcda9 100644 --- a/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordAddRequest.java @@ -1,32 +1,37 @@ package com.cultural.heritage.model.dto.cart; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; -import java.math.BigDecimal; @Data +@Schema(description = "购物车记录添加请求体", requiredProperties = {"userId", "goodId", "quantity", "subtotal"}) public class CartRecordAddRequest implements Serializable { /** * 用户id */ + @Schema(description = "用户Id(id > 0)", example = "2") private Long userId; /** * 商品id */ + @Schema(description = "商品id(id > 0)", example = "20") private Long goodId; /** * 数量 */ + @Schema(description = "商品数量(quantity > 0)", example = "3") private Integer quantity; /** * 小计 */ + @Schema(description = "小计(商品单价 * 数量)", example = "60") private Double subtotal; diff --git a/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordUpdateRequest.java index 8bfa276..e5ebd60 100644 --- a/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordUpdateRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordUpdateRequest.java @@ -1,38 +1,43 @@ package com.cultural.heritage.model.dto.cart; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; -import java.math.BigDecimal; -import java.util.Date; @Data +@Schema(description = "购物车记录更新请求体", requiredProperties = {"id", "userId", "goodId", "quantity", "subtotal"}) public class CartRecordUpdateRequest implements Serializable { /** * 购物车记录id */ + @Schema(description = "购物车记录Id(id > 0)", example = "5") private Long id; /** * 用户id */ + @Schema(description = "用户Id(id > 0)", example = "2") private Long userId; /** * 商品id */ + @Schema(description = "商品id(id > 0)", example = "20") private Long goodId; /** * 数量 */ + @Schema(description = "商品数量(quantity > 0)", example = "3") private Integer quantity; /** * 小计 */ + @Schema(description = "小计(商品单价 * 数量)", example = "60") private Double subtotal; diff --git a/src/main/java/com/cultural/heritage/model/dto/category/CategoryAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/category/CategoryAddRequest.java index c7255e1..a7cce78 100644 --- a/src/main/java/com/cultural/heritage/model/dto/category/CategoryAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/category/CategoryAddRequest.java @@ -1,26 +1,31 @@ package com.cultural.heritage.model.dto.category; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "商品类别添加请求体", requiredProperties = {"typeName", "typeUrl", "typeIntro"}) public class CategoryAddRequest implements Serializable { /** * 类别名称 */ + @Schema(description = "商品类别名", example = "材料包") private String typeName; /** * 类别图片 */ + @Schema(description = "商品图片地址", example = "https://xxx/xxx.jpg") private String typeUrl; /** * 类别简介 */ + @Schema(description = "商品类别简介", example = "非遗香囊,匠心传承") private String typeIntro; diff --git a/src/main/java/com/cultural/heritage/model/dto/contacts/ContactsAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/contacts/ContactsAddRequest.java index d14bd49..a986b56 100644 --- a/src/main/java/com/cultural/heritage/model/dto/contacts/ContactsAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/contacts/ContactsAddRequest.java @@ -1,5 +1,6 @@ package com.cultural.heritage.model.dto.contacts; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; @@ -9,29 +10,34 @@ import java.io.Serializable; * 添加联系人请求体 */ @Data +@Schema(description = "联系人添加请求体", requiredProperties = {"name", "phone", "userId", "isDefault"}) public class ContactsAddRequest implements Serializable { /** * 联系人姓名 */ + @Schema(description = "联系人姓名", example = "张三") private String name; /** * 联系人手机号 */ + @Schema(description = "联系人手机号", example = "18845892473") private String phone; /** * 用户id */ + @Schema(description = "用户id(id > 0)", example = "2") private Long userId; /** * 是否默认 */ + @Schema(description = "是否为默认地址", example = "1") private Integer isDefault; diff --git a/src/main/java/com/cultural/heritage/model/dto/contacts/ContactsUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/contacts/ContactsUpdateRequest.java index a554b42..ebeedeb 100644 --- a/src/main/java/com/cultural/heritage/model/dto/contacts/ContactsUpdateRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/contacts/ContactsUpdateRequest.java @@ -1,45 +1,49 @@ package com.cultural.heritage.model.dto.contacts; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; -import java.util.Date; /** * 联系人更新请求体 */ @Data +@Schema(description = "联系人更新请求体", requiredProperties = {"id", "name", "phone", "userId", "isDefault"}) public class ContactsUpdateRequest implements Serializable { /** * 联系人id */ + @Schema(description = "联系人id(id > 0)", example = "4") private Long id; /** * 联系人姓名 */ + @Schema(description = "联系人姓名", example = "张三") private String name; /** * 联系人手机号 */ + @Schema(description = "联系人手机号", example = "18845892473") private String phone; /** * 用户id */ + @Schema(description = "用户id(id > 0)", example = "2") private Long userId; /** * 是否默认 */ + @Schema(description = "是否为默认地址", example = "1") private Integer isDefault; diff --git a/src/main/java/com/cultural/heritage/model/dto/coupon/CouponAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/coupon/CouponAddRequest.java index f2744be..670bb95 100644 --- a/src/main/java/com/cultural/heritage/model/dto/coupon/CouponAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/coupon/CouponAddRequest.java @@ -1,74 +1,88 @@ package com.cultural.heritage.model.dto.coupon; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "优惠券添加请求体", requiredProperties = + {"name", "conditionAmount", "requirePoints", "totalNum", "residueNum", "limitNum", "useScope", "startTime", "endTime", "image", "description"}) public class CouponAddRequest implements Serializable { /** * 优惠券名称 */ + @Schema(description = "优惠券名称", example = "满200减50") private String name; /** * 满减金额 */ + @Schema(description = "满减金额", example = "50") private Double conditionAmount; /** * 需要的积分 */ + @Schema(description = "兑换需要的积分", example = "1000") private Integer requirePoints; /** * 发放数量 */ + @Schema(description = "发放数量", example = "10") private Integer totalNum; /** * 剩余数量 */ + @Schema(description = "剩余数量", example = "5") private Integer residueNum; /** * 用户限领量 */ + @Schema(description = "用户限领量", example = "3") private Integer limitNum; /** * 作用范围 */ + @Schema(description = "作用范围(商品类别名)", example = "材料包;手持物;头饰") private String useScope; /** * 有效开始日期 */ + @Schema(description = "有效开始日期", example = "2024-11-04 15:00:00") private String startTime; /** * 有效截止日期 */ + @Schema(description = "有效截止日期", example = "2024-12-04 15:00:00") private String endTime; /** * 优惠券图片 */ + @Schema(description = "优惠券图片地址", example = "https://xxx/xxx.jpg") private String image; /** * 使用说明 */ + @Schema(description = "使用说明", example = "该优惠券只作用于一个材料包类商品;取消订单后优惠券会自动退回") private String description; diff --git a/src/main/java/com/cultural/heritage/model/dto/coupon/CouponQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/coupon/CouponQueryRequest.java index 0c55835..2c82f53 100644 --- a/src/main/java/com/cultural/heritage/model/dto/coupon/CouponQueryRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/coupon/CouponQueryRequest.java @@ -1,9 +1,8 @@ package com.cultural.heritage.model.dto.coupon; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; import com.cultural.heritage.common.PageRequest; import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -14,22 +13,26 @@ import java.util.Date; @Data @EqualsAndHashCode(callSuper = true) +@Schema(description = "优惠券查询请求体", requiredProperties = {"current", "pageSize"}) public class CouponQueryRequest extends PageRequest implements Serializable { /** * 优惠券id */ + @Schema(description = "优惠券id(id > 0)", example = "4") private Long id; /** * 优惠券名称 */ + @Schema(description = "优惠券名称", example = "满200减50") private String name; /** * 有效开始日期 */ + @Schema(description = "有效开始日期", example = "2024-11-04 15:00:00") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date startTime; @@ -37,6 +40,7 @@ public class CouponQueryRequest extends PageRequest implements Serializable { /** * 有效截止日期 */ + @Schema(description = "有效截止日期", example = "2024-12-04 15:00:00") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date endTime; diff --git a/src/main/java/com/cultural/heritage/model/dto/coupon/CouponUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/coupon/CouponUpdateRequest.java index 5f778b9..d577148 100644 --- a/src/main/java/com/cultural/heritage/model/dto/coupon/CouponUpdateRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/coupon/CouponUpdateRequest.java @@ -1,73 +1,93 @@ package com.cultural.heritage.model.dto.coupon; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "优惠券更新请求体", requiredProperties = + {"id", "name", "conditionAmount", "requirePoints", "totalNum", "residueNum", "limitNum", "useScope", "startTime", "endTime", "image", "description"}) public class CouponUpdateRequest implements Serializable { /** * 优惠券id */ + @Schema(description = "优惠券id(id > 0)", example = "4") private Long id; /** * 优惠券名称 */ + @Schema(description = "优惠券名称", example = "满200减50") private String name; /** * 满减金额 */ + @Schema(description = "满减金额", example = "50") private Double conditionAmount; /** * 需要的积分 */ + @Schema(description = "兑换需要的积分", example = "1000") private Integer requirePoints; /** * 发放数量 */ + @Schema(description = "发放数量", example = "10") private Integer totalNum; /** * 剩余数量 */ + @Schema(description = "剩余数量", example = "5") private Integer residueNum; /** * 用户限领量 */ + @Schema(description = "用户限领量", example = "3") private Integer limitNum; /** * 有效开始日期 */ + @Schema(description = "有效开始日期", example = "2024-11-04 15:00:00") private String startTime; /** * 有效截止日期 */ + @Schema(description = "有效截止日期", example = "2024-12-04 15:00:00") private String endTime; + /** + * 优惠券图片 + */ + @Schema(description = "优惠券图片地址", example = "https://xxx/xxx.jpg") + private String image; + /** * 作用范围 */ + @Schema(description = "作用范围(商品类别名)", example = "材料包;手持物;头饰") private String useScope; /** * 使用说明 */ + @Schema(description = "使用说明", example = "该优惠券只作用于一个材料包类商品;取消订单后优惠券会自动退回") private String description; diff --git a/src/main/java/com/cultural/heritage/model/dto/exchange/ExchangeAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/exchange/ExchangeAddRequest.java index fbd027b..f6aa1f0 100644 --- a/src/main/java/com/cultural/heritage/model/dto/exchange/ExchangeAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/exchange/ExchangeAddRequest.java @@ -1,39 +1,42 @@ package com.cultural.heritage.model.dto.exchange; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; -import java.util.Date; /** * 积分兑换优惠券请求 */ @Data +@Schema(description = "积分兑换优惠券请求体", requiredProperties = {"userId", "couponId", "quantity", "requirePoints"}) public class ExchangeAddRequest implements Serializable { /** * 用户id */ + @Schema(description = "用户id(id > 0)", example = "2") private Long userId; /** * 优惠券id */ + @Schema(description = "优惠券id(id > 0)", example = "4") private Long couponId; /** * 数量 */ + @Schema(description = "购买数量", example = "10") private Integer quantity; /** * 优惠券积分价格 */ + @Schema(description = "优惠券积分价格", example = "2000") private Integer requirePoints; diff --git a/src/main/java/com/cultural/heritage/model/dto/file/UploadFileRequest.java b/src/main/java/com/cultural/heritage/model/dto/file/UploadFileRequest.java index da7737d..5436134 100644 --- a/src/main/java/com/cultural/heritage/model/dto/file/UploadFileRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/file/UploadFileRequest.java @@ -1,16 +1,19 @@ package com.cultural.heritage.model.dto.file; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "文件上传请求体", requiredProperties = {"biz"}) public class UploadFileRequest implements Serializable { /** * 业务 */ + @Schema(description = "图片所属业务类型(分别有user_avatar, good, system, test", example = "user_avatar") private String biz; diff --git a/src/main/java/com/cultural/heritage/model/dto/good/GoodAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/good/GoodAddRequest.java index 098c6f5..9cd5446 100644 --- a/src/main/java/com/cultural/heritage/model/dto/good/GoodAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/good/GoodAddRequest.java @@ -1,62 +1,75 @@ package com.cultural.heritage.model.dto.good; import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serializable; @Data +@Schema(description = "商品添加请求体", requiredProperties = {"name", "type", "price", "goodImg", "intro", + "introDetail, detailImg", "label", "inventory", "festivalOrder"}) public class GoodAddRequest implements Serializable { /** * 商品名 */ + @Schema(description = "商品名", example = "非遗香囊") private String name; /** * 商品类型 */ + @Schema(description = "商品类型", example = "材料包") private String type; /** * 商品价格 */ + @Schema(description = "商品价格", example = "20.00") private Double price; /** * 商品图片 */ + @Schema(description = "商品图片", example = "https://xxx/xxx.jpg") private String goodImg; /** * 商品简介 */ + @Schema(description = "商品简介", example = "传承千年文化,守护健康美好") private String intro; /** * 商品详情简介 */ + @Schema(description = "商品详情简介", example = "精选药材:选用艾草、菖蒲、苍术、白芷等十多种纯天然中草药,科学配比,香气宜人,具有驱蚊、防疫、安神等多种功效。端午香囊,传承千年文化,守护健康美好。在这个端午节,让我们共同感受传统文化的魅力,为生活增添一抹色彩!") private String introDetail; /** * 商品详情图片 */ + @Schema(description = "商品详情图片", example = "https://xxx/xxx.jpg") private String detailImg; /** * 商品标签 */ + @Schema(description = "商品标签", example = "亲情;送礼;材料包") private String label; /** * 商品库存量 */ + @Schema(description = "商品库存量", example = "10") private Integer inventory; /** * 节日限定序号 */ + @Schema(description = "节日序号(1代表端午节,2代表中秋节...)", example = "2") private Integer festivalOrder; @TableField(exist = false) diff --git a/src/main/java/com/cultural/heritage/model/dto/good/GoodQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/good/GoodQueryRequest.java index c3b9075..a0fb26b 100644 --- a/src/main/java/com/cultural/heritage/model/dto/good/GoodQueryRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/good/GoodQueryRequest.java @@ -2,36 +2,43 @@ package com.cultural.heritage.model.dto.good; import com.baomidou.mybatisplus.annotation.TableField; import com.cultural.heritage.common.PageRequest; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serializable; @Data +@Schema(description = "商品查询请求体", requiredProperties = {"current", "pageSize"}) public class GoodQueryRequest extends PageRequest implements Serializable { /** * id */ + @Schema(description = "商品id(id > 0)", example = "17") private Long id; /** * 商品名 */ + @Schema(description = "商品名", example = "非遗香囊") private String name; /** * 商品类型 */ + @Schema(description = "商品类型", example = "材料包") private String type; /** * 节日限定序号 */ + @Schema(description = "节日序号(1代表端午节,2代表中秋节...)", example = "2") private Integer festivalOrder; /** * 是否上架 */ + @Schema(description = "是否上架(1:上架;0:下架)", example = "1") private Integer isShelves; @TableField(exist = false) diff --git a/src/main/java/com/cultural/heritage/model/dto/good/GoodUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/good/GoodUpdateRequest.java index 64cdef3..9a75d62 100644 --- a/src/main/java/com/cultural/heritage/model/dto/good/GoodUpdateRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/good/GoodUpdateRequest.java @@ -1,72 +1,87 @@ package com.cultural.heritage.model.dto.good; import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serializable; @Data +@Schema(description = "商品更新请求体", requiredProperties = {"id", "name", "type", "price", "goodImg", "intro", + "introDetail, detailImg", "label", "inventory", "festivalOrder"}) public class GoodUpdateRequest implements Serializable { /** * id */ + @Schema(description = "商品id(id > 0)", example = "17") private Long id; /** * 商品名 */ + @Schema(description = "商品名", example = "非遗香囊") private String name; /** * 商品类型 */ + @Schema(description = "商品类型", example = "材料包") private String type; /** * 商品价格 */ + @Schema(description = "商品价格", example = "20.00") private Double price; /** * 商品图片 */ + @Schema(description = "商品图片", example = "https://xxx/xxx.jpg") private String goodImg; /** * 商品简介 */ + @Schema(description = "商品简介", example = "传承千年文化,守护健康美好") private String intro; /** * 商品详情简介 */ + @Schema(description = "商品详情简介", example = "精选药材:选用艾草、菖蒲、苍术、白芷等十多种纯天然中草药,科学配比,香气宜人,具有驱蚊、防疫、安神等多种功效。端午香囊,传承千年文化,守护健康美好。在这个端午节,让我们共同感受传统文化的魅力,为生活增添一抹色彩!") private String introDetail; /** * 商品详情图片 */ + @Schema(description = "商品详情图片", example = "https://xxx/xxx.jpg") private String detailImg; /** * 商品标签 */ + @Schema(description = "商品标签", example = "亲情;送礼;材料包") private String label; /** * 商品库存量 */ + @Schema(description = "商品库存量", example = "10") private Integer inventory; /** * 节日限定序号 */ + @Schema(description = "节日序号(1代表端午节,2代表中秋节...)", example = "2") private Integer festivalOrder; /** * 是否上架 */ + @Schema(description = "是否上架(1:上架;0:下架)", example = "1") private Integer isShelves; diff --git a/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java index 5919ebb..1b8c423 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java @@ -3,52 +3,62 @@ package com.cultural.heritage.model.dto.order; import com.cultural.heritage.model.dto.snapshot.AddressSnapshot; import com.cultural.heritage.model.dto.snapshot.ContactsSnapshot; import com.cultural.heritage.model.dto.snapshot.CouponSnapshot; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "订单添加请求体", requiredProperties = {"userId", "orderNumber", "addressSnapshot", "contactsSnapshot", +"couponSnapshot", "totalAmount", "orderStatus"}) public class OrderAddRequest implements Serializable { /** * 用户id */ + @Schema(description = "用户id(id > 0)", example = "2") private Long userId; /** * 订单编号 */ + @Schema(description = "订单编号", example = "20241105342838428324834") private String orderNumber; /** * 地址信息快照 */ + @Schema(description = "订单地址信息") private AddressSnapshot addressSnapshot; /** * 联系人信息快照 */ + @Schema(description = "订单联系人信息") private ContactsSnapshot contactsSnapshot; /** * 优惠券信息快照 */ + @Schema(description = "订单优惠券信息") private CouponSnapshot couponSnapshot; /** * 订单总金额 */ + @Schema(description = "订单总金额", example = "500") private Double totalAmount; /** * 订单状态 */ + @Schema(description = "订单状态", example = "待发货") private String orderStatus; diff --git a/src/main/java/com/cultural/heritage/model/dto/order/OrderItemAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/OrderItemAddRequest.java index 62684a1..eaae0d6 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/OrderItemAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/OrderItemAddRequest.java @@ -1,44 +1,52 @@ package com.cultural.heritage.model.dto.order; import com.cultural.heritage.model.dto.snapshot.GoodSnapshot; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "订单明细添加请求体", requiredProperties = {"orderId", "goodSnapshot", "priceSnapshot", "quantity", "itemTotalAmount"}) public class OrderItemAddRequest implements Serializable { /** * 关联的订单id */ + @Schema(description = "关联的订单id(id > 0)", example = "542") private Long orderId; /** * 商品信息快照 */ + @Schema(description = "订单商品信息") private GoodSnapshot goodSnapshot; /** * 商品单价快照 */ + @Schema(description = "商品单价", example = "30") private Double priceSnapshot; /** * 购买数量 */ + @Schema(description = "购买数量", example = "10") private Integer quantity; /** * 订单项金额(单价 * 数量) */ + @Schema(description = "订单项金额(单价 * 数量)", example = "300") private Double itemTotalAmount; + @Serial private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java index f9aea09..3eaf95d 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java @@ -2,6 +2,7 @@ package com.cultural.heritage.model.dto.order; import com.cultural.heritage.common.PageRequest; import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; @@ -9,41 +10,48 @@ import java.io.Serializable; import java.util.Date; @Data +@Schema(description = "订单查询请求体", requiredProperties = {"current", "pageSize"}) public class OrderQueryRequest extends PageRequest implements Serializable { /** * 用户id */ + @Schema(description = "用户id(id > 0)", example = "2") private Long userId; /** * 订单编号 */ - private String OrderNumber; + @Schema(description = "订单编号", example = "20241105342240243023420") + private String orderNumber; /** * 订单最小金额 */ + @Schema(description = "订单最小金额", example = "50") private Double minTotalAmount; /** * 订单最大金额 */ + @Schema(description = "订单最大金额", example = "350") private Double maxTotalAmount; /** * 订单状态 */ + @Schema(description = "订单状态", example = "待支付") private String orderStatus; /** * 开始时间 */ + @Schema(description = "开始时间", example = "2024-11-05 01:08:44") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date startTime; @@ -52,6 +60,7 @@ public class OrderQueryRequest extends PageRequest implements Serializable { /** * 结束时间 */ + @Schema(description = "结束时间", example = "2024-11-06 02:23:39") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date endTime; diff --git a/src/main/java/com/cultural/heritage/model/dto/order/OrderUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/OrderUpdateRequest.java index 3e1f738..bbcb831 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/OrderUpdateRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/OrderUpdateRequest.java @@ -1,22 +1,26 @@ package com.cultural.heritage.model.dto.order; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "订单更新请求体", requiredProperties = {"id", "orderStatus"}) public class OrderUpdateRequest implements Serializable { /** * 订单id */ + @Schema(description = "订单id(id > 0)", example = "40") private Long id; /** * 订单状态 */ + @Schema(description = "订单状态", example = "待支付") private String orderStatus; diff --git a/src/main/java/com/cultural/heritage/model/dto/snapshot/AddressSnapshot.java b/src/main/java/com/cultural/heritage/model/dto/snapshot/AddressSnapshot.java index 8ad2862..3e51bf6 100644 --- a/src/main/java/com/cultural/heritage/model/dto/snapshot/AddressSnapshot.java +++ b/src/main/java/com/cultural/heritage/model/dto/snapshot/AddressSnapshot.java @@ -1,35 +1,41 @@ package com.cultural.heritage.model.dto.snapshot; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "订单地址信息", requiredProperties = {"name", "phone", "region", "detailAddress"}) public class AddressSnapshot implements Serializable { /** * 联系人 */ + @Schema(description = "收货人", example = "张三") private String name; /** * 手机号 */ + @Schema(description = "手机号", example = "18845892473") private String phone; /** * 地区 */ + @Schema(description = "地区", example = "黑龙江省哈尔滨市呼兰区") private String region; /** * 详细地址 */ + @Schema(description = "详细地址", example = "学院路街道288号哈尔滨华德学院") private String detailAddress; diff --git a/src/main/java/com/cultural/heritage/model/dto/snapshot/ContactsSnapshot.java b/src/main/java/com/cultural/heritage/model/dto/snapshot/ContactsSnapshot.java index b18a4b8..6674b75 100644 --- a/src/main/java/com/cultural/heritage/model/dto/snapshot/ContactsSnapshot.java +++ b/src/main/java/com/cultural/heritage/model/dto/snapshot/ContactsSnapshot.java @@ -1,23 +1,27 @@ package com.cultural.heritage.model.dto.snapshot; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "订单联系人信息", requiredProperties = {"name", "phone"}) public class ContactsSnapshot implements Serializable { /** * 联系人姓名 */ + @Schema(description = "联系人姓名", example = "张三") private String name; /** * 联系人手机号 */ + @Schema(description = "联系人手机号", example = "18845892473") private String phone; diff --git a/src/main/java/com/cultural/heritage/model/dto/snapshot/CouponSnapshot.java b/src/main/java/com/cultural/heritage/model/dto/snapshot/CouponSnapshot.java index 8cc71a4..673c045 100644 --- a/src/main/java/com/cultural/heritage/model/dto/snapshot/CouponSnapshot.java +++ b/src/main/java/com/cultural/heritage/model/dto/snapshot/CouponSnapshot.java @@ -1,22 +1,26 @@ package com.cultural.heritage.model.dto.snapshot; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "订单优惠券信息", requiredProperties = {"name", "conditionAmount"}) public class CouponSnapshot implements Serializable { /** * 优惠券名称 */ + @Schema(description = "优惠券名称", example = "满200减50") private String name; /** * 满减金额 */ + @Schema(description = "满减金额", example = "50") private Double conditionAmount; diff --git a/src/main/java/com/cultural/heritage/model/dto/snapshot/GoodSnapshot.java b/src/main/java/com/cultural/heritage/model/dto/snapshot/GoodSnapshot.java index f132ce1..0001993 100644 --- a/src/main/java/com/cultural/heritage/model/dto/snapshot/GoodSnapshot.java +++ b/src/main/java/com/cultural/heritage/model/dto/snapshot/GoodSnapshot.java @@ -1,43 +1,51 @@ package com.cultural.heritage.model.dto.snapshot; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "订单商品信息", requiredProperties = {"name", "type", "price", "goodImg", "festivalOrder", "reserveDate"}) public class GoodSnapshot implements Serializable { /** * 商品名 */ + @Schema(description = "商品名", example = "团扇") private String name; /** * 商品类型 */ + @Schema(description = "商品类型", example = "材料包") private String type; /** * 商品价格 */ + @Schema(description = "商品价格", example = "200.00") private Double price; /** * 商品图片 */ + @Schema(description = "商品图片地址", example = "https://xxx/xxx.jpg") private String goodImg; /** * 节日限定序号 */ + @Schema(description = "节日序号(1代表端午节,2代表中秋节...)", example = "2") private Integer festivalOrder; /** * 预约日期 */ + @Schema(description = "预约日期(用户服务类,如果是商品类值为NOT_RESERVE)", example = "2024-11-22;9:00-11:00") private String reserveDate; diff --git a/src/main/java/com/cultural/heritage/model/dto/user/UserAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/user/UserAddRequest.java index ef5ae7e..b00d734 100644 --- a/src/main/java/com/cultural/heritage/model/dto/user/UserAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/user/UserAddRequest.java @@ -1,5 +1,6 @@ package com.cultural.heritage.model.dto.user; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; @@ -10,38 +11,45 @@ import java.io.Serializable; */ @Data +@Schema(description = "用户创建请求体", requiredProperties = {"userName", "userAccount", "userPassword", "userAvatar", "phone", "userRole"}) public class UserAddRequest implements Serializable { /** * 用户昵称 */ + @Schema(description = "用户昵称", example = "李四") private String userName; /** * 账号 */ + @Schema(description = "账号", example = "134354539493584") private String userAccount; /** * 密码 */ + @Schema(description = "密码", example = "2342333333343232") private String userPassword; /** * 用户头像 */ + @Schema(description = "用户头像", example = "https://xxx/xxx.jpg") private String userAvatar; /** * 手机号 */ + @Schema(description = "手机号", example = "18845892473") private String phone; /** * 用户角色 user, admin */ + @Schema(description = "用户角色(包括boss, admin, user, ban, 但只能一个超级管理员创建管理员)", example = "admin") private String userRole; @Serial diff --git a/src/main/java/com/cultural/heritage/model/dto/user/UserLoginRequest.java b/src/main/java/com/cultural/heritage/model/dto/user/UserLoginRequest.java index 46baa3d..21f507e 100644 --- a/src/main/java/com/cultural/heritage/model/dto/user/UserLoginRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/user/UserLoginRequest.java @@ -1,16 +1,27 @@ package com.cultural.heritage.model.dto.user; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "用户登录请求体", requiredProperties = {"userAccount", "userPassword"}) public class UserLoginRequest implements Serializable { + /** + * 账号 + */ + @Schema(description = "账号", example = "feiyi") private String userAccount; + + /** + * 密码 + */ + @Schema(description = "密码", example = "123456") private String userPassword; @Serial diff --git a/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java index 10112a5..e31f6bd 100644 --- a/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java @@ -1,6 +1,7 @@ package com.cultural.heritage.model.dto.user; import com.cultural.heritage.common.PageRequest; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -8,31 +9,37 @@ import java.io.Serial; import java.io.Serializable; @Data @EqualsAndHashCode(callSuper = true) +@Schema(description = "用户查询请求体", requiredProperties = {"current", "pageSize"}) public class UserQueryRequest extends PageRequest implements Serializable { /** * id */ + @Schema(description = "用户id(id > 0)", example = "2") private Long id; /** * 小程序openId */ + @Schema(description = "小程序openId", example = "fdji23ri23i423423d") private String miniOpenId; /** * 用户昵称 */ + @Schema(description = "用户昵称", example = "chenxinzhi") private String userName; /** * 手机号 */ + @Schema(description = "手机号", example = "18845892473") private String phone; /** * 用户角色:user/admin/ban */ + @Schema(description = "用户角色", example = "user") private String userRole; @Serial diff --git a/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateMyRequest.java b/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateMyRequest.java index 0cd490e..3484b2c 100644 --- a/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateMyRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateMyRequest.java @@ -1,5 +1,6 @@ package com.cultural.heritage.model.dto.user; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; @@ -9,21 +10,25 @@ import java.io.Serializable; * 用户更新个人信息请求 */ @Data +@Schema(description = "用户个人信息更新请求体", requiredProperties = {"userName", "userAvatar", "phone"}) public class UserUpdateMyRequest implements Serializable { /** * 用户昵称 */ + @Schema(description = "用户昵称", example = "王五") private String userName; /** * 用户头像 */ + @Schema(description = "用户头像", example = "https://xxx/xxx.jpg") private String userAvatar; /** * 手机号 */ + @Schema(description = "手机号", example = "18845892473") private String phone; diff --git a/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java index e45a9d6..7fbe271 100644 --- a/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java @@ -1,42 +1,50 @@ package com.cultural.heritage.model.dto.user; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.io.Serial; import java.io.Serializable; @Data +@Schema(description = "用户更新请求体", requiredProperties = {"id", "userPassword", "userName", "userAvatar", "phone", "userRole"}) public class UserUpdateRequest implements Serializable { /** * id */ + @Schema(description = "用户id(id > 0)", example = "2") private Long id; /** * 密码 */ + @Schema(description = "用户密码", example = "34234342342") private String userPassword; /** * 用户名 */ + @Schema(description = "用户昵称", example = "cxz") private String userName; /** * 头像 */ + @Schema(description = "用户头像", example = "https://xxx/xxx.jpg") private String userAvatar; /** * 手机号 */ + @Schema(description = "手机号", example = "18845892473") private String phone; /** * 用户角色 */ + @Schema(description = "用户角色(包括boss, admin, user, ban, 但只能一个超级管理员创建管理员)", example = "admin") private String userRole; @Serial diff --git a/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java b/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java index c517894..a4e5fea 100644 --- a/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java @@ -155,32 +155,34 @@ public class UserServiceImpl extends ServiceImpl implements Us @Override public UserVO userLoginByMpOpen(WxMaJscode2SessionResult sessionInfo, HttpServletRequest request) { String openid = sessionInfo.getOpenid(); - - // 查询用户是否存在 - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("miniOpenId", openid); - User user = this.getOne(queryWrapper); - // 被封号,禁止登录 - if (user != null && UserRoleEnum.BAN.getValue().equals(user.getUserRole())) { - throw new BusinessException(ErrorCode.FORBIDDEN_ERROR, "该用户已封禁,禁止登录"); + // 单机锁 + synchronized (openid.intern()) { + // 查询用户是否存在 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("miniOpenId", openid); + User user = this.getOne(queryWrapper); + // 被封号,禁止登录 + if (user != null && UserRoleEnum.BAN.getValue().equals(user.getUserRole())) { + throw new BusinessException(ErrorCode.FORBIDDEN_ERROR, "该用户已封禁,禁止登录"); + } + // 用户不存在则创建 + if (user == null) { + user = new User(); + String userAccount = RandomUtil.randomNumbers(14); + String userPassword = RandomUtil.randomString(16); + user.setUserAccount(userAccount); + user.setUserPassword(userPassword); + user.setMiniOpenId(openid); + user.setUserName("普通用户"); + user.setUserRole("user"); + user.setUserAvatar(UserConstant.USER_DEFAULT_AVATAR); + boolean result = this.save(user); + ThrowUtils.throwIf(!result, ErrorCode.SYSTEM_ERROR, "登录失败"); + // 记住用户的登录态 + } + request.getSession().setAttribute(USER_LOGIN_STATE, user); + return this.getUserVO(user); } - // 用户不存在则创建 - if (user == null) { - user = new User(); - String userAccount = RandomUtil.randomNumbers(14); - String userPassword = RandomUtil.randomString(16); - user.setUserAccount(userAccount); - user.setUserPassword(userPassword); - user.setMiniOpenId(openid); - user.setUserName("普通用户"); - user.setUserRole("user"); - user.setUserAvatar(UserConstant.USER_DEFAULT_AVATAR); - boolean result = this.save(user); - ThrowUtils.throwIf(!result, ErrorCode.SYSTEM_ERROR, "登录失败"); - // 记住用户的登录态 - } - request.getSession().setAttribute(USER_LOGIN_STATE, user); - return this.getUserVO(user); } }