|
@@ -10,7 +10,7 @@ import com.fjhx.entity.order.OrderDetails;
|
|
|
import com.fjhx.entity.order.OrderInfo;
|
|
|
import com.fjhx.enums.stock.OutTypeEnum;
|
|
|
import com.fjhx.mapper.order.OrderDetailsMapper;
|
|
|
-import com.fjhx.params.order.IssueVo;
|
|
|
+import com.fjhx.params.order.IssueDto;
|
|
|
import com.fjhx.params.order.OrderDetailsEx;
|
|
|
import com.fjhx.params.order.OrderDetailsVo;
|
|
|
import com.fjhx.params.stock.ChangeProduct;
|
|
@@ -25,7 +25,6 @@ import com.fjhx.service.system.SystemConfigService;
|
|
|
import com.fjhx.uitl.kd100.KD100Util;
|
|
|
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;
|
|
@@ -96,91 +95,27 @@ public class OrderDetailsServiceImpl extends ServiceImpl<OrderDetailsMapper, Ord
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public void issue(IssueVo issueVo) {
|
|
|
- Long orderId = issueVo.getOrderId();
|
|
|
+ public void issue(IssueDto issueDto) {
|
|
|
+ Long orderId = issueDto.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);
|
|
|
-
|
|
|
+ // 更新订单明细未出库数量
|
|
|
+ updateNotIssuedQuantity(list, issueDto.getOrderDetailsList());
|
|
|
// 修改订单状态
|
|
|
- OrderInfo orderInfo = orderInfoService.getById(orderId);
|
|
|
-
|
|
|
- // 如果是京东出库
|
|
|
- if (issueVo.getOutTypeEnum().equals(OutTypeEnum.JD)) {
|
|
|
- orderInfo.setStatus(2);
|
|
|
- orderInfo.setIssueStatus(3);
|
|
|
- }
|
|
|
- // 如果是退换货或者补发,出库一次算完成
|
|
|
- else if (orderInfo.getType() == 5) {
|
|
|
- orderInfo.setIssueStatus(3);
|
|
|
- // 补发跟进中变已补发
|
|
|
- if (orderInfo.getAfterSalesStatus() == 1) {
|
|
|
- orderInfo.setAfterSalesStatus(2);
|
|
|
- }
|
|
|
- }
|
|
|
- // 如果是线下退换货
|
|
|
- else if (orderInfo.getType() == 6) {
|
|
|
- orderInfo.setIssueStatus(3);
|
|
|
- switch (orderInfo.getAfterSalesStatus()) {
|
|
|
- // 未补发未收到退货变已补发未收到退货
|
|
|
- case 1:
|
|
|
- orderInfo.setAfterSalesStatus(5);
|
|
|
- break;
|
|
|
- // 未补发已收到退货变已补发已收到退货
|
|
|
- case 2:
|
|
|
- orderInfo.setAfterSalesStatus(3);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- // 如果未出库数量全为0,修改订单完成状态
|
|
|
- else {
|
|
|
- long count = list.stream().filter(item -> item.getNotIssuedQuantity().compareTo(BigDecimal.ZERO) > 0).count();
|
|
|
- orderInfo.setId(orderId);
|
|
|
- if (count == 0) {
|
|
|
- orderInfo.setStatus(2);
|
|
|
- orderInfo.setIssueStatus(3);
|
|
|
- } else {
|
|
|
- orderInfo.setIssueStatus(2);
|
|
|
- }
|
|
|
- }
|
|
|
- orderInfoService.updateById(orderInfo);
|
|
|
+ updateOrderInfoStatus(list, issueDto);
|
|
|
}
|
|
|
|
|
|
// 保存物流消息
|
|
|
LogisticsInfo logisticsInfo = new LogisticsInfo();
|
|
|
logisticsInfo.setBusinessId(orderId);
|
|
|
logisticsInfo.setBusinessType(2);
|
|
|
- logisticsInfo.setCode(issueVo.getLogisticsCode());
|
|
|
- logisticsInfo.setLogisticsCompanyCode(issueVo.getLogisticsCompanyCode());
|
|
|
- logisticsInfo.setWarehouseId(issueVo.getWarehouseId());
|
|
|
- //查询快递100的物流信息
|
|
|
+ logisticsInfo.setCode(issueDto.getLogisticsCode());
|
|
|
+ logisticsInfo.setLogisticsCompanyCode(issueDto.getLogisticsCompanyCode());
|
|
|
+ logisticsInfo.setWarehouseId(issueDto.getWarehouseId());
|
|
|
+ // 查询快递100的物流信息
|
|
|
Integer logisticsStatus = KD100Util.getLogisticsStatus(logisticsInfo.getLogisticsCompanyCode(), logisticsInfo.getCode());
|
|
|
logisticsInfo.setLogisticsStatus(logisticsStatus);
|
|
|
logisticsInfo.setStatus(0);
|
|
@@ -188,17 +123,16 @@ public class OrderDetailsServiceImpl extends ServiceImpl<OrderDetailsMapper, Ord
|
|
|
|
|
|
// 变更库存添加流水记录
|
|
|
StockChangeDto stockChangeDto = new StockChangeDto();
|
|
|
- stockChangeDto.setDefaultBusinessId(orderId);
|
|
|
- stockChangeDto.setDefaultWarehouseId(issueVo.getWarehouseId());
|
|
|
- stockChangeDto.setTypeEnum(issueVo.getOutTypeEnum());
|
|
|
- stockChangeDto.setChangeDetailsList(orderDetailsList);
|
|
|
+ stockChangeDto.setDefaultWarehouseId(issueDto.getWarehouseId());
|
|
|
+ stockChangeDto.setTypeEnum(issueDto.getOutTypeEnum());
|
|
|
+ stockChangeDto.setChangeDetailsList(issueDto.getOrderDetailsList());
|
|
|
stockService.changeQuantity(stockChangeDto);
|
|
|
|
|
|
// 京东出库新增调仓
|
|
|
- if (issueVo.getOutTypeEnum().equals(OutTypeEnum.JD)) {
|
|
|
- // 获取京东仓库id
|
|
|
+ if (issueDto.getOutTypeEnum().equals(OutTypeEnum.JD)) {
|
|
|
|
|
|
- List<ChangeProduct> changeProductList = issueVo.getOrderDetailsList().stream().map(item -> {
|
|
|
+ // 获取京东仓库id
|
|
|
+ List<ChangeProduct> changeProductList = issueDto.getOrderDetailsList().stream().map(item -> {
|
|
|
ChangeProduct changeProduct = new ChangeProduct();
|
|
|
changeProduct.setProductId(item.getProductId());
|
|
|
changeProduct.setQuantity(item.getChangeQuantity());
|
|
@@ -206,7 +140,7 @@ public class OrderDetailsServiceImpl extends ServiceImpl<OrderDetailsMapper, Ord
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
StockTransferAddVo stockTransferAddVo = new StockTransferAddVo();
|
|
|
- stockTransferAddVo.setOutWarehouseId(issueVo.getWarehouseId());
|
|
|
+ stockTransferAddVo.setOutWarehouseId(issueDto.getWarehouseId());
|
|
|
stockTransferAddVo.setInWarehouseId(systemConfigService.getValue(SystemConfigKeyConstant.JD_WAREHOUSE_ID, Long.class));
|
|
|
stockTransferAddVo.setRemark("京东出库");
|
|
|
stockTransferAddVo.setChangeProductList(changeProductList);
|
|
@@ -215,4 +149,71 @@ public class OrderDetailsServiceImpl extends ServiceImpl<OrderDetailsMapper, Ord
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新订单明细未出库数量
|
|
|
+ */
|
|
|
+ private void updateNotIssuedQuantity(List<OrderDetails> list, List<IssueDto.IssueDetails> orderDetailsList) {
|
|
|
+
|
|
|
+ Map<Long, BigDecimal> map = orderDetailsList.stream().collect(Collectors.toMap(IssueDto.IssueDetails::getOrderDetailsId, IssueDto.IssueDetails::getChangeQuantity));
|
|
|
+
|
|
|
+ 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().subtract(changeQuantity);
|
|
|
+ Assert.eqTrue(notIssuedQuantity.compareTo(BigDecimal.ZERO) > 0, "出库数量不能超过待出库数量");
|
|
|
+ // 重新赋值未出库数量
|
|
|
+ orderDetails.setNotIssuedQuantity(notIssuedQuantity);
|
|
|
+ }
|
|
|
+ updateBatchById(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改订单状态
|
|
|
+ */
|
|
|
+ private void updateOrderInfoStatus(List<OrderDetails> list, IssueDto issueDto) {
|
|
|
+ OrderInfo orderInfo = orderInfoService.getById(issueDto.getOrderId());
|
|
|
+
|
|
|
+ // 如果是京东出库,出去一次订单则完成
|
|
|
+ if (issueDto.getOutTypeEnum().equals(OutTypeEnum.JD)) {
|
|
|
+ orderInfo.setStatus(2);
|
|
|
+ orderInfo.setIssueStatus(3);
|
|
|
+ }
|
|
|
+ // 如果是退换货或者补发,出库一次算完成
|
|
|
+ else if (orderInfo.getType() == 5) {
|
|
|
+ orderInfo.setIssueStatus(3);
|
|
|
+ // 补发跟进中变已补发
|
|
|
+ if (orderInfo.getAfterSalesStatus() == 1) {
|
|
|
+ orderInfo.setAfterSalesStatus(2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果是线下退换货
|
|
|
+ else if (orderInfo.getType() == 6) {
|
|
|
+ orderInfo.setIssueStatus(3);
|
|
|
+ switch (orderInfo.getAfterSalesStatus()) {
|
|
|
+ // 未补发未收到退货变已补发未收到退货
|
|
|
+ case 1:
|
|
|
+ orderInfo.setAfterSalesStatus(5);
|
|
|
+ break;
|
|
|
+ // 未补发已收到退货变已补发已收到退货
|
|
|
+ case 2:
|
|
|
+ orderInfo.setAfterSalesStatus(3);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果未出库数量全为0,修改订单完成状态
|
|
|
+ else {
|
|
|
+ long count = list.stream().filter(item -> item.getNotIssuedQuantity().compareTo(BigDecimal.ZERO) > 0).count();
|
|
|
+ if (count == 0) {
|
|
|
+ orderInfo.setStatus(2);
|
|
|
+ orderInfo.setIssueStatus(3);
|
|
|
+ } else {
|
|
|
+ orderInfo.setIssueStatus(2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ orderInfoService.updateById(orderInfo);
|
|
|
+ }
|
|
|
+
|
|
|
}
|