| | |
| | | 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.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; |
| | |
| | | |
| | | private ProductModelMapper productModelMapper; |
| | | |
| | | private QualityInspectMapper qualityInspectMapper; |
| | | |
| | | private ProductProcessMapper productProcessMapper; |
| | | |
| | | private ProductMapper productMapper; |
| | | |
| | | private QualityTestStandardMapper qualityTestStandardMapper; |
| | | |
| | | private QualityInspectParamMapper qualityInspectParamMapper; |
| | | |
| | | |
| | | @Override |
| | | public IPage<ProductionProductMainDto> listPageProductionProductMainDto(Page page, ProductionProductMainDto productionProductMainDto) { |
| | |
| | | throw new RuntimeException("参数不能为空"); |
| | | } |
| | | |
| | | // 判断是新增还是更新 |
| | | if (dto.getId() != null) { |
| | | // 更新逻辑 - 只更新数量 |
| | | QueryWrapper<ProductionProductOutput> outputWrapper = new QueryWrapper<>(); |
| | | outputWrapper.eq("product_main_id", dto.getId()); |
| | | |
| | | ProductionProductOutput output = productionProductOutputMapper.selectOne(outputWrapper); |
| | | if (output == null) { |
| | | throw new RuntimeException("产出记录不存在"); |
| | | } |
| | | |
| | | // 只更新数量 |
| | | if (dto.getQuantity() != null) { |
| | | output.setQuantity(dto.getQuantity()); |
| | | productionProductOutputMapper.updateById(output); |
| | | } |
| | | return true; |
| | | } |
| | | // if (dto.isReportWork()) { |
| | | // // 更新逻辑 - 只更新数量 |
| | | // QueryWrapper<ProductionProductOutput> outputWrapper = new QueryWrapper<>(); |
| | | // outputWrapper.eq("product_main_id", dto.getId()); |
| | | // |
| | | // ProductionProductOutput output = productionProductOutputMapper.selectOne(outputWrapper); |
| | | // if (output == null) { |
| | | // throw new RuntimeException("产出记录不存在"); |
| | | // } |
| | | // |
| | | // // 只更新数量 |
| | | // if (dto.getQuantity() != null) { |
| | | // output.setQuantity(dto.getQuantity()); |
| | | // productionProductOutputMapper.updateById(output); |
| | | // } |
| | | // return true; |
| | | // } |
| | | |
| | | // 新增逻辑 |
| | | ProductionProductMain productionProductMain = new ProductionProductMain(); |
| | |
| | | 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()) |
| | | .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); |
| | | 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); |
| | | }); |
| | | } |
| | | // 添加产出 |
| | | ProductionProductOutput productionProductOutput = new ProductionProductOutput(); |
| | | productionProductOutput.setProductMainId(productionProductMain.getId()); |