| | |
| | | package cn.lihu.jh.module.ecg.service.jobrecord; |
| | | |
| | | import cn.lihu.jh.module.ecg.controller.admin.appointment.vo.AppointmentRespVO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.appointment.AppointmentDO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.devrent.DevRentDO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.jobrecord.JobRecordStatisticDO; |
| | | import cn.lihu.jh.module.ecg.dal.mysql.appointment.AppointmentMapper; |
| | | import cn.lihu.jh.module.ecg.dal.mysql.devrent.DevRentMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import cn.lihu.jh.module.ecg.controller.admin.jobrecord.vo.*; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.jobrecord.JobRecordDO; |
| | |
| | | import javax.annotation.Resource; |
| | | |
| | | import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.lihu.jh.framework.common.pojo.CommonResult.success; |
| | | import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | |
| | | |
| | | @Resource |
| | | private JobRecordMapper jobRecordMapper; |
| | | |
| | | @Resource |
| | | private DevRentMapper devRentMapper; |
| | | |
| | | @Resource |
| | | private AppointmentMapper appointmentMapper; |
| | | |
| | | @Override |
| | | public Long createJobRecord(JobRecordSaveReqVO createReqVO) { |
| | |
| | | |
| | | @Override |
| | | public JobRecordDO getJobRecord(Long id) { |
| | | return jobRecordMapper.selectById(id); |
| | | JobRecordDO jobRecordDO = jobRecordMapper.selectById(id); |
| | | if (null != jobRecordDO) { |
| | | fillPatientInfo(java.util.Collections.singletonList(jobRecordDO)); |
| | | } |
| | | return jobRecordDO; |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<JobRecordDO> getJobRecordPage(JobRecordPageReqVO pageReqVO) { |
| | | return jobRecordMapper.selectPage(pageReqVO); |
| | | PageResult<JobRecordDO> pageResult = jobRecordMapper.selectPage(pageReqVO); |
| | | |
| | | List<JobRecordDO> jobRecordDOList = pageResult.getList(); |
| | | if ( !jobRecordDOList.isEmpty() ) { |
| | | List<Long> rentIdList = jobRecordDOList.stream().map(item -> item.getRentId()).toList(); |
| | | List<Integer> paidInfoList = devRentMapper.getPaidInfo(rentIdList); |
| | | for (int i = 0; i < jobRecordDOList.size(); i++) { |
| | | jobRecordDOList.get(i).setPaid(paidInfoList.get(i)); |
| | | } |
| | | // 需求1:回填患者信息(批量,避免 N+1) |
| | | fillPatientInfo(jobRecordDOList); |
| | | } |
| | | |
| | | return pageResult; |
| | | } |
| | | |
| | | // ==================== 需求1:回填患者信息 18 项 ==================== |
| | | // 回填链路(三级): |
| | | // job_record.rentId → dev_rent.applyNo → appointment |
| | | // 之所以不用逐条 getByApplyNo:job_record 列表页一次可能返回几十条, |
| | | // 逐条查会形成 N+1。这里改为「批量取 dev_rent」+「批量取 appointment」。 |
| | | |
| | | private void fillPatientInfo(List<JobRecordDO> jobRecordDOList) { |
| | | if (null == jobRecordDOList || jobRecordDOList.isEmpty()) { |
| | | return; |
| | | } |
| | | // 1) 批量取 dev_rent,拿到 applyNo |
| | | List<Long> rentIdList = jobRecordDOList.stream() |
| | | .map(JobRecordDO::getRentId) |
| | | .filter(java.util.Objects::nonNull) |
| | | .distinct() |
| | | .toList(); |
| | | if (rentIdList.isEmpty()) { |
| | | return; |
| | | } |
| | | Map<Long, String> applyNoByRentId = new HashMap<>(); |
| | | // 一次 IN 查询取全部 applyNo(原先逐条 selectById → N 次查询) |
| | | List<DevRentDO> devRentDOList = devRentMapper.getApplyNoByIdList(rentIdList); |
| | | if (null != devRentDOList) { |
| | | devRentDOList.forEach(d -> { |
| | | if (null != d && null != d.getId() |
| | | && org.springframework.util.StringUtils.hasText(d.getApplyNo())) { |
| | | applyNoByRentId.put(d.getId(), d.getApplyNo()); |
| | | } |
| | | }); |
| | | } |
| | | if (applyNoByRentId.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | // 2) 批量取 appointment(一次 IN 查询) |
| | | List<String> applyNoList = applyNoByRentId.values().stream().distinct().toList(); |
| | | Map<String, AppointmentDO> appointmentByApplyNo = new HashMap<>(); |
| | | List<AppointmentDO> appointmentDOList = appointmentMapper.getByApplyNoList(applyNoList); |
| | | if (null != appointmentDOList) { |
| | | appointmentDOList.forEach(a -> { |
| | | if (null != a && org.springframework.util.StringUtils.hasText(a.getApplyNo())) { |
| | | appointmentByApplyNo.put(a.getApplyNo(), a); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 3) 回填 |
| | | jobRecordDOList.forEach(jobRecordDO -> { |
| | | if (null == jobRecordDO || null == jobRecordDO.getRentId()) { |
| | | return; |
| | | } |
| | | String applyNo = applyNoByRentId.get(jobRecordDO.getRentId()); |
| | | if (null == applyNo) { |
| | | return; |
| | | } |
| | | AppointmentDO appointment = appointmentByApplyNo.get(applyNo); |
| | | if (null == appointment) { |
| | | return; |
| | | } |
| | | jobRecordDO.setApplyNo(applyNo); |
| | | jobRecordDO.setEpisodeId(appointment.getEpisodeId()); |
| | | jobRecordDO.setPatGender(appointment.getPatGender()); |
| | | jobRecordDO.setPatBirthday(appointment.getPatBirthday()); |
| | | jobRecordDO.setRegisterDate(appointment.getRegisterDate()); |
| | | jobRecordDO.setDoctor(appointment.getDoctor()); |
| | | jobRecordDO.setDoctorTime(appointment.getDoctorTime()); |
| | | jobRecordDO.setPatSrc(appointment.getPatSrc()); |
| | | jobRecordDO.setPatMobile(appointment.getPatMobile()); |
| | | jobRecordDO.setPatPhone(appointment.getPatPhone()); |
| | | jobRecordDO.setPatWardDesc(appointment.getPatWardDesc()); |
| | | jobRecordDO.setPatBedNo(appointment.getPatBedNo()); |
| | | jobRecordDO.setMedicalCard(appointment.getMedicalCard()); |
| | | jobRecordDO.setDoctorAdviceNo(appointment.getDoctorAdviceNo()); |
| | | jobRecordDO.setOutpatientNo(appointment.getOutpatientNo()); |
| | | jobRecordDO.setPatIdentityId(appointment.getPatIdentityId()); |
| | | jobRecordDO.setTolerance(appointment.getTolerance()); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public List<JobRecordStatisticDO> getJobStatistic(LocalDateTime jobTimeFrom, LocalDateTime jobTimeTo) { |
| | | |
| | | return jobRecordMapper.getJobStatistic(jobTimeFrom, jobTimeTo); |
| | | } |
| | | |
| | | } |