【add】订单导出功能实现

This commit is contained in:
nixj 2024-06-13 15:44:10 +08:00
parent 7f0acc3b3f
commit d9e130ff61
4 changed files with 45 additions and 13 deletions

View File

@ -100,6 +100,24 @@ public class ManageController {
return Result.Success(SUCCESS,manageService.orderPageQuery(dto));
}
@ApiOperation("订单报表导出接口")
@PostMapping("/order/export")
public ResponseEntity<Resource> 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(){

View File

@ -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){

View File

@ -36,4 +36,6 @@ public interface ManageService {
List<OrderDownloadRecord> orderDownloadRecordQuery();
PageResult<OrderPageExcel> orderPageQuery(OrderPageQuery dto);
File orderExport(OrderPageQuery dto);
}

View File

@ -170,14 +170,18 @@ public class ManageServiceImpl implements ManageService {
@Override
public PageResult<OrderPageExcel> orderPageQuery(OrderPageQuery dto) {
// //数据权限
// List<Long> routeIds=baseUtil.getRouteIds();
// if (routeIds==null||routeIds.isEmpty()) {
// return PageResult.totalPageNum(0, new ArrayList<>());
// }
//数据权限
List<Long> dataRouteIds=baseUtil.getRouteIds();
if (dataRouteIds==null||dataRouteIds.isEmpty()) {
return PageResult.totalPageNum(0, new ArrayList<>());
}
dto.setRouteIds(dataRouteIds);
//行程号
if (!dto.getRouteOrderNo().isEmpty()){
List<RouteOrder> 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<Long> 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<Location> locations=locationRepository.findByLocationIdIn(locationIds);
//根据类型处理出行订单信息
Map<Long, OrderPageExcel> orderPageDtoMap=new HashMap<>();
@ -219,6 +224,7 @@ public class ManageServiceImpl implements ManageService {
}
//处理行程单信息
List<Long> routeIds=list.stream().map(OrderDetail::getRouteId).toList();
routeIds=routeIds.stream().distinct().filter(Objects::nonNull).collect(Collectors.toList());
List<RouteOrder> routeOrders=jdbcRouteRepository.findByRouteIdIn(routeIds);
List<OrderPageExcel> 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<Location> origin=locations.stream().filter(s->s.getLocationId().equals(finalObj.getOriginId())).toList();
List<Location> 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<RouteOrder> 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<OrderDetail> entry,Map<Long, OrderPageExcel> orderPageDtoMap){
if (entry!=null&&!entry.isEmpty()){
List<TrainOrderDetail> trainOrderDetails=jdbcTrainOrderDetailRepository.findAllByOrderIdIn(entry.stream().map(OrderDetail::getOrderId).toList());