清空数据菜单
This commit is contained in:
parent
fc643448a9
commit
7047776238
@ -15,8 +15,8 @@ type LoginScene struct {
|
|||||||
|
|
||||||
func (l *LoginScene) Info() lib.SceneInfo {
|
func (l *LoginScene) Info() lib.SceneInfo {
|
||||||
return lib.SceneInfo{
|
return lib.SceneInfo{
|
||||||
Name: "login",
|
Name: "登录",
|
||||||
Desc: "登录",
|
Desc: "user.login",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@ type myAI struct {
|
|||||||
tickets Tickets //票池
|
tickets Tickets //票池
|
||||||
robotCount uint32 //机器人数量
|
robotCount uint32 //机器人数量
|
||||||
lock sync.Mutex //
|
lock sync.Mutex //
|
||||||
config *storage.Config //
|
config *storage.Config //配置
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAI(aip AIParam) (*myAI, error) {
|
func NewAI(aip AIParam) (*myAI, error) {
|
||||||
@ -59,7 +60,6 @@ func (m *myAI) init() error {
|
|||||||
// Deprecated
|
// Deprecated
|
||||||
func (m *myAI) LoadCallers() []IScene {
|
func (m *myAI) LoadCallers() []IScene {
|
||||||
return m.iscenes
|
return m.iscenes
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据场景名称获取场景接口
|
// 根据场景名称获取场景接口
|
||||||
|
21
lib/base.go
21
lib/base.go
@ -25,11 +25,32 @@ type SceneInfo struct {
|
|||||||
Desc string
|
Desc string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CallResult struct {
|
||||||
|
ID int64 // ID。
|
||||||
|
Req RawReq // 原生请求。
|
||||||
|
Resp RawResp // 原生响应。
|
||||||
|
Code RetCode // 响应代码。
|
||||||
|
Msg string // 结果成因的简述。
|
||||||
|
Elapse time.Duration // 耗时。
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
//默认的机器人数量
|
//默认的机器人数量
|
||||||
DefaultRobotNum int = 10
|
DefaultRobotNum int = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RetCode 表示结果代码的类型。
|
||||||
|
type RetCode int
|
||||||
|
|
||||||
|
const (
|
||||||
|
RET_CODE_SUCCESS RetCode = 0 // 成功。
|
||||||
|
RET_CODE_WARNING_CALL_TIMEOUT = 1001 // 调用超时警告。
|
||||||
|
RET_CODE_ERROR_CALL = 2001 // 调用错误。
|
||||||
|
RET_CODE_ERROR_RESPONSE = 2002 // 响应内容错误。
|
||||||
|
RET_CODE_ERROR_CALEE = 2003 // 被调用方(被测软件)的内部错误。
|
||||||
|
RET_CODE_FATAL_CALL = 3001 // 调用过程中发生了致命错误!
|
||||||
|
)
|
||||||
|
|
||||||
//机器人状态
|
//机器人状态
|
||||||
const (
|
const (
|
||||||
// STATUS_ORIGINAL 代表原始。
|
// STATUS_ORIGINAL 代表原始。
|
||||||
|
23
lib/robot.go
23
lib/robot.go
@ -1,6 +1,7 @@
|
|||||||
package lib
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -35,7 +36,9 @@ type Robot struct {
|
|||||||
status uint32 //状态
|
status uint32 //状态
|
||||||
lock sync.Mutex //
|
lock sync.Mutex //
|
||||||
sceneQueue *Queue[IScene] //场景队列
|
sceneQueue *Queue[IScene] //场景队列
|
||||||
config *storage.Config
|
config *storage.Config //配置
|
||||||
|
//
|
||||||
|
resultCh chan *CallResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRobot(config *storage.Config) *Robot {
|
func NewRobot(config *storage.Config) *Robot {
|
||||||
@ -43,6 +46,7 @@ func NewRobot(config *storage.Config) *Robot {
|
|||||||
data: make(map[string]interface{}),
|
data: make(map[string]interface{}),
|
||||||
sceneQueue: NewQueue[IScene](),
|
sceneQueue: NewQueue[IScene](),
|
||||||
config: config,
|
config: config,
|
||||||
|
resultCh: make(chan *CallResult, 50),
|
||||||
}
|
}
|
||||||
robot.Store("sid", config.Global.SId)
|
robot.Store("sid", config.Global.SId)
|
||||||
return robot
|
return robot
|
||||||
@ -65,7 +69,10 @@ func (a *Robot) Get(key string) interface{} {
|
|||||||
// 发送消息
|
// 发送消息
|
||||||
func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.Message) pb.ErrorCode {
|
func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.Message) pb.ErrorCode {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
defer time.Since(start)
|
defer func() {
|
||||||
|
t := time.Since(start)
|
||||||
|
logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "rsp": rsp, "since": t}).Debug("接收消息")
|
||||||
|
}()
|
||||||
|
|
||||||
head := &pb.UserMessage{MainType: mainType, SubType: subType}
|
head := &pb.UserMessage{MainType: mainType, SubType: subType}
|
||||||
if mainType == "user" && subType == "login" {
|
if mainType == "user" && subType == "login" {
|
||||||
@ -100,7 +107,7 @@ func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.M
|
|||||||
if !ProtoUnmarshal(msg, rsp) {
|
if !ProtoUnmarshal(msg, rsp) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "rsp": rsp}).Debug("接收消息")
|
|
||||||
return pb.ErrorCode_Success
|
return pb.ErrorCode_Success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +118,11 @@ func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.M
|
|||||||
|
|
||||||
// 设置场景队列
|
// 设置场景队列
|
||||||
func (a *Robot) SetScenes(scenes []IScene) {
|
func (a *Robot) SetScenes(scenes []IScene) {
|
||||||
for _, conf := range a.config.Scenes {
|
scensConf := a.config.Scenes
|
||||||
|
sort.SliceStable(scensConf, func(i, j int) bool {
|
||||||
|
return scensConf[i].Num < scensConf[j].Num
|
||||||
|
})
|
||||||
|
for _, conf := range scensConf {
|
||||||
for _, v := range scenes {
|
for _, v := range scenes {
|
||||||
info := v.Info()
|
info := v.Info()
|
||||||
if conf.Name == info.Name {
|
if conf.Name == info.Name {
|
||||||
@ -187,11 +198,11 @@ func (m *Robot) syncCall() {
|
|||||||
}
|
}
|
||||||
elapsedTime := time.Since(start)
|
elapsedTime := time.Since(start)
|
||||||
info := scene.Info()
|
info := scene.Info()
|
||||||
logrus.WithField("耗时", elapsedTime.String()).Debug("场景【" + info.Name + "】执行完毕统计")
|
logrus.WithField("t", elapsedTime.String()).Debug("场景【" + info.Name + "】执行完毕耗时统计")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
func (m *Robot) checkResp(data []byte, rsp proto.Message) bool {
|
func (m *Robot) checkResp(data []byte, rsp proto.Message) bool {
|
||||||
msg := &pb.UserMessage{}
|
msg := &pb.UserMessage{}
|
||||||
if err := proto.Unmarshal(data, msg); err != nil {
|
if err := proto.Unmarshal(data, msg); err != nil {
|
||||||
|
@ -17,9 +17,10 @@ type mainMenu struct {
|
|||||||
quite *fyne.MenuItem
|
quite *fyne.MenuItem
|
||||||
|
|
||||||
//工具
|
//工具
|
||||||
toolMenu *fyne.Menu
|
toolMenu *fyne.Menu
|
||||||
importCM *fyne.MenuItem //导入配置
|
importMenu *fyne.MenuItem //导入配置
|
||||||
exportCM *fyne.MenuItem //导出配置
|
exportMenu *fyne.MenuItem //导出配置
|
||||||
|
clearMenu *fyne.MenuItem //清空数据
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMainMenu() *mainMenu {
|
func newMainMenu() *mainMenu {
|
||||||
@ -49,17 +50,21 @@ func newMainMenu() *mainMenu {
|
|||||||
mm.quite)
|
mm.quite)
|
||||||
|
|
||||||
// 导入配置
|
// 导入配置
|
||||||
mm.importCM = fyne.NewMenuItem("导入配置", globalWindow.ImportConfigWindow)
|
mm.importMenu = fyne.NewMenuItem("导入配置", globalWindow.ImportConfigWindow)
|
||||||
mm.importCM.Icon = theme.FileApplicationIcon()
|
mm.importMenu.Icon = theme.FileApplicationIcon()
|
||||||
|
|
||||||
mm.exportCM = fyne.NewMenuItem("导出配置", globalWindow.ExportConfigWindow)
|
mm.exportMenu = fyne.NewMenuItem("导出配置", globalWindow.ExportConfigWindow)
|
||||||
mm.exportCM.Icon = theme.FileApplicationIcon()
|
mm.exportMenu.Icon = theme.FileApplicationIcon()
|
||||||
|
|
||||||
|
mm.clearMenu = fyne.NewMenuItem("清空数据", globalWindow.ClearData)
|
||||||
|
mm.clearMenu.Icon = theme.FileApplicationIcon()
|
||||||
|
|
||||||
// 工具
|
// 工具
|
||||||
mm.toolMenu = fyne.NewMenu("工具")
|
mm.toolMenu = fyne.NewMenu("工具")
|
||||||
mm.toolMenu.Items = append(mm.toolMenu.Items,
|
mm.toolMenu.Items = append(mm.toolMenu.Items,
|
||||||
mm.importCM,
|
mm.importMenu,
|
||||||
mm.exportCM,
|
mm.exportMenu,
|
||||||
|
mm.clearMenu,
|
||||||
)
|
)
|
||||||
|
|
||||||
mm.MainMenu = fyne.NewMainMenu(
|
mm.MainMenu = fyne.NewMainMenu(
|
||||||
|
@ -847,6 +847,18 @@ func (mw *MainWindow) ImportConfigWindow() {
|
|||||||
importWin.Show()
|
importWin.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清空数据
|
||||||
|
func (mw *MainWindow) ClearData() {
|
||||||
|
empty := &storage.Config{}
|
||||||
|
mw.config = empty
|
||||||
|
if err := mw.storage.StoreConfig(empty); err != nil {
|
||||||
|
ShowTip(fmt.Sprintf("错误:%v", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mw.startContainer()
|
||||||
|
ShowTip("数据已清空")
|
||||||
|
}
|
||||||
|
|
||||||
// 退出
|
// 退出
|
||||||
func (mw *MainWindow) quiteHandle() {
|
func (mw *MainWindow) quiteHandle() {
|
||||||
dialog.ShowCustomConfirm("提示", "确定", "取消", widget.NewLabel("确定退出吗"), func(b bool) {
|
dialog.ShowCustomConfirm("提示", "确定", "取消", widget.NewLabel("确定退出吗"), func(b bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user