|
@@ -1,882 +1,795 @@
|
|
|
package jy
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
- "fmt"
|
|
|
- "log"
|
|
|
- mg "mongodb"
|
|
|
- . "qfw/util"
|
|
|
- "qfw/util/elastic"
|
|
|
- "qfw/util/mysql"
|
|
|
- "qfw/util/redis"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
-
|
|
|
- "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "log"
|
|
|
+ mg "mongodb"
|
|
|
+ . "qfw/util"
|
|
|
+ "qfw/util/elastic"
|
|
|
+ "qfw/util/mysql"
|
|
|
+ "qfw/util/redis"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- threeDay = 172800
|
|
|
- halfOfDay = 43200
|
|
|
+ threeDay = 172800
|
|
|
+ halfOfDay = 43200
|
|
|
)
|
|
|
|
|
|
type SubPushList struct {
|
|
|
- Id string `json:"_id"`
|
|
|
- Title string `json:"title"`
|
|
|
- Area string `json:"area"`
|
|
|
- Buyerclass string `json:"buyerclass"`
|
|
|
- Type string `json:"type"`
|
|
|
- S_subscopeclass string `json:"s_subscopeclass"`
|
|
|
- Publishtime int64 `json:"publishtime"`
|
|
|
- Ca_index int64 `json:"ca_index"`
|
|
|
- Ca_date int64 `json:"ca_date"`
|
|
|
- Ca_isvisit int `json:"ca_isvisit"`
|
|
|
- Ca_isvip int `json:"ca_isvip"`
|
|
|
- Ca_type int `json:"ca_type"`
|
|
|
- Matchkeys []string `json:"matchkeys"`
|
|
|
- Budget interface{} `json:"budget"`
|
|
|
- Bidamount interface{} `json:"bidamount"`
|
|
|
- Collection int `json:"collection"`
|
|
|
- Buyer string `json:"buyer"`
|
|
|
- ProjectName string `json:"projectName"`
|
|
|
- S_winner string `json:"s_winner"`
|
|
|
- Bidopentime int64 `json:"bidopentime"`
|
|
|
+ Id string `json:"_id"`
|
|
|
+ Title string `json:"title"`
|
|
|
+ Area string `json:"area"`
|
|
|
+ Buyerclass string `json:"buyerclass"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ S_subscopeclass string `json:"s_subscopeclass"`
|
|
|
+ Publishtime int64 `json:"publishtime"`
|
|
|
+ Ca_index int64 `json:"ca_index"`
|
|
|
+ Ca_date int64 `json:"ca_date"`
|
|
|
+ Ca_isvisit int `json:"ca_isvisit"`
|
|
|
+ Ca_isvip int `json:"ca_isvip"`
|
|
|
+ Ca_type int `json:"ca_type"`
|
|
|
+ Matchkeys []string `json:"matchkeys"`
|
|
|
+ Budget interface{} `json:"budget"`
|
|
|
+ Bidamount interface{} `json:"bidamount"`
|
|
|
+ Collection int `json:"collection"`
|
|
|
+ Buyer string `json:"buyer"`
|
|
|
+ ProjectName string `json:"projectName"`
|
|
|
+ S_winner string `json:"s_winner"`
|
|
|
+ Bidopentime int64 `json:"bidopentime"`
|
|
|
}
|
|
|
|
|
|
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"],"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}`
|
|
|
- querys = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","title","detail","area","city","publishtime","projectname","buyer","buyerclass","s_winner","bidamount","subtype","toptype","href","projectcode","buyerperson","buyertel","budget","bidopentime","agency","projectscope","winnerperson","winnertel"]}`
|
|
|
-
|
|
|
- MemberFlag = "m"
|
|
|
- SubVipFlag = "v"
|
|
|
- EntnicheFlag = "s"
|
|
|
- SubFreeFlag = ""
|
|
|
+ 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"],"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}`
|
|
|
+ querys = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","title","detail","area","city","publishtime","projectname","buyer","buyerclass","s_winner","bidamount","subtype","toptype","href","projectcode","buyerperson","buyertel","budget","bidopentime","agency","projectscope","winnerperson","winnertel"]}`
|
|
|
+
|
|
|
+ MemberFlag = "m"
|
|
|
+ SubVipFlag = "v"
|
|
|
+ EntnicheFlag = "s"
|
|
|
+ SubFreeFlag = ""
|
|
|
)
|
|
|
|
|
|
var aboutDbMsg map[string]*AboutDbMsg = map[string]*AboutDbMsg{
|
|
|
- SubFreeFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
- SubVipFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
- MemberFlag: &AboutDbMsg{"pushmember", "memberpush"},
|
|
|
- EntnicheFlag: &AboutDbMsg{"pushentniche", "pushentniche"},
|
|
|
+ SubFreeFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
+ SubVipFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
+ MemberFlag: &AboutDbMsg{"pushmember", "memberpush"},
|
|
|
+ EntnicheFlag: &AboutDbMsg{"pushentniche", "pushentniche"},
|
|
|
}
|
|
|
|
|
|
type AboutDbMsg struct {
|
|
|
- MysqlTable string
|
|
|
- RedisKeyFlag string
|
|
|
+ MysqlTable string
|
|
|
+ RedisKeyFlag string
|
|
|
}
|
|
|
|
|
|
type SubPush struct {
|
|
|
- Date string
|
|
|
- Datas []*SubPushList
|
|
|
- Count int64
|
|
|
+ Date string
|
|
|
+ Datas []*SubPushList
|
|
|
+ Count int64
|
|
|
}
|
|
|
|
|
|
type PushCa struct {
|
|
|
- Date int64
|
|
|
- InfoId string
|
|
|
- Visit int
|
|
|
- Index int64
|
|
|
- Keys []string
|
|
|
- Type int
|
|
|
- Isvip int
|
|
|
+ Date int64
|
|
|
+ InfoId string
|
|
|
+ Visit int
|
|
|
+ Index int64
|
|
|
+ Keys []string
|
|
|
+ Type int
|
|
|
+ Isvip int
|
|
|
}
|
|
|
|
|
|
//查询参数
|
|
|
type SubPushQueryParam struct {
|
|
|
- Mgo_bidding mg.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
|
|
|
+ Mgo_bidding mg.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 //导出
|
|
|
}
|
|
|
|
|
|
func (spqp *SubPushQueryParam) IsEmpty() bool {
|
|
|
- return spqp.SelectTime == "" && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == ""
|
|
|
+ return spqp.SelectTime == "" && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == ""
|
|
|
}
|
|
|
|
|
|
type subscribePush struct {
|
|
|
- ModuleFlag string
|
|
|
+ ModuleFlag string
|
|
|
}
|
|
|
|
|
|
func NewSubscribePush(module ...string) *subscribePush {
|
|
|
- m := ""
|
|
|
- if len(module) > 0 {
|
|
|
- m = module[0]
|
|
|
- }
|
|
|
- return &subscribePush{m}
|
|
|
+ m := ""
|
|
|
+ if len(module) > 0 {
|
|
|
+ m = module[0]
|
|
|
+ }
|
|
|
+ return &subscribePush{m}
|
|
|
}
|
|
|
|
|
|
//从pushcache_2_a中取
|
|
|
-func (s *subscribePush) GetTodayCache(userId string) (*SubPush, error) {
|
|
|
- pc_a, err := redis.GetNewBytes("pushcache_2_b", s.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 (s *subscribePush) GetTodayCacheEntniche(entId int, userId string) (*SubPush, error) {
|
|
|
- pc_a, err := redis.GetNewBytes("pushcache_2_b", s.todayKeyEntniche(entId, 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
|
|
|
+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 (s *subscribePush) PutTodayCache(userId string, pc_a *SubPush) {
|
|
|
- redis.Put("pushcache_2_b", s.todayKey(userId), pc_a, threeDay)
|
|
|
-}
|
|
|
-
|
|
|
-//往pushcache_2_a中放
|
|
|
-func (s *subscribePush) PutTodayCacheEntniche(entId int, userId string, pc_a *SubPush) {
|
|
|
- redis.Put("pushcache_2_b", s.todayKeyEntniche(entId, userId), pc_a, threeDay)
|
|
|
+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)
|
|
|
-}
|
|
|
-
|
|
|
-//获取redis key
|
|
|
-func (s *subscribePush) todayKeyEntniche(entId int, userId string) string {
|
|
|
- return fmt.Sprintf("entnichepush_%d_%s", entId, userId)
|
|
|
+ return fmt.Sprintf("%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
|
|
|
}
|
|
|
func (s *subscribePush) allKey(userId string) string {
|
|
|
- log.Println(fmt.Sprintf("all_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId))
|
|
|
- return fmt.Sprintf("all_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
|
|
|
-}
|
|
|
-
|
|
|
-//查看全部列表缓存
|
|
|
-func (s *subscribePush) allKeyEntniche(entId int, userId string) string {
|
|
|
- return fmt.Sprintf("all_entnichepush_%d_%s", entId, userId)
|
|
|
+ log.Println(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{}) *SubPushList {
|
|
|
- area := ObjToString((*info)["area"])
|
|
|
- if area == "A" {
|
|
|
- area = "全国"
|
|
|
- }
|
|
|
- industry := 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 := ObjToString((*info)["subtype"])
|
|
|
- if infotype == "" {
|
|
|
- infotype = ObjToString((*info)["toptype"])
|
|
|
- }
|
|
|
- if infotype == "" {
|
|
|
- infotype = ObjToString((*info)["type"])
|
|
|
- if infotype == "tender" {
|
|
|
- infotype = "招标"
|
|
|
- } else if infotype == "bid" {
|
|
|
- infotype = "中标"
|
|
|
- }
|
|
|
- }
|
|
|
- _id := p.InfoId
|
|
|
- if _id == "" {
|
|
|
- _id = ObjToString((*info)["_id"])
|
|
|
- }
|
|
|
- return &SubPushList{
|
|
|
- Id: EncodeArticleId2ByCheck(_id),
|
|
|
- Title: ObjToString((*info)["title"]),
|
|
|
- Area: area,
|
|
|
- Buyerclass: ObjToString((*info)["buyerclass"]),
|
|
|
- Type: infotype,
|
|
|
- S_subscopeclass: industry,
|
|
|
- Publishtime: Int64All((*info)["publishtime"]),
|
|
|
- Ca_index: p.Index,
|
|
|
- Ca_date: p.Date,
|
|
|
- Ca_isvisit: p.Visit,
|
|
|
- Ca_isvip: p.Isvip,
|
|
|
- Ca_type: p.Type,
|
|
|
- Matchkeys: p.Keys,
|
|
|
- Budget: (*info)["budget"],
|
|
|
- Bidamount: (*info)["bidamount"],
|
|
|
- Buyer: ObjToString((*info)["buyer"]),
|
|
|
- ProjectName: ObjToString((*info)["projectname"]),
|
|
|
- S_winner: ObjToString((*info)["s_winner"]),
|
|
|
- Bidopentime: Int64All((*info)["bidopentime"]),
|
|
|
- }
|
|
|
+ area := ObjToString((*info)["area"])
|
|
|
+ if area == "A" {
|
|
|
+ area = "全国"
|
|
|
+ }
|
|
|
+ industry := 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 := ObjToString((*info)["subtype"])
|
|
|
+ if infotype == "" {
|
|
|
+ infotype = ObjToString((*info)["toptype"])
|
|
|
+ }
|
|
|
+ if infotype == "" {
|
|
|
+ infotype = ObjToString((*info)["type"])
|
|
|
+ if infotype == "tender" {
|
|
|
+ infotype = "招标"
|
|
|
+ } else if infotype == "bid" {
|
|
|
+ infotype = "中标"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _id := p.InfoId
|
|
|
+ if _id == "" {
|
|
|
+ _id = ObjToString((*info)["_id"])
|
|
|
+ }
|
|
|
+ return &SubPushList{
|
|
|
+ Id: EncodeArticleId2ByCheck(_id),
|
|
|
+ Title: ObjToString((*info)["title"]),
|
|
|
+ Area: area,
|
|
|
+ Buyerclass: ObjToString((*info)["buyerclass"]),
|
|
|
+ Type: infotype,
|
|
|
+ S_subscopeclass: industry,
|
|
|
+ Publishtime: Int64All((*info)["publishtime"]),
|
|
|
+ Ca_index: p.Index,
|
|
|
+ Ca_date: p.Date,
|
|
|
+ Ca_isvisit: p.Visit,
|
|
|
+ Ca_isvip: p.Isvip,
|
|
|
+ Ca_type: p.Type,
|
|
|
+ Matchkeys: p.Keys,
|
|
|
+ Budget: (*info)["budget"],
|
|
|
+ Bidamount: (*info)["bidamount"],
|
|
|
+ Buyer: ObjToString((*info)["buyer"]),
|
|
|
+ ProjectName: ObjToString((*info)["projectname"]),
|
|
|
+ S_winner: ObjToString((*info)["s_winner"]),
|
|
|
+ Bidopentime: Int64All((*info)["bidopentime"]),
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total int64, result []*SubPushList) {
|
|
|
- log.Println(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()
|
|
|
- log.Println(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()
|
|
|
- }
|
|
|
- }
|
|
|
- nowFormat := NowFormat(Date_Short_Layout)
|
|
|
- start := (spqp.PageNum - 1) * spqp.PageSize
|
|
|
- end := start + spqp.PageSize
|
|
|
- //时间是今天,没有别的过滤条件
|
|
|
- if nowFormat == FormatDateByInt64(&starttime, Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" {
|
|
|
- var subPush *SubPush
|
|
|
- var err error
|
|
|
- if s.ModuleFlag == "s" {
|
|
|
- subPush, err = s.GetTodayCacheEntniche(spqp.EntId, spqp.UserId)
|
|
|
- } else {
|
|
|
- subPush, err = s.GetTodayCache(spqp.UserId)
|
|
|
- }
|
|
|
- if err != nil {
|
|
|
- log.Println(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,
|
|
|
- }
|
|
|
- if s.ModuleFlag == "s" {
|
|
|
- s.PutTodayCacheEntniche(spqp.EntId, spqp.UserId, subPush)
|
|
|
- } else {
|
|
|
- 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
|
|
|
- log.Println("a2")
|
|
|
- var allCache *SubPush
|
|
|
- var err error
|
|
|
- if s.ModuleFlag == "s" {
|
|
|
- allCache, err = s.GetAllCacheEntniche(spqp.EntId,spqp.UserId)
|
|
|
- } else
|
|
|
- {
|
|
|
- allCache, err = s.GetAllCache(spqp.UserId)
|
|
|
- }
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- log.Println(spqp.UserId, "GetAllCache Error", err)
|
|
|
- }
|
|
|
- if err != nil || allCache == nil || allCache.Date != nowFormat || len(allCache.Datas) == 0 {
|
|
|
- log.Println("a3")
|
|
|
- spqp.PageNum = 1
|
|
|
- log.Println(1111)
|
|
|
- list, countSearch := s.getDatasFromMysql(spqp, starttime, endtime, AllSubPushCacheSize, true)
|
|
|
- allCache = &SubPush{
|
|
|
- Date: nowFormat,
|
|
|
- Datas: list,
|
|
|
- Count: countSearch,
|
|
|
- }
|
|
|
- if s.ModuleFlag == "s" {
|
|
|
- s.PutAllCacheEntniche(spqp.EntId, spqp.UserId,allCache)
|
|
|
- } else {
|
|
|
- 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 {
|
|
|
- log.Println("a4")
|
|
|
- result, total = s.getDatasFromMysql(spqp, starttime, endtime, spqp.PageSize, true)
|
|
|
- }
|
|
|
- if result == nil {
|
|
|
- result = []*SubPushList{}
|
|
|
- }
|
|
|
- hasNextPage = len(result) >= spqp.PageSize
|
|
|
- return
|
|
|
+ log.Println(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()
|
|
|
+ log.Println(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()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println(2222)
|
|
|
+ nowFormat := NowFormat(Date_Short_Layout)
|
|
|
+ start := (spqp.PageNum - 1) * spqp.PageSize
|
|
|
+ end := start + spqp.PageSize
|
|
|
+ //时间是今天,没有别的过滤条件
|
|
|
+ if nowFormat == FormatDateByInt64(&starttime, Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" {
|
|
|
+
|
|
|
+ log.Println("a1")
|
|
|
+ subPush, err := s.GetTodayCache(spqp.UserId)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(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
|
|
|
+ log.Println("a2")
|
|
|
+ allCache, err := s.GetAllCache(spqp.UserId)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(spqp.UserId, "GetAllCache Error", err)
|
|
|
+ }
|
|
|
+ if err != nil || allCache == nil || allCache.Date != nowFormat || len(allCache.Datas) == 0 {
|
|
|
+ log.Println("a3")
|
|
|
+ spqp.PageNum = 1
|
|
|
+ log.Println(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 {
|
|
|
+ log.Println("a4")
|
|
|
+ result, total = s.getDatasFromMysql(spqp, starttime, endtime, spqp.PageSize, true)
|
|
|
+ }
|
|
|
+ if result == nil {
|
|
|
+ result = []*SubPushList{}
|
|
|
+ }
|
|
|
+ hasNextPage = len(result) >= spqp.PageSize
|
|
|
+ return
|
|
|
}
|
|
|
func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, endtime int64, size int, isLimit bool) (result []*SubPushList, 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 PushMapping.City[v] > 0 {
|
|
|
- city = append(city, fmt.Sprint(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 PushMapping.Area[v] > 0 {
|
|
|
- area = append(area, fmt.Sprint(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(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(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)", 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))
|
|
|
-
|
|
|
- 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)
|
|
|
- }
|
|
|
-
|
|
|
- log.Println(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 = []*SubPushList{}
|
|
|
- }
|
|
|
- return
|
|
|
+ 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 PushMapping.City[v] > 0 {
|
|
|
+ city = append(city, fmt.Sprint(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 PushMapping.Area[v] > 0 {
|
|
|
+ area = append(area, fmt.Sprint(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(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(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)", 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))
|
|
|
+
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+
|
|
|
+ log.Println(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 = []*SubPushList{}
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
//获取历史推送
|
|
|
func (s *subscribePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*PushCa) {
|
|
|
- pushCas = []*PushCa{}
|
|
|
- for _, v := range datas {
|
|
|
- keys := []string{}
|
|
|
- if matchkeys := ObjToString(v["matchkeys"]); matchkeys != "" {
|
|
|
- keys = strings.Split(matchkeys, " ")
|
|
|
- }
|
|
|
- pushCas = append(pushCas, &PushCa{
|
|
|
- Date: Int64All(v["date"]),
|
|
|
- InfoId: ObjToString(v["infoid"]),
|
|
|
- Visit: IntAll(v["isvisit"]),
|
|
|
- Index: Int64All(v["id"]),
|
|
|
- Keys: keys,
|
|
|
- Type: IntAll(v["type"]),
|
|
|
- Isvip: IntAll(v["isvip"]),
|
|
|
- })
|
|
|
- }
|
|
|
- return
|
|
|
+ pushCas = []*PushCa{}
|
|
|
+ for _, v := range datas {
|
|
|
+ keys := []string{}
|
|
|
+ if matchkeys := ObjToString(v["matchkeys"]); matchkeys != "" {
|
|
|
+ keys = strings.Split(matchkeys, " ")
|
|
|
+ }
|
|
|
+ pushCas = append(pushCas, &PushCa{
|
|
|
+ Date: Int64All(v["date"]),
|
|
|
+ InfoId: ObjToString(v["infoid"]),
|
|
|
+ Visit: IntAll(v["isvisit"]),
|
|
|
+ Index: Int64All(v["id"]),
|
|
|
+ Keys: keys,
|
|
|
+ Type: IntAll(v["type"]),
|
|
|
+ Isvip: IntAll(v["isvip"]),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
//根据id取内容
|
|
|
func (s *subscribePush) GetInfoByIds(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, pushCas []*PushCa) []*SubPushList {
|
|
|
- array := make([]*SubPushList, 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
|
|
|
-
|
|
|
- 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
|
|
|
- } else {
|
|
|
- es_ids = append(es_ids, v)
|
|
|
- }
|
|
|
- }
|
|
|
- // log.Println(es_ids)
|
|
|
- //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 := ObjToString(v["_id"])
|
|
|
- infos[_id] = v
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //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 := mg.BsonIdToSId(v["_id"])
|
|
|
- v["_id"] = _id
|
|
|
- infos[_id] = v
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //mongodb bidding_back
|
|
|
- mgo_back_ids := []primitive.ObjectID{}
|
|
|
- for _, v := range mgo_ids {
|
|
|
- if infos[mg.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 := mg.BsonIdToSId(v["_id"])
|
|
|
- v["_id"] = _id
|
|
|
- infos[_id] = v
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //
|
|
|
- for k, v := range pushCas {
|
|
|
- info := infos[v.InfoId]
|
|
|
- if info == nil {
|
|
|
- info = map[string]interface{}{}
|
|
|
- }
|
|
|
- array[k] = s.InfoFormat(v, &info)
|
|
|
- }
|
|
|
- return array
|
|
|
+ array := make([]*SubPushList, 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
|
|
|
+
|
|
|
+ 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
|
|
|
+ } else {
|
|
|
+ es_ids = append(es_ids, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // log.Println(es_ids)
|
|
|
+ //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 := ObjToString(v["_id"])
|
|
|
+ infos[_id] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //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 := mg.BsonIdToSId(v["_id"])
|
|
|
+ v["_id"] = _id
|
|
|
+ infos[_id] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //mongodb bidding_back
|
|
|
+ mgo_back_ids := []primitive.ObjectID{}
|
|
|
+ for _, v := range mgo_ids {
|
|
|
+ if infos[mg.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 := mg.BsonIdToSId(v["_id"])
|
|
|
+ v["_id"] = _id
|
|
|
+ infos[_id] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //
|
|
|
+ for k, v := range pushCas {
|
|
|
+ info := infos[v.InfoId]
|
|
|
+ if info == nil {
|
|
|
+ info = map[string]interface{}{}
|
|
|
+ }
|
|
|
+ array[k] = s.InfoFormat(v, &info)
|
|
|
+ }
|
|
|
+ return array
|
|
|
}
|
|
|
|
|
|
//保存最近7天的数据到历史记录
|
|
|
func (s *subscribePush) MakeHistoryDatas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId string, PushView func(userid, allquery, field string, pageNum, pageSize int) (keys []interface{}, list *[]map[string]interface{})) (bool, []*SubPushList) {
|
|
|
- log.Println("匹配最近7天数据", userId)
|
|
|
- field := `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","buyerclass","budget","bidamount"`
|
|
|
- allquery := `{"range":{"publishtime":{"gt":%s}}}`
|
|
|
- allquery = fmt.Sprintf(allquery, fmt.Sprint(time.Now().AddDate(0, 0, -7).Unix()))
|
|
|
- //allquery = ``
|
|
|
- keys, list := PushView(userId, allquery, field, 1, 50)
|
|
|
- if list == nil || len(*list) == 0 {
|
|
|
- return true, nil
|
|
|
- }
|
|
|
- matchkeys := []string{}
|
|
|
- for _, v := range keys {
|
|
|
- matchkeys = append(matchkeys, strings.Join(ObjArrToStringArr(v.([]interface{})), "+"))
|
|
|
- }
|
|
|
- publishTitle := map[string]bool{}
|
|
|
- now := time.Now().Unix()
|
|
|
- var array []*SubPushList
|
|
|
- for i := len(*list) - 1; i >= 0; i-- {
|
|
|
- v := (*list)[i]
|
|
|
- var myInsert = make(map[string]interface{})
|
|
|
- title := strings.Replace(v["title"].(string), "\n", "", -1)
|
|
|
- area_check := ObjToString(v["area"])
|
|
|
- if area_check == "A" {
|
|
|
- area_check = "全国"
|
|
|
- }
|
|
|
- if publishTitle[area_check+title] {
|
|
|
- continue
|
|
|
- } else {
|
|
|
- publishTitle[area_check+title] = true
|
|
|
- }
|
|
|
- myInsert["userid"] = userId
|
|
|
- _id := ObjToString(v["_id"])
|
|
|
- myInsert["infoid"] = _id
|
|
|
- redisKey := fmt.Sprintf("pushinfo_%s_%s", userId, _id)
|
|
|
- if isExists, _ := redis.Exists("pushcache_2_a", redisKey); isExists {
|
|
|
- continue
|
|
|
- }
|
|
|
- myInsert["date"] = now
|
|
|
- myInsert["matchkeys"] = strings.Join(matchkeys, " ")
|
|
|
- if area_check != "" {
|
|
|
- if area_check == "全国" {
|
|
|
- myInsert["area"] = 0
|
|
|
- } else if area_mapping, ok := PushMapping.Area[area_check]; ok {
|
|
|
- myInsert["area"] = area_mapping
|
|
|
- }
|
|
|
- }
|
|
|
- if city_check := ObjToString(v["city"]); city_check != "" {
|
|
|
- if city_mapping, ok := PushMapping.City[city_check]; ok {
|
|
|
- myInsert["city"] = city_mapping
|
|
|
- }
|
|
|
- }
|
|
|
- if subtype := ObjToString(v["subtype"]); subtype != "" {
|
|
|
- if subtype_mapping, ok := PushMapping.Subtype[subtype]; ok {
|
|
|
- myInsert["subtype"] = subtype_mapping
|
|
|
- }
|
|
|
- }
|
|
|
- if toptype := ObjToString(v["toptype"]); toptype != "" {
|
|
|
- if toptype_mapping, ok := PushMapping.Toptype[toptype]; ok {
|
|
|
- myInsert["toptype"] = toptype_mapping
|
|
|
- }
|
|
|
- }
|
|
|
- if buyerclass := ObjToString(v["buyerclass"]); buyerclass != "" {
|
|
|
- if buyerclass_mapping, ok := PushMapping.Buyerclass[buyerclass]; ok {
|
|
|
- myInsert["buyerclass"] = buyerclass_mapping
|
|
|
- }
|
|
|
- }
|
|
|
- if s_subscopeclass := ObjToString(v["s_subscopeclass"]); s_subscopeclass != "" {
|
|
|
- subscopeclass := []string{}
|
|
|
- for _, v := range strings.Split(s_subscopeclass, ",") {
|
|
|
- if subscopeclass_mapping, ok := PushMapping.Subscopeclass[v]; ok {
|
|
|
- subscopeclass = append(subscopeclass, fmt.Sprint(subscopeclass_mapping))
|
|
|
- }
|
|
|
- }
|
|
|
- if len(subscopeclass) > 0 {
|
|
|
- myInsert["subscopeclass"] = strings.Join(subscopeclass, ",")
|
|
|
- }
|
|
|
- }
|
|
|
- id := PushMysql.Insert("pushsubscribe", myInsert)
|
|
|
- if id > 0 {
|
|
|
- redis.Put("pushcache_2_a", redisKey, 1, 86400)
|
|
|
- } else {
|
|
|
- continue
|
|
|
- }
|
|
|
- array = append(array, s.InfoFormat(&PushCa{
|
|
|
- InfoId: _id,
|
|
|
- Date: now,
|
|
|
- Index: id,
|
|
|
- Keys: matchkeys,
|
|
|
- }, &v))
|
|
|
- }
|
|
|
- var resultList []*SubPushList
|
|
|
- for i := len(array) - 1; i >= 0; i-- {
|
|
|
- resultList = append(resultList, array[i])
|
|
|
- }
|
|
|
- return true, resultList
|
|
|
+ log.Println("匹配最近7天数据", userId)
|
|
|
+ field := `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","buyerclass","budget","bidamount"`
|
|
|
+ allquery := `{"range":{"publishtime":{"gt":%s}}}`
|
|
|
+ allquery = fmt.Sprintf(allquery, fmt.Sprint(time.Now().AddDate(0, 0, -7).Unix()))
|
|
|
+ //allquery = ``
|
|
|
+ keys, list := PushView(userId, allquery, field, 1, 50)
|
|
|
+ if list == nil || len(*list) == 0 {
|
|
|
+ return true, nil
|
|
|
+ }
|
|
|
+ matchkeys := []string{}
|
|
|
+ for _, v := range keys {
|
|
|
+ matchkeys = append(matchkeys, strings.Join(ObjArrToStringArr(v.([]interface{})), "+"))
|
|
|
+ }
|
|
|
+ publishTitle := map[string]bool{}
|
|
|
+ now := time.Now().Unix()
|
|
|
+ var array []*SubPushList
|
|
|
+ for i := len(*list) - 1; i >= 0; i-- {
|
|
|
+ v := (*list)[i]
|
|
|
+ var myInsert = make(map[string]interface{})
|
|
|
+ title := strings.Replace(v["title"].(string), "\n", "", -1)
|
|
|
+ area_check := ObjToString(v["area"])
|
|
|
+ if area_check == "A" {
|
|
|
+ area_check = "全国"
|
|
|
+ }
|
|
|
+ if publishTitle[area_check+title] {
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ publishTitle[area_check+title] = true
|
|
|
+ }
|
|
|
+ myInsert["userid"] = userId
|
|
|
+ _id := ObjToString(v["_id"])
|
|
|
+ myInsert["infoid"] = _id
|
|
|
+ redisKey := fmt.Sprintf("pushinfo_%s_%s", userId, _id)
|
|
|
+ if isExists, _ := redis.Exists("pushcache_2_a", redisKey); isExists {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ myInsert["date"] = now
|
|
|
+ myInsert["matchkeys"] = strings.Join(matchkeys, " ")
|
|
|
+ if area_check != "" {
|
|
|
+ if area_check == "全国" {
|
|
|
+ myInsert["area"] = 0
|
|
|
+ } else if area_mapping, ok := PushMapping.Area[area_check]; ok {
|
|
|
+ myInsert["area"] = area_mapping
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if city_check := ObjToString(v["city"]); city_check != "" {
|
|
|
+ if city_mapping, ok := PushMapping.City[city_check]; ok {
|
|
|
+ myInsert["city"] = city_mapping
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if subtype := ObjToString(v["subtype"]); subtype != "" {
|
|
|
+ if subtype_mapping, ok := PushMapping.Subtype[subtype]; ok {
|
|
|
+ myInsert["subtype"] = subtype_mapping
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if toptype := ObjToString(v["toptype"]); toptype != "" {
|
|
|
+ if toptype_mapping, ok := PushMapping.Toptype[toptype]; ok {
|
|
|
+ myInsert["toptype"] = toptype_mapping
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if buyerclass := ObjToString(v["buyerclass"]); buyerclass != "" {
|
|
|
+ if buyerclass_mapping, ok := PushMapping.Buyerclass[buyerclass]; ok {
|
|
|
+ myInsert["buyerclass"] = buyerclass_mapping
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if s_subscopeclass := ObjToString(v["s_subscopeclass"]); s_subscopeclass != "" {
|
|
|
+ subscopeclass := []string{}
|
|
|
+ for _, v := range strings.Split(s_subscopeclass, ",") {
|
|
|
+ if subscopeclass_mapping, ok := PushMapping.Subscopeclass[v]; ok {
|
|
|
+ subscopeclass = append(subscopeclass, fmt.Sprint(subscopeclass_mapping))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(subscopeclass) > 0 {
|
|
|
+ myInsert["subscopeclass"] = strings.Join(subscopeclass, ",")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ id := PushMysql.Insert("pushsubscribe", myInsert)
|
|
|
+ if id > 0 {
|
|
|
+ redis.Put("pushcache_2_a", redisKey, 1, 86400)
|
|
|
+ } else {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ array = append(array, s.InfoFormat(&PushCa{
|
|
|
+ InfoId: _id,
|
|
|
+ Date: now,
|
|
|
+ Index: id,
|
|
|
+ Keys: matchkeys,
|
|
|
+ }, &v))
|
|
|
+ }
|
|
|
+ var resultList []*SubPushList
|
|
|
+ for i := len(array) - 1; i >= 0; i-- {
|
|
|
+ resultList = append(resultList, array[i])
|
|
|
+ }
|
|
|
+ return true, resultList
|
|
|
}
|
|
|
|
|
|
//获取用户信息
|
|
|
func (s *subscribePush) UserInfo(MQFW mg.MongodbSim, userId string) (*map[string]interface{}, int64) {
|
|
|
- user, ok := MQFW.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, Int64All((*user)["l_firstpushtime"])
|
|
|
+ user, ok := MQFW.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, Int64All((*user)["l_firstpushtime"])
|
|
|
}
|
|
|
func (s *subscribePush) Visit(PushMysql *mysql.Mysql, userId string, id int) {
|
|
|
- if userId == "" {
|
|
|
- return
|
|
|
- }
|
|
|
- PushMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1 where userid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), userId, id)
|
|
|
- todaySubPush, err := s.GetTodayCache(userId)
|
|
|
- if err == nil && todaySubPush != nil {
|
|
|
- for _, v := range todaySubPush.Datas {
|
|
|
- if v.Ca_index == Int64All(id) {
|
|
|
- v.Ca_isvisit = 1
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- s.PutTodayCache(userId, todaySubPush)
|
|
|
- }
|
|
|
- //
|
|
|
- allSubPush, err := s.GetAllCache(userId)
|
|
|
- if err == nil && allSubPush != nil {
|
|
|
- for _, v := range allSubPush.Datas {
|
|
|
- if v.Ca_index == Int64All(id) {
|
|
|
- v.Ca_isvisit = 1
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- s.PutAllCache(userId, allSubPush)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func (s *subscribePush) VisitEntniche(PushMysql *mysql.Mysql, entId int, userId string, id int) {
|
|
|
- if id <= 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- PushMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1 where userid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), userId, id)
|
|
|
-
|
|
|
- todaySubPush, err := s.GetTodayCacheEntniche(entId, userId)
|
|
|
- if err == nil && todaySubPush != nil {
|
|
|
- for _, v := range todaySubPush.Datas {
|
|
|
- if v.Ca_index == Int64All(id) {
|
|
|
- v.Ca_isvisit = 1
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- s.PutTodayCacheEntniche(entId, userId, todaySubPush)
|
|
|
- }
|
|
|
- //
|
|
|
- allSubPush, err := s.GetAllCacheEntniche(entId, userId)
|
|
|
- if err == nil && allSubPush != nil {
|
|
|
- for _, v := range allSubPush.Datas {
|
|
|
- if v.Ca_index == Int64All(id) {
|
|
|
- v.Ca_isvisit = 1
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- s.PutAllCacheEntniche(entId, userId, allSubPush)
|
|
|
- }
|
|
|
+ if userId == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ PushMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1 where userid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), userId, id)
|
|
|
+ todaySubPush, err := s.GetTodayCache(userId)
|
|
|
+ if err == nil && todaySubPush != nil {
|
|
|
+ for _, v := range todaySubPush.Datas {
|
|
|
+ if v.Ca_index == Int64All(id) {
|
|
|
+ v.Ca_isvisit = 1
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ s.PutTodayCache(userId, todaySubPush)
|
|
|
+ }
|
|
|
+ //
|
|
|
+ allSubPush, err := s.GetAllCache(userId)
|
|
|
+ if err == nil && allSubPush != nil {
|
|
|
+ for _, v := range allSubPush.Datas {
|
|
|
+ if v.Ca_index == Int64All(id) {
|
|
|
+ v.Ca_isvisit = 1
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ s.PutAllCache(userId, allSubPush)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//查看全部列表缓存
|
|
|
func (s *subscribePush) PutAllCache(userId string, datas *SubPush) {
|
|
|
- redis.Put("pushcache_2_a", s.allKey(userId), datas, threeDay)
|
|
|
-}
|
|
|
-func (s *subscribePush) PutAllCacheEntniche(entId int, userId string, datas *SubPush) {
|
|
|
- redis.Put("pushcache_2_a", s.allKeyEntniche(entId, userId), datas, threeDay)
|
|
|
+ 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) GetAllCacheEntniche(entId int, userId string) (*SubPush, error) {
|
|
|
- return s.GetCache("pushcache_2_a", s.allKeyEntniche(entId, userId))
|
|
|
+ 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
|
|
|
+ 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, m *mysql.Mysql, list []*SubPushList) {
|
|
|
- if list == nil || len(list) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- param := []interface{}{userId}
|
|
|
- wh := []string{}
|
|
|
- for _, v := range list {
|
|
|
- array := DecodeArticleId2ByCheck(v.Id)
|
|
|
- if len(array) == 1 && array[0] != "" {
|
|
|
- param = append(param, array[0])
|
|
|
- wh = append(wh, "?")
|
|
|
- }
|
|
|
- }
|
|
|
- if len(wh) > 0 {
|
|
|
- result := m.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[EncodeArticleId2ByCheck(ObjToString(v["bid"]))] = true
|
|
|
- }
|
|
|
- }
|
|
|
- for _, v := range list {
|
|
|
- if bid_map[v.Id] {
|
|
|
- v.Collection = 1
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if list == nil || len(list) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ param := []interface{}{userId}
|
|
|
+ wh := []string{}
|
|
|
+ for _, v := range list {
|
|
|
+ array := DecodeArticleId2ByCheck(v.Id)
|
|
|
+ if len(array) == 1 && array[0] != "" {
|
|
|
+ param = append(param, array[0])
|
|
|
+ wh = append(wh, "?")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(wh) > 0 {
|
|
|
+ result := m.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[EncodeArticleId2ByCheck(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)
|
|
|
+ return fmt.Sprintf("7day_subpush_%s", userId)
|
|
|
}
|
|
|
|
|
|
func (s *subscribePush) PutSevenDayCache(userId string, datas []*SubPushList) {
|
|
|
- redis.Put("pushcache_2_a", s.sevenDayKey(userId), SubPush{Datas: datas}, 7*24*60*60)
|
|
|
+ redis.Put("pushcache_2_a", s.sevenDayKey(userId), SubPush{Datas: datas}, 7*24*60*60)
|
|
|
}
|
|
|
|
|
|
//从pushcache_2_a中取
|
|
|
func (s *subscribePush) GetSevenDayCache(userId string) ([]*SubPushList, 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
|
|
|
+ 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 := ObjToString(info["area"])
|
|
|
- if area == "A" {
|
|
|
- area = "全国"
|
|
|
- }
|
|
|
- industry := 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 := ObjToString(info["subtype"])
|
|
|
- if infotype == "" {
|
|
|
- infotype = ObjToString(info["toptype"])
|
|
|
- }
|
|
|
- if infotype == "" {
|
|
|
- infotype = ObjToString(info["type"])
|
|
|
- if infotype == "tender" {
|
|
|
- infotype = "招标"
|
|
|
- } else if infotype == "bid" {
|
|
|
- infotype = "中标"
|
|
|
- }
|
|
|
- }
|
|
|
- info["type"] = infotype
|
|
|
- return info
|
|
|
+ area := ObjToString(info["area"])
|
|
|
+ if area == "A" {
|
|
|
+ area = "全国"
|
|
|
+ }
|
|
|
+ industry := 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 := ObjToString(info["subtype"])
|
|
|
+ if infotype == "" {
|
|
|
+ infotype = ObjToString(info["toptype"])
|
|
|
+ }
|
|
|
+ if infotype == "" {
|
|
|
+ infotype = ObjToString(info["type"])
|
|
|
+ if infotype == "tender" {
|
|
|
+ infotype = "招标"
|
|
|
+ } else if infotype == "bid" {
|
|
|
+ infotype = "中标"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ info["type"] = infotype
|
|
|
+ return info
|
|
|
}
|