From 397ec18b1bc0fce047301a0f9217e6fb7fa5459d Mon Sep 17 00:00:00 2001 From: swj <1211312234@qq.com> Date: Sat, 3 Sep 2022 22:10:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B0=E6=89=80=E5=A4=9A=E7=89=88=E5=92=8C?= =?UTF-8?q?=E9=9D=9E=E5=85=B0=E6=89=80=E5=AE=9E=E9=AA=8C=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E4=B8=A4=E6=9D=BF=E5=AF=B9=E7=85=A7=E5=8F=96=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=20+=20=E6=96=B0=E5=A2=9E=E5=A7=94=E6=89=98=E5=8D=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=8A=BD=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/utils/ZipCompressUtil.java | 1 - lab-service/lab-lims/pom.xml | 1 + .../controller/ExamineResultController.java | 1079 +++++------------ .../lims/service/impl/EntrustServiceImpl.java | 403 +++--- 4 files changed, 534 insertions(+), 950 deletions(-) diff --git a/lab-common/src/main/java/org/springblade/common/utils/ZipCompressUtil.java b/lab-common/src/main/java/org/springblade/common/utils/ZipCompressUtil.java index c020d56..04e73be 100644 --- a/lab-common/src/main/java/org/springblade/common/utils/ZipCompressUtil.java +++ b/lab-common/src/main/java/org/springblade/common/utils/ZipCompressUtil.java @@ -22,7 +22,6 @@ public class ZipCompressUtil { if (!srcdir.exists()) { throw new RuntimeException(srcPathName + "不存在!"); } - Project prj = new Project(); Zip zip = new Zip(); zip.setProject(prj); diff --git a/lab-service/lab-lims/pom.xml b/lab-service/lab-lims/pom.xml index 688963a..7048ed2 100644 --- a/lab-service/lab-lims/pom.xml +++ b/lab-service/lab-lims/pom.xml @@ -29,6 +29,7 @@ 1.3 + org.apache.poi ooxml-schemas 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 307526d..039a0a3 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 @@ -501,22 +501,22 @@ public class ExamineResultController extends BladeController { * 口蹄疫Excel解析数据 */ private R ktyExcel(MultipartFile file, String examineId) { - List read = ExcelUtil.read(file, ExamineExcel.class); + 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(read.get(3).getCode12())); - list.add(Double.parseDouble(read.get(4).getCode12())); - list.add(Double.parseDouble(read.get(5).getCode12())); - list.add(Double.parseDouble(read.get(6).getCode12())); + list.add(Double.parseDouble(originRowDatas.get(3).getCode12())); + 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 list1 = list.stream().sorted().collect(Collectors.toList()); DecimalFormat df = new DecimalFormat("#0.000"); // 对照平均值 @@ -527,54 +527,54 @@ public class ExamineResultController extends BladeController { for (int r = 0; r < 8; r++) { if (r > 0) { // 第1列 - resultList.add(assumb(r, 1, read.get(r).getCode1(), read.get(r - 1).getCode1(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 1, originRowDatas.get(r).getCode1(), originRowDatas.get(r - 1).getCode1(), avg, simpleName1, experieNum)); // 第2列 - resultList.add(assumb(r, 2, read.get(r).getCode2(), read.get(r - 1).getCode2(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 2, originRowDatas.get(r).getCode2(), originRowDatas.get(r - 1).getCode2(), avg, simpleName1, experieNum)); // 第3列 - resultList.add(assumb(r, 3, read.get(r).getCode3(), read.get(r - 1).getCode3(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 3, originRowDatas.get(r).getCode3(), originRowDatas.get(r - 1).getCode3(), avg, simpleName1, experieNum)); // 第4列 - resultList.add(assumb(r, 4, read.get(r).getCode4(), read.get(r - 1).getCode4(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 4, originRowDatas.get(r).getCode4(), originRowDatas.get(r - 1).getCode4(), avg, simpleName1, experieNum)); // 第5列 - resultList.add(assumb(r, 5, read.get(r).getCode5(), read.get(r - 1).getCode5(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 5, originRowDatas.get(r).getCode5(), originRowDatas.get(r - 1).getCode5(), avg, simpleName1, experieNum)); // 第6列 - resultList.add(assumb(r, 6, read.get(r).getCode6(), read.get(r - 1).getCode6(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 6, originRowDatas.get(r).getCode6(), originRowDatas.get(r - 1).getCode6(), avg, simpleName1, experieNum)); // 第7列 - resultList.add(assumb(r, 7, read.get(r).getCode7(), read.get(r - 1).getCode7(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 7, originRowDatas.get(r).getCode7(), originRowDatas.get(r - 1).getCode7(), avg, simpleName1, experieNum)); // 第8列 - resultList.add(assumb(r, 8, read.get(r).getCode8(), read.get(r - 1).getCode8(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 8, originRowDatas.get(r).getCode8(), originRowDatas.get(r - 1).getCode8(), avg, simpleName1, experieNum)); // 第9列 - resultList.add(assumb(r, 9, read.get(r).getCode9(), read.get(r - 1).getCode9(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 9, originRowDatas.get(r).getCode9(), originRowDatas.get(r - 1).getCode9(), avg, simpleName1, experieNum)); // 第10列 - resultList.add(assumb(r, 10, read.get(r).getCode10(), read.get(r - 1).getCode10(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 10, originRowDatas.get(r).getCode10(), originRowDatas.get(r - 1).getCode10(), avg, simpleName1, experieNum)); // 第11列 - resultList.add(assumb(r, 11, read.get(r).getCode11(), read.get(r - 1).getCode11(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 11, originRowDatas.get(r).getCode11(), originRowDatas.get(r - 1).getCode11(), avg, simpleName1, experieNum)); // 第12列 - resultList.add(assumb(r, 12, read.get(r).getCode12(), read.get(r - 1).getCode12(), avg, simpleName1, experieNum)); + resultList.add(assumb(r, 12, originRowDatas.get(r).getCode12(), originRowDatas.get(r - 1).getCode12(), avg, simpleName1, experieNum)); } else { // 第1列 - resultList.add(assumb(r, 1, read.get(r).getCode1(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 1, originRowDatas.get(r).getCode1(), null, avg, simpleName1, experieNum)); // 第2列 - resultList.add(assumb(r, 2, read.get(r).getCode2(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 2, originRowDatas.get(r).getCode2(), null, avg, simpleName1, experieNum)); // 第3列 - resultList.add(assumb(r, 3, read.get(r).getCode3(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 3, originRowDatas.get(r).getCode3(), null, avg, simpleName1, experieNum)); // 第4列 - resultList.add(assumb(r, 4, read.get(r).getCode4(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 4, originRowDatas.get(r).getCode4(), null, avg, simpleName1, experieNum)); // 第5列 - resultList.add(assumb(r, 5, read.get(r).getCode5(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 5, originRowDatas.get(r).getCode5(), null, avg, simpleName1, experieNum)); // 第6列 - resultList.add(assumb(r, 6, read.get(r).getCode6(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 6, originRowDatas.get(r).getCode6(), null, avg, simpleName1, experieNum)); // 第7列 - resultList.add(assumb(r, 7, read.get(r).getCode7(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 7, originRowDatas.get(r).getCode7(), null, avg, simpleName1, experieNum)); // 第8列 - resultList.add(assumb(r, 8, read.get(r).getCode8(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 8, originRowDatas.get(r).getCode8(), null, avg, simpleName1, experieNum)); // 第9列 - resultList.add(assumb(r, 9, read.get(r).getCode9(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 9, originRowDatas.get(r).getCode9(), null, avg, simpleName1, experieNum)); // 第10列 - resultList.add(assumb(r, 10, read.get(r).getCode10(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 10, originRowDatas.get(r).getCode10(), null, avg, simpleName1, experieNum)); // 第11列 - resultList.add(assumb(r, 11, read.get(r).getCode11(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 11, originRowDatas.get(r).getCode11(), null, avg, simpleName1, experieNum)); // 第12列 - resultList.add(assumb(r, 12, read.get(r).getCode12(), null, avg, simpleName1, experieNum)); + resultList.add(assumb(r, 12, originRowDatas.get(r).getCode12(), null, avg, simpleName1, experieNum)); } } @@ -603,761 +603,322 @@ public class ExamineResultController extends BladeController { } return R.data(mapList); } - // 兰所多板 - else if ("2".equals(split[1])) { - 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(split[0]); - String[] split1 = examine.getExperieNum().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 + ""); - // 获取4个抗原对照值 - List list1 = new ArrayList<>(); - list1.add(Double.parseDouble(excels.get(3).getCode12())); - list1.add(Double.parseDouble(excels.get(4).getCode12())); - list1.add(Double.parseDouble(excels.get(5).getCode12())); - list1.add(Double.parseDouble(excels.get(6).getCode12())); - List list2 = list1.stream().sorted().collect(Collectors.toList()); - DecimalFormat df = new DecimalFormat("#0.000"); - // 对照平均值 - Double avg = Double.valueOf(df.format((list2.get(1) + list2.get(2)) / 4)); - for (int j = 0; j < excels.size(); j++) { - String a = ""; - if (j == 0) { - a = "A"; - } - if (j == 1) { - a = "B"; - } - if (j == 2) { - a = "C"; - } - if (j == 3) { - a = "D"; - } - if (j == 4) { - a = "E"; - } - if (j == 5) { - a = "F"; - } - if (j == 6) { - a = "G"; - } - if (j == 7) { - a = "H"; - } - Map> map2 = new HashMap<>(); - int u = 1; - if (j > 5) { - if (excels.get(j).getCode1() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode1()); -// map3.put("value", SP); -// int b = (i * 90) + j - 6; - int b = (i * 96) + j; - map3.put("num", split1[b - ((i + 1) * 6 + (i * 16))]); - map3.put("order", b + 1); - if (Double.parseDouble(excels.get(j).getCode1()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 1, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j; - map3.put("order", b + 1); - map2.put(a + 1, map3); - list.add(map3); - } - } else { - if (excels.get(j).getCode1() != null) { - Map map3 = new HashMap<>(); - map3.put("value", 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("value", " "); - int b = (i * 96) + j; - map3.put("order", b + 1); - map2.put(a + 1, map3); - list.add(map3); - } - } - if (excels.get(j).getCode2() != null) { - Map map3 = new HashMap<>(); - map3.put("value", 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", split1[b - ((i + 1) * 6 + (i * 16))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode2()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 2, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 2, map3); - list.add(map3); - } - if (excels.get(j).getCode3() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode3()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 16))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode3()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 3, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 3, map3); - list.add(map3); - } - if (excels.get(j).getCode4() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode4()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 16))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode4()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 4, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 4, map3); - list.add(map3); - } - if (excels.get(j).getCode5() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode5()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 16))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode5()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 5, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 5, map3); - list.add(map3); - } - if (excels.get(j).getCode6() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode6()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 16))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode6()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 6, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 6, map3); - list.add(map3); - } - if (excels.get(j).getCode7() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode7()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 16))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode7()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 7, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 7, map3); - list.add(map3); - } - if (excels.get(j).getCode8() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode8()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 16))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode8()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 8, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 8, map3); - list.add(map3); - } - if (excels.get(j).getCode9() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode9()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 16))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode9()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 9, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 9, map3); - list.add(map3); - } - if (excels.get(j).getCode10() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode10()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 16))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode10()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 10, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 10, map3); - list.add(map3); - } - if (excels.get(j).getCode11() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode11()); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 11, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 11, map3); - list.add(map3); - } - if (excels.get(j).getCode12() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode12()); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - map2.put(a + 12, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 12, map3); - list.add(map3); - } - mapList.add(map2); - } - map1.put("g" + (i + 1), mapList); - } - - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(ExamineResult::getExamineId, examine.getId()); - 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(examine.getId())); - examineResult.setOriginRecordData(JSON.toJSONString(map)); - examineResult.setOriginRecordResult(JSON.toJSONString(map1)); - examineResult.setExamineDataArr(JSON.toJSONString(list)); - service.save(examineResult); - } - return R.data(map1); - } - // 非兰所 - else { - 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(split[0]); - String[] split1 = examine.getExperieNum().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 + ""); - // 获取4个抗原对照值 - List list1 = new ArrayList<>(); - list1.add(Double.parseDouble(excels.get(3).getCode12())); - list1.add(Double.parseDouble(excels.get(4).getCode12())); - list1.add(Double.parseDouble(excels.get(5).getCode12())); - list1.add(Double.parseDouble(excels.get(6).getCode12())); - List list2 = list1.stream().sorted().collect(Collectors.toList()); - DecimalFormat df = new DecimalFormat("#0.000"); - // 对照平均值 - Double avg = Double.valueOf(df.format((list2.get(1) + list2.get(2)) / 4)); - for (int j = 0; j < excels.size(); j++) { - String a = ""; - if (j == 0) { - a = "A"; - } - if (j == 1) { - a = "B"; - } - if (j == 2) { - a = "C"; - } - if (j == 3) { - a = "D"; - } - if (j == 4) { - a = "E"; - } - if (j == 5) { - a = "F"; - } - if (j == 6) { - a = "G"; - } - if (j == 7) { - a = "H"; - } - Map> map2 = new HashMap<>(); - int u = 1; - if (j > 5) { - if (excels.get(j).getCode1() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode1()); -// map3.put("value", SP); -// int b = (i * 90) + j - 6; - int b = (i * 96) + j; - map3.put("num", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - if (Double.parseDouble(excels.get(j).getCode1()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 1, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j; - map3.put("order", b + 1); - map2.put(a + 1, map3); - list.add(map3); - } - } else { - if (excels.get(j).getCode1() != null) { - Map map3 = new HashMap<>(); - map3.put("value", 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("value", " "); - int b = (i * 96) + j; - map3.put("order", b + 1); - map2.put(a + 1, map3); - list.add(map3); - } - } - if (excels.get(j).getCode2() != null) { - Map map3 = new HashMap<>(); - map3.put("value", 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", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode2()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 2, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 2, map3); - list.add(map3); - } - if (excels.get(j).getCode3() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode3()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode3()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 3, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 3, map3); - list.add(map3); - } - if (excels.get(j).getCode4() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode4()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode4()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 4, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 4, map3); - list.add(map3); - } - if (excels.get(j).getCode5() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode5()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode5()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); - } - map2.put(a + 5, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 5, map3); - list.add(map3); - } - if (excels.get(j).getCode6() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode6()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode6()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); + + // 兰所多板---------------------------------------------------------------------------------------------------- + else if ("2".equals(split[1])) { + 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<>(); + // 按照公式计算实验数据并返回;两板对照:取偶数组去循环做参照,+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 = calcCurrGroupContrastAvg(rowInGroup1); + 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); + allPosDatasInAGroup.put(a + i, cPosData); + if (i != 1) { + u++; } - map2.put(a + 6, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 6, map3); - list.add(map3); } - if (excels.get(j).getCode7() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode7()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode7()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); + allDataInCurrGroup1.add(allPosDatasInAGroup); + } + resultMap.put("g" + (group + 1), allDataInCurrGroup1); + + // 2.对照组 + // 存这一组的所有数据 + List>> allDataInCurrGroup2 = new ArrayList<>(); + // i = 0时,是取1组的那8行 + List rowInGroup2 = groupsMap.get(String.valueOf((2 * group + 1) + 1)); + // 计算该组的[对照平均值] + Double avg2 = calcCurrGroupContrastAvg(rowInGroup2); + 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); + allPosDatasInAGroup.put(a + i, cPosData); + if (i != 1) { + u++; } - map2.put(a + 7, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 7, map3); - list.add(map3); } - if (excels.get(j).getCode8() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode8()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode8()) > avg) { - map3.put("result", "阳性"); + allDataInCurrGroup2.add(allPosDatasInAGroup); + } + resultMap.put("g" + (group + 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); + boolean isPig = "猪".equals(examine.getSimpleName().split("-")[0]); + if (data1.get("result").equals("阳性") || data2.get("result").equals("阳性")) { + data1.put("log2", isPig ? "≥1:64" : "≥1:128"); + data1.put("result", "阳性"); + allDatas.add(data1); } else { - map3.put("result", "阴性"); + data1.put("log2", isPig ? "<1:64" : "<1:128"); + data1.put("result", "阴性"); + allDatas.add(data1); } - map2.put(a + 8, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 8, map3); - list.add(map3); } - if (excels.get(j).getCode9() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode9()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode9()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); + } + } + + // 新增或修改Result数据 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ExamineResult::getExamineId, examine.getId()); + ExamineResult result = service.getOne(wrapper); + if (result != null) { + result.setOriginRecordData(JSON.toJSONString(groupsMap)); + 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(groupsMap)); + examineResult.setOriginRecordResult(JSON.toJSONString(resultMap)); + examineResult.setExamineDataArr(JSON.toJSONString(allDatas)); + service.save(examineResult); + } + return R.data(resultMap); + } + // 非兰所,11列也是样品 --------------------------------------------------------------------------------------- + else { + 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<>(); + + // 按照公式计算实验数据并返回 + // 参照组:2n 、对照组:2n + 1 + for (int group = 0; group < groupCount; group++) { + + // 1.参照组 + // 存这一组的所有数据 + List>> allDataInCurrGroup1 = new ArrayList<>(); + // i = 0时,是取1组的那8行 + List rowInGroup1 = groupsMap.get(String.valueOf((2 * group + 1) + 1)); + // 计算该组的[对照平均值] + Double avg1 = calcCurrGroupContrastAvg(rowInGroup1); + 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); + allPosDatasInAGroup.put(a + i, cPosData); + if (i != 1) { + u++; } - map2.put(a + 9, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 9, map3); - list.add(map3); } - if (excels.get(j).getCode10() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode10()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode10()) > avg) { - map3.put("result", "阳性"); - } else { - map3.put("result", "阴性"); + allDataInCurrGroup1.add(allPosDatasInAGroup); + } + resultMap.put("g" + (group + 1), allDataInCurrGroup1); + + // 1.参照组 + // 存这一组的所有数据 + List>> allDataInCurrGroup2 = new ArrayList<>(); + // i = 0时,是取1组的那8行 + List rowInGroup2 = groupsMap.get(String.valueOf((2 * group + 1) + 1)); + // 计算该组的[对照平均值] + Double avg2 = calcCurrGroupContrastAvg(rowInGroup2); + 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); + allPosDatasInAGroup.put(a + i, cPosData); + if (i != 1) { + u++; } - map2.put(a + 10, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 10, map3); - list.add(map3); } - if (excels.get(j).getCode11() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode11()); - int b = (i * 96) + j + (u * 8); - map3.put("num", split1[b - ((i + 1) * 6 + (i * 8))]); - map3.put("order", b + 1); - u++; - if (Double.parseDouble(excels.get(j).getCode11()) > avg) { - map3.put("result", "阳性"); + allDataInCurrGroup2.add(allPosDatasInAGroup); + } + resultMap.put("g" + (group + 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); + boolean isPig = "猪".equals(examine.getSimpleName().split("-")[0]); + if (data1.get("result").equals("阳性") || data2.get("result").equals("阳性")) { + data1.put("log2", isPig ? "≥1:64" : "≥1:128"); + data1.put("result", "阳性"); + allDatas.add(data1); } else { - map3.put("result", "阴性"); + data1.put("log2", isPig ? "<1:64" : "<1:128"); + data1.put("result", "阴性"); + allDatas.add(data1); } - map2.put(a + 11, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 11, map3); - list.add(map3); - } - if (excels.get(j).getCode12() != null) { - Map map3 = new HashMap<>(); - map3.put("value", excels.get(j).getCode12()); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - map2.put(a + 12, map3); - list.add(map3); - } else { - Map map3 = new HashMap<>(); - map3.put("value", " "); - int b = (i * 96) + j + (u * 8); - map3.put("order", b + 1); - u++; - map2.put(a + 12, map3); - list.add(map3); } - mapList.add(map2); } - map1.put("g" + (i + 1), mapList); } LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(ExamineResult::getExamineId, examine.getId()); ExamineResult result = service.getOne(wrapper); if (result != null) { - result.setOriginRecordData(JSON.toJSONString(map)); - result.setOriginRecordResult(JSON.toJSONString(map1)); - result.setExamineDataArr(JSON.toJSONString(list)); + result.setOriginRecordData(JSON.toJSONString(groupsMap)); + result.setOriginRecordResult(JSON.toJSONString(resultMap)); + result.setExamineDataArr(JSON.toJSONString(allDatas)); service.updateById(result); - } else { + } + else { ExamineResult examineResult = new ExamineResult(); examineResult.setExamineId(Long.valueOf(examine.getId())); - examineResult.setOriginRecordData(JSON.toJSONString(map)); - examineResult.setOriginRecordResult(JSON.toJSONString(map1)); - examineResult.setExamineDataArr(JSON.toJSONString(list)); + examineResult.setOriginRecordData(JSON.toJSONString(groupsMap)); + examineResult.setOriginRecordResult(JSON.toJSONString(resultMap)); + examineResult.setExamineDataArr(JSON.toJSONString(allDatas)); service.save(examineResult); } - return R.data(map1); + return R.data(resultMap); + } + } + + /** + * 将当前位置的数据存入allPosDatasInAGroup、addDatas + * b:从一个顺序排的检测编号里获取G1这个位置的值 + * examineType: 1:多版, 2:非兰所 + */ + private Map calcAndPutcPosData(List excels, Double avg, String[] experieNum, int group, int row, int col, int u, int examineType) { + String value = null; + // 待抽 ↓ + if (col == 1) { + value = excels.get(row).getCode1(); + } + if (col == 2) { + value = excels.get(row).getCode2(); + } + if (col == 3) { + value = excels.get(row).getCode3(); + } + if (col == 4) { + value = excels.get(row).getCode4(); + } + if (col == 5) { + value = excels.get(row).getCode5(); + } + if (col == 6) { + value = excels.get(row).getCode6(); + } + if (col == 7) { + value = excels.get(row).getCode7(); + } + if (col == 8) { + value = excels.get(row).getCode8(); + } + if (col == 9) { + value = excels.get(row).getCode9(); + } + if (col == 10) { + value = excels.get(row).getCode10(); + } + if (col == 11) { + value = excels.get(row).getCode11(); + } + if (col == 12) { + value = excels.get(row).getCode12(); + } + Map cPosData = new HashMap<>(4); + int b = (group * 96) + row; + if (col != 1) { + b += (u * 8); + } + boolean isIncludeCurr = col == 12 ? false : (examineType == 1 && col == 11 ? false : true); + if (value != null && isIncludeCurr) { + cPosData.put("value", value); + cPosData.put("order", b + 1); + cPosData.put("num", experieNum[b - ((group + 1) * 6 + (group * 16))]); + cPosData.put("result", Double.parseDouble(value) > avg ? "阳性" : "阴性"); + return cPosData; + } + cPosData.put("value", " "); + cPosData.put("order", b + 1); + return cPosData; + } + + /** + * 计算该组的 对照平均值 + */ + private Double calcCurrGroupContrastAvg(List excels) { + // 获取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())); + // 排序后,去掉一个最大值去掉一个最小值,相加除以4 + List list2 = list1.stream().sorted().collect(Collectors.toList()); + DecimalFormat df = new DecimalFormat("#0.000"); + return Double.valueOf(df.format((list2.get(1) + list2.get(2)) / 4)); + } + + /** + * 取实际的数据(排除数字标题) + */ + private Map> excludeNumTitle(int groupCount, List rows, Map> map) { + for (int i = 0; i < groupCount; i++) { + List excels = new ArrayList<>(); + for (int j = i * 8 + i; j < (i + 1) * 8 + i; j++) { + ExamineExcel excel = rows.get(j); + excels.add(excel); + } + map.put((i + 1) + "", excels); } + return map; } /** diff --git a/lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/EntrustServiceImpl.java b/lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/EntrustServiceImpl.java index d2b4ac9..6b8753e 100644 --- a/lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/EntrustServiceImpl.java +++ b/lab-service/lab-lims/src/main/java/org/springblade/lims/service/impl/EntrustServiceImpl.java @@ -138,206 +138,22 @@ public class EntrustServiceImpl extends BaseServiceImpl // 送检单位、采样单位之类的,如果没有就新增 addIfNull(entrust); - // 样品关联表入库 - List rels = new ArrayList<>(); - LocalDateTime now = LocalDateTime.now(); - - String month1 = fullByZero(now.getMonthValue()); - String day1 = fullByZero(now.getDayOfMonth()); - String hour1 = fullByZero(now.getHour()); - - // 检测编号前缀 - String[] strings = entrust.getAcceptanceNum().split("-"); - String s = strings[1] + now.getYear() + month1 + day1 + hour1 + "-"; - - StringBuilder simpleName = new StringBuilder(); - Integer simpleCount = 0; - List> list = entrust.getSimpleNames(); + // 样品关联数据入库 + entrust = addSimpleRel(entrust, id); - // 样品排序 - int sort = 1; - for (Map map : list) { - // 样品名称 - String name = (String) map.get("simpleName"); - simpleName.append(name).append(","); - // 样品数量 - Integer count = (Integer) map.get("simpleCount"); - simpleCount += count; - // 原始编号 - String num = (String) map.get("originalNum"); - String[] split = num.split("-"); - int a = Integer.parseInt(split[0]); - - for (int i = 0; i < count; i++) { - SimpleRel simpleRel = new SimpleRel(); - if (entrust.getId() != null) { - simpleRel.setEntrustId(entrust.getId()); - } else { - simpleRel.setEntrustId(id); - } - simpleRel.setSimpleName(name); - simpleRel.setReagentNum(1); - simpleRel.setReagentExperieNum(s + ((a - 1) * 2 + i + 1 + count)); - simpleRel.setExamineNum(1); - simpleRel.setExamineExperieNum(s + ((a - 1) * 2 + i + 1)); - simpleRel.setRecessiveNum((i + a) + ""); - simpleRel.setOriginalNum((i + a) + ""); - simpleRel.setStatus(0); - simpleRel.setSort(sort); - rels.add(simpleRel); - } - sort++; - } - simpleRelService.saveBatch(rels); + // 是否为合同新增委托单 + entrust = isContractTypeEntrust(entrust); // 委托单入库/修改 - if (entrust.getSampleReceiverId() != null) { - R userR = userClient.userInfoById(Long.valueOf(entrust.getSampleReceiverId())); - User data = userR.getData(); - if (data != null) { - entrust.setSampleReceiverName(data.getName()); - } - } - entrust.setSimpleName(simpleName.toString()); - entrust.setSimpleCount(simpleCount); - String originalNum = ""; - if (simpleCount > 9) { - originalNum = "01-" + simpleCount; - } else { - originalNum = "01-0" + simpleCount; - } - String s1 = JSON.toJSONString(entrust.getSimpleNames()); - entrust.setSimpleJson(s1); - entrust.setOriginalNum(originalNum); - entrust.setIsDeleted(0); - entrust.setCreateUser(null); - entrust.setCreateTime(new Date()); - entrust.setUpdateTime(new Date()); - entrust.setUpdateUser(null); - entrust.setEntrustStatus("1"); - // 是否为合同新增委托单 - if (entrust.getContractId() != null) { - entrust.setEntrustType(2); - Contract contract = new Contract(); - contract.setId(entrust.getContractId()); - contract.setStatus(2); - contractService.updateById(contract); - } else { - entrust.setEntrustType(1); - } + addOrUpdateEntrust(entrust, id); - if (entrust.getId() != null) { - this.updateById(entrust); - } else { - entrust.setId(id); - this.save(entrust); - } // 新增或修改 检测集合 addOrUpdateExamines(entrust.getExamines(), entrust.getId()); return entrust; } - /** - * 如果有就取用,没有就新增 - * 有共同点,待抽 - */ - private void addIfNull(Entrust entrust) { - // 送检单位 - EntrustCustomer byId = customerService.getById(entrust.getEntrustCustomerId()); - if (byId != null) { - entrust.setEntrustCustomerName(byId.getName()); - } else { - EntrustCustomer customer = new EntrustCustomer(); - customer.setStatus(1); - customer.setPhone(entrust.getPhone()); - customer.setId(RandomUtils.nextLong()); - customer.setFax(entrust.getFacsimile()); - customer.setEmail(entrust.getPostalCode()); - customer.setFullName(entrust.getSubmittedBy()); - customer.setName(entrust.getEntrustCustomerName()); - customerService.save(customer); - } - - // 采样单位 - EntrustCustomer byId1 = customerService.getById(entrust.getTakeCompanyId()); - if (byId1 != null) { - entrust.setTakeCompany(byId1.getName()); - } else { - EntrustCustomer customer = new EntrustCustomer(); - customer.setStatus(2); - customer.setId(RandomUtils.nextLong()); - customer.setPhone(entrust.getTakePhone()); - customer.setName(entrust.getTakeCompany()); - customer.setFullName(entrust.getTakePerson()); - customer.setAddress(entrust.getTakeCompanyAddress()); - customerService.save(customer); - } - } - - /** - * 新增或修改检验集合 - */ - private void addOrUpdateExamines(List examines, Long entrustId) { - if (CollectionUtils.isNotEmpty(examines)) { - List saveList = new ArrayList<>(); - List updateList = new ArrayList<>(); - for (int i = 0; i < examines.size(); i++) { - Examine examine = examines.get(i); - if (examine.getId() != null) { - updateList.add(examine); - } else { - examine.setStatus(0); - examine.setIsDeleted(0); - examine.setSimpleCount(0); - examine.setExperieNum(""); - examine.setExamineOrder(i + 1); - examine.setEntrustId(entrustId); - examine.setCreateTime(new Date()); - examine.setUpdateTime(new Date()); - saveList.add(examine); - } - // 使用次数 +1 操作 - addUseCount(1, examine.getExamineItemId()); - addUseCount(2, examine.getExamineWayId()); - addUseCount(3, examine.getExamineBasisId()); - } - examineService.saveBatch(saveList); - examineService.updateBatchById(updateList); - } - } - - private void addUseCount(int type, Long elementId) { - if (elementId == null) { return; } - if (type == 1) { - ExamineItem examineItem = examineItemService.getById(elementId); - Integer useCount = examineItem.getUseCount(); - examineItem.setUseCount(++ useCount); - examineItemService.updateById(examineItem); - } - if (type == 2) { - ExamineWay examineWay = examineWayService.getById(elementId); - Integer useCount = examineWay.getUseCount(); - examineWay.setUseCount(++useCount); - examineWayService.updateById(examineWay); - } - if (type == 3) { - ExamineBasis examineBasis = examineBasisService.getById(elementId); - Integer useCount = examineBasis.getUseCount(); - examineBasis.setUseCount(++useCount); - examineBasisService.updateById(examineBasis); - } - } - - /** - * 工具类: 补0 - */ - private String fullByZero(int i) { - return i < 10 ? "0" + i : String.valueOf(i); - } - @Override public void entrustPrint(String id, HttpServletResponse response) { - Entrust entrust = this.getById(id); List> resultList = new ArrayList<>(); @@ -1967,7 +1783,9 @@ public class EntrustServiceImpl extends BaseServiceImpl } } - // 根据网络图片URL转成字节数组(弃用) + /** + * 根据网络图片URL转成字节数组(弃用) + */ private static byte[] getFileStream(String url) { try { URL httpUrl = new URL(url); @@ -1983,6 +1801,9 @@ public class EntrustServiceImpl extends BaseServiceImpl return null; } + /** + * 读输入流 + */ private static byte[] readInputStream(InputStream inStream) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; @@ -1993,4 +1814,206 @@ public class EntrustServiceImpl extends BaseServiceImpl inStream.close(); return outStream.toByteArray(); } + + /** + * 委托单入库/修改 + */ + private void addOrUpdateEntrust(Entrust entrust, long id) { + if (entrust.getId() != null) { + this.updateById(entrust); + return; + } + entrust.setId(id); + this.save(entrust); + } + + /** + * 是否为合同新增委托单 + */ + private Entrust isContractTypeEntrust(Entrust entrust) { + if (entrust.getContractId() != null) { + entrust.setEntrustType(2); + Contract contract = new Contract(); + contract.setId(entrust.getContractId()); + contract.setStatus(2); + contractService.updateById(contract); + } else { + entrust.setEntrustType(1); + } + return entrust; + } + + /** + * 样品关联数据入库 + */ + private Entrust addSimpleRel(Entrust entrust, long id) { + List rels = new ArrayList<>(); + LocalDateTime now = LocalDateTime.now(); + + String month1 = fullByZero(now.getMonthValue()); + String day1 = fullByZero(now.getDayOfMonth()); + String hour1 = fullByZero(now.getHour()); + + // 检测编号前缀 + String[] strings = entrust.getAcceptanceNum().split("-"); + String s = strings[1] + now.getYear() + month1 + day1 + hour1 + "-"; + + StringBuilder simpleName = new StringBuilder(); + Integer simpleCount = 0; + List> list = entrust.getSimpleNames(); + + // 样品排序 + for (int sort = 1; sort < list.size(); sort++) { + Map map = list.get(sort); + // 样品名称 + String name = (String) map.get("simpleName"); + simpleName.append(name).append(","); + // 样品数量 + Integer count = (Integer) map.get("simpleCount"); + simpleCount += count; + // 原始编号 + String num = (String) map.get("originalNum"); + String[] split = num.split("-"); + int a = Integer.parseInt(split[0]); + + for (int i = 0; i < count; i++) { + SimpleRel simpleRel = new SimpleRel(); + if (entrust.getId() != null) { + simpleRel.setEntrustId(entrust.getId()); + } else { + simpleRel.setEntrustId(id); + } + simpleRel.setSimpleName(name); + simpleRel.setReagentNum(1); + simpleRel.setReagentExperieNum(s + ((a - 1) * 2 + i + 1 + count)); + simpleRel.setExamineNum(1); + simpleRel.setExamineExperieNum(s + ((a - 1) * 2 + i + 1)); + simpleRel.setRecessiveNum((i + a) + ""); + simpleRel.setOriginalNum((i + a) + ""); + simpleRel.setStatus(0); + simpleRel.setSort(sort); + rels.add(simpleRel); + } + } + simpleRelService.saveBatch(rels); + // 委托单内容补充 + entrust.setSimpleName(simpleName.toString()); + entrust.setSimpleCount(simpleCount); + String originalNum = "01-" + fullByZero(simpleCount); + + entrust.setIsDeleted(0); + entrust.setCreateUser(null); + entrust.setUpdateUser(null); + entrust.setEntrustStatus("1"); + entrust.setCreateTime(new Date()); + entrust.setUpdateTime(new Date()); + entrust.setOriginalNum(originalNum); + entrust.setSimpleJson(JSON.toJSONString(entrust.getSimpleNames())); + if (entrust.getSampleReceiverId() != null) { + R userR = userClient.userInfoById(Long.valueOf(entrust.getSampleReceiverId())); + User data = userR.getData(); + if (data != null) { + entrust.setSampleReceiverName(data.getName()); + } + } + return entrust; + } + + /** + * 如果有就取用,没有就新增 + * 有共同点,待抽 + */ + private void addIfNull(Entrust entrust) { + // 送检单位 + EntrustCustomer byId = customerService.getById(entrust.getEntrustCustomerId()); + if (byId != null) { + entrust.setEntrustCustomerName(byId.getName()); + } else { + EntrustCustomer customer = new EntrustCustomer(); + customer.setStatus(1); + customer.setPhone(entrust.getPhone()); + customer.setId(RandomUtils.nextLong()); + customer.setFax(entrust.getFacsimile()); + customer.setEmail(entrust.getPostalCode()); + customer.setFullName(entrust.getSubmittedBy()); + customer.setName(entrust.getEntrustCustomerName()); + customerService.save(customer); + } + + // 采样单位 + EntrustCustomer byId1 = customerService.getById(entrust.getTakeCompanyId()); + if (byId1 != null) { + entrust.setTakeCompany(byId1.getName()); + } else { + EntrustCustomer customer = new EntrustCustomer(); + customer.setStatus(2); + customer.setId(RandomUtils.nextLong()); + customer.setPhone(entrust.getTakePhone()); + customer.setName(entrust.getTakeCompany()); + customer.setFullName(entrust.getTakePerson()); + customer.setAddress(entrust.getTakeCompanyAddress()); + customerService.save(customer); + } + } + + /** + * 新增或修改检验集合 + */ + private void addOrUpdateExamines(List examines, Long entrustId) { + if (CollectionUtils.isNotEmpty(examines)) { + List saveList = new ArrayList<>(); + List updateList = new ArrayList<>(); + for (int i = 0; i < examines.size(); i++) { + Examine examine = examines.get(i); + if (examine.getId() != null) { + updateList.add(examine); + } else { + examine.setStatus(0); + examine.setIsDeleted(0); + examine.setSimpleCount(0); + examine.setExperieNum(""); + examine.setExamineOrder(i + 1); + examine.setEntrustId(entrustId); + examine.setCreateTime(new Date()); + examine.setUpdateTime(new Date()); + saveList.add(examine); + } + // 使用次数 +1 操作 + addUseCount(1, examine.getExamineItemId()); + addUseCount(2, examine.getExamineWayId()); + addUseCount(3, examine.getExamineBasisId()); + } + examineService.saveBatch(saveList); + examineService.updateBatchById(updateList); + } + } + + private void addUseCount(int type, Long elementId) { + if (elementId == null) { return; } + if (type == 1) { + ExamineItem examineItem = examineItemService.getById(elementId); + Integer useCount = examineItem.getUseCount(); + examineItem.setUseCount(++ useCount); + examineItemService.updateById(examineItem); + } + if (type == 2) { + ExamineWay examineWay = examineWayService.getById(elementId); + Integer useCount = examineWay.getUseCount(); + examineWay.setUseCount(++useCount); + examineWayService.updateById(examineWay); + } + if (type == 3) { + ExamineBasis examineBasis = examineBasisService.getById(elementId); + Integer useCount = examineBasis.getUseCount(); + examineBasis.setUseCount(++useCount); + examineBasisService.updateById(examineBasis); + } + } + + /** + * 工具类: 补0 + */ + private String fullByZero(int i) { + return i < 10 ? "0" + i : String.valueOf(i); + } }