package com.yuanchu.limslaboratory.service.impl; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.yuanchu.limslaboratory.mapper.*; import com.yuanchu.limslaboratory.pojo.*; import com.yuanchu.limslaboratory.service.PlanService; import com.yuanchu.limslaboratory.utils.MyUtil; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; import java.util.Map; /** *

* 服务实现类 *

* * @author 江苏鵷雏网络科技有限公司 * @since 2023-08-09 */ @Service public class PlanServiceImpl implements PlanService { @Resource private PlanMapper planMapper; @Resource InspectionProductMapper inspectionProductMapper; @Resource UserMapper userMapper; @Resource InstrumentMapper instrumentMapper; @Resource ReportMapper reportMapper; @Resource InspectionMapper inspectionMapper; //查询检验计划 @Override public List> selectAllPlan(String code, String beginTime, String endTime, Integer status) { return planMapper.selectAllPlan(code, beginTime, endTime, status); } //分配-->选择检验人 @Override public List> choosecheck() { return userMapper.selectUser(); } //分配-->选择设备 @Override public List> chooseinstum() { return instrumentMapper.chooseinstum(); } //分配人员与设备 @Override public String distribution(Integer id, Integer userId, Integer instrumentId) { InspectionProduct inspectionProduct = new InspectionProduct(); inspectionProduct.setId(id); //执行人 inspectionProduct.setUserId(userId); inspectionProduct.setInstrumentId(instrumentId); inspectionProductMapper.updateById(inspectionProduct); return "分配完成!"; } //检验 @Override @Transactional(rollbackFor = Exception.class) public String check(Integer id, String value) { //如果检验值不为空 if (StringUtils.isNotBlank(value)) { InspectionProduct inspectionProduct = inspectionProductMapper.selectById(id); //判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格0 String required = inspectionProduct.getRequired();//标准值 String internal = inspectionProduct.getInternal();//内控值 inspectionProduct.setTestValue(value); inspectionProduct.setTestState(checkValues(required, internal, value)); inspectionProductMapper.updateById(inspectionProduct); } else { //如果检验值为空,将原有的检验结论覆盖为null inspectionProductMapper.upda(id); } return "提交成功!"; } //上报 @Override @Transactional(rollbackFor = Exception.class) public String reported(Integer id) { /*更新检验单里面的检验结论*/ //先判断检验结果 List results = inspectionProductMapper.getresult(id); int count = 0; for (Integer result : results) { if (result != null && result==1) { count++; } } //如果检验项目中的结论包含不合格则检验单不合格 if (results.contains(0)) { Inspection inspection = new Inspection(); inspection.setId(id); inspection.setInspectionStatus(0); inspectionMapper.updateById(inspection); } else if (count == results.size()) { Inspection inspection = new Inspection(); inspection.setId(id); inspection.setInspectionStatus(1); inspectionMapper.updateById(inspection); } else return "项目未检验完!"; //生成报告单 Report report = new Report(); //生成报告单号 String recode = MyUtil.getTimeSixNumberCode("BG", "BG"); //获取检验结论 String conclusion = ""; Inspection inspection = inspectionMapper.selectById(id); if (inspection.getInspectionStatus().equals(1)) { conclusion = "合格"; } else { conclusion = "不合格"; } report.setCode(recode); report.setStatus(0); report.setConclusion(conclusion); report.setInspectionId(id); reportMapper.insert(report); return "上报成功!"; } /*判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格*/ 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; } } } }