自定义finereport/finebi函数
//自测版
package com.fr.function;
import com.fr.script.AbstractFunction;
public class TestFun extends AbstractFunction {
public Object run(Object[] args) {
String result = "";
Object str,matchP,match1,match2;
str = args[0];//需处理字符串
matchP = args[1].toString();//需处理字符串中关键字符串
match1 = args[2].toString().replaceAll("%s",matchP.toString());//替换关键字符串之前的值为空
match2 = args[3];//替换关键字符串之后的值为空
result = str.toString().replaceAll(match1.toString(), "");//关键字符串之后无,逗号情况下直接return
if (result.contains(",")){//当关键字符串之后存在,逗号情况下
result = str.toString().replaceAll(match1.toString(), "")
.replaceAll(match2.toString(), "");//运算处理
}
System.out.println(match1);
return result;
}
public static void main(String[] args) {
String str = "202103_5-正常12,202206_5-正常1,202101_5-正常,202109_5-正常,202107_5-正常,202207_2-民营,202110_5-正常,202209_5-正常,202105_5-正常,202112_5-正常,202203_5-正常,202204_5-正常,202202_5-正常,202210_,202201_5-正常,202106_5-正常,202111_5-正常,202208_5-正常,202205_2-商业,202102_5-正常,202104_5-正常,202108_5-正常last";
String matchP = "202108";
String match1 = "^.*?%s_(?=.+,?)";
String match2 = ",.*?$";
TestFun t = new TestFun();
System.out.println(t.run(new Object[]{str,matchP,match1,match2})+"aa");
System.out.println("!");
}
}
输出结果
^.*?202108_(?=.+,?)
5-正常lastaa
!
//正式版本 转换class文件后可直接放置使用
package com.fr.function;
import com.fr.script.AbstractFunction;
public class TestFun extends AbstractFunction {
public Object run(Object[] args) {
String result = "";
Object str,matchP,match1,match2;
str = args[0];//需处理字符串
matchP = args[1].toString();//需处理字符串中关键字符串
match1 = args[2].toString().replaceAll("%s",matchP.toString());//替换关键字符串之前的值为空
match2 = args[3];//替换关键字符串之后的值为空
result = str.toString().replaceAll(match1.toString(), "");//关键字符串之后无,逗号情况下直接return
if (result.contains(",")){//当关键字符串之后存在,逗号情况下
result = str.toString().replaceAll(match1.toString(), "")
.replaceAll(match2.toString(), "");//运算处理
}
// System.out.println(match1);
return result;
}
// public static void main(String[] args) {
// String str = "202103_5-正常12,202206_5-正常1,202101_5-正常,202109_5-正常,202107_5-正常,202207_2-民营,202110_5-正常,202209_5-正常,202105_5-正常,202112_5-正常,202203_5-正常,202204_5-正常,202202_5-正常,202210_,202201_5-正常,202106_5-正常,202111_5-正常,202208_5-正常,202205_2-商业,202102_5-正常,202104_5-正常,202108_5-正常last";
// String matchP = "202108";
// String match1 = "^.*?%s_(?=.+,?)";
// String match2 = ",.*?$";
// TestFun t = new TestFun();
// System.out.println(t.run(new Object[]{str,matchP,match1,match2})+"aa");
// System.out.println("!");
// }
}