123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710 |
- package util
- import (
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/encrypt"
- "app.yhyue.com/moapp/jybase/esv1"
- "app.yhyue.com/moapp/jybase/mongodb"
- "app.yhyue.com/moapp/jybase/mysql"
- "app.yhyue.com/moapp/jybase/redis"
- "encoding/json"
- "fmt"
- "github.com/zeromicro/go-zero/core/logx"
- "go.mongodb.org/mongo-driver/bson/primitive"
- IC "jyBXSubscribe/rpc/init"
- "jyBXSubscribe/rpc/type/bxsubscribe"
- "strconv"
- "strings"
- "time"
- )
- //
- const (
- pageSize = 50
- pageSizes = 10
- AllSubPushCacheSize = 250
- query = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","area", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "buyerclass","bidamount","budget","projectname","buyer","bidopentime","s_winner","filetext"],"from":0,"size":%d}`
- mongodb_fields = `{"_id":1,"area":1,"publishtime":1,"s_subscopeclass":1,"subtype":1,"title":1,"toptype":1,"type":1, "buyerclass":1,"budget":1,"bidamount":1,"s_winner":1,"bidopentime":1,"buyer":1,"projectname":1}`
- SubFreeFlag = "fType"
- SubVipFlag = "vType"
- MemberFlag = "mType"
- EntnicheFlag = "eType"
- threeDay = 172800
- )
- var aboutDbMsg map[string]*AboutDbMsg = map[string]*AboutDbMsg{
- SubFreeFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
- SubVipFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
- MemberFlag: &AboutDbMsg{"pushmember", "memberpush"},
- EntnicheFlag: &AboutDbMsg{"pushentniche", "pushentniche"},
- }
- type AboutDbMsg struct {
- MysqlTable string
- RedisKeyFlag string
- }
- type SubPush struct {
- Date string
- Datas []*bxsubscribe.SubscribeInfo
- Count int64
- }
- type PushCa struct {
- Date int64
- InfoId string
- Visit int
- Index int64
- Keys []string
- Type int
- Isvip int
- }
- //查询参数
- type SubPushQueryParam struct {
- Mgo_bidding mongodb.MongodbSim //
- Bidding string //
- Bidding_back string //
- PushMysql *mysql.Mysql //
- UserId string //用户id
- PageNum int //页面
- PageSize int //每页数量
- SelectTime string //时间
- Area string //区域
- City string //城市
- Buyerclass string //采购单位行业
- Subtype string //信息类型 二级分类
- Subscopeclass string //信息行业
- Key string //订阅词
- Export bool //导出
- EntId int
- }
- func (spqp *SubPushQueryParam) IsEmpty() bool {
- return spqp.SelectTime == "" && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == ""
- }
- type subscribePush struct {
- ModuleFlag string
- }
- func NewSubscribePush(module ...string) *subscribePush {
- m := ""
- if len(module) > 0 {
- m = module[0]
- }
- return &subscribePush{m}
- }
- //从pushcache_2_a中取
- func (h *subscribePush) GetTodayCache(userId string) (*SubPush, error) {
- pc_a, err := redis.GetNewBytes("pushcache_2_b", h.todayKey(userId))
- if err != nil {
- return nil, err
- }
- if pc_a == nil {
- return nil, nil
- }
- var p *SubPush
- if err := json.Unmarshal(*pc_a, &p); err != nil {
- return nil, err
- }
- return p, nil
- }
- //往pushcache_2_a中放
- func (h *subscribePush) PutTodayCache(userId string, pc_a *SubPush) {
- redis.Put("pushcache_2_b", h.todayKey(userId), pc_a, threeDay)
- }
- //获取redis key
- func (s *subscribePush) todayKey(userId string) string {
- return fmt.Sprintf("%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
- }
- func (s *subscribePush) allKey(userId string) string {
- logx.Info(fmt.Sprintf("all_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId))
- return fmt.Sprintf("all_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
- }
- //历史推送记录中单条信息格式化
- func (s *subscribePush) InfoFormat(p *PushCa, info *map[string]interface{}, files *map[string]bool) *bxsubscribe.SubscribeInfo {
- area := common.ObjToString((*info)["area"])
- if area == "A" {
- area = "全国"
- }
- industry := common.ObjToString((*info)["s_subscopeclass"])
- scs := strings.Split(industry, ",")
- if len(scs) > 0 {
- industry = scs[0]
- if industry != "" {
- iss := strings.Split(industry, "_")
- if len(iss) > 0 {
- industry = iss[0]
- }
- }
- }
- infotype := common.ObjToString((*info)["subtype"])
- if infotype == "" {
- infotype = common.ObjToString((*info)["toptype"])
- }
- if infotype == "" {
- infotype = common.ObjToString((*info)["type"])
- if infotype == "tender" {
- infotype = "招标"
- } else if infotype == "bid" {
- infotype = "中标"
- }
- }
- _id := p.InfoId
- if _id == "" {
- _id = common.ObjToString((*info)["_id"])
- }
- return &bxsubscribe.SubscribeInfo{
- Id: encrypt.EncodeArticleId2ByCheck(_id),
- Title: common.ObjToString((*info)["title"]),
- Area: area,
- BuyerClass: common.ObjToString((*info)["buyerclass"]),
- Subtype: infotype,
- Industry: industry,
- PublishTime: common.Int64All((*info)["publishtime"]),
- CaIndex: p.Index,
- CaDate: p.Date,
- CaIsvisit: int64(p.Visit),
- CaIsvip: int64(p.Isvip),
- CaType: int64(p.Type),
- MatchKeys: p.Keys,
- Budget: common.ObjToString((*info)["budget"]),
- BidAmount: common.ObjToString((*info)["bidamount"]),
- Buyer: common.ObjToString((*info)["buyer"]),
- ProjectName: common.ObjToString((*info)["projectname"]),
- Winner: common.ObjToString((*info)["s_winner"]),
- BidOpenTime: common.ObjToString((*info)["bidopentime"]),
- FileExists: (*files)[_id],
- }
- }
- func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total int64, result []*bxsubscribe.SubscribeInfo) {
- logx.Info(spqp.UserId, s.ModuleFlag, "subscribePush query param:", "SelectTime", spqp.SelectTime, "Area", spqp.Area, "City", spqp.City, "Subtype", spqp.Subtype, "Subscopeclass", spqp.Subscopeclass, "Buyerclass", spqp.Buyerclass, "Key", spqp.Key, "PageNum", spqp.PageNum)
- if spqp.UserId == "" {
- return
- }
- if spqp.PageNum < 1 {
- spqp.PageNum = 1
- }
- if spqp.PageSize < 1 || spqp.PageSize > pageSize {
- if !spqp.Export {
- spqp.PageSize = pageSize
- } else { //数据导出查询20000条限制
- if spqp.PageSize < 1 || spqp.PageSize > 20000 {
- spqp.PageSize = 20000
- }
- }
- }
- starttime, endtime := int64(0), int64(0)
- st, et := "", ""
- now := time.Now()
- logx.Info(4444)
- if spqp.SelectTime == "today" { //今天
- starttime = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
- } else if spqp.SelectTime == "yesterday" { //昨天
- starttime = time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, time.Local).Unix()
- endtime = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
- } else if spqp.SelectTime == "lately-7" { //最近7天
- starttime = time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix()
- } else if spqp.SelectTime == "lately-30" { //最近30天
- starttime = time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix()
- } else if spqp.SelectTime == "lastyear" { //去年
- starttime = time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix()
- endtime = time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Unix()
- } else if len(strings.Split(spqp.SelectTime, "_")) == 2 {
- st = strings.Split(spqp.SelectTime, "_")[0]
- starttime, _ = strconv.ParseInt(st, 0, 64)
- et = strings.Split(spqp.SelectTime, "_")[1]
- endtime, _ = strconv.ParseInt(et, 0, 64)
- if endtime > 0 {
- etTime := time.Unix(endtime, 0)
- endtime = time.Date(etTime.Year(), etTime.Month(), etTime.Day(), 23, 59, 59, 0, time.Local).Unix()
- }
- }
- logx.Info(2222)
- nowFormat := date.NowFormat(date.Date_Short_Layout)
- start := (spqp.PageNum - 1) * spqp.PageSize
- end := start + spqp.PageSize
- //时间是今天,没有别的过滤条件
- if nowFormat == date.FormatDateByInt64(&starttime, date.Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" {
- logx.Info("a1")
- subPush, err := s.GetTodayCache(spqp.UserId)
- if err != nil {
- logx.Info(spqp.UserId, "GetTodayCache Error", err)
- }
- if err != nil || subPush == nil || subPush.Date != nowFormat || len(subPush.Datas) == 0 {
- list, countSearch := s.getDatasFromMysql(spqp, starttime, endtime, spqp.PageSize, false)
- subPush = &SubPush{
- Date: nowFormat,
- Datas: list,
- Count: countSearch,
- }
- s.PutTodayCache(spqp.UserId, subPush)
- }
- length := len(subPush.Datas)
- if end > length {
- end = length
- }
- if start < length {
- result = subPush.Datas[start:end]
- }
- total = int64(length)
- } else if spqp.IsEmpty() && (spqp.PageNum-1)*spqp.PageSize <= 250 { //全部,没有过滤条件 之前缓存5页*50条=250
- logx.Info("a2")
- allCache, err := s.GetAllCache(spqp.UserId)
- if err != nil {
- logx.Info(spqp.UserId, "GetAllCache Error", err)
- }
- if err != nil || allCache == nil || allCache.Date != nowFormat || len(allCache.Datas) == 0 {
- spqp.PageNum = 1
- logx.Info(1111)
- list, countSearch := s.getDatasFromMysql(spqp, starttime, endtime, AllSubPushCacheSize, true)
- allCache = &SubPush{
- Date: nowFormat,
- Datas: list,
- Count: countSearch,
- }
- s.PutAllCache(spqp.UserId, allCache)
- }
- length := len(allCache.Datas)
- if end > length {
- end = length
- }
- if start < length {
- result = allCache.Datas[start:end]
- }
- total = allCache.Count
- } else {
- logx.Info("a4")
- result, total = s.getDatasFromMysql(spqp, starttime, endtime, spqp.PageSize, true)
- }
- logx.Info("-------------------------------------------------", len(result))
- if result == nil {
- result = []*bxsubscribe.SubscribeInfo{}
- }
- hasNextPage = len(result) >= spqp.PageSize
- return
- }
- //
- func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, endtime int64, size int, isLimit bool) (result []*bxsubscribe.SubscribeInfo, count int64) {
- querys := []string{fmt.Sprintf("userid='%s'", spqp.UserId)}
- //时间
- if starttime > 0 && endtime > 0 {
- querys = append(querys, fmt.Sprintf("date>=%d and date<=%d", starttime, endtime))
- } else if starttime > 0 && endtime == 0 {
- querys = append(querys, fmt.Sprintf("date>=%d", starttime))
- } else if starttime == 0 && endtime > 0 {
- querys = append(querys, fmt.Sprintf("date<=%d", endtime))
- }
- if spqp.Area != "" || spqp.City != "" {
- var sqlAreaCity = ""
- //城市
- city := []string{}
- for _, v := range strings.Split(spqp.City, ",") {
- if IC.PushMapping.City[v] > 0 {
- city = append(city, fmt.Sprint(IC.PushMapping.City[v]))
- } else {
- city = append(city, "-1")
- }
- }
- if len(city) == 1 {
- city = append(city, "9999")
- }
- if len(city) > 0 {
- sqlAreaCity = fmt.Sprintf("city in (%s)", strings.Join(city, ","))
- }
- //区域
- var sqlArea = ""
- area := []string{}
- for _, v := range strings.Split(spqp.Area, ",") {
- if IC.PushMapping.Area[v] > 0 {
- area = append(area, fmt.Sprint(IC.PushMapping.Area[v]))
- } else {
- area = append(area, "-1")
- }
- }
- if len(area) == 1 {
- area = append(area, "9999")
- }
- if len(area) > 0 {
- sqlArea = fmt.Sprintf("area in (%s)", strings.Join(area, ","))
- }
- if sqlAreaCity != "" && sqlArea != "" {
- sqlAreaCity = "( " + sqlAreaCity + " or " + sqlArea + " )"
- } else if sqlAreaCity == "" && sqlArea != "" {
- sqlAreaCity = sqlArea
- }
- if sqlAreaCity != "" {
- querys = append(querys, sqlAreaCity)
- }
- }
- //采购单位行业
- if spqp.Buyerclass != "" {
- buyerclass := []string{}
- for _, v := range strings.Split(spqp.Buyerclass, ",") {
- buyerclass = append(buyerclass, fmt.Sprint(IC.PushMapping.Buyerclass[v]))
- }
- if len(buyerclass) == 1 {
- buyerclass = append(buyerclass, "9999")
- }
- if len(buyerclass) > 0 {
- querys = append(querys, fmt.Sprintf("buyerclass in (%s)", strings.Join(buyerclass, ",")))
- }
- }
- //信息类型
- if spqp.Subtype != "" {
- subtype := []string{}
- for _, v := range strings.Split(spqp.Subtype, ",") {
- subtype = append(subtype, fmt.Sprint(IC.PushMapping.Subtype[v]))
- }
- if len(subtype) == 1 {
- subtype = append(subtype, "9999")
- }
- if len(subtype) > 0 {
- querys = append(querys, fmt.Sprintf("subtype in (%s)", strings.Join(subtype, ",")))
- }
- }
- //信息行业
- if spqp.Subscopeclass != "" {
- find_in_set := []string{}
- for _, v := range strings.Split(spqp.Subscopeclass, ",") {
- find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%d',subscopeclass)", IC.PushMapping.Subscopeclass[v]))
- }
- if len(find_in_set) == 1 {
- querys = append(querys, find_in_set[0])
- } else if len(find_in_set) > 1 {
- querys = append(querys, fmt.Sprintf("(%s)", strings.Join(find_in_set, " or ")))
- }
- }
- //关键词
- if spqp.Key != "" {
- find_in_set := []string{}
- for _, v := range strings.Split(spqp.Key, ",") {
- find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%s',replace(replace(matchkeys,'+',','),' ',','))", v))
- }
- if len(find_in_set) == 1 {
- querys = append(querys, find_in_set[0])
- } else if len(find_in_set) > 1 {
- querys = append(querys, fmt.Sprintf("(%s)", strings.Join(find_in_set, " or ")))
- }
- }
- searchSql := fmt.Sprintf(" from %s where %s order by id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, strings.Join(querys, " and "))
- fmt.Println("searchSql", searchSql)
- //查询总数
- count = spqp.PushMysql.CountBySql(fmt.Sprintf("select count(id)" + searchSql))
- logx.Info("count:", count, "---", s.ModuleFlag)
- findSql := "select id,date,infoid,isvisit,matchkeys,type"
- if s.ModuleFlag != MemberFlag {
- if s.ModuleFlag == EntnicheFlag {
- } else {
- findSql += ",isvip"
- }
- }
- findSql += searchSql
- if isLimit {
- findSql += fmt.Sprintf(" limit %d,%d", (spqp.PageNum-1)*size, size)
- }
- logx.Info(spqp.UserId, "subscribePush query sql:", findSql)
- list := spqp.PushMysql.SelectBySql(findSql)
- if list != nil && len(*list) > 0 {
- pushCas := s.GetJyPushs(*list)
- result = s.GetInfoByIds(spqp.Mgo_bidding, spqp.Bidding, spqp.Bidding_back, pushCas)
- } else {
- result = []*bxsubscribe.SubscribeInfo{}
- }
- logx.Info("------ooooo----:", len(result))
- return
- }
- //根据id取内容
- func (s *subscribePush) GetInfoByIds(Mgo_bidding mongodb.MongodbSim, bidding, bidding_back string, pushCas []*PushCa) []*bxsubscribe.SubscribeInfo {
- array := make([]*bxsubscribe.SubscribeInfo, len(pushCas))
- if len(pushCas) == 0 {
- return array
- }
- m := map[string]bool{}
- ids := []string{}
- for _, v := range pushCas {
- if m[v.InfoId] {
- continue
- }
- m[v.InfoId] = true
- ids = append(ids, v.InfoId)
- }
- infos := map[string]map[string]interface{}{}
- //redis
- files := map[string]bool{}
- es_ids := []string{}
- for _, v := range ids {
- //剑鱼程序未找到赋值 位置;猜测在推送程序中
- info_i := redis.Get("pushcache_1", fmt.Sprintf("info_%s", v))
- if info_i != nil {
- info_m, _ := info_i.(map[string]interface{})
- info_m["_id"] = v
- infos[v] = info_m
- logx.Info("----", info_m, "----")
- files[v] = info_m["fileExists"] != nil
- } else {
- es_ids = append(es_ids, v)
- }
- }
- //elasticsearch
- if len(es_ids) > 0 {
- list := elastic.Get("bidding", "bidding", fmt.Sprintf(query, strings.Join(es_ids, `","`), len(es_ids)))
- if list != nil {
- for _, v := range *list {
- _id := common.ObjToString(v["_id"])
- infos[_id] = v
- files[_id] = v["filetext"] != nil
- }
- }
- }
- //mongodb bidding
- mgo_ids := []primitive.ObjectID{}
- for _, v := range es_ids {
- if infos[v] == nil {
- _id, _ := primitive.ObjectIDFromHex(v)
- mgo_ids = append(mgo_ids, _id)
- }
- }
- if len(mgo_ids) > 0 {
- list, ok := Mgo_bidding.Find(bidding, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
- if ok && *list != nil {
- for _, v := range *list {
- _id := mongodb.BsonIdToSId(v["_id"])
- v["_id"] = _id
- infos[_id] = v
- files[_id] = v["projectinfo"] != nil
- }
- }
- }
- //mongodb bidding_back
- mgo_back_ids := []primitive.ObjectID{}
- for _, v := range mgo_ids {
- if infos[mongodb.BsonIdToSId(v)] == nil {
- mgo_back_ids = append(mgo_back_ids, v)
- }
- }
- if len(mgo_back_ids) > 0 {
- list, ok := Mgo_bidding.Find(bidding_back, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
- if ok && *list != nil {
- for _, v := range *list {
- _id := mongodb.BsonIdToSId(v["_id"])
- v["_id"] = _id
- infos[_id] = v
- files[_id] = v["projectinfo"] != nil
- }
- }
- }
- //
- for k, v := range pushCas {
- info := infos[v.InfoId]
- if info == nil {
- info = map[string]interface{}{}
- }
- array[k] = s.InfoFormat(v, &info, &files)
- }
- return array
- }
- //获取历史推送
- func (s *subscribePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*PushCa) {
- pushCas = []*PushCa{}
- for _, v := range datas {
- keys := []string{}
- if matchkeys := common.ObjToString(v["matchkeys"]); matchkeys != "" {
- keys = strings.Split(matchkeys, " ")
- }
- pushCas = append(pushCas, &PushCa{
- Date: common.Int64All(v["date"]),
- InfoId: common.ObjToString(v["infoid"]),
- Visit: common.IntAll(v["isvisit"]),
- Index: common.Int64All(v["id"]),
- Keys: keys,
- Type: common.IntAll(v["type"]),
- Isvip: common.IntAll(v["isvip"]),
- })
- }
- return
- }
- //查看全部列表缓存
- func (s *subscribePush) PutAllCache(userId string, datas *SubPush) {
- redis.Put("pushcache_2_a", s.allKey(userId), datas, threeDay)
- }
- func (s *subscribePush) GetAllCache(userId string) (*SubPush, error) {
- return s.GetCache("pushcache_2_a", s.allKey(userId))
- }
- func (s *subscribePush) GetCache(code, key string) (*SubPush, error) {
- pc_a, err := redis.GetNewBytes(code, key)
- if err != nil {
- return nil, err
- }
- if pc_a == nil {
- return nil, nil
- }
- var p *SubPush
- if err := json.Unmarshal(*pc_a, &p); err != nil {
- return nil, err
- }
- return p, nil
- }
- //是否收藏
- func (s *subscribePush) MakeCollection(userId string, list []*bxsubscribe.SubscribeInfo) {
- if list == nil || len(list) == 0 {
- return
- }
- param := []interface{}{userId}
- wh := []string{}
- for _, v := range list {
- array := encrypt.DecodeArticleId2ByCheck(v.Id)
- if len(array) == 1 && array[0] != "" {
- param = append(param, array[0])
- wh = append(wh, "?")
- }
- }
- if len(wh) > 0 {
- result := IC.MainMysql.SelectBySql(`select bid from bdcollection where userid=? and bid in (`+strings.Join(wh, ",")+`)`, param...)
- bid_map := map[string]bool{}
- if result != nil {
- for _, v := range *result {
- bid_map[encrypt.EncodeArticleId2ByCheck(common.ObjToString(v["bid"]))] = true
- }
- }
- for _, v := range list {
- if bid_map[v.Id] {
- v.Collection = 1
- }
- }
- }
- }
- //仅移动端首页使用,历史推送7天信息
- func (s *subscribePush) sevenDayKey(userId string) string {
- return fmt.Sprintf("7day_subpush_%s", userId)
- }
- func (s *subscribePush) PutSevenDayCache(userId string, datas []*bxsubscribe.SubscribeInfo) {
- redis.Put("pushcache_2_a", s.sevenDayKey(userId), SubPush{Datas: datas}, 7*24*60*60)
- }
- //从pushcache_2_a中取
- func (s *subscribePush) GetSevenDayCache(userId string) ([]*bxsubscribe.SubscribeInfo, error) {
- allPush, _ := s.GetCache("pushcache_2_a", s.sevenDayKey(userId))
- if allPush != nil && allPush.Datas != nil && len(allPush.Datas) > 0 {
- return allPush.Datas, nil
- }
- return nil, nil
- }
- //历史推送记录中单条信息格式化
- func InfoFormats(info map[string]interface{}, tmp map[string]interface{}) map[string]interface{} {
- area := common.ObjToString(info["area"])
- if area == "A" {
- area = "全国"
- }
- industry := common.ObjToString(info["s_subscopeclass"])
- scs := strings.Split(industry, ",")
- if len(scs) > 0 {
- industry = scs[0]
- if industry != "" {
- iss := strings.Split(industry, "_")
- if len(iss) > 0 {
- industry = iss[0]
- }
- }
- }
- infotype := common.ObjToString(info["subtype"])
- if infotype == "" {
- infotype = common.ObjToString(info["toptype"])
- }
- if infotype == "" {
- infotype = common.ObjToString(info["type"])
- if infotype == "tender" {
- infotype = "招标"
- } else if infotype == "bid" {
- infotype = "中标"
- }
- }
- info["type"] = infotype
- return info
- }
- //UpdateUserPushUnread 更新app未读标识为已读
- func UpdateUserPushUnread(userid string, vt string) {
- if vt == MemberFlag {
- IC.Mgo.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_member_apppushunread": 0}})
- } else if vt == EntnicheFlag {
- IC.Mgo.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_entniche_apppushunread": 0}})
- } else {
- IC.Mgo.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_apppushunread": 0}})
- }
- }
- //
- //获取用户信息
- func (s *subscribePush) UserInfo(userId string) (*map[string]interface{}, int64) {
- user, ok := IC.Mgo.FindById("user", userId, `{"s_m_openid":1,"a_m_openid":1,"s_phone":1,"a_mergeorder":1,"o_jy":1,"l_firstpushtime":1,"i_vip_status":1,"l_vip_endtime":1,"o_vipjy":1,"i_member_status":1,"o_member_jy":1}`)
- if !ok || user == nil {
- return nil, 0
- }
- return user, common.Int64All((*user)["l_firstpushtime"])
- }
- //是否有订阅词
- func GetKeySet(t string, u *map[string]interface{}, data []string) (bool, []string) {
- var industry_ = []string{}
- if u != nil {
- if t == SubFreeFlag {
- o_jy, _ := (*u)["o_jy"].(map[string]interface{})
- a_key, _ := o_jy["a_key"].([]interface{})
- logx.Info(industry_, "--------------------------", len(a_key))
- return len(a_key) > 0, industry_
- } else {
- var obj map[string]interface{}
- if t == SubVipFlag {
- obj, _ = (*u)["o_vipjy"].(map[string]interface{})
- } else if t == MemberFlag {
- obj, _ = (*u)["o_member_jy"].(map[string]interface{})
- } else if t == EntnicheFlag {
- if len(data) > 0 {
- return true, data
- } else {
- return false, data
- }
- }
- if obj != nil {
- if buyerclassObj, ok := obj["a_buyerclass"].([]interface{}); ok {
- industry_ = common.ObjArrToStringArr(buyerclassObj)
- }
- itmes, _ := obj["a_items"].([]interface{})
- for _, v := range itmes {
- item, _ := v.(map[string]interface{})
- keys, _ := item["a_key"].([]interface{})
- if len(keys) > 0 {
- return true, industry_
- }
- }
- }
- }
- }
- return false, industry_
- }
|