异步Jasper报表在更改参数名称时提供了所有数据。

huangapple 未分类评论49阅读模式
英文:

Async Jasper report gives ALL data when changing parameter name

问题

我正在处理一个现有的异步Jasper报表,该报表位于一个应用程序中,其中Java后端向Jasper服务器发送一个名为“employee_id”的参数。包含此参数名“employee_id”的相应.jrxml文件执行SQL查询以获取结果。

现在,根据新的功能,存在这样一种情况:应用程序可以发送超过1000个员工ID的情况。因此,在Java端,我正在创建每个包含最多1000个元素的子列表。
例如:

第一个子列表的参数名为 -> first1000_employee_id

第二个子列表的参数名为 -> second1000_employee_id

相应的.jrxml文件也已被修改,以添加这2个新参数,并且去除了“employee_id”。

现有的Java代码:

ReportParameter reportParameter = new ReportParameter();
reportParameter.setName("employee_id");
reportParameter.setValues(employeeIds); // employeeIds是List<String>
reportParameters.add(reportParameter);

新的Java代码:

ReportParameter reportParameterFirst1000 = new ReportParameter();
reportParameterFirst1000.setName("first1000_employee_id");
reportParameterFirst1000.setValues(first1000EmployeeIds);
reportParameters.add(reportParameterFirst1000);

ReportParameter reportParameterSecond1000 = new ReportParameter();
reportParameterSecond1000.setName("second1000_employee_id");
reportParameterSecond1000.setValues(second1000EmployeeIds);
reportParameters.add(reportParameterSecond1000);

ReportParameters parameters = new ReportParameters();
parameters.setReportParameters(reportParameters);
reportExecutionRequest.setParameters(parameters);

现有的.jrxml SQL查询:

SELECT  
    category_desc, 
	SUM(cnt)
	FROM (
        SELECT 
		category_desc,
        cnt 
        FROM   
        TXN_MV
  		WHERE
  		( employee_id IN ('0001022051') )
	 	) x       				
  		GROUP  BY 
        category_desc 
		HAVING 
       	SUM(cnt) > 0
 		ORDER BY 
  	   	cnt DESC

新的.jrxml SQL查询:

SELECT  
    category_desc, 
	SUM(cnt)
	FROM (
        SELECT 
		category_desc,
        cnt 
        FROM   
        TXN_MV
  		WHERE
  		( first1000_employee_id IN ('0001022051') 
        OR second1000_employee_id IN ('0001022052') )
	 	) x       				
  		GROUP  BY 
        category_desc 
		HAVING 
       	SUM(cnt) > 0
 		ORDER BY 
  	   	cnt DESC

现在,当我将此报表发布到Jasper服务器时,应用程序会选择所有员工ID的记录,而不是我根据新的.jrxml中的SQL查询在子列表中指定的记录。新定义的员工ID的WHERE条件被忽略,因此它从数据库中获取了所有记录。

我已经进行了调试,我看到所有的参数名都正确传递。

您能帮忙找出可能的问题吗?

英文:

I am working on an existing async jasper report in an application wherein the Java backend sends a parameter "employee_id" to the jasper server. Corresponding .jrxml file containing this parameter name "employee_id" executes the SQL query to fetch the results.

Now, as per the new functionality, there is a scenario when the application can send more than 1000 employee ids. So, in the Java side, I am creating sublists each containing at the max 1000 elements.
e.g.

first sublist has param name as --> first1000_employee_id

second sublist has param name as --> second1000_employee_id

The corresponding .jrxml file has also been modified to add these 2 new parameters and got rid of "employee_id".

Existing java code:

ReportParameter reportParameter = new ReportParameter();
reportParameter.setName(&quot;employee_id&quot;);
reportParameter.setValues(employeeIds); // employeeIds is List&lt;String&gt;
reportParameters.add(reportParameter);

New java code:

ReportParameter reportParameterFirst1000 = new ReportParameter();
reportParameterFirst1000.setName(&quot;first1000_employee_id&quot;);
reportParameterFirst1000.setValues(first1000EmployeeIds); 
reportParameters.add(reportParameterFirst1000);


ReportParameter reportParameterSecond1000 = new ReportParameter();
reportParameterSecond1000.setName(&quot;second1000_employee_id&quot;);
reportParameterSecond1000.setValues(second1000EmployeeIds);
reportParameters.add(reportParameterSecond1000);

ReportParameters parameters = new ReportParameters();
parameters.setReportParameters(reportParameters);
reportExecutionRequest.setParameters(parameters);

Existing .jrxml SQL query:

SELECT  
    category_desc, 
	SUM(cnt)
	FROM (
        SELECT 
		category_desc,
        cnt 
        FROM   
        TXN_MV
  		WHERE
  		( employee_id IN (&#39;0001022051&#39;) )
	 	) x       				
  		GROUP  BY 
        category_desc 
		HAVING 
       	SUM(cnt) &gt; 0
 		ORDER BY 
  	   	cnt DESC

New .jrxml SQL query:

SELECT  
    category_desc, 
	SUM(cnt)
	FROM (
        SELECT 
		category_desc,
        cnt 
        FROM   
        TXN_MV
  		WHERE
  		( first1000_employee_id IN (&#39;0001022051&#39;) 
        OR second1000_employee_id IN (&#39;0001022052&#39;) )
	 	) x       				
  		GROUP  BY 
        category_desc 
		HAVING 
       	SUM(cnt) &gt; 0
 		ORDER BY 
  	   	cnt DESC

Now, when I publish this report to jasper server, the application is picking the records for all the employee ids and not the ones I am specifying in the sublists based on the new SQL query in .jrxml. The WHERE condition for newly defined employee ids is getting ignored and so it is fetching all the records from the DB.

I have debugged and I see all the param names going correctly.

Could you please help what could be the issue ?

huangapple
  • 本文由 发表于 2020年5月5日 00:52:03
  • 转载请务必保留本文链接:https://java.coder-hub.com/61597471.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定