LAPTOP-SB56SG4Q\86185
3 years ago
13 changed files with 386 additions and 1 deletions
@ -1,3 +1,6 @@ |
|||||||
# open-JSD-8693 |
# open-JSD-8693 |
||||||
|
|
||||||
JSD-8693 多CPT合并导出excel |
JSD-8693 多CPT合并导出excel\ |
||||||
|
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||||
|
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||||
|
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,29 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<plugin> |
||||||
|
<id>com.fr.plugin.hfic.excel</id> |
||||||
|
<name><![CDATA[cpt导出excel功能]]></name> |
||||||
|
<active>yes</active> |
||||||
|
<version>1.0</version> |
||||||
|
<env-version>10.0~10.0</env-version> |
||||||
|
<jartime>2018-07-31</jartime> |
||||||
|
<vendor>fr.open</vendor> |
||||||
|
<description><![CDATA[cpt导出excel功能]]></description> |
||||||
|
<change-notes><![CDATA[cpt导出excel功能]]></change-notes> |
||||||
|
<main-package>com.fr.plugin.hfic</main-package> |
||||||
|
<prefer-packages> |
||||||
|
<prefer-package>com.fanruan.api</prefer-package> |
||||||
|
</prefer-packages> |
||||||
|
<extra-core> |
||||||
|
<LocaleFinder class="com.fr.plugin.hfic.LocaleFinder"/> |
||||||
|
</extra-core> |
||||||
|
<extra-report> |
||||||
|
<JavaScriptFileHandler class="com.fr.plugin.hfic.web.JavaScriptFile"/> |
||||||
|
</extra-report> |
||||||
|
<extra-decision> |
||||||
|
<HttpHandlerProvider class="com.fr.plugin.hfic.service.RequestHandlerBridge"/> |
||||||
|
<URLAliasProvider class="com.fr.plugin.hfic.service.URLAliasBridge"/> |
||||||
|
</extra-decision> |
||||||
|
<function-recorder class="com.fr.plugin.hfic.LocaleFinder"/> |
||||||
|
<function-recorder class="com.fr.plugin.hfic.service.ReportDataHandler"/> |
||||||
|
<function-recorder class="com.fr.plugin.hfic.web.JavaScriptFile"/> |
||||||
|
</plugin> |
@ -0,0 +1,40 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2020 |
||||||
|
* Project: starter |
||||||
|
* FileName: LocaleFinder |
||||||
|
* Author: Louis |
||||||
|
* Date: 2020/8/31 22:19 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.hfic; |
||||||
|
|
||||||
|
import com.fr.intelli.record.Focus; |
||||||
|
import com.fr.intelli.record.Original; |
||||||
|
import com.fr.record.analyzer.EnableMetrics; |
||||||
|
import com.fr.stable.fun.Authorize; |
||||||
|
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||||
|
|
||||||
|
import static com.fr.plugin.hfic.LocaleFinder.PLUGIN_ID; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <LocaleFinder> |
||||||
|
* |
||||||
|
* @author fr.open |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
@EnableMetrics |
||||||
|
@Authorize(callSignKey = PLUGIN_ID) |
||||||
|
public class LocaleFinder extends AbstractLocaleFinder { |
||||||
|
public static final String PLUGIN_ID = "com.fr.plugin.hfic.excel"; |
||||||
|
|
||||||
|
@Override |
||||||
|
@Focus(id = PLUGIN_ID, text = "Plugin-hfic", source = Original.PLUGIN) |
||||||
|
public String find() { |
||||||
|
return "com/fr/plugin/hfic/locale/lang"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return CURRENT_LEVEL; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,170 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2015-2019 |
||||||
|
* FileName: ReportDataHandler |
||||||
|
* Author: Louis |
||||||
|
* Date: 2019/8/22 8:34 |
||||||
|
* Description: ReportDataHandler |
||||||
|
* History: |
||||||
|
* <author> <time> <version> <desc> |
||||||
|
*/ |
||||||
|
package com.fr.plugin.hfic.service; |
||||||
|
|
||||||
|
import com.fanruan.api.i18n.I18nKit; |
||||||
|
import com.fanruan.api.log.LogKit; |
||||||
|
import com.fr.base.Parameter; |
||||||
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||||
|
import com.fr.file.CacheManager; |
||||||
|
import com.fr.file.FileCommonUtils; |
||||||
|
import com.fr.general.IOUtils; |
||||||
|
import com.fr.intelli.record.Focus; |
||||||
|
import com.fr.intelli.record.Original; |
||||||
|
import com.fr.io.TemplateWorkBookIO; |
||||||
|
import com.fr.io.exporter.excel.stream.StreamExcel2007Exporter; |
||||||
|
import com.fr.io.utils.ResourceIOUtils; |
||||||
|
import com.fr.json.JSONArray; |
||||||
|
import com.fr.json.JSONException; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.main.impl.WorkBook; |
||||||
|
import com.fr.plugin.context.PluginContexts; |
||||||
|
import com.fr.record.analyzer.EnableMetrics; |
||||||
|
import com.fr.stable.ParameterProvider; |
||||||
|
import com.fr.stable.StableUtils; |
||||||
|
import com.fr.stable.WriteActor; |
||||||
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||||
|
import com.fr.web.Browser; |
||||||
|
import com.fr.web.core.SessionPoolManager; |
||||||
|
import com.fr.web.core.utils.ExportUtils; |
||||||
|
import com.fr.web.session.SessionIDInfo; |
||||||
|
import com.fr.web.utils.WebUtils; |
||||||
|
import org.apache.tools.zip.ZipOutputStream; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.File; |
||||||
|
import java.io.FileOutputStream; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import static com.fr.plugin.hfic.LocaleFinder.PLUGIN_ID; |
||||||
|
|
||||||
|
/** |
||||||
|
* 〈Function Description〉<br> |
||||||
|
* 〈ReportDataHandler〉 |
||||||
|
* |
||||||
|
* @author fr.open |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
@EnableMetrics |
||||||
|
public class ReportDataHandler extends BaseHttpHandler { |
||||||
|
public static final String REPORT_PATH = "reportPath"; |
||||||
|
public static final String SESSION_ID = "sessionId"; |
||||||
|
public static final String REPORT_NAME = "REPORTNAME"; |
||||||
|
public static final String API_EXPORT = "/api/export"; |
||||||
|
|
||||||
|
@Override |
||||||
|
public RequestMethod getMethod() { |
||||||
|
return RequestMethod.POST; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getPath() { |
||||||
|
return API_EXPORT; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isPublic() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
@Focus(id = PLUGIN_ID, text = "Plugin-hfic", source = Original.PLUGIN) |
||||||
|
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||||
|
if (!PluginContexts.currentContext().isAvailable()) { |
||||||
|
LogKit.error(I18nKit.getLocText("Plugin-hfic_Licence_Expired")); |
||||||
|
printErrorJSON(response); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
JSONArray reportData = new JSONArray(WebUtils.getHTTPRequestParameter(request, "data")); |
||||||
|
try { |
||||||
|
String fileName = "exportExcel"; |
||||||
|
Browser browser = Browser.resolve(request); |
||||||
|
ExportUtils.setZipContext(response, fileName, browser.shouldSetContentTypeOnZipDownload()); |
||||||
|
|
||||||
|
File file = new File(CacheManager.getProviderInstance().getCacheDirectory(), "excel-temp"); |
||||||
|
File file1 = new File(file, "TEMP_" + System.currentTimeMillis() + "_" + (int) (Math.random() * 1000.0D)); |
||||||
|
for (int i = 0; file1.exists(); ++i) { |
||||||
|
file1 = new File(file, "TEMP_" + System.currentTimeMillis() + "_" + (int) (Math.random() * 1000.0D) + i); |
||||||
|
} |
||||||
|
StableUtils.mkdirs(file1); |
||||||
|
file1.deleteOnExit(); |
||||||
|
ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream()); |
||||||
|
zipOutputStream.setEncoding("GBK"); |
||||||
|
|
||||||
|
JSONObject report; |
||||||
|
try { |
||||||
|
for (Object obj : reportData) { |
||||||
|
report = (JSONObject) obj; |
||||||
|
if (report.has(REPORT_PATH)) { |
||||||
|
this.export2temp(file1, report.getString(REPORT_PATH), getParameters(report.getJSONArray("parameters"))); |
||||||
|
} else if (report.has(SESSION_ID)) { |
||||||
|
this.export2temp(file1, report.getString(SESSION_ID)); |
||||||
|
} |
||||||
|
} |
||||||
|
IOUtils.zip(zipOutputStream, file1, (String) null); |
||||||
|
zipOutputStream.closeEntry(); |
||||||
|
zipOutputStream.close(); |
||||||
|
} finally { |
||||||
|
StableUtils.deleteFile(file1); |
||||||
|
} |
||||||
|
} catch (JSONException e) { |
||||||
|
LogKit.error(e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void export2temp(File zipDir, String sessionId) throws Exception { |
||||||
|
SessionIDInfo sessionIDInfo = SessionPoolManager.getSessionIDInfor(sessionId, SessionIDInfo.class); |
||||||
|
Map<String, Object> parameterMap = sessionIDInfo.getParameterMap(); |
||||||
|
String reportPath = parameterMap.get(REPORT_NAME).toString(); |
||||||
|
export2temp(zipDir, reportPath, parameterMap); |
||||||
|
} |
||||||
|
|
||||||
|
private void export2temp(File zipDir, String reportPath, Map<String, Object> parameterMap) throws Exception { |
||||||
|
WorkBook workbook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(reportPath); |
||||||
|
FileOutputStream outputStream = new FileOutputStream(FileCommonUtils.getAbsolutePath(zipDir) + File.separator + ResourceIOUtils.getName(reportPath).replace(".cpt", ".xlsx")); |
||||||
|
StreamExcel2007Exporter ExcelExport1 = new StreamExcel2007Exporter(); |
||||||
|
ExcelExport1.export(outputStream, workbook.execute(parameterMap, new WriteActor())); |
||||||
|
} |
||||||
|
|
||||||
|
private HashMap<String, Object> getParameters(JSONArray param) { |
||||||
|
if (param == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
ParameterProvider[] parameters = new ParameterProvider[param.size()]; |
||||||
|
for (int i = 0; i < param.size(); i++) { |
||||||
|
parameters[i] = Parameter.getParameterFromJson(param.getJSONObject(i)); |
||||||
|
} |
||||||
|
HashMap<String, Object> parametersMap = new HashMap<String, Object>(); |
||||||
|
addPara2Map(parametersMap, parameters); |
||||||
|
return parametersMap; |
||||||
|
} |
||||||
|
|
||||||
|
private void addPara2Map(Map<String, Object> parametersMap, ParameterProvider[] parameters) { |
||||||
|
if (parameters == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
for (ParameterProvider parameter : parameters) { |
||||||
|
if (parameter == null || parameter.getName() == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
parametersMap.put(parameter.getName().toUpperCase(), parameter.getValue()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void printErrorJSON(HttpServletResponse res) throws Exception { |
||||||
|
JSONObject errorJSON = JSONObject.create(); |
||||||
|
errorJSON.put("error_code", 1) |
||||||
|
.put("error_msg", I18nKit.getLocText("Plugin-hfic_Licence_Expired")); |
||||||
|
WebUtils.printAsJSON(res, errorJSON); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2015-2019 |
||||||
|
* FileName: RequestHandlerBridge |
||||||
|
* Author: Louis |
||||||
|
* Date: 2019/8/17 22:20 |
||||||
|
* Description: RequestHandlerBridge |
||||||
|
* History: |
||||||
|
* <author> <time> <version> <desc> |
||||||
|
*/ |
||||||
|
package com.fr.plugin.hfic.service; |
||||||
|
|
||||||
|
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||||
|
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||||
|
import com.fr.stable.fun.Authorize; |
||||||
|
|
||||||
|
import static com.fr.plugin.hfic.LocaleFinder.PLUGIN_ID; |
||||||
|
|
||||||
|
/** |
||||||
|
* 〈Function Description〉<br> |
||||||
|
* 〈RequestHandlerBridge〉 |
||||||
|
* |
||||||
|
* @author fr.open |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
@Authorize(callSignKey = PLUGIN_ID) |
||||||
|
public class RequestHandlerBridge extends AbstractHttpHandlerProvider { |
||||||
|
@Override |
||||||
|
public BaseHttpHandler[] registerHandlers() { |
||||||
|
return new BaseHttpHandler[]{ |
||||||
|
new ReportDataHandler() |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2015-2019 |
||||||
|
* FileName: URLAliasBridge |
||||||
|
* Author: Louis |
||||||
|
* Date: 2019/8/17 22:21 |
||||||
|
* Description: URLAliasBridge |
||||||
|
* History: |
||||||
|
* <author> <time> <version> <desc> |
||||||
|
*/ |
||||||
|
package com.fr.plugin.hfic.service; |
||||||
|
|
||||||
|
import com.fr.decision.fun.impl.AbstractURLAliasProvider; |
||||||
|
import com.fr.decision.webservice.url.alias.URLAlias; |
||||||
|
import com.fr.decision.webservice.url.alias.URLAliasFactory; |
||||||
|
import com.fr.stable.fun.Authorize; |
||||||
|
|
||||||
|
import static com.fr.plugin.hfic.LocaleFinder.PLUGIN_ID; |
||||||
|
import static com.fr.plugin.hfic.service.ReportDataHandler.API_EXPORT; |
||||||
|
|
||||||
|
/** |
||||||
|
* 〈Function Description〉<br> |
||||||
|
* 〈URLAliasBridge〉 |
||||||
|
* |
||||||
|
* @author fr.open |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
@Authorize(callSignKey = PLUGIN_ID) |
||||||
|
public class URLAliasBridge extends AbstractURLAliasProvider { |
||||||
|
@Override |
||||||
|
public URLAlias[] registerAlias() { |
||||||
|
return new URLAlias[]{ |
||||||
|
URLAliasFactory.createPluginAlias(API_EXPORT, API_EXPORT, true), |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C), 2015-2019 |
||||||
|
* FileName: JavaScriptFile |
||||||
|
* Author: Louis |
||||||
|
* Date: 2019/9/4 16:33 |
||||||
|
* Description: JavaScriptFile |
||||||
|
* History: |
||||||
|
* <author> <time> <version> <desc> |
||||||
|
*/ |
||||||
|
package com.fr.plugin.hfic.web; |
||||||
|
|
||||||
|
import com.fr.intelli.record.Focus; |
||||||
|
import com.fr.intelli.record.Original; |
||||||
|
import com.fr.record.analyzer.EnableMetrics; |
||||||
|
import com.fr.stable.fun.Authorize; |
||||||
|
import com.fr.stable.fun.impl.AbstractJavaScriptFileHandler; |
||||||
|
|
||||||
|
import static com.fr.plugin.hfic.LocaleFinder.PLUGIN_ID; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 〈Function Description〉<br> |
||||||
|
* 〈JavaScriptFile〉 |
||||||
|
* |
||||||
|
* @author fr.open |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
@EnableMetrics |
||||||
|
@Authorize(callSignKey = PLUGIN_ID) |
||||||
|
public class JavaScriptFile extends AbstractJavaScriptFileHandler { |
||||||
|
@Override |
||||||
|
@Focus(id = PLUGIN_ID, text = "Plugin-hfic", source = Original.PLUGIN) |
||||||
|
public String[] pathsForFiles() { |
||||||
|
return new String[]{ |
||||||
|
"/com/fr/plugin/hfic/web/excel.js" |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,3 @@ |
|||||||
|
Plugin-hfic=cpt export excel Plugin |
||||||
|
Plugin-hfic_Group=cpt export excel Plugin |
||||||
|
Plugin-hfic_Licence_Expired=cpt export excel Plugin Licence Expired |
@ -0,0 +1,3 @@ |
|||||||
|
Plugin-hfic=cpt\u5BFC\u51FAexcel\u63D2\u4EF6 |
||||||
|
Plugin-hfic_Group=cpt\u5BFC\u51FAexcel\u63D2\u4EF6 |
||||||
|
Plugin-hfic_Licence_Expired=cpt\u5BFC\u51FAexcel\u63D2\u4EF6\u8BB8\u53EF\u8FC7\u671F |
@ -0,0 +1,31 @@ |
|||||||
|
;!(function ($) { |
||||||
|
$.extend(FR, { |
||||||
|
exportExcelZip: function (data) { |
||||||
|
FR.exportFileByForm("/url/api/export", |
||||||
|
{ |
||||||
|
data: JSON.stringify(data) |
||||||
|
}, |
||||||
|
{target: "_blank"} |
||||||
|
); |
||||||
|
}, |
||||||
|
exportFileByForm: function (e, t, i) { |
||||||
|
i = i || {}, |
||||||
|
e = FR.fineServletURL + e; |
||||||
|
var n, o = { |
||||||
|
method: i.method || "POST", |
||||||
|
url: e, |
||||||
|
data: t, |
||||||
|
target: i.target |
||||||
|
}, |
||||||
|
r = $('<form method="' + o.method + '" />'); |
||||||
|
for (n in r.attr("action", o.url), r.attr("method", o.method || "post"), r.attr("target", o.target || "_self"), !0 === i.notEncode || (o.data = this.encodeParam(o.data)), o.data) r.append('<input type="hidden" name="' + n + '" value="' + o.data[n] + '" />'); |
||||||
|
$(document.body).append(r), |
||||||
|
r[0].submit(), |
||||||
|
r.remove() |
||||||
|
}, |
||||||
|
encodeParam: function (e) { |
||||||
|
for (var t in e) _.isObject(e[t]) ? e[t] = window.encodeURIComponent(FR.jsonEncode(e[t])) : e[t] = window.encodeURIComponent(e[t]); |
||||||
|
return e |
||||||
|
}, |
||||||
|
}); |
||||||
|
})(jQuery); |
Loading…
Reference in new issue