mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 13:10:26 +08:00 
			
		
		
		
	通知媒介增加任务队列查看功能
This commit is contained in:
		
							
								
								
									
										103
									
								
								internal/web/actions/default/admins/recipients/tasks/index.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								internal/web/actions/default/admins/recipients/tasks/index.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,103 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
 | 
			
		||||
package tasks
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
	timeutil "github.com/iwind/TeaGo/utils/time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type IndexAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *IndexAction) Init() {
 | 
			
		||||
	this.Nav("", "", "task")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *IndexAction) RunGet(params struct {
 | 
			
		||||
	Status int32
 | 
			
		||||
}) {
 | 
			
		||||
	this.Data["status"] = params.Status
 | 
			
		||||
	if params.Status > 3 {
 | 
			
		||||
		params.Status = 0
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	countWaitingResp, err := this.RPC().MessageTaskRPC().CountMessageTasksWithStatus(this.AdminContext(), &pb.CountMessageTasksWithStatusRequest{Status: pb.CountMessageTasksWithStatusRequest_MessageTaskStatusNone})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var countWaiting = countWaitingResp.Count
 | 
			
		||||
	this.Data["countWaiting"] = countWaiting
 | 
			
		||||
 | 
			
		||||
	countFailedResp, err := this.RPC().MessageTaskRPC().CountMessageTasksWithStatus(this.AdminContext(), &pb.CountMessageTasksWithStatusRequest{Status: pb.CountMessageTasksWithStatusRequest_MessageTaskStatusFailed})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var countFailed = countFailedResp.Count
 | 
			
		||||
	this.Data["countFailed"] = countFailed
 | 
			
		||||
 | 
			
		||||
	// 列表
 | 
			
		||||
	var total = int64(0)
 | 
			
		||||
	switch params.Status {
 | 
			
		||||
	case 0:
 | 
			
		||||
		total = countWaiting
 | 
			
		||||
	case 3:
 | 
			
		||||
		total = countFailed
 | 
			
		||||
	}
 | 
			
		||||
	page := this.NewPage(total)
 | 
			
		||||
	this.Data["page"] = page.AsHTML()
 | 
			
		||||
 | 
			
		||||
	var taskMaps = []maps.Map{}
 | 
			
		||||
	tasksResp, err := this.RPC().MessageTaskRPC().ListMessageTasksWithStatus(this.AdminContext(), &pb.ListMessageTasksWithStatusRequest{
 | 
			
		||||
		Status: pb.ListMessageTasksWithStatusRequest_Status(params.Status),
 | 
			
		||||
		Offset: page.Offset,
 | 
			
		||||
		Size:   page.Size,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	for _, task := range tasksResp.MessageTasks {
 | 
			
		||||
		var resultMap = maps.Map{}
 | 
			
		||||
		var result = task.Result
 | 
			
		||||
		if result != nil {
 | 
			
		||||
			resultMap = maps.Map{
 | 
			
		||||
				"isOk":     result.IsOk,
 | 
			
		||||
				"error":    result.Error,
 | 
			
		||||
				"response": result.Response,
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//var recipients = []string{}
 | 
			
		||||
		var user = ""
 | 
			
		||||
		var instanceMap maps.Map
 | 
			
		||||
		if task.MessageRecipient != nil {
 | 
			
		||||
			user = task.MessageRecipient.User
 | 
			
		||||
			if task.MessageRecipient.MessageMediaInstance != nil {
 | 
			
		||||
				instanceMap = maps.Map{
 | 
			
		||||
					"id":   task.MessageRecipient.MessageMediaInstance.Id,
 | 
			
		||||
					"name": task.MessageRecipient.MessageMediaInstance.Name,
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		taskMaps = append(taskMaps, maps.Map{
 | 
			
		||||
			"id":          task.Id,
 | 
			
		||||
			"subject":     task.Subject,
 | 
			
		||||
			"body":        task.Body,
 | 
			
		||||
			"createdTime": timeutil.FormatTime("Y-m-d H:i:s", task.CreatedAt),
 | 
			
		||||
			"result":      resultMap,
 | 
			
		||||
			"status":      task.Status,
 | 
			
		||||
			"user":        user,
 | 
			
		||||
			"instance":    instanceMap,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	this.Data["tasks"] = taskMaps
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
@@ -13,6 +13,7 @@ func init() {
 | 
			
		||||
			Data("teaMenu", "admins").
 | 
			
		||||
			Data("teaSubMenu", "recipients").
 | 
			
		||||
			Prefix("/admins/recipients/tasks").
 | 
			
		||||
			Get("", new(IndexAction)).
 | 
			
		||||
			Post("/taskInfo", new(TaskInfoAction)).
 | 
			
		||||
			EndAll()
 | 
			
		||||
	})
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@
 | 
			
		||||
Vue.component("menu-item", {
 | 
			
		||||
	props: ["href", "active", "code"],
 | 
			
		||||
	data: function () {
 | 
			
		||||
		var active = this.active
 | 
			
		||||
		let active = this.active
 | 
			
		||||
		if (typeof (active) == "undefined") {
 | 
			
		||||
			var itemCode = ""
 | 
			
		||||
			if (typeof (window.TEA.ACTION.data.firstMenuItem) != "undefined") {
 | 
			
		||||
@@ -18,8 +18,19 @@ Vue.component("menu-item", {
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		let href = (this.href == null) ? "" : this.href
 | 
			
		||||
		if (typeof (href) == "string" && href.length > 0 && href.startsWith(".")) {
 | 
			
		||||
			let qIndex = href.indexOf("?")
 | 
			
		||||
			if (qIndex >= 0) {
 | 
			
		||||
				href = Tea.url(href.substring(0, qIndex)) + href.substring(qIndex)
 | 
			
		||||
			} else {
 | 
			
		||||
				href = Tea.url(href)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return {
 | 
			
		||||
			vHref: (this.href == null) ? "" : this.href,
 | 
			
		||||
			vHref: href,
 | 
			
		||||
			vActive: active
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
 
 | 
			
		||||
@@ -3,4 +3,5 @@
 | 
			
		||||
    <menu-item href="/admins/recipients/groups" code="group">接收人分组</menu-item>
 | 
			
		||||
    <menu-item href="/admins/recipients/instances" code="instance">媒介</menu-item>
 | 
			
		||||
    <menu-item href="/admins/recipients/logs" code="log">发送记录</menu-item>
 | 
			
		||||
    <menu-item href="/admins/recipients/tasks" code="task">任务队列</menu-item>
 | 
			
		||||
</first-menu>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										37
									
								
								web/views/@default/admins/recipients/tasks/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								web/views/@default/admins/recipients/tasks/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
{$layout}
 | 
			
		||||
{$template "../menu"}
 | 
			
		||||
 | 
			
		||||
<second-menu>
 | 
			
		||||
    <menu-item href=".?status=0" :active="status == 0">等待发送({{countWaiting}})</menu-item>
 | 
			
		||||
    <menu-item href=".?status=3" :active="status == 3">发送错误({{countFailed}})</menu-item>
 | 
			
		||||
</second-menu>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<p class="comment" v-if="tasks.length == 0">暂时还没有发送任务。</p>
 | 
			
		||||
 | 
			
		||||
<div v-if="tasks.length > 0">
 | 
			
		||||
    <div class="margin"></div>
 | 
			
		||||
    <table class="ui table selectable definition" v-for="task in tasks">
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td class="title">简介</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                {{task.user}} <span class="disabled">  |  </span> <span v-if="task.instance != null">媒介:{{task.instance.name}}<link-icon :href="'/admins/recipients/instances/instance?instanceId=' + task.instance.id"></link-icon></span>
 | 
			
		||||
                <span class="disabled">  |  </span> 时间:{{task.createdTime}}
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr v-if="task.subject.length > 0">
 | 
			
		||||
            <td>标题</td>
 | 
			
		||||
            <td>{{task.subject}}</td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr v-if="task.body.length > 0">
 | 
			
		||||
            <td>内容</td>
 | 
			
		||||
            <td>{{task.body}}</td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr v-if="task.status == 3 && task.result != null && !task.result.isOk" class="error">
 | 
			
		||||
            <td>错误信息</td>
 | 
			
		||||
            <td>{{task.result.error}}</td>
 | 
			
		||||
        </tr>
 | 
			
		||||
    </table>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div class="page" v-html="page"></div>
 | 
			
		||||
		Reference in New Issue
	
	Block a user