添加导出数据服务

This commit is contained in:
duwenyuan 2026-08-03 17:34:13 +08:00
parent ce2817d168
commit 3f4749ee0c
3 changed files with 41 additions and 4 deletions

View File

@ -1068,6 +1068,7 @@
LEFT JOIN CONFIGURATION.GARDS_STATIONS c1 LEFT JOIN CONFIGURATION.GARDS_STATIONS c1
ON t1.STATION_ID = c1.STATION_ID ON t1.STATION_ID = c1.STATION_ID
WHERE t1.SAMPLE_TYPE = #{sampleType} WHERE t1.SAMPLE_TYPE = #{sampleType}
AND t1.SPECTRAL_QUALIFIE='FULL'
AND t1.COLLECT_STOP BETWEEN #{startTime} AND t1.COLLECT_STOP BETWEEN #{startTime}
AND #{endTime} AND #{endTime}
ORDER BY t1.COLLECT_STOP ASC ORDER BY t1.COLLECT_STOP ASC

View File

@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Slf4j @Slf4j
@ -37,12 +38,17 @@ public class ExcelExportService {
if (CollectionUtils.isEmpty(data)) { if (CollectionUtils.isEmpty(data)) {
throw new IOException("暂无导出数据"); throw new IOException("暂无导出数据");
} }
if (data == null) {
data = new ArrayList<>();
} else {
data = new ArrayList<>(data); // 转为可变 List
}
ExportParams params = new ExportParams(handler.getSheetName(), handler.getSheetName(), ExcelType.XSSF); ExportParams params = new ExportParams(handler.getSheetName(), handler.getSheetName(), ExcelType.XSSF);
Workbook workbook = ExcelExportUtil.exportExcel(params,handler.getExcelClass(), data); try (Workbook workbook = ExcelExportUtil.exportExcel(params, handler.getExcelClass(), data)) {
download(workbook, handler.getSheetName(), response); download(workbook, handler.getSheetName(), response);
} }
}
private void download(Workbook workbook, private void download(Workbook workbook,
String fileName, String fileName,

View File

@ -84,6 +84,35 @@ public class SampleStatAnalysisService
.toLocalDate() .toLocalDate()
)) ))
.toList(); .toList();
//查询每个台站在时间范围内的各个等级的数量
List<Map<String, Object>> stationLevelCount = sortedList.stream()
.filter(station -> station.getStationCode() != null)
.filter(station -> station.getCategory() != null)
.collect(Collectors.groupingBy(
StationInfoData::getStationCode,
Collectors.mapping(
StationInfoData::getCategory,
Collectors.toList()
)
))
.entrySet().stream()
.map(entry -> {
Map<String, Object> map = new HashMap<>();
map.put("stationCode", entry.getKey());
Map<String, Long> levelCount = new HashMap<>();
entry.getValue().stream()
.filter(Objects::nonNull)
.collect(Collectors.groupingBy(
category -> category,
Collectors.counting()
))
.forEach((category, count) ->
levelCount.put("level" + category, count)
);
map.put("categoryCount", levelCount);
return map;
})
.collect(Collectors.toList());
//时间段内有多少台站 //时间段内有多少台站
Map<String, List<Map<String, Object>>> groupedByMonth = Map<String, List<Map<String, Object>>> groupedByMonth =
sortedList.stream() sortedList.stream()
@ -144,6 +173,7 @@ public class SampleStatAnalysisService
) )
)); ));
resultMap.put("stationInfo", stationInfoSet); resultMap.put("stationInfo", stationInfoSet);
resultMap.put("stationLevelCount", stationLevelCount);
resultMap.put("sampleMonitorResultList", groupedByMonth); resultMap.put("sampleMonitorResultList", groupedByMonth);
return resultMap; return resultMap;
} catch (Exception e) { } catch (Exception e) {
@ -233,7 +263,7 @@ public class SampleStatAnalysisService
vo.setCount(e.getValue()); vo.setCount(e.getValue());
return vo; return vo;
}) })
.toList(); .collect(Collectors.toList());
return sampleStatList; return sampleStatList;
} catch (Exception e) { } catch (Exception e) {