diff --git a/src/main/java/com/chint/manage/controller/ManageController.java b/src/main/java/com/chint/manage/controller/ManageController.java index 955efbc4..54057712 100644 --- a/src/main/java/com/chint/manage/controller/ManageController.java +++ b/src/main/java/com/chint/manage/controller/ManageController.java @@ -100,6 +100,24 @@ public class ManageController { return Result.Success(SUCCESS,manageService.orderPageQuery(dto)); } + @ApiOperation("订单报表导出接口") + @PostMapping("/order/export") + public ResponseEntity orderExport(@RequestBody OrderPageQuery dto){ + dto.setPageNum(1); + dto.setPageSize(Integer.MAX_VALUE); + File file = manageService.orderExport(dto); + Resource resource; + try { + resource = new InputStreamResource(new FileInputStream(file)); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + return ResponseEntity.ok() + .header("Content-Disposition", "attachment; filename=" + file.getName()) + .contentType(MediaType.parseMediaType("application/octet-stream")) + .body(resource); + } + @ApiOperation("订单下载记录查询接口") @PostMapping("/order/downloadRecordQuery") public Result orderDownloadRecordQuery(){ diff --git a/src/main/java/com/chint/manage/entity/excel/OrderPageExcel.java b/src/main/java/com/chint/manage/entity/excel/OrderPageExcel.java index 6d791d59..03b705c9 100644 --- a/src/main/java/com/chint/manage/entity/excel/OrderPageExcel.java +++ b/src/main/java/com/chint/manage/entity/excel/OrderPageExcel.java @@ -31,7 +31,7 @@ public class OrderPageExcel extends BaseExcel { private String productTypeName; @ExcelProperty("价格") private String price; // 价格 - @ExcelProperty + @ExcelIgnore private String employeeNo; @ExcelIgnore private Long originId; @@ -63,7 +63,7 @@ public class OrderPageExcel extends BaseExcel { public String getStatusName(){ if (status==null){ - return status; + return "未开始"; } if(productType.equals(LEG_TYPE_HOTEL)){ switch (status){ diff --git a/src/main/java/com/chint/manage/service/ManageService.java b/src/main/java/com/chint/manage/service/ManageService.java index cad838ab..aaef3e0b 100644 --- a/src/main/java/com/chint/manage/service/ManageService.java +++ b/src/main/java/com/chint/manage/service/ManageService.java @@ -36,4 +36,6 @@ public interface ManageService { List orderDownloadRecordQuery(); PageResult orderPageQuery(OrderPageQuery dto); + + File orderExport(OrderPageQuery dto); } diff --git a/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java b/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java index 4d19c15c..1fb5356a 100644 --- a/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java +++ b/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java @@ -170,14 +170,18 @@ public class ManageServiceImpl implements ManageService { @Override public PageResult orderPageQuery(OrderPageQuery dto) { -// //数据权限 -// List routeIds=baseUtil.getRouteIds(); -// if (routeIds==null||routeIds.isEmpty()) { -// return PageResult.totalPageNum(0, new ArrayList<>()); -// } + //数据权限 + List dataRouteIds=baseUtil.getRouteIds(); + if (dataRouteIds==null||dataRouteIds.isEmpty()) { + return PageResult.totalPageNum(0, new ArrayList<>()); + } + dto.setRouteIds(dataRouteIds); //行程号 if (!dto.getRouteOrderNo().isEmpty()){ List routeOrders=jdbcRouteRepository.findAllByRouteOrderNoContains(dto.getRouteOrderNo()); + if (routeOrders == null || routeOrders.isEmpty()) { + return PageResult.totalPageNum(0, new ArrayList<>()); + } if (dto.getRouteIds()==null){ dto.setRouteIds(routeOrders.stream().map(RouteOrder::getRouteId).toList()); }else { @@ -203,6 +207,7 @@ public class ManageServiceImpl implements ManageService { //处理地点信息 List locationIds = new ArrayList<>(list.stream().map(OrderDetail::getOriginId).toList()); locationIds.addAll(list.stream().map(OrderDetail::getDestinationId).toList()); + locationIds=locationIds.stream().distinct().filter(Objects::nonNull).collect(Collectors.toList()); List locations=locationRepository.findByLocationIdIn(locationIds); //根据类型处理出行订单信息 Map orderPageDtoMap=new HashMap<>(); @@ -219,6 +224,7 @@ public class ManageServiceImpl implements ManageService { } //处理行程单信息 List routeIds=list.stream().map(OrderDetail::getRouteId).toList(); + routeIds=routeIds.stream().distinct().filter(Objects::nonNull).collect(Collectors.toList()); List routeOrders=jdbcRouteRepository.findByRouteIdIn(routeIds); List result = list.stream().map(temp -> { @@ -228,13 +234,14 @@ public class ManageServiceImpl implements ManageService { } BeanUtils.copyProperties(temp, obj); OrderPageExcel finalObj = obj; - Location origin=locations.stream().filter(s->s.getLocationId().equals(finalObj.getOriginId())).toList().get(0); - Location destination=locations.stream().filter(s->s.getLocationId().equals(finalObj.getDestinationId())).toList().get(0); - if (origin!=null){ - finalObj.setOriginName(origin.getLocationName()); + + List origin=locations.stream().filter(s->s.getLocationId().equals(finalObj.getOriginId())).toList(); + List destination=locations.stream().filter(s->s.getLocationId().equals(finalObj.getDestinationId())).toList(); + if (!origin.isEmpty()){ + finalObj.setOriginName(origin.get(0).getLocationName()); } - if (destination!=null){ - finalObj.setDestinationName(destination.getLocationName()); + if (!destination.isEmpty()){ + finalObj.setDestinationName(destination.get(0).getLocationName()); } List orders=routeOrders.stream().filter(s->s.getRouteId().equals(finalObj.getRouteId())).toList(); if (!orders.isEmpty()) { @@ -246,6 +253,11 @@ public class ManageServiceImpl implements ManageService { return PageResult.totalPageNum(count, result); } + @Override + public File orderExport(OrderPageQuery dto) { + return ExcelUtil.exportReport(orderPageQuery(dto).getRecords()); + } + private void dealOrderTrainRecord(List entry,Map orderPageDtoMap){ if (entry!=null&&!entry.isEmpty()){ List trainOrderDetails=jdbcTrainOrderDetailRepository.findAllByOrderIdIn(entry.stream().map(OrderDetail::getOrderId).toList());