|
@@ -1,1265 +1,1205 @@
|
|
package model
|
|
package model
|
|
|
|
|
|
import (
|
|
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"
|
|
|
|
- "database/sql"
|
|
|
|
- "encoding/json"
|
|
|
|
- "fmt"
|
|
|
|
- "github.com/zeromicro/go-zero/core/logx"
|
|
|
|
- "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
- IC "jyBXSubscribe/rpc/init"
|
|
|
|
- ms "jyBXSubscribe/rpc/model/service"
|
|
|
|
- "jyBXSubscribe/rpc/type/bxsubscribe"
|
|
|
|
- "log"
|
|
|
|
- "strconv"
|
|
|
|
- "strings"
|
|
|
|
- "sync"
|
|
|
|
- "time"
|
|
|
|
|
|
+ "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"
|
|
|
|
+ "database/sql"
|
|
|
|
+ "encoding/json"
|
|
|
|
+ "fmt"
|
|
|
|
+ "github.com/zeromicro/go-zero/core/logx"
|
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
+ IC "jyBXSubscribe/rpc/init"
|
|
|
|
+ ms "jyBXSubscribe/rpc/model/service"
|
|
|
|
+ "jyBXSubscribe/rpc/type/bxsubscribe"
|
|
|
|
+ "log"
|
|
|
|
+ "strconv"
|
|
|
|
+ "strings"
|
|
|
|
+ "sync"
|
|
|
|
+ "time"
|
|
)
|
|
)
|
|
|
|
|
|
//
|
|
//
|
|
const (
|
|
const (
|
|
- pageSize = 50
|
|
|
|
- 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}`
|
|
|
|
|
|
+ pageSize = 100
|
|
|
|
+ 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"
|
|
|
|
- oneDay = 24 * 60 * 60
|
|
|
|
- Pushbidding = "pushbidding"
|
|
|
|
- Province = "province"
|
|
|
|
|
|
+ SubFreeFlag = "fType"
|
|
|
|
+ SubVipFlag = "vType"
|
|
|
|
+ MemberFlag = "mType"
|
|
|
|
+ EntnicheFlag = "eType"
|
|
|
|
+ oneDay = 24 * 60 * 60
|
|
|
|
+ Baseinfo = "global_common_data.bid_baseinfo"
|
|
|
|
+ BidTags = "global_common_data.bid_tags"
|
|
)
|
|
)
|
|
|
|
|
|
var (
|
|
var (
|
|
- buildingInsertCollKey = []string{"infoid", "area", "city", "buyerclass", "toptype", "subtype", "subscopeclass", "budget", "bidamount", "attachment_count", "publishtime"}
|
|
|
|
- ennicheInsertCollKey = []string{"entid", "deptid", "userid", "infoid", "matchkeys", "date"}
|
|
|
|
- subscribeInsertCollKey = []string{"userid", "infoid", "matchkeys", "date", "isvip"}
|
|
|
|
- memberInsertCollKey = []string{"userid", "infoid", "matchkeys", "date"}
|
|
|
|
|
|
+ ennicheInsertCollKey = []string{"entid", "deptid", "userid", "infoid", "matchkeys", "date"}
|
|
|
|
+ subscribeInsertCollKey = []string{"userid", "infoid", "matchkeys", "date", "isvip"}
|
|
|
|
+ memberInsertCollKey = []string{"userid", "infoid", "matchkeys", "date"}
|
|
)
|
|
)
|
|
|
|
|
|
var aboutDbMsg map[string]*AboutDbMsg = map[string]*AboutDbMsg{
|
|
var aboutDbMsg map[string]*AboutDbMsg = map[string]*AboutDbMsg{
|
|
- SubFreeFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
|
- SubVipFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
|
- MemberFlag: &AboutDbMsg{"pushmember", "memberpush"},
|
|
|
|
- EntnicheFlag: &AboutDbMsg{"pushentniche", "entnichepush"},
|
|
|
|
|
|
+ SubFreeFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
|
+ SubVipFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
|
+ MemberFlag: &AboutDbMsg{"pushmember", "memberpush"},
|
|
|
|
+ EntnicheFlag: &AboutDbMsg{"pushentniche", "entnichepush"},
|
|
}
|
|
}
|
|
|
|
|
|
type AboutDbMsg struct {
|
|
type AboutDbMsg struct {
|
|
- MysqlTable string
|
|
|
|
- RedisKeyFlag string
|
|
|
|
|
|
+ MysqlTable string
|
|
|
|
+ RedisKeyFlag string
|
|
}
|
|
}
|
|
|
|
|
|
type SubPush struct {
|
|
type SubPush struct {
|
|
- Date string
|
|
|
|
- Datas []*bxsubscribe.SubscribeInfo
|
|
|
|
- Count int64
|
|
|
|
|
|
+ Date string
|
|
|
|
+ Datas []*bxsubscribe.SubscribeInfo
|
|
|
|
+ Count int64
|
|
}
|
|
}
|
|
|
|
|
|
type PushCa struct {
|
|
type PushCa struct {
|
|
- Date int64
|
|
|
|
- InfoId string
|
|
|
|
- Visit int
|
|
|
|
- Index int64
|
|
|
|
- Keys []string
|
|
|
|
- Type int
|
|
|
|
- Isvip int
|
|
|
|
- FileExists bool
|
|
|
|
|
|
+ Date int64
|
|
|
|
+ InfoId string
|
|
|
|
+ Visit int
|
|
|
|
+ Index int64
|
|
|
|
+ Keys []string
|
|
|
|
+ Type int
|
|
|
|
+ Isvip int
|
|
|
|
+ FileExists bool
|
|
}
|
|
}
|
|
|
|
|
|
//查询参数
|
|
//查询参数
|
|
type SubPushQueryParam struct {
|
|
type SubPushQueryParam struct {
|
|
- Mgo_bidding mongodb.MongodbSim //
|
|
|
|
- Bidding string //
|
|
|
|
- Bidding_back string //
|
|
|
|
- UserId string //用户id
|
|
|
|
- PageNum int //页面
|
|
|
|
- PageSize int //每页数量
|
|
|
|
- SelectTime string //时间
|
|
|
|
- Area string //区域
|
|
|
|
- City string //城市
|
|
|
|
- Buyerclass string //采购单位行业
|
|
|
|
- Subtype string //信息类型 二级分类
|
|
|
|
- Subscopeclass string //信息行业
|
|
|
|
- Key string //订阅词
|
|
|
|
- Export bool //导出
|
|
|
|
- EntId string //企业id
|
|
|
|
- Price string //价格
|
|
|
|
- FileExists string //是否有附件;默认全部;1:有附件;-1:无附件
|
|
|
|
- EntUserId string //商机管理用户id
|
|
|
|
- DeptId string //商机管理用户部门id
|
|
|
|
- BaseServiceMysql *mysql.Mysql
|
|
|
|
- NewUserId int64
|
|
|
|
|
|
+ Mgo_bidding mongodb.MongodbSim //
|
|
|
|
+ Bidding string //
|
|
|
|
+ Bidding_back string //
|
|
|
|
+ UserId string //用户id
|
|
|
|
+ PageNum int //页面
|
|
|
|
+ PageSize int //每页数量
|
|
|
|
+ SelectTime string //时间
|
|
|
|
+ Area string //区域
|
|
|
|
+ City string //城市
|
|
|
|
+ Buyerclass string //采购单位行业
|
|
|
|
+ Subtype string //信息类型 二级分类
|
|
|
|
+ Subscopeclass string //信息行业
|
|
|
|
+ Key string //订阅词
|
|
|
|
+ Export bool //导出
|
|
|
|
+ EntId string //企业id
|
|
|
|
+ Price string //价格
|
|
|
|
+ FileExists string //是否有附件;默认全部;1:有附件;-1:无附件
|
|
|
|
+ EntUserId string //商机管理用户id
|
|
|
|
+ DeptId string //商机管理用户部门id
|
|
|
|
+ BaseServiceMysql *mysql.Mysql
|
|
|
|
+ NewUserId int64
|
|
}
|
|
}
|
|
|
|
|
|
func (spqp *SubPushQueryParam) IsEmpty() bool {
|
|
func (spqp *SubPushQueryParam) IsEmpty() bool {
|
|
- return spqp.SelectTime == "" && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == ""
|
|
|
|
|
|
+ return spqp.SelectTime == "" && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == ""
|
|
}
|
|
}
|
|
|
|
|
|
type subscribePush struct {
|
|
type subscribePush struct {
|
|
- ModuleFlag string
|
|
|
|
|
|
+ ModuleFlag string
|
|
}
|
|
}
|
|
|
|
|
|
func NewSubscribePush(module ...string) *subscribePush {
|
|
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中取
|
|
//从pushcache_2_a中取
|
|
func (s *subscribePush) GetTodayCache(userId string) (*SubPush, error) {
|
|
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
|
|
|
|
|
|
+ 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中放
|
|
//往pushcache_2_a中放
|
|
func (s *subscribePush) PutTodayCache(userId string, pc_a *SubPush) {
|
|
func (s *subscribePush) PutTodayCache(userId string, pc_a *SubPush) {
|
|
- redis.Put("pushcache_2_b", s.todayKey(userId), pc_a, oneDay)
|
|
|
|
|
|
+ redis.Put("pushcache_2_b", s.todayKey(userId), pc_a, oneDay)
|
|
}
|
|
}
|
|
|
|
|
|
//获取redis key
|
|
//获取redis key
|
|
func (s *subscribePush) todayKey(userId string) string {
|
|
func (s *subscribePush) todayKey(userId string) string {
|
|
- return fmt.Sprintf("%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
|
|
|
|
|
|
+ return fmt.Sprintf("%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
|
|
}
|
|
}
|
|
func (s *subscribePush) allKey(userId string) string {
|
|
func (s *subscribePush) allKey(userId string) string {
|
|
- return 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{}) *bxsubscribe.SubscribeInfo {
|
|
func (s *subscribePush) InfoFormat(p *PushCa, info *map[string]interface{}) *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{
|
|
|
|
- XId: 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"]),
|
|
|
|
- CaFileExists: p.FileExists,
|
|
|
|
- }
|
|
|
|
|
|
+ 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{
|
|
|
|
+ XId: 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"]),
|
|
|
|
+ CaFileExists: p.FileExists,
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total int64, result []*bxsubscribe.SubscribeInfo) {
|
|
func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total int64, result []*bxsubscribe.SubscribeInfo) {
|
|
- logx.Info(spqp.UserId, spqp.NewUserId, 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, "Price:", spqp.Price, "FileExists:", spqp.FileExists)
|
|
|
|
- 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)
|
|
|
|
- logx.Info(4444)
|
|
|
|
- if len(strings.Split(spqp.SelectTime, "_")) == 2 {
|
|
|
|
- st := strings.Split(spqp.SelectTime, "_")[0]
|
|
|
|
- et := strings.Split(spqp.SelectTime, "_")[1]
|
|
|
|
- if st != "" && et != "" {
|
|
|
|
- starttime, _ = strconv.ParseInt(st, 0, 64)
|
|
|
|
- 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 := 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 == "" && spqp.Price == "" && spqp.FileExists == "" {
|
|
|
|
- logx.Info("a1:", s.todayKey(spqp.UserId))
|
|
|
|
- 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:", s.allKey(spqp.UserId))
|
|
|
|
- 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))
|
|
|
|
- log.Println(spqp.IsEmpty() && (spqp.PageNum-1)*spqp.PageSize <= 250)
|
|
|
|
- if result == nil {
|
|
|
|
- result = []*bxsubscribe.SubscribeInfo{}
|
|
|
|
- }
|
|
|
|
- hasNextPage = len(result) >= spqp.PageSize
|
|
|
|
- return
|
|
|
|
|
|
+ logx.Info(spqp.UserId, spqp.NewUserId, 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, "Price:", spqp.Price, "FileExists:", spqp.FileExists)
|
|
|
|
+ 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)
|
|
|
|
+ if len(strings.Split(spqp.SelectTime, "_")) == 2 {
|
|
|
|
+ st := strings.Split(spqp.SelectTime, "_")[0]
|
|
|
|
+ et := strings.Split(spqp.SelectTime, "_")[1]
|
|
|
|
+ if st != "" && et != "" {
|
|
|
|
+ starttime, _ = strconv.ParseInt(st, 0, 64)
|
|
|
|
+ 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 := 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 == "" && spqp.Price == "" && spqp.FileExists == "" {
|
|
|
|
+ logx.Info("a1:", s.todayKey(spqp.UserId))
|
|
|
|
+ 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:", s.allKey(spqp.UserId))
|
|
|
|
+ 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))
|
|
|
|
+ log.Println(spqp.IsEmpty() && (spqp.PageNum-1)*spqp.PageSize <= 250)
|
|
|
|
+ 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) {
|
|
func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, endtime int64, size int, isLimit bool) (result []*bxsubscribe.SubscribeInfo, count int64) {
|
|
- querys := []string{fmt.Sprintf("a.userid='%s'", common.If(s.ModuleFlag == "eType", spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))}
|
|
|
|
- //时间
|
|
|
|
- if starttime > 0 && endtime > 0 {
|
|
|
|
- querys = append(querys, fmt.Sprintf("a.date>=%d and date<=%d", starttime, endtime))
|
|
|
|
- } else if starttime > 0 && endtime == 0 {
|
|
|
|
- querys = append(querys, fmt.Sprintf("a.date>=%d", starttime))
|
|
|
|
- } else if starttime == 0 && endtime > 0 {
|
|
|
|
- querys = append(querys, fmt.Sprintf("a.date<=%d", endtime))
|
|
|
|
- }
|
|
|
|
- if spqp.Area != "" || spqp.City != "" {
|
|
|
|
- var sqlAreaCity = ""
|
|
|
|
- //城市
|
|
|
|
- city := []string{}
|
|
|
|
- for _, v := range strings.Split(spqp.City, ",") {
|
|
|
|
- if IC.PushMapping.City[v] != "" {
|
|
|
|
- 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("p.city in (%s)", strings.Join(city, ","))
|
|
|
|
- }
|
|
|
|
- //区域
|
|
|
|
- var sqlArea = ""
|
|
|
|
- area := []string{}
|
|
|
|
- for _, v := range strings.Split(spqp.Area, ",") {
|
|
|
|
- if IC.PushMapping.Area[v] != "" {
|
|
|
|
- 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("p.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("b.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("b.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',b.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(a.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 ")))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //价格- 预算和中标金额
|
|
|
|
- if spqp.Price != "" && strings.Contains(spqp.Price, "-") {
|
|
|
|
- minPriceStr, maxPriceStr := strings.Split(spqp.Price, "-")[0], strings.Split(spqp.Price, "-")[1]
|
|
|
|
- minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元
|
|
|
|
- maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元
|
|
|
|
- if minPriceStr != "" && maxPriceStr != "" {
|
|
|
|
- querys = append(querys, fmt.Sprintf("((b.bidamount>=%d and b.bidamount<=%d) or (b.budget>=%d and b.budget<=%d and b.bidamount is null))", minPrice, maxPrice, minPrice, maxPrice))
|
|
|
|
- } else if minPriceStr != "" {
|
|
|
|
- querys = append(querys, fmt.Sprintf("(b.bidamount>=%d or (b.budget>=%d and b.bidamount is null))", minPrice, minPrice))
|
|
|
|
- } else if maxPriceStr != "" {
|
|
|
|
- querys = append(querys, fmt.Sprintf("(b.bidamount<=%d or (b.budget<=%d and b.bidamount is null))", maxPrice, maxPrice))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //附件
|
|
|
|
- if spqp.FileExists != "" {
|
|
|
|
- if spqp.FileExists == "1" {
|
|
|
|
- querys = append(querys, fmt.Sprintf("b.attachment_count is not null"))
|
|
|
|
- } else if spqp.FileExists == "-1" {
|
|
|
|
- querys = append(querys, fmt.Sprintf("b.attachment_count is null"))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- searchSql := fmt.Sprintf(" from %s a LEFT JOIN %s b ON a.infoid = b.infoid LEFT JOIN %s p on b.area=p.id or b.city=p.id where %s"+
|
|
|
|
- " order by a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Pushbidding, Province, strings.Join(querys, " and "))
|
|
|
|
- fmt.Println("searchSql", searchSql)
|
|
|
|
- //查询总数
|
|
|
|
- count = spqp.BaseServiceMysql.CountBySql(fmt.Sprintf("select count(a.id)" + searchSql))
|
|
|
|
- logx.Info("count:", count, "---", s.ModuleFlag)
|
|
|
|
- findSql := "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.attachment_count"
|
|
|
|
- if s.ModuleFlag != MemberFlag && s.ModuleFlag != EntnicheFlag {
|
|
|
|
- findSql += ",isvip"
|
|
|
|
- }
|
|
|
|
- findSql += searchSql
|
|
|
|
- if isLimit {
|
|
|
|
- findSql += fmt.Sprintf(" limit %d,%d", (spqp.PageNum-1)*size, size)
|
|
|
|
- }
|
|
|
|
- logx.Info(spqp.NewUserId, "subscribePush query sql:", findSql)
|
|
|
|
- list := spqp.BaseServiceMysql.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{}
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
|
|
+ querys := []string{fmt.Sprintf("a.userid='%s'", common.If(s.ModuleFlag == "eType", spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))}
|
|
|
|
+ //时间
|
|
|
|
+ if starttime > 0 && endtime > 0 {
|
|
|
|
+ querys = append(querys, fmt.Sprintf("a.date>=%d and date<=%d", starttime, endtime))
|
|
|
|
+ } else if starttime > 0 && endtime == 0 {
|
|
|
|
+ querys = append(querys, fmt.Sprintf("a.date>=%d", starttime))
|
|
|
|
+ } else if starttime == 0 && endtime > 0 {
|
|
|
|
+ querys = append(querys, fmt.Sprintf("a.date<=%d", endtime))
|
|
|
|
+ }
|
|
|
|
+ if spqp.Area != "" || spqp.City != "" {
|
|
|
|
+ var sqlAreaCity = ""
|
|
|
|
+ //城市
|
|
|
|
+ city := []string{}
|
|
|
|
+ for _, v := range strings.Split(spqp.City, ",") {
|
|
|
|
+ if IC.PushMapping.City[v] != "" {
|
|
|
|
+ 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("p.city in (%s)", strings.Join(city, ","))
|
|
|
|
+ }
|
|
|
|
+ //区域
|
|
|
|
+ var sqlArea = ""
|
|
|
|
+ area := []string{}
|
|
|
|
+ for _, v := range strings.Split(spqp.Area, ",") {
|
|
|
|
+ if IC.PushMapping.Area[v] != "" {
|
|
|
|
+ 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("p.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, ",") {
|
|
|
|
+ if IC.PushMapping.Buyerclass[v] != "" {
|
|
|
|
+ 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("b.buyerclass_code in (%s)", strings.Join(buyerclass, ",")))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ //信息类型
|
|
|
|
+ if spqp.Subtype != "" {
|
|
|
|
+ subtype := []string{}
|
|
|
|
+ for _, v := range strings.Split(spqp.Subtype, ",") {
|
|
|
|
+ if IC.PushMapping.Subtype[v] != "" {
|
|
|
|
+ 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("b.subtype_code in (%s)", strings.Join(subtype, ",")))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ //信息行业
|
|
|
|
+ if spqp.Subscopeclass != "" {
|
|
|
|
+ find_in_set := []string{}
|
|
|
|
+ for _, v := range strings.Split(spqp.Subscopeclass, ",") {
|
|
|
|
+ if IC.PushMapping.Subscopeclass[v] != "" {
|
|
|
|
+ find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%s',t.subscopeclass) and t.labelcode=2 ", 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(a.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 ")))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //价格- 预算和中标金额
|
|
|
|
+ if spqp.Price != "" && strings.Contains(spqp.Price, "-") {
|
|
|
|
+ minPriceStr, maxPriceStr := strings.Split(spqp.Price, "-")[0], strings.Split(spqp.Price, "-")[1]
|
|
|
|
+ minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元
|
|
|
|
+ maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元
|
|
|
|
+ if minPriceStr != "" && maxPriceStr != "" {
|
|
|
|
+ querys = append(querys, fmt.Sprintf("((b.bidamount>=%d and b.bidamount<=%d) or (b.budget>=%d and b.budget<=%d and b.bidamount is null))", minPrice, maxPrice, minPrice, maxPrice))
|
|
|
|
+ } else if minPriceStr != "" {
|
|
|
|
+ querys = append(querys, fmt.Sprintf("(b.bidamount>=%d or (b.budget>=%d and b.bidamount is null))", minPrice, minPrice))
|
|
|
|
+ } else if maxPriceStr != "" {
|
|
|
|
+ querys = append(querys, fmt.Sprintf("(b.bidamount<=%d or (b.budget<=%d and b.bidamount is null))", maxPrice, maxPrice))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //附件
|
|
|
|
+ if spqp.FileExists != "" {
|
|
|
|
+ if spqp.FileExists == "1" {
|
|
|
|
+ querys = append(querys, fmt.Sprintf("b.isvalidfile =1 "))
|
|
|
|
+ } else if spqp.FileExists == "-1" {
|
|
|
|
+ querys = append(querys, fmt.Sprintf("b.isvalidfile =0 "))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ searchSql := fmt.Sprintf(" from %s a LEFT JOIN %s b ON a.infoid = b.infoid LEFT JOIN %s t on t.infoid = b.infoid and t.labelcode=2 where %s"+
|
|
|
|
+ " order by a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, BidTags, strings.Join(querys, " and "))
|
|
|
|
+ fmt.Println("searchSql", searchSql)
|
|
|
|
+ //查询总数
|
|
|
|
+ count = spqp.BaseServiceMysql.CountBySql(fmt.Sprintf("select count(a.id)" + searchSql))
|
|
|
|
+ logx.Info("count:", count, "---", s.ModuleFlag)
|
|
|
|
+ findSql := "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
|
|
|
|
+ if s.ModuleFlag != MemberFlag && s.ModuleFlag != EntnicheFlag {
|
|
|
|
+ findSql += ",isvip"
|
|
|
|
+ }
|
|
|
|
+ findSql += searchSql
|
|
|
|
+ if isLimit {
|
|
|
|
+ findSql += fmt.Sprintf(" limit %d,%d", (spqp.PageNum-1)*size, size)
|
|
|
|
+ }
|
|
|
|
+ logx.Info(spqp.NewUserId, "subscribePush query sql:", findSql)
|
|
|
|
+ list := spqp.BaseServiceMysql.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{}
|
|
|
|
+ }
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
//根据id取内容
|
|
//根据id取内容
|
|
func (s *subscribePush) GetInfoByIds(Mgo_bidding mongodb.MongodbSim, bidding, bidding_back string, pushCas []*PushCa) []*bxsubscribe.SubscribeInfo {
|
|
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
|
|
|
|
- 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)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //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
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //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
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //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
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //
|
|
|
|
- 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([]*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
|
|
|
|
+ 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)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //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
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //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
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //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
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //
|
|
|
|
+ for k, v := range pushCas {
|
|
|
|
+ info := infos[v.InfoId]
|
|
|
|
+ if info == nil {
|
|
|
|
+ info = map[string]interface{}{}
|
|
|
|
+ }
|
|
|
|
+ array[k] = s.InfoFormat(v, &info)
|
|
|
|
+ }
|
|
|
|
+ return array
|
|
}
|
|
}
|
|
|
|
|
|
//获取历史推送
|
|
//获取历史推送
|
|
func (s *subscribePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*PushCa) {
|
|
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"]),
|
|
|
|
- FileExists: common.IntAll(v["attachment_count"]) > 0,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
|
|
+ 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"]),
|
|
|
|
+ FileExists: common.IntAll(v["attachment_count"]) > 0,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
//查看全部列表缓存
|
|
//查看全部列表缓存
|
|
func (s *subscribePush) PutAllCache(userId string, datas *SubPush) {
|
|
func (s *subscribePush) PutAllCache(userId string, datas *SubPush) {
|
|
- log.Println(s.allKey(userId), datas, oneDay)
|
|
|
|
- redis.Put("pushcache_2_a", s.allKey(userId), datas, oneDay)
|
|
|
|
|
|
+ log.Println(s.allKey(userId), datas, oneDay)
|
|
|
|
+ redis.Put("pushcache_2_a", s.allKey(userId), datas, oneDay)
|
|
}
|
|
}
|
|
|
|
|
|
func (s *subscribePush) GetAllCache(userId string) (*SubPush, error) {
|
|
func (s *subscribePush) GetAllCache(userId string) (*SubPush, error) {
|
|
- return s.GetCache("pushcache_2_a", s.allKey(userId))
|
|
|
|
|
|
+ return s.GetCache("pushcache_2_a", s.allKey(userId))
|
|
}
|
|
}
|
|
|
|
|
|
func (s *subscribePush) GetCache(code, key string) (*SubPush, error) {
|
|
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, list []*bxsubscribe.SubscribeInfo) {
|
|
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.XId)
|
|
|
|
- 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.XId] {
|
|
|
|
- v.Collection = 1
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if list == nil || len(list) == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ param := []interface{}{userId}
|
|
|
|
+ wh := []string{}
|
|
|
|
+ for _, v := range list {
|
|
|
|
+ array := encrypt.DecodeArticleId2ByCheck(v.XId)
|
|
|
|
+ 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.XId] {
|
|
|
|
+ v.Collection = 1
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//仅移动端首页使用,历史推送7天信息
|
|
//仅移动端首页使用,历史推送7天信息
|
|
func (s *subscribePush) sevenDayKey(userId string) string {
|
|
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 []*bxsubscribe.SubscribeInfo) {
|
|
func (s *subscribePush) PutSevenDayCache(userId string, datas []*bxsubscribe.SubscribeInfo) {
|
|
- 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中取
|
|
//从pushcache_2_a中取
|
|
func (s *subscribePush) GetSevenDayCache(userId string) ([]*bxsubscribe.SubscribeInfo, error) {
|
|
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
|
|
|
|
|
|
+ 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{} {
|
|
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
|
|
|
|
|
|
+ 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未读标识为已读
|
|
//UpdateUserPushUnread 更新app未读标识为已读
|
|
func UpdateUserPushUnread(userid string, vt string) {
|
|
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}})
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ 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) {
|
|
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"])
|
|
|
|
|
|
+ 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) {
|
|
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{})
|
|
|
|
- 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)
|
|
|
|
|
|
+ var industry_ = []string{}
|
|
|
|
+ if u != nil {
|
|
|
|
+ if t == SubFreeFlag {
|
|
|
|
+ o_jy, _ := (*u)["o_jy"].(map[string]interface{})
|
|
|
|
+ a_key, _ := o_jy["a_key"].([]interface{})
|
|
|
|
+ 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_
|
|
}
|
|
}
|
|
- 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_
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false, industry_
|
|
}
|
|
}
|
|
|
|
|
|
const (
|
|
const (
|
|
- INDEX = "bidding"
|
|
|
|
- TYPE = "bidding"
|
|
|
|
- bidField = `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","buyerclass","budget","bidamount","filetext","spidercode","site"`
|
|
|
|
- bidTime = `{"range":{"publishtime":{"gt":%d}}}`
|
|
|
|
- bidSort = `{"publishtime":"desc"}`
|
|
|
|
- findfields = `"title"`
|
|
|
|
|
|
+ INDEX = "bidding"
|
|
|
|
+ TYPE = "bidding"
|
|
|
|
+ bidField = `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","buyerclass","budget","bidamount","filetext","spidercode","site"`
|
|
|
|
+ bidTime = `{"":{"publishtime":{"gt":%d}}}`
|
|
|
|
+ bidSort = `{"publishtime":"desc"}`
|
|
|
|
+ findfields = `"title"`
|
|
)
|
|
)
|
|
|
|
|
|
//首次访问推送页面 默认生成推送数据
|
|
//首次访问推送页面 默认生成推送数据
|
|
//默认匹配es 7天内数据
|
|
//默认匹配es 7天内数据
|
|
func (s *subscribePush) DefaultDatas(spqp *SubPushQueryParam) (hasNextPage bool, total int64, result []*bxsubscribe.SubscribeInfo) {
|
|
func (s *subscribePush) DefaultDatas(spqp *SubPushQueryParam) (hasNextPage bool, total int64, result []*bxsubscribe.SubscribeInfo) {
|
|
- if spqp.UserId == "" {
|
|
|
|
- return false, 0, nil
|
|
|
|
- }
|
|
|
|
- t1 := time.Now()
|
|
|
|
- log.Println("userId:", spqp.UserId)
|
|
|
|
- log.Println("newUserId:", spqp.NewUserId)
|
|
|
|
- //用户信息
|
|
|
|
- bsp := s.getUserInfo(spqp)
|
|
|
|
- logx.Info("获取用户信息耗时:", time.Since(t1))
|
|
|
|
- t2 := time.Now()
|
|
|
|
- if len(bsp.Keyword) > 0 {
|
|
|
|
- logx.Info(time.Since(t1), "--bsp:", bsp)
|
|
|
|
- //获取查询语句
|
|
|
|
- qstr := s.getDefaultDatasSQL(bsp)
|
|
|
|
- list := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSort, bidField, 0, bsp.Size, 0, false)
|
|
|
|
- logx.Info(time.Since(t1), "count:", len(*list))
|
|
|
|
- if list != nil && len(*list) > 0 {
|
|
|
|
- total = int64(len(*list))
|
|
|
|
- //超过50条先处理50条 返回前50条
|
|
|
|
- listOne := *list
|
|
|
|
- if len(*list) > pageSize {
|
|
|
|
- listOne = (*list)[:pageSize]
|
|
|
|
- }
|
|
|
|
- result = s.listManager(spqp, listOne, bsp.Keyword, (len(listOne)+pageSize)/pageSize)
|
|
|
|
- if len(*list) > pageSize {
|
|
|
|
- hasNextPage = true
|
|
|
|
- listOther := (*list)[pageSize:]
|
|
|
|
- go s.listManager(spqp, listOther, bsp.Keyword, (len(listOther)+pageSize)/pageSize)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- logx.Info("请求耗时:", time.Since(t2))
|
|
|
|
- return
|
|
|
|
|
|
+ if spqp.UserId == "" {
|
|
|
|
+ return false, 0, nil
|
|
|
|
+ }
|
|
|
|
+ t1 := time.Now()
|
|
|
|
+ log.Println("userId:", spqp.UserId)
|
|
|
|
+ log.Println("newUserId:", spqp.NewUserId)
|
|
|
|
+ //用户信息
|
|
|
|
+ bsp := s.getUserInfo(spqp)
|
|
|
|
+ logx.Info("获取用户信息耗时:", time.Since(t1))
|
|
|
|
+ t2 := time.Now()
|
|
|
|
+ if len(bsp.Keyword) > 0 {
|
|
|
|
+ logx.Info(time.Since(t1), "--bsp:", bsp)
|
|
|
|
+ //获取查询语句
|
|
|
|
+ qstr := s.getDefaultDatasSQL(bsp)
|
|
|
|
+ list := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSort, bidField, 0, bsp.Size, 0, false)
|
|
|
|
+ logx.Info(time.Since(t1), "count:", len(*list))
|
|
|
|
+ if list != nil && len(*list) > 0 {
|
|
|
|
+ total = int64(len(*list))
|
|
|
|
+ //超过50条先处理50条 返回前50条
|
|
|
|
+ listOne := *list
|
|
|
|
+ if len(*list) > pageSize {
|
|
|
|
+ listOne = (*list)[:pageSize]
|
|
|
|
+ }
|
|
|
|
+ result = s.listManager(spqp, listOne, bsp.Keyword, (len(listOne)+pageSize)/pageSize)
|
|
|
|
+ if len(*list) > pageSize {
|
|
|
|
+ hasNextPage = true
|
|
|
|
+ listOther := (*list)[pageSize:]
|
|
|
|
+ go s.listManager(spqp, listOther, bsp.Keyword, (len(listOther)+pageSize)/pageSize)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ logx.Info("请求耗时:", time.Since(t2))
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
//保存推送表
|
|
//保存推送表
|
|
func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]interface{}, keyword []ViewKeyWord, ccount int) (resultList []*bxsubscribe.SubscribeInfo) {
|
|
func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]interface{}, keyword []ViewKeyWord, ccount int) (resultList []*bxsubscribe.SubscribeInfo) {
|
|
- t2 := time.Now()
|
|
|
|
- now := time.Now().Unix()
|
|
|
|
- var (
|
|
|
|
- wg = &sync.WaitGroup{}
|
|
|
|
- wc = make(chan bool, ccount)
|
|
|
|
- )
|
|
|
|
- for _, v := range list {
|
|
|
|
- wg.Add(1)
|
|
|
|
- wc <- true
|
|
|
|
- go func(v map[string]interface{}) {
|
|
|
|
- defer func() {
|
|
|
|
- wg.Done()
|
|
|
|
- <-wc
|
|
|
|
- }()
|
|
|
|
- redisKey := fmt.Sprintf("pushinfo_%s_%s", spqp.UserId, common.ObjToString(v["_id"]))
|
|
|
|
- title := strings.Replace(common.ObjToString(v["title"]), "\n", "", -1)
|
|
|
|
- var pushInsert = []interface{}{}
|
|
|
|
- //招投标信息表
|
|
|
|
- var buildingInsert = []interface{}{}
|
|
|
|
- infoid := ""
|
|
|
|
- area := ""
|
|
|
|
- city := ""
|
|
|
|
- subtype := ""
|
|
|
|
- toptype := ""
|
|
|
|
- buyerclass := ""
|
|
|
|
- attachment_count := ""
|
|
|
|
- bidamount := "0"
|
|
|
|
- budget := "0"
|
|
|
|
- subscopeClass := ""
|
|
|
|
- infoid = common.InterfaceToStr(v["_id"])
|
|
|
|
- if v["area"] != nil {
|
|
|
|
- area = common.InterfaceToStr(common.If(common.ObjToString(v["area"]) == "A", 0, common.If(IC.PushMapping.Area[common.ObjToString(v["area"])] != "", IC.PushMapping.Area[common.ObjToString(v["area"])], 0)))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- publishtime := ""
|
|
|
|
- if v["publishtime"] != nil {
|
|
|
|
- publishtime = time.Unix(common.Int64All(v["publishtime"]), 0).Format(date.Date_Full_Layout)
|
|
|
|
- }
|
|
|
|
- if v["city"] != nil {
|
|
|
|
- city = common.InterfaceToStr(common.If(IC.PushMapping.City[common.ObjToString(v["city"])] != "", IC.PushMapping.City[common.ObjToString(v["city"])], 0))
|
|
|
|
- }
|
|
|
|
- if v["subtype"] != nil {
|
|
|
|
- subtype = common.InterfaceToStr(common.If(IC.PushMapping.Subtype[common.ObjToString(v["subtype"])] != "", IC.PushMapping.Subtype[common.ObjToString(v["subtype"])], 0))
|
|
|
|
- }
|
|
|
|
- if v["toptype"] != nil {
|
|
|
|
- toptype = common.InterfaceToStr(common.If(IC.PushMapping.Toptype[common.ObjToString(v["toptype"])] != "", IC.PushMapping.Toptype[common.ObjToString(v["toptype"])], 0))
|
|
|
|
- }
|
|
|
|
- if v["buyerclass"] != nil {
|
|
|
|
- buyerclass = common.InterfaceToStr(common.If(IC.PushMapping.Buyerclass[common.ObjToString(v["buyerclass"])] != "", IC.PushMapping.Buyerclass[common.ObjToString(v["buyerclass"])], 0))
|
|
|
|
- }
|
|
|
|
- if v["isValidFile"] != nil {
|
|
|
|
- isValidFile, _ := v["isValidFile"].(bool)
|
|
|
|
- attachment_count = common.InterfaceToStr(common.If(isValidFile, 1, 0)) //附件 :检索库 只有附件字段,无法识别附件数量 暂定为1;为识别有附件
|
|
|
|
- }
|
|
|
|
- if v["bidamount"] != nil {
|
|
|
|
- bidamount = common.InterfaceToStr(v["bidamount"])
|
|
|
|
- }
|
|
|
|
- if v["budget"] != nil {
|
|
|
|
- budget = common.InterfaceToStr(v["budget"])
|
|
|
|
- }
|
|
|
|
- if s_subscopeclass := common.ObjToString(v["s_subscopeclass"]); s_subscopeclass != "" {
|
|
|
|
- subscopeclass := []string{}
|
|
|
|
- for _, v := range strings.Split(s_subscopeclass, ",") {
|
|
|
|
- if subscopeclass_mapping, ok := IC.PushMapping.Subscopeclass[v]; ok {
|
|
|
|
- subscopeclass = append(subscopeclass, fmt.Sprint(subscopeclass_mapping))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if len(subscopeclass) > 0 {
|
|
|
|
- subscopeClass = strings.Join(subscopeclass, ",")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- log.Println("infoid", infoid)
|
|
|
|
- buildingInsert = append(buildingInsert, infoid, area, city, buyerclass, toptype, subtype, subscopeClass, budget, bidamount, attachment_count, publishtime)
|
|
|
|
- spqp.BaseServiceMysql.ExecTx("推送记录保存", func(tx *sql.Tx) bool {
|
|
|
|
- _, _ = spqp.BaseServiceMysql.InsertIgnoreBatchByTx(tx, Pushbidding, buildingInsertCollKey, buildingInsert)
|
|
|
|
- /*log.Println(id1, id2)
|
|
|
|
- if id1 == 0 {
|
|
|
|
- //有历史记录,需要查询信息id
|
|
|
|
- data := spqp.BaseServiceMysql.FindOne(Pushbidding, map[string]interface{}{
|
|
|
|
- "infoid": infoid,
|
|
|
|
- }, "id", "")
|
|
|
|
- if data != nil {
|
|
|
|
- id2 = common.Int64All((*data)["id"])
|
|
|
|
- } else {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- }*/
|
|
|
|
- //推送记录
|
|
|
|
- matchkeys := getKeys(title, keyword)
|
|
|
|
- matchkey := strings.Join(matchkeys, " ")
|
|
|
|
- entid := spqp.EntId
|
|
|
|
- entUserId := spqp.EntUserId
|
|
|
|
- deptid := spqp.DeptId
|
|
|
|
- id := int64(0)
|
|
|
|
- switch s.ModuleFlag {
|
|
|
|
- case "eType":
|
|
|
|
- pushInsert = append(pushInsert, entid, deptid, entUserId, common.InterfaceToStr(infoid), matchkey, now)
|
|
|
|
- id, _ = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, ennicheInsertCollKey, pushInsert)
|
|
|
|
- case "mType":
|
|
|
|
- pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now)
|
|
|
|
- id, _ = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, memberInsertCollKey, pushInsert)
|
|
|
|
- case "vType":
|
|
|
|
- pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 1)
|
|
|
|
- id, _ = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, subscribeInsertCollKey, pushInsert)
|
|
|
|
- case "fType":
|
|
|
|
- pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 0)
|
|
|
|
- id, _ = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, subscribeInsertCollKey, pushInsert)
|
|
|
|
|
|
+ t2 := time.Now()
|
|
|
|
+ now := time.Now().Unix()
|
|
|
|
+ var (
|
|
|
|
+ wg = &sync.WaitGroup{}
|
|
|
|
+ wc = make(chan bool, ccount)
|
|
|
|
+ )
|
|
|
|
+ for _, v := range list {
|
|
|
|
+ wg.Add(1)
|
|
|
|
+ wc <- true
|
|
|
|
+ go func(v map[string]interface{}) {
|
|
|
|
+ defer func() {
|
|
|
|
+ wg.Done()
|
|
|
|
+ <-wc
|
|
|
|
+ }()
|
|
|
|
+ redisKey := fmt.Sprintf("pushinfo_%s_%s", spqp.UserId, common.ObjToString(v["_id"]))
|
|
|
|
+ title := strings.Replace(common.ObjToString(v["title"]), "\n", "", -1)
|
|
|
|
+ var pushInsert = []interface{}{}
|
|
|
|
+ infoid := common.InterfaceToStr(v["_id"])
|
|
|
|
+ log.Println("infoid", infoid)
|
|
|
|
+ spqp.BaseServiceMysql.ExecTx("推送记录保存", func(tx *sql.Tx) bool {
|
|
|
|
+ //推送记录
|
|
|
|
+ matchkeys := getKeys(title, keyword)
|
|
|
|
+ matchkey := strings.Join(matchkeys, " ")
|
|
|
|
+ entid := spqp.EntId
|
|
|
|
+ entUserId := spqp.EntUserId
|
|
|
|
+ deptid := spqp.DeptId
|
|
|
|
+ id := int64(0)
|
|
|
|
+ switch s.ModuleFlag {
|
|
|
|
+ case "eType":
|
|
|
|
+ pushInsert = append(pushInsert, entid, deptid, entUserId, common.InterfaceToStr(infoid), matchkey, now)
|
|
|
|
+ id, _ = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, ennicheInsertCollKey, pushInsert)
|
|
|
|
+ case "mType":
|
|
|
|
+ pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now)
|
|
|
|
+ id, _ = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, memberInsertCollKey, pushInsert)
|
|
|
|
+ case "vType":
|
|
|
|
+ pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 1)
|
|
|
|
+ id, _ = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, subscribeInsertCollKey, pushInsert)
|
|
|
|
+ case "fType":
|
|
|
|
+ pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 0)
|
|
|
|
+ id, _ = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, subscribeInsertCollKey, pushInsert)
|
|
|
|
|
|
- }
|
|
|
|
- if id > 0 {
|
|
|
|
- redis.Put("pushcache_2_a", redisKey, 1, 86400)
|
|
|
|
- resultList = append(resultList, s.InfoFormat(&PushCa{
|
|
|
|
- InfoId: infoid,
|
|
|
|
- Date: time.Now().Unix(),
|
|
|
|
- Index: id,
|
|
|
|
- Keys: matchkeys,
|
|
|
|
- FileExists: v["filetext"] != nil,
|
|
|
|
- }, &v))
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
- return false
|
|
|
|
- })
|
|
|
|
- }(v)
|
|
|
|
- }
|
|
|
|
- wg.Wait()
|
|
|
|
- log.Println("数据处理耗时:", time.Since(t2))
|
|
|
|
- return
|
|
|
|
|
|
+ }
|
|
|
|
+ if id > 0 {
|
|
|
|
+ redis.Put("pushcache_2_a", redisKey, 1, 86400)
|
|
|
|
+ resultList = append(resultList, s.InfoFormat(&PushCa{
|
|
|
|
+ InfoId: infoid,
|
|
|
|
+ Date: time.Now().Unix(),
|
|
|
|
+ Index: id,
|
|
|
|
+ Keys: matchkeys,
|
|
|
|
+ FileExists: v["filetext"] != nil,
|
|
|
|
+ }, &v))
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ return false
|
|
|
|
+ })
|
|
|
|
+ }(v)
|
|
|
|
+ }
|
|
|
|
+ wg.Wait()
|
|
|
|
+ log.Println("数据处理耗时:", time.Since(t2))
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
//获取匹配得关键词
|
|
//获取匹配得关键词
|
|
func getKeys(title string, keywords []ViewKeyWord) (str []string) {
|
|
func getKeys(title string, keywords []ViewKeyWord) (str []string) {
|
|
- if len(keywords) > 0 {
|
|
|
|
- L:
|
|
|
|
- for _, v := range keywords {
|
|
|
|
- for _, vk := range v.Keyword {
|
|
|
|
- if strings.Contains(title, vk) {
|
|
|
|
- str = append(str, v.Keyword...)
|
|
|
|
- break L
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- for _, va := range v.Appended {
|
|
|
|
- if strings.Contains(title, va) {
|
|
|
|
- str = append(str, v.Appended...)
|
|
|
|
- break L
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
|
|
+ if len(keywords) > 0 {
|
|
|
|
+ L:
|
|
|
|
+ for _, v := range keywords {
|
|
|
|
+ for _, vk := range v.Keyword {
|
|
|
|
+ if strings.Contains(title, vk) {
|
|
|
|
+ str = append(str, v.Keyword...)
|
|
|
|
+ break L
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for _, va := range v.Appended {
|
|
|
|
+ if strings.Contains(title, va) {
|
|
|
|
+ str = append(str, v.Appended...)
|
|
|
|
+ break L
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
//获取查询语句
|
|
//获取查询语句
|
|
func (s *subscribePush) getDefaultDatasSQL(bsp *ViewCondition) (str string) {
|
|
func (s *subscribePush) getDefaultDatasSQL(bsp *ViewCondition) (str string) {
|
|
- query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}}`
|
|
|
|
- query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
|
|
|
|
- multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
|
|
|
|
- query_bool_must_and := `{"bool":{"must":[%s]%s}}`
|
|
|
|
|
|
+ query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}}`
|
|
|
|
+ query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
|
|
|
|
+ multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
|
|
|
|
+ query_bool_must_and := `{"bool":{"must":[%s]%s}}`
|
|
|
|
|
|
- bools := []string{}
|
|
|
|
- musts := []string{}
|
|
|
|
- //发布时间最新7天
|
|
|
|
- musts = append(musts, fmt.Sprintf(bidTime, time.Now().AddDate(0, 0, -365).Unix()))
|
|
|
|
- //省份
|
|
|
|
- areaCity := []string{}
|
|
|
|
- if len(bsp.Area) > 0 {
|
|
|
|
- areaquery := `{"terms":{"area":[`
|
|
|
|
- for k, v := range bsp.Area {
|
|
|
|
- if k > 0 {
|
|
|
|
- areaquery += `,`
|
|
|
|
- }
|
|
|
|
- areaquery += `"` + v + `"`
|
|
|
|
- }
|
|
|
|
- areaquery += `]}}`
|
|
|
|
- areaCity = append(areaCity, areaquery)
|
|
|
|
- }
|
|
|
|
|
|
+ bools := []string{}
|
|
|
|
+ musts := []string{}
|
|
|
|
+ //发布时间最新7天
|
|
|
|
+ musts = append(musts, fmt.Sprintf(bidTime, time.Now().AddDate(0, 0, -365*4).Unix()))
|
|
|
|
+ //省份
|
|
|
|
+ areaCity := []string{}
|
|
|
|
+ if len(bsp.Area) > 0 {
|
|
|
|
+ areaquery := `{"terms":{"area":[`
|
|
|
|
+ for k, v := range bsp.Area {
|
|
|
|
+ if k > 0 {
|
|
|
|
+ areaquery += `,`
|
|
|
|
+ }
|
|
|
|
+ areaquery += `"` + v + `"`
|
|
|
|
+ }
|
|
|
|
+ areaquery += `]}}`
|
|
|
|
+ areaCity = append(areaCity, areaquery)
|
|
|
|
+ }
|
|
|
|
|
|
- //城市
|
|
|
|
- if len(bsp.City) > 0 {
|
|
|
|
- areaquery := `{"terms":{"city":[`
|
|
|
|
- for k, v := range bsp.City {
|
|
|
|
- if k > 0 {
|
|
|
|
- areaquery += `,`
|
|
|
|
- }
|
|
|
|
- areaquery += `"` + v + `"`
|
|
|
|
- }
|
|
|
|
- areaquery += `]}}`
|
|
|
|
- areaCity = append(areaCity, areaquery)
|
|
|
|
- }
|
|
|
|
- if len(areaCity) > 0 {
|
|
|
|
- musts = append(musts, fmt.Sprintf(query_bool_should, strings.Join(areaCity, ",")))
|
|
|
|
- }
|
|
|
|
- if len(bsp.Subtype) > 0 {
|
|
|
|
- subquery := `{"terms":{"subtype":[`
|
|
|
|
- for k, v := range bsp.Subtype {
|
|
|
|
- if k > 0 {
|
|
|
|
- subquery += `,`
|
|
|
|
- }
|
|
|
|
- subquery += `"` + v + `"`
|
|
|
|
- }
|
|
|
|
- subquery += `]}}`
|
|
|
|
- musts = append(musts, subquery)
|
|
|
|
- }
|
|
|
|
- if len(bsp.Buyerclass) > 0 {
|
|
|
|
- Buyerclass := `{"terms":{"buyerclass":[`
|
|
|
|
- for k, v := range bsp.Buyerclass {
|
|
|
|
- if k > 0 {
|
|
|
|
- Buyerclass += `,`
|
|
|
|
- }
|
|
|
|
- Buyerclass += `"` + v + `"`
|
|
|
|
- }
|
|
|
|
- Buyerclass += `]}}`
|
|
|
|
- musts = append(musts, Buyerclass)
|
|
|
|
- }
|
|
|
|
- boolsNum := 0 //should
|
|
|
|
- if len(bsp.Keyword) > 0 {
|
|
|
|
- boolsNum = 1
|
|
|
|
- if bsp.SelectType == "" || bsp.SelectType == "2" {
|
|
|
|
- bsp.SelectType = "detail\", \"title"
|
|
|
|
- } else {
|
|
|
|
- bsp.SelectType = "title"
|
|
|
|
- }
|
|
|
|
- multi_match = fmt.Sprintf(multi_match, "%s", "\""+bsp.SelectType+"\"")
|
|
|
|
|
|
+ //城市
|
|
|
|
+ if len(bsp.City) > 0 {
|
|
|
|
+ areaquery := `{"terms":{"city":[`
|
|
|
|
+ for k, v := range bsp.City {
|
|
|
|
+ if k > 0 {
|
|
|
|
+ areaquery += `,`
|
|
|
|
+ }
|
|
|
|
+ areaquery += `"` + v + `"`
|
|
|
|
+ }
|
|
|
|
+ areaquery += `]}}`
|
|
|
|
+ areaCity = append(areaCity, areaquery)
|
|
|
|
+ }
|
|
|
|
+ if len(areaCity) > 0 {
|
|
|
|
+ musts = append(musts, fmt.Sprintf(query_bool_should, strings.Join(areaCity, ",")))
|
|
|
|
+ }
|
|
|
|
+ if len(bsp.Subtype) > 0 {
|
|
|
|
+ subquery := `{"terms":{"subtype":[`
|
|
|
|
+ for k, v := range bsp.Subtype {
|
|
|
|
+ if k > 0 {
|
|
|
|
+ subquery += `,`
|
|
|
|
+ }
|
|
|
|
+ subquery += `"` + v + `"`
|
|
|
|
+ }
|
|
|
|
+ subquery += `]}}`
|
|
|
|
+ musts = append(musts, subquery)
|
|
|
|
+ }
|
|
|
|
+ if len(bsp.Buyerclass) > 0 {
|
|
|
|
+ Buyerclass := `{"terms":{"buyerclass":[`
|
|
|
|
+ for k, v := range bsp.Buyerclass {
|
|
|
|
+ if k > 0 {
|
|
|
|
+ Buyerclass += `,`
|
|
|
|
+ }
|
|
|
|
+ Buyerclass += `"` + v + `"`
|
|
|
|
+ }
|
|
|
|
+ Buyerclass += `]}}`
|
|
|
|
+ musts = append(musts, Buyerclass)
|
|
|
|
+ }
|
|
|
|
+ boolsNum := 0 //should
|
|
|
|
+ if len(bsp.Keyword) > 0 {
|
|
|
|
+ boolsNum = 1
|
|
|
|
+ if bsp.SelectType == "" || bsp.SelectType == "2" {
|
|
|
|
+ bsp.SelectType = "detail\", \"title"
|
|
|
|
+ } else {
|
|
|
|
+ bsp.SelectType = "title"
|
|
|
|
+ }
|
|
|
|
+ multi_match = fmt.Sprintf(multi_match, "%s", "\""+bsp.SelectType+"\"")
|
|
|
|
|
|
- for _, v := range bsp.Keyword {
|
|
|
|
- shoulds := []string{}
|
|
|
|
- must_not := []string{}
|
|
|
|
- //附加词
|
|
|
|
- for _, vv := range v.Keyword {
|
|
|
|
- vv = strings.TrimSpace(vv)
|
|
|
|
- if vv == "" {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
|
- }
|
|
|
|
|
|
+ for _, v := range bsp.Keyword {
|
|
|
|
+ shoulds := []string{}
|
|
|
|
+ must_not := []string{}
|
|
|
|
+ //附加词
|
|
|
|
+ for _, vv := range v.Keyword {
|
|
|
|
+ vv = strings.TrimSpace(vv)
|
|
|
|
+ if vv == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
|
+ }
|
|
|
|
|
|
- for _, vv := range v.Appended {
|
|
|
|
- vv = strings.TrimSpace(vv)
|
|
|
|
- if vv == "" {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
|
- }
|
|
|
|
|
|
+ for _, vv := range v.Appended {
|
|
|
|
+ vv = strings.TrimSpace(vv)
|
|
|
|
+ if vv == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
|
+ }
|
|
|
|
|
|
- //排除词
|
|
|
|
- for _, vv := range v.Exclude {
|
|
|
|
- vv = strings.TrimSpace(vv)
|
|
|
|
- if vv == "" {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- must_not = append(must_not, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
|
- }
|
|
|
|
|
|
+ //排除词
|
|
|
|
+ for _, vv := range v.Exclude {
|
|
|
|
+ vv = strings.TrimSpace(vv)
|
|
|
|
+ if vv == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ must_not = append(must_not, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
|
+ }
|
|
|
|
|
|
- //添加
|
|
|
|
- if len(shoulds) > 0 {
|
|
|
|
- notStr := ""
|
|
|
|
- if len(must_not) > 0 {
|
|
|
|
- notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(must_not, ","))
|
|
|
|
- }
|
|
|
|
- bools = append(bools, fmt.Sprintf(query_bool_must_and, strings.Join(shoulds, ","), notStr))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ //添加
|
|
|
|
+ if len(shoulds) > 0 {
|
|
|
|
+ notStr := ""
|
|
|
|
+ if len(must_not) > 0 {
|
|
|
|
+ notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(must_not, ","))
|
|
|
|
+ }
|
|
|
|
+ bools = append(bools, fmt.Sprintf(query_bool_must_and, strings.Join(shoulds, ","), notStr))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- qstr := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum)
|
|
|
|
- logx.Info("----", qstr)
|
|
|
|
- return qstr
|
|
|
|
|
|
+ qstr := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum)
|
|
|
|
+ logx.Info("----", qstr)
|
|
|
|
+ return qstr
|
|
}
|
|
}
|
|
|
|
|
|
/*已选条件--关键词*/
|
|
/*已选条件--关键词*/
|
|
type ViewKeyWord struct {
|
|
type ViewKeyWord struct {
|
|
- Keyword []string `json:"key"` //关键词
|
|
|
|
- Appended []string `json:"appendkey"` //附加词
|
|
|
|
- Exclude []string `json:"notkey"` //排除词
|
|
|
|
- MatchWay int `json:"matchway"` //匹配模式
|
|
|
|
|
|
+ Keyword []string `json:"key"` //关键词
|
|
|
|
+ Appended []string `json:"appendkey"` //附加词
|
|
|
|
+ Exclude []string `json:"notkey"` //排除词
|
|
|
|
+ MatchWay int `json:"matchway"` //匹配模式
|
|
}
|
|
}
|
|
|
|
|
|
/*已选条件*/
|
|
/*已选条件*/
|
|
type ViewCondition struct {
|
|
type ViewCondition struct {
|
|
- Area []string //地区-省份
|
|
|
|
- City []string //地区-城市
|
|
|
|
- Buyerclass []string //采购行业
|
|
|
|
- Keyword []ViewKeyWord //关键词
|
|
|
|
- SelectType string //筛选(正文 or 标题)
|
|
|
|
- Subtype []string //信息类型
|
|
|
|
- Size int //数量
|
|
|
|
|
|
+ Area []string //地区-省份
|
|
|
|
+ City []string //地区-城市
|
|
|
|
+ Buyerclass []string //采购行业
|
|
|
|
+ Keyword []ViewKeyWord //关键词
|
|
|
|
+ SelectType string //筛选(正文 or 标题)
|
|
|
|
+ Subtype []string //信息类型
|
|
|
|
+ Size int //数量
|
|
}
|
|
}
|
|
|
|
|
|
//获取用户信息
|
|
//获取用户信息
|
|
func (s *subscribePush) getUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition) {
|
|
func (s *subscribePush) getUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition) {
|
|
- var isPayBool = false
|
|
|
|
- var tmpInfo = struct {
|
|
|
|
- Items []interface{}
|
|
|
|
- BuyerClass []interface{}
|
|
|
|
- SubType []interface{}
|
|
|
|
- Area map[string]interface{}
|
|
|
|
- SelectType string
|
|
|
|
- }{}
|
|
|
|
- switch s.ModuleFlag {
|
|
|
|
- case "mType":
|
|
|
|
- userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_member_jy":1,"i_member_status":1}`)
|
|
|
|
- if !ok || userMap == nil || len(*userMap) == 0 {
|
|
|
|
- return &ViewCondition{}
|
|
|
|
- }
|
|
|
|
- //大会员
|
|
|
|
- if common.IntAll((*userMap)["i_member_status"]) > 0 {
|
|
|
|
- isPayBool = true
|
|
|
|
- o_member_jy, _ := (*userMap)["o_member_jy"].(map[string]interface{})
|
|
|
|
- tmpInfo.Items, _ = o_member_jy["a_items"].([]interface{})
|
|
|
|
- tmpInfo.BuyerClass, _ = o_member_jy["a_buyerclass"].([]interface{})
|
|
|
|
- tmpInfo.SubType, _ = o_member_jy["a_infotype"].([]interface{})
|
|
|
|
- tmpInfo.Area, _ = o_member_jy["o_area"].(map[string]interface{})
|
|
|
|
- }
|
|
|
|
- case "vType":
|
|
|
|
- userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_vipjy":1,"i_vip_status":1}`)
|
|
|
|
- if !ok || userMap == nil || len(*userMap) == 0 {
|
|
|
|
- return &ViewCondition{}
|
|
|
|
- }
|
|
|
|
- if common.IntAll((*userMap)["i_vip_status"]) > 0 {
|
|
|
|
- isPayBool = true
|
|
|
|
- o_vipjy, _ := (*userMap)["o_vipjy"].(map[string]interface{})
|
|
|
|
- tmpInfo.Items, _ = o_vipjy["a_items"].([]interface{})
|
|
|
|
- tmpInfo.BuyerClass, _ = o_vipjy["a_buyerclass"].([]interface{})
|
|
|
|
- tmpInfo.SubType, _ = o_vipjy["a_infotype"].([]interface{})
|
|
|
|
- tmpInfo.Area, _ = o_vipjy["o_area"].(map[string]interface{})
|
|
|
|
- }
|
|
|
|
- case "eType":
|
|
|
|
- //商机管理
|
|
|
|
- entUserId, _ := strconv.Atoi(spqp.EntUserId)
|
|
|
|
- entId, _ := strconv.Atoi(spqp.EntId)
|
|
|
|
- entInfo, deptId := (&ms.MatchJob{}).Start(entId, entUserId)
|
|
|
|
- if entInfo != nil && len(entInfo) > 0 {
|
|
|
|
- spqp.DeptId = strconv.Itoa(deptId)
|
|
|
|
- isPayBool = true
|
|
|
|
- tmpInfo.Items, _ = entInfo["a_items"].([]interface{})
|
|
|
|
- tmpInfo.BuyerClass, _ = entInfo["a_buyerclass"].([]interface{})
|
|
|
|
- tmpInfo.SubType, _ = entInfo["a_infotype"].([]interface{})
|
|
|
|
- tmpInfo.Area, _ = entInfo["o_area"].(map[string]interface{})
|
|
|
|
- }
|
|
|
|
- default:
|
|
|
|
- userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1}`)
|
|
|
|
- if !ok || userMap == nil || len(*userMap) == 0 {
|
|
|
|
- return &ViewCondition{}
|
|
|
|
- }
|
|
|
|
- o_jy, _ := (*userMap)["o_jy"].(map[string]interface{})
|
|
|
|
- if o_jy["a_key"] != nil {
|
|
|
|
- tmpInfo.Items, _ = o_jy["a_key"].([]interface{})
|
|
|
|
- //信息类型
|
|
|
|
- tmpInfo.SubType, _ = o_jy["a_infotype"].([]interface{})
|
|
|
|
- //省份
|
|
|
|
- tmpInfo.Area, _ = o_jy["o_area"].(map[string]interface{})
|
|
|
|
- if common.IntAllDef(o_jy["i_ppstatus"], 0) == 1 && o_jy["o_area_p"] != nil {
|
|
|
|
- tmpInfo.Area, _ = o_jy["o_area_p"].(map[string]interface{})
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- vc = &ViewCondition{
|
|
|
|
- Buyerclass: common.ObjArrToStringArr(tmpInfo.BuyerClass),
|
|
|
|
- Subtype: common.ObjArrToStringArr(tmpInfo.SubType),
|
|
|
|
- Area: getStringArrFromDbResult(tmpInfo.Area, 1),
|
|
|
|
- City: getStringArrFromDbResult(tmpInfo.Area, 2),
|
|
|
|
- SelectType: "1",
|
|
|
|
- }
|
|
|
|
- //付费用户
|
|
|
|
- if isPayBool {
|
|
|
|
- vc.Size = IC.C.DefaulCount.Pay
|
|
|
|
- vc.Keyword = getKeyWordArrFromDbResult(tmpInfo.Items, "", -1)
|
|
|
|
- } else {
|
|
|
|
- vc.Size = IC.C.DefaulCount.Free
|
|
|
|
- vc.Keyword = getKeyWordArrFromDbResultByFree(tmpInfo.Items, "", -1)
|
|
|
|
- //vc.Keyword = getKeyWordArrFromDbResult(tmpInfo.Items, "", -1)
|
|
|
|
- }
|
|
|
|
- vc.Size = 10
|
|
|
|
|
|
+ var isPayBool = false
|
|
|
|
+ var tmpInfo = struct {
|
|
|
|
+ Items []interface{}
|
|
|
|
+ BuyerClass []interface{}
|
|
|
|
+ SubType []interface{}
|
|
|
|
+ Area map[string]interface{}
|
|
|
|
+ SelectType string
|
|
|
|
+ }{}
|
|
|
|
+ switch s.ModuleFlag {
|
|
|
|
+ case "mType":
|
|
|
|
+ userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_member_jy":1,"i_member_status":1}`)
|
|
|
|
+ if !ok || userMap == nil || len(*userMap) == 0 {
|
|
|
|
+ return &ViewCondition{}
|
|
|
|
+ }
|
|
|
|
+ //大会员
|
|
|
|
+ if common.IntAll((*userMap)["i_member_status"]) > 0 {
|
|
|
|
+ isPayBool = true
|
|
|
|
+ o_member_jy, _ := (*userMap)["o_member_jy"].(map[string]interface{})
|
|
|
|
+ tmpInfo.Items, _ = o_member_jy["a_items"].([]interface{})
|
|
|
|
+ tmpInfo.BuyerClass, _ = o_member_jy["a_buyerclass"].([]interface{})
|
|
|
|
+ tmpInfo.SubType, _ = o_member_jy["a_infotype"].([]interface{})
|
|
|
|
+ tmpInfo.Area, _ = o_member_jy["o_area"].(map[string]interface{})
|
|
|
|
+ }
|
|
|
|
+ case "vType":
|
|
|
|
+ userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_vipjy":1,"i_vip_status":1}`)
|
|
|
|
+ if !ok || userMap == nil || len(*userMap) == 0 {
|
|
|
|
+ return &ViewCondition{}
|
|
|
|
+ }
|
|
|
|
+ if common.IntAll((*userMap)["i_vip_status"]) > 0 {
|
|
|
|
+ isPayBool = true
|
|
|
|
+ o_vipjy, _ := (*userMap)["o_vipjy"].(map[string]interface{})
|
|
|
|
+ tmpInfo.Items, _ = o_vipjy["a_items"].([]interface{})
|
|
|
|
+ tmpInfo.BuyerClass, _ = o_vipjy["a_buyerclass"].([]interface{})
|
|
|
|
+ tmpInfo.SubType, _ = o_vipjy["a_infotype"].([]interface{})
|
|
|
|
+ tmpInfo.Area, _ = o_vipjy["o_area"].(map[string]interface{})
|
|
|
|
+ }
|
|
|
|
+ case "eType":
|
|
|
|
+ //商机管理
|
|
|
|
+ entUserId, _ := strconv.Atoi(spqp.EntUserId)
|
|
|
|
+ entId, _ := strconv.Atoi(spqp.EntId)
|
|
|
|
+ entInfo, deptId := (&ms.MatchJob{}).Start(entId, entUserId)
|
|
|
|
+ if entInfo != nil && len(entInfo) > 0 {
|
|
|
|
+ spqp.DeptId = strconv.Itoa(deptId)
|
|
|
|
+ isPayBool = true
|
|
|
|
+ tmpInfo.Items, _ = entInfo["a_items"].([]interface{})
|
|
|
|
+ tmpInfo.BuyerClass, _ = entInfo["a_buyerclass"].([]interface{})
|
|
|
|
+ tmpInfo.SubType, _ = entInfo["a_infotype"].([]interface{})
|
|
|
|
+ tmpInfo.Area, _ = entInfo["o_area"].(map[string]interface{})
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1}`)
|
|
|
|
+ if !ok || userMap == nil || len(*userMap) == 0 {
|
|
|
|
+ return &ViewCondition{}
|
|
|
|
+ }
|
|
|
|
+ o_jy, _ := (*userMap)["o_jy"].(map[string]interface{})
|
|
|
|
+ if o_jy["a_key"] != nil {
|
|
|
|
+ tmpInfo.Items, _ = o_jy["a_key"].([]interface{})
|
|
|
|
+ //信息类型
|
|
|
|
+ tmpInfo.SubType, _ = o_jy["a_infotype"].([]interface{})
|
|
|
|
+ //省份
|
|
|
|
+ tmpInfo.Area, _ = o_jy["o_area"].(map[string]interface{})
|
|
|
|
+ if common.IntAllDef(o_jy["i_ppstatus"], 0) == 1 && o_jy["o_area_p"] != nil {
|
|
|
|
+ tmpInfo.Area, _ = o_jy["o_area_p"].(map[string]interface{})
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ vc = &ViewCondition{
|
|
|
|
+ Buyerclass: common.ObjArrToStringArr(tmpInfo.BuyerClass),
|
|
|
|
+ Subtype: common.ObjArrToStringArr(tmpInfo.SubType),
|
|
|
|
+ Area: getStringArrFromDbResult(tmpInfo.Area, 1),
|
|
|
|
+ City: getStringArrFromDbResult(tmpInfo.Area, 2),
|
|
|
|
+ SelectType: "1",
|
|
|
|
+ }
|
|
|
|
+ //付费用户
|
|
|
|
+ if isPayBool {
|
|
|
|
+ vc.Size = IC.C.DefaulCount.Pay
|
|
|
|
+ vc.Keyword = getKeyWordArrFromDbResult(tmpInfo.Items, "", -1)
|
|
|
|
+ } else {
|
|
|
|
+ vc.Size = IC.C.DefaulCount.Free
|
|
|
|
+ vc.Keyword = getKeyWordArrFromDbResultByFree(tmpInfo.Items, "", -1)
|
|
|
|
+ //vc.Keyword = getKeyWordArrFromDbResult(tmpInfo.Items, "", -1)
|
|
|
|
+ }
|
|
|
|
+ vc.Size = 10
|
|
|
|
|
|
- return
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
//关键词 附加词 排除词
|
|
//关键词 附加词 排除词
|
|
func getKeyWordArrFromDbResult(a_items []interface{}, item string, index int) (arr []ViewKeyWord) {
|
|
func getKeyWordArrFromDbResult(a_items []interface{}, item string, index int) (arr []ViewKeyWord) {
|
|
- if a_items == nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- for _, v := range a_items {
|
|
|
|
- vm, _ := v.(map[string]interface{})
|
|
|
|
- if item != "" && index >= 0 && item != common.ObjToString(vm["s_item"]) {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- kwsArr := vm["a_key"]
|
|
|
|
- for i, k := range kwsArr.([]interface{}) {
|
|
|
|
- if item != "" && index >= 0 && i != index {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- kw := ViewKeyWord{}
|
|
|
|
- b, e := json.Marshal(k)
|
|
|
|
- if e != nil {
|
|
|
|
- log.Println(e.Error())
|
|
|
|
- }
|
|
|
|
- json.Unmarshal(b, &kw)
|
|
|
|
- if kw.MatchWay == 1 {
|
|
|
|
- for _, kk := range kw.Keyword {
|
|
|
|
- arr = append(arr, ViewKeyWord{
|
|
|
|
- Keyword: []string{kk},
|
|
|
|
- Exclude: kw.Exclude,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- for _, kk := range kw.Appended {
|
|
|
|
- arr = append(arr, ViewKeyWord{
|
|
|
|
- Keyword: []string{kk},
|
|
|
|
- Exclude: kw.Exclude,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- arr = append(arr, kw)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// //关键词 附加词 排除词 省份订阅包 - 普通用户
|
|
|
|
-func getKeyWordArrFromDbResultByFree(a_items []interface{}, item string, index int) (arr []ViewKeyWord) {
|
|
|
|
- if a_items == nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- for _, v := range a_items {
|
|
|
|
- kw := ViewKeyWord{}
|
|
|
|
- b, e := json.Marshal(v)
|
|
|
|
- if e != nil {
|
|
|
|
- log.Println(e.Error())
|
|
|
|
- }
|
|
|
|
- json.Unmarshal(b, &kw)
|
|
|
|
- if kw.MatchWay == 1 {
|
|
|
|
- for _, kk := range kw.Keyword {
|
|
|
|
|
|
+ if a_items == nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, v := range a_items {
|
|
|
|
+ vm, _ := v.(map[string]interface{})
|
|
|
|
+ if item != "" && index >= 0 && item != common.ObjToString(vm["s_item"]) {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ kwsArr := vm["a_key"]
|
|
|
|
+ for i, k := range kwsArr.([]interface{}) {
|
|
|
|
+ if item != "" && index >= 0 && i != index {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ kw := ViewKeyWord{}
|
|
|
|
+ b, e := json.Marshal(k)
|
|
|
|
+ if e != nil {
|
|
|
|
+ log.Println(e.Error())
|
|
|
|
+ }
|
|
|
|
+ json.Unmarshal(b, &kw)
|
|
|
|
+ if kw.MatchWay == 1 {
|
|
|
|
+ for _, kk := range kw.Keyword {
|
|
arr = append(arr, ViewKeyWord{
|
|
arr = append(arr, ViewKeyWord{
|
|
- Keyword: []string{kk},
|
|
|
|
- Exclude: kw.Exclude,
|
|
|
|
|
|
+ Keyword: []string{kk},
|
|
|
|
+ Exclude: kw.Exclude,
|
|
})
|
|
})
|
|
- }
|
|
|
|
- for _, kk := range kw.Appended {
|
|
|
|
|
|
+ }
|
|
|
|
+ for _, kk := range kw.Appended {
|
|
arr = append(arr, ViewKeyWord{
|
|
arr = append(arr, ViewKeyWord{
|
|
- Keyword: []string{kk},
|
|
|
|
- Exclude: kw.Exclude,
|
|
|
|
|
|
+ Keyword: []string{kk},
|
|
|
|
+ Exclude: kw.Exclude,
|
|
})
|
|
})
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- arr = append(arr, kw)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ arr = append(arr, kw)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// //关键词 附加词 排除词 省份订阅包 - 普通用户
|
|
|
|
+func getKeyWordArrFromDbResultByFree(a_items []interface{}, item string, index int) (arr []ViewKeyWord) {
|
|
|
|
+ if a_items == nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, v := range a_items {
|
|
|
|
+ kw := ViewKeyWord{}
|
|
|
|
+ b, e := json.Marshal(v)
|
|
|
|
+ if e != nil {
|
|
|
|
+ log.Println(e.Error())
|
|
|
|
+ }
|
|
|
|
+ json.Unmarshal(b, &kw)
|
|
|
|
+ if kw.MatchWay == 1 {
|
|
|
|
+ for _, kk := range kw.Keyword {
|
|
|
|
+ arr = append(arr, ViewKeyWord{
|
|
|
|
+ Keyword: []string{kk},
|
|
|
|
+ Exclude: kw.Exclude,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ for _, kk := range kw.Appended {
|
|
|
|
+ arr = append(arr, ViewKeyWord{
|
|
|
|
+ Keyword: []string{kk},
|
|
|
|
+ Exclude: kw.Exclude,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ arr = append(arr, kw)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- return
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
//地区格式化
|
|
//地区格式化
|
|
func getStringArrFromDbResult(area map[string]interface{}, i int) (arr []string) {
|
|
func getStringArrFromDbResult(area map[string]interface{}, i int) (arr []string) {
|
|
- if area == nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- var eareArr []string
|
|
|
|
- var cityArr []string
|
|
|
|
- for k, v := range area {
|
|
|
|
- if len(v.([]interface{})) > 0 {
|
|
|
|
- cityArr = append(cityArr, common.ObjArrToStringArr(v.([]interface{}))...)
|
|
|
|
- } else {
|
|
|
|
- eareArr = append(eareArr, k)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if i == 1 {
|
|
|
|
- arr = eareArr
|
|
|
|
- } else {
|
|
|
|
- arr = cityArr
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
|
|
+ if area == nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var eareArr []string
|
|
|
|
+ var cityArr []string
|
|
|
|
+ for k, v := range area {
|
|
|
|
+ if len(v.([]interface{})) > 0 {
|
|
|
|
+ cityArr = append(cityArr, common.ObjArrToStringArr(v.([]interface{}))...)
|
|
|
|
+ } else {
|
|
|
|
+ eareArr = append(eareArr, k)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if i == 1 {
|
|
|
|
+ arr = eareArr
|
|
|
|
+ } else {
|
|
|
|
+ arr = cityArr
|
|
|
|
+ }
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
//IsInTsGuide 是否进入向导
|
|
//IsInTsGuide 是否进入向导
|
|
func (s *subscribePush) IsInTsGuide(userid string) bool {
|
|
func (s *subscribePush) IsInTsGuide(userid string) bool {
|
|
- if userid == "" {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- data, ok := IC.Mgo.FindById("user", userid, `{"o_jy":1,"i_ts_guide":1,"":1,"i_member_status":1,"i_vip_status":1}`)
|
|
|
|
- if ok {
|
|
|
|
- //付费用户无免费订阅,不进入订阅向导页面
|
|
|
|
- if common.IntAll((*data)["i_member_status"]) > 0 || common.IntAll((*data)["i_vip_status"]) > 0 {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- o_jy, _ := (*data)["o_jy"].(map[string]interface{})
|
|
|
|
- i_ts_guide := common.IntAll((*data)["i_ts_guide"])
|
|
|
|
- if i_ts_guide == 2 || (i_ts_guide == 0 && len(o_jy) == 0) {
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return false
|
|
|
|
|
|
+ if userid == "" {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ data, ok := IC.Mgo.FindById("user", userid, `{"o_jy":1,"i_ts_guide":1,"":1,"i_member_status":1,"i_vip_status":1}`)
|
|
|
|
+ if ok {
|
|
|
|
+ //付费用户无免费订阅,不进入订阅向导页面
|
|
|
|
+ if common.IntAll((*data)["i_member_status"]) > 0 || common.IntAll((*data)["i_vip_status"]) > 0 {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ o_jy, _ := (*data)["o_jy"].(map[string]interface{})
|
|
|
|
+ i_ts_guide := common.IntAll((*data)["i_ts_guide"])
|
|
|
|
+ if i_ts_guide == 2 || (i_ts_guide == 0 && len(o_jy) == 0) {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false
|
|
}
|
|
}
|