From 823db4f82e83fecb50ff34fceab5579184fcf434 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Sun, 9 Oct 2022 19:48:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=EF=BC=9A/d?= =?UTF-8?q?ownload/firepoint=20=E5=AF=BC=E5=87=BA=E7=81=AB=E7=82=B9?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/FirePointController.java | 5 +++ .../com/xkrs/service/FirePointService.java | 2 ++ .../service/impl/FirePointServiceImpl.java | 33 +++++++++++++++++++ src/main/java/com/xkrs/utils/ListUtils.java | 9 +++++ 4 files changed, 49 insertions(+) diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index 20cec34..bc4e95b 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -182,6 +182,11 @@ public class FirePointController { return firePointService.downloadVipUserFilePoint(request, response); } + @RequestMapping(value = "/download/firepoint", method = RequestMethod.GET) + public String downloadFirePoint(HttpServletResponse response, HttpServletRequest request, @RequestParam(value = "ids") String ids) { + return firePointService.downloadFirePoint(request, response, ids); + } + /** * 动态多条件查询火点列表 * diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index c4afcac..b0fdce7 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -86,6 +86,8 @@ public interface FirePointService { */ String downloadVipUserFilePoint(HttpServletRequest request, HttpServletResponse response); + String downloadFirePoint(HttpServletRequest request, HttpServletResponse response,String ids); + /** * 动态多条件查询火点列表 * diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 443f37f..30995ae 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -459,6 +459,39 @@ public class FirePointServiceImpl implements FirePointService { return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "ok", locale); } + @Override + public String downloadFirePoint(HttpServletRequest request, HttpServletResponse response, String ids) { + + List idList = ListUtils.toStringList(ids, ","); + if (idList.isEmpty()) { + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "无数据!", locale); + } + List> list = new ArrayList<>(); + List sourceList = firePointDao.findAllById(ListUtils.stringListToLongList(idList)); + for (FirePointEntity source : sourceList) { + Map record = new HashMap<>(); + record.put("所在区县", source.getCountyName()); + record.put("所在街道", source.getStreetName()); + record.put("发现时间", source.getSatelliteTime()); + record.put("地物类型", source.getLandType()); + record.put("经度", String.valueOf(source.getLongitude())); + record.put("纬度", String.valueOf(source.getLatitude())); + record.put("详细地址", source.getFirePointAddress()); + list.add(record); + } + LocalDate now = LocalDate.now(); + String fileName = String.format("%s_%s_%s_火点信息列表.xlsx", now.getYear(), now.getMonth().getValue(), now.getDayOfMonth()); + response.setContentType("application/octet-stream; charset=UTF8"); + response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8)); + response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); + try { + downloadXlsx(list, response.getOutputStream()); + } catch (IOException e) { + log.error("download fire point fail: {}", e.getMessage()); + } + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "ok", locale); + } + /** * 动态多条件查询火点列表 * diff --git a/src/main/java/com/xkrs/utils/ListUtils.java b/src/main/java/com/xkrs/utils/ListUtils.java index e6875d0..1fbf517 100644 --- a/src/main/java/com/xkrs/utils/ListUtils.java +++ b/src/main/java/com/xkrs/utils/ListUtils.java @@ -57,4 +57,13 @@ public class ListUtils { } return builder.toString(); } + + public static List stringListToLongList(List stringList) { + List longList = new ArrayList<>(); + for (String string:stringList) { + longList.add(Long.parseLong(string)); + } + return longList; + + } }