| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import cn.hutool.extra.qrcode.BufferedImageLuminanceSource; |
| | | 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.google.zxing.*; |
| | | import com.google.zxing.common.HybridBinarizer; |
| | | import com.yuanchu.mom.mapper.*; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.pojo.vo.RawInsProductVo; |
| | | import com.yuanchu.mom.pojo.vo.RawInspectVo; |
| | | import com.yuanchu.mom.service.*; |
| | | import com.yuanchu.mom.utils.MyUtil; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.imageio.ImageIO; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Resource |
| | | InspectUnacceptedMapper inspectUnacceptedMapper; |
| | | |
| | | @Resource |
| | | UserMapper userMapper; |
| | | |
| | | //新增原材料检验单 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String addRawInspects(String userId, RawInspectVo rawInspectVo) throws Exception { |
| | | //报检人(新增检验单的人) |
| | | rawInspectVo.setUserName(userMapper.selectById(userId).getName()); |
| | | //校验标准值,内控值格式 |
| | | List<RawInsProductVo> rawInsProductVos = rawInspectVo.getRawInsProducts(); |
| | | /*for (RawInsProductVo rawInsProductVo : rawInsProductVos) { |
| | | char internal = rawInsProductVo.getInternal().charAt(0); |
| | | char required = rawInsProductVo.getRequired().charAt(0); |
| | | if (internal != '>' && internal != '<' && internal != '=') { |
| | | return "内控值输入格式有问题!"; |
| | | } |
| | | if (required != '>' && required != '<' && required != '=') { |
| | | return "标准值输入格式有问题!"; |
| | | } |
| | | }*/ |
| | | /*新增原材料检验单*/ |
| | | RawInspect rawInspect = new RawInspect(); |
| | | BeanUtils.copyProperties(rawInspectVo, rawInspect); |
| | | rawInspectMapper.insert(rawInspect); |
| | | /*新增原材料检验项目单*/ |
| | | List<RawInsProduct> rawInsProductList = rawInsProductVos.stream().map(rawInsProVo -> { |
| | | RawInsProduct rawInsProduct = new RawInsProduct(); |
| | | BeanUtils.copyProperties(rawInsProVo, rawInsProduct); |
| | | if (ObjectUtils.isNotEmpty(rawInsProduct.getTestValue())) { |
| | | if (rawInsProduct.getTestValue().equals("过")) { |
| | | rawInsProduct.setTestState(1); |
| | | } else if (rawInsProduct.getTestValue().equals("不过")) { |
| | | rawInsProduct.setTestState(0); |
| | | } else { |
| | | //判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格0 |
| | | String required = rawInsProduct.getRequired();//标准值 |
| | | String internal = rawInsProduct.getInternal();//内控值 |
| | | String testValue = rawInsProduct.getTestValue();//检测值 |
| | | List<Integer> list = Arrays.stream(testValue.split(",")).map(s -> { |
| | | int values = checkValues(required, internal, s); |
| | | return values; |
| | | }).collect(Collectors.toList()); |
| | | if (list.contains(0)) { |
| | | //如果其中一个检验值不合格则该项目检验不合格 |
| | | rawInsProduct.setTestState(0); |
| | | } else { |
| | | rawInsProduct.setTestState(1); |
| | | } |
| | | } |
| | | rawInsProduct.setUserId(Integer.parseInt(userId)); |
| | | } |
| | | rawInsProduct.setRawInspectId(rawInspect.getId()); |
| | | return rawInsProduct; |
| | | }).collect(Collectors.toList()); |
| | | //检验项目批量添加 |
| | | rawInsProductService.saveBatch(rawInsProductList); |
| | | return rawInspect.getId().toString(); |
| | | } |
| | | |
| | | |
| | | //分页查询原材料检验单列表 |
| | | @Override |
| | |
| | | |
| | | //根据检验单id查询原材料检验单详情 |
| | | @Override |
| | | public List<Map<String, Object>> selectRawInspectsListById(Integer id) { |
| | | public Map<String, Object> selectRawInspectsListById(Integer id) { |
| | | return rawInspectMapper.selectRawInspectsListById(id); |
| | | } |
| | | |
| | |
| | | RawInspect rawInspect = new RawInspect(); |
| | | rawInspect.setId(id); |
| | | rawInspect.setInsState(1); |
| | | rawInspect.setInsTime(new Date()); |
| | | //如果检验项目中的结论包含不合格则检验单不合格 |
| | | if (results.contains(0)) { |
| | | rawInspect.setJudgeState(0); |
| | |
| | | } |
| | | |
| | | |
| | | //新增原材料检验单 |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String addRawInspects(String userName, RawInspectVo rawInspectVo) { |
| | | //报检人(新增检验单的人) |
| | | rawInspectVo.setUserName(userName); |
| | | //校验标准值,内控值格式 |
| | | List<RawInsProductVo> rawInsProductVos = rawInspectVo.getRawInsProducts(); |
| | | for (RawInsProductVo rawInsProductVo : rawInsProductVos) { |
| | | char internal = rawInsProductVo.getInternal().charAt(0); |
| | | char required = rawInsProductVo.getRequired().charAt(0); |
| | | if (internal != '>' && internal != '<' && internal != '=') { |
| | | if (required != '>' && required != '<' && required != '=') { |
| | | return "标准值输入格式有问题!"; |
| | | } |
| | | return "内控值输入格式有问题!"; |
| | | /*判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格*/ |
| | | private int checkValues(String standardValueStr, String controlValueStr, String detectionValueStr) { |
| | | double standVar = Double.parseDouble(standardValueStr); |
| | | double controlVar = Double.parseDouble(controlValueStr); |
| | | double detecVar = Double.parseDouble(detectionValueStr); |
| | | double a = standVar + controlVar; |
| | | double b = standVar - controlVar; |
| | | if (detecVar >= b && detecVar <= a) { |
| | | return 1; |
| | | } |
| | | return 0; |
| | | /*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; |
| | | } |
| | | } |
| | | /*新增原材料检验单*/ |
| | | RawInspect rawInspect = new RawInspect(); |
| | | BeanUtils.copyProperties(rawInspectVo, rawInspect); |
| | | rawInspectMapper.insert(rawInspect); |
| | | /*新增原材料检验项目单*/ |
| | | List<RawInsProduct> rawInsProductList = rawInsProductVos.stream().map(rawInsProVo -> { |
| | | RawInsProduct rawInsProduct = new RawInsProduct(); |
| | | BeanUtils.copyProperties(rawInsProVo, rawInsProduct); |
| | | rawInsProduct.setRawInspectId(rawInspect.getId()); |
| | | return rawInsProduct; |
| | | }).collect(Collectors.toList()); |
| | | //检验项目批量添加 |
| | | rawInsProductService.saveBatch(rawInsProductList); |
| | | return "新增检验单成功!"; |
| | | } |
| | | } |
| | | |