修复机构BUG

This commit is contained in:
Flow 2025-05-04 14:34:58 +08:00
parent 7b0f85ed56
commit 9e2a530ce9
3 changed files with 68 additions and 34 deletions

View File

@ -1907,19 +1907,9 @@ public class InspectPatientController {
@Operation(summary = "根据日期获取卫生院体检统计")
public CommonResult<List<WorkloadStatisticsVO>> getWorkload(@RequestParam("dates") @DateTimeFormat(pattern = "yyyy-MM-dd") List<LocalDate> dates,
@RequestParam(value = "examhosname", required = false) String examhosname) {
// 获取指定日期范围内的所有患者补充信息
List<PatientSupplementVO> supplements = patientService.getPatientSupplementsByDates(dates);
// 获取指定日期范围内的所有患者补充信息如果有医院名称则在数据库层面直接过滤
List<PatientSupplementVO> supplements = patientService.getPatientSupplementsByDatesAndHospital(dates, examhosname);
// 医院名称过滤
// - 若examhosname为null"null"字符串或空字符串则不过滤保留所有记录
// - 若examhosname有有效值则只保留匹配该医院名称的记录
if (examhosname != null && !examhosname.isEmpty() && !"null".equals(examhosname)) {
supplements = supplements.stream()
.filter(s -> examhosname.equals(s.getOrgname()))
.collect(Collectors.toList());
}
// 否则保持原有supplements不变
// 使用Map来存储统计结果key为卫生院名称+行政村名称
Map<String, WorkloadStatisticsVO> statisticsMap = new HashMap<>();

View File

@ -163,6 +163,15 @@ public interface InspectPatientService {
* @return 患者补充信息列表
*/
List<PatientSupplementVO> getPatientSupplementsByDates(List<LocalDate> dates);
/**
* 根据日期列表和医院名称获取患者补充信息
*
* @param dates 日期列表
* @param examhosname 医院名称可选
* @return 患者补充信息列表
*/
List<PatientSupplementVO> getPatientSupplementsByDatesAndHospital(List<LocalDate> dates, String examhosname);
void exportStatistics(List<LocalDate> dates, HttpServletResponse response);

View File

@ -22,7 +22,6 @@ import freemarker.template.Configuration;
import freemarker.template.Template;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xwpf.usermodel.*;
import org.jodconverter.DocumentConverter;
import org.jodconverter.LocalConverter;
@ -817,21 +816,50 @@ public class InspectPatientServiceImpl implements InspectPatientService {
return Collections.emptyList();
}
// 使用批量转换避免循环中多次创建对象
return patients.stream()
.map(patient -> {
PatientSupplementVO vo = new PatientSupplementVO();
vo.setMedicalSn(patient.getMedicalSn());
vo.setOrgname(patient.getOrgname());
vo.setDistrictname(patient.getDistrictname());
vo.setOldmanflag(patient.getOldmanflag());
vo.setHtnflag(patient.getHtnflag());
vo.setDiaflag(patient.getDiaflag());
vo.setSmiflag(patient.getSmiflag());
vo.setPulflag(patient.getPulflag());
return vo;
})
.collect(Collectors.toList());
// 转换为 PatientSupplementVO 对象
return BeanUtils.toBean(patients, PatientSupplementVO.class);
}
@Override
public List<PatientSupplementVO> getPatientSupplementsByDatesAndHospital(List<LocalDate> dates, String examhosname) {
if (dates == null || dates.isEmpty() || dates.size() < 2) {
return Collections.emptyList();
}
// 获取起始日期和结束日期
LocalDate startDate = dates.get(0);
LocalDate endDate = dates.get(1);
// 构建查询条件只查询必要的字段
LambdaQueryWrapper<InspectPatientDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.select(
InspectPatientDO::getMedicalSn,
InspectPatientDO::getOrgname,
InspectPatientDO::getDistrictname,
InspectPatientDO::getOldmanflag,
InspectPatientDO::getHtnflag,
InspectPatientDO::getDiaflag,
InspectPatientDO::getSmiflag,
InspectPatientDO::getPulflag
)
.eq(InspectPatientDO::getIsprint, 1)
.between(InspectPatientDO::getPrinttime, startDate.atStartOfDay(), endDate.atTime(23, 59, 59));
// 如果医院名称有效添加筛选条件
if (examhosname != null && !examhosname.isEmpty() && !"null".equals(examhosname)) {
queryWrapper.eq(InspectPatientDO::getExamhosname, examhosname);
}
// 查询患者信息
List<InspectPatientDO> patients = patientMapper.selectList(queryWrapper);
if (patients == null || patients.isEmpty()) {
return Collections.emptyList();
}
// 转换为 PatientSupplementVO 对象
return BeanUtils.toBean(patients, PatientSupplementVO.class);
}
/**
@ -869,6 +897,9 @@ public class InspectPatientServiceImpl implements InspectPatientService {
// 使用Map来存储统计结果key为卫生院名称+行政村名称
Map<String, WorkloadStatisticsVO> statisticsMap = new HashMap<>();
// 使用Set来记录已经统计过的患者ID避免重复统计
Set<String> countedPatients = new HashSet<>();
// 遍历所有补充信息进行统计
for (PatientSupplementVO supplement : supplements) {
@ -885,8 +916,17 @@ public class InspectPatientServiceImpl implements InspectPatientService {
vo.setSum(0);
return vo;
});
// 获取患者体检编号
String patientId = supplement.getMedicalSn();
// 统计各项数量但每个人只统计一次
if (!countedPatients.contains(patientId)) {
countedPatients.add(patientId);
statistics.setSum(statistics.getSum() + 1); // 总数加1
}
// 统计各项数量
// 统计具体指标
if ("1".equals(supplement.getOldmanflag())) {
statistics.setOldmanflag(statistics.getOldmanflag() + 1);
}
@ -902,11 +942,6 @@ public class InspectPatientServiceImpl implements InspectPatientService {
if ("1".equals(supplement.getPulflag())) {
statistics.setPulflag(statistics.getPulflag() + 1);
}
// 计算总数
statistics.setSum(statistics.getOldmanflag() + statistics.getHtnflag() +
statistics.getDiaflag() + statistics.getSmiflag() +
statistics.getPulflag());
}
// excel数据