| | |
| | | if (CollectionUtils.isEmpty(rowList)) { |
| | | continue; |
| | | } |
| | | if (StringUtils.hasText(rowList.get(0).getCustomerName()) && rowList.get(0).getCustomerName().startsWith("补片")) { |
| | | continue; |
| | | } |
| | | SalesLedger ledger = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>().eq(SalesLedger::getSalesContractNo, orderNo).last("LIMIT 1")); |
| | | if (ledger == null) { |
| | | // throw new ServiceException("导入失败,订单编号[" + orderNo + "]不存在,无法补录已发货数据"); |
| | |
| | | ledger.setStockStatus(allInbound ? 2 : (anyInbound ? 1 : 0)); |
| | | ledger.setDeliveryStatus(allShipped ? 5 : 1); |
| | | // ledger.setReviewStatus(1); |
| | | ledger.setOrderStatus(1); |
| | | salesLedgerMapper.updateById(ledger); |
| | | } |
| | | } |
| | |
| | | |
| | | salesLedgerProductServiceImpl.addProductionData(product); |
| | | contractAmount = contractAmount.add(lineAmount); |
| | | |
| | | if (customer.getCustomerName() != null && customer.getCustomerName().startsWith("补片")) { |
| | | stockUtils.addStock( |
| | | ledger.getId(), |
| | | product.getId(), |
| | | product.getProductModelId(), |
| | | qty, |
| | | StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode(), |
| | | product.getId() |
| | | ); |
| | | stockUtils.substractStock( |
| | | ledger.getId(), |
| | | product.getId(), |
| | | product.getProductModelId(), |
| | | qty, |
| | | StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), |
| | | product.getId() |
| | | ); |
| | | |
| | | StockInRecord inRecord = stockInRecordMapper.selectOne(new LambdaQueryWrapper<StockInRecord>() |
| | | .eq(StockInRecord::getSalesLedgerProductId, product.getId()) |
| | | .orderByDesc(StockInRecord::getId).last("LIMIT 1")); |
| | | if (inRecord != null) { |
| | | String batch = "RK"; |
| | | if (row.getReportDate() != null) { |
| | | String dateStr = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(row.getReportDate()); |
| | | batch += dateStr + "-" + row.getReportDate().getTime(); |
| | | } else { |
| | | batch += System.currentTimeMillis() + "-" + inRecord.getId(); |
| | | } |
| | | inRecord.setInboundBatches(batch); |
| | | if (row.getReportDate() != null) { |
| | | LocalDateTime reportDateTime = LocalDateTime.ofInstant(row.getReportDate().toInstant(), ZoneId.systemDefault()); |
| | | inRecord.setCreateTime(reportDateTime); |
| | | inRecord.setUpdateTime(reportDateTime); |
| | | } |
| | | stockInRecordMapper.updateById(inRecord); |
| | | } |
| | | |
| | | StockOutRecord outRecord = stockOutRecordMapper.selectOne(new LambdaQueryWrapper<StockOutRecord>() |
| | | .eq(StockOutRecord::getSalesLedgerProductId, product.getId()) |
| | | .orderByDesc(StockOutRecord::getId).last("LIMIT 1")); |
| | | if (outRecord != null) { |
| | | String batch = "CK"; |
| | | if (row.getReportDate() != null) { |
| | | String dateStr = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(row.getReportDate()); |
| | | batch += dateStr + "-" + row.getReportDate().getTime(); |
| | | } else { |
| | | batch += System.currentTimeMillis() + "-" + outRecord.getId(); |
| | | } |
| | | outRecord.setOutboundBatches(batch); |
| | | if (row.getReportDate() != null) { |
| | | LocalDateTime reportDateTime = LocalDateTime.ofInstant(row.getReportDate().toInstant(), ZoneId.systemDefault()); |
| | | outRecord.setCreateTime(reportDateTime); |
| | | outRecord.setUpdateTime(reportDateTime); |
| | | } |
| | | stockOutRecordMapper.updateById(outRecord); |
| | | } |
| | | |
| | | product.setStockedQuantity(qty); |
| | | product.setShippedQuantity(qty); |
| | | product.setApproveStatus(3); |
| | | updateProductStockStatus(product); |
| | | product.fillRemainingQuantity(); |
| | | updateProductShipStatus(product); |
| | | salesLedgerProductMapper.updateById(product); |
| | | |
| | | ShippingInfo shippingInfo = new ShippingInfo(); |
| | | shippingInfo.setSalesLedgerId(ledger.getId()); |
| | | shippingInfo.setSalesLedgerProductId(product.getId()); |
| | | shippingInfo.setStatus("已发货"); |
| | | if (row.getReportDate() != null) { |
| | | String dateStr = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(row.getReportDate()); |
| | | shippingInfo.setShippingNo("CK" + dateStr + "-" + row.getReportDate().getTime()); |
| | | } else { |
| | | shippingInfo.setShippingNo("CK" + System.currentTimeMillis()); |
| | | } |
| | | shippingInfo.setType("货车"); |
| | | shippingInfo.setShippingCarNumber("无"); |
| | | shippingInfo.setShippingDate(row.getReportDate()); |
| | | shippingInfoMapper.insert(shippingInfo); |
| | | } |
| | | } |
| | | |
| | | ledger.setContractAmount(contractAmount); |
| | |
| | | ledger.setReviewStatus(1); |
| | | } |
| | | |
| | | if (customer.getCustomerName() != null && customer.getCustomerName().startsWith("补片")) { |
| | | List<SalesLedgerProduct> latestProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>().eq(SalesLedgerProduct::getSalesLedgerId, ledger.getId()).eq(SalesLedgerProduct::getType, SaleEnum.SALE.getCode())); |
| | | boolean allShipped = CollectionUtils.isNotEmpty(latestProducts) && latestProducts.stream().allMatch(p -> { |
| | | BigDecimal pQty = defaultDecimal(p.getQuantity()); |
| | | BigDecimal shipped = defaultDecimal(p.getShippedQuantity()); |
| | | return shipped.compareTo(pQty) >= 0; |
| | | }); |
| | | boolean anyInbound = CollectionUtils.isNotEmpty(latestProducts) && latestProducts.stream().anyMatch(p -> defaultDecimal(p.getStockedQuantity()).compareTo(BigDecimal.ZERO) > 0); |
| | | boolean allInbound = CollectionUtils.isNotEmpty(latestProducts) && latestProducts.stream().allMatch(p -> { |
| | | BigDecimal pQty = defaultDecimal(p.getQuantity()); |
| | | BigDecimal stocked = defaultDecimal(p.getStockedQuantity()); |
| | | return pQty.compareTo(BigDecimal.ZERO) <= 0 || stocked.compareTo(pQty) >= 0; |
| | | }); |
| | | if (allShipped && rowList.get(0).getReportDate() != null) { |
| | | ledger.setDeliveryDate(DateUtils.toLocalDate(rowList.get(0).getReportDate())); |
| | | } |
| | | ledger.setStockStatus(allInbound ? 2 : (anyInbound ? 1 : 0)); |
| | | ledger.setDeliveryStatus(allShipped ? 5 : 1); |
| | | ledger.setOrderStatus(1); |
| | | } |
| | | |
| | | salesLedgerMapper.updateById(ledger); |
| | | } |
| | | } |