新增获取时间范围内年月日小时的方法

统计横坐标根据时间范围内的年月日小时填充数据并回显
This commit is contained in:
qiaoqinzheng 2024-01-23 19:24:23 +08:00
parent 229d1980dd
commit a6deb7c53f
2 changed files with 142 additions and 62 deletions

View File

@ -805,4 +805,51 @@ public class DateUtils extends PropertyEditorSupport {
return days; return days;
} }
/**
* 获取开始时间和结束时间之间的全部小时信息
* @param beginDay
* @param endDay
* @return
*/
public static List<String> getAllDayTime(String beginDay, String endDay){
List<String> dayTimes = new ArrayList<>();
try {
//开始日期
Calendar begin = Calendar.getInstance();
begin.setTime(DateUtils.parseDate(beginDay, "yyyy-MM-dd"));
//将开始日期的24个小时放入集合中
for (int i=0; i< 24; i++) {
String dayTime = beginDay;
if (i < 10) {
dayTime+=" 0"+i;
} else {
dayTime+=" "+i;
}
dayTime+=":00:00";
dayTimes.add(dayTime);
}
//结束日期
Calendar end = Calendar.getInstance();
end.setTime(DateUtils.parseDate(endDay, "yyyy-MM-dd"));
//判断 如果结束日期的时间在开始日期的时间之后
while(end.getTime().after(begin.getTime())){
//开始日期需要+1天
begin.add(Calendar.DAY_OF_MONTH, 1);
for (int i=0; i< 24; i++) {
String dayTime = DateUtils.formatDate(begin.getTime(),"yyyy-MM-dd");
if (i < 10) {
dayTime+=" 0"+i;
} else {
dayTime+=" "+i;
}
dayTime+=":00:00";
dayTimes.add(dayTime);
}
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
return dayTimes;
}
} }

View File

@ -885,6 +885,8 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
return result; return result;
} }
String endTime = DateUtils.formatDate(endDate, "yyyy-MM-dd") + " 23:59:59"; String endTime = DateUtils.formatDate(endDate, "yyyy-MM-dd") + " 23:59:59";
List<String> allDayTime = DateUtils.getAllDayTime(DateUtils.formatDate(startDate, "yyyy-MM-dd"), DateUtils.formatDate(endDate, "yyyy-MM-dd"));
resultMap.put("AllDayTime", allDayTime);
//判断查询的核素内容是否为空 //判断查询的核素内容是否为空
List<String> nuclideNameList = new LinkedList<>(); List<String> nuclideNameList = new LinkedList<>();
if (nuclideNames != null && nuclideNames.length > 0) { if (nuclideNames != null && nuclideNames.length > 0) {
@ -933,7 +935,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
//拼接sql查询结果 //拼接sql查询结果
List<Map<String, Object>> nuclideStatisticsMap = this.baseMapper.findNuclideStatistics(stationId, startTime, endTime, nuclideSql); List<Map<String, Object>> nuclideStatisticsMap = this.baseMapper.findNuclideStatistics(stationId, startTime, endTime, nuclideSql);
//处理查询结果 //处理查询结果
handleNuclideData(nuclideStatisticsMap, systemType, nuclideNameList, resultMap); handleNuclideData(nuclideStatisticsMap, systemType, nuclideNameList, allDayTime, resultMap);
//返回台站名称 //返回台站名称
String stationName = stationMap.get(stationId); String stationName = stationMap.get(stationId);
resultMap.put("STATION_NAME", stationName); resultMap.put("STATION_NAME", stationName);
@ -1159,75 +1161,106 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
return sql; return sql;
} }
private void handleNuclideData(List<Map<String, Object>> nuclideStatisticsMap, String systemType, List<String> nuclideNameList, Map<String, Object> resultMap) { private void handleNuclideData(List<Map<String, Object>> nuclideStatisticsMap, String systemType, List<String> nuclideNameList, List<String> allDateTime, Map<String, Object> resultMap) {
//存储横坐标采集开始时间 //存储横坐标采集开始时间
List<String> collectStartList = new LinkedList<>(); List<String> collectStartList = new LinkedList<>();
//存储横坐标对应体积 //存储横坐标对应体积
List<Double> quantityList = new LinkedList<>(); List<Double> quantityList = new LinkedList<>();
//存储横坐标对应acq活时间 //存储横坐标对应acq活时间
List<Double> acqLiveSecList = new LinkedList<>(); List<Double> acqLiveSecList = new LinkedList<>();
//遍历查询结果数组 //遍历日期时间
for (Map<String, Object> nuclideStatistics: nuclideStatisticsMap) { for (int i=0; i< allDateTime.size(); i++) {
//获取采集开始时间 //根据下标获取日期时间
Object collectStart = nuclideStatistics.get("COLLECT_START"); String dayTime = allDateTime.get(i);
//如果采集开始时间不为空 则存储 //遍历查询结果数组
if (Objects.nonNull(collectStart)) { for (int j=0; j< nuclideStatisticsMap.size(); j++) {
collectStartList.add(collectStart.toString()); //根据下标获取核素查询结果
} else {//否则跳过本次循环 Map<String, Object> nuclideStatistics = nuclideStatisticsMap.get(j);
continue; //获取采集开始时间
} Object collectStart = nuclideStatistics.get("COLLECT_START");
//获取体积 //采集开始时间转为字符串
Object quantity = nuclideStatistics.get("QUANTITY"); String collectStartStr = collectStart.toString();
//判断体积数值是否有 如果有 正常存储 //截取采集开始时间的年月日小时
if (Objects.nonNull(quantity)) { collectStartStr = collectStartStr.substring(0, 14) + ":00:00";
quantityList.add(Double.valueOf(quantity.toString())); //如果采集时间包含当前日期 则正常的读取数据并存入数组
} else {//如果没有存储0 if (dayTime.equals(collectStartStr)) {
quantityList.add(0.0); collectStartList.add(collectStart.toString());
} //获取体积
//获取acq活时间 Object quantity = nuclideStatistics.get("QUANTITY");
Object acquisitionLiveSec = nuclideStatistics.get("ACQUISITION_LIVE_SEC"); //判断体积数值是否有 如果有 正常存储
//判断活时间是否为空 如果不为空 正常存储 if (Objects.nonNull(quantity)) {
if (Objects.nonNull(acquisitionLiveSec)) { quantityList.add(Double.valueOf(quantity.toString()));
acqLiveSecList.add(Double.valueOf(acquisitionLiveSec.toString()));
} else {//如果为空存储0
acqLiveSecList.add(0.0);
}
//判断系统类型决定读取核素的信息
if (systemType.equals("beta") || systemType.equals("gamma")) {
for (String nuclideName: nuclideNameList) {
List<Double> concList = (List<Double>) resultMap.get(nuclideName + "Conc");
List<Double> mdcList = (List<Double>) resultMap.get(nuclideName + "MDC");
//将核素名称转为全部大写
String columnName = StringUtils.upperCase(nuclideName);
//读取查询出的浓度
Object conc = nuclideStatistics.get(columnName);
//判断如果浓度不为空 正常存储
if (Objects.nonNull(conc)) {
concList.add(Double.valueOf(conc.toString()));
} else {//如果为空 存储0
concList.add(0.0);
}
//读取查询出的mdc结果
Object mdc = nuclideStatistics.get(columnName + "MDC");
//判断如果mdc结果不为空 正常存储
if (Objects.nonNull(mdc)) {
mdcList.add(Double.valueOf(mdc.toString()));
} else { } else {
mdcList.add(0.0); quantityList.add(null);
} }
} //获取acq活时间
} else if (systemType.equals("Particulate")) { Object acquisitionLiveSec = nuclideStatistics.get("ACQUISITION_LIVE_SEC");
for (String nuclideName: nuclideNameList) { //判断活时间是否为空 如果不为空 正常存储
List<Double> concList = (List<Double>) resultMap.get(nuclideName + "Conc"); if (Objects.nonNull(acquisitionLiveSec)) {
//将核素名称转为全部大写 acqLiveSecList.add(Double.valueOf(acquisitionLiveSec.toString()));
String columnName = StringUtils.upperCase(nuclideName); } else {
//读取查询出的浓度 acqLiveSecList.add(null);
Object conc = nuclideStatistics.get(columnName); }
//判断如果浓度不为空 正常存储 //判断系统类型决定读取核素的信息
if (Objects.nonNull(conc)) { if (systemType.equals("beta") || systemType.equals("gamma")) {
concList.add(Double.valueOf(conc.toString())); for (String nuclideName: nuclideNameList) {
} else {//如果为空 存储0 List<Double> concList = (List<Double>) resultMap.get(nuclideName + "Conc");
concList.add(0.0); List<Double> mdcList = (List<Double>) resultMap.get(nuclideName + "MDC");
//将核素名称转为全部大写
String columnName = StringUtils.upperCase(nuclideName);
//读取查询出的浓度
Object conc = nuclideStatistics.get(columnName);
//判断如果浓度不为空 正常存储
if (Objects.nonNull(conc)) {
concList.add(Double.valueOf(conc.toString()));
} else {
concList.add(null);
}
//读取查询出的mdc结果
Object mdc = nuclideStatistics.get(columnName + "MDC");
//判断如果mdc结果不为空 正常存储
if (Objects.nonNull(mdc)) {
mdcList.add(Double.valueOf(mdc.toString()));
} else {
mdcList.add(null);
}
}
} else if (systemType.equals("Particulate")) {
for (String nuclideName: nuclideNameList) {
List<Double> concList = (List<Double>) resultMap.get(nuclideName + "Conc");
//将核素名称转为全部大写
String columnName = StringUtils.upperCase(nuclideName);
//读取查询出的浓度
Object conc = nuclideStatistics.get(columnName);
//判断如果浓度不为空 正常存储
if (Objects.nonNull(conc)) {
concList.add(Double.valueOf(conc.toString()));
} else {
concList.add(null);
}
}
}
break;
} else { //如果采集时间不包含当前日期 各数组填补null
//如果全数组遍历后都没有 就填充空数据
if (j == nuclideStatisticsMap.size()-1) {
collectStartList.add(dayTime);
quantityList.add(null);
acqLiveSecList.add(null);
//判断系统类型决定读取核素的信息
if (systemType.equals("beta") || systemType.equals("gamma")) {
for (String nuclideName: nuclideNameList) {
List<Double> concList = (List<Double>) resultMap.get(nuclideName + "Conc");
List<Double> mdcList = (List<Double>) resultMap.get(nuclideName + "MDC");
concList.add(null);
mdcList.add(null);
}
} else if (systemType.equals("Particulate")) {
for (String nuclideName: nuclideNameList) {
List<Double> concList = (List<Double>) resultMap.get(nuclideName + "Conc");
concList.add(null);
}
}
} }
} }
} }