Compare commits
No commits in common. 'release/10.0' and 'release/10.0' have entirely different histories.
release/10
...
release/10
30 changed files with 196 additions and 899 deletions
@ -1,29 +0,0 @@ |
|||||||
package com.fr.data; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
public class SimpleArrayTableDataDemo extends SimpleTableData { |
|
||||||
|
|
||||||
/** |
|
||||||
* 初始化列头 |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public String[] initColumnNames() { |
|
||||||
return new String[]{"Name", "Score"}; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 加载行列数据 |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public List<Object[]> loadData() { |
|
||||||
ArrayList<Object[]> valueList = new ArrayList(); |
|
||||||
valueList.add(new Object[]{"Alex", 15}); |
|
||||||
valueList.add(new Object[]{"Helly", 22}); |
|
||||||
valueList.add(new Object[]{"Bobby", 99}); |
|
||||||
return valueList; |
|
||||||
} |
|
||||||
} |
|
@ -1,100 +0,0 @@ |
|||||||
package com.fr.data; |
|
||||||
|
|
||||||
import com.fr.file.ConnectionConfig; |
|
||||||
import com.fr.log.FineLoggerFactory; |
|
||||||
import com.fr.stable.ParameterProvider; |
|
||||||
|
|
||||||
import java.sql.Connection; |
|
||||||
import java.sql.DriverManager; |
|
||||||
import java.sql.ResultSet; |
|
||||||
import java.sql.ResultSetMetaData; |
|
||||||
import java.sql.SQLException; |
|
||||||
import java.sql.Statement; |
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
/** |
|
||||||
* 带参数的程序数据集Demo 跟ParamTableDataDemo功能一样,但实现更简单 |
|
||||||
* |
|
||||||
* @author fanruan |
|
||||||
*/ |
|
||||||
public class SimpleParamTableDataDemo extends SimpleTableData { |
|
||||||
|
|
||||||
@Override |
|
||||||
public String[] initColumnNames() { |
|
||||||
String[] columnNames = new String[10]; |
|
||||||
for (int i = 0; i < 10; i++) { |
|
||||||
columnNames[i] = "column#" + i; |
|
||||||
} |
|
||||||
return columnNames; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public List<Object[]> loadData() { |
|
||||||
// 保存得到的数据库表名
|
|
||||||
String tableName = ((ParameterProvider) (parameters.get().toArray())[0]).getValue().toString(); |
|
||||||
|
|
||||||
// 构造SQL语句,并打印出来
|
|
||||||
String sql = "select * from " + tableName; |
|
||||||
FineLoggerFactory.getLogger().info("Query SQL of ParamTableDataDemo: \n" + sql); |
|
||||||
// 保存得到的结果集
|
|
||||||
ArrayList<Object[]> valueList = new ArrayList(); |
|
||||||
// 下面开始建立数据库连接,按照刚才的SQL语句进行查询
|
|
||||||
// 根据连接名获取FR数据连接定义的数据连接,如果没有定义,也可以参考getConnection方法自己创建连接
|
|
||||||
com.fr.data.impl.Connection conn = ConnectionConfig.getInstance().getConnection("FRDemo"); |
|
||||||
Connection con = null; |
|
||||||
try { |
|
||||||
con = conn.createConnection(); |
|
||||||
Statement stmt = con.createStatement(); |
|
||||||
ResultSet rs = stmt.executeQuery(sql); |
|
||||||
// 获得记录的详细信息,然后获得总列数
|
|
||||||
ResultSetMetaData rsmd = rs.getMetaData(); |
|
||||||
int colNum = rsmd.getColumnCount(); |
|
||||||
// 用对象保存数据
|
|
||||||
Object[] objArray = null; |
|
||||||
while (rs.next()) { |
|
||||||
objArray = new Object[colNum]; |
|
||||||
for (int i = 0; i < colNum; i++) { |
|
||||||
objArray[i] = rs.getObject(i + 1); |
|
||||||
} |
|
||||||
// 在valueList中加入这一行数据
|
|
||||||
valueList.add(objArray); |
|
||||||
} |
|
||||||
// 释放数据库资源
|
|
||||||
rs.close(); |
|
||||||
stmt.close(); |
|
||||||
} catch (Exception e) { |
|
||||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
||||||
} finally { |
|
||||||
try { |
|
||||||
if (con != null) { |
|
||||||
con.close(); |
|
||||||
} |
|
||||||
} catch (SQLException e) { |
|
||||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
||||||
} |
|
||||||
} |
|
||||||
return valueList; |
|
||||||
} |
|
||||||
/** |
|
||||||
* 获取数据库连接 driverName和 url 可以换成您需要的 |
|
||||||
* |
|
||||||
* @return Connection |
|
||||||
*/ |
|
||||||
private Connection getConnection() { |
|
||||||
|
|
||||||
String driverName = "org.sqlite.JDBC"; |
|
||||||
String url = "jdbc:sqlite:////Applications//FineReport10_325//webapps//webroot//help//FRDemo.db"; |
|
||||||
String username = ""; |
|
||||||
String password = ""; |
|
||||||
Connection con = null; |
|
||||||
try { |
|
||||||
Class.forName(driverName); |
|
||||||
con = DriverManager.getConnection(url, username, password); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
||||||
} |
|
||||||
return con; |
|
||||||
} |
|
||||||
} |
|
@ -1,72 +0,0 @@ |
|||||||
package com.fr.demo; |
|
||||||
|
|
||||||
import com.fr.data.core.db.DBUtils; |
|
||||||
import com.fr.form.main.Form; |
|
||||||
import com.fr.log.FineLoggerFactory; |
|
||||||
import com.fr.web.session.SessionLocalManager; |
|
||||||
import com.fr.web.weblet.DBFormlet; |
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import java.io.InputStream; |
|
||||||
import java.sql.Blob; |
|
||||||
import java.sql.Connection; |
|
||||||
import java.sql.DriverManager; |
|
||||||
import java.sql.ResultSet; |
|
||||||
import java.sql.SQLException; |
|
||||||
import java.sql.Statement; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class NewReadFrmFromDatabase extends DBFormlet { |
|
||||||
|
|
||||||
@Override |
|
||||||
public Form createForm(HttpServletRequest reportletRequest) { |
|
||||||
String name = reportletRequest.getParameter("reportname"); |
|
||||||
return createForm(name); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public Form createForm(String reportName) { |
|
||||||
Form form = new Form(); |
|
||||||
Connection connection = null; |
|
||||||
try { |
|
||||||
connection = getConnection(); |
|
||||||
// 从数据库中读模板
|
|
||||||
String sql = "select frm from report where frmname = '" + reportName |
|
||||||
+ "'"; |
|
||||||
Statement smt = connection.createStatement(); |
|
||||||
ResultSet rs = smt.executeQuery(sql); |
|
||||||
while (rs.next()) { |
|
||||||
Blob blob = rs.getBlob(1); |
|
||||||
FineLoggerFactory.getLogger().info(blob.toString()); |
|
||||||
InputStream ins = blob.getBinaryStream(); |
|
||||||
form.readStream(ins); |
|
||||||
return form; |
|
||||||
} |
|
||||||
} catch (Exception e) { |
|
||||||
throw SessionLocalManager.createLogPackedException(e); |
|
||||||
}finally { |
|
||||||
DBUtils.closeConnection(connection); |
|
||||||
} |
|
||||||
|
|
||||||
return form; |
|
||||||
} |
|
||||||
|
|
||||||
private static Connection getConnection() throws ClassNotFoundException, SQLException { |
|
||||||
// 定义数据连接(根据你实际数据库信息进行修改)
|
|
||||||
String driver = "com.mysql.jdbc.Driver"; |
|
||||||
String url = "jdbc:mysql://localhost:3306/test"; |
|
||||||
String user = "root"; |
|
||||||
String pass = "123456"; |
|
||||||
Class.forName(driver); |
|
||||||
Connection conn = DriverManager.getConnection(url, user, pass); |
|
||||||
return conn; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setParameterMap(Map<String, Object> arg0) { |
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
} |
|
||||||
} |
|
Binary file not shown.
@ -1,14 +0,0 @@ |
|||||||
package com.fr.function; |
|
||||||
|
|
||||||
import com.fr.base.Utils; |
|
||||||
import com.fr.script.AbstractFunction; |
|
||||||
|
|
||||||
public class CellSum extends AbstractFunction { |
|
||||||
public Object run(Object[] args) { |
|
||||||
String sum = Utils.objectToNumber(new SUM().run(args), false) |
|
||||||
.toString(); // 直接调用FR内部的SUM方法
|
|
||||||
String result = "所在单元格为:" + this.getCalculator().getCurrentColumnRow() |
|
||||||
+ ";总和为:" + sum; // 获取当前单元格拼出最终结果
|
|
||||||
return result; |
|
||||||
} |
|
||||||
} |
|
Binary file not shown.
@ -1,67 +0,0 @@ |
|||||||
package com.fr.function; |
|
||||||
|
|
||||||
import com.fr.script.AbstractFunction; |
|
||||||
import com.fr.stable.Primitive; |
|
||||||
import java.util.Date; |
|
||||||
import java.util.regex.Matcher; |
|
||||||
import java.util.regex.Pattern; |
|
||||||
|
|
||||||
public class DateDiff extends AbstractFunction |
|
||||||
{ |
|
||||||
private static final long serialVersionUID = -2863679010825725885L; |
|
||||||
public String format = null; |
|
||||||
private Long dif = Long.valueOf(0L); |
|
||||||
|
|
||||||
public Object run(Object[] paramArrayOfObject) |
|
||||||
{ |
|
||||||
try |
|
||||||
{ |
|
||||||
Long localLong1 = Long.valueOf(((Date)paramArrayOfObject[0]).getTime()); |
|
||||||
Long localLong2 = Long.valueOf(((Date)paramArrayOfObject[1]).getTime()); |
|
||||||
this.dif = Long.valueOf(localLong2.longValue() - localLong1.longValue()); |
|
||||||
this.format = ((String)paramArrayOfObject[2]); |
|
||||||
replace("((?i)y)", Long.valueOf(31536000000L)); |
|
||||||
replace("((?i)q)", Long.valueOf(7776000000L)); |
|
||||||
replace("M", Long.valueOf(2592000000L)); |
|
||||||
replace("((?i)w)", Long.valueOf(604800000L)); |
|
||||||
replace("((?i)d)", Long.valueOf(86400000L)); |
|
||||||
replace("((?i)h)", Long.valueOf(3600000L)); |
|
||||||
replace("m", Long.valueOf(60000L)); |
|
||||||
replace("((?i)s)", Long.valueOf(1000L)); |
|
||||||
try |
|
||||||
{ |
|
||||||
return Long.valueOf(Long.parseLong(this.format)); |
|
||||||
} |
|
||||||
catch (Exception localException2) |
|
||||||
{ |
|
||||||
return this.format; |
|
||||||
} |
|
||||||
} |
|
||||||
catch (Exception localException1) |
|
||||||
{ |
|
||||||
} |
|
||||||
return Primitive.ERROR_VALUE; |
|
||||||
} |
|
||||||
|
|
||||||
public void replace(String paramString, Long paramLong) |
|
||||||
{ |
|
||||||
Pattern localPattern = Pattern.compile(paramString + "\\{\\d*?\\}"); |
|
||||||
Matcher localMatcher = localPattern.matcher(this.format); |
|
||||||
int i = (int)(this.dif.longValue() / paramLong.longValue()); |
|
||||||
int j = 1; |
|
||||||
while (localMatcher.find()) |
|
||||||
{ |
|
||||||
String str1 = localMatcher.group(); |
|
||||||
str1 = str1.replaceAll(paramString + "\\{", ""); |
|
||||||
str1 = str1.replaceAll("\\}", ""); |
|
||||||
int k = Integer.parseInt(str1); |
|
||||||
String str2 = String.format("%0" + k + "d", new Object[] { Integer.valueOf(i) }); |
|
||||||
if (j != 0) |
|
||||||
{ |
|
||||||
j = 0; |
|
||||||
this.dif = Long.valueOf(this.dif.longValue() - i * paramLong.longValue()); |
|
||||||
} |
|
||||||
this.format = this.format.replaceFirst(paramString + "\\{\\d*?\\}", str2); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Binary file not shown.
@ -1,67 +0,0 @@ |
|||||||
package com.fr.function; |
|
||||||
import com.fr.script.AbstractFunction; |
|
||||||
import com.fr.stable.Primitive; |
|
||||||
public class FlagHtmlColor extends AbstractFunction { |
|
||||||
public Object run(Object[] args) { |
|
||||||
String txt=""; |
|
||||||
String color=""; |
|
||||||
String flag=""; |
|
||||||
if(null==args||args.length==0){ |
|
||||||
return Primitive.ERROR_NAME; |
|
||||||
}else if(args.length==1){ |
|
||||||
txt=args[0].toString(); |
|
||||||
color="red"; |
|
||||||
flag="N"; |
|
||||||
}else if(args.length==2){ |
|
||||||
txt=args[0].toString(); |
|
||||||
color=args[1].toString(); |
|
||||||
flag="N"; |
|
||||||
}else{ |
|
||||||
txt=args[0].toString(); |
|
||||||
color=args[1].toString(); |
|
||||||
flag=args[2].toString(); |
|
||||||
} |
|
||||||
String result=getHtmlStr(txt, color, flag); |
|
||||||
return result; |
|
||||||
} |
|
||||||
public String getHtmlStr(String txt,String color,String flag){ |
|
||||||
String starthtml="<font color='"+color+"'>"; |
|
||||||
String endhtml="</font>"; |
|
||||||
StringBuffer sb=new StringBuffer(); |
|
||||||
int len=txt.length(); |
|
||||||
if("N".equalsIgnoreCase(flag)){//数字
|
|
||||||
for(int i=0;i<len;i++){ |
|
||||||
char c=txt.charAt(i); |
|
||||||
if(c>='0'&&c<='9'){ |
|
||||||
String str=starthtml+c+endhtml; |
|
||||||
sb.append(str); |
|
||||||
}else{ |
|
||||||
sb.append(c); |
|
||||||
} |
|
||||||
} |
|
||||||
}else if("C".equalsIgnoreCase(flag)){//字母
|
|
||||||
for(int i=0;i<len;i++){ |
|
||||||
char c=txt.charAt(i); |
|
||||||
if((c>='a'&&c<='z')||(c>='A'&&c<='Z')){ |
|
||||||
String str=starthtml+c+endhtml; |
|
||||||
sb.append(str); |
|
||||||
}else{ |
|
||||||
sb.append(c); |
|
||||||
} |
|
||||||
} |
|
||||||
} else if("Z".equalsIgnoreCase(flag)){//中文
|
|
||||||
for(int i=0;i<len;i++){ |
|
||||||
char c=txt.charAt(i); |
|
||||||
if(c >= 0x4E00 && c <= 0x9FA5){ |
|
||||||
String str=starthtml+c+endhtml; |
|
||||||
sb.append(str); |
|
||||||
}else{ |
|
||||||
sb.append(c); |
|
||||||
} |
|
||||||
} |
|
||||||
}else{ |
|
||||||
return txt; |
|
||||||
} |
|
||||||
return sb.toString(); |
|
||||||
} |
|
||||||
} |
|
Binary file not shown.
@ -1,152 +0,0 @@ |
|||||||
package com.fr.function; |
|
||||||
|
|
||||||
import java.math.BigDecimal; |
|
||||||
|
|
||||||
import com.fr.general.FArray; |
|
||||||
import com.fr.general.GeneralUtils; |
|
||||||
import com.fr.script.AbstractFunction; |
|
||||||
|
|
||||||
public class IRR extends AbstractFunction { |
|
||||||
|
|
||||||
private static final long serialVersionUID = 7634415917398642321L; |
|
||||||
private static final String ERROR_VALUE = "#NUM!"; |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
public Object run(Object[] args) { |
|
||||||
try{ |
|
||||||
if(1 == args.length){ |
|
||||||
return run( transArr( (FArray) args[0] ) ); |
|
||||||
}else if(2 == args.length){ |
|
||||||
return run( transArr( (FArray) args[0] ), trans( args[1] ) ); |
|
||||||
} |
|
||||||
}catch(Exception e){ |
|
||||||
System.out.println(e); |
|
||||||
} |
|
||||||
return ERROR_VALUE; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 将其他类型的数字转换为大数(保证精度) |
|
||||||
* @param ele |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
private static BigDecimal trans(Object ele){ |
|
||||||
try{ |
|
||||||
String val = GeneralUtils.objectToString(ele); |
|
||||||
return new BigDecimal(val); |
|
||||||
}catch(Exception e){ |
|
||||||
|
|
||||||
} |
|
||||||
return (BigDecimal) ele; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 将数组转换为大数数组 |
|
||||||
* @param in |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
private static FArray<BigDecimal> transArr(FArray in){ |
|
||||||
FArray<BigDecimal> rt = new FArray<BigDecimal>(); |
|
||||||
for(int i=0;i<in.length();i++){ |
|
||||||
Object ele = in.elementAt(i); |
|
||||||
rt.add(trans(ele)); |
|
||||||
} |
|
||||||
return rt; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private static BigDecimal run(FArray<BigDecimal> cashflow){ |
|
||||||
return run( cashflow, new BigDecimal(0.1d) ); |
|
||||||
} |
|
||||||
|
|
||||||
private static BigDecimal run(FArray<BigDecimal> cashflow,BigDecimal guess){ |
|
||||||
BigDecimal maxrate = initRateMax(cashflow,guess); |
|
||||||
BigDecimal minrate = initRateMin(cashflow,guess); |
|
||||||
for( int i=0; i<Init_Max_Loop; i++ ){ |
|
||||||
BigDecimal testrate = minrate.add(maxrate).divide( new BigDecimal(2d) ); |
|
||||||
BigDecimal npv = NPV( cashflow, testrate ); |
|
||||||
if( npv.abs().compareTo(Accuracy) == LESS ){ |
|
||||||
guess = testrate; |
|
||||||
break; |
|
||||||
}else if( npv.compareTo(ZERO) == LESS ){ |
|
||||||
minrate = testrate; |
|
||||||
}else{ |
|
||||||
maxrate = testrate; |
|
||||||
} |
|
||||||
} |
|
||||||
//保留16位小数(足够精度)
|
|
||||||
return guess.setScale(16,BigDecimal.ROUND_HALF_UP); |
|
||||||
} |
|
||||||
|
|
||||||
//最小精度
|
|
||||||
private static final BigDecimal Accuracy = new BigDecimal(0.00000001d); |
|
||||||
//最大循环次数,excel用的是20次,不过精度只到小数点后两位,而且不一定一定能算出值,为了尽可能保证算出结果,我增加到100次,
|
|
||||||
private static final int Init_Max_Loop = 100; |
|
||||||
|
|
||||||
private static final BigDecimal ZERO = new BigDecimal(0); |
|
||||||
private static final BigDecimal ONE = new BigDecimal(1); |
|
||||||
private static final BigDecimal Z005 = new BigDecimal(0.005d); |
|
||||||
private static final BigDecimal Z2 = new BigDecimal(0.2d); |
|
||||||
|
|
||||||
private static final int GREATER = 1; |
|
||||||
private static final int LESS = -1; |
|
||||||
|
|
||||||
/** |
|
||||||
* 生成一个使NPV为负数的R作为内部收益率下限值 |
|
||||||
* @param cashflow |
|
||||||
* @param guess |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
private static BigDecimal initRateMin(FArray<BigDecimal> cashflow,BigDecimal guess){ |
|
||||||
for( int i=0; i<Init_Max_Loop; i++ ){ |
|
||||||
BigDecimal npv = NPV( cashflow, guess ); |
|
||||||
|
|
||||||
if( npv.compareTo(ZERO) == LESS ){ |
|
||||||
return guess; |
|
||||||
} |
|
||||||
BigDecimal step = guess.abs().multiply( Z2 ); |
|
||||||
guess = guess.add( step.compareTo( Z005 ) == LESS ? Z005 : step ); |
|
||||||
} |
|
||||||
return guess; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 生成一个使NPV为正数的R作为内部收益率的上限制 |
|
||||||
* @param cashflow |
|
||||||
* @param guess |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
private static BigDecimal initRateMax(FArray<BigDecimal> cashflow,BigDecimal guess){ |
|
||||||
for( int i=0; i<Init_Max_Loop; i++ ){ |
|
||||||
BigDecimal npv = NPV( cashflow, guess ); |
|
||||||
|
|
||||||
if( npv.compareTo(ZERO) == GREATER ){ |
|
||||||
return guess; |
|
||||||
} |
|
||||||
BigDecimal step = guess.abs().multiply( Z2 ); |
|
||||||
guess = guess.subtract( step.compareTo( Z005 ) == LESS ? Z005 : step ); |
|
||||||
} |
|
||||||
return guess; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 算NPV |
|
||||||
* @param cashflow |
|
||||||
* @param rate |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
private static BigDecimal NPV(FArray<BigDecimal> cashflow,BigDecimal rate){ |
|
||||||
BigDecimal npv = ZERO; |
|
||||||
BigDecimal rpowj = ONE;//(1+r)^0
|
|
||||||
BigDecimal radd1 = rate.add(ONE);//1+r
|
|
||||||
for( int j=0; j<cashflow.length(); j++ ){ |
|
||||||
BigDecimal valuej = cashflow.elementAt(j); |
|
||||||
npv = npv.add( valuej.divide( rpowj, 10, BigDecimal.ROUND_HALF_DOWN ) );// vj / (1+r)^j
|
|
||||||
rpowj = rpowj.multiply(radd1); // (1+r)^j
|
|
||||||
//npv += cashflow.elementAt(j) / Math.pow( 1+rate, j );
|
|
||||||
} |
|
||||||
return npv; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
Binary file not shown.
@ -1,128 +0,0 @@ |
|||||||
// 自定义函数实现表间校验
|
|
||||||
package com.fr.function; |
|
||||||
|
|
||||||
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.json.JSONArray; |
|
||||||
import com.fr.json.JSONObject; |
|
||||||
import com.fr.main.impl.WorkBook; |
|
||||||
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.module.ReportBaseActivator; |
|
||||||
import com.fr.report.report.ResultReport; |
|
||||||
import com.fr.script.AbstractFunction; |
|
||||||
import com.fr.stable.WriteActor; |
|
||||||
import com.fr.store.StateServiceActivator; |
|
||||||
import com.fr.workspace.simple.SimpleWork; |
|
||||||
import com.fr.write.cal.WB; |
|
||||||
|
|
||||||
import java.util.HashMap; |
|
||||||
|
|
||||||
public class ReportCheck extends AbstractFunction { |
|
||||||
private static HashMap wMap = new HashMap(); |
|
||||||
|
|
||||||
public Object run(Object[] args) { |
|
||||||
// 获取公式中的参数
|
|
||||||
String cptname = args[0].toString(); // 获取报表名称
|
|
||||||
int colnumber = Integer.parseInt(args[2].toString()); // 所取单元格所在列
|
|
||||||
int rownumber = Integer.parseInt(args[3].toString()); // 所取单元格所在行
|
|
||||||
// 定义返回的值
|
|
||||||
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 { |
|
||||||
ResultWorkBook rworkbook = null; |
|
||||||
// 读取模板
|
|
||||||
WorkBook workbook = (WorkBook)TemplateWorkBookIO |
|
||||||
.readTemplateWorkBook(cptname); |
|
||||||
// 获取需要传递给报表的参数名与参数值,格式如[{"name":para1name,"value":para1value},{"name":para2name,"value":para2value},......]
|
|
||||||
JSONArray parasArray = new JSONArray(args[1].toString()); |
|
||||||
// 需要判断是否是5秒内执行过的
|
|
||||||
// 取出保存的resultworkbook;
|
|
||||||
Object tempWObj = wMap.get(cptname + parasArray.toString()); |
|
||||||
if (tempWObj != null) { |
|
||||||
// 取出hashmap里面保存的TpObj;
|
|
||||||
TpObj curTpObj = (TpObj) tempWObj; |
|
||||||
|
|
||||||
if ((System.currentTimeMillis() - curTpObj.getExeTime()) < 8000) { |
|
||||||
rworkbook = curTpObj.getRworkbook(); |
|
||||||
} else { |
|
||||||
wMap.remove(cptname + parasArray.toString()); |
|
||||||
} |
|
||||||
} |
|
||||||
// 如果没有设置,需要生成
|
|
||||||
if (rworkbook == null) { |
|
||||||
JSONObject jo = new JSONObject(); |
|
||||||
// 定义报表执行时使用的paraMap,保存参数名与值
|
|
||||||
java.util.Map parameterMap = new java.util.HashMap(); |
|
||||||
if (parasArray.length() > 0) { |
|
||||||
for (int i = 0; i < parasArray.length(); i++) { |
|
||||||
jo = parasArray.getJSONObject(i); |
|
||||||
parameterMap.put(jo.get("name"), jo.get("value")); |
|
||||||
} |
|
||||||
} |
|
||||||
// 执行报表
|
|
||||||
rworkbook = workbook.execute(parameterMap, new WriteActor()); |
|
||||||
// 保存下来
|
|
||||||
wMap.put(cptname + parasArray.toString(), new TpObj(rworkbook, |
|
||||||
System.currentTimeMillis())); |
|
||||||
} |
|
||||||
// 获取报表结果中对应Cell的值
|
|
||||||
ResultReport report = rworkbook.getResultReport(0); |
|
||||||
CellElement cellElement = ((WB) report).getCellElement(colnumber, rownumber); |
|
||||||
returnValue = cellElement.getValue().toString(); |
|
||||||
if(cellElement.getValue() instanceof ResultFormula) { |
|
||||||
returnValue = ((ResultFormula)cellElement.getValue()).getResult().toString(); |
|
||||||
} |
|
||||||
} catch (Exception e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
return returnValue; |
|
||||||
} |
|
||||||
|
|
||||||
class TpObj { |
|
||||||
private ResultWorkBook rworkbook = null; |
|
||||||
private long exeTime = System.currentTimeMillis(); |
|
||||||
|
|
||||||
public TpObj(ResultWorkBook rworkbook, long exeTime) { |
|
||||||
this.setRworkbook(rworkbook); |
|
||||||
this.setExeTime(exeTime); |
|
||||||
} |
|
||||||
|
|
||||||
public ResultWorkBook getRworkbook() { |
|
||||||
return rworkbook; |
|
||||||
} |
|
||||||
|
|
||||||
public void setRworkbook(ResultWorkBook rworkbook) { |
|
||||||
this.rworkbook = rworkbook; |
|
||||||
} |
|
||||||
|
|
||||||
public long getExeTime() { |
|
||||||
return exeTime; |
|
||||||
} |
|
||||||
|
|
||||||
public void setExeTime(long exeTime) { |
|
||||||
this.exeTime = exeTime; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
Binary file not shown.
@ -1,15 +0,0 @@ |
|||||||
package com.fr.function; |
|
||||||
|
|
||||||
import com.fr.script.AbstractFunction; |
|
||||||
|
|
||||||
public class StringCat extends AbstractFunction { |
|
||||||
public Object run(Object[] args) { |
|
||||||
String result = ""; |
|
||||||
Object para; |
|
||||||
for (int i = 0; i < args.length; i++) { |
|
||||||
para = args[i]; |
|
||||||
result += para.toString(); |
|
||||||
} |
|
||||||
return result; |
|
||||||
} |
|
||||||
} |
|
Binary file not shown.
@ -1,59 +0,0 @@ |
|||||||
//图片在下文字在上
|
|
||||||
package com.fr.function; |
|
||||||
|
|
||||||
import com.fr.base.GraphHelper; |
|
||||||
import com.fr.data.core.db.BinaryObject; |
|
||||||
import com.fr.log.FineLoggerFactory; |
|
||||||
import com.fr.script.AbstractFunction; |
|
||||||
import com.fr.stable.CoreGraphHelper; |
|
||||||
import javax.imageio.ImageIO; |
|
||||||
import java.awt.Graphics2D; |
|
||||||
import java.awt.Image; |
|
||||||
import java.awt.image.BufferedImage; |
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* 图片在下文字在上 |
|
||||||
*/ |
|
||||||
public class StringImage extends AbstractFunction { |
|
||||||
@Override |
|
||||||
public Object run(Object[] args) { |
|
||||||
Image result = null; |
|
||||||
int p = 0; |
|
||||||
Object[] ob = new Object[2]; |
|
||||||
for (int i = 0; (i < args.length && p <= 1); i++) { |
|
||||||
if (args[i] == null) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
ob[p] = args[i]; |
|
||||||
p++; |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
if (ob[1] instanceof BinaryObject) { |
|
||||||
BinaryObject binaryObject = (BinaryObject) ob[1]; |
|
||||||
try { |
|
||||||
result = initStringImage((String) ob[0], ImageIO.read(binaryObject.getInputStream())); |
|
||||||
} catch (IOException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
} else if (ob[1] instanceof Image) { |
|
||||||
result = initStringImage((String) ob[0], (Image) ob[1]); |
|
||||||
} else { |
|
||||||
FineLoggerFactory.getLogger().warn("Unsupported type of " + ob[1].getClass()); |
|
||||||
} |
|
||||||
|
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
private Image initStringImage(String name, Image image) { |
|
||||||
BufferedImage splashBuffedImage = CoreGraphHelper.toBufferedImage(image); |
|
||||||
Graphics2D splashG2d = splashBuffedImage.createGraphics(); |
|
||||||
double centerX = 25; |
|
||||||
double centerY = 25; |
|
||||||
GraphHelper.drawString(splashG2d, name, centerX, centerY); |
|
||||||
return splashBuffedImage; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
Binary file not shown.
@ -1,25 +0,0 @@ |
|||||||
// 自定义函数Unicode编码转化为中文
|
|
||||||
package com.fr.function; |
|
||||||
|
|
||||||
import com.fr.script.AbstractFunction; |
|
||||||
|
|
||||||
public class Ubm extends AbstractFunction { |
|
||||||
public Object run(Object[] args) { |
|
||||||
String str = args[0].toString(); |
|
||||||
String st = ""; |
|
||||||
StringBuffer buffer = new StringBuffer(); |
|
||||||
while (str.length() > 0) { |
|
||||||
if (str.startsWith("%u")) { |
|
||||||
st = str.substring(2, 6); |
|
||||||
char ch = (char) Integer.parseInt(String.valueOf(st), 16); |
|
||||||
buffer.append(new Character(ch).toString()); |
|
||||||
str = str.substring(6); |
|
||||||
} else { |
|
||||||
st = str.substring(0, str.indexOf("%u")); |
|
||||||
buffer.append(st); |
|
||||||
str = str.substring(st.length()); |
|
||||||
} |
|
||||||
} |
|
||||||
return buffer.toString(); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,78 @@ |
|||||||
|
package com.fr.io; |
||||||
|
|
||||||
|
import com.fr.base.operator.common.CommonOperator; |
||||||
|
import com.fr.chart.activator.ChartBaseActivator; |
||||||
|
import com.fr.cluster.engine.activator.standalone.StandaloneModeActivator; |
||||||
|
import com.fr.config.activator.BaseDBActivator; |
||||||
|
import com.fr.config.activator.ConfigurationActivator; |
||||||
|
import com.fr.env.operator.CommonOperatorImpl; |
||||||
|
import com.fr.general.I18nResource; |
||||||
|
import com.fr.health.activator.ModuleHealActivator; |
||||||
|
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.module.ReportBaseActivator; |
||||||
|
import com.fr.report.write.WriteActivator; |
||||||
|
import com.fr.scheduler.SchedulerActivator; |
||||||
|
import com.fr.store.StateServiceActivator; |
||||||
|
import com.fr.workspace.simple.SimpleWork; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.FileInputStream; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.sql.PreparedStatement; |
||||||
|
|
||||||
|
public class SaveReportToDatabase { |
||||||
|
public static void main(String[] args) { |
||||||
|
SaveReport(); |
||||||
|
} |
||||||
|
private static void SaveReport() { |
||||||
|
try { |
||||||
|
// 连接数据库
|
||||||
|
String driver = "com.mysql.jdbc.Driver"; |
||||||
|
String url = "jdbc:mysql://review.finedevelop.com:3306/susie"; |
||||||
|
String user = "root"; |
||||||
|
String pass = "ilovejava"; |
||||||
|
Class.forName(driver); |
||||||
|
Connection conn = DriverManager.getConnection(url, user, pass); |
||||||
|
PreparedStatement presmt = conn |
||||||
|
.prepareStatement("insert into report values(?,?)"); |
||||||
|
// 读进需要保存入库的模板文件
|
||||||
|
// 首先需要定义执行所在的环境,这样才能正确读取数据库信息
|
||||||
|
// 定义报表运行环境,用于执行报表
|
||||||
|
Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(), |
||||||
|
new ConfigurationActivator(), |
||||||
|
new ResourceRepositoryActivator(), |
||||||
|
new StandaloneModeActivator(), |
||||||
|
new ModuleHealActivator(), |
||||||
|
new StateServiceActivator(), |
||||||
|
new ChartBaseActivator(), |
||||||
|
new SchedulerActivator(), |
||||||
|
new ReportBaseActivator(), |
||||||
|
new RestrictionActivator(), |
||||||
|
new ReportActivator(), |
||||||
|
new WriteActivator()); |
||||||
|
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl()); |
||||||
|
String envpath = "//Applications//FineReport10_325//webapps//webroot//WEB-INF";//工程路径
|
||||||
|
SimpleWork.checkIn(envpath); |
||||||
|
I18nResource.getInstance(); |
||||||
|
module.start(); |
||||||
|
|
||||||
|
File cptfile = new File("//doc//Primary//Parameter//Parameter.cpt"); |
||||||
|
int lens = (int) cptfile.length(); |
||||||
|
InputStream ins = new FileInputStream(cptfile); |
||||||
|
// 将模板保存入库
|
||||||
|
presmt.setString(1, "Parameter.cpt"); // 第一个字段存放模板相对路径
|
||||||
|
presmt.setBinaryStream(2, ins, lens); // 第二个字段存放模板文件的二进制流
|
||||||
|
presmt.execute(); |
||||||
|
conn.commit(); |
||||||
|
presmt.close(); |
||||||
|
conn.close(); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue