|
@@ -14,17 +14,6 @@ import java.util.Properties;
|
|
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
import javax.sql.DataSource;
|
|
|
|
|
|
|
|
-import org.apache.log4j.Logger;
|
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
|
-
|
|
|
|
|
-import com.alibaba.druid.pool.DruidDataSource;
|
|
|
|
|
-import com.alibaba.druid.pool.DruidDataSourceFactory;
|
|
|
|
|
-import com.uas.report.service.PrintService;
|
|
|
|
|
-import com.uas.report.util.ContextUtils;
|
|
|
|
|
-import com.uas.report.util.ReportConstants;
|
|
|
|
|
-
|
|
|
|
|
import net.sf.jasperreports.engine.JRException;
|
|
import net.sf.jasperreports.engine.JRException;
|
|
|
import net.sf.jasperreports.engine.JasperCompileManager;
|
|
import net.sf.jasperreports.engine.JasperCompileManager;
|
|
|
import net.sf.jasperreports.engine.JasperExportManager;
|
|
import net.sf.jasperreports.engine.JasperExportManager;
|
|
@@ -40,6 +29,18 @@ import net.sf.jasperreports.export.SimpleExporterInput;
|
|
|
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
|
|
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
|
|
|
import net.sf.jasperreports.export.SimplePdfReportConfiguration;
|
|
import net.sf.jasperreports.export.SimplePdfReportConfiguration;
|
|
|
|
|
|
|
|
|
|
+import org.apache.log4j.Logger;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.druid.pool.DruidDataSource;
|
|
|
|
|
+import com.alibaba.druid.pool.DruidDataSourceFactory;
|
|
|
|
|
+import com.uas.report.core.exception.SystemError;
|
|
|
|
|
+import com.uas.report.service.PrintService;
|
|
|
|
|
+import com.uas.report.util.ContextUtils;
|
|
|
|
|
+import com.uas.report.util.ReportConstants;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 报表打印
|
|
* 报表打印
|
|
|
*
|
|
*
|
|
@@ -52,8 +53,8 @@ public class PrintServiceImpl implements PrintService {
|
|
|
private static Logger logger = Logger.getLogger(PrintService.class);
|
|
private static Logger logger = Logger.getLogger(PrintService.class);
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public byte[] export(String userName, String reportName, String whereCondition, Map<String, Object> otherParameters,
|
|
|
|
|
- String exportFileType) {
|
|
|
|
|
|
|
+ public byte[] export(String userName, String reportName, String whereCondition,
|
|
|
|
|
+ Map<String, Object> otherParameters, String exportFileType) {
|
|
|
Map<String, Object> result = print(userName, reportName, whereCondition, otherParameters, exportFileType, null);
|
|
Map<String, Object> result = print(userName, reportName, whereCondition, otherParameters, exportFileType, null);
|
|
|
if (!CollectionUtils.isEmpty(result)) {
|
|
if (!CollectionUtils.isEmpty(result)) {
|
|
|
return (byte[]) result.get("data");
|
|
return (byte[]) result.get("data");
|
|
@@ -81,7 +82,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
private Map<String, Object> print(String userName, String reportName, String whereCondition,
|
|
private Map<String, Object> print(String userName, String reportName, String whereCondition,
|
|
|
Map<String, Object> otherParameters, String exportFileType, Integer pageIndex) {
|
|
Map<String, Object> otherParameters, String exportFileType, Integer pageIndex) {
|
|
|
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(reportName)) {
|
|
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(reportName)) {
|
|
|
- return null;
|
|
|
|
|
|
|
+ throw new SystemError("参数错误");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 报表路径为报表根路径REPORT_DIR + 当前账套用户名userName
|
|
// 报表路径为报表根路径REPORT_DIR + 当前账套用户名userName
|
|
@@ -94,7 +95,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
// 报表模板不存在
|
|
// 报表模板不存在
|
|
|
if (!jrxmlFile.exists()) {
|
|
if (!jrxmlFile.exists()) {
|
|
|
logger.error("未发现模板文件: " + jrxmlFile.getPath());
|
|
logger.error("未发现模板文件: " + jrxmlFile.getPath());
|
|
|
- return null;
|
|
|
|
|
|
|
+ throw new SystemError("未发现模板文件: " + jrxmlFile.getPath());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String jasperFilePath = jrxmlFile.getPath().replace(".jrxml", ".jasper");
|
|
String jasperFilePath = jrxmlFile.getPath().replace(".jrxml", ".jasper");
|
|
@@ -115,7 +116,8 @@ public class PrintServiceImpl implements PrintService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (JRException e) {
|
|
} catch (JRException e) {
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ logger.error(e);
|
|
|
|
|
+ throw new SystemError("编译报表模板失败");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 向报表模板传递参数:报表路径、where条件、其他参数
|
|
// 向报表模板传递参数:报表路径、where条件、其他参数
|
|
@@ -133,7 +135,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
// 获取数据源
|
|
// 获取数据源
|
|
|
DataSource dataSource = getDataSource(userName);
|
|
DataSource dataSource = getDataSource(userName);
|
|
|
if (dataSource == null) {
|
|
if (dataSource == null) {
|
|
|
- return null;
|
|
|
|
|
|
|
+ throw new SystemError("获取数据源失败");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
connection = dataSource.getConnection();
|
|
connection = dataSource.getConnection();
|
|
@@ -176,7 +178,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
return result;
|
|
return result;
|
|
|
} else {
|
|
} else {
|
|
|
logger.error("exportFileType 和 pageSize 不能同时为空!");
|
|
logger.error("exportFileType 和 pageSize 不能同时为空!");
|
|
|
- return null;
|
|
|
|
|
|
|
+ throw new SystemError("exportFileType 和 pageSize 不能同时为空!");
|
|
|
}
|
|
}
|
|
|
} catch (SQLException e) {
|
|
} catch (SQLException e) {
|
|
|
logger.error("数据库连接错误!");
|
|
logger.error("数据库连接错误!");
|