gongchunyi
3 小时以前 4295247f77b9ae0c64db3977b5717b68f86c1273
fix: 销售产品开始生产不能删除和编辑
已修改2个文件
78 ■■■■ 文件已修改
src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -21,7 +21,9 @@
import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
@@ -35,12 +37,13 @@
    /**
     * 不合格入库
     *
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public void addUnStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
    public void addUnStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
        stockUninventoryDto.setRecordId(recordId);
        stockUninventoryDto.setRecordType(String.valueOf(recordType));
@@ -51,12 +54,13 @@
    /**
     * 不合格出库
     *
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public void subtractUnStock(Long productModelId, BigDecimal quantity, Integer recordType,Long recordId) {
    public void subtractUnStock(Long productModelId, BigDecimal quantity, Integer recordType, Long recordId) {
        StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
        stockUninventoryDto.setRecordId(recordId);
        stockUninventoryDto.setRecordType(String.valueOf(recordType));
@@ -67,12 +71,13 @@
    /**
     * 合格入库
     *
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public void addStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
    public void addStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
@@ -83,12 +88,13 @@
    /**
     * 合格出库
     *
     * @param productModelId
     * @param quantity
     * @param recordType
     * @param recordId
     */
    public void substractStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
    public void substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setRecordId(recordId);
        stockInventoryDto.setRecordType(String.valueOf(recordType));
@@ -99,19 +105,23 @@
    //不合格库存删除
    public void deleteStockInRecord(Long recordId, String recordType) {
        StockInRecord one = stockInRecordService.getOne(new QueryWrapper<StockInRecord>()
        List<StockInRecord> stockInRecords = stockInRecordService.list(new QueryWrapper<StockInRecord>()
                .lambda().eq(StockInRecord::getRecordId, recordId)
                .eq(StockInRecord::getRecordType, recordType));
        if (ObjectUtils.isNotEmpty(one)) {
            stockInRecordService.batchDelete(Collections.singletonList(one.getId()));
        if (ObjectUtils.isNotEmpty(stockInRecords)) {
            List<Long> collect = stockInRecords.stream().map(StockInRecord::getId).collect(Collectors.toList());
            stockInRecordService.batchDelete(collect);
        }
    }
    public void deleteStockOutRecord(Long recordId, String recordType) {
        StockOutRecord one = stockOutRecordService.getOne(new QueryWrapper<StockOutRecord>()
        List<StockOutRecord> stockOutRecords = stockOutRecordService.list(new QueryWrapper<StockOutRecord>()
                .lambda().eq(StockOutRecord::getRecordId, recordId)
                .eq(StockOutRecord::getRecordType, recordType));
        if (ObjectUtils.isNotEmpty(one)) {
            stockOutRecordService.batchDelete(Collections.singletonList(one.getId()));
        if (ObjectUtils.isNotEmpty(stockOutRecords)) {
            List<Long> collect = stockOutRecords.stream().map(StockOutRecord::getId).collect(Collectors.toList());
            stockOutRecordService.batchDelete(collect);
        }
    }
}
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -158,6 +158,8 @@
            return 0;
        }
        checkProductionDataExist(Arrays.asList(ids));
        // 1. 先查询要删除的子表记录,获取对应的 salesLedgerId
        List<SalesLedgerProduct> deletedProducts = salesLedgerProductMapper.selectBatchIds(Arrays.asList(ids));
        if (deletedProducts.isEmpty()) {
@@ -222,6 +224,8 @@
            result = salesLedgerProductMapper.insert(salesLedgerProduct);
            addProductionData(salesLedgerProduct);
        } else {
            checkProductionDataExist(Collections.singletonList(salesLedgerProduct.getId()));
            //查询原本的产品型号id
            salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity());
            result = salesLedgerProductMapper.updateById(salesLedgerProduct);
@@ -334,6 +338,50 @@
    }
    /**
     * 检查是否有报工数据
     */
    public void checkProductionDataExist(List<Long> productIds) {
        if (org.springframework.util.CollectionUtils.isEmpty(productIds)) {
            return;
        }
        //  查询productOrder
        List<ProductOrder> productOrders = productOrderMapper.selectList(new LambdaQueryWrapper<ProductOrder>()
                .in(ProductOrder::getSaleLedgerProductId, productIds));
        if (!CollectionUtils.isEmpty(productOrders)) {
            List<Long> orderIds = productOrders.stream()
                    .map(ProductOrder::getId)
                    .collect(Collectors.toList());
            //  查询processRouteItems
            List<ProductProcessRouteItem> allRouteItems = productProcessRouteItemMapper.selectList(new LambdaQueryWrapper<ProductProcessRouteItem>()
                    .in(ProductProcessRouteItem::getProductOrderId, orderIds));
            if (!CollectionUtils.isEmpty(allRouteItems)) {
                //  获取工序项ID
                List<Long> routeItemIds = allRouteItems.stream()
                        .map(ProductProcessRouteItem::getId)
                        .collect(Collectors.toList());
                //  查询关联的工单ID
                List<ProductWorkOrder> workOrders = productWorkOrderMapper.selectList(new LambdaQueryWrapper<ProductWorkOrder>()
                        .in(ProductWorkOrder::getProductProcessRouteItemId, routeItemIds));
                if (!CollectionUtils.isEmpty(workOrders)) {
                    List<Long> workOrderIds = workOrders.stream()
                            .map(ProductWorkOrder::getId)
                            .collect(Collectors.toList());
                    //  查询关联的生产主表ID是否有数据
                    Long count = productionProductMainMapper.selectCount(new LambdaQueryWrapper<ProductionProductMain>()
                            .in(ProductionProductMain::getWorkOrderId, workOrderIds));
                    if (count != null && count > 0L) {
                        throw new RuntimeException("当前销售订单已有报工数据,不能删除和修改");
                    }
                }
            }
        }
    }
    /**
     * 删除生产数据
     */
    public void deleteProductionData(List<Long> productIds) {