|
|
@@ -638,7 +638,8 @@ public class PrintServiceImpl implements PrintService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean overload(String userName, String profile, String reportName, String whereCondition) {
|
|
|
+ public boolean overload(String userName, String profile, String reportName, String whereCondition,
|
|
|
+ String otherParameters) {
|
|
|
DataSource dataSource = MasterManager.getDataSource(userName, profile);
|
|
|
if (dataSource == null) {
|
|
|
throw new ReportException("获取数据源失败");
|
|
|
@@ -660,7 +661,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
}
|
|
|
|
|
|
// 因为子报表数据量较小,而且其参数来自主报表,无法简单地进行判断,所以不判断子报表是否过载
|
|
|
- int count = getCount(jrxmlFilePath, whereCondition, connection);
|
|
|
+ int count = getCount(jrxmlFilePath, whereCondition, otherParameters, connection);
|
|
|
logger.info("count... " + count);
|
|
|
return count >= MAX_RECODR_SIZE;
|
|
|
} catch (Exception e) {
|
|
|
@@ -681,9 +682,10 @@ public class PrintServiceImpl implements PrintService {
|
|
|
*
|
|
|
* @param jrxmlFilePath
|
|
|
* @param whereCondition
|
|
|
+ * @param otherParameters
|
|
|
* @param connection
|
|
|
*/
|
|
|
- private int getCount(String jrxmlFilePath, String whereCondition, Connection connection) {
|
|
|
+ private int getCount(String jrxmlFilePath, String whereCondition, String otherParameters, Connection connection) {
|
|
|
XMLWriter xmlWriter = null;
|
|
|
try {
|
|
|
SAXReader saxReader = new SAXReader();
|
|
|
@@ -697,6 +699,29 @@ public class PrintServiceImpl implements PrintService {
|
|
|
if (queryString.contains("$P!{WHERE_CONDITION}") && !StringUtils.isEmpty(whereCondition)) {
|
|
|
queryString = queryString.replace("$P!{WHERE_CONDITION}", whereCondition);
|
|
|
}
|
|
|
+ // 替换其他参数
|
|
|
+ if (queryString.contains("$")) {
|
|
|
+ if (StringUtils.isEmpty(otherParameters)) {
|
|
|
+ throw new ReportException("未传入动态参数");
|
|
|
+ }
|
|
|
+ JSONObject parameters = JSONObject.parseObject(otherParameters);
|
|
|
+ Pattern pattern = Pattern.compile("\\$P\\{([^\\$]*)\\}");
|
|
|
+ Matcher matcher = pattern.matcher(queryString);
|
|
|
+ while (matcher.find()) {
|
|
|
+ String match = matcher.group();
|
|
|
+ String parameterName = match.substring("$P{".length(), match.length() - 1);
|
|
|
+ Object value = parameters.get(parameterName);
|
|
|
+ if (value == null) {
|
|
|
+ throw new ReportException("未传入动态参数:" + parameterName);
|
|
|
+ }
|
|
|
+ // 如果不是数字,需以单引号括起来
|
|
|
+ if (value instanceof Number) {
|
|
|
+ queryString = queryString.replace(match, value.toString());
|
|
|
+ } else {
|
|
|
+ queryString = queryString.replace(match, "'" + value.toString() + "'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return getCount(connection, queryString);
|
|
|
} catch (DocumentException | SQLException e) {
|
|
|
throw new ReportException(e).setDetailedMessage(e);
|