2026-04-21 17:11:50 +08:00
|
|
|
package event_handlers
|
|
|
|
|
|
|
|
|
|
import (
|
2026-05-31 18:43:48 +08:00
|
|
|
"agent-desk/internal/events"
|
|
|
|
|
"agent-desk/internal/models"
|
|
|
|
|
"agent-desk/internal/pkg/enums"
|
|
|
|
|
"agent-desk/internal/pkg/eventbus"
|
2026-06-03 09:36:33 +08:00
|
|
|
"agent-desk/internal/pkg/i18nx"
|
2026-05-31 18:43:48 +08:00
|
|
|
"agent-desk/internal/services"
|
2026-04-21 17:11:50 +08:00
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/mlogclub/simple/common/strs"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
eventbus.
|
|
|
|
|
Register[events.TicketAssignedEvent]().
|
|
|
|
|
Subscribe(handleTicketAssignedNotify)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleTicketAssignedNotify(ctx context.Context, event events.TicketAssignedEvent) error {
|
|
|
|
|
if event.TicketID <= 0 || event.ToUserID <= 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
ticket := services.TicketService.Get(event.TicketID)
|
|
|
|
|
if ticket == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
content := buildTicketAssignedNotifyBody(ticket, event.ToUserID, event.Reason)
|
2026-06-03 09:36:33 +08:00
|
|
|
return services.WxWorkNotifyService.SendTextToAssigneeOrDefault(event.ToUserID, i18nx.Get("notification.ticketAssigned.title"), content)
|
2026-04-21 17:11:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func buildTicketAssignedNotifyBody(ticket *models.Ticket, assigneeID int64, reason string) string {
|
|
|
|
|
if ticket == nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
lines := []string{
|
2026-06-03 09:36:33 +08:00
|
|
|
i18nx.Getf(i18nx.DefaultLocale, "notification.ticketAssigned.wxwork.no", strs.DefaultIfBlank(ticket.TicketNo, fmt.Sprintf("#%d", ticket.ID))),
|
|
|
|
|
i18nx.Getf(i18nx.DefaultLocale, "notification.ticketAssigned.wxwork.title", strs.DefaultIfBlank(ticket.Title, "-")),
|
|
|
|
|
i18nx.Getf(i18nx.DefaultLocale, "notification.ticketAssigned.wxwork.status", enums.GetTicketStatusLabel(ticket.Status)),
|
|
|
|
|
i18nx.Getf(i18nx.DefaultLocale, "notification.assignee", resolveNotifyUserLabel(assigneeID)),
|
2026-04-21 17:11:50 +08:00
|
|
|
}
|
|
|
|
|
if strings.TrimSpace(reason) != "" {
|
2026-06-03 09:36:33 +08:00
|
|
|
lines = append(lines, i18nx.Getf(i18nx.DefaultLocale, "notification.ticketAssigned.reason", strings.TrimSpace(reason)))
|
2026-04-21 17:11:50 +08:00
|
|
|
}
|
2026-06-03 09:36:33 +08:00
|
|
|
lines = append(lines, i18nx.Getf(i18nx.DefaultLocale, "notification.time", time.Now().Format("2006-01-02 15:04:05")))
|
2026-04-21 17:11:50 +08:00
|
|
|
return strings.Join(lines, "\n")
|
|
|
|
|
}
|