| | |
| | | package com.ruoyi.production.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.appendix.service.AppendixService; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.production.dto.ProductOrderDto; |
| | | import com.ruoyi.production.dto.ProductOrderSourceDto; |
| | | 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.IProductionOrderAppendixService; |
| | | import com.ruoyi.production.service.ProductOrderService; |
| | | import com.ruoyi.productionPlan.mapper.ProductOrderPlanMapper; |
| | | import com.ruoyi.productionPlan.mapper.ProductionPlanMapper; |
| | |
| | | private StockUtils stockUtils; |
| | | |
| | | @Autowired |
| | | private AppendixService appendixService; |
| | | private IProductionOrderAppendixService productionOrderAppendixService; |
| | | |
| | | @Override |
| | | public IPage<ProductOrderDto> pageProductOrder(Page<ProductOrder> page, ProductOrderDto 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("合并的生产计划不存在"); |
| | | public Boolean revoke(List<Long> ids) { |
| | | List<ProductOrder> orders = productOrderMapper.selectBatchIds(ids); |
| | | if (orders.isEmpty()) { |
| | | throw new RuntimeException("生产订单不存在"); |
| | | } |
| | | for (ProductOrder order : orders) { |
| | | if (!ProductOrderStatusEnum.canRevoke(order.getStatus())) { |
| | | throw new RuntimeException("只有【待开始】状态的订单才可以撤回"); |
| | | } |
| | | } |
| | | |
| | | // 回退生产计划 |
| | | List<ProductOrderPlan> productOrderPlans = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, ids)); |
| | | for (ProductOrderPlan productOrderPlan : productOrderPlans) { |
| | | ProductionPlan productionPlan = productionPlanMapper.selectById(productOrderPlan.getProductionPlanId()); |
| | | productionPlan.setAssignedQuantity(productionPlan.getAssignedQuantity().subtract(productOrderPlan.getAssignedQuantity())); |
| | | productionPlanMapper.updateById(productionPlan); |
| | | 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, productOrder.getId())); |
| | | // 删除订单 |
| | | productOrderMapper.deleteById(productOrder.getId()); |
| | | // todo 删除订单下的工艺路线子表 |
| | | return null; |
| | | |
| | | // 将订单状态改为已取消 |
| | | for (ProductOrder order : orders) { |
| | | order.setStatus(ProductOrderStatusEnum.CANCEL.getCode()); |
| | | } |
| | | updateBatchById(orders); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean delete(Long[] ids) { |
| | | List<ProductOrder> orders = productOrderMapper.selectList(Wrappers.<ProductOrder>lambdaQuery().in(ProductOrder::getId, ids)); |
| | | public Boolean delete(Long id) { |
| | | ProductOrder order = productOrderMapper.selectById(id); |
| | | |
| | | if (orders.isEmpty()) { |
| | | if (order == null) { |
| | | throw new RuntimeException("生产订单不存在"); |
| | | } |
| | | for (ProductOrder order : orders) { |
| | | if (!ProductOrderStatusEnum.canDelete(order.getStatus())) { |
| | | throw new RuntimeException("只有【待开始、已取消】状态的订单才可以删除"); |
| | | } |
| | | if (!ProductOrderStatusEnum.canDelete(order.getStatus())) { |
| | | throw new RuntimeException("只有【待开始、已取消】状态的订单才可以删除"); |
| | | } |
| | | |
| | | // 是否已生产 |
| | | List<ProductWorkOrder> productWorkOrders = productWorkOrderMapper.selectList(Wrappers.<ProductWorkOrder>lambdaQuery().in(ProductWorkOrder::getProductOrderId, ids)); |
| | | List<ProductWorkOrder> productWorkOrders = productWorkOrderMapper.selectList(Wrappers.<ProductWorkOrder>lambdaQuery().eq(ProductWorkOrder::getProductOrderId, id)); |
| | | |
| | | if (!productWorkOrders.isEmpty()) { |
| | | List<Long> workOrderIds = productWorkOrders.stream() |
| | |
| | | } |
| | | |
| | | // 删除工单 |
| | | productWorkOrderMapper.delete(Wrappers.<ProductWorkOrder>lambdaQuery().in(ProductWorkOrder::getProductOrderId, ids)); |
| | | productWorkOrderMapper.delete(Wrappers.<ProductWorkOrder>lambdaQuery().eq(ProductWorkOrder::getProductOrderId, id)); |
| | | } |
| | | |
| | | // 回退生产计划 |
| | | List<ProductOrderPlan> productOrderPlans = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, ids)); |
| | | List<ProductOrderPlan> productOrderPlans = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().eq(ProductOrderPlan::getProductOrderId, id)); |
| | | |
| | | for (ProductOrderPlan productOrderPlan : productOrderPlans) { |
| | | ProductionPlan productionPlan = productionPlanMapper.selectById(productOrderPlan.getProductionPlanId()); |
| | |
| | | } |
| | | |
| | | // 删除中间表 |
| | | productOrderPlanMapper.delete(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, ids)); |
| | | productOrderPlanMapper.delete(Wrappers.<ProductOrderPlan>lambdaQuery().eq(ProductOrderPlan::getProductOrderId, id)); |
| | | |
| | | // 删除附表的工艺路线与BOM |
| | | for (Long id : ids) { |
| | | ProductOrder productOrder = baseMapper.selectById(id); |
| | | appendixService.deleteData(productOrder.getId(), productOrder.getRouteId()); |
| | | } |
| | | |
| | | // productProcessRouteItemMapper.delete(new LambdaQueryWrapper<ProductProcessRouteItem>().in(ProductProcessRouteItem::getProductOrderId, ids)); |
| | | // productProcessRouteMapper.delete(new LambdaQueryWrapper<ProductProcessRoute>().in(ProductProcessRoute::getProductOrderId, ids)); |
| | | productionOrderAppendixService.deleteData(order.getId(), order.getRouteId()); |
| | | |
| | | // 删除订单 |
| | | productOrderMapper.delete(new LambdaQueryWrapper<ProductOrder>().in(ProductOrder::getId, ids)); |
| | | productOrderMapper.deleteById(id); |
| | | |
| | | return true; |
| | | } |
| | |
| | | return "SC" + datePrefix + String.format("%04d", sequence); |
| | | } |
| | | |
| | | @Override |
| | | public List<ProductOrderSourceDto> productOrderSource(Long orderId) { |
| | | if (orderId == null) { |
| | | throw new ServiceException("查询订单数据不能为空"); |
| | | } |
| | | ProductOrder productOrder = getById(orderId); |
| | | if (productOrder == null) { |
| | | throw new ServiceException("查询失败,生产订单不存在"); |
| | | } |
| | | |
| | | List<ProductOrderSourceDto> list = baseMapper.productOrderSource(orderId); |
| | | return list; |
| | | } |
| | | } |