service:
public InputStream downShp(String areaTypeId) throws Exception {
if (StringUtils.isEmpty(areaTypeId)) {
areaTypeId = "1";
}
int count = 5;
CountDownLatch countDownLatch = new CountDownLatch(count);
String path = System.getProperty("user.dir");
String zipPathPrefix = path + File.separator + "static" + File.separator + "downloadZip" + File.separator + UUIDUtil.createUUID()+File.separator;
String zipPath =zipPathPrefix+"area.zip";
File file1 = new File(zipPathPrefix);
if (!file1.exists()) {
file1.mkdirs();
}
String[] strings = new String[]{"area_sheng", "area_shi", "area_xian", "area_xiang", "area_zerenqu"};
for (String string : strings) {
String finalAreaTypeId = areaTypeId;
taskExecutor.execute(() -> {
String sql;
if ("area_sheng".equals(string)) {
sql = "select * ,st_astext(geom) as the_geom from " + string + " " ;
} else {
sql = "select * ,st_astext(geom) as the_geom from " + string + " where area_type_id ='" + finalAreaTypeId +"'";
}
List
controller:
public ResponseEntityexportXls(@RequestParam(value = "areaTypeId", required = false) String areaTypeId) { // 设置响应头 HttpHeaders headers = new HttpHeaders(); try { headers.add("Content-Disposition", "attachment; filename=" + URLEncoder.encode("区域模板.zip", "utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); headers.add("Pragma", "no-cache"); headers.add("Expires", "0"); headers.add("Last-Modified", new Date().toString()); headers.add("ETag", String.valueOf(System.currentTimeMillis())); // 获取文件流 // InputStream inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), "area/template/区域模板.zip"); InputStream inputStream = null; try { inputStream = areaManageUpdateLogService.downShp(areaTypeId); } catch (Exception e) { e.printStackTrace(); } return ResponseEntity.ok() .headers(headers) .contentType(MediaType.APPLICATION_OCTET_STREAM) .body(new InputStreamResource(inputStream)); }



