|
@@ -6,10 +6,7 @@ import com.jjt.common.constant.Constants;
|
|
|
import com.jjt.common.domain.FileDesc;
|
|
|
import com.jjt.common.domain.IndexDO;
|
|
|
import com.jjt.common.enums.SyncType;
|
|
|
-import com.jjt.common.utils.CompressZip;
|
|
|
-import com.jjt.common.utils.FtpUtil;
|
|
|
-import com.jjt.common.utils.LinuxCommand;
|
|
|
-import com.jjt.common.utils.StringUtils;
|
|
|
+import com.jjt.common.utils.*;
|
|
|
import com.jjt.in.service.IInEsService;
|
|
|
import com.jjt.in.service.IInProcessService;
|
|
|
import com.jjt.system.service.ISysConfigService;
|
|
@@ -39,7 +36,7 @@ import java.util.Comparator;
|
|
|
* @date 2023-06-06
|
|
|
*/
|
|
|
@Service
|
|
|
-public class InProcessServiceImpl implements IInProcessService {
|
|
|
+public class InProcessServiceImpl extends InBaseService implements IInProcessService {
|
|
|
private static final Logger log = LoggerFactory.getLogger(InProcessServiceImpl.class);
|
|
|
@Resource
|
|
|
private ISysConfigService sysConfigService;
|
|
@@ -52,7 +49,7 @@ public class InProcessServiceImpl implements IInProcessService {
|
|
|
@Override
|
|
|
public void downloadFtpFile() {
|
|
|
String fgapInfo = sysConfigService.selectConfigByKey("in.fgap.info");
|
|
|
- String syncDir = sysConfigService.selectConfigByKey("in.dir.sync");
|
|
|
+ String syncDir = syncDIr();
|
|
|
FtpUtil ftpUtil = JSONObject.parseObject(fgapInfo, FtpUtil.class);
|
|
|
ftpUtil.download(syncDir);
|
|
|
}
|
|
@@ -71,22 +68,11 @@ public class InProcessServiceImpl implements IInProcessService {
|
|
|
@Override
|
|
|
public void unzip() {
|
|
|
//获取内网同步正式目录
|
|
|
- String syncDir = sysConfigService.selectConfigByKey("in.dir.sync");
|
|
|
- String tmpDir = sysConfigService.selectConfigByKey("in.dir.tmp");
|
|
|
- if (!syncDir.endsWith(Constants.DIR_END)) {
|
|
|
- syncDir += "/";
|
|
|
- }
|
|
|
- if (!tmpDir.endsWith(Constants.DIR_END)) {
|
|
|
- tmpDir += "/";
|
|
|
- }
|
|
|
-
|
|
|
+ String syncDir = syncDIr();
|
|
|
+ //获取内网临时目录
|
|
|
+ String tmpDir = tmpDIr();
|
|
|
//获取内网同步备份目录
|
|
|
- String bakDir = sysConfigService.selectConfigByKey("in.dir.bak");
|
|
|
- if (!bakDir.endsWith(Constants.DIR_END)) {
|
|
|
- bakDir += "/";
|
|
|
- }
|
|
|
- File bak = new File(bakDir);
|
|
|
- bak.mkdirs();
|
|
|
+ String bakDir = bakDir();
|
|
|
|
|
|
try {
|
|
|
// 创建File对象
|
|
@@ -113,52 +99,21 @@ public class InProcessServiceImpl implements IInProcessService {
|
|
|
String esDir = tmpDir + "es/" + desc.getName().split("\\.")[0].split("-")[2];
|
|
|
esService.parseSyncFile(esDir);
|
|
|
break;
|
|
|
+ case mysql:
|
|
|
+ handleMysqlType(zipFile);
|
|
|
case shell:
|
|
|
- String shellDir = desc.getTarget();
|
|
|
- if (StringUtils.isBlank(shellDir)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (!shellDir.endsWith(Constants.DIR_END)) {
|
|
|
- shellDir += "/";
|
|
|
- }
|
|
|
- File sd = new File(shellDir);
|
|
|
- sd.mkdirs();
|
|
|
- //复制文件到目标目录
|
|
|
- Files.copy(zipFile.toPath(), Paths.get(shellDir + zipFile.getName()));
|
|
|
- //给文件赋执行权限
|
|
|
- String dataCmd = "chmod +x " + shellDir + zipFile.getName();
|
|
|
- LinuxCommand.exec(dataCmd);
|
|
|
+ handleShellType(desc.getTarget(), zipFile);
|
|
|
break;
|
|
|
case php:
|
|
|
- String phpDir = desc.getTarget();
|
|
|
- if (StringUtils.isBlank(phpDir)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (!phpDir.endsWith(Constants.DIR_END)) {
|
|
|
- phpDir += "/";
|
|
|
- }
|
|
|
- File phpFile = new File(phpDir);
|
|
|
- phpFile.mkdirs();
|
|
|
- //解压文件到目标目录
|
|
|
- CompressZip.unzip(zipFile, phpFile);
|
|
|
+ handlePhpType(desc.getTarget(), zipFile);
|
|
|
+ break;
|
|
|
case mongo:
|
|
|
case other:
|
|
|
- String otherDir = desc.getTarget();
|
|
|
- if (StringUtils.isBlank(otherDir)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (!otherDir.endsWith(Constants.DIR_END)) {
|
|
|
- otherDir += "/";
|
|
|
- }
|
|
|
- File od = new File(otherDir);
|
|
|
- od.mkdirs();
|
|
|
- //复制文件到目标目录,如果存在则覆盖
|
|
|
- Files.copy(zipFile.toPath(), Paths.get(otherDir + zipFile.getName()), StandardCopyOption.REPLACE_EXISTING);
|
|
|
- case mysql:
|
|
|
+ handleOtherType(desc.getTarget(), zipFile);
|
|
|
+ break;
|
|
|
case crontab:
|
|
|
- String cronCmd = "crontab " + zipFile.getPath();
|
|
|
- log.info("添加crontab", cronCmd);
|
|
|
- LinuxCommand.exec(cronCmd);
|
|
|
+ handleCrontabType(zipFile);
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -189,4 +144,70 @@ public class InProcessServiceImpl implements IInProcessService {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private void handleShellType(String shellDir, File zipFile) throws IOException {
|
|
|
+ if (StringUtils.isBlank(shellDir)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!shellDir.endsWith(Constants.DIR_END)) {
|
|
|
+ shellDir += "/";
|
|
|
+ }
|
|
|
+ File sd = new File(shellDir);
|
|
|
+ sd.mkdirs();
|
|
|
+ // 复制文件到目标目录
|
|
|
+ Files.copy(zipFile.toPath(), Paths.get(shellDir + zipFile.getName()));
|
|
|
+ // 给文件赋执行权限
|
|
|
+ String dataCmd = "chmod +x " + shellDir + zipFile.getName();
|
|
|
+ LinuxCommand.exec(dataCmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleMysqlType(File zipFile) throws IOException {
|
|
|
+ String params = sysConfigService.selectConfigByKey("in.mysql.info");
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(params);
|
|
|
+
|
|
|
+ String hostname = jsonObject.getString("host");
|
|
|
+ int port = jsonObject.getIntValue("port");
|
|
|
+
|
|
|
+ String user = jsonObject.getString("user");
|
|
|
+ String pass = jsonObject.getString("pass");
|
|
|
+ String db = jsonObject.getString("db");
|
|
|
+ //组装导入命令
|
|
|
+ String cmd = String.format("mysql -u%s -p%s %s < %s", user, pass, db, zipFile.getPath());
|
|
|
+ LinuxCommand.exec(cmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handlePhpType(String phpDir, File zipFile) throws IOException {
|
|
|
+ if (StringUtils.isBlank(phpDir)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!phpDir.endsWith(Constants.DIR_END)) {
|
|
|
+ phpDir += "/";
|
|
|
+ }
|
|
|
+ File phpFile = new File(phpDir);
|
|
|
+ phpFile.mkdirs();
|
|
|
+ // 解压文件到目标目录
|
|
|
+ CompressZip.unzip(zipFile, phpFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleOtherType(String otherDir, File zipFile) throws IOException {
|
|
|
+ if (StringUtils.isBlank(otherDir)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!otherDir.endsWith(Constants.DIR_END)) {
|
|
|
+ otherDir += "/";
|
|
|
+ }
|
|
|
+ File od = new File(otherDir);
|
|
|
+ od.mkdirs();
|
|
|
+
|
|
|
+ // 复制文件到目标目录,如果存在则覆盖
|
|
|
+ Files.copy(zipFile.toPath(), Paths.get(otherDir + zipFile.getName()), StandardCopyOption.REPLACE_EXISTING);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleCrontabType(File zipFile) {
|
|
|
+ String cronCmd = "crontab " + zipFile.getPath();
|
|
|
+ log.info("添加crontab", cronCmd);
|
|
|
+ LinuxCommand.exec(cronCmd);
|
|
|
+ }
|
|
|
}
|