| | |
| | | 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.ImportRepertoryMapper; |
| | | import com.yuanchu.mom.mapper.InspectUnacceptedMapper; |
| | | import com.yuanchu.mom.mapper.RepertoryMapper; |
| | | import com.yuanchu.mom.pojo.FinishedInspect; |
| | | import com.yuanchu.mom.mapper.FinishedInspectMapper; |
| | | import com.yuanchu.mom.pojo.ImportRepertory; |
| | | import com.yuanchu.mom.pojo.InspectUnaccepted; |
| | | import com.yuanchu.mom.pojo.Repertory; |
| | | import com.yuanchu.mom.service.FinishedInspectService; |
| | | import com.yuanchu.mom.mapper.*; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.pojo.vo.FinishedInspectVo1; |
| | | import com.yuanchu.mom.service.*; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yuanchu.mom.service.InspectionItemService; |
| | | import com.yuanchu.mom.service.ProductService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | private FinishedInspectMapper finishedInspectMapper; |
| | | |
| | | @Resource |
| | | MaterialMapper materialMapper; |
| | | |
| | | @Resource |
| | | StandardService standardService; |
| | | |
| | | @Resource |
| | | SpecificationsService specificationsService; |
| | | |
| | | @Resource |
| | | InspectionItemService inspectionItemService; |
| | | |
| | | @Autowired |
| | | private ProductService productService; |
| | | |
| | | @Autowired |
| | | private InspectionItemService inspectionItemService; |
| | | @Resource |
| | | UserMapper userMapper; |
| | | |
| | | @Resource |
| | | InspectUnacceptedMapper inspectUnacceptedMapper; |
| | |
| | | @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); |
| | | /*List<Map<String, Object>> maps = productService.selectProductList(finishedInspect.getSpecificationsId()); |
| | | inspectionItemService.insertList(finishedInspect.getId(), maps);*/ |
| | | return insert; |
| | | } |
| | | return 0; |
| | |
| | | } |
| | | } |
| | | //如果是过程检验合格,需要新增半成品(1)库存,检验结果为合格1 |
| | | if (finishedInspect.getType()==1) { |
| | | if (finishedInspect.getType() == 1) { |
| | | /*新增半成品(1)库存*/ |
| | | //如果入库的信息一样只有库存不一样,则在原来的库存数量上加上相应的数量 |
| | | LambdaQueryWrapper<Repertory> queryWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | 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) { |
| | | /*新增过程检验单*/ |
| | | FinishedInspect finishedInspect = new FinishedInspect(); |
| | | finishedInspect.setType(1); |
| | | finishedInspect.setUserId(Integer.parseInt(userId)); |
| | | BeanUtils.copyProperties(finishedInspectVo1, finishedInspect); |
| | | 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); |
| | | 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()); |
| | | } |
| | | return inspectionItem; |
| | | }).collect(Collectors.toList()); |
| | | inspectionItemService.saveBatch(inspectionItemList); |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |