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