From 5e3391e2bceeb4ab9e0c64d3cd4bfce6a2c091fe Mon Sep 17 00:00:00 2001 From: VIVIMAN Date: Fri, 22 Apr 2022 16:00:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/insigma/HyToolApplication.java | 6 +- src/main/java/com/insigma/config/AppCfg.java | 24 ++++++++ .../java/com/insigma/service/Database.java | 2 +- .../java/com/insigma/service/Middleware.java | 4 +- .../service/impl/LinuxTongWebKingBase.java | 20 +++---- .../service/impl/WindowsTomcatMysql.java | 58 ++++++++++++------- .../com/insigma/utils/LinuxCommandUtil.java | 1 - .../com/insigma/utils/WinCommandUtil.java | 1 - .../com/insigma/utils/WinServiceTool.java | 12 ++-- src/main/resources/application.properties | 2 + .../resources/static/{32b.bat => 32bit.bat} | 1 + .../resources/static/{64b.bat => 64bit.bat} | 2 +- .../impl/LinuxTongWebKingBaseTest.java | 7 ++- .../service/impl/WindowsTomcatMysqlTest.java | 7 ++- .../com/insigma/utils/WinServiceToolTest.java | 3 +- 15 files changed, 100 insertions(+), 50 deletions(-) rename src/main/resources/static/{32b.bat => 32bit.bat} (99%) rename src/main/resources/static/{64b.bat => 64bit.bat} (98%) diff --git a/src/main/java/com/insigma/HyToolApplication.java b/src/main/java/com/insigma/HyToolApplication.java index 2027096..227e79a 100644 --- a/src/main/java/com/insigma/HyToolApplication.java +++ b/src/main/java/com/insigma/HyToolApplication.java @@ -22,7 +22,8 @@ import java.util.Properties; public class HyToolApplication { public static void main(String[] args) { - + Properties properties=System.getProperties(); + String propertiesValue = properties.getProperty("os.arch"); //读取配置文件的值来选择启动ui try { Properties loadProperties = PropertiesLoaderUtils @@ -35,6 +36,9 @@ public class HyToolApplication { AppCfg.DB = loadProperties.getProperty("hy.db"); AppCfg.MW = loadProperties.getProperty("hy.mw"); AppCfg.HZB = loadProperties.getProperty("hy.hzb"); + AppCfg.CODE = loadProperties.getProperty("hy.code"); + AppCfg.OSArch = loadProperties.getProperty("hy.os-arch"); + AppCfg.is32Bit = AppCfg.OSArch.equals(propertiesValue); AppCfg.BROWSER = loadProperties.getProperty("hy.browser"); SwingUtilities.invokeLater(() -> { diff --git a/src/main/java/com/insigma/config/AppCfg.java b/src/main/java/com/insigma/config/AppCfg.java index ca4bbff..9807500 100644 --- a/src/main/java/com/insigma/config/AppCfg.java +++ b/src/main/java/com/insigma/config/AppCfg.java @@ -7,8 +7,32 @@ package com.insigma.config; * @since 17:21 2022/4/18 */ public class AppCfg { + /** + * 操作系统 架构
x86 + */ + public static String OSArch; + /** + * 操作系统 架构
x86 + */ + public static boolean is32Bit; + /** + * 浏览器服务名 关键字
360se.exe + */ public static String BROWSER; + /** + * 数据库服务名
GWY20_Mysql + */ public static String DB; + /** + * 中间件服务名
GWY20_Tomcat + */ public static String MW; + /** + * 应用 安装目录
D:/hzb2021 + */ public static String HZB; + /** + * 系统环境执行脚本编码格式
GBK + */ + public static String CODE; } diff --git a/src/main/java/com/insigma/service/Database.java b/src/main/java/com/insigma/service/Database.java index e9dc6a8..2f5c95c 100644 --- a/src/main/java/com/insigma/service/Database.java +++ b/src/main/java/com/insigma/service/Database.java @@ -29,7 +29,7 @@ public interface Database { * @param size 设置大小值 * @return */ - default boolean setDbSize(int size) { + default boolean setDbSize(int size) throws Exception { System.out.printf("设置出参数:%d,但是未检测到实现应用调用此方法!", size); return false; } diff --git a/src/main/java/com/insigma/service/Middleware.java b/src/main/java/com/insigma/service/Middleware.java index a465696..0ba83c3 100644 --- a/src/main/java/com/insigma/service/Middleware.java +++ b/src/main/java/com/insigma/service/Middleware.java @@ -16,7 +16,7 @@ public interface Middleware { * 清除 应用 缓存 * @return */ - default boolean cleanMwCache() { + default boolean cleanMwCache() throws Exception { System.out.printf("清除缓存,但是未检测到实现应用调用此方法!"); return false; } @@ -25,7 +25,7 @@ public interface Middleware { * @param size 设置大小值 * @return */ - default boolean setMwSize(int size) { + default boolean setMwSize(int size) throws Exception { System.out.printf("设置应用参数:%d,但是未检测到实现应用调用此方法!", size); return false; } diff --git a/src/main/java/com/insigma/service/impl/LinuxTongWebKingBase.java b/src/main/java/com/insigma/service/impl/LinuxTongWebKingBase.java index 0603d79..3f6b244 100644 --- a/src/main/java/com/insigma/service/impl/LinuxTongWebKingBase.java +++ b/src/main/java/com/insigma/service/impl/LinuxTongWebKingBase.java @@ -32,36 +32,36 @@ public class LinuxTongWebKingBase extends Computer implements Database, Middlewa @Override public boolean rebuildIndex(List index) { - return Database.super.rebuildIndex(index); + return true; } @Override - public boolean setDbSize(int size) { - return Database.super.setDbSize(size); + public boolean setDbSize(int size) throws Exception { + return true; } @Override public boolean cleanDbCache(List sql, List tabColObjs) { - return Database.super.cleanDbCache(sql, tabColObjs); + return true; } @Override public boolean registrationDbService() { - return Database.super.registrationDbService(); + return true; } @Override - public boolean cleanMwCache() { - return Middleware.super.cleanMwCache(); + public boolean cleanMwCache() throws Exception { + return true; } @Override - public boolean setMwSize(int size) { - return Middleware.super.setMwSize(size); + public boolean setMwSize(int size) throws Exception { + return true; } @Override public boolean registrationMwService() { - return Middleware.super.registrationMwService(); + return true; } } diff --git a/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java b/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java index e042ea1..0dea1e9 100644 --- a/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java +++ b/src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java @@ -6,10 +6,7 @@ import com.insigma.entry.IndexObj; import com.insigma.entry.TabColObj; import com.insigma.service.Computer; import com.insigma.service.*; -import com.insigma.utils.DbUtil; -import com.insigma.utils.FileUtil; -import com.insigma.utils.WinCommandUtil; -import com.insigma.utils.ZipUtil; +import com.insigma.utils.*; import lombok.extern.slf4j.Slf4j; import java.sql.SQLException; @@ -38,6 +35,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware @Override public boolean rebuildIndex(List index) { + boolean retBool; log.info("创建链接..."); final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd); try { @@ -45,31 +43,37 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware session.execute("DROP INDEX ? ON ?", idx.getIdx(), idx.getTab()); session.execute("ALTER TABLE ? ADD INDEX ? (?) USING BTREE", idx.getTab(), idx.getIdx(), idx.getCol()); } + retBool = true; } catch (SQLException e) { log.error("执行更新索引发生异常:{}", e.getMessage()); - e.printStackTrace(); session.close(); - return false; + retBool = false; } session.close(); - return true; + return retBool; } @Override - public boolean setDbSize(int size) { + public boolean setDbSize(int size) throws Exception { log.info("停止 数据库 服务..."); - runShell("sc stop " + AppCfg.DB); + WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); + if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ + ws.stopService(); + } + log.info("设置 数据库 内存参数..."); FileUtil.replaceLine(AppCfg.HZB + "/mysql/my.ini", "innodb_buffer_pool_size", String.format("innodb_buffer_pool_size=%dM", size)); + log.info("启动 数据库 服务..."); - runShell("sc start " + AppCfg.DB); - return Database.super.setDbSize(size); + ws.startService(); + return true; } @Override public boolean cleanDbCache(List sql, List tabColObjs) { + boolean retBool; log.info("创建链接..."); final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd); try { @@ -84,26 +88,32 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware tab.getTab(), tab.getCol(), tab.getCol(), lj, tab.getCol()); } } + retBool = true; } catch (SQLException e) { log.error("执行 清洗数据中特殊字符串 发生异常:{}", e.getMessage()); e.printStackTrace(); session.close(); - return false; + retBool = false; } log.info("执行 清洗数据中特殊字符串 完成..."); session.close(); - return true; + return retBool; } @Override public boolean registrationDbService() { + // TODO return true; } @Override - public boolean cleanMwCache() { + public boolean cleanMwCache() throws Exception { log.info("停止 中间件 服务..."); - runShell("sc stop " + AppCfg.MW); + WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); + if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ + ws.stopService(); + } + log.info("退出 浏览器..."); runShell("taskkill /f /im " + AppCfg.BROWSER); @@ -121,24 +131,32 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware FileUtil.delAllFile(AppCfg.HZB + "/tomcat8/logs"); log.info("启动 中间件 服务..."); - runShell("sc start " + AppCfg.MW); + ws.startService(); return true; } @Override - public boolean setMwSize(int size) { + public boolean setMwSize(int size) throws Exception { log.info("停止 中间件 服务..."); - runShell("sc stop " + AppCfg.MW); - + WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); + if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ + ws.stopService(); + } + // TODO log.info("启动 中间件 服务..."); - runShell("sc start " + AppCfg.MW); + ws.startService(); return true; } @Override public boolean registrationMwService() { + if(AppCfg.is32Bit){ + runShell(AppCfg.HZB + "/tomcat8/webapps/qggwy/WEB-INF/classes/static/32bit.bat"); + }else{ + runShell(AppCfg.HZB + "/tomcat8/webapps/qggwy/WEB-INF/classes/static/64bit.bat"); + } return true; } diff --git a/src/main/java/com/insigma/utils/LinuxCommandUtil.java b/src/main/java/com/insigma/utils/LinuxCommandUtil.java index 45bcfca..dce01d4 100644 --- a/src/main/java/com/insigma/utils/LinuxCommandUtil.java +++ b/src/main/java/com/insigma/utils/LinuxCommandUtil.java @@ -37,7 +37,6 @@ public class LinuxCommandUtil implements Runnable { exitVal = process.waitFor(); } catch (IOException | InterruptedException e) { log.error("执行命令发生异常:{}", e.getMessage()); - e.printStackTrace(); } if (exitVal != 0) { diff --git a/src/main/java/com/insigma/utils/WinCommandUtil.java b/src/main/java/com/insigma/utils/WinCommandUtil.java index 97a649c..c5945d0 100644 --- a/src/main/java/com/insigma/utils/WinCommandUtil.java +++ b/src/main/java/com/insigma/utils/WinCommandUtil.java @@ -41,7 +41,6 @@ public class WinCommandUtil implements Runnable { exitVal = process.waitFor(); } catch (IOException | InterruptedException e) { log.error("执行命令发生异常:{}", e.getMessage()); - e.printStackTrace(); } if (exitVal != 0) { diff --git a/src/main/java/com/insigma/utils/WinServiceTool.java b/src/main/java/com/insigma/utils/WinServiceTool.java index 9a64a72..ee3c0ab 100644 --- a/src/main/java/com/insigma/utils/WinServiceTool.java +++ b/src/main/java/com/insigma/utils/WinServiceTool.java @@ -1,8 +1,8 @@ package com.insigma.utils; +import com.alibaba.druid.util.StringUtils; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.thymeleaf.util.StringUtils; import java.io.*; import java.nio.charset.Charset; @@ -132,7 +132,7 @@ public class WinServiceTool { InputStream inputStream = process.getInputStream(); result = convertInputStream2Str(inputStream, Charset.defaultCharset()); } catch (IOException e) { - e.printStackTrace(); + log.error("执行发生异常:{}", e.getMessage()); isExists = false; runningStatus = ServiceState.UNKNOWN; info = null; @@ -197,7 +197,7 @@ public class WinServiceTool { Process exec = Runtime.getRuntime().exec("net start " + serviceName); InputStream errorStream = exec.getErrorStream(); String errMsg = convertInputStream2Str(errorStream, getCharset()); - if (StringUtils.isEmpty(errMsg)) { + if (!StringUtils.isEmpty(errMsg)) { throw new Exception("执行启动服务[" + getServiceName() + "]出错:\n" + errMsg); } runningStatus = ServiceState.RUNNING; @@ -224,19 +224,19 @@ public class WinServiceTool { Process exec = Runtime.getRuntime().exec("net stop " + serviceName); InputStream errorStream = exec.getErrorStream(); String errMsg = convertInputStream2Str(errorStream, getCharset()); - if (StringUtils.isEmpty(errMsg)) { + if (!StringUtils.isEmpty(errMsg)) { throw new Exception("执行停止服务[" + getServiceName() + "]出错:\n" + errMsg); } runningStatus = ServiceState.STOPPED; ret = true; } catch (IOException e) { - e.printStackTrace(); + log.error("执行发生异常:{}", e.getMessage()); } } return ret; } - private enum ServiceState { + public enum ServiceState { /** * 正在运行 */ diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4d08c6c..b41e7f0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -11,4 +11,6 @@ db.pwd=admin hy.db=GWY20_Mysql hy.mw=GWY20_Tomcat hy.hzb=D:/hzb2021 +hy.code=GBK hy.browser=360se.exe +hy.os-arch=x86 diff --git a/src/main/resources/static/32b.bat b/src/main/resources/static/32bit.bat similarity index 99% rename from src/main/resources/static/32b.bat rename to src/main/resources/static/32bit.bat index 746508c..e38a5bb 100644 --- a/src/main/resources/static/32b.bat +++ b/src/main/resources/static/32bit.bat @@ -1,3 +1,4 @@ +%1 mshta vbscript:CreateObject(Shell.Application).ShellExecute(cmd.exe,``"/c %~s0 ::"``,``""``,runas,1)(window.close)&&exit @Echo Off Title 32λ÷עֶðװ· & Color 1A cd %systemroot%\system32 diff --git a/src/main/resources/static/64b.bat b/src/main/resources/static/64bit.bat similarity index 98% rename from src/main/resources/static/64b.bat rename to src/main/resources/static/64bit.bat index 278a424..de0cd5b 100644 --- a/src/main/resources/static/64b.bat +++ b/src/main/resources/static/64bit.bat @@ -1,4 +1,4 @@ - +%1 mshta vbscript:CreateObject(Shell.Application).ShellExecute(cmd.exe,``"/c %~s0 ::"``,``""``,runas,1)(window.close)&&exit @Echo Off Title 32λ÷עֶðװ· & Color 1A cd %systemroot%\system32 diff --git a/src/test/java/com/insigma/service/impl/LinuxTongWebKingBaseTest.java b/src/test/java/com/insigma/service/impl/LinuxTongWebKingBaseTest.java index c463193..76818be 100644 --- a/src/test/java/com/insigma/service/impl/LinuxTongWebKingBaseTest.java +++ b/src/test/java/com/insigma/service/impl/LinuxTongWebKingBaseTest.java @@ -20,6 +20,7 @@ public class LinuxTongWebKingBaseTest { AppCfg.DB = "GWY20_Mysql"; AppCfg.MW = "GWY20_Tomcat"; AppCfg.HZB = "D:/hzb2021"; + AppCfg.CODE = "GBK"; AppCfg.BROWSER = "360se.exe"; } @@ -32,7 +33,7 @@ public class LinuxTongWebKingBaseTest { } @Test - public void setDbSize() { + public void setDbSize() throws Exception { assertTrue(linuxTongWebKingBase.setDbSize(500)); log.info("测试完成!"); } @@ -50,13 +51,13 @@ public class LinuxTongWebKingBaseTest { } @Test - public void cleanMwCache() { + public void cleanMwCache() throws Exception { assertTrue(linuxTongWebKingBase.cleanMwCache()); log.info("测试完成!"); } @Test - public void setMwSize() { + public void setMwSize() throws Exception { assertTrue(linuxTongWebKingBase.setMwSize(500)); log.info("测试完成!"); } diff --git a/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java b/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java index aea6ee5..c3d3eaf 100644 --- a/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java +++ b/src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java @@ -19,6 +19,7 @@ public class WindowsTomcatMysqlTest { AppCfg.DB = "GWY20_Mysql"; AppCfg.MW = "GWY20_Tomcat"; AppCfg.HZB = "D:/hzb2021"; + AppCfg.CODE = "GBK"; AppCfg.BROWSER = "360se.exe"; } @@ -31,7 +32,7 @@ public class WindowsTomcatMysqlTest { } @Test - public void setDbSize() { + public void setDbSize() throws Exception { assertTrue(windowsTomcatMysql.setDbSize(500)); log.info("测试完成!"); } @@ -49,13 +50,13 @@ public class WindowsTomcatMysqlTest { } @Test - public void cleanMwCache() { + public void cleanMwCache() throws Exception { assertTrue(windowsTomcatMysql.cleanMwCache()); log.info("测试完成!"); } @Test - public void setMwSize() { + public void setMwSize() throws Exception { assertTrue(windowsTomcatMysql.setMwSize(500)); log.info("测试完成!"); } diff --git a/src/test/java/com/insigma/utils/WinServiceToolTest.java b/src/test/java/com/insigma/utils/WinServiceToolTest.java index 7ad4bfc..9e8039e 100644 --- a/src/test/java/com/insigma/utils/WinServiceToolTest.java +++ b/src/test/java/com/insigma/utils/WinServiceToolTest.java @@ -16,13 +16,14 @@ public class WinServiceToolTest { AppCfg.DB = "GWY20_Mysql"; AppCfg.MW = "GWY20_Tomcat"; AppCfg.HZB = "D:/hzb2021"; + AppCfg.CODE = "GBK"; AppCfg.BROWSER = "360se.exe"; } @Test public void getService() throws Exception { - WinServiceTool.WindowsService windowsService = WinServiceTool.getService(AppCfg.DB, "GBK"); + WinServiceTool.WindowsService windowsService = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); log.info("停止代码:{}", windowsService); assertTrue(windowsService.stopService()); log.info("启动代码:{}", windowsService);