// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . package ticket 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" "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.UserContext(), &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.UserContext(), &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.UserContext(), &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 { 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), "userId": log.UserId, "adminId": log.AdminId, }) } 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", "
\n") return s }