Files
waf-platform/EdgeUser/internal/web/actions/default/tickets/index.go
2026-02-04 20:27:13 +08:00

122 lines
3.2 KiB
Go

// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package tickets
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"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 {
Status string
CategoryId int64
}) {
if len(params.Status) == 0 {
params.Status = "none"
}
this.Data["status"] = params.Status
this.Data["categoryId"] = params.CategoryId
this.Data["currentURL"] = url.QueryEscape(this.Request.URL.String())
// 处于新状态的数字
countNewTicketsResp, err := this.RPC().UserTicketRPC().CountUserTickets(this.UserContext(), &pb.CountUserTicketsRequest{
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.UserContext(), &pb.CountUserTicketsRequest{
UserId: this.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.UserContext(), &pb.ListUserTicketsRequest{
UserId: this.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,
}
}
// 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,
}
}
latestLogMap = maps.Map{
"admin": logAdminMap,
}
}
ticketMaps = append(ticketMaps, maps.Map{
"id": ticket.Id,
"subject": ticket.Subject,
"category": categoryMap,
"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()
}