wechat.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package service
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. "go-common/app/admin/ep/melloi/model"
  7. )
  8. //AddWechatSend add wechat send
  9. func (s *Service) AddWechatSend(c context.Context, cookie, content string) (msgSendRes *model.MsgSendRes, err error) {
  10. return s.dao.AddWechatSend(c, cookie, content)
  11. }
  12. // AddWechatContent Add Wechat Content
  13. func AddWechatContent(ptestParam model.DoPtestParam, reportSuID int, jobName string, userService map[string][]string) (content string) {
  14. var (
  15. url string
  16. lay = "2006-01-02 15:04:05"
  17. ptestDetailURL string
  18. serviceList = make(map[string][]string)
  19. serviceDep string
  20. serviceName string
  21. )
  22. if ptestParam.Type == model.PROTOCOL_HTTP || ptestParam.Type == model.PROTOCOL_SCENE {
  23. ptestDetailURL = "http://melloi.bilibili.co/#/ptest-detail?reportSuId=" + strconv.Itoa(reportSuID)
  24. }
  25. if ptestParam.Type == model.PROTOCOL_GRPC {
  26. ptestDetailURL = "http://melloi.bilibili.co/#/ptest-detail-grpc?reportSuId=" + strconv.Itoa(reportSuID)
  27. }
  28. url = ptestParam.URL
  29. if ptestParam.Type == model.PROTOCOL_SCENE {
  30. for _, script := range ptestParam.Scripts {
  31. url = url + "\n" + script.URL
  32. }
  33. }
  34. // 增加依赖服务列表
  35. for _, v := range userService {
  36. for _, service := range v {
  37. serviceList[service] = nil
  38. }
  39. }
  40. for k := range serviceList {
  41. serviceDep += "\n" + k
  42. }
  43. loadTime := strconv.Itoa(ptestParam.LoadTime) + "s"
  44. if ptestParam.Upload {
  45. loadTime = "脚本用户上传,时间1800s以内"
  46. url = "脚本用户上传,url 未知"
  47. }
  48. serviceName = ptestParam.Department + "." + ptestParam.Project + "." + ptestParam.APP
  49. content = "执行人:" + ptestParam.UserName + "\n压测服务:" + serviceName + "\n" + "压测接口:" + url + "\n开始时间:" + time.Now().Format(lay) + "\n持续时间:" +
  50. loadTime + "\n压测容器:" + jobName + "\n报告地址:" + ptestDetailURL + "\n压测依赖服务:" + serviceDep
  51. return
  52. }
  53. // AddWechatDependServiceContent add wechat depend Service Content
  54. func AddWechatDependServiceContent(ptestParam model.DoPtestParam, userService map[string][]string, reportSuId int, user string) (content string) {
  55. var (
  56. url string
  57. lay = "2006-01-02 15:04:05"
  58. ptestDetailURL string
  59. serviceList string
  60. )
  61. if ptestParam.Type == model.PROTOCOL_HTTP || ptestParam.Type == model.PROTOCOL_SCENE {
  62. ptestDetailURL = "http://melloi.bilibili.co/#/ptest-detail?reportSuId=" + strconv.Itoa(reportSuId)
  63. }
  64. if ptestParam.Type == model.PROTOCOL_GRPC {
  65. ptestDetailURL = "http://melloi.bilibili.co/#/ptest-detail-grpc?reportSuId=" + strconv.Itoa(reportSuId)
  66. }
  67. url = ptestParam.URL
  68. if ptestParam.Type == model.PROTOCOL_SCENE {
  69. for _, script := range ptestParam.Scripts {
  70. url = url + "\n" + script.URL
  71. }
  72. }
  73. for _, service := range userService[user] {
  74. serviceList += "\n" + service
  75. }
  76. serviceName := ptestParam.Department + "." + ptestParam.Project + "." + ptestParam.APP
  77. content = "[Melloi压测依赖提醒] \n 压测服务:" + serviceName + "\n 压测接口:" + ptestParam.URL + "\n 压测时间:" + time.Now().Format(lay) + "\n 压测时长: " +
  78. strconv.Itoa(ptestParam.LoadTime) + "\n 报告地址:" + ptestDetailURL + "\n 依赖服务:" + serviceList
  79. return
  80. }