| | |
| | | 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.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.mapper.ProductMapper; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.pojo.Product; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.production.controller.ProductWorkOrderController; |
| | | import com.ruoyi.production.dto.ProductStructureDto; |
| | | import com.ruoyi.production.dto.ProductionProductMainDto; |
| | | import com.ruoyi.production.mapper.*; |
| | | import com.ruoyi.production.pojo.ProductProcessRouteItem; |
| | | import com.ruoyi.production.pojo.ProductionProductMain; |
| | | import com.ruoyi.production.pojo.ProductionProductOutput; |
| | | import com.ruoyi.production.pojo.*; |
| | | import com.ruoyi.production.service.ProductionProductMainService; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | | import com.ruoyi.quality.mapper.QualityInspectParamMapper; |
| | | import com.ruoyi.quality.mapper.QualityTestStandardMapper; |
| | | import com.ruoyi.quality.pojo.QualityInspect; |
| | | import com.ruoyi.quality.pojo.QualityInspectParam; |
| | | import com.ruoyi.quality.pojo.QualityTestStandard; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | public class ProductionProductMainServiceImpl extends ServiceImpl<ProductionProductMainMapper, ProductionProductMain> implements ProductionProductMainService { |
| | | |
| | | private ProductionProductMainMapper productionProductMainMapper; |
| | | |
| | | |
| | | private ProductWorkOrderController productWorkOrderController; |
| | | |
| | | |
| | | private ProductWorkOrderMapper productWorkOrderMapper; |
| | | |
| | | |
| | | private ProductProcessRouteItemMapper productProcessRouteItemMapper; |
| | | |
| | | |
| | | private ProductionProductOutputMapper productionProductOutputMapper; |
| | | |
| | | |
| | | private ProcessRouteItemMapper processRouteItemMapper; |
| | | |
| | | |
| | | private ProductModelMapper productModelMapper; |
| | | |
| | | private QualityInspectMapper qualityInspectMapper; |
| | | |
| | | private ProductProcessMapper productProcessMapper; |
| | | |
| | | private ProductMapper productMapper; |
| | | |
| | | private QualityTestStandardMapper qualityTestStandardMapper; |
| | | |
| | | private QualityInspectParamMapper qualityInspectParamMapper; |
| | | |
| | | private ProductStructureMapper productStructureMapper; |
| | | |
| | | private ProductionProductInputMapper productionProductInputMapper; |
| | | |
| | | |
| | | @Override |
| | |
| | | throw new RuntimeException("参数不能为空"); |
| | | } |
| | | |
| | | // 判断是新增还是更新 |
| | | if (dto.getId() != null) { |
| | | if (dto.isReportWork()) { |
| | | // 更新逻辑 - 只更新数量 |
| | | QueryWrapper<ProductionProductOutput> outputWrapper = new QueryWrapper<>(); |
| | | outputWrapper.eq("product_main_id", dto.getId()); |
| | | outputWrapper.eq("product_main_id", dto.getProductMainId()); |
| | | |
| | | ProductionProductOutput output = productionProductOutputMapper.selectOne(outputWrapper); |
| | | if (output == null) { |
| | |
| | | queryWrapper.select("MAX(product_no) as maxNo") |
| | | .likeRight("product_no", datePrefix); |
| | | |
| | | // 修正:安全处理可能为空的查询结果 |
| | | List<Map<String, Object>> resultList = productionProductMainMapper.selectMaps(queryWrapper); |
| | | |
| | | int sequenceNumber = 1; |
| | |
| | | productionProductMain.setStatus(0); |
| | | |
| | | // 添加报工主表 |
| | | productionProductMainMapper.insert(productionProductMain); |
| | | int insert = productionProductMainMapper.insert(productionProductMain); |
| | | |
| | | //更新工单 |
| | | if (insert > 0) { |
| | | UpdateWrapper<ProductWorkOrder> wrapper = new UpdateWrapper<>(); |
| | | wrapper.set("report_work", true) |
| | | .set("quantity", dto.getQuantity()) |
| | | .set("product_main_id", productionProductMain.getId()) |
| | | .eq("id", dto.getWorkOrderId()); |
| | | productWorkOrderMapper.update(null, wrapper); |
| | | } |
| | | ProductProcess productProcess = productProcessMapper.selectById(productProcessRouteItem.getProcessId()); |
| | | ProductModel productModel = productProcessRouteItem.getProductModelId() != null ? |
| | | productModelMapper.selectById(productProcessRouteItem.getProductModelId()) : null; |
| | | |
| | | if (productModel != null) { |
| | | Product product = productMapper.selectById(productModel.getProductId()); |
| | | int inspectType = "组装".equals(productProcess.getName()) ? 2 : 1; |
| | | |
| | | QualityInspect qualityInspect = new QualityInspect(); |
| | | qualityInspect.setProductId(product.getId()); |
| | | qualityInspect.setProductName(product.getProductName()); |
| | | qualityInspect.setModel(productModel.getModel()); |
| | | qualityInspect.setUnit(productModel.getUnit()); |
| | | qualityInspect.setQuantity(dto.getQuantity()); |
| | | qualityInspect.setProcess(productProcess.getName()); |
| | | qualityInspect.setInspectState(0); |
| | | qualityInspect.setInspectType(inspectType); |
| | | qualityInspect.setProductMainId(productionProductMain.getId()); |
| | | qualityInspectMapper.insert(qualityInspect); |
| | | |
| | | qualityTestStandardMapper.selectList( |
| | | new LambdaQueryWrapper<QualityTestStandard>() |
| | | .eq(QualityTestStandard::getProductId, product.getId()) |
| | | ).forEach(standard -> { |
| | | QualityInspectParam param = new QualityInspectParam(); |
| | | BeanUtils.copyProperties(standard, param); |
| | | param.setId(null); |
| | | param.setInspectId(qualityInspect.getId()); |
| | | qualityInspectParamMapper.insert(param); |
| | | }); |
| | | } |
| | | // 添加投入 |
| | | if (productModel != null) { |
| | | List<ProductStructureDto> productStructureDtos = productStructureMapper.listByproductModelId(productModel.getId()); |
| | | for (ProductStructureDto productStructureDto : productStructureDtos) { |
| | | ProductionProductInput productionProductInput = new ProductionProductInput(); |
| | | productionProductInput.setProductModelId(productStructureDto.getProductModelId()); |
| | | productionProductInput.setQuantity(productStructureDto.getUnitQuantity()); |
| | | productionProductInput.setProductMainId(productionProductMain.getId()); |
| | | productionProductInputMapper.insert(productionProductInput); |
| | | } |
| | | } |
| | | |
| | | // 添加产出 |
| | | ProductionProductOutput productionProductOutput = new ProductionProductOutput(); |
| | |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Boolean removeProductMain(ProductionProductMainDto dto) { |
| | | Long id = dto.getId(); |
| | | |
| | | // 删除质检参数和质检记录 |
| | | qualityInspectMapper.selectList( |
| | | new LambdaQueryWrapper<QualityInspect>() |
| | | .eq(QualityInspect::getProductMainId, id) |
| | | ).forEach(q -> { |
| | | qualityInspectParamMapper.delete( |
| | | new LambdaQueryWrapper<QualityInspectParam>() |
| | | .eq(QualityInspectParam::getInspectId, q.getId())); |
| | | qualityInspectMapper.deleteById(q.getId()); |
| | | }); |
| | | |
| | | // 删除产出记录 |
| | | productionProductOutputMapper.delete(new LambdaQueryWrapper<ProductionProductOutput>() |
| | | .eq(ProductionProductOutput::getProductMainId, id) |
| | | ); |
| | | |
| | | // 删除主表 |
| | | return productionProductMainMapper.deleteById(id) > 0; |
| | | } |
| | | } |