package com.yuanchu.limslaboratory.service.impl;
|
|
|
import cn.hutool.core.date.DateUtil;
|
import com.yuanchu.limslaboratory.mapper.*;
|
import com.yuanchu.limslaboratory.pojo.Inspection;
|
import com.yuanchu.limslaboratory.pojo.InspectionProduct;
|
import com.yuanchu.limslaboratory.pojo.NonConformanceReview;
|
import com.yuanchu.limslaboratory.pojo.Report;
|
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.time.LocalDateTime;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 服务实现类
|
* </p>
|
*
|
* @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;
|
|
@Resource
|
InspectionMaterialMapper inspectionMaterialMapper;
|
|
@Resource
|
LinkDetectionMapper linkDetectionMapper;
|
|
@Resource
|
private NonConformanceReviewMapper nonConformanceReviewMapper;
|
|
//查询检验计划
|
@Override
|
public List<Map<String, Object>> selectAllPlan(String code, String beginTime, String endTime, Integer status) {
|
return planMapper.selectAllPlan(code, beginTime, endTime, status);
|
}
|
|
//分配-->选择检验人
|
@Override
|
public List<Map<String, Object>> choosecheck() {
|
return userMapper.selectUser();
|
}
|
|
//分配-->选择设备
|
@Override
|
public List<Map<String, Object>> 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 Integer check(Integer id, String value) {
|
InspectionProduct inspectionProduct = inspectionProductMapper.selectById(id);
|
//判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格0
|
String required = inspectionProduct.getRequired();//标准值
|
String internal = inspectionProduct.getInternal();//内控值
|
inspectionProduct.setTestValue(value);
|
List<Integer> list = Arrays.stream(value.split(",")).map(s -> {
|
int values = checkValues(required, internal, s);
|
return values;
|
}).collect(Collectors.toList());
|
if (list.contains(0)) {
|
//如果其中一个检验值不合格则该项目检验不合格
|
inspectionProduct.setTestState(0);
|
}else {
|
inspectionProduct.setTestState(1);
|
}
|
inspectionProductMapper.updateById(inspectionProduct);
|
return inspectionProduct.getTestState();
|
}
|
|
//上报
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public String reported(Integer id) {
|
/*更新检验单里面的检验结论*/
|
//先判断检验结果
|
List<Integer> 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);
|
//添加不合格信息到评审
|
NonConformanceReview nonConformanceReview = new NonConformanceReview();
|
LocalDateTime localDateTime = DateUtil.toLocalDateTime(DateUtil.date());
|
nonConformanceReview.setCreatedTime(localDateTime);
|
nonConformanceReview.setUpdatedTime(localDateTime);
|
} 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;
|
}
|
}
|
}
|
}
|