123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- package main
- import (
- "github.com/gogf/gf/v2/util/gconv"
- "strings"
- "time"
- "log"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/mongodb"
- )
- func subscribeAllSync() {
- log.Println("订阅全量数据任务开始")
- session := Mgo.GetMgoConn()
- defer func() {
- Mgo.DestoryMongoConn(session)
- }()
- query := map[string]interface{}{}
- iter := session.DB(db.Mgo.DbName).C("user").Find(&query).Sort("_id").Iter()
- thisData := map[string]interface{}{}
- for {
- if !iter.Next(&thisData) {
- break
- }
- FormatSubscribeAllData(thisData)
- }
- log.Println("订阅全量数据任务结束")
- }
- func FormatSubscribeAllData(data map[string]interface{}) {
- stype, types := "", ""
- userId := mongodb.BsonIdToSId(data["_id"])
- areaCodes := ""
- keywords := ""
- keyArrs := []string{}
- if data["o_member_jy"] != nil {
- if gconv.Int64(data["i_member_status"]) > 0 {
- stype = "大会员订阅"
- types = "o_member_jy"
- }
- }
- if stype == "" {
- if data["o_vipjy"] != nil {
- stype = "超级订阅"
- types = "o_vipjy"
- } else {
- if data["o_jy"] != nil {
- stype = "免费订阅"
- types = "o_jy"
- }
- }
- }
- if types != "" {
- if jy, ok := data[types].(map[string]interface{}); ok {
- if types == "o_jy" {
- //
- if area, oks := jy["o_area"].(map[string]interface{}); oks {
- areaArr := []string{}
- for k, _ := range area {
- areaArr = append(areaArr, AreaCode[k])
- }
- if len(area) == 0 {
- areaArr = append(areaArr, AreaCode["全国"])
- }
- areaCodes = strings.Join(areaArr, ",")
- }
- //
- akey, aok := jy["a_key"].([]map[string]interface{})
- if !aok {
- akeys, _ := jy["a_key"].([]interface{})
- akey = common.ObjArrToMapArr(akeys)
- }
- for _, v := range akey {
- keysArr, asok := v["key"].([]string)
- if !asok {
- keysArr_s, _ := v["key"].([]interface{})
- keysArr = common.ObjArrToStringArr(keysArr_s)
- }
- for _, key := range keysArr {
- keyArrs = append(keyArrs, key)
- }
- }
- } else if types == "o_vipjy" {
- if area, oks := jy["area"].(map[string]interface{}); oks {
- areaArr := []string{}
- for k, _ := range area {
- areaArr = append(areaArr, AreaCode[k])
- }
- if len(area) == 0 {
- areaArr = append(areaArr, AreaCode["全国"])
- }
- areaCodes = strings.Join(areaArr, ",")
- }
- items, aok := jy["items"].([]map[string]interface{})
- if !aok {
- itemss, _ := jy["items"].([]interface{})
- items = common.ObjArrToMapArr(itemss)
- }
- for _, v := range items {
- akey, iok := v["a_key"].([]map[string]interface{})
- if !iok {
- akeys, _ := v["a_key"].([]interface{})
- akey = common.ObjArrToMapArr(akeys)
- }
- for _, v := range akey {
- keysArr, asok := v["key"].([]string)
- if !asok {
- keysArr_s, _ := v["key"].([]interface{})
- keysArr = common.ObjArrToStringArr(keysArr_s)
- }
- for _, key := range keysArr {
- keyArrs = append(keyArrs, key)
- }
- }
- }
- } else {
- if area, oks := jy["o_area"].(map[string]interface{}); oks {
- areaArr := []string{}
- for k, _ := range area {
- areaArr = append(areaArr, AreaCode[k])
- }
- if len(area) == 0 {
- areaArr = append(areaArr, AreaCode["全国"])
- }
- areaCodes = strings.Join(areaArr, ",")
- }
- if jy["o_area"] == nil {
- areaCodes = AreaCode["全国"]
- }
- items, aok := jy["a_items"].([]map[string]interface{})
- if !aok {
- itemss, _ := jy["a_items"].([]interface{})
- items = common.ObjArrToMapArr(itemss)
- }
- for _, v := range items {
- akey, iok := v["a_key"].([]map[string]interface{})
- if !iok {
- akeys, _ := v["a_key"].([]interface{})
- akey = common.ObjArrToMapArr(akeys)
- }
- for _, v := range akey {
- keysArr, asok := v["key"].([]string)
- if !asok {
- keysArr_s, _ := v["key"].([]interface{})
- keysArr = common.ObjArrToStringArr(keysArr_s)
- }
- for _, key := range keysArr {
- keyArrs = append(keyArrs, key)
- }
- }
- }
- }
- if len(keyArrs) > 0 {
- keywords = strings.Join(keyArrs, ",")
- }
- }
- start := time.Now().Format("2006-01-02") + " 00:00:00"
- end := time.Now().Format("2006-01-02") + " 23:59:59"
- nowTime := time.Now().Format("2006-01-02 15:04:05")
- subscribeData := TiDb.SelectBySql(`select * from dwd_f_userbase_subscribe_info where userid = "` + userId + `" and updatetime >= "` + start + `" and updatetime <= "` + end + `"`)
- if subscribeData != nil && len(*subscribeData) > 0 {
- TiDb.Update("dwd_f_userbase_subscribe_info", map[string]interface{}{"id": common.IntAll((*subscribeData)[0]["id"])}, map[string]interface{}{
- "updatetime": nowTime,
- "subscribe_areas": areaCodes,
- "subscribe_keywords": keywords,
- "member_type": stype,
- "userid": userId,
- })
- } else {
- TiDb.Insert("dwd_f_userbase_subscribe_info", map[string]interface{}{
- "userid": userId,
- "updatetime": nowTime,
- "subscribe_areas": areaCodes,
- "subscribe_keywords": keywords,
- "member_type": stype,
- })
- }
- }
- }
|