1.4.5.2
This commit is contained in:
138
EdgeAdmin/internal/web/actions/default/tickets/index.go
Normal file
138
EdgeAdmin/internal/web/actions/default/tickets/index.go
Normal file
@@ -0,0 +1,138 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package tickets
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
var status = this.Request.URL.Query().Get("status")
|
||||
if len(status) == 0 {
|
||||
status = "none"
|
||||
}
|
||||
this.Nav("", "", status)
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
UserId int64
|
||||
CategoryId int64
|
||||
Status string
|
||||
}) {
|
||||
if len(params.Status) == 0 {
|
||||
params.Status = "none"
|
||||
}
|
||||
|
||||
this.Data["status"] = params.Status
|
||||
this.Data["userId"] = params.UserId
|
||||
this.Data["categoryId"] = params.CategoryId
|
||||
this.Data["currentURL"] = url.QueryEscape(this.Request.URL.String())
|
||||
|
||||
// 处于新状态的数字
|
||||
countNewTicketsResp, err := this.RPC().UserTicketRPC().CountUserTickets(this.AdminContext(), &pb.CountUserTicketsRequest{
|
||||
UserId: params.UserId,
|
||||
Status: userconfigs.UserTicketStatusNone,
|
||||
UserTicketCategoryId: params.CategoryId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countNewTickets = countNewTicketsResp.Count
|
||||
this.Data["countNewTickets"] = countNewTickets
|
||||
|
||||
// 列表
|
||||
var page *actionutils.Page
|
||||
if params.Status == userconfigs.UserTicketStatusNone {
|
||||
page = this.NewPage(countNewTickets)
|
||||
} else {
|
||||
countTicketsRPC, err := this.RPC().UserTicketRPC().CountUserTickets(this.AdminContext(), &pb.CountUserTicketsRequest{
|
||||
UserId: params.UserId,
|
||||
UserTicketCategoryId: params.CategoryId,
|
||||
Status: params.Status,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countTicketsRPC.Count
|
||||
page = this.NewPage(count)
|
||||
}
|
||||
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
// 工单列表
|
||||
ticketsResp, err := this.RPC().UserTicketRPC().ListUserTickets(this.AdminContext(), &pb.ListUserTicketsRequest{
|
||||
UserId: params.UserId,
|
||||
UserTicketCategoryId: params.CategoryId,
|
||||
Status: params.Status,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var ticketMaps = []maps.Map{}
|
||||
for _, ticket := range ticketsResp.UserTickets {
|
||||
// category
|
||||
var categoryMap maps.Map
|
||||
if ticket.UserTicketCategory != nil {
|
||||
categoryMap = maps.Map{
|
||||
"id": ticket.UserTicketCategory.Id,
|
||||
"name": ticket.UserTicketCategory.Name,
|
||||
}
|
||||
}
|
||||
|
||||
// user
|
||||
var userMap maps.Map
|
||||
if ticket.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": ticket.User.Id,
|
||||
"username": ticket.User.Username,
|
||||
"fullname": ticket.User.Fullname,
|
||||
}
|
||||
}
|
||||
|
||||
// latest log
|
||||
var latestLogMap maps.Map
|
||||
if ticket.LatestUserTicketLog != nil {
|
||||
var logAdminMap maps.Map
|
||||
if ticket.LatestUserTicketLog.Admin != nil {
|
||||
logAdminMap = maps.Map{
|
||||
"id": ticket.LatestUserTicketLog.Admin.Id,
|
||||
"fullname": ticket.LatestUserTicketLog.Admin.Fullname,
|
||||
"username": ticket.LatestUserTicketLog.Admin.Username,
|
||||
}
|
||||
}
|
||||
latestLogMap = maps.Map{
|
||||
"admin": logAdminMap,
|
||||
}
|
||||
}
|
||||
|
||||
ticketMaps = append(ticketMaps, maps.Map{
|
||||
"id": ticket.Id,
|
||||
"subject": ticket.Subject,
|
||||
"category": categoryMap,
|
||||
"user": userMap,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.CreatedAt),
|
||||
"status": ticket.Status,
|
||||
"statusName": userconfigs.UserTicketStatusName(ticket.Status),
|
||||
"lastLogTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.LastLogAt),
|
||||
"latestLog": latestLogMap,
|
||||
})
|
||||
}
|
||||
this.Data["tickets"] = ticketMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user