123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package main
- import (
- "fmt"
- "go.uber.org/zap"
- "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
- "net/http"
- "sort"
- )
- // getUniqueFields 获取切片中标题和项目名称的唯一值
- func getUniqueFields(slice []map[string]interface{}) (map[string]bool, map[string]bool) {
- titles := make(map[string]bool)
- projects := make(map[string]bool)
- for _, item := range slice {
- title, titleExists := item["title"].(string)
- project, projectExists := item["projectname"].(string)
- if titleExists {
- titles[title] = true
- }
- if projectExists {
- projects[project] = true
- }
- }
- return titles, projects
- }
- // countMatches 统计切片A中的元素在切片B中存在的数量和总数量
- func countMatches(sliceA []map[string]interface{}, titlesInB, projectsInB map[string]bool) int {
- count := 0
- for _, itemA := range sliceA {
- title, titleExists := itemA["title"].(string)
- project, projectExists := itemA["projectname"].(string)
- if titleExists && titlesInB[title] {
- count++
- } else if projectExists && projectsInB[project] {
- count++
- }
- }
- return count
- }
- // SendMail 发送邮件
- func SendMail(title, content string) {
- url := fmt.Sprintf("%s?to=%s&title=%s&body=%s", GF.Email.Api, GF.Email.To, title, content)
- fmt.Println("url=>", url)
- res, err := http.Get(url)
- if err != nil {
- log.Info("SendMail", zap.Any("err", err))
- } else {
- log.Info("SendMail", zap.Any("res", res))
- }
- }
- // IsInStringArray 判断数组中是否存在字符串
- func IsInStringArray(str string, arr []string) bool {
- // 先对字符串数组进行排序
- sort.Strings(arr)
- // 使用二分查找算法查找字符串
- pos := sort.SearchStrings(arr, str)
- // 如果找到了则返回 true,否则返回 false
- return pos < len(arr) && arr[pos] == str
- }
|