完成Salon SIT整改并清理旧接口
This commit is contained in:
-8
@@ -3,7 +3,6 @@ package com.xiaowang.jayucloud.salon.core.modules.order.controller.front;
|
||||
import com.xiaowang.jayucloud.salon.core.annotation.OperationGuard;
|
||||
import com.xiaowang.jayucloud.salon.core.annotation.RequirePermission;
|
||||
import com.xiaowang.jayucloud.salon.core.common.Result;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.CheckoutPreviewDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRejectDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRequestDTO;
|
||||
@@ -14,7 +13,6 @@ import com.xiaowang.jayucloud.salon.core.modules.order.service.OrderService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.support.SecurityAuditActions;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.support.SecurityAuditSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.CheckoutPreviewVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderArtistChangeOptionsVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderArtistChangeRequestVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderArtistReviewVO;
|
||||
@@ -73,12 +71,6 @@ public class OrderController {
|
||||
return Result.success(orderVO);
|
||||
}
|
||||
|
||||
@PostMapping("/checkout-preview")
|
||||
public Result<CheckoutPreviewVO> checkoutPreview(@RequestBody CheckoutPreviewDTO checkoutPreviewDTO, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
return Result.success(orderService.checkoutPreview(userId, checkoutPreviewDTO));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
|
||||
-7
@@ -1,14 +1,12 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.order.service;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.CheckoutPreviewDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRejectDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRequestDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistReviewSubmitDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteReplyDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteSubmitDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.artist.vo.ArtistCalendarAppointmentVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.CheckoutPreviewVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderArtistChangeOptionsVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderArtistChangeRequestVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderArtistReviewVO;
|
||||
@@ -31,11 +29,6 @@ public interface OrderService {
|
||||
*/
|
||||
OrderVO createOrder(Long userId, OrderDTO orderDTO);
|
||||
|
||||
/**
|
||||
* Preview checkout pricing and coupon explanations without creating an order.
|
||||
*/
|
||||
CheckoutPreviewVO checkoutPreview(Long userId, CheckoutPreviewDTO checkoutPreviewDTO);
|
||||
|
||||
/**
|
||||
* Load data by the supplied parameter.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
|
||||
+3
-107
@@ -3,8 +3,8 @@ package com.xiaowang.jayucloud.salon.core.modules.order.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xiaowang.jayucloud.salon.core.common.BusinessException;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.CheckoutPreviewDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.CheckoutPreviewDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRejectDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRequestDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistReviewSubmitDTO;
|
||||
@@ -55,10 +55,10 @@ import com.xiaowang.jayucloud.salon.core.modules.order.support.OrderStatus;
|
||||
import com.xiaowang.jayucloud.salon.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.support.UserShopBindingSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.artist.vo.ArtistCalendarAppointmentVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.CheckoutCouponPreviewVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.CheckoutPreviewVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.CheckoutPreviewVO.CheckoutIssueVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderArtistChangeOptionsVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.CheckoutCouponPreviewVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.CheckoutPreviewVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderArtistChangeRequestVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderArtistReviewVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderItemVO;
|
||||
@@ -543,53 +543,6 @@ public class OrderServiceImpl implements OrderService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckoutPreviewVO checkoutPreview(Long userId, CheckoutPreviewDTO checkoutPreviewDTO) {
|
||||
OrderDTO orderDTO = toOrderDTO(checkoutPreviewDTO);
|
||||
CheckoutPricingContext pricingContext = buildCheckoutPricingContext(userId, orderDTO);
|
||||
List<CheckoutIssueVO> bookingIssues = collectCheckoutBookingIssues(userId, orderDTO);
|
||||
List<UserCouponVO> availableCouponOptions = couponService.getAvailableCoupons(
|
||||
userId,
|
||||
pricingContext.getProductTagNames(),
|
||||
pricingContext.getTotalAmount().doubleValue(),
|
||||
pricingContext.getShopId()
|
||||
);
|
||||
if (availableCouponOptions == null) {
|
||||
availableCouponOptions = List.of();
|
||||
}
|
||||
|
||||
List<CheckoutCouponPreviewVO> availableCoupons = availableCouponOptions.stream()
|
||||
.map(coupon -> buildAvailableCouponPreview(coupon, pricingContext.getTotalAmount()))
|
||||
.sorted(Comparator.comparing(CheckoutCouponPreviewVO::getDiscountAmount, Comparator.nullsLast(BigDecimal::compareTo)).reversed()
|
||||
.thenComparing(CheckoutCouponPreviewVO::getEndTime, Comparator.nullsLast(LocalDateTime::compareTo)))
|
||||
.toList();
|
||||
|
||||
CheckoutCouponPreviewVO bestCoupon = findBestCouponPreview(availableCoupons);
|
||||
if (bestCoupon != null) {
|
||||
bestCoupon.setBest(true);
|
||||
}
|
||||
|
||||
CheckoutCouponPreviewVO selectedCoupon = resolvePreviewSelectedCoupon(checkoutPreviewDTO, availableCoupons, bestCoupon);
|
||||
BigDecimal savedAmount = selectedCoupon == null ? BigDecimal.ZERO : safeAmount(selectedCoupon.getDiscountAmount());
|
||||
BigDecimal payableAmount = pricingContext.getTotalAmount().subtract(savedAmount);
|
||||
if (payableAmount.compareTo(BigDecimal.ZERO) < 0) {
|
||||
payableAmount = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
CheckoutPreviewVO preview = new CheckoutPreviewVO();
|
||||
preview.setSubtotalAmount(scaleMoney(pricingContext.getTotalAmount()));
|
||||
preview.setSavedAmount(scaleMoney(savedAmount));
|
||||
preview.setPayableAmount(scaleMoney(payableAmount));
|
||||
preview.setBestCoupon(bestCoupon);
|
||||
preview.setAvailableCoupons(availableCoupons);
|
||||
preview.setUnavailableCoupons(buildUnavailableCouponPreviews(availableCoupons, pricingContext));
|
||||
preview.setBookingAvailable(bookingIssues.isEmpty());
|
||||
preview.setBookingIssues(bookingIssues);
|
||||
preview.setVipTip(buildVipTip(userId, pricingContext.getTotalAmount(), availableCoupons));
|
||||
preview.setSummaryText(buildCheckoutSummaryText(preview));
|
||||
return preview;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new record.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
@@ -849,63 +802,6 @@ public class OrderServiceImpl implements OrderService {
|
||||
return buildOrderVO(order);
|
||||
}
|
||||
|
||||
private OrderDTO toOrderDTO(CheckoutPreviewDTO checkoutPreviewDTO) {
|
||||
OrderDTO orderDTO = new OrderDTO();
|
||||
if (checkoutPreviewDTO == null) {
|
||||
return orderDTO;
|
||||
}
|
||||
orderDTO.setCouponId(checkoutPreviewDTO.getCouponId());
|
||||
orderDTO.setCouponSourceType(checkoutPreviewDTO.getCouponSourceType());
|
||||
orderDTO.setRemark(checkoutPreviewDTO.getRemark());
|
||||
orderDTO.setItems(checkoutPreviewDTO.getItems());
|
||||
return orderDTO;
|
||||
}
|
||||
|
||||
private CheckoutPricingContext buildCheckoutPricingContext(Long userId, OrderDTO orderDTO) {
|
||||
if (orderDTO == null || orderDTO.getItems() == null || orderDTO.getItems().isEmpty()) {
|
||||
throw new RuntimeException("订单项不能为空");
|
||||
}
|
||||
|
||||
List<OrderItemDTO> orderItemDTOs = orderDTO.getItems();
|
||||
Map<Long, Integer> requestedQuantityByProductId = buildRequestedQuantityMap(orderItemDTOs);
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
Set<String> selectedTagNames = new LinkedHashSet<>();
|
||||
Long shopId = null;
|
||||
|
||||
for (OrderItemDTO orderItemDTO : orderItemDTOs) {
|
||||
validateOrderQuantity(orderItemDTO.getQuantity());
|
||||
ProductDO product = productMapper.selectById(orderItemDTO.getProductId());
|
||||
if (product == null || Integer.valueOf(1).equals(product.getIsDelete())) {
|
||||
throw new RuntimeException("商品不存在或已下架");
|
||||
}
|
||||
|
||||
CartDO cartItem = cartMapper.selectByUserIdAndProductId(userId, product.getId());
|
||||
Integer requestedQuantity = requestedQuantityByProductId.get(product.getId());
|
||||
if (cartItem == null || Integer.valueOf(1).equals(cartItem.getIsDelete())) {
|
||||
throw new RuntimeException("请先将商品加入购物车后再结算");
|
||||
}
|
||||
if (cartItem.getQuantity() == null || requestedQuantity == null || cartItem.getQuantity() < requestedQuantity) {
|
||||
throw new RuntimeException("购物车中的商品数量已变化,请刷新后重试");
|
||||
}
|
||||
|
||||
if (shopId == null) {
|
||||
shopId = product.getShopId();
|
||||
validateUserCanCreateOrderInShop(userId, shopId);
|
||||
} else if (!shopId.equals(product.getShopId())) {
|
||||
throw new RuntimeException("跨店铺商品请分开下单");
|
||||
}
|
||||
|
||||
collectPreviewTagNames(selectedTagNames, product.getTags());
|
||||
BigDecimal price = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
|
||||
totalAmount = totalAmount.add(price.multiply(BigDecimal.valueOf(orderItemDTO.getQuantity())));
|
||||
}
|
||||
|
||||
if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
|
||||
throw new RuntimeException("订单金额无效");
|
||||
}
|
||||
return new CheckoutPricingContext(totalAmount, shopId, String.join(",", selectedTagNames));
|
||||
}
|
||||
|
||||
private List<CheckoutIssueVO> collectCheckoutBookingIssues(Long userId, OrderDTO orderDTO) {
|
||||
List<CheckoutIssueVO> issues = new ArrayList<>();
|
||||
if (orderDTO == null || orderDTO.getItems() == null || orderDTO.getItems().isEmpty()) {
|
||||
|
||||
+3
-5
@@ -13,7 +13,6 @@ import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelp
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.service.LegalAgreementService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.service.UserAssetService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserVO;
|
||||
import com.xiaowang.jayucloud.salon.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
@@ -39,7 +38,7 @@ class UserControllerPhonePrivacyTest {
|
||||
profile.setShopBusinessExpired(false);
|
||||
profile.setShopBusinessRemainingDays(66);
|
||||
when(userService.getCurrentUserInfo()).thenReturn(profile);
|
||||
UserController controller = new UserController(userService, mock(UserAssetService.class),
|
||||
UserController controller = new UserController(userService,
|
||||
mock(PrimaryObjectStorageService.class), mock(ChunkUploadService.class),
|
||||
mock(VerificationCodeService.class), mock(UserMapper.class), mock(AdminScopeHelper.class),
|
||||
mock(ShopRoleService.class), mock(TimeOrderedSnowflakeIdGenerator.class),
|
||||
@@ -57,7 +56,6 @@ class UserControllerPhonePrivacyTest {
|
||||
@Test
|
||||
void sendsPasswordCodeToVerifiedPhoneFromCurrentAccount() {
|
||||
UserService userService = mock(UserService.class);
|
||||
UserAssetService userAssetService = mock(UserAssetService.class);
|
||||
PrimaryObjectStorageService primaryObjectStorageService = mock(PrimaryObjectStorageService.class);
|
||||
ChunkUploadService chunkUploadService = mock(ChunkUploadService.class);
|
||||
VerificationCodeService verificationCodeService = mock(VerificationCodeService.class);
|
||||
@@ -71,7 +69,7 @@ class UserControllerPhonePrivacyTest {
|
||||
LegalAgreementService legalAgreementService = mock(LegalAgreementService.class);
|
||||
AccountClosureService accountClosureService = mock(AccountClosureService.class);
|
||||
SecurityAuditLogService securityAuditLogService = mock(SecurityAuditLogService.class);
|
||||
UserController controller = new UserController(userService, userAssetService, primaryObjectStorageService,
|
||||
UserController controller = new UserController(userService, primaryObjectStorageService,
|
||||
chunkUploadService, verificationCodeService, userMapper, adminScopeHelper, shopRoleService,
|
||||
idGenerator, wechatMiniAuthService, objectStorageUrlSupport, requestThrottleService,
|
||||
legalAgreementService, accountClosureService, securityAuditLogService);
|
||||
@@ -96,7 +94,7 @@ class UserControllerPhonePrivacyTest {
|
||||
|
||||
@Test
|
||||
void rejectsPasswordCodeRequestWithoutAuthenticatedUser() {
|
||||
UserController controller = new UserController(mock(UserService.class), mock(UserAssetService.class),
|
||||
UserController controller = new UserController(mock(UserService.class),
|
||||
mock(PrimaryObjectStorageService.class), mock(ChunkUploadService.class),
|
||||
mock(VerificationCodeService.class), mock(UserMapper.class), mock(AdminScopeHelper.class),
|
||||
mock(ShopRoleService.class), mock(TimeOrderedSnowflakeIdGenerator.class),
|
||||
|
||||
Reference in New Issue
Block a user