123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package main
- import (
- "jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
- "encoding/json"
- "fmt"
- wlog "github.com/wcc4869/common_utils/log"
- "go.mongodb.org/mongo-driver/bson/primitive"
- "net"
- )
- //GetJyKey 免费订阅:o_jy.a_key.key/appendkey
- func GetJyKey(data map[string]interface{}) (res []interface{}) {
- // 获取o_jy.a_key.key的值
- if ojy, ok := data["o_jy"].(map[string]interface{}); ok {
- if akey, ok := ojy["a_key"].([]interface{}); ok {
- for _, v := range akey {
- if m, ok := v.(map[string]interface{}); ok {
- if key, ok := m["key"].([]interface{}); ok {
- res = append(res, key...)
- }
- if key, ok := m["appendkey"].([]interface{}); ok {
- res = append(res, key...)
- }
- }
- }
- }
- }
- return
- }
- //GetVipKey 超级订阅:o_vipjy.a_items.a_key.key/appendkey
- func GetVipKey(data map[string]interface{}) (res []interface{}) {
- //o_vipjy.a_items.a_key.key
- if o_vipjy, ok := data["o_vipjy"].(map[string]interface{}); ok {
- if aItems, ok := o_vipjy["a_items"].([]interface{}); ok {
- for _, aItem := range aItems {
- if a_k, ok := aItem.(map[string]interface{}); ok {
- if aKey, ok := a_k["a_key"].([]interface{}); ok {
- for _, ak := range aKey {
- if va, ok := ak.(map[string]interface{}); ok {
- if key, ok := va["key"].([]interface{}); ok {
- res = append(res, key...)
- }
- if key, ok := va["appendkey"].([]interface{}); ok {
- res = append(res, key...)
- }
- }
- }
- }
- }
- }
- }
- }
- return
- }
- //GetMemberKey 大会员订阅:o_member_jy.a_items.a_key.key/appendkey
- func GetMemberKey(data map[string]interface{}) (res []interface{}) {
- //o_member_jy.a_items.a_key.key
- if o_member_jy, ok := data["o_member_jy"].(map[string]interface{}); ok {
- if aItems, ok := o_member_jy["a_items"].([]interface{}); ok {
- for _, aItem := range aItems {
- if tem, ok := aItem.(map[string]interface{}); ok {
- if aKey, ok := tem["a_key"].([]interface{}); ok {
- for _, ak := range aKey {
- if va, ok := ak.(map[string]interface{}); ok {
- if key, ok := va["key"].([]interface{}); ok {
- res = append(res, key...)
- }
- if key, ok := va["appendkey"].([]interface{}); ok {
- res = append(res, key...)
- }
- }
- }
- }
- }
- }
- }
- }
- return
- }
- //RemoveDuplicates 过滤重复数据
- func RemoveDuplicates(elements []interface{}) []interface{} {
- encountered := map[interface{}]bool{}
- result := []interface{}{}
- for _, v := range elements {
- if encountered[v] == true {
- continue
- } else {
- encountered[v] = true
- result = append(result, v)
- }
- }
- return result
- }
- //GetUserKeys 获取用户订阅关键词
- func GetUserKeys(data map[string]interface{}) (res []interface{}) {
- keys := GetJyKey(data)
- vkeys := GetVipKey(data)
- mkeys := GetMemberKey(data)
- res = append(res, keys...)
- res = append(res, vkeys...)
- res = append(res, mkeys...)
- res = RemoveDuplicates(res)
- return
- }
- func toString(i interface{}) string {
- return fmt.Sprintf("%v", i)
- }
- //getLastUser 获取最新的用户
- func getLastUser(coll string) (user map[string]interface{}) {
- rs, _ := Mgo.Find(coll, nil, map[string]interface{}{"_id": -1}, nil, true, -1, 1)
- for _, v := range *rs {
- user = v
- }
- return
- }
- //BsonIdToSId 根据bsonID转string
- func BsonIdToSId(uid interface{}) string {
- if uid == nil {
- return ""
- } else if u, ok := uid.(string); ok {
- return u
- } else if u, ok := uid.(primitive.ObjectID); ok {
- return u.Hex()
- } else {
- return ""
- }
- }
- //StringTOBsonId StringTOBsonId
- func StringTOBsonId(id string) (bid primitive.ObjectID) {
- if id != "" {
- bid, _ = primitive.ObjectIDFromHex(id)
- } else {
- bid = primitive.NilObjectID
- }
- return
- }
- //SendUdpMsg 通知处理企业新增数据
- func SendUdpMsg(data map[string]interface{}, target *net.UDPAddr) {
- bytes, _ := json.Marshal(data)
- UdpClient.WriteUdp(bytes, udp.OP_TYPE_DATA, target)
- wlog.Info("SendUdpMsg", wlog.Any("data", data))
- wlog.Info("SendUdpMsg", wlog.Any("target", target))
- }
|