Initial commit (code only without large binaries)
This commit is contained in:
136
EdgeAdmin/internal/web/actions/default/tickets/ticket/index.go
Normal file
136
EdgeAdmin/internal/web/actions/default/tickets/ticket/index.go
Normal file
@@ -0,0 +1,136 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package ticket
|
||||
|
||||
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"
|
||||
"html"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
TicketId int64
|
||||
FromURL string
|
||||
}) {
|
||||
this.Data["fromURL"] = params.FromURL
|
||||
|
||||
// 工单信息
|
||||
ticketResp, err := this.RPC().UserTicketRPC().FindUserTicket(this.AdminContext(), &pb.FindUserTicketRequest{UserTicketId: params.TicketId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var ticket = ticketResp.UserTicket
|
||||
if ticket == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["ticket"] = maps.Map{
|
||||
"id": ticket.Id,
|
||||
"subject": ticket.Subject,
|
||||
"body": this.formatText(ticket.Body),
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.CreatedAt),
|
||||
"lastLogTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.LastLogAt),
|
||||
"status": ticket.Status,
|
||||
"statusName": userconfigs.UserTicketStatusName(ticket.Status),
|
||||
"category": categoryMap,
|
||||
"user": userMap,
|
||||
}
|
||||
|
||||
// 工单处理日志
|
||||
countLogsResp, err := this.RPC().UserTicketLogRPC().CountUserTicketLogs(this.AdminContext(), &pb.CountUserTicketLogsRequest{UserTicketId: params.TicketId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countLogs = countLogsResp.Count
|
||||
var page = this.NewPage(countLogs)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
logsResp, err := this.RPC().UserTicketLogRPC().ListUserTicketLogs(this.AdminContext(), &pb.ListUserTicketLogsRequest{
|
||||
UserTicketId: params.TicketId,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var logMaps = []maps.Map{}
|
||||
for _, log := range logsResp.UserTicketLogs {
|
||||
// admin
|
||||
var adminMap maps.Map
|
||||
if log.Admin != nil {
|
||||
adminMap = maps.Map{
|
||||
"id": log.Admin.Id,
|
||||
"fullname": log.Admin.Fullname,
|
||||
"username": log.Admin.Username,
|
||||
}
|
||||
}
|
||||
|
||||
// user
|
||||
var userMap maps.Map
|
||||
if log.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": log.User.Id,
|
||||
"fullname": log.User.Fullname,
|
||||
"username": log.User.Username,
|
||||
}
|
||||
}
|
||||
|
||||
logMaps = append(logMaps, maps.Map{
|
||||
"id": log.Id,
|
||||
"comment": this.formatText(log.Comment),
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
||||
"status": log.Status,
|
||||
"statusName": userconfigs.UserTicketStatusName(log.Status),
|
||||
|
||||
"admin": adminMap,
|
||||
"user": userMap,
|
||||
})
|
||||
}
|
||||
this.Data["logs"] = logMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) formatText(s string) string {
|
||||
s = html.EscapeString(s)
|
||||
s = strings.ReplaceAll(s, " ", " ")
|
||||
s = strings.ReplaceAll(s, "\t", " ")
|
||||
s = strings.ReplaceAll(s, "\n", "<br/>\n")
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user