Browse Source

提交对象管理2

master
VIVIMAN 3 years ago
parent
commit
31e9386c53
  1. 1
      .gitignore
  2. 6
      pom.xml
  3. 3
      src/main/java/META-INF/MANIFEST.MF
  4. 12
      src/main/java/com/insigma/HyToolApplication.java
  5. 10
      src/main/java/com/insigma/service/Computer.java
  6. 32
      src/main/java/com/insigma/service/impl/CuWindows.java
  7. 53
      src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java
  8. 66
      src/main/java/com/insigma/utils/WinCommandUtil.java
  9. 7
      src/main/resources/application-dev.yml
  10. 4
      src/main/resources/application.properties
  11. 11
      src/test/java/com/insigma/service/impl/WindowsTomcatMysqlTest.java

1
.gitignore

@ -34,3 +34,4 @@ build/
### VS Code ###
.vscode/
/out/artifacts/java_tool_jar/java_tool.jar

6
pom.xml

@ -137,6 +137,12 @@
<version>2.11.0</version>
</dependency>
<!-- 系统服务操作 -->
<dependency>
<groupId>org.hyperic</groupId>
<artifactId>sigar</artifactId>
<version>1.6.5.132</version>
</dependency>
</dependencies>

3
src/main/java/META-INF/MANIFEST.MF

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.insigma.utils.OsTest

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

@ -29,14 +29,7 @@ public class HyToolApplication {
SwingUtilities.invokeLater(() -> {
log.info("正在启动GUI =======================>>> " + guiType );
if(SWING2.equals(guiType)){
SwingSet2.main(args);
}else if(SWING9.equals(guiType)){
// TODO...
}else {
log.error("启动GUI异常 =======================>>> 请检查GUITYPE是否存在 ");
throw new RuntimeException("GUI类型出错:"+guiType);
}
SwingSet2.main(args);
});
} catch (Exception e) {
log.error("\n\t 启动GUI异常 >>>>>>>>>>>{},{}",e.getMessage(),e);
@ -46,7 +39,4 @@ public class HyToolApplication {
//spring
SpringApplication.run(HyToolApplication.class, args);
}
private static final String SWING2 = "SwingSet2GUI";
private static final String SWING9 = "Swing9patchGUI";
}

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

@ -1,23 +1,17 @@
package com.insigma.service;
import org.springframework.util.Assert;
/**
* (Computer 计算机 接口)
*
* @author zhangxianwei
* @since 2022/4/17 21:07
*/
public interface Computer extends Middleware, Database {
public abstract class Computer {
/***
* 执行 脚本程序
* @param shell 执行脚本
* @return
*/
default boolean runShell(String shell) {
Assert.notNull(shell, "未检测到要执行脚本!");
System.out.printf("执行脚本:%s,但是未检测到实现应用调用此方法!%n", shell);
return false;
}
public abstract boolean runShell(String shell);
}

32
src/main/java/com/insigma/service/impl/CuWindows.java

@ -1,32 +0,0 @@
package com.insigma.service.impl;
import com.insigma.entry.IndexObj;
import com.insigma.service.Computer;
import java.util.List;
/**
* (CuWindows )
*
* @author zhangxianwei
* @since 23:30 2022/4/17
*/
public class CuWindows implements Computer {
@Override
public boolean rebuildIndex(List<IndexObj> index) {
return false;
}
@Override
public boolean setDbSize(int size) {
System.out.printf("设置出参数:%d,但是未检测到实现应用调用此方法!", size);
return false;
}
@Override
public boolean cleanDbCache() {
System.out.println("进行缓存清除,但是未检测到实现应用调用此方法!");
return false;
}
}

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

@ -0,0 +1,53 @@
package com.insigma.service.impl;
import com.insigma.entry.IndexObj;
import com.insigma.service.Computer;
import com.insigma.service.*;
import com.insigma.utils.WinCommandUtil;
import java.util.List;
/**
* (CuWindows ) windows + tomcat + mysql
*
* @author zhangxianwei
* @since 23:30 2022/4/17
*/
public class WindowsTomcatMysql extends Computer implements Database, Middleware {
@Override
public boolean runShell(String shell) {
try {
new WinCommandUtil(shell).run();
}catch (Exception ignored){
return false;
}
return true;
}
@Override
public boolean rebuildIndex(List<IndexObj> index) {
return Database.super.rebuildIndex(index);
}
@Override
public boolean setDbSize(int size) {
return Database.super.setDbSize(size);
}
@Override
public boolean cleanDbCache() {
return Database.super.cleanDbCache();
}
@Override
public boolean cleanMwCache() {
return Middleware.super.cleanMwCache();
}
@Override
public boolean setMwSize(int size) {
return Middleware.super.setMwSize(size);
}
}

66
src/main/java/com/insigma/utils/WinCommandUtil.java

@ -0,0 +1,66 @@
package com.insigma.utils;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
/**
* CommandImpUtil
*
* @author admin
*/
@Slf4j
public class WinCommandUtil implements Runnable {
private String command;
public WinCommandUtil(String command) {
this.command = command;
}
@Override
public void run() {
Process process;
int exitVal = 0;
try {
log.debug("准备执行命令:{}",command);
process = Runtime.getRuntime().exec(command);
// Runtime.exec()创建的子进程公用父进程的流,不同平台上,父进程的stream buffer可能被打满导致子进程阻塞,从而永远无法返回。
//针对这种情况,我们只需要将子进程的stream重定向出来即可。
new RunCmdStreamThread(process.getInputStream(), "INFO").start();
new RunCmdStreamThread(process.getErrorStream(), "ERR").start();
exitVal = process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
if (exitVal != 0) {
log.error("执行命令发生异常:{}", exitVal);
throw new RuntimeException("cmd任务执行失败");
}
}
static class RunCmdStreamThread extends Thread {
InputStream is;
String printType;
RunCmdStreamThread(InputStream is, String printType) {
this.is = is;
this.printType = printType;
}
@Override
public void run() {
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
log.debug("输出:{}>{}", printType, line);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}

7
src/main/resources/application-dev.yml

@ -8,13 +8,8 @@ spring:
language:
basename: language/swingset
mybatis:
type-aliases-package: classpath:com.wuzf.swing.dao
logging:
level:
com.wuzf.swing.dao: debug
level: debug
file:
path: output/log
name: D:/ouput/logs/SwingDemoLog.log

4
src/main/resources/application.properties

@ -2,6 +2,4 @@
#设置激活配置文件
spring.profiles.active=dev
##自定义启动UI 1-swing原生UI 2-beauty美化UI 3-SwingSet3
swing.ui.type=SwingSet2GUI
swing.ui.testCN=哈哈
swing.ui.testCN=测试

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

@ -0,0 +1,11 @@
package com.insigma.service.impl;
import org.junit.jupiter.api.Test;
public class WindowsTomcatMysqlTest {
@Test
public void runShellTest(){
}
}
Loading…
Cancel
Save