richie
6 years ago
5 changed files with 241 additions and 138 deletions
@ -1,124 +1,146 @@
|
||||
package com.fr.plugin.file.submit.oss.ui.tools; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.base.extension.FileExtension; |
||||
import com.fr.data.SubmitJob; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.file.filetree.FileNode; |
||||
import com.fr.io.TemplateWorkBookIO; |
||||
import com.fr.main.impl.WorkBook; |
||||
import com.fr.plugin.customsubmmit.core.PathConfig; |
||||
import com.fr.plugin.customsubmmit.core.ServerPathColumnConfig; |
||||
import com.fr.plugin.customsubmmit.report.ServerPathSubmiterJob; |
||||
import com.fr.plugin.file.submit.oss.fun.OssSubmitTarget; |
||||
import com.fr.plugin.file.submit.oss.fun.OssSubmitTargetConfig; |
||||
import com.fr.plugin.file.submit.oss.fun.OssVariableValue; |
||||
import com.fr.plugin.file.submit.oss.job.OssSubmitJob; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.report.worksheet.WorkSheet; |
||||
import com.fr.report.write.ReportWriteAttr; |
||||
import com.fr.report.write.SubmitVisitor; |
||||
import com.fr.report.write.WClassSubmiter; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.util.List; |
||||
|
||||
public class RewritePane extends BasicPane { |
||||
|
||||
|
||||
public RewritePane() { |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
setLayout(new BorderLayout()); |
||||
UIButton button = new UIButton("Start"); |
||||
button.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
rewrite(); |
||||
} |
||||
}); |
||||
add(button, BorderLayout.NORTH); |
||||
} |
||||
|
||||
private void rewrite() { |
||||
new SwingWorker<Void, Integer>() { |
||||
@Override |
||||
protected Void doInBackground() { |
||||
FileNode[] fileNodes = FRContext.getFileNodes().list(ProjectConstants.REPORTLETS_NAME, FileExtension.CPT, true); |
||||
int len = fileNodes.length; |
||||
for (int i = 0; i < len; i++) { |
||||
FileNode fileNode = fileNodes[i]; |
||||
try { |
||||
WorkBook workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(fileNode.getEnvPath().substring(10)); |
||||
int count = workBook.getReportCount(); |
||||
for (int n = 0; n < count; n++) { |
||||
Report report = workBook.getReport(n); |
||||
if (report instanceof WorkSheet) { |
||||
ReportWriteAttr reportWriteAttr = ((WorkSheet) report).getAttributeTarget(ReportWriteAttr.XML_TAG); |
||||
if (reportWriteAttr != null) { |
||||
int submitJobCount = reportWriteAttr.getSubmitVisitorCount(); |
||||
for (int sn = 0; sn < submitJobCount; sn++) { |
||||
SubmitVisitor submitVisitor = reportWriteAttr.getSubmitVisitor(sn); |
||||
if (submitVisitor instanceof WClassSubmiter) { |
||||
SubmitJob job = ((WClassSubmiter) submitVisitor).getSubmitJob(); |
||||
if (job instanceof ServerPathSubmiterJob) { |
||||
((WClassSubmiter) submitVisitor).setSubmitJob(convert2OssJob((ServerPathSubmiterJob) job)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
try { |
||||
Thread.sleep(2000); |
||||
} catch (InterruptedException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
publish(i); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
protected void process(List<Integer> chunks) { |
||||
System.out.println("已经到第" + chunks.get(chunks.size() - 1) + "个模板"); |
||||
|
||||
} |
||||
}.execute(); |
||||
} |
||||
|
||||
private OssSubmitJob convert2OssJob(ServerPathSubmiterJob job) { |
||||
OssSubmitJob ossSubmitJob = new OssSubmitJob(); |
||||
OssSubmitTargetConfig targetConfig = new OssSubmitTargetConfig(); |
||||
ossSubmitJob.setSubmitTargetConfig(targetConfig); |
||||
|
||||
PathConfig pathConfig = job.getPathConfig(); |
||||
if (pathConfig != null) { |
||||
for (ServerPathColumnConfig config : pathConfig.getColumnConfigList()) { |
||||
OssSubmitTarget target = new OssSubmitTarget(); |
||||
targetConfig.addSubmitTarget(target); |
||||
target.setBucket("fanruan-crm"); |
||||
target.setDirectory(new OssVariableValue(config.getPath())); |
||||
target.setFile(new OssVariableValue(config.getCellConfig().toString())); |
||||
target.setName(new OssVariableValue(config.getName())); |
||||
} |
||||
} |
||||
return ossSubmitJob; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return "Transform"; |
||||
} |
||||
} |
||||
//package com.fr.plugin.file.submit.oss.ui.tools;
|
||||
//
|
||||
//import com.fr.base.FRContext;
|
||||
//import com.fr.base.extension.FileExtension;
|
||||
//import com.fr.data.SubmitJob;
|
||||
//import com.fr.design.dialog.BasicPane;
|
||||
//import com.fr.design.gui.ibutton.UIButton;
|
||||
//import com.fr.design.gui.itextarea.UITextArea;
|
||||
//import com.fr.file.filetree.FileNode;
|
||||
//import com.fr.io.TemplateWorkBookIO;
|
||||
//import com.fr.log.FineLoggerFactory;
|
||||
//import com.fr.main.TemplateWorkBook;
|
||||
//import com.fr.main.impl.WorkBook;
|
||||
//import com.fr.plugin.customsubmmit.core.PathConfig;
|
||||
//import com.fr.plugin.customsubmmit.core.ServerPathColumnConfig;
|
||||
//import com.fr.plugin.customsubmmit.report.ServerPathSubmiterJob;
|
||||
//import com.fr.plugin.file.submit.oss.fun.OssSubmitTarget;
|
||||
//import com.fr.plugin.file.submit.oss.fun.OssSubmitTargetConfig;
|
||||
//import com.fr.plugin.file.submit.oss.fun.OssVariableValue;
|
||||
//import com.fr.plugin.file.submit.oss.job.OssSubmitJob;
|
||||
//import com.fr.report.report.Report;
|
||||
//import com.fr.report.worksheet.WorkSheet;
|
||||
//import com.fr.report.write.ReportWriteAttr;
|
||||
//import com.fr.report.write.SubmitVisitor;
|
||||
//import com.fr.report.write.WClassSubmiter;
|
||||
//import com.fr.stable.project.ProjectConstants;
|
||||
//
|
||||
//import javax.swing.*;
|
||||
//import java.awt.*;
|
||||
//import java.awt.event.ActionEvent;
|
||||
//import java.awt.event.ActionListener;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.ExecutionException;
|
||||
//
|
||||
//public class RewritePane extends BasicPane {
|
||||
//
|
||||
// private UITextArea textArea;
|
||||
//
|
||||
// public RewritePane() {
|
||||
// initComponents();
|
||||
// }
|
||||
//
|
||||
// private void initComponents() {
|
||||
// setLayout(new BorderLayout());
|
||||
// UIButton button = new UIButton("Start");
|
||||
// button.addActionListener(new ActionListener() {
|
||||
// @Override
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// rewrite();
|
||||
// }
|
||||
// });
|
||||
// add(button, BorderLayout.NORTH);
|
||||
// textArea = new UITextArea();
|
||||
// add(new JScrollPane(textArea), BorderLayout.CENTER);
|
||||
// }
|
||||
//
|
||||
// private void rewrite() {
|
||||
// new SwingWorker<List<String>, Integer>() {
|
||||
// @Override
|
||||
// protected List<String> doInBackground() {
|
||||
// FileNode[] fileNodes = FRContext.getFileNodes().list(ProjectConstants.REPORTLETS_NAME, FileExtension.CPT, true);
|
||||
// int len = fileNodes.length;
|
||||
// List<String> names = new ArrayList<String>();
|
||||
// for (int i = 0; i < len; i++) {
|
||||
// boolean willSave = false;
|
||||
// FileNode fileNode = fileNodes[i];
|
||||
// try {
|
||||
// String path = fileNode.getEnvPath().substring(10);
|
||||
// WorkBook workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(path);
|
||||
// int count = workBook.getReportCount();
|
||||
// for (int n = 0; n < count; n++) {
|
||||
// Report report = workBook.getReport(n);
|
||||
// if (report instanceof WorkSheet) {
|
||||
// ReportWriteAttr reportWriteAttr = ((WorkSheet) report).getAttributeTarget(ReportWriteAttr.XML_TAG);
|
||||
// if (reportWriteAttr != null) {
|
||||
// int submitJobCount = reportWriteAttr.getSubmitVisitorCount();
|
||||
// for (int sn = 0; sn < submitJobCount; sn++) {
|
||||
// SubmitVisitor submitVisitor = reportWriteAttr.getSubmitVisitor(sn);
|
||||
// if (submitVisitor instanceof WClassSubmiter) {
|
||||
// SubmitJob job = ((WClassSubmiter) submitVisitor).getSubmitJob();
|
||||
// if (job instanceof ServerPathSubmiterJob) {
|
||||
// ((WClassSubmiter) submitVisitor).setSubmitJob(convert2OssJob((ServerPathSubmiterJob) job));
|
||||
// willSave = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (willSave) {
|
||||
// names.add(path);
|
||||
// TemplateWorkBookIO.writeTemplateWorkBook(workBook, path);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// publish(i);
|
||||
// }
|
||||
//
|
||||
// return names;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void process(List<Integer> chunks) {
|
||||
// textArea.append("已经到第" + chunks.get(chunks.size() - 1) + "个模板" + "\n");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void done() {
|
||||
// try {
|
||||
// List<String> paths = get();
|
||||
// for (String text : paths) {
|
||||
// textArea.append("成功修改了模板:" + text + "\n");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
||||
// }
|
||||
// }
|
||||
// }.execute();
|
||||
// }
|
||||
//
|
||||
// private OssSubmitJob convert2OssJob(ServerPathSubmiterJob job) {
|
||||
// OssSubmitJob ossSubmitJob = new OssSubmitJob();
|
||||
// OssSubmitTargetConfig targetConfig = new OssSubmitTargetConfig();
|
||||
// ossSubmitJob.setSubmitTargetConfig(targetConfig);
|
||||
//
|
||||
// PathConfig pathConfig = job.getPathConfig();
|
||||
// if (pathConfig != null) {
|
||||
// for (ServerPathColumnConfig config : pathConfig.getColumnConfigList()) {
|
||||
// OssSubmitTarget target = new OssSubmitTarget();
|
||||
// targetConfig.addSubmitTarget(target);
|
||||
// target.setBucket("fanruan-crm");
|
||||
// target.setDirectory(new OssVariableValue(config.getPath()));
|
||||
// target.setFile(new OssVariableValue(config.getCellConfig().toString()));
|
||||
// target.setName(new OssVariableValue(config.getName()));
|
||||
// }
|
||||
// }
|
||||
// return ossSubmitJob;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected String title4PopupWindow() {
|
||||
// return "Transform";
|
||||
// }
|
||||
//}
|
||||
|
Loading…
Reference in new issue