|
@@ -5,8 +5,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.jjt.common.constant.Constants;
|
|
import com.jjt.common.constant.Constants;
|
|
import com.jjt.common.domain.FileDesc;
|
|
import com.jjt.common.domain.FileDesc;
|
|
import com.jjt.common.utils.*;
|
|
import com.jjt.common.utils.*;
|
|
|
|
+import com.jjt.in.domain.InSyncInfo;
|
|
import com.jjt.in.service.IInEsService;
|
|
import com.jjt.in.service.IInEsService;
|
|
|
|
+import com.jjt.in.service.IInMongoService;
|
|
import com.jjt.in.service.IInProcessService;
|
|
import com.jjt.in.service.IInProcessService;
|
|
|
|
+import com.jjt.in.service.IInSyncInfoService;
|
|
import com.jjt.system.service.ISysConfigService;
|
|
import com.jjt.system.service.ISysConfigService;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -19,10 +22,7 @@ import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.StandardCopyOption;
|
|
import java.nio.file.StandardCopyOption;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.Comparator;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 数据同步Service业务层处理
|
|
* 数据同步Service业务层处理
|
|
@@ -37,6 +37,10 @@ public class InProcessServiceImpl extends InBaseService implements IInProcessSer
|
|
private ISysConfigService sysConfigService;
|
|
private ISysConfigService sysConfigService;
|
|
@Resource
|
|
@Resource
|
|
private IInEsService esService;
|
|
private IInEsService esService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IInMongoService mongoService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IInSyncInfoService syncInfoService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 从光闸FTP下载文件
|
|
* 从光闸FTP下载文件
|
|
@@ -82,47 +86,70 @@ public class InProcessServiceImpl extends InBaseService implements IInProcessSer
|
|
for (File file : files) {
|
|
for (File file : files) {
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
FileDesc desc = mapper.readValue(file, FileDesc.class);
|
|
FileDesc desc = mapper.readValue(file, FileDesc.class);
|
|
|
|
+ //写入同步记录表
|
|
|
|
+ InSyncInfo syncInfo = new InSyncInfo();
|
|
|
|
|
|
|
|
+ syncInfo.setSyncType(desc.getType().toString());
|
|
|
|
+ syncInfo.setSyncFileName(desc.getName());
|
|
File zipFile = new File(syncDir + desc.getName());
|
|
File zipFile = new File(syncDir + desc.getName());
|
|
String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.toPath()));
|
|
String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.toPath()));
|
|
|
|
+ syncInfo.setSyncFileMd5(md5);
|
|
|
|
+ syncInfo.setSyncFileSize(zipFile.length());
|
|
|
|
+ Date st = new Date();
|
|
|
|
+ syncInfo.setCreateTime(st);
|
|
if (md5.equals(desc.getMd5())) {
|
|
if (md5.equals(desc.getMd5())) {
|
|
- System.err.println("这个是正确的" + desc.toString());
|
|
|
|
- switch (desc.getType()) {
|
|
|
|
- case crontab:
|
|
|
|
- handleCrontabType(zipFile);
|
|
|
|
- break;
|
|
|
|
- case es:
|
|
|
|
- File targetDir = new File(tmpDir + "es/");
|
|
|
|
- CompressZip.unzip(zipFile, targetDir);
|
|
|
|
- String esDir = tmpDir + "es/" + desc.getName().split("\\.")[0].split("-")[2];
|
|
|
|
- esService.parseSyncFile(esDir);
|
|
|
|
- break;
|
|
|
|
- case mongo:
|
|
|
|
- case mysql:
|
|
|
|
- handleMysqlType(zipFile);
|
|
|
|
- break;
|
|
|
|
- case other:
|
|
|
|
- handleOtherType(desc.getTarget(), zipFile);
|
|
|
|
- break;
|
|
|
|
- case php:
|
|
|
|
- handlePhpType(desc.getTarget(), zipFile);
|
|
|
|
- break;
|
|
|
|
- case shell:
|
|
|
|
- handleShellType(desc.getTarget(), zipFile);
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
|
|
+ syncInfo.setSyncValid("Y");
|
|
|
|
+ try {
|
|
|
|
+ switch (desc.getType()) {
|
|
|
|
+ case crontab:
|
|
|
|
+ handleCrontabType(zipFile);
|
|
|
|
+ break;
|
|
|
|
+ case es:
|
|
|
|
+ File targetDir = new File(tmpDir + "es/");
|
|
|
|
+ CompressZip.unzip(zipFile, targetDir);
|
|
|
|
+ String esDir = tmpDir + "es/" + desc.getName().split("\\.")[0].split("-")[2];
|
|
|
|
+ esService.parseSyncFile(esDir);
|
|
|
|
+ break;
|
|
|
|
+ case mongo:
|
|
|
|
+ File mongoTargetDir = new File(tmpDir + "mongo/");
|
|
|
|
+ CompressZip.unzip(zipFile, mongoTargetDir);
|
|
|
|
+ String mongoDir = tmpDir + "mongo/" + desc.getName().split("\\.")[0].split("-")[2];
|
|
|
|
+ mongoService.parseSyncFile(mongoDir);
|
|
|
|
+ break;
|
|
|
|
+ case mysql:
|
|
|
|
+ handleMysqlType(zipFile);
|
|
|
|
+ break;
|
|
|
|
+ case other:
|
|
|
|
+ handleOtherType(desc.getTarget(), zipFile);
|
|
|
|
+ break;
|
|
|
|
+ case php:
|
|
|
|
+ handlePhpType(desc.getTarget(), zipFile);
|
|
|
|
+ break;
|
|
|
|
+ case shell:
|
|
|
|
+ handleShellType(desc.getTarget(), zipFile);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ syncInfo.setIsSucess("Y");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ syncInfo.setIsSucess("N");
|
|
|
|
+ syncInfo.setLogMsg(e.getMessage());
|
|
}
|
|
}
|
|
//移动文件到备份目录
|
|
//移动文件到备份目录
|
|
Files.move(file.toPath(), Paths.get(bakDir + file.getName()), StandardCopyOption.REPLACE_EXISTING);
|
|
Files.move(file.toPath(), Paths.get(bakDir + file.getName()), StandardCopyOption.REPLACE_EXISTING);
|
|
Files.move(zipFile.toPath(), Paths.get(bakDir + zipFile.getName()), StandardCopyOption.REPLACE_EXISTING);
|
|
Files.move(zipFile.toPath(), Paths.get(bakDir + zipFile.getName()), StandardCopyOption.REPLACE_EXISTING);
|
|
} else {
|
|
} else {
|
|
- System.err.println("这个是错误滴" + desc.toString());
|
|
|
|
|
|
+ syncInfo.setSyncValid("N");
|
|
|
|
+ syncInfo.setIsSucess("N");
|
|
}
|
|
}
|
|
|
|
+ Date et = new Date();
|
|
|
|
+ syncInfo.setCostTime(et.getTime() - st.getTime());
|
|
|
|
+ syncInfoService.insertInSyncInfo(syncInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("处理es出错啦:", e.getMessage());
|
|
|
|
|
|
+ log.error("同步处理出错啦:{}", e.getMessage());
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|