diff --git a/lab-service/lab-lims/src/main/java/org/springblade/lims/controller/ExamineResultController.java b/lab-service/lab-lims/src/main/java/org/springblade/lims/controller/ExamineResultController.java index 16f8ea9..762c885 100644 --- a/lab-service/lab-lims/src/main/java/org/springblade/lims/controller/ExamineResultController.java +++ b/lab-service/lab-lims/src/main/java/org/springblade/lims/controller/ExamineResultController.java @@ -2,6 +2,7 @@ package org.springblade.lims.controller; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; @@ -816,6 +817,576 @@ public class ExamineResultController extends BladeController { return R.data(map1); } + /** + * 常规Excel解析数据 + */ + private R>>>> ptExcel1( + MultipartFile file, + String examineId, + String infoStr, //变量对应的标版的孔位,一行行的逐渐递增 + String reg //计算公式 + ) throws Exception { + List read = ExcelUtil.read(file, ExamineExcel.class); + Map> map = new HashMap<>(); + // 组数 + int group = 0; + // 除9是否有余数 + int size = (read.size() + 1) % 9; + if (size == 0) { + group = (read.size() + 1) / 9; + } else { + group = (read.size() + 1) / 9 + 1; + } + + for (int i = 0; i < group; i++) { + List excels = new ArrayList<>(); + for (int j = i * 8 + i; j < (i + 1) * 8 + i; j++) { + ExamineExcel excel = read.get(j); + excels.add(excel); + } + map.put((i + 1) + "", excels); + } + + Examine examine = examineService.getById(examineId); + String experieNum = examine.getExperieNum(); + String[] split = experieNum.split(","); + + List> list = new ArrayList<>(); + // 按照公式计算实验数据并返回 + Map>>> map1 = new HashMap<>(); + + for (int i = 0; i < group; i++) { + List>> mapList = new ArrayList<>(); + List excels = map.get(i + 1 + ""); + +// double code1 = Double.parseDouble(excels.get(0).getCode1()); +// double code2 = Double.parseDouble(excels.get(1).getCode1()); +// double code3 = Double.parseDouble(excels.get(2).getCode1()); +// double code4 = Double.parseDouble(excels.get(3).getCode1()); +// double v1 = (code1 + code2) / 2; +// double v2 = (code3 + code4) / 2; + //按照列循环每一版的数据 + + DecimalFormat df = new DecimalFormat("#0.000"); + //解析info,确定参数x的值和其它相对不变的参数 + Map params = new HashMap<>(); //存放解析出的参数 + Integer xStart = 0; + Integer xEnd = 0; + //解析参数 + + Map info = JSON.parseObject(infoStr, new TypeReference>() { + }); + // 测试假数据 +// reg = "(x-((x1+x2)/2))/(((x3+x4)/2)-(((x1+x2)/2)))"; +// Map info = new HashMap<>(); +// info.put("x1", "1"); +// info.put("x2", "2"); +// info.put("x3", "3"); +// info.put("x4", "4"); +// info.put("x", "7-96"); + + Set strings = info.keySet(); + String x = ""; + for (String s : strings) { + String para = info.get(s); + if (para.split("-").length > 1) {//可变参数 + String[] xs = para.split("-"); + xStart = Integer.parseInt(xs[0]); + xEnd = Integer.parseInt(xs[1]); + x = s; + } else {//相对固定的参数 + Integer order = Integer.valueOf(para); + params.put(s, StringUtil.isBlank(getCode(excels, order)) ? "0" : getCode(excels, order)); + } + } + + for (int j = 0; j < excels.size(); j++) { + // 行标头:前端渲染需要A、B、C.... + String a = String.valueOf((char) (j + 65)); + + ExamineExcel examineExcel = excels.get(j);//取到一行记录 + int filedsLength = examineExcel.getClass().getDeclaredFields().length - 1; + + Map> map2 = new HashMap<>(); + for (int n = 1; n <= filedsLength; n++) { + System.out.println(n); + String code; + switch (n) { + case 1: + code = examineExcel.getCode1(); + break; + case 2: + code = examineExcel.getCode2(); + break; + case 3: + code = examineExcel.getCode3(); + break; + case 4: + code = examineExcel.getCode4(); + break; + case 5: + code = examineExcel.getCode5(); + break; + case 6: + code = examineExcel.getCode6(); + break; + case 7: + code = examineExcel.getCode7(); + break; + case 8: + code = examineExcel.getCode8(); + break; + case 9: + code = examineExcel.getCode9(); + break; + case 10: + code = examineExcel.getCode10(); + break; + case 11: + code = examineExcel.getCode11(); + break; + case 12: + code = examineExcel.getCode12(); + break; + default: + code = "0"; + } + Map mapResult = new HashMap<>(); + int index = (n - 1) * 8 + j + 1; //n是列,j是行 ,我们定义index是一列列的定义 + System.out.println("code的值==" + code + ",列n ==" + n + ",行m=" + j); + System.out.println("-------------------"); + if (StringUtil.isNoneBlank(code)) { + if (xStart <= index && index <= xEnd) { + params.put(x, code); + String value = FormulaTool.getResult(reg, params); + System.out.println(value); + String format = df.format(Double.parseDouble(value)); + mapResult.put("originResult", examineExcel.getCode1()); + mapResult.put("value", "0E-10".equals(format) ? "0" : format); + mapResult.put("num", "1"); + if (Double.parseDouble(format) >= 0.4) { + mapResult.put("result", "阳性"); + } else { + mapResult.put("result", "阴性"); + } + } + } else { + if (xStart <= index && index <= xEnd) { + mapResult.put("originResult", ""); + mapResult.put("num", ""); + } + } + mapResult.put("order", index + i * 96); + map2.put(a + n, mapResult); + list.add(mapResult); + } +// int u = 1; +// String SP = "0.00"; +// if (j > 5) { +// if (excels.get(j).getCode1() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode1()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode1()); +// map3.put("value", SP); +//// int b = (i * 90) + j - 6; +// int b = (i * 96) + j; +//// map3.put("num", split[b - ((i + 1) * 6)]); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 1, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j; +// map3.put("order", b + 1); +// map3.put("num", ""); +// map2.put(a + 1, map3); +// list.add(map3); +// } +// } else { +// if (excels.get(j).getCode1() != null) { +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode1()); +// int b = (i * 96) + j; +// map3.put("order", b + 1); +// map2.put(a + 1, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j; +// map3.put("order", b + 1); +// map3.put("num", ""); +// map2.put(a + 1, map3); +// list.add(map3); +// } +// } +// if (excels.get(j).getCode2() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode2()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode2()); +// map3.put("value", SP); +//// int b = (i * 90) + j + 2 + (u * 8); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 2, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 2, map3); +// list.add(map3); +// } +// if (excels.get(j).getCode3() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode3()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode3()); +// map3.put("value", SP); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 3, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 3, map3); +// list.add(map3); +// } +// if (excels.get(j).getCode4() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode4()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode4()); +// map3.put("value", SP); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 4, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 4, map3); +// list.add(map3); +// } +// if (excels.get(j).getCode5() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode5()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode5()); +// map3.put("value", SP); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 5, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 5, map3); +// list.add(map3); +// } +// if (excels.get(j).getCode6() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode6()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode6()); +// map3.put("value", SP); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 6, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 6, map3); +// list.add(map3); +// } +// if (excels.get(j).getCode7() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode7()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode7()); +// map3.put("value", SP); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 7, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 7, map3); +// list.add(map3); +// } +// if (excels.get(j).getCode8() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode8()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode8()); +// map3.put("value", SP); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 8, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 8, map3); +// list.add(map3); +// } +// if (excels.get(j).getCode9() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode9()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode9()); +// map3.put("value", SP); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 9, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 9, map3); +// list.add(map3); +// } +// if (excels.get(j).getCode10() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode10()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode10()); +// map3.put("value", SP); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 10, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 10, map3); +// list.add(map3); +// } +// if (excels.get(j).getCode11() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode11()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode11()); +// map3.put("value", SP); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 11, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 11, map3); +// list.add(map3); +// } +// if (excels.get(j).getCode12() != null) { +// if ((v2 - v1) != 0) { +// SP = df.format((Double.parseDouble(excels.get(j).getCode12()) - v1) / (v2 - v1)); +// } +// Map map3 = new HashMap<>(); +// map3.put("originResult", excels.get(j).getCode12()); +// map3.put("value", SP); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", "1"); +// map3.put("order", b + 1); +// u++; +// if (Double.parseDouble(SP) >= 0.4) { +// map3.put("result", "阳性"); +// } else { +// map3.put("result", "阴性"); +// } +// map2.put(a + 12, map3); +// list.add(map3); +// } else { +// Map map3 = new HashMap<>(); +// map3.put("originResult", ""); +// int b = (i * 96) + j + (u * 8); +// map3.put("num", ""); +// map3.put("order", b + 1); +// u++; +// map2.put(a + 12, map3); +// list.add(map3); +// } + mapList.add(map2); + } + map1.put("g" + (i + 1), mapList); + } + + Collections.sort(list, new Comparator>() { + @Override + public int compare(Map o1, Map o2) { + Integer id1 = (Integer) o1.get("order"); + Integer id2 = (Integer) o2.get("order"); + // 升序 + return id1.compareTo(id2); + } + }); + + int numIndex = 0; + for (Map stringObjectMap : list) { + String num = (String) stringObjectMap.get("num"); + if (num != null && !"".equals(num)) { + num = split[numIndex]; + stringObjectMap.put("num", num); + numIndex++; + } + } + // 判断分配样品数量与检测样品数量是否一致 + if (split.length != numIndex) { + throw new Exception("分配样品数量与检测样品数量不一致!"); + } + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ExamineResult::getExamineId, examineId); + ExamineResult result = service.getOne(wrapper); + if (result != null) { + result.setOriginRecordData(JSON.toJSONString(map)); + result.setOriginRecordResult(JSON.toJSONString(map1)); + result.setExamineDataArr(JSON.toJSONString(list)); + service.updateById(result); + } else { + ExamineResult examineResult = new ExamineResult(); + examineResult.setExamineId(Long.valueOf(examineId)); + examineResult.setOriginRecordData(JSON.toJSONString(map)); + examineResult.setOriginRecordResult(JSON.toJSONString(map1)); + examineResult.setExamineDataArr(JSON.toJSONString(list)); + service.save(examineResult); + } + return R.data(map1); + } + + /** * 计算常规检验的阴或阳性对照平均值 */ @@ -1086,21 +1657,28 @@ public class ExamineResultController extends BladeController { for (String key : set1) { Map data1 = layer1.get(key); Map data2 = layer2.get(key); + Map data = new HashMap<>(); + data.put("result", data1.get("result")); + data.put("log2", data1.get("log2")); + data.put("value", data1.get("value")); + data.put("order", data1.get("order")); + data.put("num", data1.get("num")); + boolean isPig = "猪".equals(examine.getSimpleName().split("-")[0]); - if (data1.get("result") == null || data2.get("result") == null) { - allDatas.add(data1); + if (data.get("result") == null || data2.get("result") == null) { + allDatas.add(data); continue; } - if (data1.get("result").equals("阳性") || data2.get("result").equals("阳性")) { - data1.put("log2", isPig ? "≥1:64" : "≥1:128"); - data1.put("result", "阳性"); - allDatas.add(data1); + if (data.get("result").equals("阳性") || data2.get("result").equals("阳性")) { + data.put("log2", isPig ? "≥1:64" : "≥1:128"); + data.put("result", "阳性"); + allDatas.add(data); yangCount++; simpleCount++; } else { - data1.put("log2", isPig ? "<1:64" : "<1:128"); - data1.put("result", "阴性"); - allDatas.add(data1); + data.put("log2", isPig ? "<1:64" : "<1:128"); + data.put("result", "阴性"); + allDatas.add(data); yinCount++; simpleCount++; } @@ -1223,21 +1801,28 @@ public class ExamineResultController extends BladeController { for (String key : set1) { Map data1 = layer1.get(key); Map data2 = layer2.get(key); + Map data = new HashMap<>(); + data.put("result", data1.get("result")); + data.put("log2", data1.get("log2")); + data.put("value", data1.get("value")); + data.put("order", data1.get("order")); + data.put("num", data1.get("num")); + boolean isPig = "猪".equals(examine.getSimpleName().split("-")[0]); - if (data1.get("result") == null || data2.get("result") == null) { - allDatas.add(data1); + if (data.get("result") == null || data2.get("result") == null) { + allDatas.add(data); continue; } - if (data1.get("result").equals("阳性") || data2.get("result").equals("阳性")) { - data1.put("log2", isPig ? "≥1:64" : "≥1:128"); - data1.put("result", "阳性"); - allDatas.add(data1); + if (data.get("result").equals("阳性") || data2.get("result").equals("阳性")) { + data.put("log2", isPig ? "≥1:64" : "≥1:128"); + data.put("result", "阳性"); + allDatas.add(data); yangCount++; simpleCount++; } else { - data1.put("log2", isPig ? "<1:64" : "<1:128"); - data1.put("result", "阴性"); - allDatas.add(data1); + data.put("log2", isPig ? "<1:64" : "<1:128"); + data.put("result", "阴性"); + allDatas.add(data); yinCount++; simpleCount++; } @@ -1277,6 +1862,409 @@ public class ExamineResultController extends BladeController { } } + /** + * 口蹄疫Excel解析数据 + */ + private R ktyExcel1(MultipartFile file, String examineId, + String infoStr, + String reg) throws Exception { + List originRowDatas = ExcelUtil.read(file, ExamineExcel.class); + String[] split = examineId.split(","); + Examine examine = examineService.getById(split[0]); + examine.setTemplateType(split[1]); + examineService.updateById(examine); + // 兰所单板---------------------------------------------------------------------------------------------------- + if ("1".equals(split[1])) { + String simpleName1 = examine.getSimpleName().split("-")[0]; + + String[] experieNum = examine.getExperieNum().split(","); + // 获取4个抗原对照值 + List list = new ArrayList<>(); + list.add(Double.parseDouble(originRowDatas.get(4).getCode12())); + list.add(Double.parseDouble(originRowDatas.get(5).getCode12())); + list.add(Double.parseDouble(originRowDatas.get(6).getCode12())); + list.add(Double.parseDouble(originRowDatas.get(7).getCode12())); + List list1 = list.stream().sorted().collect(Collectors.toList()); + DecimalFormat df = new DecimalFormat("#0.000"); + // 对照平均值 + Double avg = Double.valueOf(df.format((list1.get(1) + list1.get(2)) / 4)); + + // 结果resultList + List> resultList = new ArrayList<>(); + for (int r = 0; r < 8; r++) { + if (r > 0) { + // 第1列 + resultList.add(assumb(r, 1, originRowDatas.get(r).getCode1(), originRowDatas.get(r - 1).getCode1(), avg, simpleName1, experieNum)); + // 第2列 + resultList.add(assumb(r, 2, originRowDatas.get(r).getCode2(), originRowDatas.get(r - 1).getCode2(), avg, simpleName1, experieNum)); + // 第3列 + resultList.add(assumb(r, 3, originRowDatas.get(r).getCode3(), originRowDatas.get(r - 1).getCode3(), avg, simpleName1, experieNum)); + // 第4列 + resultList.add(assumb(r, 4, originRowDatas.get(r).getCode4(), originRowDatas.get(r - 1).getCode4(), avg, simpleName1, experieNum)); + // 第5列 + resultList.add(assumb(r, 5, originRowDatas.get(r).getCode5(), originRowDatas.get(r - 1).getCode5(), avg, simpleName1, experieNum)); + // 第6列 + resultList.add(assumb(r, 6, originRowDatas.get(r).getCode6(), originRowDatas.get(r - 1).getCode6(), avg, simpleName1, experieNum)); + // 第7列 + resultList.add(assumb(r, 7, originRowDatas.get(r).getCode7(), originRowDatas.get(r - 1).getCode7(), avg, simpleName1, experieNum)); + // 第8列 + resultList.add(assumb(r, 8, originRowDatas.get(r).getCode8(), originRowDatas.get(r - 1).getCode8(), avg, simpleName1, experieNum)); + // 第9列 + resultList.add(assumb(r, 9, originRowDatas.get(r).getCode9(), originRowDatas.get(r - 1).getCode9(), avg, simpleName1, experieNum)); + // 第10列 + resultList.add(assumb(r, 10, originRowDatas.get(r).getCode10(), originRowDatas.get(r - 1).getCode10(), avg, simpleName1, experieNum)); + // 第11列 + resultList.add(assumb(r, 11, originRowDatas.get(r).getCode11(), originRowDatas.get(r - 1).getCode11(), avg, simpleName1, experieNum)); + // 第12列 + resultList.add(assumb(r, 12, originRowDatas.get(r).getCode12(), originRowDatas.get(r - 1).getCode12(), avg, simpleName1, experieNum)); + } else { + // 第1列 + resultList.add(assumb(r, 1, originRowDatas.get(r).getCode1(), null, avg, simpleName1, experieNum)); + // 第2列 + resultList.add(assumb(r, 2, originRowDatas.get(r).getCode2(), null, avg, simpleName1, experieNum)); + // 第3列 + resultList.add(assumb(r, 3, originRowDatas.get(r).getCode3(), null, avg, simpleName1, experieNum)); + // 第4列 + resultList.add(assumb(r, 4, originRowDatas.get(r).getCode4(), null, avg, simpleName1, experieNum)); + // 第5列 + resultList.add(assumb(r, 5, originRowDatas.get(r).getCode5(), null, avg, simpleName1, experieNum)); + // 第6列 + resultList.add(assumb(r, 6, originRowDatas.get(r).getCode6(), null, avg, simpleName1, experieNum)); + // 第7列 + resultList.add(assumb(r, 7, originRowDatas.get(r).getCode7(), null, avg, simpleName1, experieNum)); + // 第8列 + resultList.add(assumb(r, 8, originRowDatas.get(r).getCode8(), null, avg, simpleName1, experieNum)); + // 第9列 + resultList.add(assumb(r, 9, originRowDatas.get(r).getCode9(), null, avg, simpleName1, experieNum)); + // 第10列 + resultList.add(assumb(r, 10, originRowDatas.get(r).getCode10(), null, avg, simpleName1, experieNum)); + // 第11列 + resultList.add(assumb(r, 11, originRowDatas.get(r).getCode11(), null, avg, simpleName1, experieNum)); + // 第12列 + resultList.add(assumb(r, 12, originRowDatas.get(r).getCode12(), null, avg, simpleName1, experieNum)); + } + } + + List> mapList = new ArrayList<>(); + for (Map map : resultList) { + if (!"".equals(map.get("log")) && !"".equals(map.get("result"))) { + mapList.add(map); + } + } + + // 判断应实验样品数量和实际样品数量是否相等 + if (experieNum.length != mapList.size()) { + throw new Exception("分配样品数量与检测样品数量不一致!"); + } + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ExamineResult::getExamineId, examine.getId()); + ExamineResult result = service.getOne(wrapper); + if (result != null) { + result.setOriginRecordData(JSON.toJSONString(mapList)); + result.setOriginRecordResult(JSON.toJSONString(mapList)); +// result.setExamineDataArr(JSON.toJSONString(list)); + result.setExamineDataArr(JSON.toJSONString(resultList)); + service.updateById(result); + } else { + ExamineResult examineResult = new ExamineResult(); + examineResult.setExamineId(Long.valueOf(examine.getId())); + examineResult.setOriginRecordData(JSON.toJSONString(mapList)); + examineResult.setOriginRecordResult(JSON.toJSONString(mapList)); +// examineResult.setExamineDataArr(JSON.toJSONString(list)); + examineResult.setExamineDataArr(JSON.toJSONString(resultList)); + service.save(examineResult); + } + return R.data(mapList); + } + // 兰所多板---------------------------------------------------------------------------------------------------- + else if ("2".equals(split[1])) { + int yinCount = 0; + int yangCount = 0; + Map>>> resultMap = new HashMap<>(); + // 以组为维度的所有数据:<1:行...>、<2:行...> + Map> groupsMap = new HashMap<>(); + // 组数 + int groupCount = (originRowDatas.size() + 1) / 9; + + // 取实际的数据(排除数字标题) + groupsMap = excludeNumTitle(groupCount, originRowDatas, groupsMap); + // 检测编号s + String[] experieNum = examine.getExperieNum().split(","); + // 用于存放每个格子的值,有顺序,无规则 + List> allDatas = new ArrayList<>(); + List> allData = new ArrayList<>(); + int simpleCount = 0; + // 按照公式计算实验数据并返回;两板对照:取偶数组去循环做参照,+1组做对照 + // 参照组:2n 、对照组:2n + 1 + for (int group = 0; group < groupCount / 2; group++) { + + // 1.参照组 + // 存这一组的所有数据 + List>> allDataInCurrGroup1 = new ArrayList<>(); + // i = 0时,是取1组的那8行 + List rowInGroup1 = groupsMap.get(String.valueOf((2 * group) + 1)); + // 计算该组的[对照平均值] + Double avg1 = calcCurrGroupContrastAvg1(rowInGroup1, infoStr, reg); + for (int row = 0; row < rowInGroup1.size(); row++) { + // 行标头:前端渲染需要A、B、C.... + String a = String.valueOf((char) (row + 65)); + // 每一个位置的值: A1、B2... + Map> allPosDatasInAGroup = new HashMap<>(); + int u = 1; + // 计算每一列 + for (int i = 1; i <= 12; i++) { + Map cPosData = calcAndPutcPosData(rowInGroup1, avg1, experieNum, group, row, i, u, 1, 1); + allData.add(cPosData); + allPosDatasInAGroup.put(a + i, cPosData); + if (i != 1) { + u++; + } + } + allDataInCurrGroup1.add(allPosDatasInAGroup); + } + resultMap.put("g" + (2 * group + 1), allDataInCurrGroup1); + + // 2.对照组 + // 存这一组的所有数据 + List>> allDataInCurrGroup2 = new ArrayList<>(); + // i = 0时,是取1组的那8行 + List rowInGroup2 = groupsMap.get(String.valueOf((2 * group + 1) + 1)); + // 计算该组的[对照平均值] + Double avg2 = calcCurrGroupContrastAvg1(rowInGroup2, infoStr, reg); + for (int row = 0; row < rowInGroup2.size(); row++) { + // 行标头:前端渲染需要A、B、C.... + String a = String.valueOf((char) (row + 65)); + // 每一个位置的值: A1、B2... + Map> allPosDatasInAGroup = new HashMap<>(); + int u = 1; + // 计算每一列 + for (int i = 1; i <= 12; i++) { + Map cPosData = calcAndPutcPosData(rowInGroup2, avg2, experieNum, group, row, i, u, 1, 2); + allData.add(cPosData); + allPosDatasInAGroup.put(a + i, cPosData); + if (i != 1) { + u++; + } + } + allDataInCurrGroup2.add(allPosDatasInAGroup); + } + resultMap.put("g" + ((2 * group + 1) + 1), allDataInCurrGroup2); + + // 3.两相比较取结果 + for (int i = 0; i < allDataInCurrGroup1.size(); i++) { + Map> layer1 = allDataInCurrGroup1.get(i); + Map> layer2 = allDataInCurrGroup2.get(i); + Set set1 = layer1.keySet(); + Set set2 = layer2.keySet(); + for (String key : set1) { + Map data1 = layer1.get(key); + Map data2 = layer2.get(key); + Map data = new HashMap<>(); + data.put("result", data1.get("result")); + data.put("log2", data1.get("log2")); + data.put("value", data1.get("value")); + data.put("order", data1.get("order")); + data.put("num", data1.get("num")); + boolean isPig = "猪".equals(examine.getSimpleName().split("-")[0]); + if (data.get("result") == null || data2.get("result") == null) { + allDatas.add(data); + continue; + } + if (data.get("result").equals("阳性") || data2.get("result").equals("阳性")) { + data.put("log2", isPig ? "≥1:64" : "≥1:128"); + data.put("result", "阳性"); + allDatas.add(data); + yangCount ++; + simpleCount ++; + } else { + data.put("log2", isPig ? "<1:64" : "<1:128"); + data.put("result", "阴性"); + allDatas.add(data); + yinCount ++; + simpleCount ++; + } + } + } + } + + // 判断应实验样品数量和实际样品数量是否相等 + if (experieNum.length != simpleCount) { + throw new Exception("分配样品数量与检测样品数量不一致!"); + } + + Map realResultMap = new HashMap<>(); + realResultMap.put("data", resultMap); + realResultMap.put("yinCount", yinCount); + realResultMap.put("yangCount", yangCount); + + // 新增或修改Result数据 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ExamineResult::getExamineId, examine.getId()); + ExamineResult result = service.getOne(wrapper); + if (result != null) { + result.setOriginRecordData(JSON.toJSONString(allData)); +// result.setOriginRecordResult(JSON.toJSONString(resultMap)); + result.setOriginRecordResult(JSON.toJSONString(realResultMap)); + result.setExamineDataArr(JSON.toJSONString(allDatas)); + service.updateById(result); + } else { + ExamineResult examineResult = new ExamineResult(); + examineResult.setExamineId(Long.valueOf(examine.getId())); + examineResult.setOriginRecordData(JSON.toJSONString(allData)); +// result.setOriginRecordResult(JSON.toJSONString(resultMap)); + examineResult.setOriginRecordResult(JSON.toJSONString(realResultMap)); + examineResult.setExamineDataArr(JSON.toJSONString(allDatas)); + service.save(examineResult); + } + return R.data(realResultMap); + } + // 非兰所,11列也是样品 --------------------------------------------------------------------------------------- + else { + int yinCount = 0; + int yangCount = 0; + Map>>> resultMap = new HashMap<>(); + // 以组为维度的所有数据:<1:行...>、<2:行...> + Map> groupsMap = new HashMap<>(); + // 组数 + int groupCount = (originRowDatas.size() + 1) / 9; + + // 取实际的数据(排除数字标题) + groupsMap = excludeNumTitle(groupCount, originRowDatas, groupsMap); + + // 检测编号s + String[] experieNum = examine.getExperieNum().split(","); + // 用于存放每个格子的值,有顺序,无规则 + List> allDatas = new ArrayList<>(); + List> allData = new ArrayList<>(); + int simpleCount = 0; + // 按照公式计算实验数据并返回 + // 参照组:2n 、对照组:2n + 1 + for (int group = 0; group < groupCount / 2; group++) { + + // 1.参照组 + // 存这一组的所有数据 + List>> allDataInCurrGroup1 = new ArrayList<>(); + // i = 0时,是取1组的那8行 + List rowInGroup1 = groupsMap.get(String.valueOf((2 * group) + 1)); + // 计算该组的[对照平均值] + Double avg1 = calcCurrGroupContrastAvg1(rowInGroup1, infoStr, reg); + for (int row = 0; row < rowInGroup1.size(); row++) { + // 行标头:前端渲染需要A、B、C.... + String a = String.valueOf((char) (row + 65)); + // 每一个位置的值: A1、B2... + Map> allPosDatasInAGroup = new HashMap<>(); + int u = 1; + // 计算每一列 + for (int i = 1; i <= 12; i++) { + Map cPosData = calcAndPutcPosData(rowInGroup1, avg1, experieNum, group, row, i, u, 2, 1); + allData.add(cPosData); + allPosDatasInAGroup.put(a + i, cPosData); + if (i != 1) { + u++; + } + } + allDataInCurrGroup1.add(allPosDatasInAGroup); + } + resultMap.put("g" + (2 * group + 1), allDataInCurrGroup1); + + // 1.对照组 + // 存这一组的所有数据 + List>> allDataInCurrGroup2 = new ArrayList<>(); + // i = 0时,是取1组的那8行 + List rowInGroup2 = groupsMap.get(String.valueOf((2 * group + 1) + 1)); + // 计算该组的[对照平均值] + Double avg2 = calcCurrGroupContrastAvg1(rowInGroup2, infoStr, reg); + for (int row = 0; row < rowInGroup2.size(); row++) { + // 行标头:前端渲染需要A、B、C.... + String a = String.valueOf((char) (row + 65)); + // 每一个位置的值: A1、B2... + Map> allPosDatasInAGroup = new HashMap<>(); + int u = 1; + // 计算每一列 + for (int i = 1; i <= 12; i++) { + Map cPosData = calcAndPutcPosData(rowInGroup2, avg2, experieNum, group, row, i, u, 2, 2); + allData.add(cPosData); + allPosDatasInAGroup.put(a + i, cPosData); + if (i != 1) { + u++; + } + } + allDataInCurrGroup2.add(allPosDatasInAGroup); + } + resultMap.put("g" + ((2 * group + 1) + 1), allDataInCurrGroup2); + + // 3.两相比较取结果 + for (int i = 0; i < allDataInCurrGroup1.size(); i++) { + Map> layer1 = allDataInCurrGroup1.get(i); + Map> layer2 = allDataInCurrGroup2.get(i); + Set set1 = layer1.keySet(); + Set set2 = layer2.keySet(); + for (String key : set1) { + Map data1 = layer1.get(key); + Map data2 = layer2.get(key); + Map data = new HashMap<>(); + data.put("result", data1.get("result")); + data.put("log2", data1.get("log2")); + data.put("value", data1.get("value")); + data.put("order", data1.get("order")); + data.put("num", data1.get("num")); + + boolean isPig = "猪".equals(examine.getSimpleName().split("-")[0]); + if (data.get("result") == null || data2.get("result") == null) { + allDatas.add(data); + continue; + } + if (data.get("result").equals("阳性") || data2.get("result").equals("阳性")) { + data.put("log2", isPig ? "≥1:64" : "≥1:128"); + data.put("result", "阳性"); + allDatas.add(data); + yangCount ++; + simpleCount ++; + } else { + data.put("log2", isPig ? "<1:64" : "<1:128"); + data.put("result", "阴性"); + allDatas.add(data); + yinCount ++; + simpleCount ++; + } + } + } + } + + // 判断应实验样品数量和实际样品数量是否相等 + if (experieNum.length != simpleCount) { + throw new Exception("分配样品数量与检测样品数量不一致!"); + } + + Map realResultMap = new HashMap<>(); + realResultMap.put("data", resultMap); + realResultMap.put("yinCount", yinCount); + realResultMap.put("yangCount", yangCount); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ExamineResult::getExamineId, examine.getId()); + ExamineResult result = service.getOne(wrapper); + if (result != null) { + result.setOriginRecordData(JSON.toJSONString(allData)); + result.setOriginRecordResult(JSON.toJSONString(realResultMap)); +// result.setOriginRecordResult(JSON.toJSONString(resultMap)); + result.setExamineDataArr(JSON.toJSONString(allDatas)); + service.updateById(result); + } else { + ExamineResult examineResult = new ExamineResult(); + examineResult.setExamineId(Long.valueOf(examine.getId())); + examineResult.setOriginRecordData(JSON.toJSONString(allData)); + examineResult.setOriginRecordResult(JSON.toJSONString(realResultMap)); +// examineResult.setOriginRecordResult(JSON.toJSONString(resultMap)); + examineResult.setExamineDataArr(JSON.toJSONString(allDatas)); + service.save(examineResult); + } + return R.data(realResultMap); + } + } + + /** * 将当前位置的数据存入allPosDatasInAGroup、addDatas * b:从一个顺序排的检测编号里获取G1这个位置的值 @@ -1329,7 +2317,7 @@ public class ExamineResultController extends BladeController { cPosData.put("order", order + 1 + 96); } cPosData.put("num", experieNum[b - ((group + 1) * 6 + (group * 16))]); - cPosData.put("result", Double.parseDouble(value) > avg ? "阳性" : "阴性"); + cPosData.put("result", Double.parseDouble(value) > avg ? "阴性" : "阳性"); return cPosData; } cPosData.put("value", value != null ? value : " "); @@ -1360,6 +2348,45 @@ public class ExamineResultController extends BladeController { return Double.valueOf(df.format((list2.get(1) + list2.get(2)) / 4)); } + /** + * 计算该组的 对照平均值 + * 1.公式内容map的value值换成真实数据值 + * 2.按照公式算对照平均值 + */ + private Double calcCurrGroupContrastAvg1(List excels, String infoStr, String reg) { + Map params = new HashMap<>(); + DecimalFormat df = new DecimalFormat("#0.000"); + + // 获取4个抗原对照值 + List list1 = new ArrayList<>(); + list1.add(Double.parseDouble(excels.get(4).getCode12())); + list1.add(Double.parseDouble(excels.get(5).getCode12())); + list1.add(Double.parseDouble(excels.get(6).getCode12())); + list1.add(Double.parseDouble(excels.get(7).getCode12())); + + // 排序,取中间两个值 + List list2 = list1.stream().sorted().collect(Collectors.toList()); + List list3 = new ArrayList<>(); + list3.add(list2.get(1)); + list3.add(list2.get(2)); + Map info = JSON.parseObject(infoStr, new TypeReference>() {}); + List list = new ArrayList<>(info.keySet()); + + // 公示内容换成真实数据换成真实数据值 + for (int i = 0; i < list.size(); i++) { + params.put(list.get(i), list3.get(i)); + } + + // 得出最终对照平均值并返回 + String value = null; + try { + value = FormulaTool.getResult(reg, params); + } catch (Exception e) { + e.printStackTrace(); + } + return Double.valueOf(df.format(Double.parseDouble(value))); + } + /** * 取实际的数据(排除数字标题) */