| | |
| | | return 0; |
| | | } |
| | | |
| | | checkProductionDataExist(Arrays.asList(ids)); |
| | | |
| | | // 1. 先查询要删除的子表记录,获取对应的 salesLedgerId |
| | | List<SalesLedgerProduct> deletedProducts = salesLedgerProductMapper.selectBatchIds(Arrays.asList(ids)); |
| | | if (deletedProducts.isEmpty()) { |
| | |
| | | result = salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | addProductionData(salesLedgerProduct); |
| | | } else { |
| | | checkProductionDataExist(Collections.singletonList(salesLedgerProduct.getId())); |
| | | |
| | | //查询原本的产品型号id |
| | | salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity()); |
| | | result = salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 检查是否有报工数据 |
| | | */ |
| | | 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) { |