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 | 94 +++++++++++++++++++++++++++++++--------------- 1 files changed, 63 insertions(+), 31 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 f4878b3..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,12 +1,15 @@ 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; @@ -74,7 +77,7 @@ */ public DepartmentTagInfoVO getTagInfo(Long id) { SysDepartment department = sysDepartmentService.getById(id); - DepartmentTagInfoVO vo = null; + DepartmentTagInfoVO vo = new DepartmentTagInfoVO(); if (Objects.isNull(department)) { throw new ServiceException("单位不存在"); } @@ -127,18 +130,20 @@ 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; } @@ -155,7 +160,7 @@ /** * 各类型医废收集总量 * - * @param type + * @param type 1-按周统计(最近7天),2-按月统计(最近30天) * @return */ public TotalCollectWeightByTypeVO totalCollectWeightByType(Integer type) { @@ -164,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()) @@ -273,16 +278,12 @@ medicalWasteCollectVO.setWasteTypeStr(sysDictDataVO.getDictLabel()); // 获取当前类型的医废记录 - List<MwCollectRecord> mwCollectRecords = collectRecordGroupByWasteType.get(sysDictDataVO.getDictCode()); - if (CollUtils.isNotEmpty(mwCollectRecords)) { - medicalWasteCollectVO.setBagNum(mwCollectRecords.size()); - medicalWasteCollectVO.setWeight(mwCollectRecords.stream() - .map(MwCollectRecord::getWeight) - .reduce(BigDecimal.ZERO, BigDecimal::add)); - } else { - medicalWasteCollectVO.setBagNum(0); - medicalWasteCollectVO.setWeight(BigDecimal.ZERO); - } + 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; } @@ -293,7 +294,15 @@ */ public List<MwWarningRecordStaticsVO> warningRecordStaticsList() { SysDepartment nanNingDepartment = getNanNingDepartment(); - List<MwWarningRecord> warningRecordList = mwWarningRecordService.lambdaQuery().eq(MwWarningRecord::getDepartmentId, nanNingDepartment.getId()).list(); + //查询南宁的所有单位 + 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(); } @@ -323,7 +332,13 @@ */ public List<MwWarningRecordVO> queryWarningRecordDetailByType(Integer type) { SysDepartment nanNingDepartment = getNanNingDepartment(); - List<MwWarningRecord> warningRecordList = mwWarningRecordService.lambdaQuery().eq(MwWarningRecord::getDepartmentId, nanNingDepartment.getId()).eq(MwWarningRecord::getType, type).list(); + //查询南宁市所有单位信息 + 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); } @@ -335,7 +350,24 @@ public List<CarDistributionVO> queryCarDistribution() { SysDepartment nanNingDepartment = getNanNingDepartment(); //查询车辆分布列表 - return mwTransitCarCollectPointService.queryCarListByTreeCode(nanNingDepartment.getTreeCode()); + 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; } /** -- Gitblit v1.7.1