tools.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "fmt"
  4. "go.uber.org/zap"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  6. "net/http"
  7. )
  8. // getUniqueFields 获取切片中标题和项目名称的唯一值
  9. func getUniqueFields(slice []map[string]interface{}) (map[string]bool, map[string]bool) {
  10. titles := make(map[string]bool)
  11. projects := make(map[string]bool)
  12. for _, item := range slice {
  13. title, titleExists := item["title"].(string)
  14. project, projectExists := item["projectname"].(string)
  15. if titleExists {
  16. titles[title] = true
  17. }
  18. if projectExists {
  19. projects[project] = true
  20. }
  21. }
  22. return titles, projects
  23. }
  24. // countMatches 统计切片A中的元素在切片B中存在的数量和总数量
  25. func countMatches(sliceA []map[string]interface{}, titlesInB, projectsInB map[string]bool) int {
  26. count := 0
  27. for _, itemA := range sliceA {
  28. title, titleExists := itemA["title"].(string)
  29. project, projectExists := itemA["projectname"].(string)
  30. if titleExists && titlesInB[title] {
  31. count++
  32. } else if projectExists && projectsInB[project] {
  33. count++
  34. }
  35. }
  36. return count
  37. }
  38. //SendMail 发送邮件
  39. func SendMail(title, content string) {
  40. url := fmt.Sprintf("%s?to=%s&title=%s&body=%s", GF.Email.Api, GF.Email.To, title, content)
  41. fmt.Println("url=>", url)
  42. res, err := http.Get(url)
  43. if err != nil {
  44. log.Info("SendMail", zap.Any("err", err))
  45. } else {
  46. log.Info("SendMail", zap.Any("res", res))
  47. }
  48. }