|
@@ -447,13 +447,9 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
|
|
|
//计算已入库数量
|
|
|
BigDecimal inCount = oldstockTransferDetails.getInQuantity().add(stockTransferDetails.getInQuantity());
|
|
|
- if (inCount.compareTo(oldstockTransferDetails.getOutQuantity()) != 0) {
|
|
|
- stockTransfer.setInStatus(1);//设置为部分接收
|
|
|
- }
|
|
|
stockTransferDetails.setInQuantity(inCount);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
if (abnormalFlag == 1) {
|
|
|
AbnormalInfo abnormalInfo = new AbnormalInfo();
|
|
|
abnormalInfo.setStatus(0);
|
|
@@ -466,8 +462,21 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- stockTransferService.updateById(stockTransfer);
|
|
|
stockTransferDetailsService.updateBatchById(stockTransferDetailsList);
|
|
|
+ //修改接收状态
|
|
|
+ Integer inStatus = 0;
|
|
|
+ List<StockTransferDetails> list = stockTransferDetailsService.list(q -> q.eq(StockTransferDetails::getStockTransferId, stockTransfer.getId()));
|
|
|
+ for (StockTransferDetails stockTransferDetails : list) {
|
|
|
+ if (stockTransferDetails.getInQuantity().compareTo(stockTransferDetails.getOutQuantity()) >= 0) {
|
|
|
+ inStatus++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (inStatus != list.size()) {
|
|
|
+ stockTransfer.setInStatus(1);//设置为部分接收
|
|
|
+ }
|
|
|
+ stockTransferService.updateById(stockTransfer);
|
|
|
+
|
|
|
+
|
|
|
//创建入库记录
|
|
|
StockJournal stockJournal = new StockJournal();
|
|
|
stockJournal.setOpType(1);
|
|
@@ -485,4 +494,74 @@ public class JdOrderServiceImpl extends ServiceImpl<JdOrderMapper, JdOrder> impl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
+ public void receiveExcelImport(MultipartFile file) {
|
|
|
+ List<JdOrderExcelImportBo> boList = ExcelUtil.read(file, JdOrderExcelImportBo.class);
|
|
|
+ if (ObjectUtil.isEmpty(boList)) {
|
|
|
+ throw new ServiceException("Excel文档为空!!!");
|
|
|
+ }
|
|
|
+ if (boList.stream().filter(item -> ObjectUtil.isEmpty(item.getCode())).count() > 0) {
|
|
|
+ throw new ServiceException("Excel中存在没有采购单号的数据请检查!!!");
|
|
|
+ }
|
|
|
+ if (boList.stream().filter(item -> ObjectUtil.isEmpty(item.getProductCode())).count() > 0) {
|
|
|
+ throw new ServiceException("Excel中存在没有商品编号的数据请检查!!!");
|
|
|
+ }
|
|
|
+ //检查是单号是否全部存在
|
|
|
+ List<String> codes = boList.stream().map(JdOrderExcelImportBo::getCode).collect(Collectors.toList());
|
|
|
+ List<JdOrder> jdOrderList = this.list(q -> q.in(JdOrder::getCode, codes));
|
|
|
+ if (jdOrderList.size() != codes.size()) {
|
|
|
+ List<String> notCodes = new ArrayList<>();
|
|
|
+ for (String code : codes) {
|
|
|
+ if (!jdOrderList.contains(code)) {
|
|
|
+ notCodes.add(code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String codeList = String.join(",", notCodes);
|
|
|
+ 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::getCustomCode).collect(Collectors.toList());
|
|
|
+ String nonCodeStr = productCodeList.stream().filter(item -> !itemCodeList.contains(item)).collect(Collectors.joining(","));
|
|
|
+ throw new ServiceException("未知产品编号:" + nonCodeStr);
|
|
|
+ }
|
|
|
+ //操作数据
|
|
|
+ Map<String, Long> productInfoMap = productInfoService.mapKV(ProductInfo::getCustomCode, ProductInfo::getId,
|
|
|
+ q -> q.in(ProductInfo::getCustomCode, productCodeList));
|
|
|
+
|
|
|
+ Map<String, Long> stockTransferMap = stockTransferService.mapKV(StockTransfer::getBusinessCode, StockTransfer::getId,
|
|
|
+ q -> q.in(StockTransfer::getBusinessCode, codes));
|
|
|
+
|
|
|
+
|
|
|
+ //根据订单id分组
|
|
|
+ Map<String, List<JdOrderExcelImportBo>> excelMap = boList.stream().collect(Collectors.groupingBy(JdOrderExcelImportBo::getCode));
|
|
|
+ for (Map.Entry<String, List<JdOrderExcelImportBo>> entry : excelMap.entrySet()) {
|
|
|
+ Long stockTransferId = stockTransferMap.get(entry.getKey());
|
|
|
+ if (ObjectUtil.isEmpty(stockTransferId)) {
|
|
|
+ throw new ServiceException("该订单未出库请先出库" + entry.getKey());
|
|
|
+ }
|
|
|
+ List<JdOrderExcelImportBo> value = entry.getValue();
|
|
|
+ List<StockTransferDetails> stockTransferDetailsList = new ArrayList<>();
|
|
|
+ for (JdOrderExcelImportBo jdOrderExcelImportBo : value) {
|
|
|
+ Long productId = productInfoMap.get(jdOrderExcelImportBo.getProductCode());
|
|
|
+ StockTransferDetails stockTransferDetails = new StockTransferDetails();
|
|
|
+ StockTransferDetails old = stockTransferDetailsService.getOne(q -> q.eq(StockTransferDetails::getStockTransferId, stockTransferId).eq(StockTransferDetails::getProductId, productId));
|
|
|
+ stockTransferDetails.setId(old.getId());
|
|
|
+ stockTransferDetails.setInQuantity(jdOrderExcelImportBo.getReceivedQuantity());
|
|
|
+ stockTransferDetails.setProductId(productId);
|
|
|
+ stockTransferDetailsList.add(stockTransferDetails);
|
|
|
+ }
|
|
|
+
|
|
|
+ //丢给接收接口处理
|
|
|
+ StockTransferDto stockTransferDto = new StockTransferDto();
|
|
|
+ stockTransferDto.setId(stockTransferId);
|
|
|
+ stockTransferDto.setStockTransferDetailsList(stockTransferDetailsList);
|
|
|
+ receive(stockTransferDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|