Commit e36b7baf by levphon

导出运营报表

1 parent feb3650d
...@@ -27,4 +27,11 @@ public class AbstractController { ...@@ -27,4 +27,11 @@ public class AbstractController {
return ""; return "";
} }
public String getExportFileUrl(String fileName, ByteArrayOutputStream baos) {
//将文件写入内存流 然后上传到文件服务器 返回文件服务器的地址给前端 前端执行下载
FileUploadServerData uploadServerData = FileUploadUtil.uploadToFileSystem(fileName, baos.toByteArray(), FileConstants.EXCEL_TYPE_XLSX);
return uploadServerData.getSecureUrl();
}
} }
...@@ -10,6 +10,7 @@ import cn.com.glsx.admin.modules.service.OpereportService; ...@@ -10,6 +10,7 @@ import cn.com.glsx.admin.modules.service.OpereportService;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.glsx.plat.common.utils.DateUtils; import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import com.glsx.plat.office.excel.EasyExcelUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -18,6 +19,8 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -18,6 +19,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -41,8 +44,20 @@ public class OpereportController extends AbstractController { ...@@ -41,8 +44,20 @@ public class OpereportController extends AbstractController {
@GetMapping(value = "/vehicle/export") @GetMapping(value = "/vehicle/export")
public R vehicleExport(ReportVehicleSearch search) { public R vehicleExport(ReportVehicleSearch search) {
List<ReportVehicleExport> list = opereportService.vehicleExport(search); List<ReportVehicleExport> list = opereportService.vehicleExport(search);
String url = super.uploadExcel(list, "运营统计报表(车辆维度)_" + DateUtils.formatSerial(new Date()), ReportVehicleExport.class); //String url = super.uploadExcel(list, "运营统计报表(车辆维度)_" + DateUtils.formatSerial(new Date()), ReportVehicleExport.class);
return R.ok().data(url);
String fileName = "运营统计报表(车辆维度)_" + DateUtils.formatSerial(new Date());
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
EasyExcelUtils.writeExcel(baos, list, fileName, ReportVehicleExport.class);
String url = getExportFileUrl(fileName, baos);
return R.ok().data(url);
} catch (IOException e) {
log.error("上传Excel失败:{}", e.getMessage());
}
return R.error("下载失败");
} }
@ApiOperation(value = "设备列表查询") @ApiOperation(value = "设备列表查询")
...@@ -56,8 +71,20 @@ public class OpereportController extends AbstractController { ...@@ -56,8 +71,20 @@ public class OpereportController extends AbstractController {
@GetMapping(value = "/device/export") @GetMapping(value = "/device/export")
public R deviceExport(ReportDeviceSearch search) { public R deviceExport(ReportDeviceSearch search) {
List<ReportDeviceExport> list = opereportService.deviceExport(search); List<ReportDeviceExport> list = opereportService.deviceExport(search);
String url = super.uploadExcel(list, "运营统计报表(设备维度)_" + DateUtils.formatSerial(new Date()), ReportDeviceExport.class); //String url = super.uploadExcel(list, "运营统计报表(设备维度)_" + DateUtils.formatSerial(new Date()), ReportDeviceExport.class);
return R.ok().data(url);
String fileName = "运营统计报表(设备维度)_" + DateUtils.formatSerial(new Date());
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
EasyExcelUtils.writeExcel(baos, list, fileName, ReportDeviceExport.class);
String url = getExportFileUrl(fileName, baos);
return R.ok().data(url);
} catch (IOException e) {
log.error("上传Excel失败:{}", e.getMessage());
}
return R.error("下载失败");
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!