package com.yuanchu.limslaboratory.service.impl; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.yuanchu.limslaboratory.mapper.InspectionProductMapper; import com.yuanchu.limslaboratory.pojo.InspectionProduct; import com.yuanchu.limslaboratory.pojo.vo.InsProductVo; import com.yuanchu.limslaboratory.service.InspectionProductService; import org.springframework.stereotype.Service; import javax.annotation.Resource; /** * 申请单下物料中的项目(InspectionProduct)表服务实现类 * * @author zss * @since 2023-08-03 13:04:54 */ @Service public class InspectionProductServiceImpl extends ServiceImpl implements InspectionProductService { @Resource InspectionProductMapper inspectionProductMapper; //更新检验项目 @Override public boolean updateInsProduct(Integer userId, InspectionProduct inspectionProduct) { //赋值检验员id inspectionProduct.setUserId(userId); //判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格0 String testValue = inspectionProduct.getTestValue();//检验值 String required = inspectionProduct.getRequired();//标准值 String internal = inspectionProduct.getInternal();//内控值 inspectionProduct.setTestState(checkValues(required, internal, testValue)); //根据检验项目名和关联的检验物料id来查询检验项目的数据 LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(InspectionProduct::getInspectionMaterialId, inspectionProduct.getInspectionMaterialId()) .eq(InspectionProduct::getName, inspectionProduct.getName()); inspectionProductMapper.update(inspectionProduct, updateWrapper); return true; } /*判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格*/ 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; } } } }