| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.production.dto.ProductProcessRouteItemDto; |
| | | import com.ruoyi.production.mapper.ProductOrderMapper; |
| | | import com.ruoyi.production.mapper.ProductWorkOrderMapper; |
| | | import com.ruoyi.production.pojo.ProductOrder; |
| | | import com.ruoyi.production.pojo.ProductProcessRouteItem; |
| | | import com.ruoyi.production.pojo.ProductWorkOrder; |
| | | import com.ruoyi.production.mapper.*; |
| | | import com.ruoyi.production.pojo.*; |
| | | import com.ruoyi.production.service.ProductProcessRouteItemService; |
| | | import com.ruoyi.production.service.ProductWorkOrderService; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | | import com.ruoyi.quality.pojo.QualityInspect; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | |
| | | private ProductWorkOrderMapper productWorkOrderMapper; |
| | | |
| | | private SalesLedgerProductMapper salesLedgerProductMapper; |
| | | |
| | | private ProductionProductMainMapper productionProductMainMapper; |
| | | |
| | | private ProductionProductInputMapper productionProductInputMapper; |
| | | |
| | | private ProductionProductOutputMapper productionProductOutputMapper; |
| | | |
| | | private QualityInspectMapper qualityInspectMapper; |
| | | |
| | | private SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper; |
| | | |
| | | @GetMapping("list") |
| | | @ApiOperation("根据Id查询工艺项目") |
| | |
| | | @ApiOperation("删除生产工艺路线") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R deleteRouteItem(@RequestBody ProductProcessRouteItemDto processRouteItemDto) { |
| | | |
| | | if (processRouteItemDto == null || processRouteItemDto.getId() == null) { |
| | | return R.fail("参数错误,ID不能为空"); |
| | | return R.fail("删除失败:工艺路线项ID不能为空"); |
| | | } |
| | | Long routeItemId = processRouteItemDto.getId(); |
| | | |
| | | try { |
| | | // 先删除关联的工单数据 |
| | | LambdaQueryWrapper<ProductWorkOrder> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(ProductWorkOrder::getProductProcessRouteItemId, processRouteItemDto.getId()); |
| | | productWorkOrderMapper.delete(wrapper); |
| | | // 查询工单 |
| | | ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectOne( |
| | | new LambdaQueryWrapper<ProductWorkOrder>() |
| | | .eq(ProductWorkOrder::getProductProcessRouteItemId, routeItemId) |
| | | .last("LIMIT 1") |
| | | ); |
| | | if (productWorkOrder == null) { |
| | | return R.fail("删除失败:未找到关联的生产工单"); |
| | | } |
| | | Long workOrderId = productWorkOrder.getId(); |
| | | Long productOrderId = productWorkOrder.getProductOrderId(); |
| | | |
| | | // 查询生产主表 |
| | | List<ProductionProductMain> productionProductMains = productionProductMainMapper.selectList( |
| | | new LambdaQueryWrapper<ProductionProductMain>() |
| | | .eq(ProductionProductMain::getWorkOrderId, workOrderId) |
| | | ); |
| | | if (!productionProductMains.isEmpty()) { |
| | | // 批量删除子表 |
| | | for (ProductionProductMain main : productionProductMains) { |
| | | Long mainId = main.getId(); |
| | | // 删除投入 |
| | | productionProductInputMapper.delete(new LambdaQueryWrapper<ProductionProductInput>() |
| | | .eq(ProductionProductInput::getProductMainId, mainId)); |
| | | // 删除产出 |
| | | productionProductOutputMapper.delete(new LambdaQueryWrapper<ProductionProductOutput>() |
| | | .eq(ProductionProductOutput::getProductMainId, mainId)); |
| | | // 删除质检 |
| | | qualityInspectMapper.delete(new LambdaQueryWrapper<QualityInspect>() |
| | | .eq(QualityInspect::getProductMainId, mainId)); |
| | | } |
| | | } |
| | | |
| | | // 删除报工(生产主表) |
| | | productionProductMainMapper.delete(new LambdaQueryWrapper<ProductionProductMain>() |
| | | .eq(ProductionProductMain::getWorkOrderId, workOrderId)); |
| | | |
| | | // 查询订单 + 删除核算 |
| | | ProductOrder productOrder = productOrderMapper.selectById(productOrderId); |
| | | if (productOrder != null && productOrder.getSalesLedgerId() != null) { |
| | | salesLedgerProductionAccountingMapper.delete(new LambdaQueryWrapper<SalesLedgerProductionAccounting>() |
| | | .eq(SalesLedgerProductionAccounting::getSalesLedgerId, productOrder.getSalesLedgerId())); |
| | | } |
| | | |
| | | // 删除关联工单 |
| | | productWorkOrderMapper.delete(new LambdaQueryWrapper<ProductWorkOrder>() |
| | | .eq(ProductWorkOrder::getProductProcessRouteItemId, routeItemId)); |
| | | |
| | | // 删除主表数据 |
| | | productProcessRouteItemService.removeById(processRouteItemDto.getId()); |
| | | return R.ok(); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("删除失败:" + e.getMessage()); |
| | | } |
| | | boolean removeFlag = productProcessRouteItemService.removeById(routeItemId); |
| | | if (!removeFlag) { |
| | | return R.fail("删除失败:工艺路线项主表数据不存在"); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } catch (Exception e) { |
| | | return R.fail("删除生产工艺路线失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | } |