更新无选项情况
This commit is contained in:
parent
bd838c974d
commit
49df61b4e0
@ -2,10 +2,11 @@ package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"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)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("new sftp client error: %w", err)
|
||||
}
|
||||
defer sftpClient.Close()
|
||||
source, err := sftpClient.Open(srcFileName)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("sftp client open src file error: %w", err)
|
||||
}
|
||||
defer source.Close()
|
||||
target, err := os.OpenFile(targetFileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
// source, err := sftpClient.Open(srcFileName)
|
||||
// if err != nil {
|
||||
// return 0, fmt.Errorf("sftp client open src file error: %w", err)
|
||||
// }
|
||||
// defer source.Close()
|
||||
srcFile, err := os.Open(srcFileName)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("open local file error: %w", err)
|
||||
}
|
||||
defer target.Close()
|
||||
n, err := io.Copy(target, source)
|
||||
defer srcFile.Close()
|
||||
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
@ -37,11 +37,8 @@ func TestScp(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if n, err := ssh.Scp("E:\\svn\\dreamworks\\client\\dreamworks\\ExcelFile\\check.bat",
|
||||
"/opt"); err != nil {
|
||||
if err := ssh.ScpCopy(`E:/svn/dreamworks/client/dreamworks/ExcelFile/check.bat`, "/opt"); err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(n)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ func (this *RtaskListView) CreateView(t *model.TestCase) fyne.CanvasObject {
|
||||
input.PlaceHolder = "分组编号"
|
||||
this.form.AppendItem(widget.NewFormItem("", input))
|
||||
|
||||
|
||||
|
||||
// task list button
|
||||
taskListBtn := widget.NewButtonWithIcon("任务列表", theme.ConfirmIcon(), func() {
|
||||
if input.Text == "" {
|
||||
@ -46,9 +48,14 @@ func (this *RtaskListView) CreateView(t *model.TestCase) fyne.CanvasObject {
|
||||
}
|
||||
})
|
||||
|
||||
//修改结果
|
||||
resultBtn := widget.NewButtonWithIcon("修改结果", theme.ConfirmIcon(), func() {
|
||||
|
||||
})
|
||||
|
||||
// layout
|
||||
split := container.NewHSplit(this.dataListWidget, container.NewVBox(this.form, taskListBtn))
|
||||
split.Offset = 1
|
||||
split := container.NewHSplit(this.dataListWidget, container.NewVBox(this.form, taskListBtn, resultBtn))
|
||||
split.Offset = 0.7
|
||||
|
||||
//data listener for
|
||||
this.dataListener()
|
||||
|
@ -25,10 +25,19 @@ func (this *RtaskTestView) CreateView(t *model.TestCase) fyne.CanvasObject {
|
||||
condiInput := widget.NewEntry()
|
||||
condiInput.PlaceHolder = "条件ID为空时走触发逻辑否则走校验逻辑"
|
||||
|
||||
res := widget.NewEntry()
|
||||
res.PlaceHolder = "已完成任务列表"
|
||||
|
||||
input := widget.NewEntry()
|
||||
input.PlaceHolder = "分组编号"
|
||||
|
||||
this.form.AppendItem(widget.NewFormItem("任务类型", rtaskTypeInput))
|
||||
this.form.AppendItem(widget.NewFormItem("参数", paramsInput))
|
||||
this.form.AppendItem(widget.NewFormItem("条件ID", condiInput))
|
||||
|
||||
this.form.AppendItem(widget.NewFormItem("分组编号", input))
|
||||
this.form.AppendItem(widget.NewFormItem("任务列表", res))
|
||||
|
||||
this.form.OnSubmit = func() {
|
||||
// if rtaskTypeInput.Text == "" {
|
||||
// dialog.ShowError(errors.New("请填写任务类型ID"), this.w)
|
||||
|
@ -44,13 +44,31 @@ func (this *apiComp) BattleFinish(session comm.IUserSession, req *pb.RtaskBattle
|
||||
ok bool
|
||||
)
|
||||
|
||||
if frtaskArr, ok = rtask.FrtaskIds[conf.Group]; ok {
|
||||
//验证该任务是否已完成
|
||||
if _, ok := utils.Findx(frtaskArr.RtaskIds, req.RtaskId); ok {
|
||||
for _, v := range sideConf.Reward {
|
||||
if v.ChooseId == 0 {
|
||||
this.moduleRtask.DispenseRes(session, v.Reward, true)
|
||||
}
|
||||
// 查找任务组
|
||||
if frtaskArr, ok = rtask.FrtaskIds[conf.Group]; !ok {
|
||||
frtaskArr = &pb.FrtaskIds{}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
code = pb.ErrorCode_SystemError
|
||||
}
|
||||
|
@ -821,6 +821,7 @@ type RtaskTestReq struct {
|
||||
RtaskType int32 `protobuf:"varint,1,opt,name=rtaskType,proto3" json:"rtaskType"` //任务类型
|
||||
Params []int32 `protobuf:"varint,2,rep,packed,name=params,proto3" json:"params"` //参数
|
||||
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() {
|
||||
@ -876,12 +877,20 @@ func (x *RtaskTestReq) GetCondiId() int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *RtaskTestReq) GetGroupId() int32 {
|
||||
if x != nil {
|
||||
return x.GroupId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type RtaskTestResp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
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() {
|
||||
@ -923,6 +932,13 @@ func (x *RtaskTestResp) GetFlag() bool {
|
||||
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_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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
0x64, 0x22, 0x23, 0x0a, 0x0d, 0x52, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65,
|
||||
0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x6c, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08,
|
||||
0x52, 0x04, 0x66, 0x6c, 0x61, 0x67, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x64, 0x12, 0x18, 0x0a, 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01,
|
||||
0x28, 0x05, 0x52, 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64, 0x22, 0x3f, 0x0a, 0x0d, 0x52,
|
||||
0x74, 0x61, 0x73, 0x6b, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04,
|
||||
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 (
|
||||
|
Loading…
Reference in New Issue
Block a user