因为系统业务需要,只能使用springbean方式打印导出,勾选数据量少的时候一切正常,勾选上千条时参数太长系统报错,记录一下解决办法
handlePrint() {
this.loading = true;
pdfFileStream({
ids: this.Ids,
file: "file:test.ureport.xml",
}).then((response) => {
this.$tools.printPdf(response);//打印pdf流
this.loading = false;
});
},
export function pdfFileStream(data) {
return request({
url: '/system/printExcle/pdfFileStream',
method: 'post',
data: data,
timeout: 1000000,
responseType: 'blob',
})
}
@RestController
@RequestMapping("/system/printExcle")
public class PrintExcleController {
@Autowired
private ExportManager exportManager;
/**
* 打印-pdf流
* @param resp
* @throws IOException
*/
@PostMapping("/pdfFileStream")
public void pdfFileStream(@RequestBody PrintVo printVo, HttpServletResponse resp) throws IOException
{
if (printVo!=null) {
if(StringUtils.isNotBlank(printVo.getFile())) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("file",printVo.getFile());
if(printVo.getIds()!=null){
parameters.put("ids",StringUtils.join(printVo.getIds(), ","));
}
fileStream(parameters, resp);
}
}
}
public void fileStream(Map<String, Object> parameters, HttpServletResponse resp) throws IOException
{
OutputStream outputStream=resp.getOutputStream();
try {
resp.setContentType("application/pdf");
resp.setHeader("Content-Disposition","inline");
ExportConfigure configure=new ExportConfigureImpl(parameters.get("file").toString(),parameters,outputStream);
exportManager.exportPdf(configure);
}catch(Exception ex) {
throw new ReportException(ex);
}finally {
outputStream.flush();
outputStream.close();
}
}
public void excel(Map<String, Object> parameters, HttpServletResponse resp) throws IOException
{
OutputStream outputStream=null;
try {
resp.setContentType("application/octet-stream;charset=ISO8859-1");
resp.setHeader("Content-Disposition","attachment");
outputStream=resp.getOutputStream();
ExportConfigure configure=new ExportConfigureImpl(parameters.get("file").toString(),parameters,outputStream);
exportManager.exportExcel(configure);
}catch(Exception ex) {
throw new ReportException(ex);
}finally {
outputStream.flush();
outputStream.close();
}
}
}
public class PrintVo {
private String[] ids;
private String file;
}
@Component
public class CauseChangeHistoryBean {
public List<Test> test(String dsName, String datasetName, Map<String, Object> parameters) {
List<Test> list = new ArrayList<>();
......................
return list;
}