| | |
| | | import com.ruoyi.purchase.pojo.PurchaseLedger; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.stock.service.StockInventoryService; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.framework.security.LoginUser; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | |
| | | private ProcurementRecordService procurementRecordService; |
| | | private IApproveProcessService approveProcessService; |
| | | |
| | | private StockInventoryService stockInventoryService; |
| | | private SalesLedgerMapper salesLedgerMapper; |
| | | |
| | | @Override |
| | | public int add(QualityInspectDto qualityInspectDto) { |
| | |
| | | ); |
| | | syncQualifiedInboundToPurchaseProducts(qualityInspect, qualifiedQty); |
| | | } |
| | | } else if (Objects.equals(qualityInspect.getInspectType(), 2) && qualityInspect.getSalesLedgerId() != null) { |
| | | // 销售订单的成品出厂检验,提交后直接入库 |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setRecordId(qualityInspect.getSalesLedgerProductId()); |
| | | stockInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode()); |
| | | stockInventoryDto.setQualitity(qualifiedQty); |
| | | stockInventoryDto.setProductModelId(qualityInspect.getProductModelId()); |
| | | stockInventoryDto.setSalesLedgerId(qualityInspect.getSalesLedgerId()); |
| | | stockInventoryDto.setSalesLedgerProductId(qualityInspect.getSalesLedgerProductId()); |
| | | stockInventoryService.addstockInventory(stockInventoryDto); |
| | | |
| | | syncQualifiedInboundToSalesProducts(qualityInspect, qualifiedQty); |
| | | } else { |
| | | stockUtils.addStock( |
| | | qualityInspect.getPurchaseLedgerId() == null ? null : qualityInspect.getPurchaseLedgerId(), |
| | |
| | | qualityInspect.setInspectState(1); |
| | | int updated = qualityInspectMapper.updateById(qualityInspect); |
| | | refreshPurchaseLedgerStockStatusByInspect(qualityInspect.getPurchaseLedgerId()); |
| | | if (qualityInspect.getSalesLedgerId() != null) { |
| | | refreshSalesLedgerStockStatusByInspect(qualityInspect.getSalesLedgerId()); |
| | | } |
| | | return updated; |
| | | } |
| | | |
| | |
| | | qualityInspectParamService.remove(Wrappers.<QualityInspectParam>lambdaQuery().eq(QualityInspectParam::getInspectId, qualityInspectDto.getId())); |
| | | for (QualityInspectParam qualityInspectParam : qualityInspectDto.getQualityInspectParams()) { |
| | | qualityInspectParam.setInspectId(qualityInspectDto.getId()); |
| | | qualityInspectParam.setId(null); |
| | | } |
| | | qualityInspectParamService.saveBatch(qualityInspectDto.getQualityInspectParams()); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private void syncQualifiedInboundToSalesProducts(QualityInspect qualityInspect, BigDecimal inboundQty) { |
| | | if (qualityInspect == null || qualityInspect.getSalesLedgerProductId() == null || inboundQty == null) { |
| | | return; |
| | | } |
| | | if (inboundQty.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return; |
| | | } |
| | | |
| | | SalesLedgerProduct line = salesLedgerProductMapper.selectById(qualityInspect.getSalesLedgerProductId()); |
| | | if (line == null) { |
| | | return; |
| | | } |
| | | |
| | | BigDecimal orderQty = line.getQuantity() == null ? BigDecimal.ZERO : line.getQuantity(); |
| | | BigDecimal stocked = line.getStockedQuantity() == null ? BigDecimal.ZERO : line.getStockedQuantity(); |
| | | BigDecimal newStocked = stocked.add(inboundQty); |
| | | |
| | | int status; |
| | | if (newStocked.compareTo(BigDecimal.ZERO) <= 0) { |
| | | status = 0; |
| | | } else if (orderQty.compareTo(BigDecimal.ZERO) > 0 && newStocked.compareTo(orderQty) < 0) { |
| | | status = 1; |
| | | } else { |
| | | status = 2; |
| | | } |
| | | |
| | | line.setStockedQuantity(newStocked); |
| | | line.setProductStockStatus(status); |
| | | line.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.updateById(line); |
| | | } |
| | | |
| | | private void refreshSalesLedgerStockStatusByInspect(Long salesLedgerId) { |
| | | if (salesLedgerId == null) { |
| | | return; |
| | | } |
| | | List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId)); |
| | | if (products == null || products.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | boolean hasStocked = false; |
| | | boolean allStocked = true; |
| | | for (SalesLedgerProduct product : products) { |
| | | BigDecimal orderQty = product.getQuantity() == null ? BigDecimal.ZERO : product.getQuantity(); |
| | | BigDecimal sq = product.getStockedQuantity() == null ? BigDecimal.ZERO : product.getStockedQuantity(); |
| | | if (sq.compareTo(BigDecimal.ZERO) > 0) { |
| | | hasStocked = true; |
| | | } |
| | | if (orderQty.compareTo(BigDecimal.ZERO) <= 0 || sq.compareTo(orderQty) < 0) { |
| | | allStocked = false; |
| | | } |
| | | } |
| | | |
| | | SalesLedger ledger = salesLedgerMapper.selectById(salesLedgerId); |
| | | if (ledger != null) { |
| | | ledger.setStockStatus(allStocked ? 2 : (hasStocked ? 1 : 0)); |
| | | salesLedgerMapper.updateById(ledger); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |