From 2e056a33245642de862c368e0cdb69ca25453021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Tue, 3 Feb 2026 14:38:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(device):=20=E8=AE=BE=E5=A4=87=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=B7=BB=E5=8A=A0=E5=AF=BC=E5=87=BA=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/DeviceController.java | 41 ++++++++++++++++++ .../gongfu/controller/DeviceController.java | 42 +++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/DeviceController.java b/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/DeviceController.java index a3bdf0a7..725cf03a 100644 --- a/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/DeviceController.java +++ b/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/DeviceController.java @@ -134,6 +134,47 @@ public class DeviceController extends ControllerBase { return ApiResult.success(resultData, query, result.getTotal()); } + /** + * 导出设备列表 + * @param query + */ + @PostMapping("exportSearch") + public void exportSearch(HttpServletResponse response,@RequestBody DeviceQuery query) throws IOException { + Page result = deviceService.getList(new Page<>(1, Integer.MAX_VALUE), query); + List states = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE); + List datas = result.getRecords().stream().map(d -> { + DeviceExportDTO dto = new DeviceExportDTO(); + dto.setId(String.valueOf(d.getId())); + dto.setDeviceNo(d.getDeviceNo()); + dto.setDeviceName(d.getCustomerName()+d.getDeviceNo()); + dto.setDeviceType(d.getDeviceType()); + dto.setDeviceTypeSub(d.getDeviceTypeSub()); + dto.setModelNo(d.getModelNo()); + dto.setDeviceStateDesc(states.stream().filter(s -> Objects.equals(s.getId(), d.getDeviceState())).findFirst().get().getName()); + dto.setCustomerName(d.getCustomerName()); + dto.setAgentName(d.getAgentName()); + dto.setAreaName(d.getAreaName()); + dto.setAddress(d.getAddress()); + dto.setShipmentDate(d.getShipmentDate()); + dto.setStartWarrantyDate(d.getStartWarrantyDate()); + if (Objects.nonNull(d.getWarrantyMonth())) { + dto.setWarrantyMonth(String.valueOf(d.getWarrantyMonth())); + } + dto.setServiceAgentName(d.getServiceAgentName()); + return dto; + }).collect(Collectors.toList()); + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("设备导出.xlsx", StandardCharsets.UTF_8)); +// ClassPathResource resource = new ClassPathResource("templates/deviceForUpdate.xlsx"); +// new Workbook() +// .addSheet(new TemplateSheet(resource.getInputStream()) +// .setData(datas) +// .setData("@list:deviceStateDesc", dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE) +// .stream().map(DictionaryItem::getName).collect(Collectors.toList()))) +// .writeTo(response.getOutputStream()); + new Workbook().addSheet(new ListSheet<>(datas)).writeTo(response.getOutputStream()); + } + /** * 获取设备详情 * @param id diff --git a/nflg-mobilebroken-gongfu/src/main/java/com/nflg/mobilebroken/gongfu/controller/DeviceController.java b/nflg-mobilebroken-gongfu/src/main/java/com/nflg/mobilebroken/gongfu/controller/DeviceController.java index d7b7e63a..91aa59e7 100644 --- a/nflg-mobilebroken-gongfu/src/main/java/com/nflg/mobilebroken/gongfu/controller/DeviceController.java +++ b/nflg-mobilebroken-gongfu/src/main/java/com/nflg/mobilebroken/gongfu/controller/DeviceController.java @@ -137,6 +137,48 @@ public class DeviceController extends ControllerBase { return ApiResult.success(resultData, query, result.getTotal()); } + /** + * 导出设备列表 + * @param query + */ + @PostMapping("exportSearch") + public void exportSearch(HttpServletResponse response,@RequestBody DeviceQuery query) throws IOException { + Page result = deviceService.getList(new Page<>(1, Integer.MAX_VALUE), query); + List states = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE); + List datas = result.getRecords().stream().map(d -> { + DeviceExportDTO dto = new DeviceExportDTO(); + dto.setId(String.valueOf(d.getId())); + dto.setDeviceNo(d.getDeviceNo()); + dto.setDeviceName(d.getCustomerName()+d.getDeviceNo()); + dto.setDeviceType(d.getDeviceType()); + dto.setDeviceTypeSub(d.getDeviceTypeSub()); + dto.setModelNo(d.getModelNo()); + dto.setDeviceStateDesc(states.stream().filter(s -> Objects.equals(s.getId(), d.getDeviceState())).findFirst().get().getName()); + dto.setCustomerName(d.getCustomerName()); + dto.setAgentName(d.getAgentName()); + dto.setAreaName(d.getAreaName()); + dto.setAddress(d.getAddress()); + dto.setShipmentDate(d.getShipmentDate()); + dto.setStartWarrantyDate(d.getStartWarrantyDate()); + if (Objects.nonNull(d.getWarrantyMonth())) { + dto.setWarrantyMonth(String.valueOf(d.getWarrantyMonth())); + } + dto.setProductLine(d.getProductLine()); + dto.setServiceAgentName(d.getServiceAgentName()); + return dto; + }).collect(Collectors.toList()); + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("设备导出.xlsx", StandardCharsets.UTF_8)); +// ClassPathResource resource = new ClassPathResource("templates/deviceForUpdate.xlsx"); +// new Workbook() +// .addSheet(new TemplateSheet(resource.getInputStream()) +// .setData(datas) +// .setData("@list:deviceStateDesc", dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DEVICE_STATE) +// .stream().map(DictionaryItem::getName).collect(Collectors.toList()))) +// .writeTo(response.getOutputStream()); + new Workbook().addSheet(new ListSheet<>(datas)).writeTo(response.getOutputStream()); + } + /** * 获取设备详情 * @param id