| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockUnQualifiedRecordTypeEnum; |
| | | import com.ruoyi.appendix.service.AppendixService; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.production.dto.ProductBomDto; |
| | | import com.ruoyi.production.dto.ProductOrderDto; |
| | | import com.ruoyi.production.dto.ProductStructureDto; |
| | | import com.ruoyi.production.enums.ProductOrderStatusEnum; |
| | | import com.ruoyi.production.mapper.*; |
| | | import com.ruoyi.production.pojo.*; |
| | | import com.ruoyi.production.service.ProcessRouteService; |
| | | import com.ruoyi.production.service.ProductOrderService; |
| | | import com.ruoyi.productionPlan.mapper.ProductOrderPlanMapper; |
| | | import com.ruoyi.productionPlan.mapper.ProductionPlanMapper; |
| | | import com.ruoyi.productionPlan.pojo.ProductOrderPlan; |
| | | import com.ruoyi.productionPlan.pojo.ProductionPlan; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | | import com.ruoyi.quality.pojo.QualityInspect; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | |
| | | private ProductionProductMainMapper productionProductMainMapper; |
| | | |
| | | @Autowired |
| | | private ProductOrderPlanMapper productOrderPlanMapper; |
| | | |
| | | @Autowired |
| | | private ProductionPlanMapper productionPlanMapper; |
| | | |
| | | @Autowired |
| | | private ProductionProductOutputMapper productionProductOutputMapper; |
| | | |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private StockUtils stockUtils; |
| | | |
| | | @Autowired |
| | | private AppendixService appendixService; |
| | | |
| | | @Override |
| | | public IPage<ProductOrderDto> pageProductOrder(Page page, ProductOrderDto productOrder) { |
| | | public IPage<ProductOrderDto> pageProductOrder(Page<ProductOrder> page, ProductOrderDto productOrder) { |
| | | return productOrderMapper.pageProductOrder(page, productOrder); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean revoke(ProductOrder productOrder) { |
| | | // todo 判断是否产生报工信息 |
| | | |
| | | // 查询合并的生产计划 |
| | | List<ProductOrderPlan> productOrderPlans = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, productOrder.getId())); |
| | | if (productOrderPlans.isEmpty()) { |
| | | throw new RuntimeException("合并的生产计划不存在"); |
| | | } |
| | | for (ProductOrderPlan productOrderPlan : productOrderPlans) { |
| | | ProductionPlan productionPlan = productionPlanMapper.selectById(productOrderPlan.getProductionPlanId()); |
| | | productionPlan.setAssignedQuantity(productionPlan.getAssignedQuantity().subtract(productOrderPlan.getAssignedQuantity())); |
| | | productionPlanMapper.updateById(productionPlan); |
| | | } |
| | | // 删除关联关系 |
| | | productOrderPlanMapper.delete(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, productOrder.getId())); |
| | | // 删除订单 |
| | | productOrderMapper.deleteById(productOrder.getId()); |
| | | // todo 删除订单下的工艺路线子表 |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<ProcessRoute> listProcessRoute(Long productModelId) { |
| | | return productOrderMapper.listProcessRoute(productModelId); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean delete(Long[] ids) { |
| | | List<ProductOrder> orders = productOrderMapper.selectList(Wrappers.<ProductOrder>lambdaQuery().in(ProductOrder::getId, ids)); |
| | | |
| | | //批量查询productOrder |
| | | List<ProductOrder> productOrders = productOrderMapper.selectList( |
| | | new LambdaQueryWrapper<ProductOrder>() |
| | | .in(ProductOrder::getId, ids) |
| | | ); |
| | | if (!org.springframework.util.CollectionUtils.isEmpty(productOrders)) { |
| | | |
| | | |
| | | // 批量查询processRouteItems |
| | | List<ProductProcessRouteItem> allRouteItems = productProcessRouteItemMapper.selectList( |
| | | new LambdaQueryWrapper<ProductProcessRouteItem>() |
| | | .in(ProductProcessRouteItem::getProductOrderId, ids) |
| | | ); |
| | | |
| | | if (!com.baomidou.mybatisplus.core.toolkit.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 (!com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(workOrders)) { |
| | | List<Long> workOrderIds = workOrders.stream() |
| | | .map(ProductWorkOrder::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 查询关联的生产主表ID |
| | | List<ProductionProductMain> productMains = productionProductMainMapper.selectList( |
| | | new LambdaQueryWrapper<ProductionProductMain>() |
| | | .in(ProductionProductMain::getWorkOrderId, workOrderIds) |
| | | ); |
| | | List<Long> productMainIds = productMains.stream() |
| | | .map(ProductionProductMain::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 删除产出表、投入表数据 |
| | | if (!com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(productMainIds)) { |
| | | productionProductOutputMapper.deleteByProductMainIds(productMainIds); |
| | | productionProductInputMapper.deleteByProductMainIds(productMainIds); |
| | | List<QualityInspect> qualityInspects = qualityInspectMapper.selectList( |
| | | new LambdaQueryWrapper<QualityInspect>() |
| | | .in(QualityInspect::getProductMainId, productMainIds) |
| | | ); |
| | | //删除出库记录 |
| | | for (Long productMainId : productMainIds) { |
| | | //删除生产出库记录 |
| | | stockUtils.deleteStockOutRecord(productMainId, StockQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode()); |
| | | //删除报废的入库记录 |
| | | stockUtils.deleteStockInRecord(productMainId, StockUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode()); |
| | | } |
| | | qualityInspects.forEach(qualityInspect -> { |
| | | //inspectState=1 已提交 不能删除 |
| | | if (qualityInspect.getInspectState() == 1) { |
| | | throw new RuntimeException("已提交的检验单不能删除"); |
| | | } |
| | | }); |
| | | qualityInspectMapper.deleteByProductMainIds(productMainIds); |
| | | salesLedgerProductionAccountingMapper.delete(new LambdaQueryWrapper<SalesLedgerProductionAccounting>() |
| | | .in(SalesLedgerProductionAccounting::getProductMainId, productMainIds)); |
| | | } |
| | | |
| | | // 删除生产主表数据 |
| | | productionProductMainMapper.deleteByWorkOrderIds(workOrderIds); |
| | | |
| | | // 删除工单数据 |
| | | productWorkOrderMapper.delete(new LambdaQueryWrapper<ProductWorkOrder>() |
| | | .in(ProductWorkOrder::getProductProcessRouteItemId, routeItemIds)); |
| | | } |
| | | } |
| | | // 批量删除processRouteItem |
| | | productProcessRouteItemMapper.delete(new LambdaQueryWrapper<ProductProcessRouteItem>() |
| | | .in(ProductProcessRouteItem::getProductOrderId, ids)); |
| | | |
| | | // 批量删除productProcessRoute |
| | | productProcessRouteMapper.delete(new LambdaQueryWrapper<ProductProcessRoute>() |
| | | .in(ProductProcessRoute::getProductOrderId, ids)); |
| | | |
| | | // 批量删除productOrder |
| | | productOrderMapper.delete(new LambdaQueryWrapper<ProductOrder>() |
| | | .in(ProductOrder::getId, ids)); |
| | | if (orders.isEmpty()) { |
| | | throw new RuntimeException("生产订单不存在"); |
| | | } |
| | | for (ProductOrder order : orders) { |
| | | if (!ProductOrderStatusEnum.canDelete(order.getStatus())) { |
| | | throw new RuntimeException("只有【待开始、已取消】状态的订单才可以删除"); |
| | | } |
| | | } |
| | | |
| | | // 是否已生产 |
| | | List<ProductWorkOrder> productWorkOrders = productWorkOrderMapper.selectList(Wrappers.<ProductWorkOrder>lambdaQuery().in(ProductWorkOrder::getProductOrderId, ids)); |
| | | |
| | | if (!productWorkOrders.isEmpty()) { |
| | | List<Long> workOrderIds = productWorkOrders.stream() |
| | | .map(ProductWorkOrder::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<ProductionProductMain> productionProductMains = productionProductMainMapper.selectList(Wrappers.<ProductionProductMain>lambdaQuery().in(ProductionProductMain::getWorkOrderId, workOrderIds)); |
| | | if (!productionProductMains.isEmpty()) { |
| | | throw new RuntimeException("生产订单已经开始生产,不能删除"); |
| | | } |
| | | |
| | | // 删除工单 |
| | | productWorkOrderMapper.delete(Wrappers.<ProductWorkOrder>lambdaQuery().in(ProductWorkOrder::getProductOrderId, ids)); |
| | | } |
| | | |
| | | // 回退生产计划 |
| | | List<ProductOrderPlan> productOrderPlans = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, ids)); |
| | | |
| | | for (ProductOrderPlan productOrderPlan : productOrderPlans) { |
| | | ProductionPlan productionPlan = productionPlanMapper.selectById(productOrderPlan.getProductionPlanId()); |
| | | |
| | | if (productionPlan != null) { |
| | | // 回退数量 |
| | | BigDecimal newAssigned = productionPlan.getAssignedQuantity() |
| | | .subtract(productOrderPlan.getAssignedQuantity()); |
| | | |
| | | if (newAssigned.compareTo(BigDecimal.ZERO) < 0) { |
| | | newAssigned = BigDecimal.ZERO; |
| | | } |
| | | productionPlan.setAssignedQuantity(newAssigned); |
| | | BigDecimal volume = productionPlan.getVolume() == null ? BigDecimal.ZERO : productionPlan.getVolume(); |
| | | |
| | | int status; |
| | | if (newAssigned.compareTo(BigDecimal.ZERO) == 0) { |
| | | status = 0; // 未下发 |
| | | } else if (newAssigned.compareTo(volume) < 0) { |
| | | status = 1; // 部分下发 |
| | | } else { |
| | | status = 2; // 已下发 |
| | | } |
| | | productionPlan.setStatus(status); |
| | | |
| | | productionPlanMapper.updateById(productionPlan); |
| | | } |
| | | } |
| | | |
| | | // 删除中间表 |
| | | productOrderPlanMapper.delete(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, ids)); |
| | | |
| | | // 删除附表的工艺路线与BOM |
| | | for (Long id : ids) { |
| | | ProductOrder productOrder = baseMapper.selectById(id); |
| | | appendixService.deleteData(productOrder.getRouteId()); |
| | | } |
| | | |
| | | // productProcessRouteItemMapper.delete(new LambdaQueryWrapper<ProductProcessRouteItem>().in(ProductProcessRouteItem::getProductOrderId, ids)); |
| | | // productProcessRouteMapper.delete(new LambdaQueryWrapper<ProductProcessRoute>().in(ProductProcessRoute::getProductOrderId, ids)); |
| | | |
| | | // 删除订单 |
| | | productOrderMapper.delete(new LambdaQueryWrapper<ProductOrder>().in(ProductOrder::getId, ids)); |
| | | |
| | | return true; |
| | | } |
| | | |