|
|
@@ -41,9 +41,10 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.report.SpecialProperties;
|
|
|
import com.uas.report.core.exception.ReportException;
|
|
|
import com.uas.report.jasperreports.engine.export.CustomJRXlsExporter;
|
|
|
+import com.uas.report.model.Master;
|
|
|
import com.uas.report.service.FileService;
|
|
|
import com.uas.report.service.PrintService;
|
|
|
-import com.uas.report.util.DataSourceUtils;
|
|
|
+import com.uas.report.util.MasterManager;
|
|
|
import com.uas.report.util.FileUtils;
|
|
|
import com.uas.report.util.ReportConstants;
|
|
|
import com.uas.report.util.ReportUtils;
|
|
|
@@ -86,12 +87,8 @@ public class PrintServiceImpl implements PrintService {
|
|
|
@Override
|
|
|
public byte[] export(String userName, String profile, String reportName, String whereCondition,
|
|
|
String otherParameters, String exportFileType) {
|
|
|
- DataSource dataSource = DataSourceUtils.getDataSource(userName, profile);
|
|
|
- if (dataSource == null) {
|
|
|
- throw new ReportException("获取数据源失败");
|
|
|
- }
|
|
|
- Map<String, Object> result = print(userName, reportName, whereCondition, otherParameters, exportFileType, null,
|
|
|
- dataSource);
|
|
|
+ Map<String, Object> result = print(userName, profile, reportName, whereCondition, otherParameters,
|
|
|
+ exportFileType, null);
|
|
|
if (!CollectionUtils.isEmpty(result)) {
|
|
|
return (byte[]) result.get("data");
|
|
|
}
|
|
|
@@ -101,26 +98,23 @@ public class PrintServiceImpl implements PrintService {
|
|
|
@Override
|
|
|
public Map<String, Object> preview(String userName, String profile, String reportName, String whereCondition,
|
|
|
String otherParameters, Integer pageIndex) {
|
|
|
- DataSource dataSource = DataSourceUtils.getDataSource(userName, profile);
|
|
|
- if (dataSource == null) {
|
|
|
- throw new ReportException("获取数据源失败");
|
|
|
- }
|
|
|
- return print(userName, reportName, whereCondition, otherParameters, null, pageIndex, dataSource);
|
|
|
+ return print(userName, profile, reportName, whereCondition, otherParameters, null, pageIndex);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 输出报表的数据
|
|
|
*
|
|
|
* @param userName
|
|
|
+ * @param profile
|
|
|
* @param reportName
|
|
|
* @param whereCondition
|
|
|
* @param otherParameters
|
|
|
* @param exportFileType
|
|
|
* @param pageIndex
|
|
|
- * @return
|
|
|
+ * @return 页码pageSize:int,数据data:byte[]
|
|
|
*/
|
|
|
- private Map<String, Object> print(String userName, String reportName, String whereCondition, String otherParameters,
|
|
|
- String exportFileType, Integer pageIndex, DataSource dataSource) {
|
|
|
+ private Map<String, Object> print(String userName, String profile, String reportName, String whereCondition,
|
|
|
+ String otherParameters, String exportFileType, Integer pageIndex) {
|
|
|
// TODO 重新实现jasperserver接口
|
|
|
// try {
|
|
|
// resourceService.syncResources(userName);
|
|
|
@@ -128,12 +122,17 @@ public class PrintServiceImpl implements PrintService {
|
|
|
// throw new ReportException(e).setDetailedMessage(e);
|
|
|
// }
|
|
|
|
|
|
- userName = processMasterOfB2B(userName, reportName);
|
|
|
- String jrxmlFilePath = fileService.getJrxmlFilePath(userName, reportName);
|
|
|
+ DataSource dataSource = MasterManager.getDataSource(userName, profile);
|
|
|
+ if (dataSource == null) {
|
|
|
+ throw new ReportException("获取数据源失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ String masterOfJrxml = getMasterOfJrxml(userName, reportName);
|
|
|
+ String jrxmlFilePath = fileService.getJrxmlFilePath(masterOfJrxml, reportName);
|
|
|
|
|
|
// 向报表模板传递参数:报表路径、where条件、其他参数
|
|
|
Map<String, Object> parameters = new HashMap<>();
|
|
|
- parameters.put(ReportConstants.PARAMETER_REPORT_DIR, fileService.getMasterPath(userName));
|
|
|
+ parameters.put(ReportConstants.PARAMETER_REPORT_DIR, fileService.getMasterPath(masterOfJrxml));
|
|
|
if (!StringUtils.isEmpty(whereCondition)) {
|
|
|
parameters.put(ReportConstants.PARAMETER_WHERE_CONDITION, whereCondition);
|
|
|
}
|
|
|
@@ -503,7 +502,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String processMasterOfB2B(String userName, String reportName) {
|
|
|
+ public String getMasterOfJrxml(String userName, String reportName) {
|
|
|
ReportUtils.checkParameters(userName, reportName);
|
|
|
if (userName.startsWith("B2B")) {
|
|
|
String jrxmlFilePath = fileService.getJrxmlFilePath(userName, reportName);
|
|
|
@@ -512,6 +511,18 @@ public class PrintServiceImpl implements PrintService {
|
|
|
if (!jrxmlFile.exists()) {
|
|
|
return specialProperties.getStandardMaster() + "/B2B";
|
|
|
}
|
|
|
+ } else {
|
|
|
+ // 如果主账套与子账套共用模板
|
|
|
+ if (specialProperties.shareJrxmlsWithSubMaster()) {
|
|
|
+ Master master = MasterManager.getMaster(userName);
|
|
|
+ if (master != null) {
|
|
|
+ // 获取账套的主账套
|
|
|
+ while (master.hasParent()) {
|
|
|
+ master = MasterManager.getMaster(master.getParent().getName());
|
|
|
+ }
|
|
|
+ userName = master.getName();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return userName;
|
|
|
}
|