forked from demo/example
Browse Source
Merge in PG/plugin-report-doc-demo from ~ROSIE.XU/plugin-report-doc-demo-rosie:release/10.0 to release/10.0 * commit 'a6372ce1d78e262815994110a6f33edb9e4cbbc8': 自定义函数设置下拉树默认值-https://help.finereport.com/doc-view-3637.html 文档中用到的自定义函数 TREENODEFINDER Java脚本代码 函数用途:通过「自定义函数」实现根据子节点的值找出叶子节点的完整路径,从而实现下拉树控件默认值的简单设置。release/10.0
susie
4 years ago
1 changed files with 126 additions and 0 deletions
@ -0,0 +1,126 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package com.fr.function; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.SynchronizedLiveDataModelUtils; |
||||
import com.fr.data.impl.RecursionDataModel; |
||||
import com.fr.general.FArray; |
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.invoke.Reflect; |
||||
import com.fr.script.AbstractFunction; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.security.function.RestrictScript; |
||||
import com.fr.stable.Primitive; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.exception.FormulaException; |
||||
|
||||
import java.util.Map; |
||||
|
||||
@RestrictScript |
||||
public class TREENODEFINDER extends AbstractFunction { |
||||
public TREENODEFINDER() { |
||||
} |
||||
|
||||
public Object run(Object[] args) throws FormulaException { |
||||
if (!this.validateArgs(args)) { |
||||
return Primitive.ERROR_NAME; |
||||
} else { |
||||
boolean noLiveDataModel = !this.liveDataModel4ShareExists(); |
||||
DataModel dataModel = this.generateDataModel(args); |
||||
|
||||
try { |
||||
if (args.length != 2) { |
||||
return Primitive.NULL; |
||||
} |
||||
if (args[0] instanceof FArray) { |
||||
FArray nodeArray = (FArray) args[0]; |
||||
FArray result = new FArray(); |
||||
for (int i = 0; i < nodeArray.length(); i++) { |
||||
result.simpleAdd(this.run(GeneralUtils.objectToString(nodeArray.elementAt(i)), dataModel)); |
||||
} |
||||
return result; |
||||
} else { |
||||
return this.run(GeneralUtils.objectToString(args[0]), dataModel); |
||||
} |
||||
} finally { |
||||
if (noLiveDataModel && dataModel != null) { |
||||
try { |
||||
dataModel.release(); |
||||
} catch (Exception var11) { |
||||
this.log(var11.getMessage(), var11); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
private boolean liveDataModel4ShareExists() { |
||||
Calculator calculatorProvider = this.getCalculator(); |
||||
if (calculatorProvider == null) { |
||||
return false; |
||||
} else { |
||||
Map var1 = (Map) calculatorProvider.getAttribute(SynchronizedLiveDataModelUtils.CUR_LIVE_RS); |
||||
return var1 != null && !var1.isEmpty(); |
||||
} |
||||
} |
||||
|
||||
public Object run(String nodeValue, DataModel dataModel) { |
||||
try { |
||||
RecursionDataModel rdm = Reflect.on(dataModel).get("dataModel"); |
||||
int treeStart = 0; |
||||
|
||||
int m; |
||||
for (m = 0; m < rdm.getColumnCount(); ++m) { |
||||
String colName = rdm.getColumnName(m); |
||||
if (colName.startsWith("FR_GEN_")) { |
||||
treeStart = m; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
m = 0; |
||||
|
||||
for (int len = rdm.getRowCount(); m < len; ++m) { |
||||
int i = 0; |
||||
|
||||
for (int colCount = rdm.getColumnCount(); i < colCount; ++i) { |
||||
String value = GeneralUtils.objectToString(rdm.getValueAt(m, i)); |
||||
if (StringUtils.equals(nodeValue, value)) { |
||||
FArray array = new FArray(); |
||||
|
||||
for (int j = treeStart; j < colCount; ++j) { |
||||
String val = GeneralUtils.objectToString(rdm.getValueAt(m, j)); |
||||
if (StringUtils.isNotEmpty(val)) { |
||||
array.add(val); |
||||
} |
||||
} |
||||
|
||||
return array; |
||||
} |
||||
} |
||||
} |
||||
} catch (Exception var13) { |
||||
this.log(var13.getMessage(), var13); |
||||
} |
||||
|
||||
return Primitive.NULL; |
||||
} |
||||
|
||||
public boolean validateArgs(Object[] args) { |
||||
return args != null && args.length >= 1; |
||||
} |
||||
|
||||
public DataModel generateDataModel(Object[] args) { |
||||
return BaseUtils.getDataModelFromTableDataName(this.getCalculator(), args[1].toString()); |
||||
} |
||||
|
||||
public Type getType() { |
||||
return REPORT; |
||||
} |
||||
} |
Loading…
Reference in new issue