|
|
@ -4,12 +4,14 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"archive/zip" |
|
|
|
"bufio" |
|
|
|
"database/sql" |
|
|
|
"fmt" |
|
|
|
_ "github.com/go-sql-driver/mysql" |
|
|
|
"github.com/lxn/walk" |
|
|
|
. "github.com/lxn/walk/declarative" |
|
|
|
"github.com/lxn/win" |
|
|
|
"github.com/mzky/zip" |
|
|
|
"golang.org/x/sys/windows" |
|
|
|
"golang.org/x/sys/windows/registry" |
|
|
|
"io" |
|
|
@ -23,6 +25,7 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
var version = "V2021 1.0.1" |
|
|
|
var passwordname = "Qw^e1@10&++Hzb...?8" |
|
|
|
|
|
|
|
func (mw *myApp) aboutactionTriggered() { |
|
|
|
walk.MsgBox(mw.mw, "功能说明", strings.Join([]string{ |
|
|
@ -174,11 +177,11 @@ func getWindows() error { |
|
|
|
Text: "关于", |
|
|
|
OnTriggered: app.aboutactionTriggered, |
|
|
|
}, |
|
|
|
Action{ |
|
|
|
/*Action{ |
|
|
|
// Image: "./image//yaoqiu.png",
|
|
|
|
Text: "要求", |
|
|
|
OnTriggered: app.aboutactionTriggered, |
|
|
|
}, |
|
|
|
},*/ |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
@ -601,11 +604,46 @@ func setServerSize() { |
|
|
|
|
|
|
|
// dbBak 数据备份功能
|
|
|
|
func dbBak() { |
|
|
|
showMsg("【待完善】数据备份!") |
|
|
|
db, _ := sql.Open("mysql", "root:admin@tcp(127.0.0.1:35017)/hy_qggwy?charset=utf8") |
|
|
|
showMsg("连接数据库成功!") |
|
|
|
|
|
|
|
// 创建临时文件夹
|
|
|
|
dir := time.Now().Format("2006102150405") |
|
|
|
if err := os.MkdirAll(dir, os.ModePerm); err != nil { |
|
|
|
showMsg("创建临时目录时发生异常!") |
|
|
|
} |
|
|
|
|
|
|
|
QuerySQL(db, dir, "select * from a01 where STATUS=1", "a01", []string{"A0155", "JSNLSJ", "TBSJ", "XGSJ"}) |
|
|
|
QuerySQL(db, dir, "select * from a02 where a0000 in (select a0000 from a01 where status=1)", "a02", []string{}) |
|
|
|
QuerySQL(db, dir, "select * from a05 where a0000 in (select a0000 from a01 where status=1)", "a05", []string{}) |
|
|
|
QuerySQL(db, dir, "select * from a06 where a0000 in (select a0000 from a01 where status=1)", "a06", []string{}) |
|
|
|
QuerySQL(db, dir, "select * from a08 where a0000 in (select a0000 from a01 where status=1)", "a08", []string{}) |
|
|
|
QuerySQL(db, dir, "select * from a14 where a0000 in (select a0000 from a01 where status=1)", "a14", []string{}) |
|
|
|
QuerySQL(db, dir, "select * from a15 where a0000 in (select a0000 from a01 where status=1)", "a15", []string{}) |
|
|
|
QuerySQL(db, dir, "select * from a36 where a0000 in (select a0000 from a01 where status=1)", "a36", []string{}) |
|
|
|
QuerySQL(db, dir, "select * from a99z1 where a0000 in (select a0000 from a01 where status=1)", "a99z1", []string{}) |
|
|
|
QuerySQL(db, dir, "select * from a30 where a0000 in (select a0000 from a01 where status=1)", "a30", []string{}) |
|
|
|
QuerySQL(db, dir, "select * from a33 where a0000 in (select a0000 from a01 where status=1)", "a33", []string{}) |
|
|
|
QuerySQL(db, dir, "select * from a57 where a0000 in (select a0000 from a01 where status=1)", "a57", []string{}) |
|
|
|
|
|
|
|
// 处理照片信息
|
|
|
|
copyFileByA57(db, dir) |
|
|
|
|
|
|
|
dirName := fmt.Sprintf("./%s", dir) |
|
|
|
fileName := fmt.Sprintf("%s.gz", dir) |
|
|
|
// 进行压缩操作 并 删除压缩前目录
|
|
|
|
Zip(dirName, fileName) |
|
|
|
if err := os.RemoveAll(dir); err != nil { |
|
|
|
showMsg("删除历史目录时发生异常!") |
|
|
|
} |
|
|
|
showMsg("已完成数据备份!") |
|
|
|
showMsg(fmt.Sprintf(`⭐数据备份:%s`, fileName)) |
|
|
|
} |
|
|
|
|
|
|
|
// reDbBak 备份数据还原
|
|
|
|
func reDbBak() { |
|
|
|
// 执行还原操作
|
|
|
|
// runSQL("mysqlPath", "sqlPath")
|
|
|
|
showMsg("【待完善】备份数据还原!") |
|
|
|
} |
|
|
|
|
|
|
@ -767,3 +805,161 @@ func (mw *myApp) RunAppSetingDialog(owner walk.Form, confirmCall func(*AppSeting |
|
|
|
}, |
|
|
|
}.Run(owner) |
|
|
|
} |
|
|
|
|
|
|
|
// runSQL 执行sql脚本
|
|
|
|
func runSQL(mysqlPath, sqlPath string) { |
|
|
|
log.Print("调用执行对应的SQL脚本:", sqlPath) |
|
|
|
c := exec.Command("cmd", "/C", mysqlPath+"mysql -uroot -padmin hy_qggwy < "+sqlPath) |
|
|
|
if err := c.Run(); err != nil { |
|
|
|
log.Print("【不影响执行】执行时发生异常!异常为:", err) |
|
|
|
} |
|
|
|
log.Print("预置脚本数据成功!") |
|
|
|
} |
|
|
|
|
|
|
|
// QuerySQL 获取表数据
|
|
|
|
func QuerySQL(db *sql.DB, dir, sqlStr, tableName string, colNil []string) { |
|
|
|
rows, _ := db.Query(sqlStr) |
|
|
|
showMsg(fmt.Sprintf(`开始备份数据:%s;`, tableName)) |
|
|
|
defer rows.Close() |
|
|
|
cloumns, _ := rows.Columns() |
|
|
|
values := make([]sql.RawBytes, len(cloumns)) |
|
|
|
scanArgs := make([]interface{}, len(values)) |
|
|
|
for i := range values { |
|
|
|
scanArgs[i] = &values[i] |
|
|
|
} |
|
|
|
aa := "" |
|
|
|
for rows.Next() { |
|
|
|
_ = rows.Scan(scanArgs...) |
|
|
|
key, value := "(", "(" |
|
|
|
aa = aa + "insert into " + tableName + " " |
|
|
|
for i, col := range values { |
|
|
|
kk := cloumns[i] |
|
|
|
if inStr(colNil, kk) { |
|
|
|
continue |
|
|
|
} |
|
|
|
if i == len(values)-1 { |
|
|
|
key = key + kk |
|
|
|
if value == "(" { |
|
|
|
if col == nil { |
|
|
|
value = value + "NULL" |
|
|
|
} else { |
|
|
|
value = value + "'" + string(col) + "'" |
|
|
|
} |
|
|
|
} else { |
|
|
|
if col == nil { |
|
|
|
value = value + ",NULL" |
|
|
|
} else { |
|
|
|
value = value + ",'" + string(col) + "'" |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
key = key + kk + "," |
|
|
|
if value == "(" { |
|
|
|
if col == nil { |
|
|
|
value = value + "NULL" |
|
|
|
} else { |
|
|
|
value = value + "'" + string(col) + "'" |
|
|
|
} |
|
|
|
} else { |
|
|
|
if col == nil { |
|
|
|
value = value + ",NULL" |
|
|
|
} else { |
|
|
|
value = value + ",'" + string(col) + "'" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
key = key + ")" |
|
|
|
value = value + ");\n" |
|
|
|
aa = aa + key + " values " + value |
|
|
|
} |
|
|
|
var path string |
|
|
|
path = fmt.Sprintf("%s/%s.sql", dir, tableName) |
|
|
|
file3, _ := os.Create(path) |
|
|
|
_, _ = file3.WriteString(aa) |
|
|
|
file3.Close() |
|
|
|
} |
|
|
|
|
|
|
|
// inStr 判断字段关系
|
|
|
|
func inStr(colNil []string, kk string) bool { |
|
|
|
for _, s := range colNil { |
|
|
|
if s == kk { |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
// copyFileByA57 复制需要备份的照片文件
|
|
|
|
func copyFileByA57(db *sql.DB, mysqlPath string) { |
|
|
|
codeValues, _ := db.Query("select concat('tomcat8/HZBPHOTOS/', PHOTOPATH) filePath, PHOTONAME fileName from " + |
|
|
|
"a57 where a0000 in (select a0000 from a01 where status=1);") |
|
|
|
//返回所有列
|
|
|
|
filePath, fileName := "", "" |
|
|
|
for codeValues.Next() { |
|
|
|
_ = codeValues.Scan(&filePath, &fileName) |
|
|
|
if filePath != "" { |
|
|
|
from := path + "/" + filePath + fileName |
|
|
|
to := mysqlPath + "/" + filePath |
|
|
|
_ = os.MkdirAll(to, os.ModePerm) |
|
|
|
if _, err := CopyFile(from, to+fileName); err != nil { |
|
|
|
showMsg(fmt.Sprintf(`发现存在照片无法复制:%s`, filePath+fileName)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// CopyFile 复制文件操作
|
|
|
|
func CopyFile(src, des string) (w int64, err error) { |
|
|
|
srcFile, _ := os.Open(src) |
|
|
|
defer srcFile.Close() |
|
|
|
desFile, _ := os.Create(des) |
|
|
|
defer desFile.Close() |
|
|
|
|
|
|
|
return io.Copy(desFile, srcFile) |
|
|
|
} |
|
|
|
|
|
|
|
// Zip 打包成zip文件
|
|
|
|
func Zip(srcDir string, zipFileName string) { |
|
|
|
|
|
|
|
// 预防:旧文件无法覆盖
|
|
|
|
_ = os.RemoveAll(zipFileName) |
|
|
|
|
|
|
|
// 创建:zip文件
|
|
|
|
zipfile, _ := os.Create(zipFileName) |
|
|
|
defer zipfile.Close() |
|
|
|
|
|
|
|
// 打开:zip文件
|
|
|
|
archive := zip.NewWriter(zipfile) |
|
|
|
defer archive.Close() |
|
|
|
|
|
|
|
// 遍历路径信息
|
|
|
|
_ = filepath.Walk(srcDir, func(path string, info os.FileInfo, _ error) error { |
|
|
|
|
|
|
|
// 如果是源路径,提前进行下一个遍历
|
|
|
|
if path == srcDir { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
// 获取:文件头信息
|
|
|
|
header, _ := zip.FileInfoHeader(info) |
|
|
|
header.Name = strings.TrimPrefix(path, srcDir+`/`) |
|
|
|
|
|
|
|
// 判断:文件是不是文件夹
|
|
|
|
if info.IsDir() { |
|
|
|
header.Name += `/` |
|
|
|
} else { |
|
|
|
// 设置:zip的文件压缩算法
|
|
|
|
header.Method = zip.Deflate |
|
|
|
} |
|
|
|
|
|
|
|
// 创建:压缩包头部信息
|
|
|
|
writer, _ := archive.Encrypt(header.Name, passwordname, zip.AES256Encryption) |
|
|
|
if !info.IsDir() { |
|
|
|
file, _ := os.Open(path) |
|
|
|
defer file.Close() |
|
|
|
_, _ = io.Copy(writer, file) |
|
|
|
} |
|
|
|
return nil |
|
|
|
}) |
|
|
|
} |
|
|
|