更新无选项情况

This commit is contained in:
wh_zcy 2022-09-26 22:48:47 +08:00
parent bd838c974d
commit 49df61b4e0
7 changed files with 151 additions and 29 deletions

View File

@ -2,10 +2,11 @@ package service
import ( import (
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"log"
"net" "net"
"os" "os"
"path"
"time" "time"
"github.com/pkg/sftp" "github.com/pkg/sftp"
@ -111,25 +112,80 @@ func (ss *SSHService) RunShell(shell string) {
} }
func (ss *SSHService) Scp(srcFileName, targetFileName string) (int64, error) { //单个copy
func (ss *SSHService) ScpCopy(localFilePath, remoteDir string) error {
var (
err error
)
sftpClient, err := sftp.NewClient(ss.Client)
if err != nil {
return fmt.Errorf("new sftp client error: %w", err)
}
defer sftpClient.Close()
srcFile, err := os.Open(localFilePath)
if err != nil {
log.Println("scpCopy:", err)
return err
}
defer srcFile.Close()
var remoteFileName = path.Base(localFilePath)
dstFile, err := sftpClient.Create(path.Join(remoteDir, remoteFileName))
if err != nil {
log.Println("scpCopy:", err)
return err
}
defer dstFile.Close()
buf := make([]byte, 1024)
for {
n, _ := srcFile.Read(buf)
if n == 0 {
break
}
dstFile.Write(buf[0:n])
}
return nil
}
func (ss *SSHService) Scp(targetDir, srcFileName string) (int, error) {
sftpClient, err := sftp.NewClient(ss.Client) sftpClient, err := sftp.NewClient(ss.Client)
if err != nil { if err != nil {
return 0, fmt.Errorf("new sftp client error: %w", err) return 0, fmt.Errorf("new sftp client error: %w", err)
} }
defer sftpClient.Close() defer sftpClient.Close()
source, err := sftpClient.Open(srcFileName) // source, err := sftpClient.Open(srcFileName)
if err != nil { // if err != nil {
return 0, fmt.Errorf("sftp client open src file error: %w", err) // return 0, fmt.Errorf("sftp client open src file error: %w", err)
} // }
defer source.Close() // defer source.Close()
target, err := os.OpenFile(targetFileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) srcFile, err := os.Open(srcFileName)
if err != nil { if err != nil {
return 0, fmt.Errorf("open local file error: %w", err) return 0, fmt.Errorf("open local file error: %w", err)
} }
defer target.Close() defer srcFile.Close()
n, err := io.Copy(target, source)
var remoteFileName = path.Base(srcFileName)
dstFile, err := sftpClient.Create(path.Join(targetDir, remoteFileName))
if err != nil {
fmt.Errorf("scpCopy:%v", err)
return 0, err
}
// n, err := io.Copy(target, source)
if err != nil { if err != nil {
return 0, fmt.Errorf("copy file error: %w", err) return 0, fmt.Errorf("copy file error: %w", err)
} }
defer dstFile.Close()
buf := make([]byte, 1024)
n := 0
for {
n, _ = srcFile.Read(buf)
if n == 0 {
break
}
dstFile.Write(buf[0:n])
}
return n, nil return n, nil
} }

View File

@ -37,11 +37,8 @@ func TestScp(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if n, err := ssh.Scp("E:\\svn\\dreamworks\\client\\dreamworks\\ExcelFile\\check.bat", if err := ssh.ScpCopy(`E:/svn/dreamworks/client/dreamworks/ExcelFile/check.bat`, "/opt"); err != nil {
"/opt"); err != nil {
fmt.Println(err) fmt.Println(err)
} else {
fmt.Println(n)
} }
} }

View File

@ -33,6 +33,8 @@ func (this *RtaskListView) CreateView(t *model.TestCase) fyne.CanvasObject {
input.PlaceHolder = "分组编号" input.PlaceHolder = "分组编号"
this.form.AppendItem(widget.NewFormItem("", input)) this.form.AppendItem(widget.NewFormItem("", input))
// task list button // task list button
taskListBtn := widget.NewButtonWithIcon("任务列表", theme.ConfirmIcon(), func() { taskListBtn := widget.NewButtonWithIcon("任务列表", theme.ConfirmIcon(), func() {
if input.Text == "" { if input.Text == "" {
@ -46,9 +48,14 @@ func (this *RtaskListView) CreateView(t *model.TestCase) fyne.CanvasObject {
} }
}) })
//修改结果
resultBtn := widget.NewButtonWithIcon("修改结果", theme.ConfirmIcon(), func() {
})
// layout // layout
split := container.NewHSplit(this.dataListWidget, container.NewVBox(this.form, taskListBtn)) split := container.NewHSplit(this.dataListWidget, container.NewVBox(this.form, taskListBtn, resultBtn))
split.Offset = 1 split.Offset = 0.7
//data listener for //data listener for
this.dataListener() this.dataListener()

View File

@ -25,10 +25,19 @@ func (this *RtaskTestView) CreateView(t *model.TestCase) fyne.CanvasObject {
condiInput := widget.NewEntry() condiInput := widget.NewEntry()
condiInput.PlaceHolder = "条件ID为空时走触发逻辑否则走校验逻辑" condiInput.PlaceHolder = "条件ID为空时走触发逻辑否则走校验逻辑"
res := widget.NewEntry()
res.PlaceHolder = "已完成任务列表"
input := widget.NewEntry()
input.PlaceHolder = "分组编号"
this.form.AppendItem(widget.NewFormItem("任务类型", rtaskTypeInput)) this.form.AppendItem(widget.NewFormItem("任务类型", rtaskTypeInput))
this.form.AppendItem(widget.NewFormItem("参数", paramsInput)) this.form.AppendItem(widget.NewFormItem("参数", paramsInput))
this.form.AppendItem(widget.NewFormItem("条件ID", condiInput)) this.form.AppendItem(widget.NewFormItem("条件ID", condiInput))
this.form.AppendItem(widget.NewFormItem("分组编号", input))
this.form.AppendItem(widget.NewFormItem("任务列表", res))
this.form.OnSubmit = func() { this.form.OnSubmit = func() {
// if rtaskTypeInput.Text == "" { // if rtaskTypeInput.Text == "" {
// dialog.ShowError(errors.New("请填写任务类型ID"), this.w) // dialog.ShowError(errors.New("请填写任务类型ID"), this.w)

View File

@ -44,13 +44,31 @@ func (this *apiComp) BattleFinish(session comm.IUserSession, req *pb.RtaskBattle
ok bool ok bool
) )
if frtaskArr, ok = rtask.FrtaskIds[conf.Group]; ok { // 查找任务组
//验证该任务是否已完成 if frtaskArr, ok = rtask.FrtaskIds[conf.Group]; !ok {
if _, ok := utils.Findx(frtaskArr.RtaskIds, req.RtaskId); ok { frtaskArr = &pb.FrtaskIds{}
for _, v := range sideConf.Reward { }
if v.ChooseId == 0 {
this.moduleRtask.DispenseRes(session, v.Reward, true) if _, ok := utils.Findx(frtaskArr.RtaskIds, req.RtaskId); !ok {
} // 更新完成的任务
frtaskArr.RtaskIds = append(frtaskArr.RtaskIds, req.RtaskId)
if rtask.FrtaskIds == nil {
rtask.FrtaskIds = make(map[int32]*pb.FrtaskIds)
}
rtask.FrtaskIds[conf.Group] = frtaskArr
update := map[string]interface{}{
"frtaskIds": rtask.FrtaskIds,
}
if err := this.moduleRtask.modelRtask.Change(session.GetUserId(), update); err != nil {
code = pb.ErrorCode_SystemError
return
}
// 发奖
for _, v := range sideConf.Reward {
if v.ChooseId == 0 {
this.moduleRtask.DispenseRes(session, v.Reward, true)
} }
} }
} }

View File

@ -26,6 +26,22 @@ func (this *apiComp) Rtest(session comm.IUserSession, req *pb.RtaskTestReq) (cod
} }
} }
if req.GroupId != 0 {
// 获取当前玩家
rtask := this.moduleRtask.modelRtask.GetRtask(session.GetUserId())
if rtask == nil {
code = pb.ErrorCode_RtaskNoRtask
return
}
ids := make([]int32, 0)
if v, ok := rtask.FrtaskIds[req.GroupId]; ok {
ids = v.RtaskIds
}
rsp.RtaskIds = ids
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), "rtest", rsp); err != nil { if err := session.SendMsg(string(this.moduleRtask.GetType()), "rtest", rsp); err != nil {
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
} }

View File

@ -821,6 +821,7 @@ type RtaskTestReq struct {
RtaskType int32 `protobuf:"varint,1,opt,name=rtaskType,proto3" json:"rtaskType"` //任务类型 RtaskType int32 `protobuf:"varint,1,opt,name=rtaskType,proto3" json:"rtaskType"` //任务类型
Params []int32 `protobuf:"varint,2,rep,packed,name=params,proto3" json:"params"` //参数 Params []int32 `protobuf:"varint,2,rep,packed,name=params,proto3" json:"params"` //参数
CondiId int32 `protobuf:"varint,3,opt,name=condiId,proto3" json:"condiId"` //条件ID CondiId int32 `protobuf:"varint,3,opt,name=condiId,proto3" json:"condiId"` //条件ID
GroupId int32 `protobuf:"varint,4,opt,name=groupId,proto3" json:"groupId"` //分组编号
} }
func (x *RtaskTestReq) Reset() { func (x *RtaskTestReq) Reset() {
@ -876,12 +877,20 @@ func (x *RtaskTestReq) GetCondiId() int32 {
return 0 return 0
} }
func (x *RtaskTestReq) GetGroupId() int32 {
if x != nil {
return x.GroupId
}
return 0
}
type RtaskTestResp struct { type RtaskTestResp struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Flag bool `protobuf:"varint,1,opt,name=flag,proto3" json:"flag"` Flag bool `protobuf:"varint,1,opt,name=flag,proto3" json:"flag"`
RtaskIds []int32 `protobuf:"varint,2,rep,packed,name=rtaskIds,proto3" json:"rtaskIds"`
} }
func (x *RtaskTestResp) Reset() { func (x *RtaskTestResp) Reset() {
@ -923,6 +932,13 @@ func (x *RtaskTestResp) GetFlag() bool {
return false return false
} }
func (x *RtaskTestResp) GetRtaskIds() []int32 {
if x != nil {
return x.RtaskIds
}
return nil
}
var File_rtask_rtask_msg_proto protoreflect.FileDescriptor var File_rtask_rtask_msg_proto protoreflect.FileDescriptor
var file_rtask_rtask_msg_proto_rawDesc = []byte{ var file_rtask_rtask_msg_proto_rawDesc = []byte{
@ -995,16 +1011,19 @@ var file_rtask_rtask_msg_proto_rawDesc = []byte{
0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x26, 0x0a, 0x06, 0x72, 0x65, 0x63, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x26, 0x0a, 0x06, 0x72, 0x65, 0x63,
0x6f, 0x72, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x52, 0x74, 0x6f, 0x72, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x52, 0x74,
0x61, 0x73, 0x6b, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x61, 0x73, 0x6b, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f, 0x72,
0x64, 0x22, 0x5e, 0x0a, 0x0c, 0x52, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x64, 0x22, 0x78, 0x0a, 0x0c, 0x52, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65,
0x71, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01,
0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x72, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x12, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x72, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x12,
0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x05, 0x52, 0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x05, 0x52,
0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x64, 0x69,
0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x49, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x49,
0x64, 0x22, 0x23, 0x0a, 0x0d, 0x52, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01,
0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x6c, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x28, 0x05, 0x52, 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64, 0x22, 0x3f, 0x0a, 0x0d, 0x52,
0x52, 0x04, 0x66, 0x6c, 0x61, 0x67, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x66, 0x6c, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x66, 0x6c, 0x61, 0x67,
0x12, 0x1a, 0x0a, 0x08, 0x72, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03,
0x28, 0x05, 0x52, 0x08, 0x72, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x73, 0x42, 0x06, 0x5a, 0x04,
0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (