You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.8 KiB
79 lines
2.8 KiB
4 years ago
|
package com.fr.plugin.demo.data.transfer;
|
||
|
|
||
|
import com.fanruan.api.log.LogKit;
|
||
|
import com.fanruan.api.runtime.ResourceKit;
|
||
|
import com.fanruan.api.util.GeneralKit;
|
||
|
import com.fr.decision.fun.impl.AbstractDataTransferProcessProvider;
|
||
|
import com.fr.intelli.record.Focus;
|
||
|
import com.fr.intelli.record.Original;
|
||
|
import com.fr.record.analyzer.EnableMetrics;
|
||
|
import com.fr.third.fasterxml.jackson.databind.ObjectMapper;
|
||
|
|
||
|
import java.io.ByteArrayOutputStream;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.Map;
|
||
|
import java.util.Set;
|
||
|
|
||
|
/**
|
||
|
* @author lidongy
|
||
|
* @version 10.0
|
||
|
* Created by lidongy on 2021/3/31
|
||
|
*/
|
||
|
@EnableMetrics
|
||
|
public class DemoTransferProcess extends AbstractDataTransferProcessProvider {
|
||
|
private static final String EXPORT_TEMP_DIR = "export_temp_dir";
|
||
|
private static final String IMPORT_TEMP_DIR = "import_temp_dir";
|
||
|
|
||
|
@Override
|
||
|
@Focus(id = "com.fr.plugin.demo.data.transfer.process", text = "", source = Original.PLUGIN)
|
||
|
public void afterBuildExportData(Map<Integer, Set<String>> allResource) {
|
||
|
printAllResource(allResource);
|
||
|
ResourceKit.write(GeneralKit.pathJoin(EXPORT_TEMP_DIR, "extra.txt"), "resource");
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void afterImport(Map<Integer, Set<String>> allResource) {
|
||
|
printAllResource(allResource);
|
||
|
ByteArrayOutputStream outputStream = null;
|
||
|
InputStream inputStream = null;
|
||
|
try {
|
||
|
inputStream = ResourceKit.read(GeneralKit.pathJoin(IMPORT_TEMP_DIR, EXPORT_TEMP_DIR, "extra.txt"));
|
||
|
outputStream = new ByteArrayOutputStream();
|
||
|
byte[] buffer = new byte[1024];
|
||
|
int len = -1;
|
||
|
while ((len = inputStream.read(buffer)) != -1) {
|
||
|
outputStream.write(buffer, 0, len);
|
||
|
}
|
||
|
} catch (IOException e) {
|
||
|
LogKit.error(e, e.getMessage());
|
||
|
} finally {
|
||
|
try {
|
||
|
if (outputStream != null) {
|
||
|
outputStream.close();
|
||
|
}
|
||
|
if (inputStream != null) {
|
||
|
inputStream.close();
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
LogKit.error(e, e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
LogKit.info("读到了资源为" + outputStream.toString());
|
||
|
}
|
||
|
|
||
|
private void printAllResource(Map<Integer, Set<String>> allResource) {
|
||
|
try {
|
||
|
Iterator<Map.Entry<Integer, Set<String>>> it = allResource.entrySet().iterator();
|
||
|
while (it.hasNext()) {
|
||
|
Map.Entry<Integer, Set<String>> entry = it.next();
|
||
|
LogKit.info("导出数据类型:" + entry.getKey());
|
||
|
LogKit.info("id集合:" + new ObjectMapper().writeValueAsString(entry.getValue()));
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
LogKit.error(e, e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
}
|