Browse Source

增加代码控制设置

master
VIVIMAN 3 years ago
parent
commit
ab3ae4bf2b
  1. 2
      .gitignore
  2. 1
      pom.xml
  3. 5
      run.bat
  4. 49
      src/main/java/com/insigma/HyToolApplication.java
  5. 4
      src/main/java/com/insigma/config/AppCfg.java
  6. 31
      src/main/java/com/insigma/config/SpringContextUtil.java
  7. 27
      src/main/java/com/insigma/service/Computer.java
  8. 2
      src/main/java/com/insigma/service/Database.java
  9. 11
      src/main/java/com/insigma/service/impl/LinuxTongWebKingBase.java
  10. 21
      src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java
  11. 103
      src/main/java/com/insigma/ui/SwingFrame.java
  12. 47
      src/main/java/com/insigma/ui/Test.java
  13. 1
      src/main/resources/application.properties
  14. 2
      src/main/resources/run.bat
  15. 2
      src/test/java/com/insigma/service/impl/LinuxTongWebKingBaseTest.java
  16. 22
      src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java

2
.gitignore

@ -36,3 +36,5 @@ build/
.vscode/ .vscode/
/out/artifacts/java_tool_jar/java_tool.jar /out/artifacts/java_tool_jar/java_tool.jar
/java_tool.jar /java_tool.jar
/hy-tool-0.0.1-SNAPSHOT.jar
/*.log

1
pom.xml

@ -177,6 +177,7 @@
</execution> </execution>
</executions> </executions>
<configuration> <configuration>
<mainClass>com.insigma.HyToolApplication</mainClass>
<includeSystemScope>true</includeSystemScope> <includeSystemScope>true</includeSystemScope>
<excludes> <excludes>
<exclude> <exclude>

5
run.bat

@ -1,7 +1,6 @@
call :IsAdmin call :IsAdmin
:: 输出到日志 > bakup_%date:~0,4%%date:~5,2%%date:~8,2%.log
java -jar java_tool.jar mvn clean package -Dmaven.test.skip=true & cd target & copy /Y "hy-tool-0.0.1-SNAPSHOT.jar" "../hy-tool-0.0.1-SNAPSHOT.jar" & cd ../ & java -jar hy-tool-0.0.1-SNAPSHOT.jar
:IsAdmin :IsAdmin
Reg.exe query "HKU\S-1-5-19\Environment" Reg.exe query "HKU\S-1-5-19\Environment"
If Not %ERRORLEVEL% EQU 0 ( If Not %ERRORLEVEL% EQU 0 (

49
src/main/java/com/insigma/HyToolApplication.java

@ -1,14 +1,21 @@
package com.insigma; package com.insigma;
import com.insigma.config.AppCfg; import com.insigma.config.AppCfg;
import com.insigma.config.SpringContextUtil;
import com.insigma.service.Computer;
import com.insigma.service.Database;
import com.insigma.service.Middleware;
import com.insigma.ui.SwingFrame; import com.insigma.ui.SwingFrame;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.EncodedResource; import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.thymeleaf.util.StringUtils;
import java.io.IOException;
import java.util.Properties; import java.util.Properties;
/** /**
@ -19,10 +26,34 @@ import java.util.Properties;
public class HyToolApplication { public class HyToolApplication {
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("java.awt.headless", "false");
Properties properties=System.getProperties(); Properties properties=System.getProperties();
String propertiesValue = properties.getProperty("os.arch"); String propertiesValue = properties.getProperty("os.arch");
//读取配置文件的值来选择启动ui
try { try {
// 设置基础变量参数
HyToolApplication.setPropertiesInfo(propertiesValue);
// 启动 spring
SpringApplication.run(HyToolApplication.class, args);
// SwingUtilities.invokeLater(() -> {
// log.info("正在启动GUI =======================>>> 成功!");
// SwingSet2.main(args);
// });
} catch (Exception e) {
log.error("\n\t 启动GUI异常 >>>>>>>>>>>{},{}",e.getMessage(),e);
e.printStackTrace();
} finally {
if(!StringUtils.isEmpty(AppCfg.BEAN)){
Computer computer = SpringContextUtil.getBean(AppCfg.BEAN);
Database database = SpringContextUtil.getBean(AppCfg.BEAN);
Middleware middleware = SpringContextUtil.getBean(AppCfg.BEAN);
SwingFrame.run(computer, database, middleware);
}
}
}
private static void setPropertiesInfo(String propertiesValue) throws IOException {
Properties loadProperties = PropertiesLoaderUtils Properties loadProperties = PropertiesLoaderUtils
.loadProperties(new EncodedResource(new ClassPathResource("application.properties"), "UTF-8")); .loadProperties(new EncodedResource(new ClassPathResource("application.properties"), "UTF-8"));
@ -34,25 +65,13 @@ public class HyToolApplication {
AppCfg.DB = loadProperties.getProperty("hy.db"); AppCfg.DB = loadProperties.getProperty("hy.db");
AppCfg.MW = loadProperties.getProperty("hy.mw"); AppCfg.MW = loadProperties.getProperty("hy.mw");
AppCfg.HZB = loadProperties.getProperty("hy.hzb"); AppCfg.HZB = loadProperties.getProperty("hy.hzb");
AppCfg.BEAN = loadProperties.getProperty("hy.bean");
AppCfg.CODE = loadProperties.getProperty("hy.code"); AppCfg.CODE = loadProperties.getProperty("hy.code");
AppCfg.OSArch = loadProperties.getProperty("hy.os-arch"); AppCfg.OSArch = loadProperties.getProperty("hy.os-arch");
AppCfg.is32Bit = AppCfg.OSArch.equals(propertiesValue); AppCfg.is32Bit = AppCfg.OSArch.equals(propertiesValue);
AppCfg.BROWSER = loadProperties.getProperty("hy.browser"); AppCfg.BROWSER = loadProperties.getProperty("hy.browser");
// SwingUtilities.invokeLater(() -> {
// log.info("正在启动GUI =======================>>> 成功!");
// SwingSet2.main(args);
// });
SwingFrame.run();
log.info("获取参数1:{}, {}, {}, {}", url, usr, pwd, drive); log.info("获取参数1:{}, {}, {}, {}", url, usr, pwd, drive);
log.info("获取参数2:{}, {}, {}", AppCfg.DB, AppCfg.MW, AppCfg.HZB); log.info("获取参数2:{}, {}, {}, {}", AppCfg.DB, AppCfg.MW, AppCfg.HZB, AppCfg.BEAN);
log.info("获取参数3:{}, {}, {}, {}", AppCfg.CODE, AppCfg.OSArch, AppCfg.is32Bit, AppCfg.BROWSER); log.info("获取参数3:{}, {}, {}, {}", AppCfg.CODE, AppCfg.OSArch, AppCfg.is32Bit, AppCfg.BROWSER);
} catch (Exception e) {
log.error("\n\t 启动GUI异常 >>>>>>>>>>>{},{}",e.getMessage(),e);
e.printStackTrace();
}
//spring
SpringApplication.run(HyToolApplication.class, args);
} }
} }

4
src/main/java/com/insigma/config/AppCfg.java

@ -7,6 +7,10 @@ package com.insigma.config;
* @since 17:21 2022/4/18 * @since 17:21 2022/4/18
*/ */
public class AppCfg { public class AppCfg {
/**
* 操作对象信息
*/
public static String BEAN;
/** /**
* 操作系统 架构 <br/>x86 * 操作系统 架构 <br/>x86
*/ */

31
src/main/java/com/insigma/config/SpringContextUtil.java

@ -0,0 +1,31 @@
package com.insigma.config;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class SpringContextUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringContextUtil.applicationContext = applicationContext;
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
@SuppressWarnings("unchecked")
public static <T> T getBean(String name) throws BeansException {
return (T) applicationContext.getBean(name);
}
@SuppressWarnings("unchecked")
public static <T> T getBean(Class<?> clz) throws BeansException {
return (T) applicationContext.getBean(clz);
}
}

27
src/main/java/com/insigma/service/Computer.java

@ -6,23 +6,40 @@ package com.insigma.service;
* @author zhangxianwei * @author zhangxianwei
* @since 2022/4/17 21:07 * @since 2022/4/17 21:07
*/ */
public abstract class Computer { public interface Computer {
/*** /***
* 执行 脚本程序 * 执行 脚本程序
* @param shell 执行脚本 * @param shell 执行脚本
* @return 执行执行脚本成功 * @return 执行执行脚本成功
*/ */
public abstract boolean runShell(String shell); default boolean runShell(String shell) {
System.out.println(String.format("设置出参数:%s,但是未检测到实现应用调用此方法!", shell));
return false;
}
/*** /***
* 执行 备份操作 * 执行 备份操作
* @param path 备份文件目录路径 不带结尾符
* @return 是否备份成功 * @return 是否备份成功
*/ */
public abstract boolean runBak(); default boolean runBak(String path) {
System.out.println(String.format("设置出参数:%s,但是未检测到实现应用调用此方法!", path));
return false;
}
/*** /***
* 执行 还原操作 * 执行 还原操作
* @param path 还原文件路径 * @param filePath 还原文件路径
* @return 是否备份成功 * @return 是否备份成功
*/ */
public abstract boolean runRestore(String path); default boolean runRestore(String filePath) {
System.out.println(String.format("设置出参数:%s,但是未检测到实现应用调用此方法!", filePath));
return false;
}
/***
* 执行 打开服务操作
* @return 是否备份成功
*/
default void openServer() {
}
} }

2
src/main/java/com/insigma/service/Database.java

@ -29,7 +29,7 @@ public interface Database {
* @param size 设置大小值 * @param size 设置大小值
* @return * @return
*/ */
default boolean setDbSize(int ...size) throws Exception { default boolean setDbSize(int ...size) {
System.out.println(String.format("设置出参数:%d,但是未检测到实现应用调用此方法!", size)); System.out.println(String.format("设置出参数:%d,但是未检测到实现应用调用此方法!", size));
return false; return false;
} }

11
src/main/java/com/insigma/service/impl/LinuxTongWebKingBase.java

@ -11,6 +11,7 @@ import com.insigma.utils.DbUtil;
import com.insigma.utils.FileUtil; import com.insigma.utils.FileUtil;
import com.insigma.utils.LinuxCommandUtil; import com.insigma.utils.LinuxCommandUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
@ -22,10 +23,12 @@ import java.util.List;
* @since 16:43 2022/4/19 * @since 16:43 2022/4/19
*/ */
@Slf4j @Slf4j
public class LinuxTongWebKingBase extends Computer implements Database, Middleware { @Service
public class LinuxTongWebKingBase implements Computer, Database, Middleware {
@Override @Override
public boolean runShell(String shell) { public boolean runShell(String shell) {
log.info("准备执行shell命令...");
try { try {
new LinuxCommandUtil(shell).run(); new LinuxCommandUtil(shell).run();
}catch (Exception e){ }catch (Exception e){
@ -36,12 +39,14 @@ public class LinuxTongWebKingBase extends Computer implements Database, Middlewa
} }
@Override @Override
public boolean runBak() { public boolean runBak(String path) {
log.info("准备执行备份命令...");
return false; return false;
} }
@Override @Override
public boolean runRestore(String path) { public boolean runRestore(String filePath) {
log.info("准备执行还原命令...");
return false; return false;
} }

21
src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java

@ -9,6 +9,7 @@ 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.stereotype.Service;
import java.io.File; import java.io.File;
import java.sql.SQLException; import java.sql.SQLException;
@ -24,10 +25,12 @@ import java.util.List;
* @since 23:30 2022/4/17 * @since 23:30 2022/4/17
*/ */
@Slf4j @Slf4j
public class WindowsTomcatMysql extends Computer implements Database, Middleware { @Service
public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean runShell(String shell) { public boolean runShell(String shell) {
log.info("准备执行shell命令...");
try { try {
new WinCommandUtil(shell).run(); new WinCommandUtil(shell).run();
}catch (Exception e){ }catch (Exception e){
@ -38,7 +41,8 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
} }
@Override @Override
public boolean runBak() { public boolean runBak(String path) {
log.info("准备执行备份命令...");
boolean retBool; boolean retBool;
log.info("创建备份文件目录..."); log.info("创建备份文件目录...");
String format = DateTimeFormatter.BASIC_ISO_DATE.format(LocalDate.now()); String format = DateTimeFormatter.BASIC_ISO_DATE.format(LocalDate.now());
@ -98,16 +102,16 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
} }
@Override @Override
public boolean runRestore(String path) { public boolean runRestore(String filePath) {
boolean retBool; boolean retBool;
boolean b = cn.hutool.core.io.FileUtil.isFile(path); boolean b = cn.hutool.core.io.FileUtil.isFile(filePath);
if(b){ if(b){
String namePath = path.substring(0, path.indexOf(".gz")); String namePath = filePath.substring(0, filePath.indexOf(".gz"));
String picPath = File.separatorChar + "tomcat8" + File.separatorChar + "HZBPHOTOS"; String picPath = File.separatorChar + "tomcat8" + File.separatorChar + "HZBPHOTOS";
String dbPath = AppCfg.HZB + File.separatorChar + "mysql" + File.separatorChar + "data"; String dbPath = AppCfg.HZB + File.separatorChar + "mysql" + File.separatorChar + "data";
log.info("判断文件:{}...存在:{}", path, b); log.info("判断文件:{}...存在:{}", filePath, b);
log.info("解压文件..."); log.info("解压文件...");
ZipUtil.unZip7Z(path, namePath); ZipUtil.unZip7Z(filePath, namePath);
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
@ -131,7 +135,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
} }
retBool = true; retBool = true;
}else{ }else{
log.error("判断文件:{}...不存在,请检查!", path); log.error("判断文件:{}...不存在,请检查!", filePath);
retBool = false; retBool = false;
} }
return retBool; return retBool;
@ -430,6 +434,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
return false; return false;
} }
@Override
public void openServer(){ public void openServer(){
runShell("SERVICES.MSC"); runShell("SERVICES.MSC");
log.info("打开本地服务完成!"); log.info("打开本地服务完成!");

103
src/main/java/com/insigma/ui/SwingFrame.java

@ -1,6 +1,8 @@
package com.insigma.ui; package com.insigma.ui;
import com.insigma.service.impl.WindowsTomcatMysql; import com.insigma.service.Computer;
import com.insigma.service.Database;
import com.insigma.service.Middleware;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -11,8 +13,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.awt.EventQueue; import java.awt.EventQueue;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -45,6 +45,11 @@ import java.awt.Component;
*/ */
@Slf4j @Slf4j
public class SwingFrame extends JFrame implements ActionListener { public class SwingFrame extends JFrame implements ActionListener {
private static Computer computer;
private static Database database;
private static Middleware middleware;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JPanel contentPane; private JPanel contentPane;
private final int MIN_PROGRESS = 0; private final int MIN_PROGRESS = 0;
@ -62,7 +67,9 @@ public class SwingFrame extends JFrame implements ActionListener {
/** /**
* Launch the application. * Launch the application.
*/ */
public static void run() { public static void run(Computer c, Database d, Middleware m) {
// 必须启动时,注入对象
setObjInfo(c, d, m);
// try { // try {
// for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { // for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
// if ("Nimbus".equals(info.getName())) { // if ("Nimbus".equals(info.getName())) {
@ -78,9 +85,7 @@ public class SwingFrame extends JFrame implements ActionListener {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
EventQueue.invokeLater(new Runnable() { EventQueue.invokeLater(() -> {
public void run() {
try {
SwingFrame frame = new SwingFrame(); SwingFrame frame = new SwingFrame();
frame.setTitle("系统工具"); //设置显示窗口标题 frame.setTitle("系统工具"); //设置显示窗口标题
// frame.setSize(1600,400);//设置显示窗口大小 // frame.setSize(1600,400);//设置显示窗口大小
@ -89,18 +94,23 @@ public class SwingFrame extends JFrame implements ActionListener {
frame.setBounds(100, 100, 930, 580); frame.setBounds(100, 100, 930, 580);
frame.setVisible(true); frame.setVisible(true);
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JavaSwing\\src\\main\\java\\com\\insigma\\ui\\favicon.jpg")); frame.setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\JavaSwing\\src\\main\\java\\com\\insigma\\ui\\favicon.jpg"));
} catch (Exception e) {
e.printStackTrace();
}
}
}); });
} }
private static void setObjInfo(Computer c, Database d, Middleware m) {
computer = c;
database = d;
middleware = m;
log.info("【机器】启动应用:{}", computer);
log.info("【库源】启动应用:{}", database);
log.info("【容器】启动应用:{}", middleware);
}
/** /**
* Create the frame. * Create the frame.
* @throws IOException * @throws IOException
*/ */
public SwingFrame() throws IOException { public SwingFrame() {
contentPane = new JPanel(); contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
@ -178,11 +188,7 @@ public class SwingFrame extends JFrame implements ActionListener {
lblNewLabel_3.addMouseListener(new MouseAdapter() { lblNewLabel_3.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
try{ computer.openServer();
new WindowsTomcatMysql().openServer();
}catch (Exception ex){
ex.printStackTrace();
}
} }
}); });
lblNewLabel_3.setBounds(128, 125, 140, 31); lblNewLabel_3.setBounds(128, 125, 140, 31);
@ -233,18 +239,10 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton btnNewButton_7 = new JButton(msgBtn); JButton btnNewButton_7 = new JButton(msgBtn);
btnNewButton_7.setBounds(72, 138, 329, 59); btnNewButton_7.setBounds(72, 138, 329, 59);
btnNewButton_7.setFont(new Font("微软雅黑", Font.PLAIN, 15)); btnNewButton_7.setFont(new Font("微软雅黑", Font.PLAIN, 15));
btnNewButton_7.addActionListener(new ActionListener() { btnNewButton_7.addActionListener(e -> {
@SneakyThrows database.setDbSize(200000);
public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(200000);
middleware.setMwSize(200000);
new WindowsTomcatMysql().setMwSize(200000);
}
}); });
memoryPanel.add(btnNewButton_7); memoryPanel.add(btnNewButton_7);
@ -258,14 +256,9 @@ public class SwingFrame extends JFrame implements ActionListener {
@Override @Override
@SneakyThrows @SneakyThrows
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(160000); database.setDbSize(160000);
new WindowsTomcatMysql().setMwSize(160000);
middleware.setMwSize(160000);
} }
}); });
memoryPanel.add(button_1); memoryPanel.add(button_1);
@ -280,14 +273,9 @@ public class SwingFrame extends JFrame implements ActionListener {
@Override @Override
@SneakyThrows @SneakyThrows
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(80000); database.setDbSize(80000);
new WindowsTomcatMysql().setMwSize(80000);
middleware.setMwSize(80000);
} }
}); });
memoryPanel.add(button_2); memoryPanel.add(button_2);
@ -302,14 +290,9 @@ public class SwingFrame extends JFrame implements ActionListener {
@Override @Override
@SneakyThrows @SneakyThrows
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(40000); database.setDbSize(40000);
new WindowsTomcatMysql().setMwSize(40000);
middleware.setMwSize(40000);
} }
}); });
memoryPanel.add(button_3); memoryPanel.add(button_3);
@ -320,20 +303,10 @@ public class SwingFrame extends JFrame implements ActionListener {
btnNewButton_1.setBackground(new Color(55, 205, 255)); btnNewButton_1.setBackground(new Color(55, 205, 255));
btnNewButton_1.setBorderPainted(false);//去掉按钮的边框的设置 btnNewButton_1.setBorderPainted(false);//去掉按钮的边框的设置
btnNewButton_1.setBounds(566, 472, 113, 40); btnNewButton_1.setBounds(566, 472, 113, 40);
btnNewButton_1.addActionListener(new ActionListener() { btnNewButton_1.addActionListener(e -> {
public void actionPerformed(ActionEvent e) {
//暂定保存内容 //暂定保存内容
}
}); });
memoryPanel.add(btnNewButton_1); memoryPanel.add(btnNewButton_1);
backupsPanel = new JPanel();//数据库备份、还原面板 backupsPanel = new JPanel();//数据库备份、还原面板
@ -741,7 +714,7 @@ public class SwingFrame extends JFrame implements ActionListener {
tabbedPane.addTab("测试", null, textPanel, null); tabbedPane.addTab("测试", null, textPanel, null);
// 代码可以注释掉,我这边开发放开 // 代码可以注释掉,我这边开发放开
Test.runTest(textPanel); Test.runTest(textPanel, computer, database, middleware);
// new Timer(500, new ActionListener() { // new Timer(500, new ActionListener() {
// @Override // @Override
// public void actionPerformed(ActionEvent e) { // public void actionPerformed(ActionEvent e) {
@ -762,17 +735,17 @@ public class SwingFrame extends JFrame implements ActionListener {
// try{ // try{
// Runtime rt = Runtime.getRuntime();runBak // Runtime rt = Runtime.getRuntime();runBak
// Process p = rt.exec("cmd.exe /c compmgmt.msc"); // Process p = rt.exec("cmd.exe /c compmgmt.msc");
// new WindowsTomcatMysql().openServer(); // computer.openServer();
// }catch (Exception ex){ // }catch (Exception ex){
// ex.printStackTrace(); // ex.printStackTrace();
// } // }
// } // }
if(buttonCommand.equals("开始优化")) { if("开始优化".equals(buttonCommand)) {
try{ try{
tabbedPane.addTab("开始优化界面", null, startRepairPanel, null); tabbedPane.addTab("开始优化界面", null, startRepairPanel, null);
tabbedPane.setSelectedComponent(startRepairPanel); tabbedPane.setSelectedComponent(startRepairPanel);
// new WindowsTomcatMysql().startDbService(); // database.startDbService();
// new WindowsTomcatMysql().startDbService(); // database.startDbService();
}catch (Exception ex){ }catch (Exception ex){
ex.printStackTrace(); ex.printStackTrace();
} }

47
src/main/java/com/insigma/ui/Test.java

@ -1,13 +1,18 @@
package com.insigma.ui; package com.insigma.ui;
import com.insigma.config.AppCfg;
import com.insigma.entry.IndexObj; import com.insigma.entry.IndexObj;
import com.insigma.entry.TabColObj; import com.insigma.entry.TabColObj;
import com.insigma.service.Computer;
import com.insigma.service.Database;
import com.insigma.service.Middleware;
import com.insigma.service.impl.WindowsTomcatMysql; import com.insigma.service.impl.WindowsTomcatMysql;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Objects;
/** /**
* (Test ) 测试工具类 * (Test ) 测试工具类
@ -18,29 +23,35 @@ import java.awt.event.ActionListener;
@Slf4j @Slf4j
public class Test { public class Test {
protected static void runTest(JPanel textPanel) { private static int n = 0;
addButton(textPanel, new JButton("执行shell命令"), e -> new WindowsTomcatMysql().runShell("SERVICES.MSC"));
addButton(textPanel, new JButton("备份"), e -> new WindowsTomcatMysql().runBak()); protected static void runTest(JPanel textPanel, Computer computer, Database database, Middleware middleware) {
// addButton(textPanel, new JButton("还原"), e -> new WindowsTomcatMysql().runRestore("")); if(Objects.isNull(computer) || Objects.isNull(database) || Objects.isNull(middleware)){
addButton(textPanel, new JButton("重建索引"), e -> new WindowsTomcatMysql().rebuildIndex(IndexObj.getData())); return;
addButton(textPanel, new JButton("设置数据库大小"), e -> new WindowsTomcatMysql().setDbSize(512)); }
addButton(textPanel, new JButton("清楚垃圾数据"), e -> new WindowsTomcatMysql().cleanDbCache(TabColObj.getSQL(), TabColObj.getData())); addButton(textPanel, new JButton("执行shell命令"), e -> computer.runShell("SERVICES.MSC"));
addButton(textPanel, new JButton("注册数据库服务"), e -> new WindowsTomcatMysql().registrationDbService()); addButton(textPanel, new JButton("备份"), e -> computer.runBak(AppCfg.HZB));
addButton(textPanel, new JButton("清楚应用缓存"), e -> new WindowsTomcatMysql().cleanMwCache()); // addButton(textPanel, new JButton("还原"), e -> computer.runRestore(""));
addButton(textPanel, new JButton("设置中间件大小"), e -> new WindowsTomcatMysql().setMwSize(128,256,512,512)); addButton(textPanel, new JButton("重建索引"), e -> database.rebuildIndex(IndexObj.getData()));
addButton(textPanel, new JButton("注册中间件服务"), e -> new WindowsTomcatMysql().registrationMwService()); addButton(textPanel, new JButton("设置数据库大小"), e -> database.setDbSize(512));
addButton(textPanel, new JButton("启动数据库服务"), e -> new WindowsTomcatMysql().startDbService()); addButton(textPanel, new JButton("清楚垃圾数据"), e -> database.cleanDbCache(TabColObj.getSQL(), TabColObj.getData()));
addButton(textPanel, new JButton("停止数据库服务"), e -> new WindowsTomcatMysql().stopDbService()); addButton(textPanel, new JButton("注册数据库服务"), e -> database.registrationDbService());
addButton(textPanel, new JButton("启动中间件服务"), e -> new WindowsTomcatMysql().startMwService()); addButton(textPanel, new JButton("清楚应用缓存"), e -> middleware.cleanMwCache());
addButton(textPanel, new JButton("停止中间件服务"), e -> new WindowsTomcatMysql().stopMwService()); addButton(textPanel, new JButton("设置中间件大小"), e -> middleware.setMwSize(128,256,512,512));
addButton(textPanel, new JButton("打开本地服务"), e -> new WindowsTomcatMysql().openServer()); addButton(textPanel, new JButton("注册中间件服务"), e -> middleware.registrationMwService());
addButton(textPanel, new JButton("启动数据库服务"), e -> database.startDbService());
addButton(textPanel, new JButton("停止数据库服务"), e -> database.stopDbService());
addButton(textPanel, new JButton("启动中间件服务"), e -> middleware.startMwService());
addButton(textPanel, new JButton("停止中间件服务"), e -> middleware.stopMwService());
addButton(textPanel, new JButton("打开本地服务"), e -> computer.openServer());
} }
private static void addButton(JPanel textPanel, JButton button, ActionListener l) { private static void addButton(JPanel textPanel, JButton button, ActionListener l) {
button.setFont(new Font("微软雅黑", Font.PLAIN, 15)); button.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button.setBounds(14, 13, 170, 35); int k = n++;
button.setBounds(14 + k/12*200, 13 + k%12 * 40, 170, 35);
button.addActionListener(l); button.addActionListener(l);
log.info("输出对象:{}", button); log.debug("输出对象:{}", button);
textPanel.add(button); textPanel.add(button);
} }
} }

1
src/main/resources/application.properties

@ -12,6 +12,7 @@ db.pwd=admin
hy.db=GWY20_Mysql hy.db=GWY20_Mysql
hy.mw=GWY20_Tomcat hy.mw=GWY20_Tomcat
hy.hzb=D:/hzb2021 hy.hzb=D:/hzb2021
hy.bean=windowsTomcatMysql
hy.code=GBK hy.code=GBK
hy.browser=360se.exe hy.browser=360se.exe
hy.os-arch=x86 hy.os-arch=x86

2
src/main/resources/run.bat

@ -1,2 +0,0 @@
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
java -jar java_tool.jar

2
src/test/java/com/insigma/service/impl/LinuxTongWebKingBaseTest.java

@ -77,7 +77,7 @@ public class LinuxTongWebKingBaseTest {
@Test @Test
public void runBak() { public void runBak() {
assertTrue(linuxTongWebKingBase.runBak()); assertTrue(linuxTongWebKingBase.runBak(AppCfg.HZB));
log.info("测试完成!"); log.info("测试完成!");
} }

22
src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java

@ -27,13 +27,13 @@ public class WindowsTomcatMysqlTest {
WindowsTomcatMysql windowsTomcatMysql = new WindowsTomcatMysql(); WindowsTomcatMysql windowsTomcatMysql = new WindowsTomcatMysql();
@Test @Test
public void rebuildIndex() throws Exception { public void rebuildIndex() {
assertTrue(windowsTomcatMysql.rebuildIndex(IndexObj.getData())); assertTrue(windowsTomcatMysql.rebuildIndex(IndexObj.getData()));
log.info("测试完成!"); log.info("测试完成!");
} }
@Test @Test
public void setDbSize() throws Exception { public void setDbSize() {
assertTrue(windowsTomcatMysql.setDbSize(500)); assertTrue(windowsTomcatMysql.setDbSize(500));
log.info("测试完成!"); log.info("测试完成!");
} }
@ -51,13 +51,13 @@ public class WindowsTomcatMysqlTest {
} }
@Test @Test
public void cleanMwCache() throws Exception { public void cleanMwCache() {
assertTrue(windowsTomcatMysql.cleanMwCache()); assertTrue(windowsTomcatMysql.cleanMwCache());
log.info("测试完成!"); log.info("测试完成!");
} }
@Test @Test
public void setMwSize() throws Exception { public void setMwSize() {
assertTrue(windowsTomcatMysql.setMwSize(128,256,512,512)); assertTrue(windowsTomcatMysql.setMwSize(128,256,512,512));
log.info("测试完成!"); log.info("测试完成!");
} }
@ -75,37 +75,37 @@ public class WindowsTomcatMysqlTest {
} }
@Test @Test
public void runBak() throws Exception { public void runBak() {
assertTrue(windowsTomcatMysql.runBak()); assertTrue(windowsTomcatMysql.runBak(AppCfg.HZB));
log.info("测试完成!"); log.info("测试完成!");
} }
@Test @Test
public void runRestore() throws Exception { public void runRestore() {
assertTrue(windowsTomcatMysql.runRestore("")); assertTrue(windowsTomcatMysql.runRestore(""));
log.info("测试完成!"); log.info("测试完成!");
} }
@Test @Test
public void startDbService() throws Exception { public void startDbService() {
assertTrue(windowsTomcatMysql.startDbService()); assertTrue(windowsTomcatMysql.startDbService());
log.info("测试完成!"); log.info("测试完成!");
} }
@Test @Test
public void stopDbService() throws Exception { public void stopDbService() {
assertTrue(windowsTomcatMysql.stopDbService()); assertTrue(windowsTomcatMysql.stopDbService());
log.info("测试完成!"); log.info("测试完成!");
} }
@Test @Test
public void startMwService() throws Exception { public void startMwService() {
assertTrue(windowsTomcatMysql.startMwService()); assertTrue(windowsTomcatMysql.startMwService());
log.info("测试完成!"); log.info("测试完成!");
} }
@Test @Test
public void stopMwService() throws Exception { public void stopMwService() {
assertTrue(windowsTomcatMysql.stopMwService()); assertTrue(windowsTomcatMysql.stopMwService());
log.info("测试完成!"); log.info("测试完成!");
} }

Loading…
Cancel
Save