|
@@ -3,13 +3,14 @@ package com.qizhen.healsphere.service.impl;
|
|
|
import com.qizhen.healsphere.repository.mapper.BacteriaGenusMapper;
|
|
|
import com.qizhen.healsphere.repository.mapper.EpifluMapper;
|
|
|
import com.qizhen.healsphere.repository.mapper.StrainMapper;
|
|
|
+import com.qizhen.healsphere.repository.mapper.EpifluQueryMapper;
|
|
|
import com.qizhen.healsphere.web.param.*;
|
|
|
+import com.qizhen.healsphere.web.vo.InputVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
-import java.time.Year;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
@@ -28,6 +29,9 @@ public class ZYApiServiceImpl {
|
|
|
@Autowired
|
|
|
private EpifluMapper epifluMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private EpifluQueryMapper epifluQueryMapper;
|
|
|
+
|
|
|
public List<BacteriaGenus> getBacteriaInfo(String input) {
|
|
|
log.info("Calling getBacteriaInfo with input: {}", input);
|
|
|
// 将输入字符串按逗号分割成列表
|
|
@@ -63,7 +67,7 @@ public class ZYApiServiceImpl {
|
|
|
return epifluMapper.selectCountBySubtype(subType);
|
|
|
}
|
|
|
|
|
|
- public Map<String,Double> getCumulativeList(String subtype) {
|
|
|
+ public Map<String,Integer> getCumulativeList(String subtype) {
|
|
|
Date maxCollectionDate = epifluMapper.findMaxCollectionDateBySubtype(subtype);
|
|
|
// 更安全的日期转换方式
|
|
|
LocalDate startDate = maxCollectionDate.toInstant()
|
|
@@ -73,7 +77,7 @@ public class ZYApiServiceImpl {
|
|
|
LocalDate endDate = startDate.plusMonths(12).minusDays(1);
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
|
- Map<String, Double> cumulative = new TreeMap<>(); // 使用 TreeMap 保持键的有序性
|
|
|
+ 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);
|
|
@@ -81,11 +85,27 @@ public class ZYApiServiceImpl {
|
|
|
//如果要把逻辑改成每个月占比,把下面的 startDate改成monthStartDate
|
|
|
int countInMonth = epifluMapper.selectCountBySubtypeAndDateRange(subtype, startDate, monthEndDate);
|
|
|
int countInYear = epifluMapper.selectCountBySubtypeAndDateRange(subtype, startDate, endDate);
|
|
|
- double percentage = (double) countInMonth / countInYear * 100;
|
|
|
- cumulative.put(monthKey, Math.round(percentage * 10.0) / 10.0); // 保留小数点后一位
|
|
|
+ int percentage = (int) countInMonth / countInYear * 100;
|
|
|
+ cumulative.put(monthKey, (int) (Math.ceil(percentage * 10.0) / 10.0));
|
|
|
}
|
|
|
return cumulative;
|
|
|
}
|
|
|
+ public Map<String, Integer> getCumulativeCountList(InputVO inputVO) {
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate oneWeekAgo = today.minusWeeks(1);
|
|
|
+ Map<String, Integer> cumulative = new TreeMap<>();
|
|
|
+
|
|
|
+ // 遍历从 oneWeekAgo 到 today 的每一天
|
|
|
+ for (LocalDate date = oneWeekAgo; !date.isAfter(today); date = date.plusDays(1)) {
|
|
|
+ // 调用 mapper.selectCount 方法获取数量
|
|
|
+ Integer count = epifluMapper.selectCount(inputVO.getSubtype(), inputVO.getIsChina(), date);
|
|
|
+ // 将日期格式化为 yyyy-MM-dd 并存入 Map
|
|
|
+ cumulative.put(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), count);
|
|
|
+ }
|
|
|
+
|
|
|
+ return cumulative;
|
|
|
+ }
|
|
|
+
|
|
|
// public Map<String, Integer> getInEachContinentMap(String subtype) {
|
|
|
// List<String> continentList = Arrays.asList("Asia", "Europe", "Africa", "North America", "South America", "Oceania");
|
|
|
// Date maxCollectionDate = epifluMapper.findMaxCollectionDateBySubtype(subtype);
|
|
@@ -208,11 +228,87 @@ public Map<String, Object> getInEachContinentMap(String subtype) {
|
|
|
|
|
|
geoInfoList.add(geoInfo);
|
|
|
}
|
|
|
-
|
|
|
return geoInfoList;
|
|
|
}
|
|
|
+ public List<GeoInfo> getChineseGeoInfoList(InputVO inputVO){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
//获取所有的subType值
|
|
|
public List<String> findDistinctSubtype(){
|
|
|
return epifluMapper.findDistinctSubtype();
|
|
|
}
|
|
|
+//
|
|
|
+// public List<String> getCladeListBySearch(InputVO inputVO) {
|
|
|
+// return epifluMapper.findDistinctCladeBySearchWithConditions(inputVO.getSubType(), 0, inputVO.getStartDate(), inputVO.getEndDate());
|
|
|
+// }
|
|
|
+ public GraphInfo getGraphData(InputVO inputVO) {
|
|
|
+ GraphInfo graphInfo = new GraphInfo();
|
|
|
+
|
|
|
+ String subType = inputVO.getSubtype();
|
|
|
+ graphInfo.setEpifluentName("甲流"); // 写死
|
|
|
+ graphInfo.setClade(inputVO.getConstellation());
|
|
|
+ graphInfo.setSubtype(subType);
|
|
|
+
|
|
|
+ // 设置统计数据
|
|
|
+ graphInfo.setCount(epifluQueryMapper.getCountByQuery(inputVO));
|
|
|
+
|
|
|
+ // 获取 startDate 和 endDate
|
|
|
+ Date startDate = inputVO.getStartDate();
|
|
|
+ Date endDate = inputVO.getEndDate();
|
|
|
+
|
|
|
+ if (startDate != null && endDate != null) {
|
|
|
+ LocalDate startLocalDate = startDate.toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDate();
|
|
|
+ LocalDate endLocalDate = endDate.toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDate();
|
|
|
+ Map<String, Integer> dailyCounts = new TreeMap<>();
|
|
|
+ // 遍历 startDate 到 endDate 的每一天
|
|
|
+ for (LocalDate date = startLocalDate; !date.isAfter(endLocalDate); date = date.plusDays(1)) {
|
|
|
+ // 遍历 constellation 列表
|
|
|
+ int totalCount = 0;
|
|
|
+ for (String constellation : inputVO.getConstellation()) {
|
|
|
+ Integer count = epifluMapper.selectDayCount(inputVO.getSubtype(), constellation, date);
|
|
|
+ if (count != null) {
|
|
|
+ totalCount += count;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dailyCounts.put(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), totalCount);
|
|
|
+ }
|
|
|
+ // 设置累积数据
|
|
|
+ graphInfo.setCumulative(dailyCounts);
|
|
|
+ }
|
|
|
+ //TODO 总结分析
|
|
|
+
|
|
|
+ // 设置地理信息
|
|
|
+ graphInfo.setGeoInfoList(getGeoInfoList(subType));
|
|
|
+
|
|
|
+ return graphInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+// public int getQueryCount(InputVO inputVO) {
|
|
|
+// return epifluQueryMapper.getCountByQuery(inputVO);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// public Map<String,Double> getCumulativeListByInputVO(InputVO inputVO) {
|
|
|
+// Date startDate = inputVO.getStartDate();
|
|
|
+// Date endDate= inputVO.getEndDate();
|
|
|
+//
|
|
|
+//
|
|
|
+// Map<String, Double> 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);
|
|
|
+// double percentage = (double) countInMonth / countInYear * 100;
|
|
|
+// cumulative.put(monthKey, Math.round(percentage * 10.0) / 10.0); // 保留小数点后一位
|
|
|
+// }
|
|
|
+// return cumulative;
|
|
|
+// }
|
|
|
}
|