Browse Source

完成基本备份功能

master
VIVIMAN 3 years ago
parent
commit
609e6ffdf4
  1. 71
      golang_learn/data_func/go_to_windows/main.go
  2. BIN
      golang_learn/data_func/go_to_windows/main.ico
  3. BIN
      golang_learn/data_func/go_to_windows/main.syso
  4. 265
      golang_learn/data_func/go_to_windows/main.txt
  5. 43
      golang_learn/data_func/go_to_windows/versioninfo.json

71
golang_learn/data_func/go_to_windows/main.go

@ -62,6 +62,21 @@ var service1, service3 myService
// 该部分不存在最后 横线 (格式为 D:\hzb2021),使用时需要补充横线 // 该部分不存在最后 横线 (格式为 D:\hzb2021),使用时需要补充横线
var path string var path string
// 基础库部分脚本(除 a01 和 b01)
var tableName = []string{
"a02", "a05", "a06", "a08", "a14", "a15", "a17", "a36", "a30", "a33", "a57", "a65", "a99z1",
}
// 统计部分脚本
var tableNameTj = []string{
"tj_un", "tb_set_unit", "tb_rpt_cv_cfg",
"J2001", "J2002", "J2003", "J2004", "J2005", "J2006", "J2007", "J2008", "J2101", "J2102", "J2103", "J2104",
"J2105", "J2106", "J2107", "J2108", "M_M01", "M_M02", "M_M03", "M_M04", "M_M05", "M_M06", "M_M07", "M_M09",
"M_N01", "M_N02", "M_N03", "M_N04", "M_N05", "M_P01", "M_P02", "M_P03", "M_Q01", "M_Q02", "M_Q03", "M_Q04",
"M_Q05", "M_Q06", "M_Q07", "M_Q08", "M_Q09", "M_Q10", "M_Q11", "M_Q12", "M_Q13",
"inner_check_result", "outer_check_result", "statistics_state", "middleverify_error_list", "tj_tbsm_item_list", "tb_zyhz",
}
// init 初始化 // init 初始化
func init() { func init() {
app.title = "公务员管理系统-运行监控" app.title = "公务员管理系统-运行监控"
@ -82,12 +97,12 @@ func main() {
if e := HasHzb(); e != nil { if e := HasHzb(); e != nil {
walk.MsgBox(app.mw, "错误", "请先下载并安装 组工 软件,才可以正常使用软件!", walk.MsgBoxIconWarning) walk.MsgBox(app.mw, "错误", "请先下载并安装 组工 软件,才可以正常使用软件!", walk.MsgBoxIconWarning)
OpenUrl("https://www.12371.cn/zgrjxz/gwywx/") _ = OpenUrl("https://www.12371.cn/zgrjxz/gwywx/")
return return
} }
if e := InHzb(); e != nil { if e := InHzb(); e != nil {
walk.MsgBox(app.mw, "错误", "当前工具未在正确的位置,请将工具移至安装软件目录下(如:./hzb2020/HyServer.exe)!", walk.MsgBoxIconWarning) walk.MsgBox(app.mw, "错误", "当前工具未在正确的位置!\n请将工具移至安装软件目录下(如:./hzb2020/HyServer.exe)。", walk.MsgBoxIconWarning)
return return
} }
@ -619,6 +634,12 @@ func setServerSize() {
// dbBak 数据备份功能 // dbBak 数据备份功能
func dbBak() { func dbBak() {
// 判断 mysql 服务应用启动
if service1.btnStart.Enabled() {
walk.MsgBox(app.mw, "错误", "数据库服务未启动,进行数据库服务启动!", walk.MsgBoxIconWarning)
startService(service1)
}
db, _ := sql.Open("mysql", "root:admin@tcp(127.0.0.1:35017)/hy_qggwy?charset=utf8") db, _ := sql.Open("mysql", "root:admin@tcp(127.0.0.1:35017)/hy_qggwy?charset=utf8")
showMsg("连接数据库成功!") showMsg("连接数据库成功!")
@ -628,20 +649,16 @@ func dbBak() {
showMsg("创建临时目录时发生异常!") showMsg("创建临时目录时发生异常!")
} }
// 统计库部分
for i := 0; i < len(tableNameTj); i++ {
QuerySQL(db, dir, "select * from "+tableNameTj[i], tableNameTj[i], []string{})
}
// 基础库部分
QuerySQL(db, dir, "select * from a01 where STATUS=1", "a01", []string{"A0155", "JSNLSJ", "TBSJ", "XGSJ"}) 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{}) for i := 0; i < len(tableName); i++ {
QuerySQL(db, dir, "select * from a05 where a0000 in (select a0000 from a01 where status=1)", "a05", []string{}) QuerySQL(db, dir, "select * from "+tableName[i]+" where a0000 in (select a0000 from a01 where status=1)", tableName[i], []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 a17 where a0000 in (select a0000 from a01 where status=1)", "a17", []string{})
QuerySQL(db, dir, "select * from a36 where a0000 in (select a0000 from a01 where status=1)", "a36", []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{})
QuerySQL(db, dir, "select * from a65 where a0000 in (select a0000 from a01 where status=1)", "a65", []string{})
QuerySQL(db, dir, "select * from a99z1 where a0000 in (select a0000 from a01 where status=1)", "a99z1", []string{})
QuerySQL(db, dir, "select * from b01", "b01", []string{}) QuerySQL(db, dir, "select * from b01", "b01", []string{})
// 处理照片信息 // 处理照片信息
@ -1004,6 +1021,16 @@ func OpenUrl(url string) error {
// hasHzb 判断软件是否安装 // hasHzb 判断软件是否安装
func HasHzb() error { func HasHzb() error {
key2020, err2020 := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\全国公务员管理信息系统2020版`, registry.QUERY_VALUE)
defer key2020.Close()
key2021, err2021 := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\全国公务员管理信息系统2021版`, registry.QUERY_VALUE)
defer key2021.Close()
// 判断是否已经存在了
if err2020 != nil && err2021 != nil {
return errors.New("未发现注册软件!")
}
return nil return nil
} }
@ -1012,16 +1039,10 @@ func InHzb() error {
pwd, _ := os.Getwd() pwd, _ := os.Getwd()
// 判断依据 为是否存在 360se6、tools、Tomcat8 和 mysql 目录下 // 判断依据 为是否存在 360se6、tools、Tomcat8 和 mysql 目录下
fileInfoList, _ := ioutil.ReadDir(pwd) fileInfoList, _ := ioutil.ReadDir(pwd)
if Contains(fileInfoList, "360se6") == -1 { if Contains(fileInfoList, "360se6") == -1 ||
return errors.New("目录错误") Contains(fileInfoList, "mysql") == -1 ||
} Contains(fileInfoList, "tomcat8") == -1 ||
if Contains(fileInfoList, "mysql") == -1 { Contains(fileInfoList, "tools") == -1 {
return errors.New("目录错误")
}
if Contains(fileInfoList, "tomcat8") == -1 {
return errors.New("目录错误")
}
if Contains(fileInfoList, "tools") == -1 {
return errors.New("目录错误") return errors.New("目录错误")
} }
return nil return nil

BIN
golang_learn/data_func/go_to_windows/main.ico

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
golang_learn/data_func/go_to_windows/main.syso

Binary file not shown.

265
golang_learn/data_func/go_to_windows/main.txt

@ -1,265 +0,0 @@
// +build windows
// +build 386
package main
import (
"fmt"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"github.com/lxn/win"
"golang.org/x/sys/windows"
"os/exec"
"syscall"
"time"
)
type myApp struct {
title string
msg *walk.TextEdit
mw *walk.MainWindow
}
type myService struct {
text string
serviceName string
labelState *walk.Label
btnStart *walk.PushButton
btnStop *walk.PushButton
}
var app myApp
var service1, service2, service3 myService
func init() {
app.title = "XXXX管理系统-运行监控"
service1 = myService{
text: "数据存储库",
serviceName: "GWY20_Mysql",
}
service2 = myService{
text: "Web服务(nginx)",
serviceName: "nginx",
}
service3 = myService{
text: "公务员系统",
serviceName: "GWY20_Tomcat",
}
}
func main() {
_ = getWindows()
walk.App().SetProductName(app.title)
walk.App().SetOrganizationName("dwt")
_ = service1.labelState.SetText("未安装")
_ = service2.labelState.SetText("未安装")
_ = service3.labelState.SetText("未安装")
service1.btnStart.Clicked().Attach(func() {
startService(service1)
})
service1.btnStop.Clicked().Attach(func() {
stopService(service1)
})
service2.btnStart.Clicked().Attach(func() {
startService(service2)
})
service2.btnStop.Clicked().Attach(func() {
stopService(service2)
})
service3.btnStart.Clicked().Attach(func() {
startService(service3)
})
service3.btnStop.Clicked().Attach(func() {
stopService(service3)
})
go flushServiceStat(service1)
go flushServiceStat(service2)
go flushServiceStat(service3)
app.mw.Show()
app.mw.Run()
}
func setServiceState(service myService, msg string, btnStartStatus bool, btnStopStatus bool) {
_ = service.labelState.SetText(msg)
service.btnStart.SetEnabled(btnStartStatus)
service.btnStop.SetEnabled(btnStopStatus)
}
// 刷新服务状态的协程程序
func flushServiceStat(service myService) {
for {
winService, err := NewWinService(service.serviceName)
if winService == nil || err != nil {
if err == windows.ERROR_SERVICE_DOES_NOT_EXIST {
setServiceState(service, "未安装", false, false)
} else {
setServiceState(service, "服务打开失败", false, false)
}
} else {
if winService.IsStop() {
setServiceState(service, "已经停止", true, false)
} else if winService.IsRunning() {
setServiceState(service, "正在运行", false, true)
}
}
time.Sleep(time.Second)
}
}
// 启动服务
func startService(service myService) {
s, err := NewWinService(service.serviceName)
if s == nil || err != nil {
return
}
showMsg(service.serviceName + " 服务开始启动......")
err = s.StartService()
if err != nil {
showMsg(service.serviceName + " 服务启动失败!")
} else {
showMsg(service.serviceName + " 服务启动成功。")
}
}
// 停止服务
func stopService(service myService) {
s, err := NewWinService(service.serviceName)
if s == nil || err != nil {
return
}
showMsg(service.serviceName + " 服务开始停止......")
err = s.StopService()
if err != nil {
showMsg(service.serviceName + " 服务停止失败!")
} else {
showMsg(service.serviceName + " 服务停止成功。")
}
}
func showMsg(msg string) {
app.msg.AppendText(time.Now().Format("2006-01-02 15:04:05 "))
app.msg.AppendText(msg)
app.msg.AppendText("\r\n")
}
// 初始始化窗体
func getWindows() error {
icon, _ := walk.NewIconFromResourceId(3)
err := MainWindow{
Visible: false,
AssignTo: &app.mw,
Title: app.title,
Size: Size{500, 360},
Font: Font{Family: "微软雅黑", PointSize: 9},
Icon: icon,
Layout: VBox{},
Children: []Widget{
GroupBox{
Title: "基础服务状态",
Layout: Grid{Columns: 3},
Children: []Widget{
Label{Text: service1.text, MinSize: Size{220, 30}, TextColor: walk.RGB(255, 255, 0)},
Label{AssignTo: &service1.labelState, Text: "正在运行", MinSize: Size{80, 30}},
Composite{
Layout: HBox{},
MaxSize: Size{132, 30},
Children: []Widget{
PushButton{
AssignTo: &service1.btnStop,
MaxSize: Size{60, 30},
Text: "停止",
},
PushButton{
AssignTo: &service1.btnStart,
MaxSize: Size{60, 30},
Text: "启动",
},
},
},
Label{Text: service2.text},
Label{AssignTo: &service2.labelState, Text: "正在运行"},
Composite{
Layout: HBox{},
MaxSize: Size{132, 30},
Children: []Widget{
PushButton{
AssignTo: &service2.btnStop,
MaxSize: Size{60, 30},
Text: "停止",
},
PushButton{
AssignTo: &service2.btnStart,
MaxSize: Size{60, 30},
Text: "启动",
},
},
},
},
},
GroupBox{
Title: "业务服务状态",
Layout: Grid{Columns: 3},
Children: []Widget{
Label{Text: service3.text, MinSize: Size{220, 30}},
Label{AssignTo: &service3.labelState, Text: "正在运行", MinSize: Size{80, 30}},
Composite{
Layout: HBox{},
MaxSize: Size{132, 30},
Children: []Widget{
PushButton{
AssignTo: &service3.btnStop,
MaxSize: Size{60, 30},
Text: "停止",
},
PushButton{
AssignTo: &service3.btnStart,
MaxSize: Size{60, 30},
Text: "启动",
},
},
},
},
},
TextEdit{AssignTo: &app.msg, VScroll: true, ReadOnly: true},
Composite{
Layout: HBox{},
Children: []Widget{
PushButton{
MinSize: Size{160, 30},
Text: "打开windows服务管理程序",
OnClicked: func() {
c := exec.Command("cmd", "/C", "SERVICES.MSC")
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // 不显示命令窗口
if err := c.Start(); err != nil {
showMsg(fmt.Sprintf("打开windows服务管理程序失败, 错误信息: %s", err))
}
},
},
HSpacer{},
PushButton{
MinSize: Size{121, 30},
Text: "关闭本监控窗口",
OnClicked: func() {
walk.App().Exit(0)
},
},
},
},
},
OnSizeChanged: func() {
_ = app.mw.SetSize(walk.Size(Size{500, 360}))
},
}.Create()
winLong := win.GetWindowLong(app.mw.Handle(), win.GWL_STYLE)
// 不能调整窗口大小,禁用最大化按钮
win.SetWindowLong(app.mw.Handle(), win.GWL_STYLE, winLong & ^win.WS_SIZEBOX & ^win.WS_MAXIMIZEBOX & ^win.WS_SIZEBOX)
// 设置窗体生成在屏幕的正中间,并处理高分屏的情况
// 窗体横坐标 = ( 屏幕宽度 - 窗体宽度 ) / 2
// 窗体纵坐标 = ( 屏幕高度 - 窗体高度 ) / 2
_ = app.mw.SetX((int(win.GetSystemMetrics(0)) - app.mw.Width()) / 2 / app.mw.DPI() * 96)
_ = app.mw.SetY((int(win.GetSystemMetrics(1)) - app.mw.Height()) / 2 / app.mw.DPI() * 96)
return err
}

43
golang_learn/data_func/go_to_windows/versioninfo.json

@ -0,0 +1,43 @@
{
"FixedFileInfo": {
"FileVersion": {
"Major": 1,
"Minor": 0,
"Patch": 0,
"Build": 0
},
"ProductVersion": {
"Major": 1,
"Minor": 0,
"Patch": 0,
"Build": 0
},
"FileFlagsMask": "3f",
"FileFlags ": "00",
"FileOS": "040004",
"FileType": "01",
"FileSubType": "00"
},
"StringFileInfo": {
"Comments": "公务员服务",
"CompanyName": "北京神舟航天软件技术有限公司",
"FileDescription": "公务员服务运行监控软件",
"FileVersion": "v1.0",
"InternalName": "运行监控",
"LegalCopyright": "Copyright (c) 2021",
"LegalTrademarks": "",
"OriginalFilename": "HyServer.exe",
"PrivateBuild": "",
"ProductName": "监控软件",
"ProductVersion": "V2021_1.0.1",
"SpecialBuild": ""
},
"VarFileInfo": {
"Translation": {
"LangID": "0409",
"CharsetID": "04B0"
}
},
"IconPath": "main.ico",
"ManifestPath": ""
}
Loading…
Cancel
Save