Compare commits
11 Commits
release/10
...
persist/10
Author | SHA1 | Date |
---|---|---|
|
d1776fa526 | 5 years ago |
|
ca629a1ff6 | 5 years ago |
|
99ff96fea6 | 5 years ago |
|
e1f402023f | 5 years ago |
|
5a3d9301af | 5 years ago |
|
34ec362f64 | 5 years ago |
|
c81c49f7ad | 5 years ago |
|
9a474478b3 | 5 years ago |
|
10e88848e4 | 6 years ago |
|
d6274eea84 | 6 years ago |
|
de51123131 | 6 years ago |
41 changed files with 451 additions and 571 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
|
|
||||||
|
|
||||||
} |
|
||||||
} |
|
@ -1,34 +0,0 @@ |
|||||||
package com.fr.demo; |
|
||||||
|
|
||||||
import java.util.Map; |
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
|
|
||||||
import com.fr.form.main.Form; |
|
||||||
import com.fr.form.main.FormIO; |
|
||||||
import com.fr.log.FineLoggerFactory; |
|
||||||
import com.fr.web.weblet.Formlet; |
|
||||||
|
|
||||||
|
|
||||||
public class SimpleReportletDemoFrm extends Formlet { |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setParameterMap(Map arg0) { |
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected Form createForm(HttpServletRequest request) throws Exception { |
|
||||||
Form form = null; |
|
||||||
//模板的相对路径
|
|
||||||
String tplPath = "//doc//frm//决策报表入门.frm"; |
|
||||||
this.setTplPath(tplPath); |
|
||||||
try { |
|
||||||
form = FormIO.readForm(tplPath); |
|
||||||
} catch (Exception e) { |
|
||||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
||||||
} |
|
||||||
return form; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,45 @@ |
|||||||
|
//SubSection函数-Oracle查询参数个数限制
|
||||||
|
package com.fr.function; |
||||||
|
|
||||||
|
import com.fr.general.FArray; |
||||||
|
import com.fr.script.AbstractFunction; |
||||||
|
|
||||||
|
public class SubSection extends AbstractFunction { |
||||||
|
public Object run(Object[] args) { |
||||||
|
// 获取第一个对象,即取得传入的参数
|
||||||
|
Object para = args[0]; |
||||||
|
String parastr = para.toString(); |
||||||
|
// 由于是复选参数,因此要去掉前后的"("和")"
|
||||||
|
if (parastr.startsWith("(") && parastr.endsWith(")")) { |
||||||
|
parastr = parastr.substring(1, parastr.length() - 1); |
||||||
|
} |
||||||
|
// 将字符串转为","分割的数组
|
||||||
|
String test[] = parastr.split(","); |
||||||
|
int len = test.length; |
||||||
|
int loopnum = len / 500; |
||||||
|
if (len % 500 != 0) { |
||||||
|
loopnum += 1; |
||||||
|
} |
||||||
|
; |
||||||
|
// 返回的值是数组,需要定义成我们内部的类型FArray
|
||||||
|
FArray result = new FArray(); |
||||||
|
String str = ""; |
||||||
|
int k = 1; |
||||||
|
for (int i = 0; i < loopnum; i++) { |
||||||
|
for (int j = 500 * i; j < 500 * (i + 1) && j < len; j++) { |
||||||
|
if (k != 500 && j != (len - 1)) { |
||||||
|
str += test[j] + ","; |
||||||
|
} else { |
||||||
|
str += test[j]; |
||||||
|
} |
||||||
|
k++; |
||||||
|
} |
||||||
|
// 每500个形成一组并在每组外部加上"("和")"
|
||||||
|
str = "(" + str + ")"; |
||||||
|
result.add(str); |
||||||
|
str = ""; |
||||||
|
k = 1; |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -1,126 +0,0 @@ |
|||||||
//
|
|
||||||
// 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; |
|
||||||
} |
|
||||||
} |
|
Binary file not shown.
@ -0,0 +1,105 @@ |
|||||||
|
// 导出打印单选按钮及复选框
|
||||||
|
package com.fr.function; |
||||||
|
|
||||||
|
import com.fr.base.AbstractPainter; |
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.base.GraphHelper; |
||||||
|
import com.fr.base.Style; |
||||||
|
import com.fr.general.FArray; |
||||||
|
import com.fr.general.FRFont; |
||||||
|
import com.fr.script.AbstractFunction; |
||||||
|
import com.fr.stable.Primitive; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.FontMetrics; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.Image; |
||||||
|
|
||||||
|
public class Widget2Image extends AbstractFunction { |
||||||
|
public Object run(Object[] args) { |
||||||
|
if (args.length < 3) |
||||||
|
return Primitive.NULL; |
||||||
|
// 第一个参数:控件类型,不区分大小写
|
||||||
|
String type = args[0].toString().toLowerCase(); |
||||||
|
if (!("checkbox".equals(type) || "radiobutton".equals(type))) |
||||||
|
return Primitive.ERROR_VALUE; |
||||||
|
// 第二个参数:控件按钮个数
|
||||||
|
int num = Integer.parseInt(args[1].toString()); |
||||||
|
// 第三个参数:按钮组的值,哪些被选中
|
||||||
|
String selection = args[2].toString(); |
||||||
|
// 第四个参数:可选参数,按钮组对应的显示值数组
|
||||||
|
FArray textArray = new FArray(); |
||||||
|
if (args.length == 4 && args[3] instanceof FArray) { |
||||||
|
textArray = (FArray) args[3]; |
||||||
|
} |
||||||
|
return new WidgetPaint(type, num, selection, textArray); |
||||||
|
} |
||||||
|
|
||||||
|
public static class WidgetPaint extends AbstractPainter { |
||||||
|
public static String CHECK_ON = "/com/fr/web/images/checkon.gif"; |
||||||
|
public static String CHECK_OFF = "/com/fr/web/images/checkoff.gif"; |
||||||
|
public static String RADIO_ON = "/com/fr/web/images/radioon.gif"; |
||||||
|
public static String RADIO_OFF = "/com/fr/web/images/radiooff.gif"; |
||||||
|
public static FRFont DEFUALT_FONT = FRFont.getInstance(); |
||||||
|
public static FontMetrics FontMetrics = GraphHelper |
||||||
|
.getFontMetrics(DEFUALT_FONT); |
||||||
|
private String type; |
||||||
|
private int num; |
||||||
|
private String selection; |
||||||
|
private FArray textArray; |
||||||
|
|
||||||
|
{ |
||||||
|
DEFUALT_FONT = DEFUALT_FONT.applyForeground(Color.BLACK); |
||||||
|
} |
||||||
|
|
||||||
|
public WidgetPaint(String type, int num, String selection, |
||||||
|
FArray textArray) { |
||||||
|
this.type = type; |
||||||
|
this.num = num; |
||||||
|
this.selection = selection; |
||||||
|
this.textArray = textArray; |
||||||
|
} |
||||||
|
|
||||||
|
private String resolveText(int i) { |
||||||
|
if (i < this.textArray.length()) { |
||||||
|
return this.textArray.elementAt(i).toString(); |
||||||
|
} |
||||||
|
return StringUtils.EMPTY; |
||||||
|
} |
||||||
|
|
||||||
|
public void paint(Graphics g, int width, int height, int resolution, |
||||||
|
Style style) { |
||||||
|
String OFF = CHECK_OFF; |
||||||
|
String ON = CHECK_ON; |
||||||
|
if ("radiobutton".equals(type)) { |
||||||
|
OFF = RADIO_OFF; |
||||||
|
ON = RADIO_ON; |
||||||
|
} |
||||||
|
Image[] checkOFFON = {BaseUtils.readImage(OFF), |
||||||
|
BaseUtils.readImage(ON)}; |
||||||
|
int[] imgWidths = {checkOFFON[0].getWidth(null), |
||||||
|
checkOFFON[1].getWidth(null)}; |
||||||
|
int[] imgHeights = {checkOFFON[0].getHeight(null), |
||||||
|
checkOFFON[1].getHeight(null)}; |
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
g2d.setFont(FRFont.getInstance()); |
||||||
|
g2d.setPaint(Color.BLACK); |
||||||
|
int x = 2; |
||||||
|
int y = (height - imgHeights[0]) / 2; |
||||||
|
String select = selection; |
||||||
|
for (int i = 0; i < num; i++) { |
||||||
|
int bit = Integer.parseInt(select.substring(i, i + 1)); |
||||||
|
g2d.drawImage(checkOFFON[bit], x, y, imgWidths[bit], |
||||||
|
imgHeights[bit], null); |
||||||
|
x += imgWidths[bit] + 2; |
||||||
|
String text = resolveText(i); |
||||||
|
g2d.setBackground(Color.BLACK); |
||||||
|
g2d.drawString(text, (float) x, (float) (y + FontMetrics |
||||||
|
.getAscent())); |
||||||
|
x += FontMetrics.stringWidth(text) + 2; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,77 @@ |
|||||||
|
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 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(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,77 @@ |
|||||||
|
package com.fr.test; |
||||||
|
|
||||||
|
import com.fr.base.FRContext; |
||||||
|
import com.fr.base.Formula; |
||||||
|
import com.fr.general.FArray; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.script.AbstractFunction; |
||||||
|
import com.fr.script.Calculator; |
||||||
|
import com.fr.stable.Primitive; |
||||||
|
|
||||||
|
public class gauthority extends AbstractFunction { |
||||||
|
public gauthority() { |
||||||
|
} |
||||||
|
|
||||||
|
public Object run(Object[] args) { |
||||||
|
int[] newArgs = new int[args.length]; |
||||||
|
|
||||||
|
for (int i = 0; i < args.length; ++i) { |
||||||
|
if (!(args[i] instanceof Integer) || (Integer) args[i] <= 0) { |
||||||
|
return Primitive.ERROR_NAME; |
||||||
|
} |
||||||
|
|
||||||
|
newArgs[i] = (Integer) args[i]; |
||||||
|
} |
||||||
|
|
||||||
|
FArray res = new FArray(); |
||||||
|
Calculator ca = this.getCalculator(); |
||||||
|
Formula f = new Formula("$fr_userposition"); |
||||||
|
|
||||||
|
try { |
||||||
|
Object dp = ca.eval(f); |
||||||
|
if (dp instanceof FArray) { |
||||||
|
FArray fa = (FArray) dp; |
||||||
|
|
||||||
|
for (int i = 0; i < fa.length(); ++i) { |
||||||
|
JSONObject jo = (JSONObject) fa.elementAt(i); |
||||||
|
String dName = jo.getString("jobTitle"); |
||||||
|
if (newArgs.length == 0) { |
||||||
|
res.add(dName); |
||||||
|
} else { |
||||||
|
String[] dNames = dName.split(","); |
||||||
|
res.add(this.buildRes(dNames, newArgs)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (Exception var12) { |
||||||
|
FRContext.getLogger().error(var12.getMessage(), var12); |
||||||
|
} |
||||||
|
|
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
private String buildRes(String[] dNames, int[] args) { |
||||||
|
StringBuffer sb = new StringBuffer(); |
||||||
|
|
||||||
|
for (int i = 0; i < args.length; ++i) { |
||||||
|
int index = args[i]; |
||||||
|
if (dNames.length >= index) { |
||||||
|
sb.append(dNames[index - 1]).append(","); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return sb.substring(0, sb.length() > 0 ? sb.length() - 1 : 0); |
||||||
|
} |
||||||
|
|
||||||
|
public Type getType() { |
||||||
|
return OTHER; |
||||||
|
} |
||||||
|
|
||||||
|
public String getCN() { |
||||||
|
return "GETUSERDEPARTMENTS():返回角色部门\n示例:\nGETUSERDEPARTMENTS():返回角色所有部门,若多个部门则数组\nGETUSERDEPARTMENTS(3,2):返回角色该部门的第三层和第二层名字,\n若多个部门则返回数组,若没有第三层则只显示第二层"; |
||||||
|
} |
||||||
|
|
||||||
|
public String getEN() { |
||||||
|
return ""; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue