| | |
| | | serviceDonatebaseinfo.setDeptid(user.getDeptId()); |
| | | } |
| | | List<ServiceDonatebaseinfo> serviceDonatebaseinfos = serviceDonatebaseinfoMapper.selectServiceDonatebaseinfoList(serviceDonatebaseinfo); |
| | | |
| | | // 一次性取出各捐献基础对应的死亡时间,避免在循环里按 InfoID 逐条查见证表(N+1) |
| | | List<Long> infoIds = new ArrayList<>(); |
| | | for (ServiceDonatebaseinfo item : serviceDonatebaseinfos) { |
| | | if (item.getId() != null) { |
| | | infoIds.add(item.getId()); |
| | | } |
| | | } |
| | | Map<Long, Date> deathTimeMap = new HashMap<>(); |
| | | if (!infoIds.isEmpty()) { |
| | | for (ServiceDonationwitness witness : serviceDonationwitnessMapper.selectDeathTimeByInfoIds(infoIds)) { |
| | | if (witness.getInfoid() != null && !deathTimeMap.containsKey(witness.getInfoid())) { |
| | | deathTimeMap.put(witness.getInfoid(), witness.getDeathtime()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | for (ServiceDonatebaseinfo serviceDonatebaseinfo1 : serviceDonatebaseinfos) { |
| | | //先给个年龄默认值(因为age是数字类型,不能放横杠,所以就所横扛放到单位上) |
| | | serviceDonatebaseinfo1.setAgeunit("-"); |
| | |
| | | serviceDonatebaseinfo1.setAge2(null); |
| | | |
| | | //获取死亡时间,如果获取见证里有死亡时间,则进行计算他的年龄 |
| | | ServiceDonationwitness sdw = new ServiceDonationwitness(); |
| | | sdw.setInfoid(serviceDonatebaseinfo1.getId()); |
| | | List<ServiceDonationwitness> serviceDonationwitnessList = serviceDonationwitnessMapper.selectServiceDonationwitnessList(sdw); |
| | | if (!CollectionUtils.isEmpty(serviceDonationwitnessList) && serviceDonatebaseinfo1.getBirthday() != null) { |
| | | Date deathtime = serviceDonationwitnessList.get(0).getDeathtime(); |
| | | if (ObjectUtils.isNotEmpty(deathtime)) { |
| | | Date deathtime = deathTimeMap.get(serviceDonatebaseinfo1.getId()); |
| | | if (ObjectUtils.isNotEmpty(deathtime) && serviceDonatebaseinfo1.getBirthday() != null) { |
| | | Map<String, String> map = CalculateDateUtils.calculateAge(serviceDonatebaseinfo1.getBirthday().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), deathtime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); |
| | | if (Objects.isNull(map)) { |
| | | log.error("ServiceDonationwitness出生日期:{},ServiceDonationwitness死亡日期:{}", serviceDonatebaseinfo1.getBirthday(), deathtime); |
| | |
| | | serviceDonatebaseinfo1.setAgeunit(map.get("ageUnit")); |
| | | serviceDonatebaseinfo1.setAge2(org.apache.commons.lang3.ObjectUtils.isNotEmpty(map.get("age2")) ? Long.valueOf(map.get("age2")) : null); |
| | | serviceDonatebaseinfo1.setAgeunit2(map.get("ageUnit2")); |
| | | } |
| | | } |
| | | |
| | | } |