package com.yuanchu.mom.service.impl; import com.yuanchu.mom.mapper.InspectionItemMapper; import com.yuanchu.mom.mapper.TechniqueMapper; import com.yuanchu.mom.pojo.InspectionItem; import com.yuanchu.mom.pojo.dto.InspectionItemDto; import com.yuanchu.mom.pojo.dto.UpdateInspectionItemDto; import com.yuanchu.mom.service.DeviceService; import com.yuanchu.mom.service.InspectionItemService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** *

* 服务实现类 *

* * @author 江苏鵷雏网络科技有限公司 * @since 2023-08-01 */ @Service public class InspectionItemServiceImpl extends ServiceImpl implements InspectionItemService { @Resource private InspectionItemMapper inspectionItemMapper; @Resource TechniqueMapper techniqueMapper; //新增按钮-->2、查询所有检验项目 @Override public List selectInspectionItem(Integer id, Integer type) { return inspectionItemMapper.selectInspectionItem(id,type); } //新增过程检验单-->选择设备 @Override public List> chooseDev(Integer technologyId, String father, String name) { //该工艺id下生产工艺最新版本 Integer ver = techniqueMapper.selectVerByTeId(technologyId).get(0); return techniqueMapper.selDevByVerTecIdFaNam(technologyId, father, name, ver); } //新增按钮-->2、检验项目-->失去焦点发起该请求 @Override public Integer addProcessInspectionSheet(String username, UpdateInspectionItemDto updateInspectionItemDto) { //查询内控值和标准值 InspectionItem inspectionItem = inspectionItemMapper.selectById(updateInspectionItemDto.getInspectionItemId()); inspectionItem.setInspectionValue(updateInspectionItemDto.getInspectionValue()); inspectionItem.setDeviceId(updateInspectionItemDto.getDeviceId()); List list = Arrays.stream( updateInspectionItemDto.getInspectionValue().split(",")).map(s -> { int values = checkValues(inspectionItem.getRequired(), inspectionItem.getInternal(), s); return values; }).collect(Collectors.toList()); if (list.contains(0)) { //如果其中一个检验值不合格则该项目检验不合格 inspectionItem.setResult(0); } else { inspectionItem.setResult(1); } inspectionItemMapper.updateById(inspectionItem); //返回检验项目的结论 return inspectionItem.getResult(); } /*判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格*/ 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.equals(standardValue); case "≥": return detectionValue >= standardValue; case "≤": return detectionValue <= standardValue; default: return false; } } } }