// 访客预约相关钉钉消息模板 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 // 所有访客信息(已格式化,每行一条用
连接) EmployeeName string VisitTime string VisitPurpose string Remark string VehicleInfo string // 车辆信息(已格式化,每行一条用
连接) 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 := "有新的访客预约

" // 访客 text += "【访客】
" if m.VisitorList != "" { text += m.VisitorList + "
" } // 接待信息 text += "**接待员工:** " + m.EmployeeName + "
" text += "**访问时间:** " + m.VisitTime + "
" if m.VisitPurpose != "" { text += "**来访目的:** " + m.VisitPurpose + "
" } text += "
" // 车辆 if m.VehicleInfo != "" { text += "**车辆信息:**
" + m.VehicleInfo } // 备注 if m.Remark != "" { text += "**备注:** " + m.Remark } text += "

请及时前往微信小程序“四川凌空天行”处理预约申请。" return title, text } // BuildApproveNotificationMsg 构建审批通知消息(发送给下一节点审批人) func BuildApproveNotificationMsg(m *AppointmentResultMessage) (title, markdown string) { title = fmt.Sprintf("✅ 审批通过 - %s", m.ApproverName) text := "审批通过

" text += "**审批人:** " + m.ApproverName + "
" text += "**结果:** 通过
" if m.Comment != "" { text += "**审批意见:** " + m.Comment + "
" } text += "**访问时间:** " + m.VisitTime + "
" text += "**访客:** " + m.VisitorName + "
" text += "
请前往小程序处理您的审批任务。" return title, text } // BuildRejectNotificationMsg 构建审批拒绝通知消息(发送给下一节点审批人) func BuildRejectNotificationMsg(m *AppointmentResultMessage) (title, markdown string) { title = fmt.Sprintf("❌ 审批已终止 - %s", m.ApproverName) text := "审批已终止

" text += "**拒绝人:** " + m.ApproverName + "
" text += "**结果:** 拒绝
" if m.Comment != "" { text += "**拒绝原因:** " + m.Comment + "
" } text += "**访问时间:** " + m.VisitTime + "
" text += "**访客:** " + m.VisitorName + "
" text += "
该预约申请已被拒绝,无需继续处理。" return title, text } // BuildSameNodeCancelledMsg 构建同节点已取消通知消息 // 当同一节点有多人审批(非会签),其中一人已审时,通知其他待审人 func BuildSameNodeCancelledMsg(approvedUserName, comment, visitTime string) (title, markdown string) { title = fmt.Sprintf("ℹ️ %s 已审批", approvedUserName) text := "审批状态更新

" text += "**已审批人:** " + approvedUserName + "
" if comment != "" { text += "**备注:** " + comment + "
" } text += "**访问时间:** " + visitTime + "
" text += "
该节点已有其他审批人处理,此任务已自动取消。" return title, text }