|
@@ -2,18 +2,30 @@ package com.fjhx.service.order.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.entity.logistics.LogisticsInfo;
|
|
|
import com.fjhx.entity.order.OrderDetails;
|
|
|
+import com.fjhx.entity.order.OrderInfo;
|
|
|
import com.fjhx.mapper.order.OrderDetailsMapper;
|
|
|
import com.fjhx.params.order.IssueVo;
|
|
|
import com.fjhx.params.order.OrderDetailsEx;
|
|
|
import com.fjhx.params.order.OrderDetailsVo;
|
|
|
+import com.fjhx.params.stock.StockChangeVo;
|
|
|
+import com.fjhx.service.logistics.LogisticsInfoService;
|
|
|
import com.fjhx.service.order.OrderDetailsService;
|
|
|
+import com.fjhx.service.order.OrderInfoService;
|
|
|
+import com.fjhx.service.stock.StockService;
|
|
|
import com.fjhx.utils.Assert;
|
|
|
import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -26,6 +38,16 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class OrderDetailsServiceImpl extends ServiceImpl<OrderDetailsMapper, OrderDetails> implements OrderDetailsService {
|
|
|
|
|
|
+ @Lazy
|
|
|
+ @Autowired
|
|
|
+ private OrderInfoService orderInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LogisticsInfoService logisticsInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StockService stockService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<OrderDetails> getPage(Map<String, Object> condition) {
|
|
|
|
|
@@ -59,9 +81,74 @@ public class OrderDetailsServiceImpl extends ServiceImpl<OrderDetailsMapper, Ord
|
|
|
return baseMapper.listByOrderSalesId(wrapper);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void issue(IssueVo issueVo) {
|
|
|
+ Long orderId = issueVo.getOrderId();
|
|
|
+ Assert.notEmpty(orderId, "订单id不能为空");
|
|
|
+
|
|
|
+ List<IssueVo.IssueDetails> orderDetailsList = issueVo.getOrderDetailsList();
|
|
|
+
|
|
|
+ Map<Long, BigDecimal> map = orderDetailsList.stream().collect(Collectors.toMap(
|
|
|
+ IssueVo.IssueDetails::getOrderDetailsId,
|
|
|
+ IssueVo.IssueDetails::getChangeQuantity
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 变更订单明细未出库数量
|
|
|
+ synchronized (this) {
|
|
|
+ List<OrderDetails> list = list(q -> q.eq(OrderDetails::getOrderId, orderId));
|
|
|
+
|
|
|
+ for (OrderDetails orderDetails : list) {
|
|
|
+ Long id = orderDetails.getId();
|
|
|
+ BigDecimal changeQuantity = map.get(id);
|
|
|
+ if (changeQuantity == null || changeQuantity.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal notIssuedQuantity = orderDetails.getNotIssuedQuantity();
|
|
|
+
|
|
|
+ if (notIssuedQuantity.compareTo(changeQuantity) < 0) {
|
|
|
+ throw new ServiceException("出库数量超过待出库数量,操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重新赋值未出库数量
|
|
|
+ orderDetails.setNotIssuedQuantity(notIssuedQuantity.subtract(changeQuantity));
|
|
|
+ }
|
|
|
+ updateBatchById(list);
|
|
|
+
|
|
|
+ // 如果未出库数量全为0,修改订单完成状态
|
|
|
+ long count = list.stream().filter(item -> item.getNotIssuedQuantity().compareTo(BigDecimal.ZERO) > 0).count();
|
|
|
+ OrderInfo orderInfo = new OrderInfo();
|
|
|
+ orderInfo.setId(orderId);
|
|
|
+ if (count == 0) {
|
|
|
+ orderInfo.setStatus(2);
|
|
|
+ orderInfo.setIssueStatus(3);
|
|
|
+ } else {
|
|
|
+ orderInfo.setIssueStatus(2);
|
|
|
+ }
|
|
|
+ orderInfoService.updateById(orderInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存物流消息
|
|
|
+ LogisticsInfo logisticsInfo = new LogisticsInfo();
|
|
|
+ logisticsInfo.setBusinessId(orderId);
|
|
|
+ logisticsInfo.setBusinessType(2);
|
|
|
+ logisticsInfo.setCode(issueVo.getLogisticsCode());
|
|
|
+ logisticsInfo.setLogisticsCompanyCode(issueVo.getLogisticsCompanyCode());
|
|
|
+ logisticsInfo.setWarehouseId(issueVo.getWarehouseId());
|
|
|
+ // TODO 添加快递100的状态
|
|
|
+ // logisticsInfo.setLogisticsStatus();
|
|
|
+ logisticsInfo.setStatus(0);
|
|
|
+ logisticsInfoService.save(logisticsInfo);
|
|
|
+
|
|
|
+ // 变更库存添加流水记录
|
|
|
+ StockChangeVo stockChangeVo = new StockChangeVo();
|
|
|
+ stockChangeVo.setDefaultBusinessId(orderId);
|
|
|
+ stockChangeVo.setDefaultWarehouseId(issueVo.getWarehouseId());
|
|
|
+ stockChangeVo.setTypeEnum(issueVo.getOutTypeEnum());
|
|
|
+ stockChangeVo.setChangeDetailsList(orderDetailsList);
|
|
|
|
|
|
+ stockService.changeQuantity(stockChangeVo);
|
|
|
}
|
|
|
|
|
|
}
|