@ -9,7 +9,10 @@ import com.insigma.service.*;
import com.insigma.utils.* ;
import com.insigma.utils.* ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import java.io.File ;
import java.sql.SQLException ;
import java.sql.SQLException ;
import java.time.LocalDate ;
import java.time.format.DateTimeFormatter ;
import java.util.List ;
import java.util.List ;
@ -34,35 +37,101 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
}
}
@Override
@Override
public boolean runBak ( ) {
public boolean runBak ( ) throws Exception {
return false ;
boolean retBool ;
log . info ( "创建备份文件目录..." ) ;
String format = DateTimeFormatter . BASIC_ISO_DATE . format ( LocalDate . now ( ) ) ;
boolean b = FileUtil . mkDirectory ( AppCfg . HZB + File . separatorChar + format ) ;
if ( b ) {
log . info ( "创建备份目录:{}" , format ) ;
WinServiceTool . WindowsService ws = WinServiceTool . getService ( AppCfg . DB , AppCfg . CODE ) ;
if ( ws . getRunningStatus ( ) = = WinServiceTool . WindowsService . ServiceState . RUNNING ) {
log . info ( "备份照片文件..." ) ;
copyFileByA57 ( format ) ;
log . info ( "停止 数据库 服务..." ) ;
ws . stopService ( ) ;
log . info ( "备份压缩数据库文件..." ) ;
ZipUtil . zip7Z (
AppCfg . HZB + File . separatorChar + "mysql" + File . separatorChar + "data" ,
AppCfg . HZB + File . separatorChar + format + File . separatorChar + "data.gz" ) ;
log . info ( "备份压缩备份文件..." ) ;
ZipUtil . zip7Z (
AppCfg . HZB + File . separatorChar + "format" ,
AppCfg . HZB + File . separatorChar + format + ".gz" ) ;
log . info ( "启动 数据库 服务..." ) ;
ws . startService ( ) ;
}
retBool = true ;
} else {
retBool = false ;
}
return retBool ;
}
}
@Override
private void copyFileByA57 ( String format ) {
public boolean rebuildIndex ( List < IndexObj > index ) {
boolean retBool ;
log . info ( "创建链接..." ) ;
log . info ( "创建链接..." ) ;
final Session session = DbUtil . getSession ( DbUtil . url , DbUtil . usr , DbUtil . pwd , DbUtil . drive ) ;
final Session session = DbUtil . getSession ( DbUtil . url , DbUtil . usr , DbUtil . pwd , DbUtil . drive ) ;
String sql ;
try {
try {
for ( IndexObj idx : index ) {
String sql = "select concat('tomcat8/HZBPHOTOS/', PHOTOPATH, '/', PHOTONAME) fileName from a57 where exists (select 1 from a01 where a01.a0000=a57.a0000 and status=1)" ;
try {
List < String > query = session . query ( sql , String . class ) ;
sql = String . format ( "DROP INDEX %s ON %s" , idx . getIdx ( ) , idx . getTab ( ) ) ;
String from , to ;
log . debug ( sql ) ;
for ( int i = 0 , j = query . size ( ) ; i < j ; i + + ) {
session . execute ( sql ) ;
from = AppCfg . HZB + query . get ( i ) ;
} finally {
to = AppCfg . HZB + format + query . get ( i ) ;
sql = String . format ( "ALTER TABLE %s ADD INDEX %s (%s) USING BTREE" , idx . getTab ( ) , idx . getIdx ( ) , idx . getCol ( ) ) ;
cn . hutool . core . io . FileUtil . copy ( from , to , false ) ;
log . debug ( sql ) ;
session . execute ( sql ) ;
}
}
}
retBool = true ;
} catch ( SQLException e ) {
} catch ( SQLException e ) {
log . error ( "执行更新索引发生异常:{}" , e . getMessage ( ) ) ;
log . error ( "执行查询报错:{}" , e . getMessage ( ) ) ;
session . close ( ) ;
e . printStackTrace ( ) ;
}
}
@Override
public boolean runRestore ( String path ) {
boolean retBool ;
boolean b = cn . hutool . core . io . FileUtil . isFile ( path ) ;
if ( b ) {
log . info ( "判断文件:{}...存在:{}" , path , b ) ;
retBool = true ;
} else {
log . error ( "判断文件:{}...不存在,请检查!" , path ) ;
retBool = false ;
retBool = false ;
}
}
session . close ( ) ;
return retBool ;
}
@Override
public boolean rebuildIndex ( List < IndexObj > index ) {
boolean retBool = false ;
WinServiceTool . WindowsService ws = WinServiceTool . getService ( AppCfg . DB , AppCfg . CODE ) ;
if ( ws . getRunningStatus ( ) = = WinServiceTool . WindowsService . ServiceState . RUNNING ) {
log . info ( "创建链接..." ) ;
final Session session = DbUtil . getSession ( DbUtil . url , DbUtil . usr , DbUtil . pwd , DbUtil . drive ) ;
String sql ;
try {
for ( IndexObj idx : index ) {
try {
sql = String . format ( "DROP INDEX %s ON %s" , idx . getIdx ( ) , idx . getTab ( ) ) ;
log . debug ( sql ) ;
session . execute ( sql ) ;
} finally {
sql = String . format ( "ALTER TABLE %s ADD INDEX %s (%s) USING BTREE" , idx . getTab ( ) , idx . getIdx ( ) , idx . getCol ( ) ) ;
log . debug ( sql ) ;
session . execute ( sql ) ;
}
}
retBool = true ;
} catch ( SQLException e ) {
log . error ( "执行更新索引发生异常:{}" , e . getMessage ( ) ) ;
session . close ( ) ;
retBool = false ;
}
session . close ( ) ;
}
return retBool ;
return retBool ;
}
}
@ -96,34 +165,37 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
@Override
@Override
public boolean cleanDbCache ( List < String > sqls , List < TabColObj > tabColObjs ) {
public boolean cleanDbCache ( List < String > sqls , List < TabColObj > tabColObjs ) {
boolean retBool ;
boolean retBool = false ;
log . info ( "创建链接..." ) ;
WinServiceTool . WindowsService ws = WinServiceTool . getService ( AppCfg . DB , AppCfg . CODE ) ;
final Session session = DbUtil . getSession ( DbUtil . url , DbUtil . usr , DbUtil . pwd , DbUtil . drive ) ;
if ( ws . getRunningStatus ( ) = = WinServiceTool . WindowsService . ServiceState . RUNNING ) {
try {
log . info ( "创建链接..." ) ;
log . info ( "执行 预置 SQL 脚本..." ) ;
final Session session = DbUtil . getSession ( DbUtil . url , DbUtil . usr , DbUtil . pwd , DbUtil . drive ) ;
for ( String sql : sqls ) {
try {
log . debug ( sql ) ;
log . info ( "执行 预置 SQL 脚本..." ) ;
session . execute ( sql ) ;
for ( String sql : sqls ) {
}
log . info ( "执行 清洗数据中特殊字符串 脚本..." ) ;
String sql ;
for ( String lj : DbUtil . RUBBISH ) {
for ( TabColObj tab : tabColObjs ) {
sql = String . format ( "update %s set %s=replace(%s, '%s', '') where %s is not null" ,
tab . getTab ( ) , tab . getCol ( ) , tab . getCol ( ) , lj , tab . getCol ( ) ) ;
log . debug ( sql ) ;
log . debug ( sql ) ;
session . execute ( sql ) ;
session . execute ( sql ) ;
}
}
log . info ( "执行 清洗数据中特殊字符串 脚本..." ) ;
String sql ;
for ( String lj : DbUtil . RUBBISH ) {
for ( TabColObj tab : tabColObjs ) {
sql = String . format ( "update %s set %s=replace(%s, '%s', '') where %s is not null" ,
tab . getTab ( ) , tab . getCol ( ) , tab . getCol ( ) , lj , tab . getCol ( ) ) ;
log . debug ( sql ) ;
session . execute ( sql ) ;
}
}
retBool = true ;
} catch ( SQLException e ) {
log . error ( "执行 清洗数据中特殊字符串 发生异常:{}" , e . getMessage ( ) ) ;
e . printStackTrace ( ) ;
session . close ( ) ;
retBool = false ;
}
}
retBool = true ;
log . info ( "执行 清洗数据中特殊字符串 完成..." ) ;
} catch ( SQLException e ) {
log . error ( "执行 清洗数据中特殊字符串 发生异常:{}" , e . getMessage ( ) ) ;
e . printStackTrace ( ) ;
session . close ( ) ;
session . close ( ) ;
retBool = false ;
}
}
log . info ( "执行 清洗数据中特殊字符串 完成..." ) ;
session . close ( ) ;
return retBool ;
return retBool ;
}
}
@ -243,6 +315,58 @@ public class WindowsTomcatMysql extends Computer implements Database, Middleware
return true ;
return true ;
}
}
@Override
public boolean startDbService ( ) throws Exception {
log . info ( "启动 数据库 服务..." ) ;
WinServiceTool . WindowsService ws = WinServiceTool . getService ( AppCfg . DB , AppCfg . CODE ) ;
if ( ws . getRunningStatus ( ) = = WinServiceTool . WindowsService . ServiceState . STOPPED ) {
ws . startService ( ) ;
return true ;
}
if ( ws . getRunningStatus ( ) = = WinServiceTool . WindowsService . ServiceState . RUNNING ) {
ws . restartService ( ) ;
return true ;
}
return false ;
}
@Override
public boolean stopDbService ( ) throws Exception {
log . info ( "停止 数据库 服务..." ) ;
WinServiceTool . WindowsService ws = WinServiceTool . getService ( AppCfg . DB , AppCfg . CODE ) ;
if ( ws . getRunningStatus ( ) = = WinServiceTool . WindowsService . ServiceState . RUNNING ) {
ws . stopService ( ) ;
return true ;
}
return false ;
}
@Override
public boolean startMwService ( ) throws Exception {
log . info ( "启动 中间件 服务..." ) ;
WinServiceTool . WindowsService ws = WinServiceTool . getService ( AppCfg . MW , AppCfg . CODE ) ;
if ( ws . getRunningStatus ( ) = = WinServiceTool . WindowsService . ServiceState . STOPPED ) {
ws . startService ( ) ;
return true ;
}
if ( ws . getRunningStatus ( ) = = WinServiceTool . WindowsService . ServiceState . RUNNING ) {
ws . restartService ( ) ;
return true ;
}
return false ;
}
@Override
public boolean stopMwService ( ) throws Exception {
log . info ( "停止 中间件 服务..." ) ;
WinServiceTool . WindowsService ws = WinServiceTool . getService ( AppCfg . MW , AppCfg . CODE ) ;
if ( ws . getRunningStatus ( ) = = WinServiceTool . WindowsService . ServiceState . RUNNING ) {
ws . stopService ( ) ;
return true ;
}
return false ;
}
public void openServer ( ) {
public void openServer ( ) {
runShell ( "SERVICES.MSC" ) ;
runShell ( "SERVICES.MSC" ) ;
log . info ( "打开本地服务完成!" ) ;
log . info ( "打开本地服务完成!" ) ;