diff --git a/JSD-9274-需求确认书V1.docx b/JSD-9274-需求确认书V1.docx new file mode 100644 index 0000000..64cc300 Binary files /dev/null and b/JSD-9274-需求确认书V1.docx differ diff --git a/README.md b/README.md index 2e7e2f4..362ad62 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # open-JSD-9274 -JSD-9274 数据集扩展 \ No newline at end of file +JSD-9274 数据集扩展\ +免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ +仅作为开发者学习参考使用!禁止用于任何商业用途!\ +为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 \ No newline at end of file diff --git a/lib/finekit-10.0.jar b/lib/finekit-10.0.jar new file mode 100644 index 0000000..611c8f5 Binary files /dev/null and b/lib/finekit-10.0.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..1bb3833 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,21 @@ + + + com.fr.plugin.third.party.jsdjche + + yes + 0.2 + 10.0 + 2019-01-01 + fr.open + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/third/party/jsdjche/Utils.java b/src/main/java/com/fr/plugin/third/party/jsdjche/Utils.java new file mode 100644 index 0000000..82a95bf --- /dev/null +++ b/src/main/java/com/fr/plugin/third/party/jsdjche/Utils.java @@ -0,0 +1,188 @@ +package com.fr.plugin.third.party.jsdjche; + +import com.fanruan.api.log.LogKit; +import com.fanruan.api.util.StringKit; +import com.fr.third.org.apache.http.HttpEntity; +import com.fr.third.org.apache.http.HttpStatus; +import com.fr.third.org.apache.http.client.config.RequestConfig; +import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse; +import com.fr.third.org.apache.http.client.methods.HttpGet; +import com.fr.third.org.apache.http.client.methods.HttpPost; +import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier; +import com.fr.third.org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import com.fr.third.org.apache.http.entity.StringEntity; +import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; +import com.fr.third.org.apache.http.impl.client.HttpClients; +import com.fr.third.org.apache.http.ssl.SSLContextBuilder; +import com.fr.third.org.apache.http.ssl.TrustStrategy; +import com.fr.third.org.apache.http.util.EntityUtils; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.UUID; + +public class Utils { + public static String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"; + public static RequestConfig REQUEST_CONFIG = RequestConfig.custom() + .setConnectionRequestTimeout(30000) + .setSocketTimeout(30000) // 服务端相应超时 + .setConnectTimeout(30000) // 建立socket链接超时时间 + .build(); + + public static CloseableHttpClient createSSLClientDefault() { + try { + SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { + + @Override + public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { + return true; + } + }).build(); + HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE; + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); + return HttpClients.custom().setSSLSocketFactory(sslsf).build(); + } catch (Exception e) { + LogKit.error(e.getMessage(), e); + } + return HttpClients.createDefault(); + } + + public static synchronized CloseableHttpClient createHttpClient(String url) { + CloseableHttpClient httpClient = null; + if (StringKit.isEmpty(url)) { + httpClient = HttpClients.createDefault(); + return httpClient; + } + + if (url.startsWith("https://")) { + httpClient = createSSLClientDefault(); + return httpClient; + } + httpClient = HttpClients.createDefault(); + return httpClient; + } + + public static synchronized String createHttpGetContent(CloseableHttpClient httpClient, String url, String basicAuth) throws IOException { + if ((httpClient == null) || (StringKit.isEmpty(url))) { + return ""; + } + + HttpGet httpGet = new HttpGet(url); + httpGet.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT); + if (StringKit.isNotEmpty(basicAuth)) { + httpGet.addHeader("Authorization", basicAuth); + } + + httpGet.setConfig(Utils.REQUEST_CONFIG); + CloseableHttpResponse response = httpClient.execute(httpGet); + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode != HttpStatus.SC_OK) { + response.close(); + LogKit.info("http请求出错,http status:" + statusCode); + return ""; + } + + HttpEntity httpEntity = response.getEntity(); + if (httpEntity == null) { + response.close(); + LogKit.info("http请求出错,http响应内容为空"); + return ""; + } + String responseContent = EntityUtils.toString(httpEntity, "UTF-8"); + response.close(); + if (StringKit.isEmpty(responseContent)) { + LogKit.info("http请求出错,http响应内容为空1"); + return ""; + } + return responseContent; + } + + public static synchronized String createHttpPostContent(CloseableHttpClient httpClient, String url, String bodyContent, String basicAuth,String contentType) throws IOException { + if ((httpClient == null) || (StringKit.isEmpty(url))) { + return ""; + } + + HttpPost httpPost = new HttpPost(url); + httpPost.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT); + httpPost.setConfig(Utils.REQUEST_CONFIG); + if (StringKit.isNotEmpty(basicAuth)) { + httpPost.addHeader("Authorization", basicAuth); + } + if (StringKit.isNotEmpty(contentType)) { + httpPost.addHeader("Content-Type", contentType); + } + StringEntity bodyEntity = new StringEntity(bodyContent, "UTF-8"); + httpPost.setEntity(bodyEntity); + CloseableHttpResponse response = httpClient.execute(httpPost); + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode != HttpStatus.SC_OK) { + response.close(); + LogKit.info("http请求出错,http status:" + statusCode); + return ""; + } + + HttpEntity httpEntity = response.getEntity(); + if (httpEntity == null) { + response.close(); + LogKit.info("http请求出错,http响应内容为空"); + return ""; + } + String responseContent = EntityUtils.toString(httpEntity, "UTF-8"); + response.close(); + if (StringKit.isEmpty(responseContent)) { + LogKit.info("http请求出错,http响应内容为空1"); + return ""; + } + return responseContent; + } + + + /** + * 获取完整请求链接 + * + * @param req 请求 + * @return + */ + public static String getFullRequestUrl(HttpServletRequest req) { + if (req == null) { + return ""; + } + String url = req.getRequestURL().toString(); + String queryUrl = req.getQueryString(); + if ((queryUrl == null) || "null".equalsIgnoreCase(queryUrl)) { + queryUrl = ""; + } else { + queryUrl = "?" + queryUrl; + } + String fullUrl = url + queryUrl; + return fullUrl; + } + + + /** + * 重定向 + * + * @param res + * @param url + */ + public static void sendRedirect(HttpServletResponse res, String url) { + if ((res == null) || (StringKit.isEmpty(url))) { + return; + } + res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); + res.setHeader("Location", url); + } + + + public static synchronized String getUuid() { + String uuid = UUID.randomUUID().toString().replace("-", ""); + return uuid; + } + + +} diff --git a/src/main/java/com/fr/plugin/third/party/jsdjche/config/CustomDataConfig.java b/src/main/java/com/fr/plugin/third/party/jsdjche/config/CustomDataConfig.java new file mode 100644 index 0000000..377a5ca --- /dev/null +++ b/src/main/java/com/fr/plugin/third/party/jsdjche/config/CustomDataConfig.java @@ -0,0 +1,68 @@ +package com.fr.plugin.third.party.jsdjche.config; + +import com.fr.config.*; +import com.fr.config.holder.Conf; +import com.fr.config.holder.factory.Holders; + +import java.util.concurrent.ConcurrentHashMap; + +/** + * 配置数据保存 + */ +@Visualization(category = "自定义数据集配置") +public class CustomDataConfig extends DefaultConfiguration { + public String getNameSpace() { + return this.getClass().getName(); + } + + private static volatile CustomDataConfig config = null; + + public static CustomDataConfig getInstance() { + if (config == null) { + config = ConfigContext.getConfigInstance(CustomDataConfig.class); + } + return config; + } + + @Identifier(value = "dataSyncUrl", name = "数据地址", description = "", status = Status.SHOW) + private Conf dataSyncUrl = Holders.simple("http://10.12.8.130/ssss/rest/windFarmBi/provideData"); + + @Identifier(value = "dataUsername", name = "数据用户名", description = "", status = Status.SHOW) + private Conf dataUsername = Holders.simple("xxxx"); + + @Identifier(value = "dataPassword", name = "数据密码", description = "", status = Status.SHOW) + private Conf dataPassword = Holders.simple("zzzz"); + + public String getDataSyncUrl() { + return dataSyncUrl.get(); + } + + public void setDataSyncUrl(String dataSyncUrl) { + this.dataSyncUrl.set(dataSyncUrl); + } + + public String getDataUsername() { + return dataUsername.get(); + } + + public void setDataUsername(String dataUsername) { + this.dataUsername.set(dataUsername); + } + + public String getDataPassword() { + return dataPassword.get(); + } + + public void setDataPassword(String dataPassword) { + this.dataPassword.set(dataPassword); + } + + @Override + public Object clone() throws CloneNotSupportedException { + CustomDataConfig cloned = (CustomDataConfig) super.clone(); + cloned.dataSyncUrl = (Conf) dataSyncUrl.clone(); + cloned.dataUsername = (Conf) dataUsername.clone(); + cloned.dataPassword = (Conf) dataPassword.clone(); + return cloned; + } +} diff --git a/src/main/java/com/fr/plugin/third/party/jsdjche/config/DataConfigInitializeMonitor.java b/src/main/java/com/fr/plugin/third/party/jsdjche/config/DataConfigInitializeMonitor.java new file mode 100644 index 0000000..861db1d --- /dev/null +++ b/src/main/java/com/fr/plugin/third/party/jsdjche/config/DataConfigInitializeMonitor.java @@ -0,0 +1,26 @@ +package com.fr.plugin.third.party.jsdjche.config; + +import com.fr.intelli.record.Focus; +import com.fr.intelli.record.Original; +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; +import com.fr.record.analyzer.EnableMetrics; +import com.fr.stable.fun.Authorize; + +/** + * 配置信息初始化 + */ +@EnableMetrics +@Authorize(callSignKey = "com.fr.plugin.third.party.jsdjche") +public class DataConfigInitializeMonitor extends AbstractPluginLifecycleMonitor { + @Override + @Focus(id = "com.fr.plugin.third.party.jsdjche", text = "plugin-jsdjche", source = Original.PLUGIN) + public void afterRun(PluginContext pluginContext) { + CustomDataConfig.getInstance(); + } + + @Override + public void beforeStop(PluginContext pluginContext) { + + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpDataModel.java b/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpDataModel.java new file mode 100644 index 0000000..56c1c0f --- /dev/null +++ b/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpDataModel.java @@ -0,0 +1,161 @@ +package com.fr.plugin.third.party.jsdjche.data; + +import com.fanruan.api.log.LogKit; +import com.fanruan.api.util.StringKit; +import com.fr.base.TableData; +import com.fr.data.AbstractDataModel; +import com.fr.general.data.TableDataException; +import com.fr.json.JSONArray; +import com.fr.json.JSONObject; +import com.fr.plugin.context.PluginContexts; +import com.fr.plugin.third.party.jsdjche.Utils; +import com.fr.plugin.third.party.jsdjche.config.CustomDataConfig; +import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; +import com.fr.utils.Base64; + +import java.util.ArrayList; +import java.util.List; + +public class CustomHttpDataModel extends AbstractDataModel { + private static String[] COLUMN_NAMES = {"projectscadacode", "projectname", "servicestarttime", "serviceendtime"}; + private int rowCount = TableData.RESULT_ALL; + private DatasetData datas = new DatasetData(); + + public CustomHttpDataModel(int count) { + this.rowCount = count; + if (this.rowCount == 0) { + return; + } + queryData(); + } + + @Override + public int getColumnCount() throws TableDataException { + return COLUMN_NAMES.length; + } + + @Override + public String getColumnName(int i) throws TableDataException { + return COLUMN_NAMES[i]; + } + + @Override + public boolean hasRow(int rowIndex) throws TableDataException { + int count = getRowCount(); + return rowIndex < count; + } + + @Override + public int getRowCount() throws TableDataException { + if (this.datas == null) { + return 0; + } + List> values = this.datas.getValues(); + if (values == null) { + return 0; + } + int count = values.size(); + return count; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) throws TableDataException { + if (this.datas == null) { + return ""; + } + List> values = this.datas.getValues(); + if ((values == null) || (values.size() <= rowIndex)) { + return ""; + } + List rowValues = values.get(rowIndex); + if ((rowValues == null) || (rowValues.size() <= columnIndex)) { + return ""; + } + return rowValues.get(columnIndex); + } + + @Override + public void release() throws Exception { + this.datas = null; + } + + /** + * 查询数据 + */ + private void queryData() { + try { + createDatas(); + } catch (Exception e) { + LogKit.error("自定义数据集获取信息,请求出错," + e.getMessage() + "," + e.getCause(), e); + } + } + + private void createDatas() throws Exception { + String userSyncUrl = CustomDataConfig.getInstance().getDataSyncUrl(); + String userSyncUsername = CustomDataConfig.getInstance().getDataUsername(); + String userSyncPassword = CustomDataConfig.getInstance().getDataPassword(); + if (StringKit.isEmpty(userSyncUrl) || StringKit.isEmpty(userSyncUsername) || StringKit.isEmpty(userSyncPassword)) { + return; + } + + CloseableHttpClient httpClient = Utils.createHttpClient(userSyncUrl); + String authValue = userSyncUsername + ":" + userSyncPassword; + String auth = "Basic " + Base64.getEncoder().encodeToString(authValue.getBytes("utf-8")); + String content = ""; + LogKit.info("自定义数据集,请求数据.."); + + //添加认证 + if (!PluginContexts.currentContext().isAvailable()) { + LogKit.error("自定义数据集插件试用过期, 请购买许可证"); + return; + } + content = Utils.createHttpPostContent(httpClient, userSyncUrl,"{}", auth,"application/json"); + httpClient.close(); + if (StringKit.isEmpty(content)) { + return; + } + LogKit.info("自定义数据集,json内容:\n" + content); + addDatas(content); + } + + private void addDatas(String content) throws TableDataException { + if (StringKit.isEmpty(content)) { + return; + } + JSONObject resJson = new JSONObject(content); + int code = resJson.getInt("code"); + if (code != 1) { + return; + } + + JSONArray dataJsons = resJson.getJSONArray("data"); + if ((dataJsons == null) || (dataJsons.size() <= 0)) { + return; + } + String projectScadaCode = "", projectName = "", serviceStartTime = "", serviceEndTime = ""; + JSONObject dataJson; + int tempCount = 0; + for (int i = 0, max = dataJsons.size() - 1; i <= max; i++) { + if ((this.rowCount >= 1) && (tempCount >= this.rowCount)) { + return; + } + dataJson = dataJsons.getJSONObject(i); + projectScadaCode = dataJson.getString("projectScadaCode", ""); + projectName = dataJson.getString("projectName", ""); + serviceStartTime = dataJson.getString("serviceStartTime", ""); + serviceEndTime = dataJson.getString("serviceEndTime", ""); + addRowDatas(projectScadaCode, projectName, serviceStartTime, serviceEndTime); + tempCount++; + } + } + + private void addRowDatas(String projectScadaCode, String projectName, String serviceStartTime, String serviceEndTime) { + List rowDatas = new ArrayList<>(); + rowDatas.add(projectScadaCode); + rowDatas.add(projectName); + rowDatas.add(serviceStartTime); + rowDatas.add(serviceEndTime); + List> values = this.datas.getValues(); + values.add(rowDatas); + } +} diff --git a/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpTableData.java b/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpTableData.java new file mode 100644 index 0000000..c97e398 --- /dev/null +++ b/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpTableData.java @@ -0,0 +1,18 @@ +package com.fr.plugin.third.party.jsdjche.data; + +import com.fr.base.TableData; +import com.fr.data.AbstractParameterTableData; +import com.fr.general.data.DataModel; +import com.fr.script.Calculator; + +public class CustomHttpTableData extends AbstractParameterTableData { + @Override + public DataModel createDataModel(Calculator calculator) { + return createDataModel(calculator, TableData.RESULT_ALL); + } + + @Override + public DataModel createDataModel(Calculator calculator, int rowCount) { + return new CustomHttpDataModel(rowCount); + } +} diff --git a/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpTableDataDefine.java b/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpTableDataDefine.java new file mode 100644 index 0000000..92e4dcd --- /dev/null +++ b/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpTableDataDefine.java @@ -0,0 +1,50 @@ +package com.fr.plugin.third.party.jsdjche.data; + + +import com.fr.base.TableData; +import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; +import com.fr.design.fun.ServerTableDataDefineProvider; +import com.fr.design.fun.impl.AbstractTableDataDefineProvider; +import com.fr.design.i18n.Toolkit; + + +public class CustomHttpTableDataDefine extends AbstractTableDataDefineProvider implements ServerTableDataDefineProvider { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public Class classForTableData() { + return CustomHttpTableData.class; + } + + @Override + public Class classForInitTableData() { + return CustomHttpTableData.class; + } + + @Override + public Class appearanceForTableData() { + + return CustomHttpTableDataPane.class; + } + + @Override + public String nameForTableData() { + return Toolkit.i18nText("自定义数据集"); + } + + @Override + public String prefixForTableData() { + return "custom_data"; + } + + @Override + public String iconPathForTableData() { + return ""; + } + + +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpTableDataPane.java b/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpTableDataPane.java new file mode 100644 index 0000000..4ee3d63 --- /dev/null +++ b/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomHttpTableDataPane.java @@ -0,0 +1,76 @@ +package com.fr.plugin.third.party.jsdjche.data; + +import com.fanruan.api.design.DesignKit; +import com.fanruan.api.design.ui.component.UIButton; +import com.fr.design.data.datapane.preview.PreviewTablePane; +import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; +import com.fr.general.IOUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + + +public class CustomHttpTableDataPane extends AbstractTableDataPane { + public CustomHttpTableDataPane() { + super(); + createContent(); + } + + + + @Override + public void populateBean(CustomHttpTableData ob) { + if (ob == null) { + return; + } + + } + + @Override + public CustomHttpTableData updateBean() { + CustomHttpTableData tableData = new CustomHttpTableData(); + return tableData; + } + + @Override + protected String title4PopupWindow() { + return DesignKit.i18nText("ESB用户数据集"); + } + + + private void createContent() { + setLayout(new BorderLayout()); + JPanel contentPane = new JPanel(); + contentPane.setLayout(new BorderLayout()); + add(contentPane, BorderLayout.CENTER); + + + JPanel connectionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5)); + + UIButton previewButton = createIconButton("Fine-Design_Basic_Preview", "/com/fr/design/images/m_file/preview.png"); + previewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + PreviewTablePane.previewTableData(updateBean()); + } + }); + connectionPanel.add(previewButton); + contentPane.add(connectionPanel, BorderLayout.NORTH); + + } + + /** + * 获取图标按钮 + * + * @param toolTip 提示信息,国际化key + * @param iconPath 图标路径 + * @return + */ + public static UIButton createIconButton(String toolTip, String iconPath) { + UIButton iconButton = new UIButton(IOUtils.readIcon(iconPath)); + iconButton.setToolTipText(DesignKit.i18nText(toolTip)); + return iconButton; + } + +} diff --git a/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomUniversalServerTableDataProvider.java b/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomUniversalServerTableDataProvider.java new file mode 100644 index 0000000..883114b --- /dev/null +++ b/src/main/java/com/fr/plugin/third/party/jsdjche/data/CustomUniversalServerTableDataProvider.java @@ -0,0 +1,44 @@ +package com.fr.plugin.third.party.jsdjche.data; + +import com.fr.decision.fun.impl.AbstractUniversalServerTableDataProvider; +import com.fr.json.JSONObject; +import com.fr.web.struct.Atom; +import com.fr.web.struct.Component; +import com.fr.web.struct.browser.RequestClient; +import com.fr.web.struct.category.ParserType; +import com.fr.web.struct.category.ScriptPath; + +public class CustomUniversalServerTableDataProvider extends AbstractUniversalServerTableDataProvider { + @Override + public Class classForTableData() { + return CustomHttpTableData.class; + } + + @Override + public String nameForTableData() { + return "custom_data"; + } + + @Override + public JSONObject serialize(CustomHttpTableData data) { + //bean.setParameters(parameterBeans); + //return JSONObject.mapFrom(bean); + return new JSONObject(); + } + + @Override + public CustomHttpTableData deserialize(CustomHttpTableData data, JSONObject config ) { + CustomHttpTableData dataSet = new CustomHttpTableData(); + return dataSet; + } + + @Override + public Atom client() { + return new Component(){ + @Override + public ScriptPath script(RequestClient client ) { + return ScriptPath.build("com/fr/plugin/third/party/jsdjche/web/tabledata.js", ParserType.DYNAMIC); + } + }; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/third/party/jsdjche/data/DatasetData.java b/src/main/java/com/fr/plugin/third/party/jsdjche/data/DatasetData.java new file mode 100644 index 0000000..45002b3 --- /dev/null +++ b/src/main/java/com/fr/plugin/third/party/jsdjche/data/DatasetData.java @@ -0,0 +1,67 @@ +package com.fr.plugin.third.party.jsdjche.data; + +import java.util.ArrayList; +import java.util.List; + +/** + * 数据集数据 + */ +public class DatasetData { + private String name; + private List columns; + private List> values; + + public DatasetData() { + columns = new ArrayList(); + values = new ArrayList>(); + } + + /** + * 获取表名 + * @return 表名 + */ + public String getName() { + return this.name; + } + + /** + * 设置表名 + * @param name 表名 + */ + public void setName(String name) { + this.name = name; + } + + /** + * 获取列名 + * @return 列名 + */ + public List getColumns() { + return this.columns; + } + + /** + * 设置列名 + * @param columns 列名 + */ + public void setColumns(List columns) { + this.columns = columns; + } + + /** + * 获取表数据 + * @return 表数据 + */ + public List> getValues() { + return this.values; + } + + /** + * 设置表数据 + * @param values + */ + public void setValues(List> values) { + this.values = values; + } + +} diff --git a/src/main/resources/com/fr/plugin/third/party/jsdjche/web/tabledata.js b/src/main/resources/com/fr/plugin/third/party/jsdjche/web/tabledata.js new file mode 100644 index 0000000..6922f3d --- /dev/null +++ b/src/main/resources/com/fr/plugin/third/party/jsdjche/web/tabledata.js @@ -0,0 +1,292 @@ +!(function () { + var Model = BI.inherit(Fix.Model, { + _init: function () { + this.service = BI.Services.getService("dec.service.data.set"); + }, + context: ["dataSetName", "ableSave"], + state: function () { + var val = this.options.value.datasetData || {}; + return { + config: val.config || "", + parameters: val.parameters || [] + }; + }, + childContext: ["previewAble", "previewedDataSet"], + watch: { + previewAble: function (v) { + this.setAbleSave(v); + } + }, + computed: { + paramHeader: function () { + //定义参数列表表头 + var map = BI.map(BI.Constants.getConstant("dec.constants.data.set.sql.header"), function (i, v) { + return BI.extend({ + textAlign: "left", + height: 30, + hgap: 10 + }, v); + }); + map.push({ + textAlign: "left", + height: 30, + hgap: 10, + text: "" + }); + return [map]; + }, + paramItems: function () { + var self = this; + return BI.map(this.model.parameters, function (i, param) { + return [{ + type: "bi.text_editor", + value: param.name, + textAlign: "left", + height: 30, + lgap: 10, + listeners: [{ + eventName: BI.TextEditor.EVENT_CHANGE, + action: function () { + self.setParamName(i, this.getValue()); + } + }] + }, { + type: "bi.icon_text_value_combo", + cls: "field-type-change", + height: 30, + items: BI.Constants.getConstant("dec.constants.data.set.sql.field"), + value: param.type, + listeners: [{ + eventName: BI.IconTextValueCombo.EVENT_CHANGE, + action: function () { + self.setParamType(i, this.getValue()[0]); + } + }] + }, self.service.createParameterValueItem(param, function (val) { + self.setParamValue(i, val); + }), { + type: "bi.icon_button", + cls: "default-delete-font", + height: 30, + lgap: 10, + title: BI.i18nText("Dec-Basic_Delete"), + handler: function () { + self.deleteParameter(i); + } + }]; + }); + }, + previewAble: function () { + return true; + }, + previewedDataSet: function () { + return { + datasetType: DecCst.DataSet.Type.CUSTOM_DATA, + datasetName: this.model.dataSetName, + datasetData: { + parameters:[] + } + }; + } + }, + actions: { + initPage: function (cb) { + var self = this; + cb(); + }, + setConfig: function (v) { + this.model.config = v; + }, + refreshParam: function () { + var self = this; + Dec.Utils.getDataSetParameters(this.model.previewedDataSet, function (res) { + self.model.parameters = self.service.getParameters(res.data, self.model.parameters); + }); + }, + addParamter: function (v) { + this.model.parameters.push(v); + }, + deleteParameter: function (index) { + this.model.parameters.splice(index, 1); + }, + setParamName: function (index, name) { + this.model.parameters[index].name = name; + }, + setParamType: function (index, type) { + if (this.model.parameters[index].type !== type) { + this.model.parameters[index].type = type; + this.model.parameters[index].value = this.service.getDefaultValueByType(type); + this.model.parameters.splice(0, 0); + } + }, + setParamValue: function (index, val) { + this.model.parameters[index].value = val; + }, + setAbleSave: function (v) { + this.model.ableSave = v; + } + } + }); + BI.model("dec.model.data.set.type.demo.data", Model); + + + var DemoData = BI.inherit(BI.Widget, { + props: { + baseCls: "dec-data-set-sql", + $testId: "dec-data-set-sql", + value: { + datasetData: {} + } + }, + _store: function () { + return BI.Models.getModel("dec.model.data.set.type.demo.data", this.options); + }, + watch: { + config: function (v) { + this.configEditor.setValue(v); + }, + "config || parameters.**": function () { + this.previewPane.resetPreview(); + }, + parameters: function () { + this.paramSettingPane.populate(this.model.paramItems, this.model.paramHeader); + } + }, + beforeInit: function (cb) { + this.store.initPage(cb); + }, + mounted: function () { + // 在render方法里的子组件被渲染到页面之后的钩子函数 + this.previewPane.resetPreview(); + this.store.setAbleSave(true); + }, + render: function () { + var self = this; + return { + type: "bi.htape", + items: [ + //左侧的配置界面 + /*{ + el: { + type: "bi.vtape", + items: [ + { + height: 24, + type: "bi.label", + cls: "dec-font-weight-bold", + text: "Config", + title: "Config", + textAlign: "left", + }, + { + height: 220, + type: "bi.textarea_editor", + cls: "bi-border", + value: this.model.config, + ref: function (_ref) { + self.configEditor = _ref; + }, + listeners: [{ + eventName: BI.FormulaEditor.EVENT_CHANGE, + action: function () { + self.store.setConfig(this.getValue()); + } + }] + }, + //下面是参数面板 + { + type: "bi.left_right_vertical_adapt", + height: 24, + items: { + left: [{ + type: "bi.label", + cls: "dec-font-weight-bold", + text: BI.i18nText("Dec-Basic_Parameter_Setting") + }], + right: [{ + type: "bi.icon_button", + cls: "add-keyword-font", + level: "ignore", + lgap: 10, + handler: function () { + self.store.addParamter({ + type: "String", + name: "", + value: "" + }); + } + }, { + type: "bi.icon_button", + cls: "refresh-font", + lgap: 10, + level: "ignore", + handler: function () { + self.store.refreshParam(); + } + }] + } + }, { + type: "bi.components.style_table", + cls: "param-table", + width: 420, + columnSize: [130, 120, 120, ""], + items: this.model.paramItems, + header: this.model.paramHeader, + ref: function () { + self.paramSettingPane = this; + } + } + ], + lgap: 10, + vgap: 15 + }, + width: 410, + lgap: 10, + vgap: 15 + },*/ + //右侧的预览界面 + { + el: { + type: "bi.absolute", + cls: "bi-sortable-holder", + items: [{ + el: { + type: "dec.data.set.preview", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + //self.store.refreshParam(); + self.previewPane.previewData(); + } + }], + ref: function (_ref) { + self.previewPane = _ref; + } + }, top: 10, right: 10, bottom: 10, left: 10 + }] + }, + hgap: 10, + vgap: 15 + } + ] + }; + }, + getValue: function () { + return { + config: this.model.config, + parameters: this.model.parameters + }; + } + }); + BI.shortcut("dec.data.set.type.custom.data", DemoData); + + $.extend(DecCst.DataSet.Type, {CUSTOM_DATA: "custom_data"}); + BI.config("dec.provider.data.set", function (provider) { + provider.registerDataSetType({ + value: DecCst.DataSet.Type.CUSTOM_DATA, + text: "自定义数据集", + cardType: "dec.data.set.type.custom.data", + iconCls: "management-maintenance-cloud-font" + }); + }); +})(); \ No newline at end of file