|
@@ -46,126 +46,119 @@ public class IsolateFacade extends IsolateServiceImpl {
|
|
|
*/
|
|
|
public List<IsolateDTO> getIsolate(InputVO inputVO) {
|
|
|
List<IsolateDTO> resultList = new ArrayList<>();
|
|
|
- if (StringUtil.isNotBlank(inputVO.getContinent())) {
|
|
|
- List<Epiflu> subtypeContinent = getSubtypeContinent(inputVO.getContinent());
|
|
|
+ List<EpifluDTO> subtypeContinent = epifluMapper.getSubtypeContinent(inputVO);
|
|
|
+
|
|
|
+ boolean flag = StringUtil.isBlank(inputVO.getSubtype())
|
|
|
+ || subtypeContinent.stream()
|
|
|
+ .map(EpifluDTO::getSubtype)
|
|
|
+ .noneMatch(st -> Objects.equals(st, inputVO.getSubtype()));
|
|
|
+
|
|
|
+ if (flag) {
|
|
|
+ for (EpifluDTO epifluDTO : subtypeContinent) {
|
|
|
+ resultList.add(getIsolateDTOList(inputVO, epifluDTO));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
// 创建并填充DTO
|
|
|
IsolateDTO isolateDTO = new IsolateDTO();
|
|
|
isolateDTO.setEpifluentName("甲流");
|
|
|
- boolean flag = StringUtil.isBlank(inputVO.getSubtype())
|
|
|
- || subtypeContinent.stream()
|
|
|
- .map(Epiflu::getSubtype)
|
|
|
- .noneMatch(st -> Objects.equals(st, inputVO.getSubtype()));
|
|
|
-
|
|
|
- if (flag) {
|
|
|
- return getIsolateDTOList(inputVO);
|
|
|
- }
|
|
|
resultList.add(isolateDTO);
|
|
|
- } else {
|
|
|
- return getIsolateDTOList(inputVO);
|
|
|
}
|
|
|
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
- public List<IsolateDTO> getIsolateDTOList(InputVO inputVO) {
|
|
|
- List<GraphInfo> graphInfoList = this.selectGraphInfo(inputVO);
|
|
|
-
|
|
|
- // 收集所有唯一的subtype
|
|
|
- List<String> subtypes = graphInfoList.stream()
|
|
|
- .map(GraphInfo::getSubtype)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- if (subtypes.isEmpty()) {
|
|
|
- return Collections.emptyList(); // 根据实际需求返回适当值
|
|
|
- }
|
|
|
-
|
|
|
- // 批量查询所有相关的Isolate记录,按subtype和日期排序
|
|
|
- List<Isolate> allIsolates = getBaseMapper().selectList(
|
|
|
- new QueryWrapper<Isolate>()
|
|
|
- .in("subtype", subtypes)
|
|
|
- .orderByAsc("subtype", "collection_date")
|
|
|
- );
|
|
|
+ public IsolateDTO getIsolateDTOList(InputVO inputVO, EpifluDTO epifluDTO) {
|
|
|
|
|
|
- // 按subtype分组,优化数据处理
|
|
|
- Map<String, List<Isolate>> isolatesBySubtype = allIsolates.stream()
|
|
|
- .collect(Collectors.groupingBy(Isolate::getSubtype));
|
|
|
+ IsolateDTO isolateDTO = new IsolateDTO();
|
|
|
|
|
|
- List<IsolateDTO> resultList = new ArrayList<>();
|
|
|
// 定义日期格式
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String subtype = epifluDTO.getSubtype();
|
|
|
+ QueryWrapper<Epiflu> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("subtype", subtype)
|
|
|
+ .orderByAsc("subtype", "collection_date");
|
|
|
+ List<Epiflu> epiflus = epifluMapper.selectList(wrapper);
|
|
|
|
|
|
- for (GraphInfo graphInfo : graphInfoList) {
|
|
|
- String subtype = graphInfo.getSubtype();
|
|
|
- List<Isolate> isolateList = isolatesBySubtype.getOrDefault(subtype, Collections.emptyList());
|
|
|
-
|
|
|
- if (isolateList.isEmpty()) {
|
|
|
- continue; // 跳过无数据的subtype
|
|
|
+ if (epiflus.isEmpty()) {
|
|
|
+ return isolateDTO;
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(epifluDTO, isolateDTO);
|
|
|
+ isolateDTO.setEpifluentName("甲流");
|
|
|
+ // 处理首个隔离信息
|
|
|
+ Epiflu firstEpiflu = epiflus.get(0);
|
|
|
+ String firstLocation = firstEpiflu.getLocation() != null ? firstEpiflu.getLocation() : "未知地区";
|
|
|
+ Date firstDate = firstEpiflu.getCollectionDate();
|
|
|
+ // 格式化日期(处理空值)
|
|
|
+ String formattedDate = (firstDate != null) ? dateFormat.format(firstDate) : "未知日期";
|
|
|
+
|
|
|
+ // 收集传播地点(排除首个)
|
|
|
+ Set<String> propagationLocations = new LinkedHashSet<>();
|
|
|
+ for (int i = 1; i < epiflus.size(); i++) {
|
|
|
+ String location = epiflus.get(i).getLocation();
|
|
|
+ if (location != null) {
|
|
|
+ String lastSegment = getLastSegment(location);
|
|
|
+ propagationLocations.add(lastSegment);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // 处理首个隔离信息
|
|
|
- Isolate firstIsolate = isolateList.get(0);
|
|
|
- String firstLocation = firstIsolate.getLocation() != null ? firstIsolate.getLocation() : "未知地区";
|
|
|
- Date firstDate = firstIsolate.getCollectionDate();
|
|
|
- // 格式化日期(处理空值)
|
|
|
- String formattedDate = (firstDate != null) ? dateFormat.format(firstDate) : "未知日期";
|
|
|
+ String propagation = propagationLocations.isEmpty() ? "无" : String.join(",", propagationLocations);
|
|
|
+ // 构建分析文本
|
|
|
+ String analyse = String.format("%s首次爆发在%s的%s,之后在%s传播。",
|
|
|
+ subtype, formattedDate, firstLocation, propagation);
|
|
|
|
|
|
- // 收集传播地点(排除首个)
|
|
|
- Set<String> propagationLocations = new LinkedHashSet<>();
|
|
|
- for (int i = 1; i < isolateList.size(); i++) {
|
|
|
- String location = isolateList.get(i).getLocation();
|
|
|
- if (location != null) {
|
|
|
- String lastSegment = getLastSegment(location);
|
|
|
- propagationLocations.add(lastSegment);
|
|
|
- }
|
|
|
- }
|
|
|
+ // 创建并填充DTO
|
|
|
+ isolateDTO.setEpifluentName("甲流");
|
|
|
+ isolateDTO.setCumulativeMap(getCumulativeList(inputVO, epifluDTO));
|
|
|
+ isolateDTO.setAnalyse(analyse);
|
|
|
+ isolateDTO.setGeoInfoList(getGeoInfoList(inputVO, epifluDTO));
|
|
|
|
|
|
- String propagation = propagationLocations.isEmpty() ? "无" : String.join(",", propagationLocations);
|
|
|
+ return isolateDTO;
|
|
|
|
|
|
- // 构建分析文本
|
|
|
- String analyse = String.format("%s首次爆发日期:%s在%s爆发,之后在%s传播。",
|
|
|
- subtype, formattedDate, firstLocation, propagation);
|
|
|
+ }
|
|
|
|
|
|
- // 创建并填充DTO
|
|
|
- IsolateDTO isolateDTO = new IsolateDTO();
|
|
|
- BeanUtil.copyProperties(graphInfo, isolateDTO);
|
|
|
- isolateDTO.setEpifluentName("甲流");
|
|
|
- isolateDTO.setSubtype(subtype);
|
|
|
- isolateDTO.setCumulative(getCumulativeList(subtype));
|
|
|
- isolateDTO.setAnalyse(analyse);
|
|
|
- isolateDTO.setGeoInfoList(getGeoInfoList(inputVO, subtype));
|
|
|
- resultList.add(isolateDTO);
|
|
|
+ public Map<String, CumulativeDTO> getCumulativeList(InputVO inputVO, EpifluDTO epifluDTO) {
|
|
|
+ String cladeStr = epifluDTO.getClade();
|
|
|
+ List<String> cladeList = Optional.ofNullable(cladeStr)
|
|
|
+ .filter(s -> !s.trim().isEmpty())
|
|
|
+ .map(s -> Arrays.stream(s.split(","))
|
|
|
+ .map(String::trim) // 去除前后空格
|
|
|
+ .filter(part -> !part.isEmpty()) // 过滤空字符串
|
|
|
+ .collect(Collectors.toList()) // 改为收集为 List
|
|
|
+ )
|
|
|
+ .orElse(Collections.emptyList()); // 默认返回空 List
|
|
|
+ Map<String, CumulativeDTO> cumulativeMap = new HashMap<>();
|
|
|
+
|
|
|
+ ChinaCollectionDateDTO chinaCollectionDateDTO = new ChinaCollectionDateDTO();
|
|
|
+ if (StringUtil.isNotBlank(inputVO.getStartDate()) && StringUtil.isNotBlank(inputVO.getEndDate())) {
|
|
|
+ chinaCollectionDateDTO.setMINCollectionDate(inputVO.getStartDate());
|
|
|
+ chinaCollectionDateDTO.setMAXCollectionDate(inputVO.getEndDate());
|
|
|
+ chinaCollectionDateDTO.setCount(epifluDTO.getCount());
|
|
|
+ } else {
|
|
|
+ String subtype = epifluDTO.getSubtype();
|
|
|
+ chinaCollectionDateDTO = epifluMapper.findCollectionDate(subtype);
|
|
|
}
|
|
|
- return resultList;
|
|
|
- }
|
|
|
|
|
|
- public Map<String, Integer> getCumulativeList(String subtype) {
|
|
|
- Date maxCollectionDate = epifluMapper.findMaxCollectionDateBySubtype(subtype);
|
|
|
- // 更安全的日期转换方式
|
|
|
- LocalDate startDate = maxCollectionDate.toInstant()
|
|
|
- .atZone(ZoneId.of("UTC")) // 明确指定时区为UTC
|
|
|
- .toLocalDate()
|
|
|
- .withDayOfYear(1);
|
|
|
- LocalDate endDate = startDate.plusMonths(12).minusDays(1);
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
-
|
|
|
- Map<String, Integer> cumulative = new TreeMap<>(); // 使用 TreeMap 保持键的有序性
|
|
|
- for (int i = 0; i < 12; i++) {
|
|
|
- LocalDate monthStartDate = startDate.plusMonths(i);
|
|
|
- LocalDate monthEndDate = monthStartDate.plusMonths(1).minusDays(1);
|
|
|
- String monthKey = monthStartDate.format(formatter);
|
|
|
- //如果要把逻辑改成每个月占比,把下面的 startDate改成monthStartDate
|
|
|
- int countInMonth = epifluMapper.selectCountBySubtypeAndDateRange(subtype, startDate, monthEndDate);
|
|
|
- int countInYear = epifluMapper.selectCountBySubtypeAndDateRange(subtype, startDate, endDate);
|
|
|
- int percentage = (int) countInMonth / countInYear * 100;
|
|
|
- cumulative.put(monthKey, (int) (Math.ceil(percentage * 10.0) / 10.0));
|
|
|
+ // 定义起始和结束日期
|
|
|
+ LocalDate startDate = LocalDate.parse(chinaCollectionDateDTO.getMINCollectionDate());
|
|
|
+ LocalDate endDate = LocalDate.parse(chinaCollectionDateDTO.getMAXCollectionDate());
|
|
|
+ // 生成日期列表
|
|
|
+ List<LocalDate> dateList = generateDateIntervals(startDate, endDate, 30);
|
|
|
+
|
|
|
+ for (LocalDate localDate : dateList) {
|
|
|
+ CumulativeDTO cumulativeDTO = new CumulativeDTO();
|
|
|
+ inputVO.setStartDate(localDate.toString());
|
|
|
+ inputVO.setSubtype(epifluDTO.getSubtype());
|
|
|
+ inputVO.setClade(cladeList);
|
|
|
+ Integer count = epifluMapper.selectCountByInput(inputVO);
|
|
|
+ double percentage = (chinaCollectionDateDTO.getCount() == 0) ? 0.0 : (count * 100.0) / chinaCollectionDateDTO.getCount();
|
|
|
+ cumulativeDTO.setCount(count);
|
|
|
+ cumulativeDTO.setPercentage(percentage);
|
|
|
+ cumulativeMap.put(localDate.toString(), cumulativeDTO);
|
|
|
}
|
|
|
- return cumulative;
|
|
|
+ return cumulativeMap;
|
|
|
}
|
|
|
|
|
|
- public List<GeoInfo> getGeoInfoList(InputVO inputVO, String input) {
|
|
|
-
|
|
|
+ public List<GeoInfo> getGeoInfoList(InputVO inputVO, EpifluDTO epifluDTO) {
|
|
|
List<String> continentList = StringUtil.isBlank(inputVO.getContinent())
|
|
|
? Arrays.asList("Asia", "Europe", "Africa", "North America", "South America", "Oceania")
|
|
|
: Collections.singletonList(inputVO.getContinent().trim());
|
|
@@ -176,7 +169,7 @@ public class IsolateFacade extends IsolateServiceImpl {
|
|
|
GeoInfo geoInfo = new GeoInfo();
|
|
|
|
|
|
// 1. 获取clade统计数据
|
|
|
- List<CladeCountResult> cladeCountResult = epifluMapper.selectCladeCountByContinent(continent, input);
|
|
|
+ List<CladeCountResult> cladeCountResult = epifluMapper.selectCladeCountByProvince(continent, epifluDTO.getSubtype());
|
|
|
|
|
|
// 2. 转换数据格式
|
|
|
List<GeoDataItem> dataItems = cladeCountResult.stream()
|
|
@@ -197,6 +190,7 @@ public class IsolateFacade extends IsolateServiceImpl {
|
|
|
geoInfoList.add(geoInfo);
|
|
|
}
|
|
|
return geoInfoList;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|