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; + + } }