email_template.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package email
  2. import (
  3. "fmt"
  4. "strconv"
  5. "go-common/app/job/main/videoup-report/model/email"
  6. "go-common/library/log"
  7. )
  8. //NotifyEmailTemplate 优质UP主/时政UP主/企业UP主/十万粉丝报备邮件
  9. func (d *Dao) NotifyEmailTemplate(params map[string]string) (tpl *email.Template) {
  10. headers := map[string][]string{
  11. email.FROM: {d.c.Mail.Username},
  12. }
  13. //to
  14. typeIDStr := params["typeId"]
  15. if len(d.emailAddr[typeIDStr]) == 0 {
  16. log.Info("archive(%s) type(%s) don't config email address.", params["aid"], typeIDStr)
  17. return
  18. }
  19. headers[email.TO] = d.emailAddr[typeIDStr]
  20. //subject
  21. headers[email.SUBJECT] = []string{fmt.Sprintf("优质/十万粉稿件处理报备[%s]--操作人: %s[%s]", params["upName"], params["username"], params["department"])}
  22. //body
  23. body := `
  24. 稿件标题:%s
  25. up主:%s
  26. 稿件链接:http://www.bilibili.com/video/av%s
  27. 触发条件:%s
  28. 处理操作:%s
  29. `
  30. body = fmt.Sprintf(body, params["title"], params["upName"], params["aid"], params["condition"], params["change"])
  31. fromVideo, err := strconv.ParseBool(params["fromVideo"])
  32. if err != nil {
  33. log.Error("NotifyEmailTemplate get email template: strconv.ParseBool error(%v) aid(%s) fromVideo(%s)", err, params["aid"], params["fromVideo"])
  34. return
  35. }
  36. //视频追踪信息还没上线,先不写
  37. if !fromVideo {
  38. body += fmt.Sprintf("稿件追踪:http://manager.bilibili.co/#!/archive_utils/arc-track?aid=%s", params["aid"])
  39. }
  40. aid, _ := strconv.ParseInt(params["aid"], 10, 64)
  41. uid, _ := strconv.ParseInt(params["uid"], 10, 64)
  42. tpl = &email.Template{
  43. Headers: headers,
  44. Body: body,
  45. ContentType: "text/plain",
  46. Type: email.EmailUP,
  47. AID: aid,
  48. UID: uid,
  49. Username: params["username"],
  50. Department: params["department"],
  51. }
  52. log.Info("NotifyEmailTemplate: email template(%+v)", tpl)
  53. return
  54. }
  55. //PrivateEmailTemplate 私单报备邮件模板
  56. func (d *Dao) PrivateEmailTemplate(params map[string]string) (tpl *email.Template) {
  57. headers := map[string][]string{
  58. email.FROM: {d.c.Mail.Username},
  59. }
  60. //to
  61. to := d.PrivateAddr[params["typeId"]]
  62. if len(to) == 0 {
  63. log.Error("PrivateEmailTemplate lack email address config: typeId(%s), params(%v)", params["typeId"], params)
  64. return
  65. }
  66. headers[email.TO] = to
  67. //cc
  68. cc := d.PrivateAddr["CC"]
  69. if len(cc) > 0 {
  70. headers[email.CC] = cc
  71. }
  72. subject := fmt.Sprintf("私单稿件报备_%s_av%s", params["upName"], params["aid"])
  73. headers[email.SUBJECT] = []string{subject}
  74. body := `稿件标题: %s
  75. 稿件状态: %s
  76. 禁止项状态: 排行禁止:%s ;动态禁止:%s ; 推荐禁止:%s
  77. UP主: %s
  78. 粉丝量:%s
  79. 操作人: %s [%s]
  80. 备注: %s`
  81. body = fmt.Sprintf(body, params["arcTitle"], params["arcState"], params["noRankAttr"], params["noDynamicAttr"], params["noRecommendAttr"],
  82. params["upName"], params["upFans"], params["mngName"], params["mngDepartment"], params["note"])
  83. aid, _ := strconv.ParseInt(params["aid"], 10, 64)
  84. uid, _ := strconv.ParseInt(params["uid"], 10, 64)
  85. tpl = &email.Template{
  86. Headers: headers,
  87. Body: body,
  88. ContentType: "text/plain",
  89. Type: params["emailType"],
  90. AID: aid,
  91. UID: uid,
  92. Username: params["mngName"],
  93. Department: params["mngDepartment"],
  94. }
  95. log.Info("PrivateEmailTemplate: email template(%+v)", tpl)
  96. return
  97. }
  98. // MinitorNotifyTeamplate 审核监控报警邮件模板
  99. func (d *Dao) MonitorNotifyTemplate(subject string, body string, toEmails []string) (tpl *email.Template) {
  100. headers := map[string][]string{
  101. email.FROM: {d.c.Mail.Username},
  102. }
  103. headers[email.TO] = toEmails
  104. headers[email.SUBJECT] = []string{subject}
  105. tpl = &email.Template{
  106. Headers: headers,
  107. Body: body,
  108. ContentType: "text/plain",
  109. Type: email.EmailMonitor,
  110. AID: 0,
  111. UID: 0,
  112. Username: "",
  113. Department: "",
  114. }
  115. log.Info("MinitorNotifyTeamplate: email template(%+v)", tpl)
  116. return
  117. }