'init'
This commit is contained in:
119
sc-lktx-backend/internal/pkg/dingtalk/templates.go
Normal file
119
sc-lktx-backend/internal/pkg/dingtalk/templates.go
Normal file
@@ -0,0 +1,119 @@
|
||||
// 访客预约相关钉钉消息模板
|
||||
package dingtalk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FormatCSTTime 格式化时间为 Asia/Shanghai 时区的 "01-02 15:04 ~ 15:04" 格式
|
||||
func FormatCSTTime(start, end time.Time) string {
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
if err != nil {
|
||||
loc = time.UTC
|
||||
}
|
||||
start = start.In(loc)
|
||||
end = end.In(loc)
|
||||
if start.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return start.Format("01-02 15:04") + " ~ " + end.Format("15:04")
|
||||
}
|
||||
|
||||
// AppointmentMessage 访客预约消息参数
|
||||
type AppointmentMessage struct {
|
||||
VisitorList string // 所有访客信息(已格式化,每行一条用<br>连接)
|
||||
EmployeeName string
|
||||
VisitTime string
|
||||
VisitPurpose string
|
||||
Remark string
|
||||
VehicleInfo string // 车辆信息(已格式化,每行一条用<br>连接)
|
||||
AppointmentID uint
|
||||
}
|
||||
|
||||
// AppointmentResultMessage 预约审批结果消息参数
|
||||
type AppointmentResultMessage struct {
|
||||
ApproverName string
|
||||
Action string // "通过" / "拒绝"
|
||||
Comment string
|
||||
AppointmentID uint
|
||||
VisitTime string
|
||||
VisitorName string
|
||||
}
|
||||
|
||||
// BuildNewAppointmentMsg 构建新预约提醒消息(发送给被访员工)
|
||||
func BuildNewAppointmentMsg(m *AppointmentMessage) (title, markdown string) {
|
||||
title = "📋 新的访客预约"
|
||||
text := "有新的访客预约<br><br>"
|
||||
|
||||
// 访客
|
||||
text += "【访客】<br>"
|
||||
if m.VisitorList != "" {
|
||||
text += m.VisitorList + "<br>"
|
||||
}
|
||||
|
||||
// 接待信息
|
||||
text += "**接待员工:** " + m.EmployeeName + "<br>"
|
||||
text += "**访问时间:** " + m.VisitTime + "<br>"
|
||||
if m.VisitPurpose != "" {
|
||||
text += "**来访目的:** " + m.VisitPurpose + "<br>"
|
||||
}
|
||||
text += "<br>"
|
||||
|
||||
// 车辆
|
||||
if m.VehicleInfo != "" {
|
||||
text += "**车辆信息:**<br>" + m.VehicleInfo
|
||||
}
|
||||
|
||||
// 备注
|
||||
if m.Remark != "" {
|
||||
text += "**备注:** " + m.Remark
|
||||
}
|
||||
|
||||
text += "<br><br>请及时前往微信小程序“四川凌空天行”处理预约申请。"
|
||||
return title, text
|
||||
}
|
||||
|
||||
// BuildApproveNotificationMsg 构建审批通知消息(发送给下一节点审批人)
|
||||
func BuildApproveNotificationMsg(m *AppointmentResultMessage) (title, markdown string) {
|
||||
title = fmt.Sprintf("✅ 审批通过 - %s", m.ApproverName)
|
||||
text := "审批通过<br><br>"
|
||||
text += "**审批人:** " + m.ApproverName + "<br>"
|
||||
text += "**结果:** 通过<br>"
|
||||
if m.Comment != "" {
|
||||
text += "**审批意见:** " + m.Comment + "<br>"
|
||||
}
|
||||
text += "**访问时间:** " + m.VisitTime + "<br>"
|
||||
text += "**访客:** " + m.VisitorName + "<br>"
|
||||
text += "<br>请前往小程序处理您的审批任务。"
|
||||
return title, text
|
||||
}
|
||||
|
||||
// BuildRejectNotificationMsg 构建审批拒绝通知消息(发送给下一节点审批人)
|
||||
func BuildRejectNotificationMsg(m *AppointmentResultMessage) (title, markdown string) {
|
||||
title = fmt.Sprintf("❌ 审批已终止 - %s", m.ApproverName)
|
||||
text := "审批已终止<br><br>"
|
||||
text += "**拒绝人:** " + m.ApproverName + "<br>"
|
||||
text += "**结果:** 拒绝<br>"
|
||||
if m.Comment != "" {
|
||||
text += "**拒绝原因:** " + m.Comment + "<br>"
|
||||
}
|
||||
text += "**访问时间:** " + m.VisitTime + "<br>"
|
||||
text += "**访客:** " + m.VisitorName + "<br>"
|
||||
text += "<br>该预约申请已被拒绝,无需继续处理。"
|
||||
return title, text
|
||||
}
|
||||
|
||||
// BuildSameNodeCancelledMsg 构建同节点已取消通知消息
|
||||
// 当同一节点有多人审批(非会签),其中一人已审时,通知其他待审人
|
||||
func BuildSameNodeCancelledMsg(approvedUserName, comment, visitTime string) (title, markdown string) {
|
||||
title = fmt.Sprintf("ℹ️ %s 已审批", approvedUserName)
|
||||
text := "审批状态更新<br><br>"
|
||||
text += "**已审批人:** " + approvedUserName + "<br>"
|
||||
if comment != "" {
|
||||
text += "**备注:** " + comment + "<br>"
|
||||
}
|
||||
text += "**访问时间:** " + visitTime + "<br>"
|
||||
text += "<br>该节点已有其他审批人处理,此任务已自动取消。"
|
||||
return title, text
|
||||
}
|
||||
Reference in New Issue
Block a user