From 3115d589ca3faaecda604e2a66fe193a93ba9cbc Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期一, 30 十二月 2024 21:42:57 +0800 Subject: [PATCH] 1.bug修改 2.出库超时预警定时任务 --- medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java | 128 ++++++++++++++++++++++++++++++++++++++---- 1 files changed, 116 insertions(+), 12 deletions(-) diff --git a/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java b/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java index 7eb9c8f..368c4fc 100644 --- a/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java +++ b/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java @@ -25,6 +25,7 @@ import com.sinata.system.service.ISysDictDataService; import com.sinata.system.service.MwCheckoutRecordService; import com.sinata.system.service.MwCollectRecordService; +import com.sinata.system.service.MwDisposalHandleRecordService; import com.sinata.system.service.MwDisposalRecordService; import com.sinata.system.service.MwWarningRecordService; import com.sinata.system.service.SysDepartmentService; @@ -41,6 +42,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -57,6 +59,7 @@ private final MwWarningRecordService mwWarningRecordService; private final HttpServletResponse response; private final MwDisposalRecordService mwDisposalRecordService; + private final MwDisposalHandleRecordService mwDisposalHandleRecordService; /** * 机构分布-获取机构列表 @@ -80,6 +83,10 @@ */ public DepartmentReportVO hospitalReport(HospitalReportQuery query) { DepartmentReportVO vo = new DepartmentReportVO(); + SysDepartment department = sysDepartmentService.getById(query.getDepartmentId()); + if (Objects.nonNull(department)) { + vo.setDepartmentName(department.getDepartmentName()); + } List<SysDictDataVO> wasteTypeList = sysDictDataService.medicalWasteTypeList(); if (CollUtils.isEmpty(wasteTypeList)) { @@ -133,13 +140,17 @@ totalCount = totalCount.add(currentCount); totalWeight = totalWeight.add(weight); } + itemVO.getData().add(totalCount); + itemVO.getData().add(totalWeight); //查询预警记录判断是否超时 if (query.getDateType().equals(1)) { itemVO.setOverTimeFlag("否"); List<Long> collectIdList = collectRecordList.stream().filter(e -> finalSdf.format(e.getCollectTime()).equals(date)).map(MwCollectRecord::getId).collect(Collectors.toList()); - List<MwWarningRecord> warningRecordList = mwWarningRecordService.lambdaQuery().in(MwWarningRecord::getWarningTargetId, collectIdList).list(); - if (CollUtils.isNotEmpty(warningRecordList)) { - itemVO.setOverTimeFlag("是"); + if (CollUtils.isNotEmpty(collectIdList)) { + List<MwWarningRecord> warningRecordList = mwWarningRecordService.lambdaQuery().in(MwWarningRecord::getWarningTargetId, collectIdList).list(); + if (CollUtils.isNotEmpty(warningRecordList)) { + itemVO.setOverTimeFlag("是"); + } } } list.add(itemVO); @@ -222,6 +233,9 @@ public DepartmentReportVO transformList(TransformQuery query) { DepartmentReportVO vo = new DepartmentReportVO(); SysDepartment department = sysDepartmentService.getById(query.getDepartmentId()); + if (Objects.nonNull(department)) { + vo.setDepartmentName(department.getDepartmentName()); + } SysDepartment region = sysDepartmentService.getDepartmentByParentId(department.getParentId()); List<SysDepartment> hospitalList = sysDepartmentService.lambdaQuery().likeRight(SysDepartment::getTreeCode, region.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.MEDICAL_INSTITUTION.getCode()).list(); if (CollUtils.isNotEmpty(hospitalList)) { @@ -332,10 +346,14 @@ */ public DepartmentReportVO disposalReport(DisposalReportQuery query) { DepartmentReportVO vo = new DepartmentReportVO(); + SysDepartment department = sysDepartmentService.getById(query.getDepartmentId()); + if (Objects.nonNull(department)) { + vo.setDepartmentName(department.getDepartmentName()); + } //已接收 - List<MwDisposalRecordReportVO> receivedList = mwDisposalRecordService.disposalReportByType(query, 1); + List<MwDisposalRecordReportVO> receivedList = mwDisposalRecordService.disposalReceiveReport(query); //已处置 - List<MwDisposalRecordReportVO> disposaledList = mwDisposalRecordService.disposalReportByType(query, 2); + List<MwDisposalRecordReportVO> disposaledList = mwDisposalHandleRecordService.disposalReport(query); SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS); switch (query.getDateType()) { case 1: @@ -445,17 +463,25 @@ headTitles.add(Lists.newArrayList("日期")); wasteTypeList.forEach(item -> { headTitles.add(Lists.newArrayList("医疗废物接收量(kg)", item.getDictLabel())); - headTitles.add(Lists.newArrayList("医疗废物接收量(kg)", item.getDictLabel())); }); wasteTypeList.forEach(item -> { - headTitles.add(Lists.newArrayList("医疗废物处置量(kg)", item.getDictLabel())); headTitles.add(Lists.newArrayList("医疗废物处置量(kg)", item.getDictLabel())); }); return headTitles; } + /** + * 监管报表 + * + * @param query + * @return + */ public DepartmentReportVO regulationReport(DisposalReportQuery query) { DepartmentReportVO vo = new DepartmentReportVO(); + SysDepartment department = sysDepartmentService.getById(query.getDepartmentId()); + if (Objects.nonNull(department)) { + vo.setDepartmentName(department.getDepartmentName()); + } //医废产生量 List<MwCollectRecordVO> collectRecordList = mwCollectRecordService.getRegulationReportList(query); //医废转移量 @@ -480,16 +506,94 @@ if (CollUtils.isNotEmpty(wasteTypeList)) { vo.setLegend(wasteTypeList.stream().map(SysDictData::getDictLabel).collect(Collectors.toList())); vo.setList(new ArrayList<>()); + List<DepartmentReportItemVO> list = new ArrayList<>(); for (String date : dateList) { DepartmentReportItemVO departmentReportItemVO = new DepartmentReportItemVO(); departmentReportItemVO.setName(date); + departmentReportItemVO.setData(new ArrayList<>()); SimpleDateFormat finalSdf = sdf; for (SysDictData sysDictData : wasteTypeList) { - collectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && finalSdf.format(e.getCollectTime()).equals(date)).map(MwCollectRecordVO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add); - } - } - } + BigDecimal weight = collectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && + finalSdf.format(e.getCollectTime()).equals(date)).map(MwCollectRecordVO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add); + departmentReportItemVO.getData().add(weight); - return null; + } + for (SysDictData sysDictData : wasteTypeList) { + BigDecimal weight = checkoutRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && + finalSdf.format(e.getCollectTime()).equals(date)).map(MwCollectRecordVO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add); + departmentReportItemVO.getData().add(weight); + } + for (SysDictData sysDictData : wasteTypeList) { + BigDecimal weight = disposalRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && + finalSdf.format(e.getCollectTime()).equals(date)).map(MwCollectRecordVO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add); + departmentReportItemVO.getData().add(weight); + } + list.add(departmentReportItemVO); + } + vo.setList(list); + } + return vo; + } + + public void regulationReportExport(DisposalReportQuery query) throws IOException { + List<List<String>> head = regulationReportHead(query.getWasteTypeCodeList()); + System.out.println(JSONObject.toJSONString(head)); + // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 + String fileName = URLEncoder.encode("监管报表", "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + // 这里需要设置不关闭流 + FastExcel.write(response.getOutputStream()) + .head(head) + .autoCloseStream(Boolean.TRUE) + .sheet("监管报表") + .doWrite(getRegulationReportStaticsData(query)); + } + + /** + * 监管报表导出数据 + * + * @param query + * @return + */ + private List<List<Object>> getRegulationReportStaticsData(DisposalReportQuery query) { + DepartmentReportVO vo = regulationReport(query); + List<DepartmentReportItemVO> list = vo.getList(); + if (CollUtils.isNotEmpty(list)) { + List<List<Object>> result = new ArrayList<>(); + for (DepartmentReportItemVO departmentReportItemVO : list) { + List<Object> data = new ArrayList<>(); + data.add(departmentReportItemVO.getName()); + data.addAll(departmentReportItemVO.getData()); + result.add(data); + } + return result; + } + return CollUtils.emptyList(); + } + + /** + * 监管报表表头 + * + * @param wasteTypeCodeList + * @return + */ + private List<List<String>> regulationReportHead(List<Long> wasteTypeCodeList) { + //查询医废类型 + List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList).list(); + List<List<String>> headTitles = Lists.newArrayList(); + headTitles.add(Lists.newArrayList("日期")); + wasteTypeList.forEach(item -> { + headTitles.add(Lists.newArrayList("医疗废物产生量(kg)", item.getDictLabel())); + }); + wasteTypeList.forEach(item -> { + headTitles.add(Lists.newArrayList("医疗废物转移量(kg)", item.getDictLabel())); + }); + wasteTypeList.forEach(item -> { + headTitles.add(Lists.newArrayList("医疗废物处置量(kg)", item.getDictLabel())); + }); + return headTitles; } } -- Gitblit v1.7.1