Browse Source

调试代码

master
VIVIMAN 3 years ago
parent
commit
1efbe3bcf3
  1. 8
      src/main/java/com/insigma/HyToolApplication.java
  2. 24
      src/main/java/com/insigma/func/RunThrowingConsumer.java
  3. 14
      src/main/java/com/insigma/func/ThrowingConsumer.java
  4. 4
      src/main/java/com/insigma/service/Computer.java
  5. 4
      src/main/java/com/insigma/service/Database.java
  6. 8
      src/main/java/com/insigma/service/Middleware.java
  7. 99
      src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java
  8. 94
      src/main/java/com/insigma/ui/SwingFrame.java
  9. 46
      src/main/java/com/insigma/ui/Test.java
  10. 0
      src/main/resources/META-INF/spring.factories

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

@ -1,9 +1,7 @@
package com.insigma;
import cn.hutool.db.Session;
import com.insigma.config.AppCfg;
import com.insigma.ui.SwingFrame;
import com.insigma.utils.DbUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -46,9 +44,9 @@ public class HyToolApplication {
// SwingSet2.main(args);
// });
SwingFrame.run();
Session session = DbUtil.getSession(url, usr, pwd, drive);
log.info("获取{}连接,进行操作!", session);
session.close();
log.info("获取参数1:{}, {}, {}, {}", url, usr, pwd, drive);
log.info("获取参数2:{}, {}, {}", AppCfg.DB, AppCfg.MW, AppCfg.HZB);
log.info("获取参数3:{}, {}, {}, {}", AppCfg.CODE, AppCfg.OSArch, AppCfg.is32Bit, AppCfg.BROWSER);
} catch (Exception e) {
log.error("\n\t 启动GUI异常 >>>>>>>>>>>{},{}",e.getMessage(),e);
e.printStackTrace();

24
src/main/java/com/insigma/func/RunThrowingConsumer.java

@ -0,0 +1,24 @@
package com.insigma.func;
import java.util.function.Consumer;
/**
* @author Vivim
*/
public class RunThrowingConsumer {
/***
* 带有参数和异常处理的的消费接口
*/
public static <T> Consumer<T> throwingConsumerWrapper(
ThrowingConsumer<T, Exception> throwingConsumer) {
return i -> {
try {
throwingConsumer.accept(i);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
};
}
}

14
src/main/java/com/insigma/func/ThrowingConsumer.java

@ -0,0 +1,14 @@
package com.insigma.func;
/**
* @author Vivim
*/
@FunctionalInterface
public interface ThrowingConsumer<T, E extends Exception> {
/***
* 带有参数和异常处理的的消费接口
* @param t
* @throws E
*/
void accept(T t) throws E;
}

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

@ -18,11 +18,11 @@ public abstract class Computer {
* 执行 备份操作
* @return 是否备份成功
*/
public abstract boolean runBak() throws Exception;
public abstract boolean runBak();
/***
* 执行 还原操作
* @param path 还原文件路径
* @return 是否备份成功
*/
public abstract boolean runRestore(String path) throws Exception;
public abstract boolean runRestore(String path);
}

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

@ -57,7 +57,7 @@ public interface Database {
* 实现数据库服务启动
* @return
*/
default boolean startDbService() throws Exception {
default boolean startDbService() {
System.out.println("进行数据库服务启动,但是未检测到实现应用调用此方法!");
return false;
}
@ -66,7 +66,7 @@ public interface Database {
* 实现数据库服务停止
* @return
*/
default boolean stopDbService() throws Exception {
default boolean stopDbService() {
System.out.println("进行数据库服务停止,但是未检测到实现应用调用此方法!");
return false;
}

8
src/main/java/com/insigma/service/Middleware.java

@ -12,7 +12,7 @@ public interface Middleware {
* 清除 中间件 缓存
* @return
*/
default boolean cleanMwCache() throws Exception {
default boolean cleanMwCache() {
System.out.println("清除缓存,但是未检测到实现应用调用此方法!");
return false;
}
@ -21,7 +21,7 @@ public interface Middleware {
* @param size
* @return
*/
default boolean setMwSize(int ...size) throws Exception {
default boolean setMwSize(int ...size) {
System.out.println(String.format("设置应用参数:%d,%d,%d,%d,但是未检测到实现应用调用此方法!", size));
return false;
}
@ -39,7 +39,7 @@ public interface Middleware {
* 实现中间件服务启动
* @return
*/
default boolean startMwService() throws Exception {
default boolean startMwService() {
System.out.println("进行中间件服务启动,但是未检测到实现应用调用此方法!");
return false;
}
@ -48,7 +48,7 @@ public interface Middleware {
* 实现中间件服务停止
* @return
*/
default boolean stopMwService() throws Exception {
default boolean stopMwService() {
System.out.println("进行中间件服务停止,但是未检测到实现应用调用此方法!");
return false;
}

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

@ -4,6 +4,7 @@ import cn.hutool.db.Session;
import com.insigma.config.AppCfg;
import com.insigma.entry.IndexObj;
import com.insigma.entry.TabColObj;
import com.insigma.func.ThrowingConsumer;
import com.insigma.service.Computer;
import com.insigma.service.*;
import com.insigma.utils.*;
@ -37,7 +38,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
}
@Override
public boolean runBak() throws Exception {
public boolean runBak() {
boolean retBool;
log.info("创建备份文件目录...");
String format = DateTimeFormatter.BASIC_ISO_DATE.format(LocalDate.now());
@ -50,7 +51,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
copyFileByA57(format);
log.info("停止 数据库 服务...");
ws.stopService();
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) {
return false;
}
log.info("备份压缩数据库文件...");
ZipUtil.zip7Z(
@ -63,7 +66,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
AppCfg.HZB + File.separatorChar + format + ".gz");
log.info("启动 数据库 服务...");
ws.startService();
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) {
return false;
}
retBool = true;
} else {
retBool = false;
@ -93,7 +98,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
}
@Override
public boolean runRestore(String path) throws Exception {
public boolean runRestore(String path) {
boolean retBool;
boolean b = cn.hutool.core.io.FileUtil.isFile(path);
if(b){
@ -106,7 +111,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
ws.stopService();
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) {
return false;
}
}
log.info("删除原数据文件...");
cn.hutool.core.io.FileUtil.del(dbPath);
@ -119,7 +126,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
log.info("移动照片文件...");
cn.hutool.core.io.FileUtil.copy(namePath + picPath, AppCfg.HZB + picPath, true);
ws.startService();
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) {
return false;
}
retBool = true;
}else{
log.error("判断文件:{}...不存在,请检查!", path);
@ -127,6 +136,18 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
}
return retBool;
}
private boolean canNotRun(WinServiceTool.WindowsService ws,
ThrowingConsumer<WinServiceTool.WindowsService, Exception> consumer) {
boolean canRun;
try {
consumer.accept(ws);
canRun = true;
} catch (Exception e) {
log.error("执行发生异常:{}", e.getMessage());
canRun = false;
}
return !canRun;
}
@Override
public boolean rebuildIndex(List<IndexObj> index) {
@ -166,7 +187,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
* @throws Exception
*/
@Override
public boolean setDbSize(int ...size) throws Exception {
public boolean setDbSize(int ...size) {
if(size == null || size.length!=1){
log.error("请检测参数是否正确...");
return false;
@ -174,7 +195,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
log.info("停止 数据库 服务...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
ws.stopService();
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) {
return false;
}
}
log.info("设置 数据库 内存参数...");
@ -183,7 +206,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
String.format("innodb_buffer_pool_size=%dM", size[0]));
log.info("启动 数据库 服务...");
ws.startService();
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) {
return false;
}
return true;
}
@ -245,11 +270,13 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
}
@Override
public boolean cleanMwCache() throws Exception {
public boolean cleanMwCache() {
log.info("停止 中间件 服务...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
ws.stopService();
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) {
return false;
}
}
log.info("退出 浏览器...");
@ -269,7 +296,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
FileUtil.delAllFile(AppCfg.HZB + "/tomcat8/logs");
log.info("启动 中间件 服务...");
ws.startService();
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) {
return false;
}
return true;
}
@ -280,7 +309,7 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
* @throws Exception
*/
@Override
public boolean setMwSize(int ...size) throws Exception {
public boolean setMwSize(int ...size) {
if(size == null || size.length!=4){
log.error("请检测参数是否正确...");
return false;
@ -288,7 +317,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
log.info("停止 中间件 服务...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
ws.stopService();
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) {
return false;
}
}
if(WinCommandUtil.RegisterUtil.registerJava(AppCfg.HZB, size[0], size[1], size[2], size[3])){
@ -296,7 +327,9 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
}
log.info("启动 中间件 服务...");
ws.startService();
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) {
return false;
}
return true;
}
@ -340,52 +373,58 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
}
@Override
public boolean startDbService() throws Exception {
public boolean startDbService() {
boolean bool;
log.info("启动 数据库 服务...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.STOPPED){
ws.startService();
return true;
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) {
return false;
}
}
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
ws.restartService();
return true;
if (canNotRun(ws, WinServiceTool.WindowsService::restartService)) {
return false;
}
}
return false;
}
@Override
public boolean stopDbService() throws Exception {
public boolean stopDbService() {
boolean bool;
log.info("停止 数据库 服务...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
ws.stopService();
return true;
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) {
return false;
}
}
return false;
}
@Override
public boolean startMwService() throws Exception {
public boolean startMwService() {
boolean bool;
log.info("启动 中间件 服务...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.STOPPED){
ws.startService();
return true;
return !canNotRun(ws, WinServiceTool.WindowsService::startService);
}
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
ws.restartService();
return true;
return !canNotRun(ws, WinServiceTool.WindowsService::restartService);
}
return false;
}
@Override
public boolean stopMwService() throws Exception {
public boolean stopMwService() {
log.info("停止 中间件 服务...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
ws.stopService();
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) {
return false;
}
return true;
}
return false;

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

@ -39,6 +39,7 @@ import javax.swing.JProgressBar;
import javax.swing.JTextPane;
import javax.swing.filechooser.FileFilter;
import java.awt.Component;
import java.util.function.Function;
/**
* @author BeiJing-GWY
@ -59,10 +60,6 @@ public class SwingFrame extends JFrame implements ActionListener {
private JPanel startBackupPanel;
private JPanel startRestorePanel;
private JTabbedPane tabbedPane;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
/**
* Launch the application.
*/
@ -87,8 +84,7 @@ public class SwingFrame extends JFrame implements ActionListener {
// } catch (Exception e) {
// e.printStackTrace();
// }
EventQueue.invokeLater(new Runnable() {
public void run() {
EventQueue.invokeLater(() -> {
try {
SwingFrame frame = new SwingFrame();
frame.setTitle("系统工具"); //设置显示窗口标题
@ -101,7 +97,6 @@ public class SwingFrame extends JFrame implements ActionListener {
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
@ -226,9 +221,7 @@ public class SwingFrame extends JFrame implements ActionListener {
JButton btnNewButton_7 = new JButton(msgBtn);
btnNewButton_7.setBounds(72, 138, 329, 59);
btnNewButton_7.setFont(new Font("微软雅黑", Font.PLAIN, 15));
btnNewButton_7.addActionListener(new ActionListener() {
@SneakyThrows
public void actionPerformed(ActionEvent e) {
btnNewButton_7.addActionListener(e -> {
new WindowsTomcatMysql().setDbSize(200000);
@ -237,7 +230,6 @@ public class SwingFrame extends JFrame implements ActionListener {
new WindowsTomcatMysql().setMwSize(200000);
}
});
memoryPanel.add(btnNewButton_7);
@ -248,6 +240,7 @@ public class SwingFrame extends JFrame implements ActionListener {
button_1.setBounds(72, 227, 329, 59);
button_1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_1.addActionListener(new ActionListener() {
@Override
@SneakyThrows
public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(160000);
@ -269,6 +262,7 @@ public class SwingFrame extends JFrame implements ActionListener {
button_2.setBounds(72, 314, 329, 59);
button_2.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_2.addActionListener(new ActionListener() {
@Override
@SneakyThrows
public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(80000);
@ -290,6 +284,7 @@ public class SwingFrame extends JFrame implements ActionListener {
button_3.setBounds(72, 399, 329, 59);
button_3.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_3.addActionListener(new ActionListener() {
@Override
@SneakyThrows
public void actionPerformed(ActionEvent e) {
new WindowsTomcatMysql().setDbSize(40000);
@ -438,6 +433,7 @@ public class SwingFrame extends JFrame implements ActionListener {
upgradePanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e){ //鼠标点击事件
@SuppressWarnings("unused")
URI uri = null;
@ -461,10 +457,12 @@ public class SwingFrame extends JFrame implements ActionListener {
}
@Override
public void mouseEntered(MouseEvent e) { //鼠标移入事件
lblNewLabel_9.setForeground(Color.red);
}
@Override
public void mouseExited(MouseEvent e) { //鼠标移出事件
lblNewLabel_9.setForeground(new Color(30, 144, 255));
}
@ -715,78 +713,8 @@ public class SwingFrame extends JFrame implements ActionListener {
textPanel.setBackground(Color.WHITE);
tabbedPane.addTab("测试", null, textPanel, null);
JButton button_7 = new JButton("开始数据库服务");
button_7.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_7.setBounds(14, 13, 170, 35);
textPanel.add(button_7);
JButton button_8 = new JButton("停止数据库服务");
button_8.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_8.setBounds(14, 61, 170, 24);
button_8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
new WindowsTomcatMysql().stopDbService();
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
textPanel.add(button_8);
JButton button_9 = new JButton("开始中间件");
button_9.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_9.setBounds(14, 98, 170, 35);
button_9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
new WindowsTomcatMysql().startMwService();
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
textPanel.add(button_9);
JButton button_10 = new JButton("停止中间件");
button_10.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_10.setBounds(14, 153, 170, 35);
button_10.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
new WindowsTomcatMysql().stopMwService();
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
textPanel.add(button_10);
JButton button_11 = new JButton("测试按钮");
button_11.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button_11.setBounds(14, 226, 170, 35);
textPanel.add(button_11);
textField_1 = new JTextField();
textField_1.setBounds(247, 19, 170, 29);
textPanel.add(textField_1);
textField_1.setColumns(10);
textField_2 = new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(247, 86, 170, 29);
textPanel.add(textField_2);
textField_3 = new JTextField();
textField_3.setColumns(10);
textField_3.setBounds(247, 159, 170, 29);
textPanel.add(textField_3);
textField_4 = new JTextField();
textField_4.setColumns(10);
textField_4.setBounds(247, 232, 170, 29);
textPanel.add(textField_4);
// 代码可以注释掉,我这边开发放开
Test.runTest(textPanel);
// new Timer(500, new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {

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

@ -0,0 +1,46 @@
package com.insigma.ui;
import com.insigma.entry.IndexObj;
import com.insigma.entry.TabColObj;
import com.insigma.service.impl.WindowsTomcatMysql;
import lombok.extern.slf4j.Slf4j;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
/**
* (Test ) 测试工具类
*
* @author zhangxianwei
* @since 21:30 2022/4/28
*/
@Slf4j
public class Test {
protected static void runTest(JPanel textPanel) {
addButton(textPanel, new JButton("执行shell命令"), e -> new WindowsTomcatMysql().runShell("SERVICES.MSC"));
addButton(textPanel, new JButton("备份"), e -> new WindowsTomcatMysql().runBak());
// addButton(textPanel, new JButton("还原"), e -> new WindowsTomcatMysql().runRestore(""));
addButton(textPanel, new JButton("重建索引"), e -> new WindowsTomcatMysql().rebuildIndex(IndexObj.getData()));
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("注册数据库服务"), e -> new WindowsTomcatMysql().registrationDbService());
addButton(textPanel, new JButton("清楚应用缓存"), e -> new WindowsTomcatMysql().cleanMwCache());
addButton(textPanel, new JButton("设置中间件大小"), e -> new WindowsTomcatMysql().setMwSize(128,256,512,512));
addButton(textPanel, new JButton("注册中间件服务"), e -> new WindowsTomcatMysql().registrationMwService());
addButton(textPanel, new JButton("启动数据库服务"), e -> new WindowsTomcatMysql().startDbService());
addButton(textPanel, new JButton("停止数据库服务"), e -> new WindowsTomcatMysql().stopDbService());
addButton(textPanel, new JButton("启动中间件服务"), e -> new WindowsTomcatMysql().startMwService());
addButton(textPanel, new JButton("停止中间件服务"), e -> new WindowsTomcatMysql().stopMwService());
addButton(textPanel, new JButton("打开本地服务"), e -> new WindowsTomcatMysql().openServer());
}
private static void addButton(JPanel textPanel, JButton button, ActionListener l) {
button.setFont(new Font("微软雅黑", Font.PLAIN, 15));
button.setBounds(14, 13, 170, 35);
button.addActionListener(l);
log.info("输出对象:{}", button);
textPanel.add(button);
}
}

0
src/main/resources/META-INF/spring.factories

Loading…
Cancel
Save