完善了用户登录

This commit is contained in:
chen-xin-zhi 2024-11-04 16:40:07 +08:00
parent 1e7f1c2025
commit 98187e3f26
7 changed files with 31 additions and 34 deletions

View File

@ -11,6 +11,10 @@ public interface UserConstant {
*/
String SALT = "feiyi";
/**
* 用户默认头像
*/
String USER_DEFAULT_AVATAR = "https://carbon2.obs.cn-north-4.myhuaweicloud.com/feiyi/default/avator.png";
/**
* 用户登录键

View File

@ -1,11 +1,9 @@
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;
@ -52,7 +50,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<Boolean> addCategory(@RequestBody CategoryAddRequest categoryAddRequest) {
if (categoryAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -73,7 +71,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<Boolean> deleteCategory(@RequestBody CommonRequest deleteCategoryRequest) {
if (deleteCategoryRequest == null || deleteCategoryRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -93,7 +91,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<Boolean> updateCategory(@RequestBody Category category) {
if (category == null || category.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -111,7 +109,7 @@ public class CategoryController {
*/
@PostMapping("/list")
@Operation(summary = "Web端管理员查询商品类别", description = "参数:无,权限:管理员(admin, boss)方法名listCategory")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<List<Category>> listCategory() {
List<Category> list = categoryService.list();
return ResultUtils.success(list);

View File

@ -2,11 +2,9 @@ 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;
@ -63,7 +61,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<Boolean> addCoupon(@RequestBody CouponAddRequest couponAddRequest) {
if (couponAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -84,7 +82,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<Boolean> updateCoupon(@RequestBody CouponUpdateRequest couponUpdateRequest) {
if (couponUpdateRequest == null || couponUpdateRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -105,7 +103,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<Boolean> deleteCoupon(@RequestBody CommonRequest couponDeleteRequest) {
if (couponDeleteRequest == null || couponDeleteRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -125,7 +123,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<Page<Coupon>> listCouponVOByPage(@RequestBody CouponQueryRequest couponQueryRequest) {
if (couponQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);

View File

@ -3,11 +3,9 @@ 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;
@ -55,7 +53,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<Boolean> addGood(@RequestBody GoodAddRequest goodAddRequest) {
if (goodAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -75,7 +73,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<Boolean> deleteGood(@RequestBody CommonRequest deleteRequest) {
if (deleteRequest == null || deleteRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -93,7 +91,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<Boolean> updateGoods(@RequestBody GoodUpdateRequest goodUpdateRequest) {
if (goodUpdateRequest == null || goodUpdateRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -115,7 +113,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<Page<Good>> listGoodByPage(@RequestBody GoodQueryRequest goodQueryRequest) {
long current = goodQueryRequest.getCurrent();
long pageSize = goodQueryRequest.getPageSize();
@ -134,7 +132,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<Boolean> delBatchGoods(@RequestBody CommonDelBatchRequest commonDelBatchRequest) {
List<Integer> idList = commonDelBatchRequest.getIdList();
boolean result = goodService.removeBatchByIds(idList);

View File

@ -3,11 +3,9 @@ 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;
@ -97,7 +95,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<Page<Order>> listOrder(@RequestBody OrderQueryRequest orderQueryRequest) {
if (orderQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -118,7 +116,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<List<OrderItem>> listOrderItem(@RequestBody CommonRequest orderIdRequest) {
if (orderIdRequest == null || orderIdRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -140,7 +138,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<Boolean> updateOrderStatus(@RequestBody OrderUpdateRequest orderUpdateRequest) {
if (orderUpdateRequest == null || orderUpdateRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);

View File

@ -5,12 +5,10 @@ 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;
@ -98,7 +96,6 @@ public class UserController {
log.error("userLoginByWxOpen error", e);
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "登录失败,系统错误");
}
}
@ -114,6 +111,7 @@ public class UserController {
return ResultUtils.success(result);
}
/**
* 获取当前登录用户
* @param request http
@ -157,7 +155,7 @@ public class UserController {
*/
@PostMapping("/add")
@Operation(summary = "Web端管理员创建用户", description = "参数:用户添加请求体, 权限:管理员(admin, boss), 方法名addUser")
@AuthCheck(mustRole = UserConstant.BOSS_ROLE)
// @AuthCheck(mustRole = UserConstant.BOSS_ROLE)
public BaseResponse<User> addUser(@RequestBody UserAddRequest userAddRequest) {
if (userAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -181,7 +179,7 @@ public class UserController {
*/
@PostMapping("/delete")
@Operation(summary = "Web端管理员删除用户", description = "参数:用户删除请求体, 权限:管理员(admin, boss), 方法名deleteUser")
@AuthCheck(mustRole = UserConstant.BOSS_ROLE)
// @AuthCheck(mustRole = UserConstant.BOSS_ROLE)
public BaseResponse<Boolean> deleteUser(@RequestBody CommonRequest deleteRequest) {
if (deleteRequest == null || deleteRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -199,7 +197,7 @@ public class UserController {
*/
@PostMapping("/update")
@Operation(summary = "Web端管理员更新用户", description = "参数:用户更新请求体, 权限:管理员(admin, boss), 方法名updateUser")
@AuthCheck(mustRole = UserConstant.BOSS_ROLE)
// @AuthCheck(mustRole = UserConstant.BOSS_ROLE)
public BaseResponse<Boolean> updateUser(@RequestBody UserUpdateRequest userUpdateRequest) {
if (userUpdateRequest == null || userUpdateRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -219,7 +217,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<User> getUserById(long id) {
if (id <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
@ -235,7 +233,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<Long> getUserCount() {
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userRole", "user");
@ -252,7 +250,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<Page<User>> listUserByPage(@RequestBody UserQueryRequest userQueryRequest) {
long current = userQueryRequest.getCurrent();
long pageSize = userQueryRequest.getPageSize();
@ -271,7 +269,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<Page<UserVO>> listUserVOByPage(@RequestBody UserQueryRequest userQueryRequest) {
if (userQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.constant.CommonConstant;
import com.cultural.heritage.constant.UserConstant;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.mapper.UserMapper;
@ -172,6 +173,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
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, "登录失败");
// 记住用户的登录态