feat:订单创建
parent
6d9aca34a1
commit
f2b809bc3c
|
|
@ -1,9 +1,13 @@
|
|||
package com.ruoyi.common.utils.bean;
|
||||
|
||||
import java.util.Set;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.SimpleEntity;
|
||||
import com.ruoyi.common.core.domain.XktBaseEntity;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.Validator;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* bean对象属性验证
|
||||
|
|
@ -21,4 +25,12 @@ public class BeanValidators
|
|||
throw new ConstraintViolationException(constraintViolations);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends SimpleEntity> boolean exists(T entity) {
|
||||
return entity != null && Constants.UNDELETED.equals(entity.getDelFlag());
|
||||
}
|
||||
|
||||
public static <T extends XktBaseEntity> boolean exists(T entity) {
|
||||
return entity != null && Constants.UNDELETED.equals(entity.getDelFlag());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ import java.math.BigDecimal;
|
|||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ExpressFeeConfig extends SimpleEntity {
|
||||
/**
|
||||
* 物流ID
|
||||
*/
|
||||
private Long expressId;
|
||||
/**
|
||||
* 地区编码,基于行政区划代码做扩展,唯一约束
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ public class ExpressFeeConfigDTO {
|
|||
* ID
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 物流ID
|
||||
*/
|
||||
private Long expressId;
|
||||
/**
|
||||
* 地区编码,基于行政区划代码做扩展,唯一约束
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -15,6 +15,18 @@ public class StoreOrderAddDTO {
|
|||
* 档口ID
|
||||
*/
|
||||
private Long storeId;
|
||||
/**
|
||||
* 下单用户ID
|
||||
*/
|
||||
private Long orderUserId;
|
||||
/**
|
||||
* 订单备注
|
||||
*/
|
||||
private String orderRemark;
|
||||
/**
|
||||
* 物流ID
|
||||
*/
|
||||
private Long expressId;
|
||||
/**
|
||||
* 收货人-名称
|
||||
*/
|
||||
|
|
@ -50,10 +62,10 @@ public class StoreOrderAddDTO {
|
|||
/**
|
||||
* 明细列表
|
||||
*/
|
||||
private List<OrderDetail> detailList;
|
||||
private List<Detail> detailList;
|
||||
|
||||
@Data
|
||||
public static class OrderDetail {
|
||||
public static class Detail {
|
||||
/**
|
||||
* 商品颜色尺码ID
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-04-02 22:39
|
||||
|
|
@ -15,5 +13,4 @@ import java.util.List;
|
|||
@ToString(callSuper = true)
|
||||
public class StoreOrderDetailInfoDTO extends StoreOrderDetailDTO {
|
||||
|
||||
private List<StoreOrderDetailInfoDTO> detailList;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-04-02 22:37
|
||||
|
|
@ -11,7 +13,7 @@ import lombok.ToString;
|
|||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class StoreOrderInfoDTO extends StoreOrderDTO{
|
||||
public class StoreOrderInfoDTO extends StoreOrderDTO {
|
||||
|
||||
|
||||
private List<StoreOrderDetailInfoDTO> detailList;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ public enum EDeliveryType {
|
|||
SHIP_COMPLETE(1, "货齐再发"),
|
||||
PARTIAL_SHIPMENT(2, "有货先发");
|
||||
|
||||
private Integer value;
|
||||
private String label;
|
||||
private final Integer value;
|
||||
private final String label;
|
||||
|
||||
public static EDeliveryType of(String value) {
|
||||
public static EDeliveryType of(Integer value) {
|
||||
for (EDeliveryType e : EDeliveryType.values()) {
|
||||
if (e.getValue().equals(value)) {
|
||||
return e;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package com.ruoyi.xkt.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-04-02 23:42
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum EExpressStatus {
|
||||
|
||||
INIT(1, "初始"),
|
||||
PLACING(2, "下单中"),
|
||||
PLACED(3, "已下单"),
|
||||
CANCELLING(4, "取消中"),
|
||||
PICKED_UP(5, "已揽件"),
|
||||
INTERCEPTING(6, "拦截中"),
|
||||
COMPLETED(99, "已结束");
|
||||
|
||||
private final Integer value;
|
||||
private final String label;
|
||||
|
||||
public static EExpressStatus of(Integer value) {
|
||||
for (EExpressStatus e : EExpressStatus.values()) {
|
||||
if (e.getValue().equals(value)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,10 +14,10 @@ public enum EExpressType {
|
|||
PLATFORM(1, "平台物流"),
|
||||
STORE(2, "档口物流");
|
||||
|
||||
private Integer value;
|
||||
private String label;
|
||||
private final Integer value;
|
||||
private final String label;
|
||||
|
||||
public static EExpressType of(String value) {
|
||||
public static EExpressType of(Integer value) {
|
||||
for (EExpressType e : EExpressType.values()) {
|
||||
if (e.getValue().equals(value)) {
|
||||
return e;
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ public enum EOrderStatus {
|
|||
PLATFORM_INTERVENED(23, "平台介入"),
|
||||
AFTER_SALE_COMPLETED(24, "售后完成");
|
||||
|
||||
private Integer value;
|
||||
private String label;
|
||||
private final Integer value;
|
||||
private final String label;
|
||||
|
||||
public static EOrderStatus of(String value) {
|
||||
public static EOrderStatus of(Integer value) {
|
||||
for (EOrderStatus e : EOrderStatus.values()) {
|
||||
if (e.getValue().equals(value)) {
|
||||
return e;
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ public enum EOrderType {
|
|||
SALES_ORDER(1, "销售订单"),
|
||||
RETURN_ORDER(2, "退货订单");
|
||||
|
||||
private Integer value;
|
||||
private String label;
|
||||
private final Integer value;
|
||||
private final String label;
|
||||
|
||||
public static EOrderType of(String value) {
|
||||
public static EOrderType of(Integer value) {
|
||||
for (EOrderType e : EOrderType.values()) {
|
||||
if (e.getValue().equals(value)) {
|
||||
return e;
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ public enum EPayStatus {
|
|||
PAYING(2, "支付中"),
|
||||
PAID(3, "已支付");
|
||||
|
||||
private Integer value;
|
||||
private String label;
|
||||
private final Integer value;
|
||||
private final String label;
|
||||
|
||||
public static EPayStatus of(String value) {
|
||||
public static EPayStatus of(Integer value) {
|
||||
for (EPayStatus e : EPayStatus.values()) {
|
||||
if (e.getValue().equals(value)) {
|
||||
return e;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.ruoyi.xkt.service;
|
||||
|
||||
import com.ruoyi.xkt.dto.order.StoreOrderAddDTO;
|
||||
import com.ruoyi.xkt.dto.order.StoreOrderDetailInfoDTO;
|
||||
import com.ruoyi.xkt.dto.order.StoreOrderInfoDTO;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
|
|
@ -14,5 +14,5 @@ public interface IStoreOrderService {
|
|||
* @param storeOrderAddDTO
|
||||
* @return
|
||||
*/
|
||||
StoreOrderDetailInfoDTO createOrder(StoreOrderAddDTO storeOrderAddDTO);
|
||||
StoreOrderInfoDTO createOrder(StoreOrderAddDTO storeOrderAddDTO);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
package com.ruoyi.xkt.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.xkt.domain.StoreProduct;
|
||||
import com.ruoyi.xkt.domain.StoreProductColorSize;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.bean.BeanValidators;
|
||||
import com.ruoyi.xkt.domain.*;
|
||||
import com.ruoyi.xkt.dto.order.StoreOrderAddDTO;
|
||||
import com.ruoyi.xkt.dto.order.StoreOrderDetailInfoDTO;
|
||||
import com.ruoyi.xkt.enums.EProductStatus;
|
||||
import com.ruoyi.xkt.enums.EVoucherSequenceType;
|
||||
import com.ruoyi.xkt.dto.order.StoreOrderInfoDTO;
|
||||
import com.ruoyi.xkt.enums.*;
|
||||
import com.ruoyi.xkt.mapper.*;
|
||||
import com.ruoyi.xkt.service.IStoreOrderService;
|
||||
import com.ruoyi.xkt.service.IVoucherSequenceService;
|
||||
|
|
@ -16,10 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -37,6 +40,10 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
|
|||
@Autowired
|
||||
private StoreOrderExpressTrackMapper storeOrderExpressTrackMapper;
|
||||
@Autowired
|
||||
private ExpressMapper expressMapper;
|
||||
@Autowired
|
||||
private ExpressFeeConfigMapper expressFeeConfigMapper;
|
||||
@Autowired
|
||||
private StoreProductMapper storeProductMapper;
|
||||
@Autowired
|
||||
private StoreProductColorSizeMapper storeProductColorSizeMapper;
|
||||
|
|
@ -45,13 +52,192 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
|
|||
|
||||
@Transactional
|
||||
@Override
|
||||
public StoreOrderDetailInfoDTO createOrder(StoreOrderAddDTO storeOrderAddDTO) {
|
||||
checkOrderDetail(storeOrderAddDTO.getStoreId(), storeOrderAddDTO.getDetailList());
|
||||
public StoreOrderInfoDTO createOrder(StoreOrderAddDTO storeOrderAddDTO) {
|
||||
Long orderUserId = storeOrderAddDTO.getOrderUserId();
|
||||
Long storeId = storeOrderAddDTO.getStoreId();
|
||||
Long expressId = storeOrderAddDTO.getExpressId();
|
||||
//校验
|
||||
checkExpress(expressId);
|
||||
checkDelivery(storeOrderAddDTO.getDeliveryType(),
|
||||
storeOrderAddDTO.getDeliveryEndTime());
|
||||
Map<Long, StoreProductColorSize> spcsMap = checkOrderDetailThenRtnSpcsMap(storeId,
|
||||
storeOrderAddDTO.getDetailList());
|
||||
//快递费配置
|
||||
ExpressFeeConfig expressFeeConfig = getExpressFeeConfig(expressId,
|
||||
storeOrderAddDTO.getDestinationProvinceCode(), storeOrderAddDTO.getDestinationCityCode(),
|
||||
storeOrderAddDTO.getDestinationCountyCode());
|
||||
boolean isFirstExpressItem = true;
|
||||
//生成订单明细
|
||||
List<StoreOrderDetail> storeOrderDetailList = new ArrayList<>(storeOrderAddDTO.getDetailList().size());
|
||||
int orderGoodsQuantity = 0;
|
||||
BigDecimal orderGoodsAmount = BigDecimal.ZERO;
|
||||
BigDecimal orderExpressFee = BigDecimal.ZERO;
|
||||
for (StoreOrderAddDTO.Detail detail : storeOrderAddDTO.getDetailList()) {
|
||||
StoreProductColorSize spcs = spcsMap.get(detail.getStoreProdColorSizeId());
|
||||
StoreOrderDetail storeOrderDetail = new StoreOrderDetail();
|
||||
storeOrderDetailList.add(storeOrderDetail);
|
||||
storeOrderDetail.setStoreProdColorSizeId(spcs.getId());
|
||||
storeOrderDetail.setStoreProdId(spcs.getStoreProdId());
|
||||
storeOrderDetail.setDetailStatus(EOrderStatus.PENDING_PAYMENT.getValue());
|
||||
storeOrderDetail.setPayStatus(EPayStatus.INIT.getValue());
|
||||
storeOrderDetail.setExpressStatus(EExpressStatus.INIT.getValue());
|
||||
//计算明细费用
|
||||
BigDecimal goodsPrice = calcPrice(orderUserId, spcs);
|
||||
Integer goodsQuantity = detail.getGoodsQuantity();
|
||||
BigDecimal goodsAmount = NumberUtil.mul(goodsPrice, BigDecimal.valueOf(goodsQuantity));
|
||||
BigDecimal expressFee;
|
||||
if (isFirstExpressItem) {
|
||||
if (goodsQuantity == 1) {
|
||||
expressFee = expressFeeConfig.getFirstItemAmount();
|
||||
} else {
|
||||
BigDecimal nextAmount = NumberUtil.mul(expressFeeConfig.getNextItemAmount(),
|
||||
BigDecimal.valueOf(goodsQuantity - 1));
|
||||
expressFee = NumberUtil.add(expressFeeConfig.getFirstItemAmount(), nextAmount);
|
||||
}
|
||||
isFirstExpressItem = false;
|
||||
} else {
|
||||
expressFee = NumberUtil.mul(expressFeeConfig.getNextItemAmount(), BigDecimal.valueOf(goodsQuantity));
|
||||
}
|
||||
BigDecimal totalAmount = NumberUtil.add(goodsAmount, expressFee);
|
||||
storeOrderDetail.setGoodsPrice(goodsPrice);
|
||||
storeOrderDetail.setGoodsQuantity(goodsQuantity);
|
||||
storeOrderDetail.setGoodsAmount(goodsAmount);
|
||||
storeOrderDetail.setExpressFee(expressFee);
|
||||
storeOrderDetail.setTotalAmount(totalAmount);
|
||||
storeOrderDetail.setDelFlag(Constants.UNDELETED);
|
||||
storeOrderDetail.setVersion(0L);
|
||||
//计算订单费用
|
||||
orderGoodsQuantity = orderGoodsQuantity + goodsQuantity;
|
||||
orderGoodsAmount = NumberUtil.add(orderGoodsAmount, goodsAmount);
|
||||
orderExpressFee = NumberUtil.add(orderExpressFee, expressFee);
|
||||
}
|
||||
//生成订单号
|
||||
String orderNo = voucherSequenceService.generateCode(storeOrderAddDTO.getStoreId(),
|
||||
EVoucherSequenceType.STORE_ORDER.getValue(), DateUtil.today());
|
||||
String orderNo = voucherSequenceService.generateCode(storeId, EVoucherSequenceType.STORE_ORDER.getValue(),
|
||||
DateUtil.today());
|
||||
StoreOrder order = new StoreOrder();
|
||||
order.setStoreId(storeId);
|
||||
order.setOrderUserId(storeOrderAddDTO.getOrderUserId());
|
||||
order.setOrderNo(orderNo);
|
||||
order.setOrderType(EOrderType.SALES_ORDER.getValue());
|
||||
order.setOrderStatus(EOrderStatus.PENDING_PAYMENT.getValue());
|
||||
order.setPayStatus(EPayStatus.INIT.getValue());
|
||||
order.setOrderRemark(storeOrderAddDTO.getOrderRemark());
|
||||
order.setGoodsQuantity(orderGoodsQuantity);
|
||||
order.setGoodsAmount(orderGoodsAmount);
|
||||
order.setExpressFee(orderExpressFee);
|
||||
order.setTotalAmount(NumberUtil.add(orderGoodsAmount, orderExpressFee));
|
||||
order.setExpressId(expressId);
|
||||
//发货人信息
|
||||
//TODO
|
||||
return null;
|
||||
//收货人信息
|
||||
order.setDestinationContactName(storeOrderAddDTO.getDestinationContactName());
|
||||
order.setDestinationContactPhoneNumber(storeOrderAddDTO.getDestinationContactPhoneNumber());
|
||||
order.setDestinationProvinceCode(storeOrderAddDTO.getDestinationProvinceCode());
|
||||
order.setDestinationCityCode(storeOrderAddDTO.getDestinationCityCode());
|
||||
order.setDestinationCountyCode(storeOrderAddDTO.getDestinationCountyCode());
|
||||
order.setDestinationDetailAddress(storeOrderAddDTO.getDestinationDetailAddress());
|
||||
order.setDeliveryType(storeOrderAddDTO.getDeliveryType());
|
||||
order.setDeliveryEndTime(storeOrderAddDTO.getDeliveryEndTime());
|
||||
order.setVoucherDate(DateUtil.date());
|
||||
//自动完成时间
|
||||
//TODO
|
||||
order.setVersion(0L);
|
||||
order.setDelFlag(Constants.UNDELETED);
|
||||
//落库
|
||||
storeOrderMapper.insert(order);
|
||||
Long orderId = order.getId();
|
||||
List<Long> orderDetailIdList = new ArrayList<>(storeOrderDetailList.size());
|
||||
storeOrderDetailList.forEach(storeOrderDetail -> {
|
||||
storeOrderDetail.setStoreOrderId(orderId);
|
||||
storeOrderDetailMapper.insert(storeOrderDetail);
|
||||
orderDetailIdList.add(storeOrderDetail.getId());
|
||||
});
|
||||
//操作记录
|
||||
//TODO
|
||||
//返回
|
||||
StoreOrderInfoDTO infoDTO = BeanUtil.toBean(order, StoreOrderInfoDTO.class);
|
||||
infoDTO.setDetailList(BeanUtil.copyToList(storeOrderDetailList, StoreOrderDetailInfoDTO.class));
|
||||
return infoDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算商品单价
|
||||
*
|
||||
* @param orderUserId
|
||||
* @param storeProductColorSize
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal calcPrice(Long orderUserId, StoreProductColorSize storeProductColorSize) {
|
||||
//TODO
|
||||
return BigDecimal.ONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取快递费配置
|
||||
*
|
||||
* @param expressId
|
||||
* @param provinceCode
|
||||
* @param cityCode
|
||||
* @param countyCode
|
||||
* @return
|
||||
*/
|
||||
private ExpressFeeConfig getExpressFeeConfig(Long expressId, String provinceCode, String cityCode,
|
||||
String countyCode) {
|
||||
Assert.notNull(expressId);
|
||||
Assert.notEmpty(provinceCode);
|
||||
Assert.notEmpty(cityCode);
|
||||
Assert.notEmpty(countyCode);
|
||||
Map<String, ExpressFeeConfig> map = expressFeeConfigMapper.selectList(Wrappers.lambdaQuery(ExpressFeeConfig.class)
|
||||
.eq(ExpressFeeConfig::getExpressId, expressId)
|
||||
.in(ExpressFeeConfig::getRegionCode, Arrays.asList(provinceCode, cityCode, countyCode)))
|
||||
.stream()
|
||||
//过滤掉已被删除的配置
|
||||
.filter(BeanValidators::exists)
|
||||
.collect(Collectors.toMap(o -> o.getRegionCode(), o -> o, (n, o) -> n));
|
||||
ExpressFeeConfig expressFeeConfig = null;
|
||||
if (CollUtil.isNotEmpty(map)) {
|
||||
if (map.size() == 1) {
|
||||
expressFeeConfig = CollUtil.getFirst(map.values());
|
||||
} else {
|
||||
expressFeeConfig = map.get(countyCode);
|
||||
//按区市省从小到大去匹配
|
||||
if (expressFeeConfig == null) {
|
||||
expressFeeConfig = map.get(cityCode);
|
||||
if (expressFeeConfig == null) {
|
||||
expressFeeConfig = map.get(provinceCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.isTrue(BeanValidators.exists(expressFeeConfig), "快递费用配置不存在");
|
||||
return expressFeeConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查发货配置
|
||||
*
|
||||
* @param deliveryType
|
||||
* @param deliveryEndTime
|
||||
*/
|
||||
private void checkDelivery(Integer deliveryType, Date deliveryEndTime) {
|
||||
EDeliveryType deliveryTypeEnum = EDeliveryType.of(deliveryType);
|
||||
Assert.notNull(deliveryTypeEnum, "发货方式异常");
|
||||
if (deliveryEndTime != null
|
||||
&& deliveryTypeEnum != EDeliveryType.PARTIAL_SHIPMENT) {
|
||||
throw new ServiceException("有货先发才能设置最晚发货时间");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查快递
|
||||
*
|
||||
* @param expressId
|
||||
*/
|
||||
private void checkExpress(Long expressId) {
|
||||
Assert.notNull(expressId);
|
||||
Express express = expressMapper.selectById(expressId);
|
||||
Assert.isTrue(BeanValidators.exists(express), "快递不存在");
|
||||
Assert.isTrue(express.getSystemDeliverAccess(), "快递不可用");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,12 +245,14 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
|
|||
*
|
||||
* @param storeId
|
||||
* @param detailList
|
||||
* @return 商品颜色尺码集合
|
||||
*/
|
||||
private void checkOrderDetail(Long storeId, List<StoreOrderAddDTO.OrderDetail> detailList) {
|
||||
private Map<Long, StoreProductColorSize> checkOrderDetailThenRtnSpcsMap(Long storeId,
|
||||
List<StoreOrderAddDTO.Detail> detailList) {
|
||||
Assert.notNull(storeId, "档口不能为空");
|
||||
Assert.notEmpty(detailList, "商品不能为空");
|
||||
Set<Long> spcsIds = detailList.stream()
|
||||
.map(StoreOrderAddDTO.OrderDetail::getStoreProdColorSizeId)
|
||||
.map(StoreOrderAddDTO.Detail::getStoreProdColorSizeId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
//下单商品颜色尺码
|
||||
|
|
@ -76,20 +264,23 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
|
|||
//下单商品
|
||||
Map<Long, StoreProduct> spMap = storeProductMapper.selectByIds(spIdList).stream()
|
||||
.collect(Collectors.toMap(StoreProduct::getId, o -> o));
|
||||
for (StoreOrderAddDTO.OrderDetail detail : detailList) {
|
||||
Set<Long> spcsIdCheckSet = new HashSet<>(detailList.size());
|
||||
for (StoreOrderAddDTO.Detail detail : detailList) {
|
||||
Assert.notNull(detail.getStoreProdColorSizeId(), "商品颜色尺码异常");
|
||||
Integer goodsQuantity = detail.getGoodsQuantity();
|
||||
if (Objects.isNull(goodsQuantity) || goodsQuantity == 0) {
|
||||
if (Objects.isNull(goodsQuantity) || goodsQuantity <= 0) {
|
||||
throw new IllegalArgumentException("商品数量异常");
|
||||
}
|
||||
StoreProductColorSize spcs = spcsMap.get(detail.getStoreProdColorSizeId());
|
||||
Assert.isTrue(Objects.nonNull(spcs) && Constants.UNDELETED.equals(spcs.getDelFlag()),
|
||||
"商品颜色尺码不存在");
|
||||
Assert.isTrue(BeanValidators.exists(spcs), "商品颜色尺码不存在");
|
||||
StoreProduct sp = spMap.get(spcs.getStoreProdId());
|
||||
Assert.isTrue(Objects.nonNull(sp) && Constants.UNDELETED.equals(sp.getDelFlag()),
|
||||
"商品不存在");
|
||||
Assert.isTrue(BeanValidators.exists(sp), "商品不存在");
|
||||
Assert.isTrue(storeId.equals(sp.getStoreId()), "系统不支持跨档口下单");
|
||||
Assert.isTrue(EProductStatus.accessOrder(sp.getProdStatus()), "商品状态异常");
|
||||
//相同商品颜色尺码只能存在一条明细
|
||||
Assert.isFalse(spcsIdCheckSet.contains(spcs.getId()), "商品明细异常");
|
||||
spcsIdCheckSet.add(spcs.getId());
|
||||
}
|
||||
return spcsMap;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue