VIVIMAN
3 years ago
19 changed files with 800 additions and 333 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,14 @@ |
|||
package com.insigma.config; |
|||
|
|||
/** |
|||
* (AppConfig 类) |
|||
* |
|||
* @author zhangxianwei |
|||
* @since 17:21 2022/4/18 |
|||
*/ |
|||
public class AppCfg { |
|||
public static String BROWSER; |
|||
public static String DB; |
|||
public static String MW; |
|||
public static String HZB; |
|||
} |
@ -0,0 +1,16 @@ |
|||
package com.insigma.entry; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* (IndexObj 类) |
|||
* |
|||
* @author zhangxianwei |
|||
* @since 21:29 2022/4/17 |
|||
*/ |
|||
@Data |
|||
public class TabColObj { |
|||
|
|||
private String tab; |
|||
private String col; |
|||
} |
@ -0,0 +1,44 @@ |
|||
package com.insigma.utils; |
|||
|
|||
import cn.hutool.db.Session; |
|||
import cn.hutool.db.ds.simple.SimpleDataSource; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import javax.sql.DataSource; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Objects; |
|||
|
|||
/** |
|||
* (DbUtil 类) |
|||
* |
|||
* @author zhangxianwei |
|||
* @since 15:18 2022/4/18 |
|||
*/ |
|||
public class DbUtil { |
|||
|
|||
private static DataSource ds; |
|||
public static String url; |
|||
public static String usr; |
|||
public static String pwd; |
|||
|
|||
public static Session getSession(String url, String usr, String pwd) { |
|||
if(Objects.isNull(ds)){ |
|||
DbUtil.url = url; |
|||
DbUtil.usr = url; |
|||
DbUtil.pwd = url; |
|||
ds = new SimpleDataSource(isDb(url), usr, pwd); |
|||
} |
|||
return Session.create(ds); |
|||
} |
|||
|
|||
private static final String MYSQL = "jdbc:mysql"; |
|||
private static String isDb(String url){ |
|||
if(StringUtils.startsWithIgnoreCase(url, MYSQL)){ |
|||
url += "?useUnicode=true&characterEncoding=utf8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"; |
|||
} |
|||
return url; |
|||
} |
|||
|
|||
public static final List<String> RUBBISH = Arrays.asList("�","","�","","&#"); |
|||
} |
@ -0,0 +1,78 @@ |
|||
package com.insigma.utils; |
|||
|
|||
import java.io.*; |
|||
|
|||
/** |
|||
* (FileUtil 类) |
|||
* |
|||
* @author zhangxianwei |
|||
* @since 16:23 2022/4/18 |
|||
*/ |
|||
public class FileUtil { |
|||
|
|||
public static void replaceLine(String path, String keyword, String replaceToStr) { |
|||
String temp; |
|||
try { |
|||
File file = new File(path); |
|||
FileInputStream fis = new FileInputStream(file); |
|||
InputStreamReader isr = new InputStreamReader(fis); |
|||
BufferedReader br = new BufferedReader(isr); |
|||
StringBuffer buf = new StringBuffer(); |
|||
|
|||
// 保存该行前面的内容
|
|||
while ((temp = br.readLine()) != null) { |
|||
if (temp.trim().startsWith(keyword)) { |
|||
buf = buf.append(replaceToStr); |
|||
} else { |
|||
buf = buf.append(temp); |
|||
} |
|||
buf = buf.append(System.getProperty("line.separator")); |
|||
} |
|||
|
|||
br.close(); |
|||
FileOutputStream fos = new FileOutputStream(file); |
|||
PrintWriter pw = new PrintWriter(fos); |
|||
pw.write(buf.toString().toCharArray()); |
|||
pw.flush(); |
|||
pw.close(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 删除整个文件夹里的内容 |
|||
* |
|||
* @param path |
|||
* @throws Exception |
|||
*/ |
|||
public static void delAllFile(String path) { |
|||
File file = new File(path); |
|||
if (!file.exists()) { |
|||
return; |
|||
} |
|||
if (!file.isDirectory()) { |
|||
return; |
|||
} |
|||
String[] tempList = file.list(); |
|||
File temp = null; |
|||
for (int i = 0; i < tempList.length; i++) { |
|||
if (path.endsWith(File.separator)) { |
|||
temp = new File(path + tempList[i]); |
|||
} else { |
|||
temp = new File(path + File.separator + tempList[i]); |
|||
} |
|||
if (temp.isFile()) { |
|||
temp.delete(); |
|||
} |
|||
if (temp.isDirectory()) { |
|||
delAllFile(path + File.separatorChar + tempList[i]);// 先删除文件夹里面的文件
|
|||
File folderPath = new File(path + File.separatorChar + tempList[i]); // 再删除空文件夹
|
|||
folderPath.delete(); |
|||
} |
|||
} |
|||
file.delete(); //删除自身文件夹
|
|||
} |
|||
} |
@ -0,0 +1,71 @@ |
|||
package com.insigma.utils; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import java.io.BufferedReader; |
|||
import java.io.IOException; |
|||
import java.io.InputStream; |
|||
import java.io.InputStreamReader; |
|||
|
|||
/** |
|||
* CommandImpUtil |
|||
* |
|||
* @author admin |
|||
*/ |
|||
@Slf4j |
|||
public class LinuxCommandUtil implements Runnable { |
|||
private String command; |
|||
|
|||
public LinuxCommandUtil(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("shell任务执行失败"); |
|||
} |
|||
} |
|||
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
package com.insigma.utils; |
|||
|
|||
/** |
|||
* (RegisterUtil 类) |
|||
* |
|||
* @author zhangxianwei |
|||
* @since 18:02 2022/4/18 |
|||
*/ |
|||
public class RegisterUtil { |
|||
|
|||
|
|||
} |
@ -0,0 +1,69 @@ |
|||
package com.insigma.utils; |
|||
|
|||
import com.insigma.config.AppCfg; |
|||
|
|||
import java.io.File; |
|||
|
|||
/** |
|||
* (ZipUtil 类) |
|||
* |
|||
* @author zhangxianwei |
|||
* @since 17:34 2022/4/18 |
|||
*/ |
|||
public class ZipUtil { |
|||
private static final String SX = "/"; |
|||
private static final String XX = "\\"; |
|||
public static void zip7Z(String dirName, String zipFileName) { |
|||
if (XX.equals(File.separator)) { |
|||
String cmd7z = getRootPath() + "7-Zip/7z.exe"; |
|||
try { |
|||
String cmd = "cmd.exe /c " + cmd7z.trim().replace(" ", "\" \"") + " a -tzip \"" + zipFileName + "\" \"" + dirName + "\\*\""; |
|||
new WinCommandUtil(cmd).run(); |
|||
} catch (Exception ie) { |
|||
ie.printStackTrace(); |
|||
} |
|||
} else if (SX.equals(File.separator)) { |
|||
try { |
|||
String cmd777 = "chmod -R 777 "+dirName; |
|||
new LinuxCommandUtil(cmd777).run(); |
|||
|
|||
int index = cmd777.lastIndexOf(File.separator); |
|||
String cmd777Short = cmd777.substring(0,index); |
|||
new LinuxCommandUtil(cmd777Short).run(); |
|||
|
|||
String cmd = "7z a "+zipFileName+" "+dirName+" "; |
|||
new LinuxCommandUtil(cmd).run(); |
|||
} catch (Exception ie) { |
|||
ie.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
public static void unZip7Z(String filepath, String destinationDir) { |
|||
if (XX.equals(File.separator)) { |
|||
String cmd7z = getRootPath() + "7-Zip/7z.exe"; |
|||
try { |
|||
String cmd = "cmd.exe /c " + cmd7z.trim().replace(" ", "\" \"") + " x \"" + filepath + "\" -o\"" + destinationDir + "\" " + " -y "; |
|||
new WinCommandUtil(cmd).run(); |
|||
} catch (Exception ie) { |
|||
ie.printStackTrace(); |
|||
} |
|||
} else if (SX.equals(File.separator)) { |
|||
try { |
|||
|
|||
String cmd777 ="chmod -R 777 "+filepath+File.separator; |
|||
new WinCommandUtil(cmd777).run(); |
|||
|
|||
String cmd = "unzip -o "+filepath+" -d "+destinationDir+""; |
|||
new WinCommandUtil(cmd).run(); |
|||
|
|||
new WinCommandUtil(cmd777).run(); |
|||
} catch (Exception ie) { |
|||
ie.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static String getRootPath() { |
|||
return AppCfg.HZB + "/tomcat8/webapps/qggwy/WEB-INF/classes/static/softTools/"; |
|||
} |
|||
} |
Loading…
Reference in new issue