From 0184bf471382f9328df9bdd47acf451e4e2c5cb0 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期三, 11 六月 2025 13:57:37 +0800 Subject: [PATCH] 达梦数据库及数据库脚本 --- medicalWaste-system/src/main/java/com/sinata/system/service/biz/ScreenService.java | 261 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 240 insertions(+), 21 deletions(-) diff --git a/medicalWaste-system/src/main/java/com/sinata/system/service/biz/ScreenService.java b/medicalWaste-system/src/main/java/com/sinata/system/service/biz/ScreenService.java index 970b29e..405659c 100644 --- a/medicalWaste-system/src/main/java/com/sinata/system/service/biz/ScreenService.java +++ b/medicalWaste-system/src/main/java/com/sinata/system/service/biz/ScreenService.java @@ -1,20 +1,34 @@ package com.sinata.system.service.biz; +import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson2.JSONArray; import com.sinata.common.exception.ServiceException; import com.sinata.common.utils.BeanUtils; import com.sinata.common.utils.CollUtils; import com.sinata.common.utils.DateUtils; import com.sinata.system.domain.MedicalWasteStaticsVO; import com.sinata.system.domain.MwCollectRecord; +import com.sinata.system.domain.MwTransitCarCollectPoint; +import com.sinata.system.domain.MwWarningRecord; import com.sinata.system.domain.SysDepartment; +import com.sinata.system.domain.vo.CarDistributionVO; +import com.sinata.system.domain.vo.DepartmentTagInfoVO; +import com.sinata.system.domain.vo.MedicalInstitutionCollectListVO; +import com.sinata.system.domain.vo.MedicalWasteCollectVO; +import com.sinata.system.domain.vo.MwWarningRecordStaticsVO; +import com.sinata.system.domain.vo.MwWarningRecordVO; import com.sinata.system.domain.vo.ScreenDepartmentVO; import com.sinata.system.domain.vo.SysDictDataVO; import com.sinata.system.domain.vo.TodayMedicalWastePieVO; import com.sinata.system.domain.vo.TotalCollectWeightByTypeVO; import com.sinata.system.enums.DepartmentEnum; +import com.sinata.system.enums.WarningTypeEnum; import com.sinata.system.service.ISysDictDataService; import com.sinata.system.service.MwCollectRecordService; +import com.sinata.system.service.MwDisposalRecordService; +import com.sinata.system.service.MwTransitCarCollectPointService; +import com.sinata.system.service.MwWarningRecordService; import com.sinata.system.service.SysDepartmentService; import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; @@ -23,6 +37,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; @@ -39,6 +54,9 @@ private final SysDepartmentService sysDepartmentService; private final MwCollectRecordService mwCollectRecordService; private final ISysDictDataService sysDictDataService; + private final MwDisposalRecordService mwDisposalRecordService; + private final MwWarningRecordService mwWarningRecordService; + private final MwTransitCarCollectPointService mwTransitCarCollectPointService; /** * 机构分布-获取机构列表 @@ -51,6 +69,25 @@ return BeanUtils.copyToList(list, ScreenDepartmentVO.class); } + /** + * 获取大屏单位标签信息 + * + * @param id + * @return + */ + public DepartmentTagInfoVO getTagInfo(Long id) { + SysDepartment department = sysDepartmentService.getById(id); + DepartmentTagInfoVO vo = new DepartmentTagInfoVO(); + if (Objects.isNull(department)) { + throw new ServiceException("单位不存在"); + } + if (department.getOrgType().equals(DepartmentEnum.MEDICAL_INSTITUTION.getCode())) { + vo = mwCollectRecordService.getTagInfo(id); + } else { + vo = mwDisposalRecordService.getTagInfo(id); + } + return vo; + } /** * 预警数据统计 * @@ -81,11 +118,8 @@ * @return */ public List<TodayMedicalWastePieVO> todayMedicalWastePie() { - SysDepartment nanNingDepartment = getNanNingDepartment(); - //查询南宁市下面的医疗机构 - List<SysDepartment> list = sysDepartmentService.lambdaQuery().likeRight(SysDepartment::getTreeCode, nanNingDepartment.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.MEDICAL_INSTITUTION.getCode()).list(); - List<Long> departmentIdList = list.stream().map(SysDepartment::getId).collect(Collectors.toList()); List<TodayMedicalWastePieVO> todayMedicalWastePieVOList = new ArrayList<>(); + List<Long> departmentIdList = getNanNingMedicalInsitutionIdList(); if (CollUtils.isEmpty(departmentIdList)) { return todayMedicalWastePieVOList; } @@ -96,25 +130,37 @@ return todayMedicalWastePieVOList; } int total = collectRecordList.size(); - // 分组并统计每个 wasteTypeStr 对应的记录数 - Map<String, Long> resultMap = collectRecordList.stream() - .collect(Collectors.groupingBy(MwCollectRecord::getWasteTypeStr, Collectors.counting())); - - todayMedicalWastePieVOList = resultMap.entrySet().stream().map(entry -> { + //查询医废类型列表 + List<SysDictDataVO> sysDictDataVOS = sysDictDataService.medicalWasteTypeList(); + // 分组并统计每个 wasteType 对应的记录数 + Map<Long, Long> resultMap = collectRecordList.stream() + .collect(Collectors.groupingBy(MwCollectRecord::getWasteType, Collectors.counting())); + todayMedicalWastePieVOList = sysDictDataVOS.stream().map(sysDictDataVO -> { + Long count = resultMap.getOrDefault(sysDictDataVO.getDictCode(), 0L); TodayMedicalWastePieVO todayMedicalWastePieVO = new TodayMedicalWastePieVO(); - todayMedicalWastePieVO.setMedicalWasteStr(entry.getKey()); - todayMedicalWastePieVO.setCount(entry.getValue().intValue()); - todayMedicalWastePieVO.setProportion(BigDecimal.valueOf(entry.getValue()).divide(BigDecimal.valueOf(total), RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100))); + todayMedicalWastePieVO.setMedicalWasteStr(sysDictDataVO.getDictLabel()); + todayMedicalWastePieVO.setCssClass(sysDictDataVO.getCssClass()); + todayMedicalWastePieVO.setCount(count.intValue()); + todayMedicalWastePieVO.setProportion(BigDecimal.valueOf(count).divide(BigDecimal.valueOf(total), 4, RoundingMode.FLOOR).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.FLOOR)); return todayMedicalWastePieVO; }).collect(Collectors.toList()); - return todayMedicalWastePieVOList; } /** + * 南宁市医疗单位id列表 + * + * @return + */ + public List<Long> getNanNingMedicalInsitutionIdList() { + SysDepartment nanNingDepartment = getNanNingDepartment(); + List<SysDepartment> list = sysDepartmentService.lambdaQuery().likeRight(SysDepartment::getTreeCode, nanNingDepartment.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.MEDICAL_INSTITUTION.getCode()).list(); + return list.stream().map(SysDepartment::getId).collect(Collectors.toList()); + } + /** * 各类型医废收集总量 * - * @param type + * @param type 1-按周统计(最近7天),2-按月统计(最近30天) * @return */ public TotalCollectWeightByTypeVO totalCollectWeightByType(Integer type) { @@ -123,17 +169,17 @@ Date startTime = DateUtils.getNowDate(); Date endTime = DateUtils.getNowDate(); if (type.equals(1)) { - //获取最本周的日期 - vo.setDateList(DateUtils.getAllDatesOfCurrentWeek("MM-dd")); - startTime = DateUtils.getFirstDayOfCurrentWeekAtMidnight(); + //按周统计,统计最近7天的数据 + vo.setDateList(DateUtils.getAllDatesOfLastNDays("MM-dd", 7)); + startTime = DateUtils.getFirstDayOfLastNDaysAtMidnight(7); } else { - //最近一个月的日期 - vo.setDateList(DateUtils.getAllDatesOfCurrentMonth("MM-dd")); - startTime = DateUtils.getFirstDayOfCurrentMonthAtMidnight(); + //按月统计,统计最近30天的数据 + vo.setDateList(DateUtils.getAllDatesOfLastNDays("MM-dd", 30)); + startTime = DateUtils.getFirstDayOfLastNDaysAtMidnight(30); } //查询医废类型 List<SysDictDataVO> medicalWasteTypeList = sysDictDataService.medicalWasteTypeList(); - + vo.setWasteTypeList(medicalWasteTypeList); //查询南宁市下面的医疗机构 List<SysDepartment> list = sysDepartmentService.lambdaQuery() .likeRight(SysDepartment::getTreeCode, nanNingDepartment.getTreeCode()) @@ -160,4 +206,177 @@ } return vo; } + + /** + * 医疗机构收集情况 + * + * @return + */ + public List<MedicalInstitutionCollectListVO> medicalInstitutionCollectList() { + // 获取南宁市医疗机构ID列表 + List<Long> nanNingMedicalInstitutionIdList = getNanNingMedicalInsitutionIdList(); + if (CollUtils.isEmpty(nanNingMedicalInstitutionIdList)) { + return CollUtils.emptyList(); + } + + // 查询收集记录 + List<MwCollectRecord> collectRecordList = mwCollectRecordService.lambdaQuery() + .in(MwCollectRecord::getDepartmentId, nanNingMedicalInstitutionIdList) + .list(); + if (CollUtils.isEmpty(collectRecordList)) { + return CollUtils.emptyList(); + } + + // 查询医废类型 + List<SysDictDataVO> medicalWasteTypeList = sysDictDataService.medicalWasteTypeList(); + + // 根据医院分组 + Map<String, List<MwCollectRecord>> recordGroupByDepartment = collectRecordList.stream() + .collect(Collectors.groupingBy(MwCollectRecord::getHospitalName)); + + // 构建结果列表 + return recordGroupByDepartment.entrySet().stream() + .map(entry -> buildMedicalInstitutionCollectVO(entry.getKey(), entry.getValue(), medicalWasteTypeList)) + .collect(Collectors.toList()); + } + + /** + * 构建医疗机构收集情况视图对象 + * + * @param hospitalName + * @param records + * @param medicalWasteTypeList + * @return + */ + private MedicalInstitutionCollectListVO buildMedicalInstitutionCollectVO(String hospitalName, List<MwCollectRecord> records, List<SysDictDataVO> medicalWasteTypeList) { + // 医院基础信息 + MedicalInstitutionCollectListVO vo = new MedicalInstitutionCollectListVO(); + vo.setHospitalName(hospitalName); + + // 根据医废类型分组 + Map<Long, List<MwCollectRecord>> collectRecordGroupByWasteType = records.stream() + .collect(Collectors.groupingBy(MwCollectRecord::getWasteType)); + + // 构建医废类型统计信息 + List<MedicalWasteCollectVO> medicalWasteList = medicalWasteTypeList.stream() + .map(sysDictDataVO -> buildMedicalWasteCollectVO(sysDictDataVO, collectRecordGroupByWasteType)) + .collect(Collectors.toList()); + vo.setMedicalWasteList(medicalWasteList); + + return vo; + } + + /** + * 封装医废类型统计信息 + * + * @param sysDictDataVO + * @param collectRecordGroupByWasteType + * @return + */ + private MedicalWasteCollectVO buildMedicalWasteCollectVO(SysDictDataVO sysDictDataVO, Map<Long, List<MwCollectRecord>> collectRecordGroupByWasteType) { + MedicalWasteCollectVO medicalWasteCollectVO = new MedicalWasteCollectVO(); + medicalWasteCollectVO.setWasteTypeStr(sysDictDataVO.getDictLabel()); + + // 获取当前类型的医废记录 + List<MwCollectRecord> mwCollectRecords = collectRecordGroupByWasteType.getOrDefault(sysDictDataVO.getDictCode(), CollUtils.emptyList()); + medicalWasteCollectVO.setCssClass(sysDictDataVO.getCssClass()); + medicalWasteCollectVO.setBagNum(mwCollectRecords.size()); + medicalWasteCollectVO.setWeight(mwCollectRecords.stream() + .map(MwCollectRecord::getWeight) + .reduce(BigDecimal.ZERO, BigDecimal::add)); + return medicalWasteCollectVO; + } + + /** + * 预警记录统计 + * + * @return + */ + public List<MwWarningRecordStaticsVO> warningRecordStaticsList() { + SysDepartment nanNingDepartment = getNanNingDepartment(); + //查询南宁的所有单位 + List<SysDepartment> list = sysDepartmentService.lambdaQuery() + .likeRight(SysDepartment::getTreeCode, nanNingDepartment.getTreeCode()) + .in(SysDepartment::getOrgType, DepartmentEnum.MEDICAL_INSTITUTION.getCode(), DepartmentEnum.DISPOSAL_UNIT.getCode()).list(); + if (CollUtils.isEmpty(list)) { + return CollUtils.emptyList(); + } + List<Long> departmentIds = list.stream().map(SysDepartment::getId).collect(Collectors.toList()); + List<MwWarningRecord> warningRecordList = mwWarningRecordService.lambdaQuery().in(MwWarningRecord::getDepartmentId, departmentIds).list(); + if (CollUtils.isEmpty(warningRecordList)) { + return CollUtils.emptyList(); + } + return Arrays.stream(WarningTypeEnum.values()).map(item -> buildWarningRecordStaticsVO(item, warningRecordList)).collect(Collectors.toList()); + } + + /** + * 构建预警记录统计视图对象 + * + * @param item + * @param warningRecordList + * @return + */ + private MwWarningRecordStaticsVO buildWarningRecordStaticsVO(WarningTypeEnum item, List<MwWarningRecord> warningRecordList) { + MwWarningRecordStaticsVO vo = new MwWarningRecordStaticsVO(); + vo.setType(item.getCode()); + vo.setTypeName(item.getDesc()); + vo.setCount(warningRecordList.stream().filter(record -> record.getType().equals(item.getCode())).count()); + return vo; + } + + /** + * 根据预警类型查询预警详情 + * + * @param type + * @return + */ + public List<MwWarningRecordVO> queryWarningRecordDetailByType(Integer type) { + SysDepartment nanNingDepartment = getNanNingDepartment(); + //查询南宁市所有单位信息 + List<SysDepartment> list = sysDepartmentService.lambdaQuery().likeRight(SysDepartment::getTreeCode, nanNingDepartment.getTreeCode()).list(); + if (CollUtils.isEmpty(list)) { + return CollUtils.emptyList(); + } + List<Long> departmentIds = list.stream().map(SysDepartment::getId).collect(Collectors.toList()); + List<MwWarningRecord> warningRecordList = mwWarningRecordService.lambdaQuery().in(MwWarningRecord::getDepartmentId, departmentIds).eq(MwWarningRecord::getType, type).list(); + return BeanUtils.copyToList(warningRecordList, MwWarningRecordVO.class); + } + + /** + * 车辆分布 + * + * @return + */ + public List<CarDistributionVO> queryCarDistribution() { + SysDepartment nanNingDepartment = getNanNingDepartment(); + //查询车辆分布列表 + List<CarDistributionVO> carDistributionVOS = mwTransitCarCollectPointService.queryCarListByTreeCode(nanNingDepartment.getTreeCode()); + if (CollUtils.isNotEmpty(carDistributionVOS)) { + for (CarDistributionVO carDistributionVO : carDistributionVOS) { + MwTransitCarCollectPoint point = mwTransitCarCollectPointService.lambdaQuery().eq(MwTransitCarCollectPoint::getCarId, carDistributionVO.getId()).eq(MwTransitCarCollectPoint::getTransitDate, DateUtil.format(DateUtil.date(), DatePattern.NORM_DATE_PATTERN)).last("LIMIT 1").one(); + if (Objects.nonNull(point)) { + String pointList = point.getPointList(); + List<Long> pointIdList = JSONArray.parseArray(pointList, Long.class); + if (CollUtils.isNotEmpty(pointIdList)) { + //查询最后一个点位 + SysDepartment department = sysDepartmentService.getById(pointIdList.get(pointIdList.size() - 1)); + carDistributionVO.setLatitude(department.getLatitude()); + carDistributionVO.setLongitude(department.getLongitude()); + } + } + } + + } + return carDistributionVOS; + } + + /** + * 车辆分布详情 + * + * @param id + * @return + */ + public CarDistributionVO queryCarDistributionDetail(Long id) { + return mwTransitCarCollectPointService.queryCarDistributionDetail(id); + } } -- Gitblit v1.7.1