|
|
@@ -65,7 +65,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
String otherParameters, ExportType exportType)
|
|
|
throws JRException, IOException, DocumentException, SQLException {
|
|
|
Map<String, Object> result = print(userName, profile, reportName, whereCondition, otherParameters, exportType,
|
|
|
- null);
|
|
|
+ null, true);
|
|
|
if (!CollectionUtils.isEmpty(result)) {
|
|
|
return (byte[]) result.get("data");
|
|
|
}
|
|
|
@@ -76,7 +76,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
public Map<String, Object> preview(String userName, String profile, String reportName, String whereCondition,
|
|
|
String otherParameters, Integer pageIndex)
|
|
|
throws JRException, IOException, DocumentException, SQLException {
|
|
|
- return print(userName, profile, reportName, whereCondition, otherParameters, null, pageIndex);
|
|
|
+ return print(userName, profile, reportName, whereCondition, otherParameters, null, pageIndex, true);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -89,6 +89,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
* @param otherParameters
|
|
|
* @param exportType
|
|
|
* @param pageIndex
|
|
|
+ * @param useFileVirtualizer 是否使用文件虚拟化技术
|
|
|
* @return 页码pageSize:int,数据data:byte[]
|
|
|
* @throws JRException
|
|
|
* @throws IOException
|
|
|
@@ -96,7 +97,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
* @throws SQLException
|
|
|
*/
|
|
|
private Map<String, Object> print(String userName, String profile, String reportName, String whereCondition,
|
|
|
- String otherParameters, ExportType exportType, Integer pageIndex)
|
|
|
+ String otherParameters, ExportType exportType, Integer pageIndex, boolean useFileVirtualizer)
|
|
|
throws JRException, IOException, DocumentException, SQLException {
|
|
|
// TODO 重新实现jasperserver接口
|
|
|
// try {
|
|
|
@@ -115,12 +116,14 @@ public class PrintServiceImpl implements PrintService {
|
|
|
|
|
|
// 向报表模板传递参数:报表路径、where条件、其他参数
|
|
|
Map<String, Object> parameters = new HashMap<>();
|
|
|
- File virtualizerDir = new File(fileService.getMasterPath("tmp") + "/virtualizer");
|
|
|
- if (!virtualizerDir.exists()) {
|
|
|
- virtualizerDir.mkdirs();
|
|
|
- }
|
|
|
- parameters.put(JRParameter.REPORT_VIRTUALIZER, new JRFileVirtualizer(2, virtualizerDir.getAbsolutePath()));
|
|
|
- parameters.put(ReportConstants.PARAMETER_REPORT_DIR, fileService.getMasterPath(masterOfJrxml));
|
|
|
+ if (useFileVirtualizer) {
|
|
|
+ File virtualizerDir = new File(fileService.getMasterPath("tmp") + "/virtualizer");
|
|
|
+ if (!virtualizerDir.exists()) {
|
|
|
+ virtualizerDir.mkdirs();
|
|
|
+ }
|
|
|
+ parameters.put(JRParameter.REPORT_VIRTUALIZER, new JRFileVirtualizer(2, virtualizerDir.getAbsolutePath()));
|
|
|
+ }
|
|
|
+ parameters.put(ReportConstants.PARAMETER_REPORT_DIR, fileService.getMasterPath(masterOfJrxml));
|
|
|
if (!StringUtils.isEmpty(whereCondition)) {
|
|
|
parameters.put(ReportConstants.PARAMETER_WHERE_CONDITION, whereCondition);
|
|
|
}
|
|
|
@@ -199,7 +202,14 @@ public class PrintServiceImpl implements PrintService {
|
|
|
// TODO 先写入文件,用时再读取,防止数据量太大,内存不足
|
|
|
result.put("data", data);
|
|
|
return result;
|
|
|
- } finally {
|
|
|
+ } catch (JRRuntimeException e) {
|
|
|
+ // 如果因为某个类未实现 Serializable 而无法反序列化,则不使用 REPORT_VIRTUALIZER
|
|
|
+ if (e.getCause() instanceof NotSerializableException) {
|
|
|
+ logger.error(e.getMessage() + " 取消 REPORT_VIRTUALIZER ,重新打印");
|
|
|
+ return print(userName, profile, reportName, whereCondition, otherParameters, exportType, pageIndex, false);
|
|
|
+ }
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
if (connection != null) {
|
|
|
connection.close();
|
|
|
}
|