| | |
| | | import com.ruoyi.purchase.dto.SimpleReturnOrderGroupDto; |
| | | import com.ruoyi.purchase.mapper.PurchaseReturnOrderProductsMapper; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | | import com.ruoyi.quality.mapper.QualityInspectParamMapper; |
| | | import com.ruoyi.quality.mapper.QualityTestStandardMapper; |
| | | import com.ruoyi.quality.mapper.QualityTestStandardParamMapper; |
| | | import com.ruoyi.quality.pojo.QualityInspect; |
| | | import com.ruoyi.quality.pojo.QualityInspectParam; |
| | | import com.ruoyi.quality.pojo.QualityTestStandard; |
| | | import com.ruoyi.quality.pojo.QualityTestStandardParam; |
| | | import com.ruoyi.sales.dto.*; |
| | | import com.ruoyi.sales.mapper.*; |
| | | import com.ruoyi.sales.pojo.*; |
| | |
| | | private final ProductionProductOutputMapper productionProductOutputMapper; |
| | | private final ProductionProductInputMapper productionProductInputMapper; |
| | | private final QualityInspectMapper qualityInspectMapper; |
| | | private final QualityInspectParamMapper qualityInspectParamMapper; |
| | | private final QualityTestStandardMapper qualityTestStandardMapper; |
| | | private final QualityTestStandardParamMapper qualityTestStandardParamMapper; |
| | | private final RedisTemplate<String, String> redisTemplate; |
| | | |
| | | private final ISalesLedgerProductProcessService salesLedgerProductProcessService; |
| | |
| | | if (selectedProduct.getProductModelId() == null) { |
| | | throw new ServiceException("入库失败,产品规格未维护,无法入库"); |
| | | } |
| | | BigDecimal orderQty = selectedProduct.getQuantity() == null ? BigDecimal.ZERO : selectedProduct.getQuantity(); |
| | | BigDecimal qualifiedStocked = selectedProduct.getStockedQuantity() == null ? BigDecimal.ZERO : selectedProduct.getStockedQuantity(); |
| | | BigDecimal inboundQty = inboundQtyByLineId.getOrDefault(selectedProduct.getId(), BigDecimal.ZERO); |
| | | if (inboundQty.compareTo(BigDecimal.ZERO) > 0 && qualifiedStocked.add(inboundQty).compareTo(orderQty) > 0) { |
| | | throw new ServiceException("入库失败,合格入库数量之和不能大于订单数量"); |
| | | } |
| | | } |
| | | String approveUserIds = resolveApproveUserIds(dto.getApproveUserIds(), salesLedger.getId(), INBOUND_BIZ_TYPE_SCAN_QUALIFIED); |
| | | if (StringUtils.isEmpty(approveUserIds)) { |
| | |
| | | } |
| | | BigDecimal oldStocked = dbProduct.getStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getStockedQuantity(); |
| | | BigDecimal newStocked = oldStocked.add(inboundThisLine); |
| | | BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity(); |
| | | if (newStocked.compareTo(orderQty) > 0) { |
| | | throw new ServiceException("入库失败,合格入库数量之和不能大于订单数量"); |
| | | } |
| | | |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setRecordId(dbProduct.getId()); |
| | |
| | | stockInventoryDto.setSalesLedgerProductId(dbProduct.getId()); |
| | | stockInventoryService.addstockInventory(stockInventoryDto); |
| | | |
| | | BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity(); |
| | | int lineStockStatus; |
| | | if (newStocked.compareTo(BigDecimal.ZERO) <= 0) { |
| | | lineStockStatus = 0; |
| | |
| | | if (selectedProduct.getProductModelId() == null) { |
| | | throw new ServiceException("不合格入库失败,产品规格未维护,无法入库"); |
| | | } |
| | | BigDecimal orderQty = selectedProduct.getQuantity() == null ? BigDecimal.ZERO : selectedProduct.getQuantity(); |
| | | BigDecimal qualifiedStocked = selectedProduct.getStockedQuantity() == null ? BigDecimal.ZERO : selectedProduct.getStockedQuantity(); |
| | | BigDecimal unqualifiedStocked = selectedProduct.getUnqualifiedStockedQuantity() == null ? BigDecimal.ZERO : selectedProduct.getUnqualifiedStockedQuantity(); |
| | | BigDecimal inboundQty = inboundQtyByLineId.getOrDefault(selectedProduct.getId(), BigDecimal.ZERO); |
| | | BigDecimal remainForUnqualified = orderQty.subtract(qualifiedStocked); |
| | | if (remainForUnqualified.compareTo(BigDecimal.ZERO) <= 0 && inboundQty.compareTo(BigDecimal.ZERO) > 0) { |
| | | throw new ServiceException("不合格入库失败,该产品已无可入不合格库数量"); |
| | | } |
| | | if (inboundQty.compareTo(BigDecimal.ZERO) > 0 && unqualifiedStocked.add(inboundQty).compareTo(orderQty) > 0) { |
| | | throw new ServiceException("不合格入库失败,不合格入库数量之和不能大于订单数量"); |
| | | } |
| | | if (inboundQty.compareTo(BigDecimal.ZERO) > 0 && unqualifiedStocked.add(inboundQty).compareTo(remainForUnqualified) > 0) { |
| | | throw new ServiceException("不合格入库失败,不合格入库数量不能大于订单数量减去合格入库数量"); |
| | | } |
| | | } |
| | | String approveUserIds = resolveApproveUserIds(dto.getApproveUserIds(), salesLedger.getId(), INBOUND_BIZ_TYPE_SCAN_UNQUALIFIED); |
| | | if (StringUtils.isEmpty(approveUserIds)) { |
| | |
| | | if (dbProduct.getProductModelId() == null) { |
| | | throw new ServiceException("不合格入库失败,产品规格未维护,无法入库"); |
| | | } |
| | | stockUtils.addUnStock(ledgerId, dbProduct.getId(), dbProduct.getProductModelId(), inboundThisLine, StockInUnQualifiedRecordTypeEnum.SALES_SCAN_UNSTOCK_IN.getCode(), dbProduct.getId()); |
| | | BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity(); |
| | | BigDecimal qualifiedStocked = dbProduct.getStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getStockedQuantity(); |
| | | BigDecimal oldUnStocked = dbProduct.getUnqualifiedStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getUnqualifiedStockedQuantity(); |
| | | dbProduct.setUnqualifiedStockedQuantity(oldUnStocked.add(inboundThisLine)); |
| | | BigDecimal newUnStocked = oldUnStocked.add(inboundThisLine); |
| | | BigDecimal remainForUnqualified = orderQty.subtract(qualifiedStocked); |
| | | if (remainForUnqualified.compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new ServiceException("不合格入库失败,该产品已无可入不合格库数量"); |
| | | } |
| | | if (newUnStocked.compareTo(orderQty) > 0) { |
| | | throw new ServiceException("不合格入库失败,不合格入库数量之和不能大于订单数量"); |
| | | } |
| | | if (newUnStocked.compareTo(remainForUnqualified) > 0) { |
| | | throw new ServiceException("不合格入库失败,不合格入库数量不能大于订单数量减去合格入库数量"); |
| | | } |
| | | stockUtils.addUnStock(ledgerId, dbProduct.getId(), dbProduct.getProductModelId(), inboundThisLine, StockInUnQualifiedRecordTypeEnum.SALES_SCAN_UNSTOCK_IN.getCode(), dbProduct.getId()); |
| | | dbProduct.setUnqualifiedStockedQuantity(newUnStocked); |
| | | dbProduct.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.updateById(dbProduct); |
| | | } |
| | |
| | | if (dbProduct.getProductModelId() == null) { |
| | | throw new ServiceException("导入失败,订单编号[" + orderNo + "]产品规格未维护,无法补录出库"); |
| | | } |
| | | // 历史已发货补录:直接写入入库+出库记录 |
| | | stockUtils.addStock( |
| | | ledger.getId(), |
| | | dbProduct.getId(), |
| | | dbProduct.getProductModelId(), |
| | | allocQty, |
| | | StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode(), |
| | | dbProduct.getId() |
| | | ); |
| | | stockUtils.substractStock( |
| | | ledger.getId(), |
| | | dbProduct.getId(), |
| | | dbProduct.getProductModelId(), |
| | | allocQty, |
| | | StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), |
| | | dbProduct.getId() |
| | | ); |
| | | BigDecimal oldShipped = defaultDecimal(dbProduct.getShippedQuantity()); |
| | | BigDecimal newShipped = oldShipped.add(allocQty); |
| | | dbProduct.setStockedQuantity(defaultDecimal(dbProduct.getQuantity())); |
| | | dbProduct.setShippedQuantity(newShipped); |
| | | dbProduct.setApproveStatus(3); |
| | | updateProductStockStatus(dbProduct); |
| | | dbProduct.fillRemainingQuantity(); |
| | | updateProductShipStatus(dbProduct); |
| | |
| | | throw new ServiceException("导入失败,订单编号[" + orderNo + "]存在重复发货记录,请勿重复导入"); |
| | | } |
| | | shippingInfoMapper.insert(shippingInfo); |
| | | createShippingQualityInspect(ledger, dbProduct, row, allocQty); |
| | | } |
| | | } |
| | | |
| | |
| | | BigDecimal shipped = defaultDecimal(p.getShippedQuantity()); |
| | | return shipped.compareTo(qty) >= 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 qty = defaultDecimal(p.getQuantity()); |
| | | BigDecimal stocked = defaultDecimal(p.getStockedQuantity()); |
| | | return qty.compareTo(BigDecimal.ZERO) <= 0 || stocked.compareTo(qty) >= 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); |
| | | salesLedgerMapper.updateById(ledger); |
| | | } |
| | |
| | | String subCategory = StringUtils.hasText(row.getProductSubCategory()) ? row.getProductSubCategory().trim() : ""; |
| | | return ledgerId + "|" + subCategory + "|" + shippingNo + "|" + dateStr + "|" + defaultDecimal(row.getQuantity()); |
| | | } |
| | | |
| | | private void createShippingQualityInspect(SalesLedger ledger, SalesLedgerProduct dbProduct, SalesShippingImportDto row, BigDecimal inspectQty) { |
| | | if (ledger == null || dbProduct == null || inspectQty == null || inspectQty.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return; |
| | | } |
| | | Date checkDate = row.getReportDate() != null ? row.getReportDate() : new Date(); |
| | | QualityInspect qualityInspect = new QualityInspect(); |
| | | qualityInspect.setInspectType(2); |
| | | qualityInspect.setCheckTime(checkDate); |
| | | qualityInspect.setCustomer(StringUtils.hasText(ledger.getCustomerName()) ? ledger.getCustomerName() : row.getCustomerName()); |
| | | qualityInspect.setCheckName(StringUtils.hasText(row.getCreator()) ? row.getCreator().trim() : null); |
| | | qualityInspect.setProductId(dbProduct.getProductId()); |
| | | qualityInspect.setProductName(dbProduct.getProductCategory()); |
| | | qualityInspect.setModel(dbProduct.getSpecificationModel()); |
| | | qualityInspect.setUnit(resolveInspectUnit(dbProduct)); |
| | | qualityInspect.setQuantity(inspectQty); |
| | | qualityInspect.setCheckResult("合格"); |
| | | qualityInspect.setInspectState(1); |
| | | qualityInspect.setApprovalStatus(1); |
| | | qualityInspect.setProductModelId(dbProduct.getProductModelId()); |
| | | |
| | | QualityTestStandard selectedStandard = null; |
| | | if (dbProduct.getProductId() != null) { |
| | | List<QualityTestStandard> standards = qualityTestStandardMapper.getQualityTestStandardByProductId(dbProduct.getProductId(), 2, null); |
| | | if (CollectionUtils.isNotEmpty(standards)) { |
| | | selectedStandard = standards.get(0); |
| | | qualityInspect.setTestStandardId(selectedStandard.getId()); |
| | | } |
| | | } |
| | | qualityInspectMapper.insert(qualityInspect); |
| | | |
| | | if (selectedStandard == null || selectedStandard.getId() == null) { |
| | | return; |
| | | } |
| | | List<QualityTestStandardParam> standardParams = qualityTestStandardParamMapper.selectList(Wrappers.<QualityTestStandardParam>lambdaQuery().eq(QualityTestStandardParam::getTestStandardId, selectedStandard.getId())); |
| | | if (CollectionUtils.isEmpty(standardParams)) { |
| | | return; |
| | | } |
| | | List<QualityInspectParam> inspectParams = standardParams.stream().map(item -> { |
| | | QualityInspectParam param = new QualityInspectParam(); |
| | | param.setInspectId(qualityInspect.getId()); |
| | | param.setParameterItem(item.getParameterItem()); |
| | | param.setUnit(item.getUnit()); |
| | | param.setStandardValue(item.getStandardValue()); |
| | | param.setControlValue(item.getControlValue()); |
| | | param.setTestValue("无瑕疵"); |
| | | return param; |
| | | }).collect(Collectors.toList()); |
| | | inspectParams.forEach(qualityInspectParamMapper::insert); |
| | | } |
| | | |
| | | private String resolveInspectUnit(SalesLedgerProduct dbProduct) { |
| | | if (dbProduct == null) { |
| | | return null; |
| | | } |
| | | if (StringUtils.hasText(dbProduct.getUnit())) { |
| | | return dbProduct.getUnit(); |
| | | } |
| | | if (dbProduct.getProductModelId() == null) { |
| | | return null; |
| | | } |
| | | ProductModel productModel = productModelMapper.selectById(dbProduct.getProductModelId()); |
| | | if (productModel == null || !StringUtils.hasText(productModel.getUnit())) { |
| | | return null; |
| | | } |
| | | return productModel.getUnit(); |
| | | } |
| | | } |