| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | 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.yuanchu.mom.mapper.*; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.pojo.vo.FinishedInspectVo1; |
| | | import com.yuanchu.mom.pojo.vo.FinishedInspectVo; |
| | | import com.yuanchu.mom.service.*; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | |
| | | public class FinishedInspectServiceImpl extends ServiceImpl<FinishedInspectMapper, FinishedInspect> implements FinishedInspectService { |
| | | |
| | | @Resource |
| | | private FinishedInspectMapper finishedInspectMapper; |
| | | FinishedInspectMapper finishedInspectMapper; |
| | | |
| | | @Resource |
| | | MaterialMapper materialMapper; |
| | | ManualTechnologyMapper manualTechnologyMapper; |
| | | |
| | | @Resource |
| | | StandardService standardService; |
| | | |
| | | @Resource |
| | | SpecificationsService specificationsService; |
| | | ProductService productService; |
| | | |
| | | @Resource |
| | | InspectionItemService inspectionItemService; |
| | | |
| | | @Autowired |
| | | private ProductService productService; |
| | | |
| | | @Resource |
| | | UserMapper userMapper; |
| | | InspectionItemMapper inspectionItemMapper; |
| | | |
| | | @Resource |
| | | InspectUnacceptedMapper inspectUnacceptedMapper; |
| | |
| | | @Resource |
| | | RepertoryMapper repertoryMapper; |
| | | |
| | | @Resource |
| | | ImportRepertoryMapper importRepertoryMapper; |
| | | |
| | | @Resource |
| | | TechnologyMapper technologyMapper; |
| | | |
| | | @Resource |
| | | TechniqueMapper techniqueMapper; |
| | | |
| | | @Override |
| | | public Integer addProcessInspectionSheet(FinishedInspect finishedInspect) { |
| | | finishedInspect.setType(0); |
| | | int insert = finishedInspectMapper.insert(finishedInspect); |
| | | if (insert == 1) { |
| | | /*List<Map<String, Object>> maps = productService.selectProductList(finishedInspect.getSpecificationsId()); |
| | | inspectionItemService.insertList(finishedInspect.getId(), maps);*/ |
| | | return insert; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer inspectionConclusion(String username, Integer finishedInspectId, Integer result) { |
| | | //更新检验单里面的检验结论 |
| | | LambdaUpdateWrapper<FinishedInspect> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(FinishedInspect::getId, finishedInspectId); |
| | | updateWrapper.set(FinishedInspect::getResult, result); |
| | | finishedInspectMapper.update(new FinishedInspect(), updateWrapper); |
| | | FinishedInspect finishedInspect = finishedInspectMapper.selectById(finishedInspectId); |
| | | /*检验结论为不合格*/ |
| | | if (result == 0) { |
| | | //如果是成品的结论为不合格,需要新增成品不合格检验单 |
| | | if (finishedInspect.getType() == 0) { |
| | | /*新增成品不合格检验单*/ |
| | | InspectUnaccepted inspectUnaccepted = InspectUnaccepted.builder() |
| | | .reason(finishedInspect.getProjectName() + "不合格") //暂且定义为工程名称不合格 |
| | | .rawInspectId(finishedInspectId) |
| | | .build(); |
| | | inspectUnacceptedMapper.insert(inspectUnaccepted); |
| | | } |
| | | //如果是过程检验的结论为不合格,需要新增半成品库存且检验结果为不合格 |
| | | if (finishedInspect.getType() == 1) { |
| | | /*新增半成品(1)库存*/ |
| | | //如果入库的信息一样只有库存不一样,则在原来的库存数量上加上相应的数量 |
| | | LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Repertory::getOrderCode, finishedInspect.getOrderNumber()) |
| | | .eq(Repertory::getQualityTraceability, finishedInspect.getQualityTraceability()) |
| | | .eq(Repertory::getName, finishedInspect.getMaterial()) |
| | | .eq(Repertory::getSpecifications, finishedInspect.getSpecificationsModel()) |
| | | .eq(Repertory::getUnit, finishedInspect.getUnit()) |
| | | .eq(Repertory::getType, 1) |
| | | .eq(Repertory::getCheckResult, 0); |
| | | Repertory rep = repertoryMapper.selectOne(queryWrapper); |
| | | if (rep != null) { |
| | | rep.setNumber(rep.getNumber() + finishedInspect.getQuantity()); |
| | | rep.setUserName(username); |
| | | repertoryMapper.updateById(rep); |
| | | } else { |
| | | //如果除了库存别的信息有任何一个不一样,则新增一条半成品库存 |
| | | Repertory repertory = Repertory.builder() |
| | | .orderCode(finishedInspect.getOrderNumber()) |
| | | .qualityTraceability(finishedInspect.getQualityTraceability()) |
| | | .name(finishedInspect.getMaterial()) |
| | | .specifications(finishedInspect.getSpecificationsModel()) |
| | | .unit(finishedInspect.getUnit()) |
| | | .number(finishedInspect.getQuantity()) |
| | | .userName(username) |
| | | .type(1) |
| | | .checkResult(0)//检验结果为不合格 |
| | | .build(); |
| | | repertoryMapper.insert(repertory); |
| | | } |
| | | } |
| | | } |
| | | /*检验结论为合格*/ |
| | | if (result == 1) { |
| | | //如果是成品检验合格,,需要新增成品(0)库存和入库记录 |
| | | if (finishedInspect.getType() == 0) { |
| | | /*新增成品入库记录*/ |
| | | ImportRepertory importRepertory = ImportRepertory.builder() |
| | | .orderCode(finishedInspect.getOrderNumber()) |
| | | .qualityTraceability(finishedInspect.getQualityTraceability()) |
| | | .name(finishedInspect.getMaterial()) |
| | | .specifications(finishedInspect.getSpecificationsModel()) |
| | | .unit(finishedInspect.getUnit()) |
| | | .number(finishedInspect.getQuantity()) |
| | | .userName(username) |
| | | .build(); |
| | | importRepertoryMapper.insert(importRepertory); |
| | | /*新增成品(0)库存*/ |
| | | //如果入库的信息一样只有库存不一样,则在原来的库存数量上加上相应的数量 |
| | | LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Repertory::getOrderCode, finishedInspect.getOrderNumber()) |
| | | .eq(Repertory::getQualityTraceability, finishedInspect.getQualityTraceability()) |
| | | .eq(Repertory::getName, finishedInspect.getMaterial()) |
| | | .eq(Repertory::getSpecifications, finishedInspect.getSpecificationsModel()) |
| | | .eq(Repertory::getUnit, finishedInspect.getUnit()) |
| | | .eq(Repertory::getType, 0) |
| | | .eq(Repertory::getCheckResult, 1); |
| | | Repertory rep = repertoryMapper.selectOne(queryWrapper); |
| | | if (rep != null) { |
| | | rep.setNumber(rep.getNumber() + finishedInspect.getQuantity()); |
| | | rep.setUserName(username); |
| | | repertoryMapper.updateById(rep); |
| | | } else { |
| | | //如果除了库存别的信息有任何一个不一样,则新增一条成品库存 |
| | | Repertory repertory = Repertory.builder() |
| | | .orderCode(finishedInspect.getOrderNumber()) |
| | | .qualityTraceability(finishedInspect.getQualityTraceability()) |
| | | .name(finishedInspect.getMaterial()) |
| | | .specifications(finishedInspect.getSpecificationsModel()) |
| | | .unit(finishedInspect.getUnit()) |
| | | .number(finishedInspect.getQuantity()) |
| | | .userName(username) |
| | | .type(0) |
| | | .checkResult(1) //库存检验结果为合格 |
| | | .build(); |
| | | repertoryMapper.insert(repertory); |
| | | } |
| | | } |
| | | //如果是过程检验合格,需要新增半成品(1)库存,检验结果为合格1 |
| | | if (finishedInspect.getType() == 1) { |
| | | /*新增半成品(1)库存*/ |
| | | //如果入库的信息一样只有库存不一样,则在原来的库存数量上加上相应的数量 |
| | | LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Repertory::getOrderCode, finishedInspect.getOrderNumber()) |
| | | .eq(Repertory::getQualityTraceability, finishedInspect.getQualityTraceability()) |
| | | .eq(Repertory::getName, finishedInspect.getMaterial()) |
| | | .eq(Repertory::getSpecifications, finishedInspect.getSpecificationsModel()) |
| | | .eq(Repertory::getUnit, finishedInspect.getUnit()) |
| | | .eq(Repertory::getType, 1) |
| | | .eq(Repertory::getCheckResult, 1); |
| | | Repertory rep = repertoryMapper.selectOne(queryWrapper); |
| | | if (rep != null) { |
| | | rep.setNumber(rep.getNumber() + finishedInspect.getQuantity()); |
| | | rep.setUserName(username); |
| | | repertoryMapper.updateById(rep); |
| | | } else { |
| | | //如果除了库存别的信息有任何一个不一样,则新增一条半成品库存 |
| | | Repertory repertory = Repertory.builder() |
| | | .orderCode(finishedInspect.getOrderNumber()) |
| | | .qualityTraceability(finishedInspect.getQualityTraceability()) |
| | | .name(finishedInspect.getMaterial()) |
| | | .specifications(finishedInspect.getSpecificationsModel()) |
| | | .unit(finishedInspect.getUnit()) |
| | | .number(finishedInspect.getQuantity()) |
| | | .userName(username) |
| | | .type(1) |
| | | .checkResult(1)//检验结果为合格 |
| | | .build(); |
| | | repertoryMapper.insert(repertory); |
| | | } |
| | | } |
| | | |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<Map<String, Object>> selectFinishedInspectPage(Page<Object> page, Integer inspectResult, String inspectDate, String inspectUsername) { |
| | | return finishedInspectMapper.selectFinishedInspectPage(page, inspectResult, inspectDate, inspectUsername); |
| | | } |
| | | |
| | | //新增过程检验单-->根据订单号选择产品信息 |
| | | //新增检验单-->根据订单号选择产品信息 |
| | | @Override |
| | | public List<Map<String, Object>> chooseMater(String orderNumber) { |
| | | return finishedInspectMapper.chooseMater(orderNumber); |
| | | } |
| | | |
| | | //新增过程检验单 |
| | | //新增成品检验单 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String addProcess(String userId, FinishedInspectVo1 finishedInspectVo1) { |
| | | /*新增过程检验单*/ |
| | | public Integer addProcessInspectionSheet(String userId, FinishedInspectVo finishedInspectVo) { |
| | | /*新增成品检验单*/ |
| | | FinishedInspect finishedInspect = new FinishedInspect(); |
| | | finishedInspect.setType(1); |
| | | finishedInspect.setUserId(Integer.parseInt(userId)); |
| | | BeanUtils.copyProperties(finishedInspectVo1, finishedInspect); |
| | | finishedInspect.setOrderNumber(finishedInspectVo.getOrderNumber()); |
| | | finishedInspect.setCustomerName(finishedInspectVo.getPrname()); |
| | | finishedInspect.setProjectName(finishedInspectVo.getSname()); |
| | | finishedInspect.setQualityTraceability(finishedInspectVo.getQualityTraceability()); |
| | | finishedInspect.setUnit(finishedInspectVo.getUnit()); |
| | | finishedInspect.setQuantity(finishedInspectVo.getQuantity()); |
| | | finishedInspect.setSpecificationsModel(finishedInspectVo.getSpecificationsModel()); |
| | | finishedInspect.setMaterial(finishedInspectVo.getMaterial()); |
| | | finishedInspect.setMaterialCode(finishedInspectVo.getMcode()); |
| | | finishedInspectMapper.insert(finishedInspect); |
| | | /*批量新增过程检验项目表*/ |
| | | /*批量新增成品检验项目单*/ |
| | | //获取型号id |
| | | Integer specificationId = getSpecificationId(finishedInspectVo1.getMaterial(), finishedInspectVo1.getMaterialCode(), finishedInspectVo1.getSpecificationsModel()); |
| | | //查询标准BOM技术指标中该型号工艺下最新版本的检验项目 |
| | | Integer ver = productService.selectVerByPro(specificationId).get(0);//该型号下技术指标最新版本 |
| | | List<Product> productList = productService.selProByVerSpe(finishedInspectVo1.getTechnologyId(), ver); |
| | | //Integer specificationId = getSpecificationId(finishedInspectVo.getMaterial(), finishedInspectVo.getMcode(), finishedInspectVo.getSpecificationsModel()); |
| | | //根据生产订单id查询编制工序的最后一道工艺 |
| | | List<ManualTechnology> manualTechnologyList = manualTechnologyMapper.selAllByMoId(finishedInspectVo.getId()); |
| | | //获取最后一道工艺关联的工艺路线id |
| | | Integer technologyId = manualTechnologyList.get(0).getTechnologyId(); |
| | | /*//查询标准BOM技术指标中该型号工艺下最新版本的检验项目 |
| | | Integer ver = productService.selectVerByPro(specificationId).get(0);//该型号下技术指标最新版本*/ |
| | | List<Product> productList = productService.selProByVerSpe(technologyId); |
| | | List<InspectionItem> inspectionItemList = productList.stream().map(product -> { |
| | | InspectionItem inspectionItem = new InspectionItem(); |
| | | BeanUtils.copyProperties(product, inspectionItem); |
| | | inspectionItem.setFinishInspectId(finishedInspect.getId()); |
| | | //如果新增时还填写了检验值则要进行判断检验结果 |
| | | if (ObjectUtils.isNotEmpty(finishedInspectVo1.getInspectionValue())) { |
| | | inspectionItem.setInspectionValue(finishedInspectVo1.getInspectionValue()); |
| | | //判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格0 |
| | | String required = product.getRequired();//标准值 |
| | | String internal = product.getInternal();//内控值 |
| | | String testValue = finishedInspectVo1.getInspectionValue();//检测值 |
| | | List<Integer> list = Arrays.stream(testValue.split(",")).map(s -> { |
| | | int values = checkValues(required, internal, s); |
| | | return values; |
| | | }).collect(Collectors.toList()); |
| | | if (list.contains(0)) { |
| | | //如果其中一个检验值不合格则该项目检验不合格 |
| | | inspectionItem.setResult(0); |
| | | } else { |
| | | inspectionItem.setResult(1); |
| | | } |
| | | inspectionItem.setUsername(userMapper.selectById(userId).getName()); |
| | | } |
| | | inspectionItem.setId(null); |
| | | inspectionItem.setCreateTime(new Date()); |
| | | inspectionItem.setUpdateTime(new Date()); |
| | | inspectionItem.setInspectId(finishedInspect.getId()); |
| | | inspectionItem.setType(2);//成品 |
| | | return inspectionItem; |
| | | }).collect(Collectors.toList()); |
| | | inspectionItemService.saveBatch(inspectionItemList); |
| | | return "新增过程检验单"+finishedInspect.getId()+"成功!"; |
| | | return finishedInspect.getId(); |
| | | } |
| | | |
| | | //新增过程检验单-->选择设备 |
| | | //上报(更新检验状态) |
| | | @Override |
| | | public List<Map<String, Object>> chooseDev(Integer technologyId, String father, String name) { |
| | | //该工艺id下生产工艺最新版本 |
| | | Integer ver = techniqueMapper.selectVerByTeId(technologyId).get(0); |
| | | return techniqueMapper.selDevByVerTecIdFaNam(technologyId,father,name,ver); |
| | | } |
| | | |
| | | |
| | | /*根据样品名称,样品编号,型号规格获取型号id*/ |
| | | private Integer getSpecificationId(String name, String mcode, String specification) { |
| | | //获取物料id |
| | | Material material = materialMapper.selectOne(Wrappers.<Material>query() |
| | | .eq("name", name) |
| | | .eq("code", mcode)); |
| | | if (Objects.isNull(material)) { |
| | | return null; |
| | | } |
| | | //获取规格名称和型号名称 |
| | | String[] split = specification.split("-"); |
| | | String stName = split[0]; |
| | | String spName = split[1]; |
| | | //获取规格id |
| | | Standard standard = standardService.getOne(Wrappers.<Standard>query() |
| | | .eq("name", stName) |
| | | .eq("material_id", material.getId())); |
| | | //获取型号id |
| | | Specifications specifications = specificationsService.getOne(Wrappers.<Specifications>query() |
| | | .eq("name", spName) |
| | | .eq("standard_id", standard.getId())); |
| | | return specifications.getId(); |
| | | } |
| | | |
| | | /*判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格*/ |
| | | private int checkValues(String standardValueStr, String controlValueStr, String detectionValueStr) { |
| | | boolean isStandardValueSatisfied = isValueSatisfied(standardValueStr, detectionValueStr); |
| | | boolean isControlValueSatisfied = isValueSatisfied(controlValueStr, detectionValueStr); |
| | | |
| | | if (isStandardValueSatisfied && isControlValueSatisfied) { |
| | | return 1; |
| | | } else { |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | private boolean isValueSatisfied(String valueStr, String detectionValueStr) { |
| | | String substring = valueStr.substring(1, 2); |
| | | if (substring.equals("=")) { |
| | | String operator = valueStr.substring(0, 2); |
| | | Double standardValue = Double.parseDouble(valueStr.substring(2)); |
| | | Double detectionValue = Double.parseDouble(detectionValueStr); |
| | | switch (operator) { |
| | | case ">=": |
| | | return detectionValue >= standardValue; |
| | | case "<=": |
| | | return detectionValue <= standardValue; |
| | | default: |
| | | return false; |
| | | } |
| | | } else { |
| | | String operator = valueStr.substring(0, 1); |
| | | Double standardValue = Double.parseDouble(valueStr.substring(1)); |
| | | Double detectionValue = Double.parseDouble(detectionValueStr); |
| | | switch (operator) { |
| | | case ">": |
| | | return detectionValue > standardValue; |
| | | case "≥": |
| | | return detectionValue >= standardValue; |
| | | case "≤": |
| | | return detectionValue <= standardValue; |
| | | case "<": |
| | | return detectionValue < standardValue; |
| | | case "=": |
| | | return detectionValue.equals(standardValue); |
| | | default: |
| | | return false; |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String updateFinishInspectsById(String username,Integer id) { |
| | | /*更新检验单里面的检验结论*/ |
| | | //先判断检验结果 |
| | | List<Integer> results = inspectionItemMapper.getResult(id,1); |
| | | int count = 0; |
| | | for (Integer result : results) { |
| | | if (result != null && result == 1) { |
| | | count++; |
| | | } |
| | | } |
| | | FinishedInspect finishedInspect = finishedInspectMapper.selectById(id); |
| | | //如果检验项目中的结论包含不合格则检验单不合格 |
| | | if (results.contains(0)) { |
| | | finishedInspect.setResult(0);//不合格 |
| | | //更新检验单 |
| | | finishedInspectMapper.updateById(finishedInspect); |
| | | } else if (count == results.size()) { |
| | | finishedInspect.setResult(1);//合格 |
| | | finishedInspectMapper.updateById(finishedInspect); |
| | | } else return "项目未检验完!"; |
| | | /*如果检验结论为不合格,则需要新增不合格检验单*/ |
| | | if (finishedInspect.getResult() == 0) { |
| | | InspectUnaccepted finishUnaccepted = InspectUnaccepted.builder() |
| | | .reason(finishedInspect.getMaterial() + "不合格") //暂且定义为产品名称不合格 |
| | | .rawInspectId(id) |
| | | .type(1) //类型为成品检验 |
| | | .build(); |
| | | inspectUnacceptedMapper.insert(finishUnaccepted); |
| | | } |
| | | /*如果检验结论为合格,则需要新增半成品库存*/ |
| | | if (finishedInspect.getResult() == 1) { |
| | | //如果入库的信息一样只有库存不一样,则在原来的库存数量上加上相应的数量 |
| | | LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Repertory::getOrderCode, finishedInspect.getOrderNumber()) |
| | | .eq(Repertory::getQualityTraceability, finishedInspect.getQualityTraceability()) |
| | | .eq(Repertory::getName, finishedInspect.getMaterial()) |
| | | .eq(Repertory::getSpecifications, finishedInspect.getSpecificationsModel()) |
| | | .eq(Repertory::getUnit, finishedInspect.getUnit()) |
| | | .eq(Repertory::getType, 1); |
| | | Repertory rep = repertoryMapper.selectOne(queryWrapper); |
| | | if (rep != null ) { |
| | | rep.setNumber(rep.getNumber() + finishedInspect.getQuantity()); |
| | | rep.setUserName(username); |
| | | repertoryMapper.updateById(rep); |
| | | } else { |
| | | //如果除了库存别的信息有任何一个不一样,则新增一条成品库存 |
| | | Repertory repertory = new Repertory(); |
| | | repertory.setOrderCode(finishedInspect.getOrderNumber()); |
| | | repertory.setQualityTraceability(finishedInspect.getQualityTraceability()); |
| | | repertory.setName(finishedInspect.getMaterial()); |
| | | repertory.setSpecifications(finishedInspect.getSpecificationsModel()); |
| | | repertory.setUnit(finishedInspect.getUnit()); |
| | | repertory.setNumber(finishedInspect.getQuantity()); |
| | | repertory.setUserName(username); |
| | | repertory.setType(1);//半成品 |
| | | repertory.setCheckResult(1);//暂定不删 |
| | | repertoryMapper.insert(repertory); |
| | | } |
| | | } |
| | | return "上报成功!"; |
| | | } |
| | | |
| | | //分页查询成品检验单列表 |
| | | @Override |
| | | public IPage<Map<String, Object>> selectFinishedInspectPage(Page<Object> page, Integer result, String material) { |
| | | return finishedInspectMapper.selectFinishedInspectPage(page, result,material); |
| | | } |
| | | |
| | | //根据检验单id查询成品检验单详情 |
| | | @Override |
| | | public List<Map<String, Object>> selectFinishInspectsListById(Integer id) { |
| | | return finishedInspectMapper.selectFinishInspectsListById(id); |
| | | } |
| | | |
| | | |
| | | } |