杂务:打包并提交当前改动
This commit is contained in:
@@ -55,6 +55,11 @@ public class AuthInterceptor implements HandlerInterceptor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentUser.getStatus() != null && !Integer.valueOf(1).equals(currentUser.getStatus())) {
|
||||
writeJsonResponse(response, HttpServletResponse.SC_FORBIDDEN, "账号已被禁用");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isAdminPath(path) && (currentUser.getType() == null || currentUser.getType() < 2)) {
|
||||
writeJsonResponse(response, HttpServletResponse.SC_FORBIDDEN, "无后台访问权限");
|
||||
return false;
|
||||
|
||||
@@ -18,11 +18,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
.excludePathPatterns(
|
||||
"/user/login",
|
||||
"/user/register",
|
||||
"/user/check/**",
|
||||
"/user/refresh-token",
|
||||
"/user/send-verification-code",
|
||||
"/user/phone-login",
|
||||
"/user/reset-password-by-phone",
|
||||
"/user/get/account/**",
|
||||
"/shop/list/simple",
|
||||
"/admin/auth/login",
|
||||
"/admin/auth/refresh",
|
||||
|
||||
+5
@@ -29,6 +29,11 @@ public class AdminAuthController {
|
||||
@PostMapping("/refresh")
|
||||
public Result<LoginResponseVO> refreshToken(@RequestBody RefreshTokenRequestDTO refreshTokenRequestDTO) {
|
||||
LoginResponseVO loginResponseVO = userService.refreshToken(refreshTokenRequestDTO.getRefreshToken());
|
||||
if (loginResponseVO.getUserInfo() == null
|
||||
|| loginResponseVO.getUserInfo().getType() == null
|
||||
|| loginResponseVO.getUserInfo().getType() < 2) {
|
||||
throw new RuntimeException("您没有后台管理权限");
|
||||
}
|
||||
return Result.success(loginResponseVO);
|
||||
}
|
||||
}
|
||||
|
||||
+73
-9
@@ -3,13 +3,19 @@ package com.xiaowang.yuminailcore.controller;
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.CouponDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.CouponService;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.vo.CouponVO;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 后台优惠券管理控制器
|
||||
@@ -20,13 +26,17 @@ import java.util.List;
|
||||
public class AdminCouponController {
|
||||
|
||||
private final CouponService couponService;
|
||||
private final UserService userService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
/**
|
||||
* 创建优惠券
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("coupon:create")
|
||||
public Result<Long> createCoupon(@RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
||||
public Result<Long> createCoupon(HttpServletRequest request, @RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId != null ? shopId : couponDTO.getShopId());
|
||||
Long couponId = couponService.createCoupon(couponDTO, shopId);
|
||||
return Result.success(couponId);
|
||||
}
|
||||
@@ -36,7 +46,15 @@ public class AdminCouponController {
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("coupon:edit")
|
||||
public Result<Boolean> updateCoupon(@PathVariable Long id, @RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
||||
public Result<Boolean> updateCoupon(HttpServletRequest request, @PathVariable Long id, @RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
CouponVO couponVO = couponService.getCouponById(id);
|
||||
if (couponVO == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, couponVO.getShopId(), "无权编辑其他店铺优惠券");
|
||||
Long targetShopId = shopId != null ? shopId : (couponDTO.getShopId() != null ? couponDTO.getShopId() : couponVO.getShopId());
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, targetShopId);
|
||||
boolean success = couponService.updateCoupon(id, couponDTO, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
@@ -46,7 +64,14 @@ public class AdminCouponController {
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("coupon:delete")
|
||||
public Result<Boolean> deleteCoupon(@PathVariable Long id, @RequestParam(required = false) Long shopId) {
|
||||
public Result<Boolean> deleteCoupon(HttpServletRequest request, @PathVariable Long id, @RequestParam(required = false) Long shopId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
CouponVO couponVO = couponService.getCouponById(id);
|
||||
if (couponVO == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, couponVO.getShopId(), "无权删除其他店铺优惠券");
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, couponVO.getShopId());
|
||||
boolean success = couponService.deleteCoupon(id, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
@@ -56,8 +81,12 @@ public class AdminCouponController {
|
||||
*/
|
||||
@GetMapping("/detail/{id}")
|
||||
@RequirePermission("coupon:view")
|
||||
public Result<CouponVO> getCouponById(@PathVariable Long id) {
|
||||
public Result<CouponVO> getCouponById(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
CouponVO couponVO = couponService.getCouponById(id);
|
||||
if (couponVO != null) {
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, couponVO.getShopId(), "无权查看其他店铺优惠券");
|
||||
}
|
||||
return Result.success(couponVO);
|
||||
}
|
||||
|
||||
@@ -66,7 +95,9 @@ public class AdminCouponController {
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequirePermission("coupon:view")
|
||||
public Result<PageResultVO<CouponVO>> listCoupons(@RequestParam Integer page, @RequestParam Integer size, @RequestParam(required = false) Long shopId) {
|
||||
public Result<PageResultVO<CouponVO>> listCoupons(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer size, @RequestParam(required = false) Long shopId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||
PageResultVO<CouponVO> pageResult = couponService.listCoupons(page, size, shopId);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
@@ -76,8 +107,15 @@ public class AdminCouponController {
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("coupon:view")
|
||||
public Result<List<CouponVO>> listAllCoupons() {
|
||||
public Result<List<CouponVO>> listAllCoupons(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
List<CouponVO> coupons = couponService.listAllCoupons();
|
||||
if (shopId != null) {
|
||||
coupons = coupons.stream()
|
||||
.filter(coupon -> shopId.equals(coupon.getShopId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return Result.success(coupons);
|
||||
}
|
||||
|
||||
@@ -86,7 +124,19 @@ public class AdminCouponController {
|
||||
*/
|
||||
@PostMapping("/assign")
|
||||
@RequirePermission("coupon:assign")
|
||||
public Result<Boolean> assignCouponToUser(@RequestParam Long userId, @RequestParam Long couponId, @RequestParam(required = false) Long shopId) {
|
||||
public Result<Boolean> assignCouponToUser(HttpServletRequest request, @RequestParam Long userId, @RequestParam Long couponId, @RequestParam(required = false) Long shopId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
CouponVO couponVO = couponService.getCouponById(couponId);
|
||||
if (couponVO == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, couponVO.getShopId(), "无权发放其他店铺优惠券");
|
||||
UserVO targetUser = userService.getUserById(userId);
|
||||
if (targetUser == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权给其他店铺用户发放优惠券");
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, couponVO.getShopId());
|
||||
boolean success = couponService.assignCouponToUser(userId, couponId, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
@@ -96,8 +146,22 @@ public class AdminCouponController {
|
||||
*/
|
||||
@PostMapping("/distribute")
|
||||
@RequirePermission("coupon:assign")
|
||||
public Result<Boolean> distributeCoupon(@RequestParam Long couponId, @RequestParam List<Long> userIds, @RequestParam Integer quantity, @RequestParam(required = false) Long shopId) {
|
||||
public Result<Boolean> distributeCoupon(HttpServletRequest request, @RequestParam Long couponId, @RequestParam List<Long> userIds, @RequestParam Integer quantity, @RequestParam(required = false) Long shopId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
CouponVO couponVO = couponService.getCouponById(couponId);
|
||||
if (couponVO == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, couponVO.getShopId(), "无权发放其他店铺优惠券");
|
||||
for (Long userId : userIds) {
|
||||
UserVO targetUser = userService.getUserById(userId);
|
||||
if (targetUser == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权给其他店铺用户发放优惠券");
|
||||
}
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, couponVO.getShopId());
|
||||
boolean success = couponService.distributeCoupon(couponId, userIds, quantity, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-4
@@ -2,12 +2,15 @@ package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.OrderService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.vo.OrderVO;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -19,6 +22,7 @@ import java.util.List;
|
||||
public class AdminOrderController {
|
||||
|
||||
private final OrderService orderService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
/**
|
||||
* 获取订单列表(分页)
|
||||
@@ -26,15 +30,22 @@ public class AdminOrderController {
|
||||
@GetMapping("/list")
|
||||
@RequirePermission("order:view")
|
||||
public Result<PageResultVO<OrderVO>> listOrders(
|
||||
HttpServletRequest request,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) Integer status
|
||||
) {
|
||||
// 先获取所有订单,然后进行分页处理
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
|
||||
List<OrderVO> allOrders = orderService.getAllOrders();
|
||||
if (shopId != null) {
|
||||
allOrders = allOrders.stream()
|
||||
.filter(order -> shopId.equals(order.getShopId()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
// 根据条件过滤
|
||||
if (keyword != null && !keyword.isEmpty()) {
|
||||
allOrders = allOrders.stream()
|
||||
.filter(order -> order.getOrderNo() != null && order.getOrderNo().contains(keyword))
|
||||
@@ -46,7 +57,6 @@ public class AdminOrderController {
|
||||
.toList();
|
||||
}
|
||||
|
||||
// 手动分页
|
||||
int total = allOrders.size();
|
||||
int start = (page - 1) * size;
|
||||
int end = Math.min(start + size, total);
|
||||
@@ -66,7 +76,19 @@ public class AdminOrderController {
|
||||
*/
|
||||
@PutMapping("/update-status/{id}")
|
||||
@RequirePermission("order:process")
|
||||
public Result<Boolean> updateOrderStatus(@PathVariable Long id, @RequestParam Integer status) {
|
||||
public Result<Boolean> updateOrderStatus(HttpServletRequest request, @PathVariable Long id, @RequestParam Integer status) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
if (shopId != null) {
|
||||
OrderVO orderVO = orderService.getAllOrders().stream()
|
||||
.filter(order -> id.equals(order.getId()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (orderVO == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, orderVO.getShopId(), "无权处理其他店铺订单");
|
||||
}
|
||||
orderService.processOrder(id, status);
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
+23
-4
@@ -4,7 +4,10 @@ import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.PermissionDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserPermissionDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.PermissionService;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.vo.PermissionVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -18,24 +21,32 @@ import java.util.List;
|
||||
public class AdminPermissionController {
|
||||
|
||||
private final PermissionService permissionService;
|
||||
private final UserService userService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("permission:create")
|
||||
public Result<Long> createPermission(@RequestBody PermissionDTO permissionDTO) {
|
||||
public Result<Long> createPermission(HttpServletRequest request, @RequestBody PermissionDTO permissionDTO) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以维护权限定义");
|
||||
Long id = permissionService.createPermission(permissionDTO);
|
||||
return Result.success(id);
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("permission:edit")
|
||||
public Result<Boolean> updatePermission(@PathVariable Long id, @RequestBody PermissionDTO permissionDTO) {
|
||||
public Result<Boolean> updatePermission(HttpServletRequest request, @PathVariable Long id, @RequestBody PermissionDTO permissionDTO) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以维护权限定义");
|
||||
boolean success = permissionService.updatePermission(id, permissionDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("permission:delete")
|
||||
public Result<Boolean> deletePermission(@PathVariable Long id) {
|
||||
public Result<Boolean> deletePermission(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以维护权限定义");
|
||||
boolean success = permissionService.deletePermission(id);
|
||||
return Result.success(success);
|
||||
}
|
||||
@@ -63,7 +74,15 @@ public class AdminPermissionController {
|
||||
|
||||
@GetMapping("/user/{userId}")
|
||||
@RequirePermission("permission:view")
|
||||
public Result<List<PermissionVO>> listUserPermissions(@PathVariable Long userId) {
|
||||
public Result<List<PermissionVO>> listUserPermissions(HttpServletRequest request, @PathVariable Long userId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
UserDO targetUser = userService.getById(userId);
|
||||
if (targetUser == null) {
|
||||
throw new RuntimeException("目标用户不存在");
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权查看其他店铺用户权限");
|
||||
}
|
||||
List<PermissionVO> permissionVOs = permissionService.listUserPermissions(userId);
|
||||
return Result.success(permissionVOs);
|
||||
}
|
||||
|
||||
+32
-5
@@ -3,12 +3,15 @@ package com.xiaowang.yuminailcore.controller;
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.ProductDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.ProductService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@@ -17,44 +20,68 @@ import java.util.List;
|
||||
public class AdminProductController {
|
||||
|
||||
private final ProductService productService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
@GetMapping("/list")
|
||||
@RequirePermission("product:view")
|
||||
public Result<PageResultVO<ProductVO>> listProducts(
|
||||
HttpServletRequest request,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) Long shopId
|
||||
) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||
PageResultVO<ProductVO> result = productService.pageProducts(page, size, keyword, shopId);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("product:create")
|
||||
public Result<Long> createProduct(@RequestBody ProductDTO productDTO) {
|
||||
public Result<Long> createProduct(HttpServletRequest request, @RequestBody ProductDTO productDTO) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
productDTO.setShopId(adminScopeHelper.resolveShopScope(currentUser, productDTO.getShopId()));
|
||||
Long id = productService.createProduct(productDTO);
|
||||
return Result.success(id);
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("product:edit")
|
||||
public Result<Boolean> updateProduct(@PathVariable Long id, @RequestBody ProductDTO productDTO) {
|
||||
public Result<Boolean> updateProduct(HttpServletRequest request, @PathVariable Long id, @RequestBody ProductDTO productDTO) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
ProductVO productVO = productService.getProductById(id);
|
||||
if (productVO == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, productVO.getShopId(), "无权编辑其他店铺商品");
|
||||
Long targetShopId = productDTO.getShopId() != null ? productDTO.getShopId() : productVO.getShopId();
|
||||
productDTO.setShopId(adminScopeHelper.resolveShopScope(currentUser, targetShopId));
|
||||
boolean success = productService.updateProduct(id, productDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("product:delete")
|
||||
public Result<Boolean> deleteProduct(@PathVariable Long id) {
|
||||
public Result<Boolean> deleteProduct(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
ProductVO productVO = productService.getProductById(id);
|
||||
if (productVO == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, productVO.getShopId(), "无权删除其他店铺商品");
|
||||
boolean success = productService.deleteProduct(id);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("product:view")
|
||||
public Result<List<ProductVO>> listAllProducts() {
|
||||
List<ProductVO> products = productService.listAllProducts();
|
||||
public Result<List<ProductVO>> listAllProducts(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
List<ProductVO> products = shopId == null
|
||||
? productService.listAllProducts()
|
||||
: productService.listProductsByShopId(shopId);
|
||||
return Result.success(products);
|
||||
}
|
||||
}
|
||||
|
||||
+32
-6
@@ -3,12 +3,15 @@ package com.xiaowang.yuminailcore.controller;
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.ShopDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.ShopService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@@ -17,50 +20,73 @@ import java.util.List;
|
||||
public class AdminShopController {
|
||||
|
||||
private final ShopService shopService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
@GetMapping("/list")
|
||||
@RequirePermission("shop:view")
|
||||
public Result<PageResultVO<ShopVO>> listShops(
|
||||
HttpServletRequest request,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) Long shopId
|
||||
) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||
PageResultVO<ShopVO> result = shopService.pageShops(page, size, keyword, shopId);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("shop:create")
|
||||
public Result<Long> createShop(@RequestBody ShopDTO shopDTO) {
|
||||
public Result<Long> createShop(HttpServletRequest request, @RequestBody ShopDTO shopDTO) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以创建店铺");
|
||||
Long id = shopService.createShop(shopDTO);
|
||||
return Result.success(id);
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("shop:edit")
|
||||
public Result<Boolean> updateShop(@PathVariable Long id, @RequestBody ShopDTO shopDTO) {
|
||||
public Result<Boolean> updateShop(HttpServletRequest request, @PathVariable Long id, @RequestBody ShopDTO shopDTO) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
ShopVO shopVO = shopService.getShopById(id);
|
||||
if (shopVO == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, shopVO.getId(), "无权编辑其他店铺信息");
|
||||
boolean success = shopService.updateShop(id, shopDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("shop:delete")
|
||||
public Result<Boolean> deleteShop(@PathVariable Long id) {
|
||||
public Result<Boolean> deleteShop(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
adminScopeHelper.requirePlatformAdmin(currentUser, "只有平台管理员可以删除店铺");
|
||||
boolean success = shopService.deleteShop(id);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("shop:view")
|
||||
public Result<List<ShopVO>> listAllShops() {
|
||||
List<ShopVO> shops = shopService.listAllShops();
|
||||
public Result<List<ShopVO>> listAllShops(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
List<ShopVO> shops;
|
||||
if (adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
shops = shopService.listAllShops();
|
||||
} else {
|
||||
ShopVO currentShop = shopService.getShopById(adminScopeHelper.getManagedShopId(currentUser));
|
||||
shops = currentShop == null ? List.of() : List.of(currentShop);
|
||||
}
|
||||
return Result.success(shops);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@RequirePermission("shop:view")
|
||||
public Result<ShopVO> getShop(@PathVariable Long id) {
|
||||
public Result<ShopVO> getShop(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, id, "无权查看其他店铺信息");
|
||||
ShopVO shop = shopService.getShopById(id);
|
||||
return Result.success(shop);
|
||||
}
|
||||
|
||||
+36
-8
@@ -3,11 +3,14 @@ package com.xiaowang.yuminailcore.controller;
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.TagDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.TagService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -19,13 +22,16 @@ import java.util.List;
|
||||
public class AdminTagController {
|
||||
|
||||
private final TagService tagService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
/**
|
||||
* 创建标签
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("tag:create")
|
||||
public Result<Long> createTag(@RequestBody TagDTO tagDTO) {
|
||||
public Result<Long> createTag(HttpServletRequest request, @RequestBody TagDTO tagDTO) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
tagDTO.setShopId(adminScopeHelper.resolveShopScope(currentUser, tagDTO.getShopId()));
|
||||
Long id = tagService.createTag(tagDTO);
|
||||
return Result.success(id);
|
||||
}
|
||||
@@ -35,7 +41,15 @@ public class AdminTagController {
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("tag:edit")
|
||||
public Result<Boolean> updateTag(@PathVariable Long id, @RequestBody TagDTO tagDTO) {
|
||||
public Result<Boolean> updateTag(HttpServletRequest request, @PathVariable Long id, @RequestBody TagDTO tagDTO) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
TagVO tagVO = tagService.getTagById(id);
|
||||
if (tagVO == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, tagVO.getShopId(), "无权编辑其他店铺标签");
|
||||
Long targetShopId = tagDTO.getShopId() != null ? tagDTO.getShopId() : tagVO.getShopId();
|
||||
tagDTO.setShopId(adminScopeHelper.resolveShopScope(currentUser, targetShopId));
|
||||
boolean success = tagService.updateTag(id, tagDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
@@ -45,7 +59,13 @@ public class AdminTagController {
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("tag:delete")
|
||||
public Result<Boolean> deleteTag(@PathVariable Long id) {
|
||||
public Result<Boolean> deleteTag(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
TagVO tagVO = tagService.getTagById(id);
|
||||
if (tagVO == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, tagVO.getShopId(), "无权删除其他店铺标签");
|
||||
boolean success = tagService.deleteTag(id);
|
||||
return Result.success(success);
|
||||
}
|
||||
@@ -55,8 +75,12 @@ public class AdminTagController {
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<TagVO> getTagById(@PathVariable Long id) {
|
||||
public Result<TagVO> getTagById(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
TagVO tagVO = tagService.getTagById(id);
|
||||
if (tagVO != null) {
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, tagVO.getShopId(), "无权查看其他店铺标签");
|
||||
}
|
||||
return Result.success(tagVO);
|
||||
}
|
||||
|
||||
@@ -65,8 +89,10 @@ public class AdminTagController {
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<List<TagVO>> listAllTags() {
|
||||
List<TagVO> tagVOs = tagService.listAllTags();
|
||||
public Result<List<TagVO>> listAllTags(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
List<TagVO> tagVOs = shopId == null ? tagService.listAllTags() : tagService.listTagsByShopId(shopId);
|
||||
return Result.success(tagVOs);
|
||||
}
|
||||
|
||||
@@ -75,8 +101,10 @@ public class AdminTagController {
|
||||
*/
|
||||
@GetMapping("/list/by-shop/{shopId}")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<List<TagVO>> listTagsByShopId(@PathVariable Long shopId) {
|
||||
public Result<List<TagVO>> listTagsByShopId(HttpServletRequest request, @PathVariable Long shopId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||
List<TagVO> tagVOs = tagService.listTagsByShopId(shopId);
|
||||
return Result.success(tagVOs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+55
-8
@@ -3,7 +3,9 @@ package com.xiaowang.yuminailcore.controller;
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import lombok.Data;
|
||||
@@ -20,37 +22,64 @@ import java.util.stream.Collectors;
|
||||
public class AdminUserController {
|
||||
|
||||
private final UserService userService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
@GetMapping("/list")
|
||||
@RequirePermission("user:view")
|
||||
public Result<PageResultVO<UserVO>> listUsers(
|
||||
HttpServletRequest request,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) Long shopId,
|
||||
@RequestParam(required = false) Integer type
|
||||
) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||
PageResultVO<UserVO> result = userService.pageUsers(page, size, keyword, shopId, type);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("user:create")
|
||||
public Result<Long> createUser(@RequestBody UserDTO userDTO) {
|
||||
public Result<Long> createUser(HttpServletRequest request, @RequestBody UserDTO userDTO) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
adminScopeHelper.ensureAssignableUserType(currentUser, userDTO.getType());
|
||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
userDTO.setShopId(adminScopeHelper.getManagedShopId(currentUser));
|
||||
}
|
||||
Long id = userService.createUser(userDTO);
|
||||
return Result.success(id);
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("user:edit")
|
||||
public Result<Boolean> updateUser(@PathVariable Long id, @RequestBody UserDTO userDTO) {
|
||||
public Result<Boolean> updateUser(HttpServletRequest request, @PathVariable Long id, @RequestBody UserDTO userDTO) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
UserVO targetUser = userService.getUserById(id);
|
||||
if (targetUser == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权编辑其他店铺用户");
|
||||
if (userDTO.getType() != null) {
|
||||
adminScopeHelper.ensureAssignableUserType(currentUser, userDTO.getType());
|
||||
}
|
||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
userDTO.setShopId(adminScopeHelper.getManagedShopId(currentUser));
|
||||
}
|
||||
boolean success = userService.updateUser(id, userDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@PutMapping("/status/{id}")
|
||||
@RequirePermission("user:disable")
|
||||
public Result<Boolean> updateUserStatus(@PathVariable Long id, @RequestBody StatusRequest request) {
|
||||
public Result<Boolean> updateUserStatus(HttpServletRequest httpRequest, @PathVariable Long id, @RequestBody StatusRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(httpRequest);
|
||||
UserVO targetUser = userService.getUserById(id);
|
||||
if (targetUser == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权变更其他店铺用户状态");
|
||||
boolean success = userService.updateUserStatus(id, request.getStatus());
|
||||
return Result.success(success);
|
||||
}
|
||||
@@ -58,6 +87,12 @@ public class AdminUserController {
|
||||
@PostMapping("/reset-password/{userId}")
|
||||
@RequirePermission("user:reset_password")
|
||||
public Result<Boolean> resetPassword(HttpServletRequest request, @PathVariable Long userId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
UserVO targetUser = userService.getUserById(userId);
|
||||
if (targetUser == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权重置其他店铺用户密码");
|
||||
Long currentUserId = (Long) request.getAttribute("userId");
|
||||
boolean success = userService.resetPassword(userId, currentUserId);
|
||||
return Result.success(success);
|
||||
@@ -65,7 +100,13 @@ public class AdminUserController {
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("user:delete")
|
||||
public Result<Boolean> deleteUser(@PathVariable Long id) {
|
||||
public Result<Boolean> deleteUser(HttpServletRequest request, @PathVariable Long id) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
UserVO targetUser = userService.getUserById(id);
|
||||
if (targetUser == null) {
|
||||
return Result.success(false);
|
||||
}
|
||||
adminScopeHelper.ensureShopAccessible(currentUser, targetUser.getShopId(), "无权删除其他店铺用户");
|
||||
boolean success = userService.deleteUser(id);
|
||||
return Result.success(success);
|
||||
}
|
||||
@@ -83,8 +124,11 @@ public class AdminUserController {
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("user:view")
|
||||
public Result<List<UserVO>> listAllUsers() {
|
||||
List<UserVO> users = userService.listAllUsers();
|
||||
public Result<List<UserVO>> listAllUsers(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
List<UserVO> users = adminScopeHelper.isPlatformAdmin(currentUser)
|
||||
? userService.listAllUsers()
|
||||
: userService.listUsersByShopId(adminScopeHelper.getManagedShopId(currentUser));
|
||||
return Result.success(users);
|
||||
}
|
||||
|
||||
@@ -95,13 +139,16 @@ public class AdminUserController {
|
||||
*/
|
||||
@GetMapping("/list/artists")
|
||||
@RequirePermission("user:view")
|
||||
public Result<List<UserVO>> listArtists(@RequestParam(required = false) Long shopId) {
|
||||
public Result<List<UserVO>> listArtists(HttpServletRequest request, @RequestParam(required = false) Long shopId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
shopId = adminScopeHelper.resolveShopScope(currentUser, shopId);
|
||||
// 用户类型 3 表示美甲师
|
||||
List<UserVO> artists = userService.listUsersByType(3);
|
||||
// 如果指定了店铺ID,则过滤该店铺的美甲师
|
||||
if (shopId != null) {
|
||||
final Long resolvedShopId = shopId;
|
||||
artists = artists.stream()
|
||||
.filter(artist -> shopId.equals(artist.getShopId()))
|
||||
.filter(artist -> resolvedShopId.equals(artist.getShopId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return Result.success(artists);
|
||||
|
||||
+24
-8
@@ -1,6 +1,7 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.entity.CommentDO;
|
||||
import com.xiaowang.yuminailcore.entity.OrderDO;
|
||||
@@ -13,6 +14,7 @@ import com.xiaowang.yuminailcore.mapper.OrderMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.support.AdminScopeHelper;
|
||||
import com.xiaowang.yuminailcore.vo.DashboardStatsVO;
|
||||
import com.xiaowang.yuminailcore.vo.HotProductVO;
|
||||
import com.xiaowang.yuminailcore.vo.RecentActivityVO;
|
||||
@@ -39,14 +41,15 @@ public class DashboardController {
|
||||
private final CommentMapper commentMapper;
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
|
||||
@GetMapping("/stats")
|
||||
@RequirePermission("dashboard:view")
|
||||
public Result<DashboardStatsVO> getDashboardStats(HttpServletRequest request) {
|
||||
DashboardStatsVO stats = new DashboardStatsVO();
|
||||
|
||||
// 获取当前用户信息
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
UserDO currentUser = userMapper.selectById(userId);
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
Long shopIdScope = null;
|
||||
|
||||
if (currentUser != null) {
|
||||
// 根据用户类型显示不同的数据
|
||||
@@ -58,6 +61,7 @@ public class DashboardController {
|
||||
} else { // 店长或美甲师
|
||||
Long shopId = currentUser.getShopId();
|
||||
if (shopId != null) {
|
||||
shopIdScope = shopId;
|
||||
// 只显示当前店铺的数据
|
||||
stats.setTotalUsers(userMapper.selectCount(new LambdaQueryWrapper<UserDO>().eq(UserDO::getShopId, shopId)));
|
||||
stats.setTotalProducts(productMapper.selectCount(new LambdaQueryWrapper<ProductDO>().eq(ProductDO::getShopId, shopId)));
|
||||
@@ -79,8 +83,8 @@ public class DashboardController {
|
||||
stats.setTodayOrders(0L);
|
||||
}
|
||||
|
||||
stats.setHotProducts(getHotProducts());
|
||||
stats.setRecentActivities(getRecentActivities());
|
||||
stats.setHotProducts(getHotProducts(shopIdScope));
|
||||
stats.setRecentActivities(getRecentActivities(shopIdScope));
|
||||
|
||||
return Result.success(stats);
|
||||
}
|
||||
@@ -106,7 +110,7 @@ public class DashboardController {
|
||||
}
|
||||
}
|
||||
|
||||
private List<HotProductVO> getHotProducts() {
|
||||
private List<HotProductVO> getHotProducts(Long shopId) {
|
||||
// 通过订单商品表统计每个商品的订单数量,按订单数量排序
|
||||
// 使用SQL查询获取商品及其订单数量
|
||||
List<Map<String, Object>> productOrderCounts = orderItemMapper.selectMaps(
|
||||
@@ -124,7 +128,7 @@ public class DashboardController {
|
||||
Long productId = Long.valueOf(map.get("product_id").toString());
|
||||
ProductDO product = productMapper.selectById(productId);
|
||||
|
||||
if (product != null) {
|
||||
if (product != null && (shopId == null || shopId.equals(product.getShopId()))) {
|
||||
HotProductVO vo = new HotProductVO();
|
||||
BeanUtils.copyProperties(product, vo);
|
||||
vo.setLikeCount(product.getLikeCount() != null ? product.getLikeCount() : 0);
|
||||
@@ -135,6 +139,9 @@ public class DashboardController {
|
||||
// 如果按订单数量查询没有结果,使用点赞数作为备选
|
||||
if (hotProducts.isEmpty()) {
|
||||
LambdaQueryWrapper<ProductDO> wrapper = new LambdaQueryWrapper<>();
|
||||
if (shopId != null) {
|
||||
wrapper.eq(ProductDO::getShopId, shopId);
|
||||
}
|
||||
wrapper.orderByDesc(ProductDO::getLikeCount)
|
||||
.last("LIMIT 5");
|
||||
List<ProductDO> products = productMapper.selectList(wrapper);
|
||||
@@ -150,10 +157,13 @@ public class DashboardController {
|
||||
return hotProducts;
|
||||
}
|
||||
|
||||
private List<RecentActivityVO> getRecentActivities() {
|
||||
private List<RecentActivityVO> getRecentActivities(Long shopId) {
|
||||
List<RecentActivityVO> activities = new ArrayList<>();
|
||||
|
||||
LambdaQueryWrapper<UserDO> userWrapper = new LambdaQueryWrapper<>();
|
||||
if (shopId != null) {
|
||||
userWrapper.eq(UserDO::getShopId, shopId);
|
||||
}
|
||||
userWrapper.orderByDesc(UserDO::getCreateTime)
|
||||
.last("LIMIT 3");
|
||||
List<UserDO> recentUsers = userMapper.selectList(userWrapper);
|
||||
@@ -170,6 +180,9 @@ public class DashboardController {
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<ProductDO> productWrapper = new LambdaQueryWrapper<>();
|
||||
if (shopId != null) {
|
||||
productWrapper.eq(ProductDO::getShopId, shopId);
|
||||
}
|
||||
productWrapper.orderByDesc(ProductDO::getCreateTime)
|
||||
.last("LIMIT 2");
|
||||
List<ProductDO> recentProducts = productMapper.selectList(productWrapper);
|
||||
@@ -186,6 +199,9 @@ public class DashboardController {
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<CommentDO> commentWrapper = new LambdaQueryWrapper<>();
|
||||
if (shopId != null) {
|
||||
commentWrapper.eq(CommentDO::getShopId, shopId);
|
||||
}
|
||||
commentWrapper.orderByDesc(CommentDO::getCreateTime)
|
||||
.last("LIMIT 2");
|
||||
List<CommentDO> recentComments = commentMapper.selectList(commentWrapper);
|
||||
|
||||
+17
-8
@@ -1,5 +1,6 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.PermissionDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserPermissionDTO;
|
||||
@@ -30,8 +31,9 @@ public class PermissionController {
|
||||
*
|
||||
* @param permissionDTO 权限DTO
|
||||
* @return 权限ID
|
||||
*/
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("permission:create")
|
||||
public Result<Long> createPermission(@RequestBody PermissionDTO permissionDTO) {
|
||||
Long id = permissionService.createPermission(permissionDTO);
|
||||
return Result.success(id);
|
||||
@@ -43,8 +45,9 @@ public class PermissionController {
|
||||
* @param id 权限ID
|
||||
* @param permissionDTO 权限DTO
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("permission:edit")
|
||||
public Result<Boolean> updatePermission(@PathVariable Long id, @RequestBody PermissionDTO permissionDTO) {
|
||||
boolean success = permissionService.updatePermission(id, permissionDTO);
|
||||
return Result.success(success);
|
||||
@@ -55,8 +58,9 @@ public class PermissionController {
|
||||
*
|
||||
* @param id 权限ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("permission:delete")
|
||||
public Result<Boolean> deletePermission(@PathVariable Long id) {
|
||||
boolean success = permissionService.deletePermission(id);
|
||||
return Result.success(success);
|
||||
@@ -67,8 +71,9 @@ public class PermissionController {
|
||||
*
|
||||
* @param id 权限ID
|
||||
* @return 权限VO
|
||||
*/
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
@RequirePermission("permission:view")
|
||||
public Result<PermissionVO> getPermissionById(@PathVariable Long id) {
|
||||
PermissionVO permissionVO = permissionService.getPermissionById(id);
|
||||
return Result.success(permissionVO);
|
||||
@@ -78,8 +83,9 @@ public class PermissionController {
|
||||
* 查询所有权限
|
||||
*
|
||||
* @return 权限VO列表
|
||||
*/
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("permission:view")
|
||||
public Result<List<PermissionVO>> listAllPermissions() {
|
||||
List<PermissionVO> permissionVOs = permissionService.listAllPermissions();
|
||||
return Result.success(permissionVOs);
|
||||
@@ -90,8 +96,9 @@ public class PermissionController {
|
||||
*
|
||||
* @param permissionGroup 权限分组
|
||||
* @return 权限VO列表
|
||||
*/
|
||||
*/
|
||||
@GetMapping("/list/group/{permissionGroup}")
|
||||
@RequirePermission("permission:view")
|
||||
public Result<List<PermissionVO>> listPermissionsByGroup(@PathVariable String permissionGroup) {
|
||||
List<PermissionVO> permissionVOs = permissionService.listPermissionsByGroup(permissionGroup);
|
||||
return Result.success(permissionVOs);
|
||||
@@ -102,8 +109,9 @@ public class PermissionController {
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限VO列表
|
||||
*/
|
||||
*/
|
||||
@GetMapping("/list/user/{userId}")
|
||||
@RequirePermission("permission:view")
|
||||
public Result<List<PermissionVO>> listUserPermissions(@PathVariable Long userId) {
|
||||
List<PermissionVO> permissionVOs = permissionService.listUserPermissions(userId);
|
||||
return Result.success(permissionVOs);
|
||||
@@ -114,8 +122,9 @@ public class PermissionController {
|
||||
*
|
||||
* @param userPermissionDTO 用户权限分配DTO
|
||||
* @return 是否分配成功
|
||||
*/
|
||||
*/
|
||||
@PostMapping("/assign")
|
||||
@RequirePermission("permission:assign")
|
||||
public Result<Boolean> assignPermissions(HttpServletRequest request, @RequestBody UserPermissionDTO userPermissionDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
boolean success = permissionService.assignPermissions(userPermissionDTO, userId);
|
||||
|
||||
+42
-3
@@ -1,5 +1,6 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.*;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
@@ -42,6 +43,7 @@ public class UserController {
|
||||
* @return 用户ID
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("user:create")
|
||||
public Result<Long> createUser(@RequestBody UserDTO userDTO) {
|
||||
Long id = userService.createUser(userDTO);
|
||||
return Result.success(id);
|
||||
@@ -55,6 +57,7 @@ public class UserController {
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("user:edit")
|
||||
public Result<Boolean> updateUser(@PathVariable Long id, @RequestBody UserDTO userDTO) {
|
||||
boolean success = userService.updateUser(id, userDTO);
|
||||
return Result.success(success);
|
||||
@@ -67,6 +70,7 @@ public class UserController {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("user:delete")
|
||||
public Result<Boolean> deleteUser(@PathVariable Long id) {
|
||||
boolean success = userService.deleteUser(id);
|
||||
return Result.success(success);
|
||||
@@ -79,6 +83,7 @@ public class UserController {
|
||||
* @return 用户VO
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
@RequirePermission("user:view")
|
||||
public Result<UserVO> getUserById(@PathVariable Long id) {
|
||||
UserVO userVO = userService.getUserById(id);
|
||||
return Result.success(userVO);
|
||||
@@ -90,6 +95,7 @@ public class UserController {
|
||||
* @return 用户VO列表
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("user:view")
|
||||
public Result<List<UserVO>> listAllUsers() {
|
||||
List<UserVO> userVOs = userService.listAllUsers();
|
||||
return Result.success(userVOs);
|
||||
@@ -102,6 +108,7 @@ public class UserController {
|
||||
* @return 用户VO列表
|
||||
*/
|
||||
@GetMapping("/list/shop/{shopId}")
|
||||
@RequirePermission("user:view")
|
||||
public Result<List<UserVO>> listUsersByShopId(@PathVariable Long shopId) {
|
||||
List<UserVO> userVOs = userService.listUsersByShopId(shopId);
|
||||
return Result.success(userVOs);
|
||||
@@ -126,11 +133,35 @@ public class UserController {
|
||||
* @return 用户VO
|
||||
*/
|
||||
@GetMapping("/get/account/{account}")
|
||||
@RequirePermission("user:view")
|
||||
public Result<UserVO> getUserByAccount(@PathVariable String account) {
|
||||
UserVO userVO = userService.getUserByAccount(account);
|
||||
return Result.success(userVO);
|
||||
}
|
||||
|
||||
@GetMapping("/check/account/{account}")
|
||||
public Result<AvailabilityVO> checkAccountAvailability(@PathVariable String account) {
|
||||
UserDO userDO = userMapper.selectOne(
|
||||
com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getAccount, account)
|
||||
);
|
||||
boolean available = userDO == null || Integer.valueOf(1).equals(userDO.getIsDelete());
|
||||
String message = available ? "账号可用" : "账号已被注册";
|
||||
return Result.success(new AvailabilityVO(available, message));
|
||||
}
|
||||
|
||||
@GetMapping("/check/phone/{phone}")
|
||||
public Result<AvailabilityVO> checkPhoneAvailability(@PathVariable String phone) {
|
||||
UserDO userDO = userMapper.selectOne(
|
||||
com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getPhone, phone)
|
||||
.eq(UserDO::getIsDelete, 0)
|
||||
);
|
||||
boolean available = userDO == null;
|
||||
String message = available ? "手机号可用" : "该手机号已被注册";
|
||||
return Result.success(new AvailabilityVO(available, message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
@@ -235,10 +266,10 @@ public class UserController {
|
||||
* @param userDTO 用户DTO
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PutMapping({"/update", "/info"})
|
||||
public Result<Boolean> updateCurrentUserInfo(HttpServletRequest request, @RequestBody UserDTO userDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
boolean success = userService.updateUser(userId, userDTO);
|
||||
boolean success = userService.updateCurrentUserInfo(userId, userDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@@ -299,6 +330,7 @@ public class UserController {
|
||||
* @return 是否重置成功
|
||||
*/
|
||||
@PostMapping("/reset-password/{userId}")
|
||||
@RequirePermission("user:reset_password")
|
||||
public Result<Boolean> resetPassword(HttpServletRequest request, @PathVariable Long userId) {
|
||||
Long currentUserId = (Long) request.getAttribute("userId");
|
||||
boolean success = userService.resetPassword(userId, currentUserId);
|
||||
@@ -315,7 +347,7 @@ public class UserController {
|
||||
@PutMapping("/password")
|
||||
public Result<Boolean> updatePassword(HttpServletRequest request, @RequestBody PasswordDTO passwordDTO) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
boolean success = userService.updatePassword(userId, passwordDTO.getPassword());
|
||||
boolean success = userService.updatePassword(userId, passwordDTO.getPassword(), passwordDTO.getVerificationCode());
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@@ -376,5 +408,12 @@ public class UserController {
|
||||
@Data
|
||||
public static class PasswordDTO {
|
||||
private String password;
|
||||
private String verificationCode;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class AvailabilityVO {
|
||||
private final boolean available;
|
||||
private final String message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -20,5 +21,6 @@ public class BindPhoneRequestDTO {
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
private String code;
|
||||
@JsonAlias("code")
|
||||
private String verificationCode;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CartMapper extends BaseMapper<CartDO> {
|
||||
@Select("SELECT * FROM t_cart WHERE user_id = #{userId}")
|
||||
@Select("SELECT * FROM t_cart WHERE user_id = #{userId} AND is_delete = 0")
|
||||
List<CartDO> selectByUserId(@Param("userId") Long userId);
|
||||
|
||||
@Select("SELECT * FROM t_cart WHERE user_id = #{userId} AND product_id = #{productId}")
|
||||
@Select("SELECT * FROM t_cart WHERE user_id = #{userId} AND product_id = #{productId} AND is_delete = 0")
|
||||
CartDO selectByUserIdAndProductId(@Param("userId") Long userId, @Param("productId") Long productId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ public interface UserService extends IService<UserDO> {
|
||||
|
||||
UserVO getCurrentUserInfo();
|
||||
|
||||
boolean updateCurrentUserInfo(Long userId, UserDTO userDTO);
|
||||
|
||||
boolean bindPhone(Long userId, BindPhoneRequestDTO bindPhoneRequestDTO);
|
||||
|
||||
boolean bindEmail(Long userId, BindEmailRequestDTO bindEmailRequestDTO);
|
||||
@@ -62,7 +64,7 @@ public interface UserService extends IService<UserDO> {
|
||||
|
||||
boolean updateUserAvatar(Long userId, String avatarUrl);
|
||||
|
||||
boolean updatePassword(Long userId, String password);
|
||||
boolean updatePassword(Long userId, String password, String verificationCode);
|
||||
|
||||
boolean updatePhone(Long userId, UpdatePhoneRequestDTO updatePhoneDTO);
|
||||
}
|
||||
|
||||
+43
-1
@@ -7,7 +7,9 @@ import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||
import com.xiaowang.yuminailcore.mapper.CartMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||
import com.xiaowang.yuminailcore.service.CartService;
|
||||
import com.xiaowang.yuminailcore.service.TagService;
|
||||
import com.xiaowang.yuminailcore.vo.CartVO;
|
||||
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -15,6 +17,7 @@ import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CartServiceImpl implements CartService {
|
||||
@@ -25,9 +28,14 @@ public class CartServiceImpl implements CartService {
|
||||
@Resource
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Resource
|
||||
private TagService tagService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void addToCart(Long userId, CartDTO cartDTO) {
|
||||
validateQuantity(cartDTO.getQuantity());
|
||||
|
||||
// 检查商品是否存在
|
||||
ProductDO product = productMapper.selectById(cartDTO.getProductId());
|
||||
if (product == null || product.getIsDelete() == 1) {
|
||||
@@ -77,11 +85,15 @@ public class CartServiceImpl implements CartService {
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateCartQuantity(Long userId, CartDTO cartDTO) {
|
||||
validateQuantity(cartDTO.getQuantity());
|
||||
CartDO cart = cartMapper.selectByUserIdAndProductId(userId, cartDTO.getProductId());
|
||||
if (cart != null) {
|
||||
cart.setQuantity(cartDTO.getQuantity());
|
||||
cartMapper.updateById(cart);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new RuntimeException("购物车商品不存在");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,6 +108,7 @@ public class CartServiceImpl implements CartService {
|
||||
CartVO cartVO = new CartVO();
|
||||
cartVO.setId(cart.getId());
|
||||
cartVO.setProductId(product.getId());
|
||||
cartVO.setShopId(product.getShopId());
|
||||
cartVO.setProductTitle(product.getTitle());
|
||||
// 简单处理,取第一张图片
|
||||
String imageFileIds = product.getImageFileIds();
|
||||
@@ -107,6 +120,9 @@ public class CartServiceImpl implements CartService {
|
||||
cartVO.setQuantity(cart.getQuantity());
|
||||
cartVO.setTotalPrice(product.getPrice().multiply(new BigDecimal(cart.getQuantity())));
|
||||
cartVO.setTags(product.getTags());
|
||||
cartVO.setTagNames(resolveTagNames(product.getTags()));
|
||||
cartVO.setApproximateDuration(product.getApproximateDuration());
|
||||
cartVO.setBookableArtists(product.getBookableArtists());
|
||||
cartVOList.add(cartVO);
|
||||
}
|
||||
}
|
||||
@@ -123,4 +139,30 @@ public class CartServiceImpl implements CartService {
|
||||
.eq("is_delete", 0);
|
||||
cartMapper.delete(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateQuantity(Integer quantity) {
|
||||
if (quantity == null || quantity < 1 || quantity > 99) {
|
||||
throw new RuntimeException("购物车数量必须在1到99之间");
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveTagNames(String tagIds) {
|
||||
if (tagIds == null || tagIds.isBlank()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return List.of(tagIds.split(";")).stream()
|
||||
.map(String::trim)
|
||||
.filter(tagId -> !tagId.isEmpty())
|
||||
.map(tagId -> {
|
||||
try {
|
||||
TagVO tagVO = tagService.getTagById(Long.parseLong(tagId));
|
||||
return tagVO != null ? tagVO.getTagName() : null;
|
||||
} catch (NumberFormatException ex) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(tagName -> tagName != null && !tagName.isBlank())
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.dto.ProductDTO;
|
||||
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.service.ObjectStorageFileService;
|
||||
import com.xiaowang.yuminailcore.service.ProductService;
|
||||
import com.xiaowang.yuminailcore.service.TagService;
|
||||
@@ -37,9 +39,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
private final ProductMapper productMapper;
|
||||
private final TagService tagService;
|
||||
private final ObjectStorageFileService objectStorageFileService;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public Long createProduct(ProductDTO productDTO) {
|
||||
validateBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists());
|
||||
ProductDO productDO = new ProductDO();
|
||||
productDO.setShopId(productDTO.getShopId());
|
||||
productDO.setTitle(productDTO.getTitle());
|
||||
@@ -61,6 +65,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
if (productDO == null) {
|
||||
return false;
|
||||
}
|
||||
validateBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists());
|
||||
productDO.setShopId(productDTO.getShopId());
|
||||
productDO.setTitle(productDTO.getTitle());
|
||||
productDO.setDescription(productDTO.getDescription());
|
||||
@@ -239,4 +244,38 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void validateBookableArtists(Long shopId, String bookableArtists) {
|
||||
if (!StringUtils.hasText(bookableArtists)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shopId == null || shopId <= 0) {
|
||||
throw new RuntimeException("配置可预约美甲师前必须先选择店铺");
|
||||
}
|
||||
|
||||
for (String artistIdStr : bookableArtists.split(",")) {
|
||||
if (!StringUtils.hasText(artistIdStr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Long artistId;
|
||||
try {
|
||||
artistId = Long.parseLong(artistIdStr.trim());
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new RuntimeException("可预约美甲师配置格式不正确");
|
||||
}
|
||||
|
||||
UserDO artist = userMapper.selectById(artistId);
|
||||
if (artist == null || Integer.valueOf(1).equals(artist.getIsDelete())) {
|
||||
throw new RuntimeException("存在无效的美甲师配置");
|
||||
}
|
||||
if (!Integer.valueOf(3).equals(artist.getType())) {
|
||||
throw new RuntimeException("存在非美甲师账号被配置到可预约列表");
|
||||
}
|
||||
if (!shopId.equals(artist.getShopId())) {
|
||||
throw new RuntimeException("不可跨店铺配置可预约美甲师");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+82
-44
@@ -22,7 +22,6 @@ import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -53,7 +52,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
private final NailArtistInfoService nailArtistInfoService;
|
||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
private final VerificationCodeService verificationCodeService;
|
||||
private final RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
/**
|
||||
* 创建新用户
|
||||
@@ -397,9 +395,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
.eq(UserDO::getAccount, loginRequestDTO.getAccount())
|
||||
);
|
||||
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
assertUserAvailable(userDO);
|
||||
|
||||
// 检查是否为未设置密码的账号
|
||||
if (ENCODED_UNSET_PASSWORD.equals(userDO.getPassword())) {
|
||||
@@ -457,6 +453,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
}
|
||||
userDO = registerByPhone(phoneLoginRequestDTO.getPhone(), phoneLoginRequestDTO.getShopId());
|
||||
} else {
|
||||
assertUserAvailable(userDO);
|
||||
if (userDO.getShopId() == null || userDO.getShopId() == 0) {
|
||||
if (phoneLoginRequestDTO.getShopId() == null || phoneLoginRequestDTO.getShopId() == 0) {
|
||||
throw new RuntimeException("请选择店铺");
|
||||
@@ -518,9 +515,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
.eq(UserDO::getAccount, loginRequestDTO.getAccount())
|
||||
);
|
||||
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
assertUserAvailable(userDO);
|
||||
|
||||
if (!passwordEncoder.matches(loginRequestDTO.getPassword(), userDO.getPassword())) {
|
||||
throw new RuntimeException("密码错误");
|
||||
@@ -610,9 +605,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
String account = jwtUtil.getAccountFromToken(refreshToken);
|
||||
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
assertUserAvailable(userDO);
|
||||
|
||||
String newAccessToken = jwtUtil.generateAccessToken(userId, account);
|
||||
String newRefreshToken = jwtUtil.generateRefreshToken(userId, account);
|
||||
@@ -643,12 +636,35 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateCurrentUserInfo(Long userId, UserDTO userDTO) {
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
assertUserAvailable(userDO);
|
||||
|
||||
if (userDTO.getNickname() != null) {
|
||||
userDO.setNickname(userDTO.getNickname());
|
||||
}
|
||||
if (userDTO.getAvatar() != null) {
|
||||
if (userDTO.getAvatar().isEmpty()) {
|
||||
userDO.setAvatar(null);
|
||||
} else {
|
||||
userDO.setAvatar(userDTO.getAvatar());
|
||||
}
|
||||
}
|
||||
if (userDTO.getSignature() != null) {
|
||||
userDO.setSignature(userDTO.getSignature());
|
||||
}
|
||||
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindPhone(Long userId, BindPhoneRequestDTO bindPhoneRequestDTO) {
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
assertUserAvailable(userDO);
|
||||
validateVerificationCode(bindPhoneRequestDTO.getPhone(), bindPhoneRequestDTO.getVerificationCode());
|
||||
ensurePhoneNotUsed(bindPhoneRequestDTO.getPhone(), userId);
|
||||
|
||||
userDO.setPhone(bindPhoneRequestDTO.getPhone());
|
||||
userDO.setPhoneVerified(1);
|
||||
@@ -745,20 +761,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
@Override
|
||||
public boolean updateUserAvatar(Long userId, String avatarUrl) {
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
assertUserAvailable(userDO);
|
||||
userDO.setAvatar(avatarUrl);
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updatePassword(Long userId, String password) {
|
||||
public boolean updatePassword(Long userId, String password, String verificationCode) {
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
assertUserAvailable(userDO);
|
||||
if (!StringUtils.hasText(userDO.getPhone())) {
|
||||
throw new RuntimeException("请先绑定手机号");
|
||||
}
|
||||
validateVerificationCode(userDO.getPhone(), verificationCode);
|
||||
userDO.setPassword(passwordEncoder.encode(password));
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
@@ -770,27 +786,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
String newPhone = updatePhoneDTO.getNewPhone();
|
||||
String verificationCode = updatePhoneDTO.getVerificationCode();
|
||||
|
||||
// 验证验证码
|
||||
String redisKey = "verification_code:" + newPhone;
|
||||
String storedCode = redisTemplate.opsForValue().get(redisKey);
|
||||
if (storedCode == null || !storedCode.equals(verificationCode)) {
|
||||
throw new RuntimeException("验证码错误");
|
||||
}
|
||||
|
||||
// 检查新手机号是否已被其他用户使用
|
||||
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
||||
wrapper.eq(UserDO::getPhone, newPhone);
|
||||
wrapper.ne(UserDO::getId, userId);
|
||||
if (userMapper.selectOne(wrapper) != null) {
|
||||
throw new RuntimeException("手机号已被使用");
|
||||
}
|
||||
|
||||
// 更新手机号
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
assertUserAvailable(userDO);
|
||||
if (!StringUtils.hasText(userDO.getPhone())) {
|
||||
throw new RuntimeException("当前账号未绑定手机号");
|
||||
}
|
||||
if (!userDO.getPhone().equals(oldPhone)) {
|
||||
throw new RuntimeException("原手机号不匹配");
|
||||
}
|
||||
|
||||
validateVerificationCode(newPhone, verificationCode);
|
||||
ensurePhoneNotUsed(newPhone, userId);
|
||||
|
||||
userDO.setPhone(newPhone);
|
||||
userDO.setPhoneVerified(1);
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
@@ -801,25 +810,54 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
String verificationCode = resetPasswordRequestDTO.getVerificationCode();
|
||||
String newPassword = resetPasswordRequestDTO.getNewPassword();
|
||||
|
||||
// 验证验证码
|
||||
String redisKey = "verification_code:" + phone;
|
||||
String storedCode = redisTemplate.opsForValue().get(redisKey);
|
||||
if (storedCode == null || !storedCode.equals(verificationCode)) {
|
||||
throw new RuntimeException("验证码错误");
|
||||
}
|
||||
validateVerificationCode(phone, verificationCode);
|
||||
|
||||
// 根据手机号查找用户
|
||||
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
||||
wrapper.eq(UserDO::getPhone, phone);
|
||||
wrapper.eq(UserDO::getIsDelete, 0);
|
||||
UserDO userDO = userMapper.selectOne(wrapper);
|
||||
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("未绑定手机号,请联系店员");
|
||||
}
|
||||
if (userDO.getStatus() != null && !Integer.valueOf(1).equals(userDO.getStatus())) {
|
||||
throw new RuntimeException("账号已被禁用");
|
||||
}
|
||||
|
||||
// 更新密码
|
||||
userDO.setPassword(passwordEncoder.encode(newPassword));
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
|
||||
private void assertUserAvailable(UserDO userDO) {
|
||||
if (userDO == null || Integer.valueOf(1).equals(userDO.getIsDelete())) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
if (userDO.getStatus() != null && !Integer.valueOf(1).equals(userDO.getStatus())) {
|
||||
throw new RuntimeException("账号已被禁用");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateVerificationCode(String phone, String verificationCode) {
|
||||
if (!StringUtils.hasText(phone) || !StringUtils.hasText(verificationCode)) {
|
||||
throw new RuntimeException("验证码不能为空");
|
||||
}
|
||||
if (!verificationCodeService.verifyCode(phone, verificationCode)) {
|
||||
throw new RuntimeException("验证码错误或已过期");
|
||||
}
|
||||
}
|
||||
|
||||
private void ensurePhoneNotUsed(String phone, Long currentUserId) {
|
||||
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getPhone, phone)
|
||||
.eq(UserDO::getIsDelete, 0);
|
||||
if (currentUserId != null) {
|
||||
wrapper.ne(UserDO::getId, currentUserId);
|
||||
}
|
||||
if (userMapper.selectOne(wrapper) != null) {
|
||||
throw new RuntimeException("手机号已被使用");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+27
-3
@@ -3,12 +3,13 @@ package com.xiaowang.yuminailcore.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.dto.WishlistDTO;
|
||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||
import com.xiaowang.yuminailcore.entity.ProductDO;
|
||||
import com.xiaowang.yuminailcore.entity.WishlistDO;
|
||||
import com.xiaowang.yuminailcore.mapper.WishlistMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ProductMapper;
|
||||
import com.xiaowang.yuminailcore.service.WishlistService;
|
||||
import com.xiaowang.yuminailcore.service.ProductService;
|
||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -29,6 +30,11 @@ public class WishlistServiceImpl extends ServiceImpl<WishlistMapper, WishlistDO>
|
||||
@Override
|
||||
@Transactional
|
||||
public void addToWishlist(Long userId, Long productId) {
|
||||
ProductDO product = getValidProduct(productId);
|
||||
if (product == null) {
|
||||
throw new RuntimeException("商品不存在或已下架");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<WishlistDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(WishlistDO::getUserId, userId);
|
||||
wrapper.eq(WishlistDO::getProductId, productId);
|
||||
@@ -51,12 +57,17 @@ public class WishlistServiceImpl extends ServiceImpl<WishlistMapper, WishlistDO>
|
||||
if (count(wrapper) > 0) {
|
||||
remove(wrapper);
|
||||
// 减少商品收藏数
|
||||
productMapper.decrementCollectCount(productId);
|
||||
if (getValidProduct(productId) != null) {
|
||||
productMapper.decrementCollectCount(productId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInWishlist(Long userId, Long productId) {
|
||||
if (getValidProduct(productId) == null) {
|
||||
return false;
|
||||
}
|
||||
LambdaQueryWrapper<WishlistDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(WishlistDO::getUserId, userId);
|
||||
wrapper.eq(WishlistDO::getProductId, productId);
|
||||
@@ -74,6 +85,19 @@ public class WishlistServiceImpl extends ServiceImpl<WishlistMapper, WishlistDO>
|
||||
ProductVO productVO = productService.getProductById(wishlistDO.getProductId());
|
||||
wishlistDTO.setProduct(productVO);
|
||||
return wishlistDTO;
|
||||
}).collect(Collectors.toList());
|
||||
}).filter(wishlistDTO -> wishlistDTO.getProduct() != null).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private ProductDO getValidProduct(Long productId) {
|
||||
if (productId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ProductDO product = productMapper.selectById(productId);
|
||||
if (product == null || Integer.valueOf(1).equals(product.getIsDelete())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return product;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.xiaowang.yuminailcore.support;
|
||||
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AdminScopeHelper {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public UserDO getCurrentUser(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
if (userId == null) {
|
||||
throw new RuntimeException("未获取到当前用户信息");
|
||||
}
|
||||
|
||||
UserDO currentUser = userService.getById(userId);
|
||||
if (currentUser == null || Integer.valueOf(1).equals(currentUser.getIsDelete())) {
|
||||
throw new RuntimeException("当前用户不存在或已失效");
|
||||
}
|
||||
|
||||
return currentUser;
|
||||
}
|
||||
|
||||
public boolean isPlatformAdmin(UserDO currentUser) {
|
||||
return currentUser != null && Integer.valueOf(4).equals(currentUser.getType());
|
||||
}
|
||||
|
||||
public Long getManagedShopId(UserDO currentUser) {
|
||||
if (isPlatformAdmin(currentUser)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (currentUser == null || currentUser.getShopId() == null || currentUser.getShopId() <= 0) {
|
||||
throw new RuntimeException("当前账号未绑定店铺,无法访问后台业务数据");
|
||||
}
|
||||
|
||||
return currentUser.getShopId();
|
||||
}
|
||||
|
||||
public Long resolveShopScope(UserDO currentUser, Long requestedShopId) {
|
||||
Long managedShopId = getManagedShopId(currentUser);
|
||||
return managedShopId != null ? managedShopId : requestedShopId;
|
||||
}
|
||||
|
||||
public void ensureShopAccessible(UserDO currentUser, Long targetShopId, String message) {
|
||||
Long managedShopId = getManagedShopId(currentUser);
|
||||
if (managedShopId != null && !managedShopId.equals(targetShopId)) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void requirePlatformAdmin(UserDO currentUser, String message) {
|
||||
if (!isPlatformAdmin(currentUser)) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void ensureAssignableUserType(UserDO currentUser, Integer targetType) {
|
||||
if (targetType == null) {
|
||||
throw new RuntimeException("用户类型不能为空");
|
||||
}
|
||||
|
||||
if (isPlatformAdmin(currentUser)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Integer.valueOf(2).equals(currentUser.getType())) {
|
||||
if (Integer.valueOf(0).equals(targetType) || Integer.valueOf(3).equals(targetType)) {
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException("店长只能创建或维护普通用户、美甲师");
|
||||
}
|
||||
|
||||
if (Integer.valueOf(3).equals(currentUser.getType())) {
|
||||
if (Integer.valueOf(0).equals(targetType)) {
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException("美甲师只能创建或维护普通用户");
|
||||
}
|
||||
|
||||
throw new RuntimeException("当前角色无权维护后台用户");
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,14 @@ import java.math.BigDecimal;
|
||||
public class CartVO {
|
||||
private Long id;
|
||||
private Long productId;
|
||||
private Long shopId;
|
||||
private String productTitle;
|
||||
private String productImage;
|
||||
private BigDecimal price;
|
||||
private Integer quantity;
|
||||
private BigDecimal totalPrice;
|
||||
private String tags;
|
||||
}
|
||||
private String tagNames;
|
||||
private String approximateDuration;
|
||||
private String bookableArtists;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user