| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | |
| | | } |
| | | List<EthicalReviewVO> ethicalReviewVOS = serviceEthicalreviewopinionsMapper.selectVOList(ethicalReviewVO); |
| | | |
| | | // 一次性取出各捐献基础对应的死亡时间,避免在循环里按捐献基础ID逐条查见证表(N+1) |
| | | List<Long> infoIds = new ArrayList<>(); |
| | | for (EthicalReviewVO item : ethicalReviewVOS) { |
| | | 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 (EthicalReviewVO ethicalReviewVO1 : ethicalReviewVOS) { |
| | | //先给个年龄默认值(因为age是数字类型,不能放横杠,所以就所横扛放到单位上) |
| | | ethicalReviewVO1.setAgeunit("-"); |
| | | ethicalReviewVO1.setAge(null); |
| | | ethicalReviewVO1.setAge2(null); |
| | | //获取死亡时间,如果获取见证里有死亡时间,则进行计算他的年龄 |
| | | ServiceDonationwitness sdw = new ServiceDonationwitness(); |
| | | sdw.setInfoid(ethicalReviewVO1.getId()); |
| | | List<ServiceDonationwitness> serviceDonationwitnessList = serviceDonationwitnessMapper.selectServiceDonationwitnessList(sdw); |
| | | if (!CollectionUtils.isEmpty(serviceDonationwitnessList) && ethicalReviewVO1.getBirthday() != null) { |
| | | Date deathtime = serviceDonationwitnessList.get(0).getDeathtime(); |
| | | if (ObjectUtils.isNotEmpty(deathtime)) { |
| | | Map<String, String> map = CalculateDateUtils.calculateAge(ethicalReviewVO1.getBirthday().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), deathtime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); |
| | | if (ObjectUtils.isEmpty(map)) { |
| | | log.error("EthicalReviewVO出生日期:{},EthicalReviewVO死亡日期:{}", ethicalReviewVO1.getBirthday(), deathtime); |
| | | continue; |
| | | } |
| | | ethicalReviewVO1.setAge(org.apache.commons.lang3.ObjectUtils.isNotEmpty(map.get("age")) ? Long.valueOf(map.get("age")) : null); |
| | | ethicalReviewVO1.setAgeunit(map.get("ageUnit")); |
| | | ethicalReviewVO1.setAge2(org.apache.commons.lang3.ObjectUtils.isNotEmpty(map.get("age2")) ? Long.valueOf(map.get("age2")) : null); |
| | | ethicalReviewVO1.setAgeunit2(map.get("ageUnit2")); |
| | | Date deathtime = deathTimeMap.get(ethicalReviewVO1.getId()); |
| | | if (ObjectUtils.isNotEmpty(deathtime) && ethicalReviewVO1.getBirthday() != null) { |
| | | Map<String, String> map = CalculateDateUtils.calculateAge(ethicalReviewVO1.getBirthday().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), deathtime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); |
| | | if (ObjectUtils.isEmpty(map)) { |
| | | log.error("EthicalReviewVO出生日期:{},EthicalReviewVO死亡日期:{}", ethicalReviewVO1.getBirthday(), deathtime); |
| | | continue; |
| | | } |
| | | ethicalReviewVO1.setAge(org.apache.commons.lang3.ObjectUtils.isNotEmpty(map.get("age")) ? Long.valueOf(map.get("age")) : null); |
| | | ethicalReviewVO1.setAgeunit(map.get("ageUnit")); |
| | | ethicalReviewVO1.setAge2(org.apache.commons.lang3.ObjectUtils.isNotEmpty(map.get("age2")) ? Long.valueOf(map.get("age2")) : null); |
| | | ethicalReviewVO1.setAgeunit2(map.get("ageUnit2")); |
| | | } |
| | | |
| | | } |