|
@ -1,7 +1,9 @@ |
|
|
package com.insigma.service.impl; |
|
|
package com.insigma.service.impl; |
|
|
|
|
|
|
|
|
import cn.hutool.db.Session; |
|
|
import cn.hutool.db.Session; |
|
|
|
|
|
import com.insigma.command.LocalCommandExecutor; |
|
|
import com.insigma.config.AppCfg; |
|
|
import com.insigma.config.AppCfg; |
|
|
|
|
|
import com.insigma.entry.ExecuteResult; |
|
|
import com.insigma.entry.IndexObj; |
|
|
import com.insigma.entry.IndexObj; |
|
|
import com.insigma.entry.TabColObj; |
|
|
import com.insigma.entry.TabColObj; |
|
|
import com.insigma.func.ThrowingConsumer; |
|
|
import com.insigma.func.ThrowingConsumer; |
|
@ -9,7 +11,10 @@ import com.insigma.service.Computer; |
|
|
import com.insigma.service.*; |
|
|
import com.insigma.service.*; |
|
|
import com.insigma.utils.*; |
|
|
import com.insigma.utils.*; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
import org.thymeleaf.util.StringUtils; |
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.sql.SQLException; |
|
|
import java.sql.SQLException; |
|
@ -28,16 +33,21 @@ import java.util.List; |
|
|
@Service |
|
|
@Service |
|
|
public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private LocalCommandExecutor localCommandExecutor; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean runShell(String shell) { |
|
|
public boolean runShell(String shell, boolean isWinCommandUtil) { |
|
|
log.info("准备执行>> shell命令..."); |
|
|
if(isWinCommandUtil){ |
|
|
try { |
|
|
|
|
|
new WinCommandUtil(shell).run(); |
|
|
new WinCommandUtil(shell).run(); |
|
|
}catch (Exception e){ |
|
|
log.info("执行完毕。"); |
|
|
log.error("执行发生异常:{}", e.getMessage()); |
|
|
return true; |
|
|
return false; |
|
|
}else{ |
|
|
|
|
|
log.info("准备执行>> shell命令..."); |
|
|
|
|
|
ExecuteResult executeResult = localCommandExecutor.executeCommand(shell, 6000); |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
|
|
|
return executeResult.getExitCode() == 0; |
|
|
} |
|
|
} |
|
|
return true; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -80,6 +90,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
} else { |
|
|
} else { |
|
|
retBool = false; |
|
|
retBool = false; |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return retBool; |
|
|
return retBool; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -139,6 +150,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
log.error("判断文件:{}...不存在,请检查!", filePath); |
|
|
log.error("判断文件:{}...不存在,请检查!", filePath); |
|
|
retBool = false; |
|
|
retBool = false; |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return retBool; |
|
|
return retBool; |
|
|
} |
|
|
} |
|
|
private boolean canNotRun(WinServiceTool.WindowsService ws, |
|
|
private boolean canNotRun(WinServiceTool.WindowsService ws, |
|
@ -151,6 +163,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
log.error("执行发生异常:{}", e.getMessage()); |
|
|
log.error("执行发生异常:{}", e.getMessage()); |
|
|
canRun = false; |
|
|
canRun = false; |
|
|
} |
|
|
} |
|
|
|
|
|
log.debug("执行更新 {} 服务状态:{}", ws.getInfo(), canRun); |
|
|
return !canRun; |
|
|
return !canRun; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -169,6 +182,8 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
sql = String.format("DROP INDEX %s ON %s", idx.getIdx(), idx.getTab()); |
|
|
sql = String.format("DROP INDEX %s ON %s", idx.getIdx(), idx.getTab()); |
|
|
log.debug(sql); |
|
|
log.debug(sql); |
|
|
session.execute(sql); |
|
|
session.execute(sql); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("发生错误索引:{}", e.getMessage()); |
|
|
}finally { |
|
|
}finally { |
|
|
sql = String.format("ALTER TABLE %s ADD INDEX %s (%s) USING BTREE", idx.getTab(), idx.getIdx(), idx.getCol()); |
|
|
sql = String.format("ALTER TABLE %s ADD INDEX %s (%s) USING BTREE", idx.getTab(), idx.getIdx(), idx.getCol()); |
|
|
log.debug(sql); |
|
|
log.debug(sql); |
|
@ -183,6 +198,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
} |
|
|
} |
|
|
session.close(); |
|
|
session.close(); |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return retBool; |
|
|
return retBool; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -216,6 +232,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -228,21 +245,25 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
log.info("创建链接..."); |
|
|
log.info("创建链接..."); |
|
|
final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd, DbUtil.drive); |
|
|
final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd, DbUtil.drive); |
|
|
try { |
|
|
try { |
|
|
log.info("执行 预置 SQL 脚本..."); |
|
|
if(!CollectionUtils.isEmpty(sqls)){ |
|
|
for (String sql : sqls) { |
|
|
log.info("执行 预置 SQL 脚本..."); |
|
|
log.debug(sql); |
|
|
for (String sql : sqls) { |
|
|
session.execute(sql); |
|
|
|
|
|
} |
|
|
|
|
|
log.info("执行 清洗数据中特殊字符串 脚本..."); |
|
|
|
|
|
String sql; |
|
|
|
|
|
for (String lj : DbUtil.RUBBISH) { |
|
|
|
|
|
for (TabColObj tab : tabColObjs) { |
|
|
|
|
|
sql = String.format("update %s set %s=replace(%s, '%s', '') where %s is not null", |
|
|
|
|
|
tab.getTab(), tab.getCol(), tab.getCol(), lj, tab.getCol()); |
|
|
|
|
|
log.debug(sql); |
|
|
log.debug(sql); |
|
|
session.execute(sql); |
|
|
session.execute(sql); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if(!CollectionUtils.isEmpty(tabColObjs)){ |
|
|
|
|
|
log.info("执行 清洗数据中特殊字符串 脚本..."); |
|
|
|
|
|
String sql; |
|
|
|
|
|
for (String lj : DbUtil.RUBBISH) { |
|
|
|
|
|
for (TabColObj tab : tabColObjs) { |
|
|
|
|
|
sql = String.format("update %s set %s=replace(%s, '%s', '') where %s is not null", |
|
|
|
|
|
tab.getTab(), tab.getCol(), tab.getCol(), lj, tab.getCol()); |
|
|
|
|
|
log.debug(sql); |
|
|
|
|
|
session.execute(sql); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
retBool = true; |
|
|
retBool = true; |
|
|
} catch (SQLException e) { |
|
|
} catch (SQLException e) { |
|
|
log.error("执行 清洗数据中特殊字符串 发生异常:{}", e.getMessage()); |
|
|
log.error("执行 清洗数据中特殊字符串 发生异常:{}", e.getMessage()); |
|
@ -253,6 +274,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
log.info("执行 清洗数据中特殊字符串 完成..."); |
|
|
log.info("执行 清洗数据中特殊字符串 完成..."); |
|
|
session.close(); |
|
|
session.close(); |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return retBool; |
|
|
return retBool; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -275,6 +297,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
String.format("%s\\mysql\\bin\\mysqld --defaults-file=%s\\mysql\\my.ini %s", AppCfg.HZB, AppCfg.HZB, AppCfg.DB))){ |
|
|
String.format("%s\\mysql\\bin\\mysqld --defaults-file=%s\\mysql\\my.ini %s", AppCfg.HZB, AppCfg.HZB, AppCfg.DB))){ |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -283,13 +306,11 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
log.info("准备执行>> 清楚应用缓存命令..."); |
|
|
log.info("准备执行>> 清楚应用缓存命令..."); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { |
|
|
stopMwService(); |
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.info("退出 浏览器..."); |
|
|
log.info("退出 浏览器..."); |
|
|
runShell("taskkill /f /im " + AppCfg.BROWSER); |
|
|
runShell("taskkill /f /im " + AppCfg.BROWSER, false); |
|
|
|
|
|
|
|
|
log.info("删除 浏览器 历史文件..."); |
|
|
log.info("删除 浏览器 历史文件..."); |
|
|
FileUtil.delAllFile(AppCfg.HZB + "/360se6/User Data"); |
|
|
FileUtil.delAllFile(AppCfg.HZB + "/360se6/User Data"); |
|
@ -308,6 +329,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -327,9 +349,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
log.info("停止 中间件 服务..."); |
|
|
log.info("停止 中间件 服务..."); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { |
|
|
stopMwService(); |
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(WinCommandUtil.RegisterUtil.registerJava(AppCfg.HZB, size[0], size[1], size[2], size[3])){ |
|
|
if(WinCommandUtil.RegisterUtil.registerJava(AppCfg.HZB, size[0], size[1], size[2], size[3])){ |
|
@ -340,6 +360,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -380,6 +401,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
AppCfg.HZB)){ |
|
|
AppCfg.HZB)){ |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -397,6 +419,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -409,6 +432,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -420,27 +444,29 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware { |
|
|
return !canNotRun(ws, WinServiceTool.WindowsService::startService); |
|
|
return !canNotRun(ws, WinServiceTool.WindowsService::startService); |
|
|
} |
|
|
} |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
return !canNotRun(ws, WinServiceTool.WindowsService::restartService); |
|
|
stopMwService(); |
|
|
|
|
|
log.info("已停止应用服务..."); |
|
|
|
|
|
return startMwService(); |
|
|
} |
|
|
} |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean stopMwService() { |
|
|
public boolean stopMwService() { |
|
|
log.info("准备执行>> 停止应用服务命令..."); |
|
|
log.info("准备执行>> 停止应用服务命令..."); |
|
|
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); |
|
|
String port = localCommandExecutor.getPort("netstat -ano", "54022", 6000); |
|
|
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ |
|
|
if(StringUtils.isEmpty(port)){ |
|
|
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
return false; |
|
|
log.info("执行完毕。"); |
|
|
|
|
|
return runShell("taskkill /F /PID " + port, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void openServer(){ |
|
|
public void openServer(){ |
|
|
log.info("准备执行>> 打开本地服务命令..."); |
|
|
log.info("准备执行>> 打开本地服务命令..."); |
|
|
runShell("SERVICES.MSC"); |
|
|
new WinCommandUtil("SERVICES.MSC").run(); |
|
|
|
|
|
log.info("执行完毕。"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|