|
@@ -130,6 +130,7 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
productInfoService.attributeAssign(jdOrderDetailsVoList, JdOrderDetails::getProductId, (item, product) -> {
|
|
|
item.setProductCode(product.getCode());
|
|
|
item.setProductName(product.getName());
|
|
|
+ item.setProductCustomCode(product.getCustomCode());
|
|
|
});
|
|
|
|
|
|
result.setJdOrderDetailsList(jdOrderDetailsVoList);
|
|
@@ -187,7 +188,6 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
CustomizeAreaUtil.setAreaId(jdOrderDto);
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@DSTransactional
|
|
@@ -195,25 +195,38 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
public void excelImport(MultipartFile file, Long customerId) {
|
|
|
List<JdOrderExcelImportBo> boList = ExcelUtil.read(file, JdOrderExcelImportBo.class);
|
|
|
|
|
|
+ //检查采购单号是否已经在系统中存在,如果存在报错
|
|
|
+ List<String> codes = boList.stream().map(JdOrderExcelImportBo::getCode).distinct().collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isEmpty(codes)) {
|
|
|
+ throw new ServiceException("采购单号不能为空");
|
|
|
+ }
|
|
|
+ List<JdOrder> jdOrderList = this.list(q -> q.in(JdOrder::getCode, codes));
|
|
|
+ if (ObjectUtil.isNotEmpty(jdOrderList)) {
|
|
|
+ String codeList = jdOrderList.stream().map(JdOrder::getCode).collect(Collectors.joining(","));
|
|
|
+ throw new ServiceException("以下订单已经在系统中存在->" + codeList);
|
|
|
+ }
|
|
|
+
|
|
|
List<String> productCodeList = boList.stream().map(JdOrderExcelImportBo::getProductCode)
|
|
|
.filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
|
|
|
// 验证产品编号是否存在
|
|
|
List<ProductInfo> productInfoList = productInfoService.list(q -> q.in(ProductInfo::getCustomCode, productCodeList));
|
|
|
if (productInfoList.size() != productCodeList.size()) {
|
|
|
- List<String> itemCodeList = productInfoList.stream().map(ProductInfo::getCode).collect(Collectors.toList());
|
|
|
+ List<String> itemCodeList = productInfoList.stream().map(ProductInfo::getCustomCode).collect(Collectors.toList());
|
|
|
String nonCodeStr = productCodeList.stream().filter(item -> !itemCodeList.contains(item)).collect(Collectors.joining(","));
|
|
|
throw new ServiceException("未知产品编号:" + nonCodeStr);
|
|
|
}
|
|
|
|
|
|
// 产品编号、产品id map
|
|
|
- Map<String, Long> productCodeIdMap = productInfoList.stream().collect(Collectors.toMap(ProductInfo::getCode, BaseIdPo::getId));
|
|
|
+ Map<String, Long> productCodeIdMap = productInfoList.stream().collect(Collectors.toMap(ProductInfo::getCustomCode, BaseIdPo::getId));
|
|
|
|
|
|
// 订单编号、订单信息 map
|
|
|
HashMap<String, JdOrder> orderCodeIdMap = new LinkedHashMap<>();
|
|
|
List<JdOrderDetails> orderDetailsList = new ArrayList<>();
|
|
|
|
|
|
- List<StockWait> stockWaitList = new ArrayList<>();
|
|
|
+// List<StockWait> stockWaitList = new ArrayList<>();
|
|
|
+ //订单编号、待出库记录 map
|
|
|
+ Map<String, StockWait> stockWaitMap = new HashMap<>();
|
|
|
List<StockWaitDetails> stockWaitDetailsList = new ArrayList<>();
|
|
|
|
|
|
long batchFlag = IdWorker.getId();
|
|
@@ -243,7 +256,8 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
stockWait.setBusinessId(item.getId());
|
|
|
stockWait.setBusinessCode(item.getCode());
|
|
|
stockWait.setStatus(0);
|
|
|
- stockWaitList.add(stockWait);
|
|
|
+// stockWaitList.add(stockWait);
|
|
|
+ stockWaitMap.put(bo.getCode(), stockWait);
|
|
|
|
|
|
return item;
|
|
|
});
|
|
@@ -254,7 +268,11 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
JdOrderDetails jdOrderDetails = new JdOrderDetails();
|
|
|
jdOrderDetails.setId(IdWorker.getId());
|
|
|
jdOrderDetails.setJdOrderId(jdOrder.getId());
|
|
|
- jdOrderDetails.setProductId(productCodeIdMap.get(bo.getProductCode()));
|
|
|
+ Long productId = productCodeIdMap.get(bo.getProductCode());
|
|
|
+ if (ObjectUtil.isEmpty(productId)) {
|
|
|
+ throw new ServiceException("未知产品->" + bo.getProductCode());
|
|
|
+ }
|
|
|
+ jdOrderDetails.setProductId(productId);
|
|
|
jdOrderDetails.setPrice(bo.getPrice());
|
|
|
jdOrderDetails.setQuantity(bo.getQuantity());
|
|
|
jdOrderDetails.setSubtotal(subtotal);
|
|
@@ -263,18 +281,24 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
|
|
|
//创建待出库明细
|
|
|
StockWaitDetails stockWaitDetails = new StockWaitDetails();
|
|
|
- stockWaitDetails.setStockWaitId(jdOrderDetails.getId());
|
|
|
+ //获取待出库id并赋值给明细
|
|
|
+ StockWait stockWait = stockWaitMap.get(bo.getCode());
|
|
|
+ if (ObjectUtil.isEmpty(stockWait)) {
|
|
|
+ throw new ServiceException("待出库id为空");
|
|
|
+ }
|
|
|
+ stockWaitDetails.setStockWaitId(stockWait.getId());
|
|
|
stockWaitDetails.setProductId(jdOrderDetails.getProductId());
|
|
|
stockWaitDetails.setQuantity(jdOrderDetails.getQuantity());
|
|
|
stockWaitDetails.setBusinessDetailsId(jdOrderDetails.getId());
|
|
|
stockWaitDetailsList.add(stockWaitDetails);
|
|
|
}
|
|
|
|
|
|
+ //保存京东订单信息
|
|
|
this.saveBatch(orderCodeIdMap.values());
|
|
|
this.jdOrderDetailsService.saveBatch(orderDetailsList);
|
|
|
|
|
|
//保存待出库明细
|
|
|
- stockWaitService.saveBatch(stockWaitList);
|
|
|
+ stockWaitService.saveBatch(stockWaitMap.values());
|
|
|
stockWaitDetailsService.saveBatch(stockWaitDetailsList);
|
|
|
}
|
|
|
|
|
@@ -350,7 +374,7 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
|
|
|
List<LogisticsDetails> logisticsDetailsList = new ArrayList<>();
|
|
|
for (JdOrderDetails jdOrderDetails : jdOrderDetailsList) {
|
|
|
- LogisticsDetails logisticsDetails =new LogisticsDetails();
|
|
|
+ LogisticsDetails logisticsDetails = new LogisticsDetails();
|
|
|
logisticsDetails.setLogisticsInfoId(logisticsInfos.getId());
|
|
|
logisticsDetails.setLogisticsInfoCode(logisticsInfos.getCode());
|
|
|
logisticsDetails.setBusinessDetailsId(jdOrderDetails.getId());
|