| | |
| | | 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.StockOutQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockInUnQualifiedRecordTypeEnum; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | 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.ProductOrderService; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean delete(Long[] ids) { |
| | | //妿已ç»å¼å§ç产,ä¸è½å é¤ |
| | | //æ¥è¯¢ç产订åä¸çå·¥å |
| | | List<ProductOrder> orders = productOrderMapper.selectList(Wrappers.<ProductOrder>lambdaQuery().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.size()>0){ |
| | | //夿æ¯å¦ææ¥å·¥æ°æ® |
| | | List<ProductionProductMain> productionProductMains = productionProductMainMapper.selectList(Wrappers.<ProductionProductMain>lambdaQuery() |
| | | .in(ProductionProductMain::getWorkOrderId, productWorkOrders.stream().map(ProductWorkOrder::getId).collect(Collectors.toList()))); |
| | | if (productionProductMains.size()>0){ |
| | | |
| | | 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)); |
| | | } |
| | | //å é¤å·¥èºè·¯çº¿ |
| | | 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)); |
| | | |
| | | // åéç产计å |
| | | 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)); |
| | | |
| | | // TODO: å é¤é表çå·¥èºè·¯çº¿ä¸BOM |
| | | 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; |
| | | } |
| | | |