pioneer
2 years ago
commit
95ee08c940
23 changed files with 2282 additions and 0 deletions
@ -0,0 +1,6 @@
|
||||
# open-JSD-10441 |
||||
|
||||
JSD-10441 在填报工具栏里面,有像excel导入一样的,可以导入csv文件\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<plugin> |
||||
<id>com.fr.plugin.ajhig.file.import</id> |
||||
<name><![CDATA[导入文件定制_EK]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.1</version> |
||||
<env-version>10.0~10.0</env-version> |
||||
<jartime>2018-10-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[导入文件定制]]></description> |
||||
<change-notes><![CDATA[ |
||||
[2022-08-01]JSD-10441插件初始化<br/> |
||||
<p>导入文件定制</p> |
||||
]]></change-notes> |
||||
<main-package>com.fr.plugin.ajhig</main-package> |
||||
<prefer-packages> |
||||
<prefer-package>com.fanruan.api.*</prefer-package> |
||||
</prefer-packages> |
||||
<extra-core> |
||||
<LocaleFinder class="com.fr.plugin.ajhig.provider.LocaleFinder"/> |
||||
<WebService class="com.fr.plugin.ajhig.service.ReportWriteService"/> |
||||
</extra-core> |
||||
<extra-report> |
||||
<ExtensionButtonProvider class="com.fr.plugin.ajhig.toolbar.ImportCSVButton"/> |
||||
<JavaScriptFileHandler class="com.fr.plugin.ajhig.web.JavaScriptFile"/> |
||||
</extra-report> |
||||
<extra-designer> |
||||
<ToolbarItemProvider class="com.fr.plugin.ajhig.toolbar.ImportCSVToolbarItem"/> |
||||
</extra-designer> |
||||
<function-recorder class="com.fr.plugin.ajhig.provider.LocaleFinder"/> |
||||
<function-recorder class="com.fr.plugin.ajhig.service.ReportWriteService"/> |
||||
</plugin> |
@ -0,0 +1,32 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter11 |
||||
* FileName: CsvImportProcessor |
||||
* Author: |
||||
* Date: 2022/9/14 22:43 |
||||
*/ |
||||
package com.fr.plugin.ajhig.fun; |
||||
|
||||
import com.fr.main.TemplateWorkBook; |
||||
import com.fr.report.cell.DynamicAttrElem; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.stable.fun.mark.Immutable; |
||||
|
||||
import java.io.InputStream; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <CsvImportProcessor> |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
public interface CsvImportProcessor extends Immutable { |
||||
String MARK_STRING = "CsvImportProcessor"; |
||||
int CURRENT_LEVEL = 1; |
||||
|
||||
TemplateWorkBook generateWorkBookByStream(InputStream inputStream, String fileName, Map<String, Object> parameters) throws Exception; |
||||
|
||||
Object processImportCellValue(DynamicAttrElem dynamicAttrElem, Object value, Report report); |
||||
} |
@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter11 |
||||
* FileName: AbstractCsvImportProcessor |
||||
* Author: |
||||
* Date: 2022/9/14 22:53 |
||||
*/ |
||||
package com.fr.plugin.ajhig.fun.impl; |
||||
|
||||
import com.fr.plugin.ajhig.fun.CsvImportProcessor; |
||||
import com.fr.report.cell.DynamicAttrElem; |
||||
import com.fr.report.report.Report; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <AbstractCsvImportProcessor> |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
public abstract class AbstractCsvImportProcessor implements CsvImportProcessor { |
||||
public AbstractCsvImportProcessor() { |
||||
} |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return -1; |
||||
} |
||||
|
||||
@Override |
||||
public int layerIndex() { |
||||
return -1; |
||||
} |
||||
|
||||
@Override |
||||
public Object processImportCellValue(DynamicAttrElem dynamicAttrElem, Object value, Report report) { |
||||
return value; |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,31 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter11 |
||||
* FileName: CsvReportImporterFactory |
||||
* Author: |
||||
* Date: 2022/9/15 9:08 |
||||
*/ |
||||
package com.fr.plugin.ajhig.io.importer; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <CsvReportImporterFactory> |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class CsvReportImporterFactory { |
||||
private static final Map<String, Class<? extends CsvReportImporter>> csvReportImporterMap = new HashMap<>(); |
||||
|
||||
public CsvReportImporterFactory() { |
||||
} |
||||
|
||||
public static CsvReportImporter createCsvImporter(String importerType) { |
||||
|
||||
return new CsvReportImporter(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,23 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter11 |
||||
* FileName: WriteCsvImportException |
||||
* Author: |
||||
* Date: 2022/9/15 11:46 |
||||
*/ |
||||
package com.fr.plugin.ajhig.io.importer; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <WriteCsvImportException> |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class WriteCsvImportException extends Exception { |
||||
private static final long serialVersionUID = -5680935509808898723L; |
||||
|
||||
public WriteCsvImportException(String msg) { |
||||
super(msg); |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter11 |
||||
* FileName: CsvImportResult |
||||
* Author: |
||||
* Date: 2022/9/15 11:39 |
||||
*/ |
||||
package com.fr.plugin.ajhig.io.result; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <CsvImportResult> |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class CsvImportResult { |
||||
private boolean success; |
||||
private Exception wie; |
||||
private String msg; |
||||
|
||||
public CsvImportResult() { |
||||
this.success = true; |
||||
} |
||||
|
||||
public CsvImportResult(boolean success, Exception wie) { |
||||
this.success = success; |
||||
this.wie = wie; |
||||
} |
||||
|
||||
public CsvImportResult(boolean success, String msg) { |
||||
this.success = success; |
||||
this.msg = msg; |
||||
} |
||||
|
||||
public static CsvImportResult success() { |
||||
return new CsvImportResult(); |
||||
} |
||||
|
||||
public static CsvImportResult fail(Exception e) { |
||||
return new CsvImportResult(false, e); |
||||
} |
||||
|
||||
public static CsvImportResult fail(String msg) { |
||||
return new CsvImportResult(false, msg); |
||||
} |
||||
|
||||
public boolean isSuccess() { |
||||
return this.success; |
||||
} |
||||
|
||||
public Exception getWie() { |
||||
return this.wie; |
||||
} |
||||
|
||||
public String getMsg() { |
||||
return this.msg; |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter11 |
||||
* FileName: CsvImportResultHandler |
||||
* Author: |
||||
* Date: 2022/9/15 11:43 |
||||
*/ |
||||
package com.fr.plugin.ajhig.io.result; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <CsvImportResultHandler> |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class CsvImportResultHandler { |
||||
private static final String SUCCESS = "success"; |
||||
private static final String MSG = "msg"; |
||||
private static final CsvImportResultHandler INSTANCE = new CsvImportResultHandler(); |
||||
|
||||
public CsvImportResultHandler() { |
||||
} |
||||
|
||||
public static CsvImportResultHandler getInstance() { |
||||
return INSTANCE; |
||||
} |
||||
|
||||
public void input(HttpServletResponse response, CsvImportResult importResult) throws Exception { |
||||
String msg = importResult.getMsg(); |
||||
if (msg == null && importResult.getWie() != null) { |
||||
msg = importResult.getWie().getMessage(); |
||||
} |
||||
JSONObject result = JSONObject.create(); |
||||
result.put("success", importResult.isSuccess()); |
||||
result.put("msg", msg); |
||||
WebUtils.printAsString(response, result.toString()); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* Copyright (C), 2015-2019 |
||||
* FileName: LocaleFinder |
||||
* Author: |
||||
* Date: 2019/6/5 16:20 |
||||
* Description: LocaleFinder |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ajhig.provider; |
||||
|
||||
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.ajhig.provider.LocaleFinder.PLUGIN_ID; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈LocaleFinder〉 |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
@EnableMetrics |
||||
@Authorize(callSignKey = PLUGIN_ID) |
||||
public class LocaleFinder extends AbstractLocaleFinder { |
||||
public static final String PLUGIN_ID = "com.fr.plugin.ajhig.file.import"; |
||||
public static final String ICON_PATH = "/com/fr/plugin/ajhig/images/json16.png"; |
||||
|
||||
@Override |
||||
@Focus(id = PLUGIN_ID, text = "Plugin-ajhig", source = Original.PLUGIN) |
||||
public String find() { |
||||
return "com/fr/plugin/ajhig/locale/lang"; |
||||
} |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return CURRENT_LEVEL; |
||||
} |
||||
} |
@ -0,0 +1,88 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter11 |
||||
* FileName: ImpWCSVData |
||||
* Author: |
||||
* Date: 2022/9/13 15:58 |
||||
*/ |
||||
package com.fr.plugin.ajhig.service; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.base.CustomConfigManager; |
||||
import com.fr.io.importer.ExcelReportImporter; |
||||
import com.fr.io.importer.ExcelReportImporterFactory; |
||||
import com.fr.main.TemplateWorkBook; |
||||
import com.fr.plugin.ajhig.io.importer.WriteCsvImportException; |
||||
import com.fr.plugin.ajhig.io.result.CsvImportResult; |
||||
import com.fr.plugin.ajhig.io.result.CsvImportResultHandler; |
||||
import com.fr.plugin.ajhig.write.web.csv.WebCsvUtils; |
||||
import com.fr.restriction.MemoryAlarmException; |
||||
import com.fr.web.core.ActionNoSessionCMD; |
||||
import com.fr.web.core.ErrorHandlerHelper; |
||||
import com.fr.web.core.ReportSessionIDInfor; |
||||
import com.fr.web.core.SessionPoolManager; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <ImpWCSVData导入CSV> |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class ImpWCSVAction extends ActionNoSessionCMD { |
||||
private static final String CMD = "imp_w_csv_data"; |
||||
|
||||
public ImpWCSVAction() { |
||||
} |
||||
|
||||
@Override |
||||
public String getCMD() { |
||||
return CMD; |
||||
} |
||||
|
||||
@Override |
||||
public void actionCMD(HttpServletRequest request, HttpServletResponse response, String sessionID) throws Exception { |
||||
ReportSessionIDInfor sessionIDInfor = SessionPoolManager.getSessionIDInfor(sessionID, ReportSessionIDInfor.class); |
||||
if (sessionIDInfor == null) { |
||||
ErrorHandlerHelper.getErrorHandler().error(request, response, "cmd: \"" + this.getCMD() + "\", SessionID: \"" + sessionID + "\" not exist."); |
||||
return; |
||||
} |
||||
TemplateWorkBook templateWorkBook; |
||||
try { |
||||
templateWorkBook = WebCsvUtils.dealWithUploadCsv(request, response); |
||||
} catch (MemoryAlarmException memoryAlarmException) { |
||||
LogKit.error(memoryAlarmException.getMessage(), memoryAlarmException); |
||||
CsvImportResultHandler.getInstance().input(response, CsvImportResult.fail(memoryAlarmException.getLocaleKey())); |
||||
return; |
||||
} catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
CsvImportResultHandler.getInstance().input(response, CsvImportResult.fail(e)); |
||||
return; |
||||
} |
||||
|
||||
try { |
||||
boolean checkWidget = CustomConfigManager.getInstance().isCheckWidget(); |
||||
String importerType = WebUtils.getHTTPRequestParameter(request, "type"); |
||||
// CsvReportImporter csvReportImporter = CsvReportImporterFactory.createCsvImporter(importerType);
|
||||
// csvReportImporter.importExcel2Book(sessionIDInfor, sessionIDInfor.getContextBook(), templateWorkBook, sessionIDInfor.getParameterMap4Execute(), checkWidget);
|
||||
|
||||
ExcelReportImporter csvReportImporter = ExcelReportImporterFactory.createExcelImporter(importerType); |
||||
csvReportImporter.importExcel2Book(sessionIDInfor, sessionIDInfor.getContextBook(), templateWorkBook, sessionIDInfor.getParameterMap4Execute(), checkWidget); |
||||
|
||||
CsvImportResultHandler.getInstance().input(response, CsvImportResult.success()); |
||||
} catch (MemoryAlarmException memoryAlarmException) { |
||||
LogKit.error(memoryAlarmException.getMessage(), memoryAlarmException); |
||||
CsvImportResultHandler.getInstance().input(response, CsvImportResult.fail(memoryAlarmException.getLocaleKey())); |
||||
} catch (WriteCsvImportException writeCsvImportException) { |
||||
LogKit.error(writeCsvImportException.getMessage(), writeCsvImportException); |
||||
CsvImportResultHandler.getInstance().input(response, CsvImportResult.fail(writeCsvImportException)); |
||||
} catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
CsvImportResultHandler.getInstance().input(response, CsvImportResult.fail("Plugin-ajhig_Import_Failed")); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter11 |
||||
* FileName: ReportWriteService |
||||
* Author: |
||||
* Date: 2022/9/13 12:08 |
||||
*/ |
||||
package com.fr.plugin.ajhig.service; |
||||
|
||||
import com.fanruan.api.i18n.I18nKit; |
||||
import com.fr.decision.system.session.TimeoutDefaultSessionException; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.fr.stable.fun.Service; |
||||
import com.fr.web.core.*; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import static com.fr.plugin.ajhig.provider.LocaleFinder.PLUGIN_ID; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <ReportWriteService> |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
@Authorize(callSignKey = PLUGIN_ID) |
||||
public class ReportWriteService implements Service { |
||||
|
||||
private static final ActionCMD[] actions = { |
||||
new ImpWCSVAction() |
||||
}; |
||||
|
||||
@Override |
||||
public String actionOP() { |
||||
return "ajhig_write"; |
||||
} |
||||
|
||||
@Override |
||||
@Focus(id = PLUGIN_ID, text = "Plugin-ajhig", source = Original.PLUGIN) |
||||
public void process(HttpServletRequest request, HttpServletResponse response, String op, String sessionID) throws Exception { |
||||
ReportSessionIDInfor sessionIDInfor = SessionPoolManager.getSessionIDInfor(sessionID, ReportSessionIDInfor.class); |
||||
if (sessionIDInfor == null) { |
||||
throw new TimeoutDefaultSessionException(); |
||||
} |
||||
if (PluginContexts.currentContext() == null || !PluginContexts.currentContext().isAvailable()) { |
||||
ErrorHandlerHelper.getErrorHandler().error(request, response, I18nKit.getLocText("Plugin-ajhig_Licence_Expired")); |
||||
return; |
||||
} |
||||
|
||||
WebActionsDispatcher.dealForActionCMD(request, response, sessionID, actions); |
||||
} |
||||
} |
@ -0,0 +1,100 @@
|
||||
/* |
||||
* Copyright (C), 2015-2019 |
||||
* FileName: JSONExtensionButton |
||||
* Author: |
||||
* Date: 2019/8/28 17:16 |
||||
* Description: JSONExtensionButton |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ajhig.toolbar; |
||||
|
||||
import com.fanruan.api.i18n.I18nKit; |
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.form.ui.WebContentUtils; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.js.JavaScript; |
||||
import com.fr.js.JavaScriptImpl; |
||||
import com.fr.plugin.ajhig.utils.FuncUtils; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.report.fun.impl.AbstractExtensionButton; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.fr.stable.web.Repository; |
||||
|
||||
import java.util.UUID; |
||||
|
||||
import static com.fr.plugin.ajhig.provider.LocaleFinder.PLUGIN_ID; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈JSONExtensionButton〉 |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
@Authorize(callSignKey = PLUGIN_ID) |
||||
public class ImportCSVButton extends AbstractExtensionButton { |
||||
private static final long serialVersionUID = 7697898326364103005L; |
||||
private String uuid = UUID.randomUUID().toString(); |
||||
|
||||
public ImportCSVButton() { |
||||
super(I18nKit.getLocText("Plugin-ajhig_Import_CSV"), FuncUtils.loadIcon()); |
||||
} |
||||
|
||||
public ImportCSVButton(String text) { |
||||
super(text); |
||||
} |
||||
|
||||
public ImportCSVButton(String text, String iconName) { |
||||
super(text, iconName); |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends Widget> classForDirectoryButton() { |
||||
return this.getClass(); |
||||
} |
||||
|
||||
@Override |
||||
public String getParentDirectory() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public String getType() { |
||||
return "CsvReportImporter.class"; |
||||
} |
||||
|
||||
@Override |
||||
public String getRelatedCheckBoxTitle() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isSelected() { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public void setSelected(boolean b) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
protected JavaScript initAction(Repository repository) { |
||||
String js = WebContentUtils.getContentPanel(repository) + ".initCsvButton(this,'" + this.getUuid() + "');"; |
||||
return super.initAction(repository).append(repository, js); |
||||
} |
||||
|
||||
@Override |
||||
protected JavaScriptImpl clickAction(Repository repository) { |
||||
if (PluginContexts.currentContext() == null || !PluginContexts.currentContext().isAvailable()) { |
||||
LogKit.error(I18nKit.getLocText("Plugin-ajhig_Licence_Expired")); |
||||
return null; |
||||
} |
||||
return new JavaScriptImpl(WebContentUtils.getContentPanel(repository) + ".importCSVData()"); |
||||
} |
||||
|
||||
public String getUuid() { |
||||
return this.uuid; |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
/* |
||||
* Copyright (C), 2015-2019 |
||||
* FileName: ImportCSVToolbarItem |
||||
* Author: |
||||
* Date: 2019/8/29 16:15 |
||||
* Description: ImportCSVToolbarItem |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ajhig.toolbar; |
||||
|
||||
import com.fanruan.api.i18n.I18nKit; |
||||
import com.fr.base.IconManager; |
||||
import com.fr.design.fun.impl.AbstractToolbarItem; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.plugin.ajhig.provider.LocaleFinder; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈ImportCSVToolbarItem〉 |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
@Authorize(callSignKey = LocaleFinder.PLUGIN_ID) |
||||
public class ImportCSVToolbarItem extends AbstractToolbarItem { |
||||
@Override |
||||
public Class<? extends Widget> classForWidget() { |
||||
return ImportCSVButton.class; |
||||
} |
||||
|
||||
@Override |
||||
public String iconPathForWidget() { |
||||
return IconManager.EXCEL.getPath(); |
||||
} |
||||
|
||||
@Override |
||||
public String nameForWidget() { |
||||
return I18nKit.getLocText("Plugin-ajhig_Import_CSV"); |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
/* |
||||
* Copyright (C), 2015-2019 |
||||
* FileName: FuncUtils |
||||
* Author: |
||||
* Date: 2019/8/22 15:05 |
||||
* Description: FuncUtils |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ajhig.utils; |
||||
|
||||
import com.fr.base.IconManager; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈FuncUtils〉 |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class FuncUtils { |
||||
public static String loadIcon() { |
||||
// Icon icon = new Icon("json", IOUtils.readImage(ICON_PATH));
|
||||
// IconManager.getIconManager().addIcon(icon, true);
|
||||
// return icon.getName();
|
||||
return IconManager.EXCEL.getName(); |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
/* |
||||
* Copyright (C), 2015-2019 |
||||
* FileName: JavaScriptFile |
||||
* Author: |
||||
* Date: 2019/8/29 16:33 |
||||
* Description: JavaScriptFile |
||||
* History: |
||||
* <author> <time> <version> <desc> |
||||
*/ |
||||
package com.fr.plugin.ajhig.web; |
||||
|
||||
import com.fanruan.api.i18n.I18nKit; |
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fr.plugin.ajhig.provider.LocaleFinder; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.stable.fun.Authorize; |
||||
import com.fr.stable.fun.impl.AbstractJavaScriptFileHandler; |
||||
|
||||
/** |
||||
* 〈Function Description〉<br> |
||||
* 〈JavaScriptFile〉 |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
@Authorize(callSignKey = LocaleFinder.PLUGIN_ID) |
||||
public class JavaScriptFile extends AbstractJavaScriptFileHandler { |
||||
@Override |
||||
public String[] pathsForFiles() { |
||||
if (PluginContexts.currentContext() == null || !PluginContexts.currentContext().isAvailable()) { |
||||
LogKit.error(I18nKit.getLocText("Plugin-ajhig_Licence_Expired")); |
||||
return new String[0]; |
||||
} |
||||
return new String[]{ |
||||
"/com/fr/plugin/ajhig/web/fileImport.js" |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,32 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter11 |
||||
* FileName: DefaultCsvImporterProcessor |
||||
* Author: |
||||
* Date: 2022/9/14 16:47 |
||||
*/ |
||||
package com.fr.plugin.ajhig.write.web.csv; |
||||
|
||||
import com.fr.main.TemplateWorkBook; |
||||
import com.fr.plugin.ajhig.fun.impl.AbstractCsvImportProcessor; |
||||
import com.fr.plugin.ajhig.io.importer.CsvReportImporter; |
||||
|
||||
import java.io.InputStream; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <DefaultCsvImporterProcessor> |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class DefaultCsvImporterProcessor extends AbstractCsvImportProcessor { |
||||
public DefaultCsvImporterProcessor() { |
||||
} |
||||
|
||||
@Override |
||||
public TemplateWorkBook generateWorkBookByStream(InputStream inputStream, String fileName, Map<String, Object> parameters) throws Exception { |
||||
return (new CsvReportImporter()).generateWorkBookByStream(inputStream, parameters); |
||||
} |
||||
} |
@ -0,0 +1,228 @@
|
||||
/* |
||||
* Copyright (C), 2018-2022 |
||||
* Project: starter11 |
||||
* FileName: WebCSVUtils |
||||
* Author: |
||||
* Date: 2022/9/13 16:33 |
||||
*/ |
||||
package com.fr.plugin.ajhig.write.web.csv; |
||||
|
||||
import com.fr.base.Utils; |
||||
import com.fr.base.extension.FileExtension; |
||||
import com.fr.data.impl.excelplus.ExcelDataModelPlus; |
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.json.JSON; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONFactory; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.main.TemplateWorkBook; |
||||
import com.fr.plugin.ajhig.fun.CsvImportProcessor; |
||||
import com.fr.report.ExtraReportClassManager; |
||||
import com.fr.report.restriction.config.TempRestrictionConfigSelector; |
||||
import com.fr.restriction.MemoryAlarmException; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.web.core.upload.SmartFile; |
||||
import com.fr.web.core.upload.SmartFileManager; |
||||
import com.fr.web.core.upload.SmartFiles; |
||||
import com.fr.web.core.upload.SmartUpload; |
||||
import com.fr.web.utils.WebUtils; |
||||
import com.fr.write.web.excel.CustomizeExcelImportProcessor; |
||||
import com.fr.write.web.excel.ExcelSheetUtils; |
||||
import com.fr.write.web.excel.SheetDataManager; |
||||
|
||||
import javax.servlet.ServletContext; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.ByteArrayInputStream; |
||||
import java.util.*; |
||||
|
||||
import static com.fr.plugin.ajhig.io.importer.CsvReportImporter.CSV_IMPORT_PROCESSOR; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <WebCSVUtils> |
||||
* |
||||
* @author |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class WebCsvUtils { |
||||
public WebCsvUtils() { |
||||
} |
||||
|
||||
public static JSONObject getExcelConfigBySheet(HttpServletRequest var0, HttpServletResponse var1, String var2, int var3) throws Exception { |
||||
ByteArrayInputStream var4 = null; |
||||
new ArrayList(); |
||||
int var6 = WebUtils.getHTTPRequestIntParameter(var0, "limit"); |
||||
|
||||
List var5; |
||||
try { |
||||
JSONObject var8; |
||||
try { |
||||
SmartFile var7 = SmartFileManager.getInstance().getSmartFile(var2); |
||||
if (var7 == null) { |
||||
var8 = JSONObject.create(); |
||||
return var8; |
||||
} |
||||
|
||||
var4 = new ByteArrayInputStream(var7.getBytes()); |
||||
var5 = SheetDataManager.getInstance().getSingleSheetData(var2, var3); |
||||
if (var5.isEmpty()) { |
||||
List var15 = ExcelDataModelPlus.createMutiSheetData(var4, var7.getFileName().toLowerCase()); |
||||
SheetDataManager.getInstance().cacheFile(var2, var15); |
||||
var5 = (List) var15.get(var3); |
||||
} |
||||
} catch (MemoryAlarmException var13) { |
||||
var8 = (JSONObject) JSONFactory.createJSON(JSON.OBJECT); |
||||
var8.put("error", "Error: " + var13.getMessage()); |
||||
JSONObject var9 = var8; |
||||
return var9; |
||||
} |
||||
} finally { |
||||
if (var4 != null) { |
||||
var4.close(); |
||||
} |
||||
|
||||
} |
||||
|
||||
return parseListData2JSON(var5, var6); |
||||
} |
||||
|
||||
private static JSONObject parseListData2JSON(List<Object[]> var0, int var1) throws JSONException { |
||||
JSONObject var2 = JSONObject.create(); |
||||
if (var0 == null) { |
||||
return var2; |
||||
} else { |
||||
int var3 = 0; |
||||
|
||||
Object[] var5; |
||||
for (Iterator var4 = var0.iterator(); var4.hasNext(); var3 = Math.max(var3, var5.length)) { |
||||
var5 = (Object[]) var4.next(); |
||||
} |
||||
|
||||
int var10 = var1 == -1 ? var0.size() : Math.min(var1, var0.size()); |
||||
String[][] var11 = new String[var10][var3]; |
||||
|
||||
for (int var6 = 0; var6 < var10; ++var6) { |
||||
String[] var7 = new String[var3]; |
||||
Object[] var8 = (Object[]) var0.get(var6); |
||||
|
||||
int var9; |
||||
for (var9 = 0; var9 < var8.length; ++var9) { |
||||
var7[var9] = GeneralUtils.objectToString(var8[var9]); |
||||
} |
||||
|
||||
for (var9 = var8.length; var9 < var3; ++var9) { |
||||
var7[var9] = ""; |
||||
} |
||||
|
||||
var11[var6] = var7; |
||||
} |
||||
|
||||
var2.put("cellData", var11); |
||||
var2.put("rowCount", var0.size()); |
||||
return var2; |
||||
} |
||||
} |
||||
|
||||
public static String[] getSheetsName(String var0) { |
||||
SmartFile var1 = SmartFileManager.getInstance().getSmartFile(var0); |
||||
|
||||
try { |
||||
return ExcelSheetUtils.getAllSheets(var1); |
||||
} catch (Exception var3) { |
||||
FineLoggerFactory.getLogger().error(var3.getMessage(), var3); |
||||
return new String[0]; |
||||
} |
||||
} |
||||
|
||||
public static SmartFile getCsvFromReq(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
ServletContext servletContext = request.getSession().getServletContext(); |
||||
int maxExcelImportCellCount = TempRestrictionConfigSelector.getInstance().getMaxExcelImportCellCount(); |
||||
SmartUpload upload = new SmartUpload(); |
||||
upload.setLimitCount(maxExcelImportCellCount); |
||||
upload.initialize(servletContext, request, response); |
||||
upload.setAllowedFilesList(FileExtension.CSV, FileExtension.TXT); |
||||
upload.upload(); |
||||
SmartFiles uploadFiles = upload.getFiles(); |
||||
if (uploadFiles.getSize() == 0L) { |
||||
return null; |
||||
} |
||||
String fileIndex = WebUtils.getHTTPRequestParameter(request, "fileIndex"); |
||||
int fileIndexNum = fileIndex == null ? 0 : Integer.parseInt(Utils.objectToString(fileIndex)); |
||||
if (fileIndexNum < 0 || (long) fileIndexNum >= uploadFiles.getSize()) { |
||||
fileIndexNum = 0; |
||||
} |
||||
SmartFile file = uploadFiles.getFile(fileIndexNum); |
||||
if (!validateCsvFile(file)) { |
||||
throw new CsvUploadException("Plugin-ajhig_Should_Select_An_CSV_File"); |
||||
} else { |
||||
return file; |
||||
} |
||||
} |
||||
|
||||
public static TemplateWorkBook dealWithUploadCsv(HttpServletRequest request, HttpServletResponse response, Map<String, Object> parameters) throws Exception { |
||||
SmartFile smartFile = getCsvFromReq(request, response); |
||||
ByteArrayInputStream inputStream = null; |
||||
TemplateWorkBook workBook; |
||||
try { |
||||
inputStream = new ByteArrayInputStream(smartFile.getBytes()); |
||||
String fileName = smartFile.getFileName().toLowerCase(); |
||||
Object importProcessor = ExtraReportClassManager.getInstance().getSingle(CSV_IMPORT_PROCESSOR); |
||||
if (importProcessor == null) { |
||||
importProcessor = new DefaultCsvImporterProcessor(); |
||||
} |
||||
workBook = ((CsvImportProcessor) importProcessor).generateWorkBookByStream(inputStream, fileName, parameters); |
||||
} finally { |
||||
if (inputStream != null) { |
||||
inputStream.close(); |
||||
} |
||||
} |
||||
return workBook; |
||||
} |
||||
|
||||
public static TemplateWorkBook customizedDealWithUploadExcel(HttpServletRequest var0, HttpServletResponse var1, Map<String, Object> var2) throws Exception { |
||||
String var3 = (String) var2.get("sessionID"); |
||||
SmartFile var4 = SmartFileManager.getInstance().getSmartFile(var3); |
||||
ByteArrayInputStream var5 = null; |
||||
TemplateWorkBook var6 = null; |
||||
|
||||
try { |
||||
var5 = new ByteArrayInputStream(var4.getBytes()); |
||||
if (!validateCsvFile(var4)) { |
||||
throw new CsvUploadException("Fine-Engine_Should_Select_An_Excel_File"); |
||||
} |
||||
|
||||
String var7 = var4.getFileName().toLowerCase(); |
||||
CustomizeExcelImportProcessor var8 = new CustomizeExcelImportProcessor(); |
||||
var6 = var8.generateWorkBookByStream(var5, var7, var2); |
||||
} finally { |
||||
if (var5 != null) { |
||||
var5.close(); |
||||
} |
||||
|
||||
} |
||||
|
||||
return var6; |
||||
} |
||||
|
||||
public static TemplateWorkBook dealWithUploadCsv(HttpServletRequest request, HttpServletResponse response) throws Exception { |
||||
return dealWithUploadCsv(request, response, new HashMap<>()); |
||||
} |
||||
|
||||
public static void cacheTMPExcel(HttpServletRequest var0, HttpServletResponse var1, String var2) throws Exception { |
||||
SmartFile var3 = getCsvFromReq(var0, var1); |
||||
SmartFileManager.getInstance().cacheFile(var2, var3); |
||||
} |
||||
|
||||
private static boolean validateCsvFile(SmartFile file) { |
||||
String csvType = file.getFileExt(); |
||||
return StringUtils.equalsIgnoreCase(csvType, "csv") || StringUtils.equalsIgnoreCase(csvType, "txt"); |
||||
} |
||||
|
||||
public static class CsvUploadException extends Exception { |
||||
private CsvUploadException(String e) { |
||||
super(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
Plugin-ajhig=File Import Plugin |
||||
Plugin-ajhig_Group=File Import Plugin |
||||
Plugin-ajhig_Licence_Expired=File Import Plugin Licence Expired |
||||
Plugin-ajhig_Import_CSV=Import[CSV] |
||||
Plugin-ajhig_Import_Txt=Import[Txt] |
||||
Plugin-ajhig_Import_CSV_Import=Import CSV |
||||
Plugin-ajhig_Import_Failed=Import Failed |
||||
Plugin-ajhig_Should_Select_An_CSV_File=Select an CSV file |
||||
Plugin-ajhig_NS_Exception_ReadCsvError=File parsing error. |
||||
Plugin-ajhig_Csv_Start=Start Importing Sheet: |
||||
Plugin-ajhig_Csv_By_Location=CSV import, start location matching. |
||||
Plugin-ajhig_Csv_Uc_List=Cells of uncertain row imported: |
||||
Plugin-ajhig_Csv_import_cost=Import CSV successfully, time (ms): |
@ -0,0 +1,13 @@
|
||||
Plugin-ajhig=\u5BFC\u5165\u6587\u4EF6\u5B9A\u5236 |
||||
Plugin-ajhig_Group=\u5BFC\u5165\u6587\u4EF6\u5B9A\u5236\u63D2\u4EF6 |
||||
Plugin-ajhig_Licence_Expired=\u5BFC\u5165\u6587\u4EF6\u5B9A\u5236\u63D2\u4EF6\u8BB8\u53EF\u8FC7\u671F |
||||
Plugin-ajhig_Import_CSV=\u5BFC\u5165[CSV] |
||||
Plugin-ajhig_Import_Txt=\u5BFC\u5165[Txt] |
||||
Plugin-ajhig_Import_CSV_Import=\u5BFC\u5165CSV |
||||
Plugin-ajhig_Import_Failed=\u5BFC\u5165\u5931\u8D25 |
||||
Plugin-ajhig_Should_Select_An_CSV_File=\u8BF7\u9009\u62E9CSV\u6587\u4EF6 |
||||
Plugin-ajhig_NS_Exception_ReadCsvError=\u6587\u4EF6\u89E3\u6790\u51FA\u9519 |
||||
Plugin-ajhig_Csv_Start=\u5F00\u59CB\u5BFC\u5165sheet: |
||||
Plugin-ajhig_Csv_By_Location=CSV\u5BFC\u5165, \u5F00\u59CB\u4F4D\u7F6E\u5339\u914D |
||||
Plugin-ajhig_Csv_Uc_List=\u4E0D\u5B9A\u884C\u5BFC\u5165\u5355\u5143\u683C\u4E3A: |
||||
Plugin-ajhig_Csv_import_cost=\u5BFC\u5165CSV\u6210\u529F, \u8017\u65F6(\u6BEB\u79D2): |
@ -0,0 +1,176 @@
|
||||
(function ($) { |
||||
if (FR.WritePane) { |
||||
$.extend(FR.WritePane.prototype, { |
||||
importCSV: function (j) { |
||||
FR.showUploadDialog($.extend({ |
||||
title: FR.i18nText("Plugin-ajhig_Import_CSV_Import"), |
||||
autoUpload: true |
||||
}, |
||||
this.importCSVOptions(j))) |
||||
}, |
||||
initCsvButton: function (j, m, k) { |
||||
var l = $(j.$table || j.$btndiv); |
||||
l.one("mouseover", |
||||
function () { |
||||
if ($("#" + m).length > 0) { |
||||
var o = $("#" + m); |
||||
var n = $("input", o) |
||||
} else { |
||||
var o = $('<form enctype="multipart/form-data" class="class_importexcelform" id="' + m + '"></form>').appendTo("body"); |
||||
var n = $('<input type="file" name="file" style="width:86px; height:23px; cursor : pointer" size="2"/>').appendTo(o) |
||||
} |
||||
n.mouseover(function () { |
||||
l.mouseover() |
||||
}).mouseout(function () { |
||||
l.mouseout() |
||||
}).mousedown(function () { |
||||
l.mousedown() |
||||
}).mouseup(function () { |
||||
l.mouseup() |
||||
}).change(function () { |
||||
if (!j.isEnabled()) { |
||||
return |
||||
} |
||||
if (this.value === "") { |
||||
return |
||||
} |
||||
_g()._importCSVData(m, k) |
||||
}).click(function (p) { |
||||
if (!j.isEnabled()) { |
||||
p.stopEvent() |
||||
} |
||||
if (contentPane.delay) { |
||||
p.stopEvent() |
||||
} |
||||
this.value = "" |
||||
}); |
||||
n.css({ |
||||
top: l.offset().top, |
||||
left: l.offset().left, |
||||
width: l.width(), |
||||
display: k === "menu" ? "none" : "", |
||||
position: "absolute", |
||||
"z-index": 7999, |
||||
"opacity": 0 |
||||
}) |
||||
}) |
||||
}, |
||||
importCSVOptions: function (l) { |
||||
if (l && l.indexOf("customize") !== -1) { |
||||
return this.customizeImportCSVOptions() |
||||
} |
||||
var j = this; |
||||
var k = FR.servletURL + "?sessionID=" + this.currentSessionID + "&op=ajhig_write&cmd=imp_w_csv_data"; |
||||
return { |
||||
url: l ? k + "&type=" + l : k, |
||||
callback: function (n, m) { |
||||
this.dealWithImpResult(n, m) |
||||
}.createDelegate(this), |
||||
beforeAction: function () { |
||||
j.fireEvent(FR.Events.BIMEXCEL) |
||||
}, |
||||
afterAction: function () { |
||||
j.fireEvent(FR.Events.AIMEXCEL) |
||||
} |
||||
} |
||||
}, |
||||
// dealWithImpResult: function (m, k) {
|
||||
// if (k === "success") {
|
||||
// var j = FR.jsonDecode(m.responseText);
|
||||
// if (j.exception === "FAILPASS") {
|
||||
// FR.Msg.toast(FR.i18nText("Fine-Engine_custom_import_not_register"))
|
||||
// } else {
|
||||
// if (j.success) {
|
||||
// this.loadContentPane();
|
||||
// if (this.isAutoStash()) {
|
||||
// this.stash()
|
||||
// }
|
||||
// if (FR.Browser.isIE()) {
|
||||
// var l = $(".class_importexcelform");
|
||||
// $.each(l,
|
||||
// function (n, p) {
|
||||
// var o = $("input", p);
|
||||
// o.replaceWith(o.clone(true))
|
||||
// })
|
||||
// }
|
||||
// } else {
|
||||
// FR.Msg.toast(FR.i18nText(j.msg))
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// FR.Msg.toast(FR.i18nText("Fine-Engine_Send_Failed"))
|
||||
// }
|
||||
// },
|
||||
customizeImportCSVOptions: function () { |
||||
var j = this; |
||||
return { |
||||
url: FR.servletURL + "?sessionID=" + this.currentSessionID + "&op=ajhig_write&cmd=c_cache_csv", |
||||
callback: function (m, l) { |
||||
if (l === "success") { |
||||
var k = FR.jsonDecode(m.responseText); |
||||
if (k.success) { |
||||
FR.$defaultImport("/com/fr/write/web/excel/ces.js", "js"); |
||||
FR.$defaultImport("/com/fr/write/web/css/ces.css", "css"); |
||||
try { |
||||
FR.CUSTEXCELIMPORT.initSettingDialog(k.msg, this.currentSessionID, |
||||
function (p, o) { |
||||
j.dealWithImpResult(p, o); |
||||
j.fireEvent(FR.Events.AIMEXCEL) |
||||
}) |
||||
} catch (n) { |
||||
FR.Msg.toast(n) |
||||
} |
||||
} else { |
||||
FR.Msg.toast(FR.i18nText(k.msg)) |
||||
} |
||||
} else { |
||||
FR.Msg.toast(FR.i18nText("Fine-Engine_Send_Failed")) |
||||
} |
||||
}.createDelegate(this), |
||||
beforeAction: function () { |
||||
j.fireEvent(FR.Events.BIMEXCEL) |
||||
} |
||||
} |
||||
}, |
||||
_importCSVData_Customize: function (j) { |
||||
this._importCSVData(j, "customize") |
||||
}, |
||||
_importCSVData_Customize_Menu: function (j) { |
||||
this.importCSVType = "customize_m"; |
||||
$("#" + j + " input").click() |
||||
}, |
||||
_importCSVData_Cover_Menu: function (j) { |
||||
this.importCSVType = "cover"; |
||||
$("#" + j + " input").click() |
||||
}, |
||||
_importCSVData_Clean_Menu: function (j) { |
||||
this.importCSVType = "clean"; |
||||
$("#" + j + " input").click() |
||||
}, |
||||
_importCSVData_Append_Menu: function (j) { |
||||
this.importCSVType = "append"; |
||||
$("#" + j + " input").click() |
||||
}, |
||||
_importCSVData_Multi: function (k, j) { |
||||
this.importCSVType = j; |
||||
this._importCSVData(k, j) |
||||
}, |
||||
importExcel_Append: function () { |
||||
this.importCSV("append") |
||||
}, |
||||
importExcel_Cover: function () { |
||||
this.importCSV("cover") |
||||
}, |
||||
importCSV_Clean: function () { |
||||
this.importCSV("clean") |
||||
}, |
||||
importCSVData: function (j) { |
||||
this._importCSVData(j) |
||||
}, |
||||
_importCSVData: function (k, j) { |
||||
var j = j === "menu" ? this.importCSVType : j; |
||||
FR.autoSubmit(this.importCSVOptions(j), $("#" + k)) |
||||
} |
||||
}); |
||||
} |
||||
})(jQuery); |
Loading…
Reference in new issue