清空数据菜单

This commit is contained in:
wh_zcy 2022-12-12 20:37:06 +08:00
parent fc643448a9
commit 7047776238
6 changed files with 68 additions and 19 deletions

View File

@ -15,8 +15,8 @@ type LoginScene struct {
func (l *LoginScene) Info() lib.SceneInfo {
return lib.SceneInfo{
Name: "login",
Desc: "登录",
Name: "登录",
Desc: "user.login",
}
}

View File

@ -16,7 +16,8 @@ type myAI struct {
tickets Tickets //票池
robotCount uint32 //机器人数量
lock sync.Mutex //
config *storage.Config //
config *storage.Config //配置
}
func NewAI(aip AIParam) (*myAI, error) {
@ -59,7 +60,6 @@ func (m *myAI) init() error {
// Deprecated
func (m *myAI) LoadCallers() []IScene {
return m.iscenes
}
// 根据场景名称获取场景接口

View File

@ -25,11 +25,32 @@ type SceneInfo struct {
Desc string
}
type CallResult struct {
ID int64 // ID。
Req RawReq // 原生请求。
Resp RawResp // 原生响应。
Code RetCode // 响应代码。
Msg string // 结果成因的简述。
Elapse time.Duration // 耗时。
}
const (
//默认的机器人数量
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 (
// STATUS_ORIGINAL 代表原始。

View File

@ -1,6 +1,7 @@
package lib
import (
"sort"
"strings"
"sync"
"sync/atomic"
@ -35,7 +36,9 @@ type Robot struct {
status uint32 //状态
lock sync.Mutex //
sceneQueue *Queue[IScene] //场景队列
config *storage.Config
config *storage.Config //配置
//
resultCh chan *CallResult
}
func NewRobot(config *storage.Config) *Robot {
@ -43,6 +46,7 @@ func NewRobot(config *storage.Config) *Robot {
data: make(map[string]interface{}),
sceneQueue: NewQueue[IScene](),
config: config,
resultCh: make(chan *CallResult, 50),
}
robot.Store("sid", config.Global.SId)
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 {
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}
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) {
break
}
logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "rsp": rsp}).Debug("接收消息")
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) {
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 {
info := v.Info()
if conf.Name == info.Name {
@ -187,11 +198,11 @@ func (m *Robot) syncCall() {
}
elapsedTime := time.Since(start)
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 {
msg := &pb.UserMessage{}
if err := proto.Unmarshal(data, msg); err != nil {

View File

@ -17,9 +17,10 @@ type mainMenu struct {
quite *fyne.MenuItem
//工具
toolMenu *fyne.Menu
importCM *fyne.MenuItem //导入配置
exportCM *fyne.MenuItem //导出配置
toolMenu *fyne.Menu
importMenu *fyne.MenuItem //导入配置
exportMenu *fyne.MenuItem //导出配置
clearMenu *fyne.MenuItem //清空数据
}
func newMainMenu() *mainMenu {
@ -49,17 +50,21 @@ func newMainMenu() *mainMenu {
mm.quite)
// 导入配置
mm.importCM = fyne.NewMenuItem("导入配置", globalWindow.ImportConfigWindow)
mm.importCM.Icon = theme.FileApplicationIcon()
mm.importMenu = fyne.NewMenuItem("导入配置", globalWindow.ImportConfigWindow)
mm.importMenu.Icon = theme.FileApplicationIcon()
mm.exportCM = fyne.NewMenuItem("导出配置", globalWindow.ExportConfigWindow)
mm.exportCM.Icon = theme.FileApplicationIcon()
mm.exportMenu = fyne.NewMenuItem("导出配置", globalWindow.ExportConfigWindow)
mm.exportMenu.Icon = theme.FileApplicationIcon()
mm.clearMenu = fyne.NewMenuItem("清空数据", globalWindow.ClearData)
mm.clearMenu.Icon = theme.FileApplicationIcon()
// 工具
mm.toolMenu = fyne.NewMenu("工具")
mm.toolMenu.Items = append(mm.toolMenu.Items,
mm.importCM,
mm.exportCM,
mm.importMenu,
mm.exportMenu,
mm.clearMenu,
)
mm.MainMenu = fyne.NewMainMenu(

View File

@ -847,6 +847,18 @@ func (mw *MainWindow) ImportConfigWindow() {
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() {
dialog.ShowCustomConfirm("提示", "确定", "取消", widget.NewLabel("确定退出吗"), func(b bool) {