Browse Source

REPORT-91033 修复代码

persist/11.0
obo 1 year ago
parent
commit
9098db36a0
  1. 84
      src/main/java/com/fr/function/ReportCheck.java

84
src/main/java/com/fr/function/ReportCheck.java

@ -1,92 +1,67 @@
// 自定义函数实现表间校验
package com.fr.function; package com.fr.function;
import com.fr.base.ResultFormula; import com.fr.base.ResultFormula;
import com.fr.base.operator.common.CommonOperator;
import com.fr.chart.activator.ChartBaseActivator;
import com.fr.config.activator.BaseDBActivator;
import com.fr.config.activator.ConfigurationActivator;
import com.fr.env.operator.CommonOperatorImpl;
import com.fr.io.TemplateWorkBookIO; import com.fr.io.TemplateWorkBookIO;
import com.fr.json.JSONArray; import com.fr.json.JSONArray;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.main.impl.WorkBook; import com.fr.main.impl.WorkBook;
import com.fr.main.workbook.ResultWorkBook; import com.fr.main.workbook.ResultWorkBook;
import com.fr.module.Module;
import com.fr.module.tool.ActivatorToolBox;
import com.fr.report.ReportActivator;
import com.fr.report.RestrictionActivator;
import com.fr.report.cell.CellElement; import com.fr.report.cell.CellElement;
import com.fr.report.module.ReportBaseActivator;
import com.fr.report.report.ResultReport; import com.fr.report.report.ResultReport;
import com.fr.script.AbstractFunction; import com.fr.script.AbstractFunction;
import com.fr.stable.WriteActor; import com.fr.stable.WriteActor;
import com.fr.store.StateServiceActivator;
import com.fr.workspace.simple.SimpleWork;
import com.fr.write.cal.WB; import com.fr.write.cal.WB;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
public class ReportCheck extends AbstractFunction { public class ReportCheck extends AbstractFunction {
private static HashMap wMap = new HashMap();
private static final Map<String, TpObj> wMap = new HashMap<>();
public Object run(Object[] args) { public Object run(Object[] args) {
// 获取公式中的参数 // 获取公式中的参数
String cptname = args[0].toString(); // 获取报表名称 String cptname = args[0].toString(); // 获取报表名称
int colnumber = Integer.parseInt(args[2].toString()); // 所取单元格所在列 int colnumber = Integer.parseInt(args[2].toString()); // 所取单元格所在列
int rownumber = Integer.parseInt(args[3].toString()); // 所取单元格所在行 int rownumber = Integer.parseInt(args[3].toString()); // 所取单元格所在行
// 定义返回的值 // 定义返回的值
Object returnValue = null; Object returnValue = null;
// 定义报表运行环境,用于执行报表
Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(),
new ConfigurationActivator(),
new StateServiceActivator(),
new ReportBaseActivator(),
new RestrictionActivator(),
new ReportActivator(),
new ChartBaseActivator());
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl());
String envpath= "//Applications//FineReport10_325//webapps//webroot//WEB-INF"; //工程路径
SimpleWork.checkIn(envpath);
module.start();
try { try {
ResultWorkBook rworkbook = null; ResultWorkBook rworkbook = null;
// 读取模板 // 读取模板
WorkBook workbook = (WorkBook)TemplateWorkBookIO WorkBook workbook = (WorkBook)TemplateWorkBookIO
.readTemplateWorkBook(cptname); .readTemplateWorkBook(cptname);
// 获取需要传递给报表的参数名与参数值,格式如[{"name":para1name,"value":para1value},{"name":para2name,"value":para2value},......] // 获取需要传递给报表的参数名与参数值,格式如[{"name":para1name,"value":para1value},{"name":para2name,"value":para2value},......]
JSONArray parasArray = new JSONArray(args[1].toString()); JSONArray parasArray = new JSONArray(args[1].toString());
// 需要判断是否是5秒内执行过的 // 需要判断是否是8秒内执行过的
// 取出保存的resultworkbook;
Object tempWObj = wMap.get(cptname + parasArray.toString()); TpObj tempWObj = wMap.get(cptname + parasArray);
if (tempWObj != null) { if (tempWObj != null) {
// 取出hashmap里面保存的TpObj;
TpObj curTpObj = (TpObj) tempWObj;
if ((System.currentTimeMillis() - curTpObj.getExeTime()) < 8000) { if ((System.currentTimeMillis() - tempWObj.getExeTime()) < 8000) {
rworkbook = curTpObj.getRworkbook(); rworkbook = tempWObj.getRworkbook();
} else { } else {
wMap.remove(cptname + parasArray.toString()); wMap.remove(cptname + parasArray);
} }
} }
// 如果没有设置,需要生成 // 如果没有设置,需要生成
if (rworkbook == null) { if (rworkbook == null) {
JSONObject jo = new JSONObject(); JSONObject jo;
// 定义报表执行时使用的paraMap,保存参数名与值 // 定义报表执行时使用的paraMap,保存参数名与值
java.util.Map parameterMap = new java.util.HashMap(); Map parameterMap = new HashMap<>();
if (parasArray.length() > 0) { if (!parasArray.isEmpty()) {
for (int i = 0; i < parasArray.length(); i++) { for (int i = 0; i < parasArray.length(); i++) {
jo = parasArray.getJSONObject(i); jo = parasArray.getJSONObject(i);
parameterMap.put(jo.get("name"), jo.get("value")); parameterMap.put(jo.get("name"), jo.get("value"));
} }
} }
// 执行报表 // 执行报表
rworkbook = workbook.execute(parameterMap, new WriteActor()); rworkbook = workbook.execute(parameterMap, new WriteActor());
// 保存下来 // 保存下来
wMap.put(cptname + parasArray.toString(), new TpObj(rworkbook, wMap.put(cptname + parasArray, new TpObj(rworkbook,
System.currentTimeMillis())); System.currentTimeMillis()));
} }
// 获取报表结果中对应Cell的值 // 获取报表结果中对应Cell的值
ResultReport report = rworkbook.getResultReport(0); ResultReport report = rworkbook.getResultReport(0);
CellElement cellElement = ((WB) report).getCellElement(colnumber, rownumber); CellElement cellElement = ((WB) report).getCellElement(colnumber, rownumber);
returnValue = cellElement.getValue().toString(); returnValue = cellElement.getValue().toString();
@ -98,31 +73,24 @@ public class ReportCheck extends AbstractFunction {
} }
return returnValue; return returnValue;
} }
static class TpObj {
class TpObj {
private ResultWorkBook rworkbook = null; private ResultWorkBook rworkbook = null;
private long exeTime = System.currentTimeMillis(); private long exeTime = System.currentTimeMillis();
public TpObj(ResultWorkBook rworkbook, long exeTime) { public TpObj(ResultWorkBook rworkbook, long exeTime) {
this.setRworkbook(rworkbook); this.setRworkbook(rworkbook);
this.setExeTime(exeTime); this.setExeTime(exeTime);
} }
public ResultWorkBook getRworkbook() { public ResultWorkBook getRworkbook() {
return rworkbook; return rworkbook;
} }
public void setRworkbook(ResultWorkBook rworkbook) { public void setRworkbook(ResultWorkBook rworkbook) {
this.rworkbook = rworkbook; this.rworkbook = rworkbook;
} }
public long getExeTime() { public long getExeTime() {
return exeTime; return exeTime;
} }
public void setExeTime(long exeTime) { public void setExeTime(long exeTime) {
this.exeTime = exeTime; this.exeTime = exeTime;
} }
} }
}
}

Loading…
Cancel
Save