You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
4.7 KiB
149 lines
4.7 KiB
package com.insigma.service.impl;
|
|
|
|
import cn.hutool.db.Session;
|
|
import com.insigma.config.AppCfg;
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
|
|
import java.sql.SQLException;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
* (CuWindows 类) windows 环境下 tomcat + mysql
|
|
*
|
|
* @author zhangxianwei
|
|
* @since 23:30 2022/4/17
|
|
*/
|
|
@Slf4j
|
|
public class WindowsTomcatMysql extends Computer implements Database, Middleware {
|
|
|
|
@Override
|
|
public boolean runShell(String shell) {
|
|
try {
|
|
new WinCommandUtil(shell).run();
|
|
}catch (Exception e){
|
|
log.error("执行发生异常:{}", e.getMessage());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean rebuildIndex(List<IndexObj> index) {
|
|
log.info("创建链接...");
|
|
final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd);
|
|
try {
|
|
for (IndexObj idx : index) {
|
|
session.execute("DROP INDEX ? ON ?", idx.getIdx(), idx.getTab());
|
|
session.execute("ALTER TABLE ? ADD INDEX ? (?) USING BTREE", idx.getTab(), idx.getIdx(), idx.getCol());
|
|
}
|
|
} catch (SQLException e) {
|
|
log.error("执行更新索引发生异常:{}", e.getMessage());
|
|
e.printStackTrace();
|
|
session.close();
|
|
return false;
|
|
}
|
|
session.close();
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean setDbSize(int size) {
|
|
log.info("停止 数据库 服务...");
|
|
runShell("sc stop " + AppCfg.DB);
|
|
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);
|
|
}
|
|
|
|
@Override
|
|
public boolean cleanDbCache(List<String> sql, List<TabColObj> tabColObjs) {
|
|
log.info("创建链接...");
|
|
final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd);
|
|
try {
|
|
log.info("执行 预置 SQL 脚本...");
|
|
for (String s : sql) {
|
|
session.execute(s);
|
|
}
|
|
log.info("执行 清洗数据中特殊字符串 脚本...");
|
|
for (String lj : DbUtil.RUBBISH) {
|
|
for (TabColObj tab : tabColObjs) {
|
|
session.execute("update ? set ?=replace(?, '?', '') where ? is not null",
|
|
tab.getTab(), tab.getCol(), tab.getCol(), lj, tab.getCol());
|
|
}
|
|
}
|
|
} catch (SQLException e) {
|
|
log.error("执行 清洗数据中特殊字符串 发生异常:{}", e.getMessage());
|
|
e.printStackTrace();
|
|
session.close();
|
|
return false;
|
|
}
|
|
log.info("执行 清洗数据中特殊字符串 完成...");
|
|
session.close();
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean registrationDbService() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean cleanMwCache() {
|
|
log.info("停止 中间件 服务...");
|
|
runShell("sc stop " + AppCfg.MW);
|
|
log.info("退出 浏览器...");
|
|
runShell("taskkill /f /im " + AppCfg.BROWSER);
|
|
|
|
log.info("删除 浏览器 历史文件...");
|
|
FileUtil.delAllFile(AppCfg.HZB + "/360se6/User Data");
|
|
|
|
log.info("解压 新浏览器 文件...");
|
|
ZipUtil.unZip7Z(AppCfg.HZB + "/tools/User Data.zip", AppCfg.HZB + "/360se6");
|
|
|
|
log.info("删除 应用 缓存文件...");
|
|
FileUtil.delAllFile(AppCfg.HZB + "/tomcat8/temp");
|
|
FileUtil.delAllFile(AppCfg.HZB + "/tomcat8/work/Catalina/localhost/qggwy");
|
|
|
|
log.info("删除 应用 日志文件...");
|
|
FileUtil.delAllFile(AppCfg.HZB + "/tomcat8/logs");
|
|
|
|
log.info("启动 中间件 服务...");
|
|
runShell("sc start " + AppCfg.MW);
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean setMwSize(int size) {
|
|
log.info("停止 中间件 服务...");
|
|
runShell("sc stop " + AppCfg.MW);
|
|
|
|
|
|
|
|
log.info("启动 中间件 服务...");
|
|
runShell("sc start " + AppCfg.MW);
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean registrationMwService() {
|
|
return true;
|
|
}
|
|
|
|
public void openServer(){
|
|
runShell("SERVICES.MSC");
|
|
log.info("打开本地服务完成!");
|
|
}
|
|
}
|
|
|