| | |
| | | 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.ProductWorkOrderMapper; |
| | | 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; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | |
| | | @Api(tags = "生产工艺路线") |
| | | public class ProductProcessRouteItemController { |
| | | |
| | | private final ProductOrderMapper productOrderMapper; |
| | | private ProductProcessRouteItemService productProcessRouteItemService; |
| | | |
| | | private ProductWorkOrderService productWorkOrderService; |
| | | |
| | | 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 addOrUpdate(@RequestBody ProductProcessRouteItemDto processRouteItemDto) { |
| | | |
| | | ProductOrder productOrder = productOrderMapper.selectById(processRouteItemDto.getRouteId()); |
| | | if (productOrder == null) { |
| | | return R.fail("未找到ID为[" + processRouteItemDto.getRouteId() + "]的产品订单"); |
| | | } |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectOne(new LambdaQueryWrapper<SalesLedgerProduct>() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, productOrder.getSalesLedgerId())); |
| | | |
| | | if (salesLedgerProduct == null) { |
| | | return R.fail("未找到销售台账ID为[" + productOrder.getSalesLedgerId() + "]的台账产品"); |
| | | } |
| | | |
| | | List<ProductProcessRouteItem> items = processRouteItemDto.getProcessRouteItem(); |
| | | if (CollectionUtils.isEmpty(items)) { |
| | | return R.ok(); |
| | |
| | | workOrder.setProductProcessRouteItemId(item.getId()); |
| | | workOrder.setProductOrderId(item.getRouteId()); |
| | | workOrder.setWorkOrderNo(workOrderNoStr); |
| | | workOrder.setPlanQuantity(salesLedgerProduct.getQuantity()); |
| | | workOrder.setStatus(1); |
| | | workOrders.add(workOrder); |
| | | } |
| | |
| | | @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()); |
| | | boolean removeFlag = productProcessRouteItemService.removeById(routeItemId); |
| | | if (!removeFlag) { |
| | | return R.fail("删除失败:工艺路线项主表数据不存在"); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("删除失败:" + e.getMessage()); |
| | | return R.fail("删除生产工艺路线失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |