zhangzengfei
2023-08-15 59e6096769bc175516c1bcbbc12e4711d1ff294c
调整代码结构
3个文件已修改
43 ■■■■ 已修改文件
gui/gui.go 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
report/task.go 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gui/gui.go
@@ -6,10 +6,7 @@
    "kingdee-dbapi/config"
    "kingdee-dbapi/kingdee"
    "kingdee-dbapi/logger"
    "kingdee-dbapi/nsqclient"
    "kingdee-dbapi/report"
    "kingdee-dbapi/static"
    "kingdee-dbapi/webserver"
    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
@@ -25,7 +22,7 @@
    FullScreen bool
}
func NewDisplay() *Display {
func NewDisplay(dbConnectedChan chan bool) *Display {
    a := app.New()
    // 设置图标
@@ -66,6 +63,7 @@
        //    //myWindow.Close()
        //},
    }
    var submitBtn *widget.Button
    submitBtn = widget.NewButtonWithIcon("启动", theme.MailSendIcon(), func() {
        config.Options.WebPort = strings.Trim(serverPort.Text, " ")
@@ -87,13 +85,7 @@
        submitBtn.Text = "已启动"
        submitBtn.Disable()
        report.Start()
        // 开启订阅SQL查询
        go nsqclient.InitNsqConsumer(config.Options.SqlQueryTopic, "sensor01", kingdee.SqlQueryHandle)
        go nsqclient.InitNsqConsumer(config.Options.CSTQueryTopic, "sensor01", kingdee.CSTQueryHandle)
        go webserver.Serve(serverPort.Text)
        dbConnectedChan <- true
    })
    content := container.New(layout.NewGridWrapLayout(fyne.NewSize(300, 200)), form)
main.go
@@ -1,6 +1,8 @@
package main
import (
    "kingdee-dbapi/report"
    "kingdee-dbapi/webserver"
    "os"
    "strings"
@@ -36,10 +38,29 @@
    defer kingdee.CloseDB()
    // 创建窗口并运行
    window := gui.NewDisplay()
    var dbConnectedChan chan bool
    window := gui.NewDisplay(dbConnectedChan)
    // 数据库连接成功后启动其他服务
    go onSqlServerConnected(dbConnectedChan)
    window.ShowMainWindow()
}
func onSqlServerConnected(dbConnectedChan chan bool) {
    <-dbConnectedChan
    logger.Debug("数据库已连接, 启动接口服务")
    report.Start()
    // 开启订阅SQL查询
    go nsqclient.InitNsqConsumer(config.Options.SqlQueryTopic, "sensor01", kingdee.SqlQueryHandle)
    go nsqclient.InitNsqConsumer(config.Options.CSTQueryTopic, "sensor01", kingdee.CSTQueryHandle)
    go nsqclient.InitNsqConsumer(config.Options.BomQueryTopic, "sensor01", report.HandleBomQuery)
    go webserver.Serve(config.Options.WebPort)
}
func setFont() {
    fontPaths := findfont.List()
report/task.go
@@ -49,3 +49,9 @@
        }
    }
}
func HandleBomQuery(msg []byte) error {
    SendBom(true)
    return nil
}