|
@@ -11,6 +11,7 @@ import (
|
|
|
"qfw/util/redis"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "sync"
|
|
|
"time"
|
|
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
@@ -18,6 +19,7 @@ import (
|
|
|
|
|
|
const (
|
|
|
threeDay = 172800
|
|
|
+ oneDay = 86400
|
|
|
halfOfDay = 43200
|
|
|
)
|
|
|
|
|
@@ -34,6 +36,7 @@ type SubPushList struct {
|
|
|
Ca_isvisit int `json:"ca_isvisit"`
|
|
|
Ca_isvip int `json:"ca_isvip"`
|
|
|
Ca_type int `json:"ca_type"`
|
|
|
+ Ca_fileExists bool `json:"ca_fileExists"`
|
|
|
Matchkeys []string `json:"matchkeys"`
|
|
|
Budget interface{} `json:"budget"`
|
|
|
Bidamount interface{} `json:"bidamount"`
|
|
@@ -42,15 +45,17 @@ type SubPushList struct {
|
|
|
ProjectName string `json:"projectName"`
|
|
|
S_winner string `json:"s_winner"`
|
|
|
Bidopentime int64 `json:"bidopentime"`
|
|
|
+ Spidercode string `json:"spidercode"`
|
|
|
+ Site string `json:"site"`
|
|
|
}
|
|
|
|
|
|
const (
|
|
|
pageSize = 50
|
|
|
pageSizes = 10
|
|
|
AllSubPushCacheSize = 250
|
|
|
- query = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","area", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "buyerclass","bidamount","budget","projectname","buyer","bidopentime","s_winner"],"from":0,"size":%d}`
|
|
|
- mongodb_fields = `{"_id":1,"area":1,"publishtime":1,"s_subscopeclass":1,"subtype":1,"title":1,"toptype":1,"type":1, "buyerclass":1,"budget":1,"bidamount":1,"s_winner":1,"bidopentime":1,"buyer":1,"projectname":1}`
|
|
|
- querys = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","title","detail","area","city","publishtime","projectname","buyer","buyerclass","s_winner","bidamount","subtype","toptype","href","projectcode","buyerperson","buyertel","budget","bidopentime","agency","projectscope","winnerperson","winnertel"]}`
|
|
|
+ query = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","area", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "buyerclass","bidamount","budget","projectname","buyer","bidopentime","s_winner","spidercode","site"],"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,"spidercode":1,"site":1}`
|
|
|
+ querys = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","title","detail","area","city","publishtime","projectname","buyer","buyerclass","s_winner","bidamount","subtype","toptype","href","projectcode","buyerperson","buyertel","budget","bidopentime","agency","projectscope","winnerperson","winnertel","spidercode","site"]}`
|
|
|
|
|
|
MemberFlag = "m"
|
|
|
SubVipFlag = "v"
|
|
@@ -62,7 +67,7 @@ var aboutDbMsg map[string]*AboutDbMsg = map[string]*AboutDbMsg{
|
|
|
SubFreeFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
SubVipFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
|
|
|
MemberFlag: &AboutDbMsg{"pushmember", "memberpush"},
|
|
|
- EntnicheFlag: &AboutDbMsg{"pushentniche", "pushentniche"},
|
|
|
+ EntnicheFlag: &AboutDbMsg{"pushentniche", "entnichepush"},
|
|
|
}
|
|
|
|
|
|
type AboutDbMsg struct {
|
|
@@ -77,13 +82,14 @@ type SubPush struct {
|
|
|
}
|
|
|
|
|
|
type PushCa struct {
|
|
|
- Date int64
|
|
|
- InfoId string
|
|
|
- Visit int
|
|
|
- Index int64
|
|
|
- Keys []string
|
|
|
- Type int
|
|
|
- Isvip int
|
|
|
+ Date int64
|
|
|
+ InfoId string
|
|
|
+ Visit int
|
|
|
+ Index int64
|
|
|
+ Keys []string
|
|
|
+ Type int
|
|
|
+ Isvip int
|
|
|
+ FileExists bool
|
|
|
}
|
|
|
|
|
|
//查询参数
|
|
@@ -103,11 +109,13 @@ type SubPushQueryParam struct {
|
|
|
Subscopeclass string //信息行业
|
|
|
Key string //订阅词
|
|
|
Export bool //导出
|
|
|
- EntId int
|
|
|
+ EntId int //企业id
|
|
|
+ Price string //价格
|
|
|
+ FileExists string //是否有附件;默认全部;1:有附件;-1:无附件
|
|
|
}
|
|
|
|
|
|
func (spqp *SubPushQueryParam) IsEmpty() bool {
|
|
|
- return spqp.SelectTime == "" && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == ""
|
|
|
+ return spqp.SelectTime == "" && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == ""
|
|
|
}
|
|
|
|
|
|
type subscribePush struct {
|
|
@@ -140,7 +148,7 @@ func (h *subscribePush) GetTodayCache(userId string) (*SubPush, error) {
|
|
|
|
|
|
//往pushcache_2_a中放
|
|
|
func (h *subscribePush) PutTodayCache(userId string, pc_a *SubPush) {
|
|
|
- redis.Put("pushcache_2_b", h.todayKey(userId), pc_a, threeDay)
|
|
|
+ redis.Put("pushcache_2_b", h.todayKey(userId), pc_a, oneDay)
|
|
|
}
|
|
|
|
|
|
//获取redis key
|
|
@@ -148,7 +156,6 @@ func (s *subscribePush) todayKey(userId string) string {
|
|
|
return fmt.Sprintf("%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
|
|
|
}
|
|
|
func (s *subscribePush) allKey(userId string) string {
|
|
|
- log.Println(fmt.Sprintf("all_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId))
|
|
|
return fmt.Sprintf("all_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
|
|
|
}
|
|
|
|
|
@@ -198,6 +205,7 @@ func (s *subscribePush) InfoFormat(p *PushCa, info *map[string]interface{}) *Sub
|
|
|
Ca_isvisit: p.Visit,
|
|
|
Ca_isvip: p.Isvip,
|
|
|
Ca_type: p.Type,
|
|
|
+ Ca_fileExists: p.FileExists,
|
|
|
Matchkeys: p.Keys,
|
|
|
Budget: (*info)["budget"],
|
|
|
Bidamount: (*info)["bidamount"],
|
|
@@ -205,11 +213,13 @@ func (s *subscribePush) InfoFormat(p *PushCa, info *map[string]interface{}) *Sub
|
|
|
ProjectName: ObjToString((*info)["projectname"]),
|
|
|
S_winner: ObjToString((*info)["s_winner"]),
|
|
|
Bidopentime: Int64All((*info)["bidopentime"]),
|
|
|
+ Site: ObjToString((*info)["site"]),
|
|
|
+ Spidercode: ObjToString((*info)["spidercode"]),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total int64, result []*SubPushList) {
|
|
|
- log.Println(spqp.UserId, s.ModuleFlag, "subscribePush query param:", "SelectTime", spqp.SelectTime, "Area", spqp.Area, "City", spqp.City, "Subtype", spqp.Subtype, "Subscopeclass", spqp.Subscopeclass, "Buyerclass", spqp.Buyerclass, "Key", spqp.Key, "PageNum", spqp.PageNum)
|
|
|
+ log.Println(spqp.UserId, s.ModuleFlag, "subscribePush query param:", "SelectTime:", spqp.SelectTime, "Area:", spqp.Area, "City:", spqp.City, "Subtype:", spqp.Subtype, "Subscopeclass:", spqp.Subscopeclass, "Buyerclass:", spqp.Buyerclass, "Key:", spqp.Key, "PageNum:", spqp.PageNum, "Price:", spqp.Price, "FileExists:", spqp.FileExists)
|
|
|
if spqp.UserId == "" {
|
|
|
return
|
|
|
}
|
|
@@ -228,7 +238,6 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
|
|
|
starttime, endtime := int64(0), int64(0)
|
|
|
st, et := "", ""
|
|
|
now := time.Now()
|
|
|
- log.Println(4444)
|
|
|
if spqp.SelectTime == "today" { //今天
|
|
|
starttime = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
|
|
|
} else if spqp.SelectTime == "yesterday" { //昨天
|
|
@@ -251,14 +260,11 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
|
|
|
endtime = time.Date(etTime.Year(), etTime.Month(), etTime.Day(), 23, 59, 59, 0, time.Local).Unix()
|
|
|
}
|
|
|
}
|
|
|
- log.Println(2222)
|
|
|
nowFormat := NowFormat(Date_Short_Layout)
|
|
|
start := (spqp.PageNum - 1) * spqp.PageSize
|
|
|
end := start + spqp.PageSize
|
|
|
//时间是今天,没有别的过滤条件
|
|
|
- if nowFormat == FormatDateByInt64(&starttime, Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" {
|
|
|
-
|
|
|
- log.Println("a1")
|
|
|
+ if nowFormat == FormatDateByInt64(&starttime, Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == "" {
|
|
|
subPush, err := s.GetTodayCache(spqp.UserId)
|
|
|
if err != nil {
|
|
|
log.Println(spqp.UserId, "GetTodayCache Error", err)
|
|
@@ -281,15 +287,12 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
|
|
|
}
|
|
|
total = int64(length)
|
|
|
} else if spqp.IsEmpty() && (spqp.PageNum-1)*spqp.PageSize <= 250 { //全部,没有过滤条件 之前缓存5页*50条=250
|
|
|
- log.Println("a2")
|
|
|
allCache, err := s.GetAllCache(spqp.UserId)
|
|
|
if err != nil {
|
|
|
log.Println(spqp.UserId, "GetAllCache Error", err)
|
|
|
}
|
|
|
if err != nil || allCache == nil || allCache.Date != nowFormat || len(allCache.Datas) == 0 {
|
|
|
- log.Println("a3")
|
|
|
spqp.PageNum = 1
|
|
|
- log.Println(1111)
|
|
|
list, countSearch := s.getDatasFromMysql(spqp, starttime, endtime, AllSubPushCacheSize, true)
|
|
|
allCache = &SubPush{
|
|
|
Date: nowFormat,
|
|
@@ -307,7 +310,6 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
|
|
|
}
|
|
|
total = allCache.Count
|
|
|
} else {
|
|
|
- log.Println("a4")
|
|
|
result, total = s.getDatasFromMysql(spqp, starttime, endtime, spqp.PageSize, true)
|
|
|
}
|
|
|
if result == nil {
|
|
@@ -418,26 +420,43 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
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 := Int64All(Float64All(minPriceStr) * 10000) //换成元
|
|
|
+ maxPrice := Int64All(Float64All(maxPriceStr) * 10000) //换成元
|
|
|
+ if minPriceStr != "" && maxPriceStr != "" {
|
|
|
+ querys = append(querys, fmt.Sprintf("((bidamount>=%d and bidamount<=%d) or (budget>=%d and budget<=%d and bidamount is null))", minPrice, maxPrice, minPrice, maxPrice))
|
|
|
+ } else if minPriceStr != "" {
|
|
|
+ querys = append(querys, fmt.Sprintf("(bidamount>=%d or (budget>=%d and bidamount is null))", minPrice, minPrice))
|
|
|
+ } else if maxPriceStr != "" {
|
|
|
+ querys = append(querys, fmt.Sprintf("( bidamount<=%d or (budget<=%d and bidamount is null))", maxPrice, maxPrice))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //附件
|
|
|
+ if spqp.FileExists != "" {
|
|
|
+ if spqp.FileExists == "1" {
|
|
|
+ querys = append(querys, fmt.Sprintf("attachment_count is not null"))
|
|
|
+ } else if spqp.FileExists == "-1" {
|
|
|
+ querys = append(querys, fmt.Sprintf("attachment_count is null"))
|
|
|
+ }
|
|
|
+ }
|
|
|
searchSql := fmt.Sprintf(" from %s where %s order by id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, strings.Join(querys, " and "))
|
|
|
fmt.Println("searchSql", searchSql)
|
|
|
//查询总数
|
|
|
count = spqp.PushMysql.CountBySql(fmt.Sprintf("select count(id)" + searchSql))
|
|
|
-
|
|
|
- findSql := "select id,date,infoid,isvisit,matchkeys,type"
|
|
|
+ findSql := "select id,date,infoid,isvisit,matchkeys,type,attachment_count"
|
|
|
if s.ModuleFlag != MemberFlag {
|
|
|
if s.ModuleFlag == EntnicheFlag {
|
|
|
|
|
|
} else {
|
|
|
findSql += ",isvip"
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
findSql += searchSql
|
|
|
if isLimit {
|
|
|
findSql += fmt.Sprintf(" limit %d,%d", (spqp.PageNum-1)*size, size)
|
|
|
}
|
|
|
-
|
|
|
log.Println(spqp.UserId, "subscribePush query sql:", findSql)
|
|
|
list := spqp.PushMysql.SelectBySql(findSql)
|
|
|
if list != nil && len(*list) > 0 {
|
|
@@ -457,7 +476,7 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
|
|
|
func (s *subscribePush) GetOnlyInfoId(pushCas []*PushCa) []*SubPushList {
|
|
|
array := make([]*SubPushList, len(pushCas))
|
|
|
for k, v := range pushCas {
|
|
|
- array[k] = &SubPushList{Id: v.InfoId}
|
|
|
+ array[k] = &SubPushList{Id: EncodeArticleId2ByCheck(v.InfoId)}
|
|
|
}
|
|
|
return array
|
|
|
}
|
|
@@ -471,13 +490,14 @@ func (s *subscribePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*P
|
|
|
keys = strings.Split(matchkeys, " ")
|
|
|
}
|
|
|
pushCas = append(pushCas, &PushCa{
|
|
|
- Date: Int64All(v["date"]),
|
|
|
- InfoId: ObjToString(v["infoid"]),
|
|
|
- Visit: IntAll(v["isvisit"]),
|
|
|
- Index: Int64All(v["id"]),
|
|
|
- Keys: keys,
|
|
|
- Type: IntAll(v["type"]),
|
|
|
- Isvip: IntAll(v["isvip"]),
|
|
|
+ Date: Int64All(v["date"]),
|
|
|
+ InfoId: ObjToString(v["infoid"]),
|
|
|
+ Visit: IntAll(v["isvisit"]),
|
|
|
+ Index: Int64All(v["id"]),
|
|
|
+ Keys: keys,
|
|
|
+ Type: IntAll(v["type"]),
|
|
|
+ Isvip: IntAll(v["isvip"]),
|
|
|
+ FileExists: IntAll(v["attachment_count"]) > 0,
|
|
|
})
|
|
|
}
|
|
|
return
|
|
@@ -500,8 +520,7 @@ func (s *subscribePush) GetInfoByIds(Mgo_bidding mg.MongodbSim, bidding, bidding
|
|
|
}
|
|
|
infos := map[string]map[string]interface{}{}
|
|
|
//redis
|
|
|
-
|
|
|
- es_ids := []string{}
|
|
|
+ es_ids := ids
|
|
|
for _, v := range ids {
|
|
|
info_i := redis.Get("pushcache_1", fmt.Sprintf("info_%s", v))
|
|
|
if info_i != nil {
|
|
@@ -512,7 +531,6 @@ func (s *subscribePush) GetInfoByIds(Mgo_bidding mg.MongodbSim, bidding, bidding
|
|
|
es_ids = append(es_ids, v)
|
|
|
}
|
|
|
}
|
|
|
- // log.Println(es_ids)
|
|
|
//elasticsearch
|
|
|
if len(es_ids) > 0 {
|
|
|
list := elastic.Get("bidding", "bidding", fmt.Sprintf(query, strings.Join(es_ids, `","`), len(es_ids)))
|
|
@@ -525,7 +543,7 @@ func (s *subscribePush) GetInfoByIds(Mgo_bidding mg.MongodbSim, bidding, bidding
|
|
|
}
|
|
|
//mongodb bidding
|
|
|
mgo_ids := []primitive.ObjectID{}
|
|
|
- for _, v := range es_ids {
|
|
|
+ for _, v := range ids {
|
|
|
if infos[v] == nil {
|
|
|
_id, _ := primitive.ObjectIDFromHex(v)
|
|
|
mgo_ids = append(mgo_ids, _id)
|
|
@@ -572,7 +590,7 @@ func (s *subscribePush) GetInfoByIds(Mgo_bidding mg.MongodbSim, bidding, bidding
|
|
|
//保存最近7天的数据到历史记录
|
|
|
func (s *subscribePush) MakeHistoryDatas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, userId string, PushView func(userid, allquery, field string, pageNum, pageSize int) (keys []interface{}, list *[]map[string]interface{})) (bool, []*SubPushList) {
|
|
|
log.Println("匹配最近7天数据", userId)
|
|
|
- field := `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","buyerclass","budget","bidamount"`
|
|
|
+ field := `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","buyerclass","budget","bidamount","filetext","spidercode","site"`
|
|
|
allquery := `{"range":{"publishtime":{"gt":%s}}}`
|
|
|
allquery = fmt.Sprintf(allquery, fmt.Sprint(time.Now().AddDate(0, 0, -7).Unix()))
|
|
|
//allquery = ``
|
|
@@ -636,6 +654,19 @@ func (s *subscribePush) MakeHistoryDatas(MQFW mg.MongodbSim, PushMysql *mysql.My
|
|
|
myInsert["buyerclass"] = buyerclass_mapping
|
|
|
}
|
|
|
}
|
|
|
+ //附件 :检索库 只有附件字段,无法识别附件数量 暂定为1;为识别有附件
|
|
|
+ //v["filetext"]filetext := ObjToString(v["filetext"]); filetext != ""
|
|
|
+ if v["filetext"] != nil {
|
|
|
+ myInsert["attachment_count"] = 1
|
|
|
+ }
|
|
|
+ //中标金额
|
|
|
+ if v["bidamount"] != nil {
|
|
|
+ myInsert["bidamount"] = Int64All(v["bidamount"])
|
|
|
+ }
|
|
|
+ //预算
|
|
|
+ if v["budget"] != nil {
|
|
|
+ myInsert["budget"] = Int64All(v["budget"])
|
|
|
+ }
|
|
|
if s_subscopeclass := ObjToString(v["s_subscopeclass"]); s_subscopeclass != "" {
|
|
|
subscopeclass := []string{}
|
|
|
for _, v := range strings.Split(s_subscopeclass, ",") {
|
|
@@ -654,10 +685,11 @@ func (s *subscribePush) MakeHistoryDatas(MQFW mg.MongodbSim, PushMysql *mysql.My
|
|
|
continue
|
|
|
}
|
|
|
array = append(array, s.InfoFormat(&PushCa{
|
|
|
- InfoId: _id,
|
|
|
- Date: now,
|
|
|
- Index: id,
|
|
|
- Keys: matchkeys,
|
|
|
+ InfoId: _id,
|
|
|
+ Date: now,
|
|
|
+ Index: id,
|
|
|
+ Keys: matchkeys,
|
|
|
+ FileExists: v["filetext"] != nil,
|
|
|
}, &v))
|
|
|
}
|
|
|
var resultList []*SubPushList
|
|
@@ -705,7 +737,7 @@ func (s *subscribePush) Visit(PushMysql *mysql.Mysql, userId string, id int) {
|
|
|
|
|
|
//查看全部列表缓存
|
|
|
func (s *subscribePush) PutAllCache(userId string, datas *SubPush) {
|
|
|
- redis.Put("pushcache_2_a", s.allKey(userId), datas, threeDay)
|
|
|
+ redis.Put("pushcache_2_a", s.allKey(userId), datas, oneDay)
|
|
|
}
|
|
|
|
|
|
func (s *subscribePush) GetAllCache(userId string) (*SubPush, error) {
|
|
@@ -728,7 +760,7 @@ func (s *subscribePush) GetCache(code, key string) (*SubPush, error) {
|
|
|
}
|
|
|
|
|
|
//是否收藏
|
|
|
-func (s *subscribePush) MakeCollection(userId string, m *mysql.Mysql, list []*SubPushList) {
|
|
|
+func (s *subscribePush) MakeCollection(userId string, m *mysql.Mysql, list []*SubPushList, fileSignBool bool) {
|
|
|
if list == nil || len(list) == 0 {
|
|
|
return
|
|
|
}
|
|
@@ -750,6 +782,9 @@ func (s *subscribePush) MakeCollection(userId string, m *mysql.Mysql, list []*Su
|
|
|
}
|
|
|
}
|
|
|
for _, v := range list {
|
|
|
+ if !fileSignBool {
|
|
|
+ v.Ca_fileExists = false
|
|
|
+ }
|
|
|
if bid_map[v.Id] {
|
|
|
v.Collection = 1
|
|
|
}
|
|
@@ -807,3 +842,151 @@ func InfoFormats(info map[string]interface{}, tmp map[string]interface{}) map[st
|
|
|
info["type"] = infotype
|
|
|
return info
|
|
|
}
|
|
|
+
|
|
|
+//保存最近7天的数据到历史记录--新
|
|
|
+/*已选条件--关键词*/
|
|
|
+type ViewKeyWord struct {
|
|
|
+ Keyword []string `json:"key"` //关键词
|
|
|
+ Appended []string `json:"appendkey"` //附加词
|
|
|
+ Exclude []string `json:"notkey"` //排除词
|
|
|
+ MatchWay int `json:"matchway"` //匹配模式
|
|
|
+}
|
|
|
+
|
|
|
+func (s *subscribePush) MakeHistoryDatasNew(PushMysql *mysql.Mysql, userId string, entId int, DefaultPushList func(userId, moduleFlag string, entId int) (keyword []byte, list *[]map[string]interface{}, deptId int)) (bool, []*SubPushList) {
|
|
|
+ log.Println(s.ModuleFlag, "匹配最近7天数据", userId, entId)
|
|
|
+ //
|
|
|
+ t1 := time.Now()
|
|
|
+ kw, list, deptId := DefaultPushList(userId, s.ModuleFlag, entId)
|
|
|
+ if list == nil || len(*list) == 0 {
|
|
|
+ return false, nil
|
|
|
+ }
|
|
|
+ var isNext = false
|
|
|
+ log.Println("es查询耗时:", time.Since(t1))
|
|
|
+ var resultList []*SubPushList
|
|
|
+ if list != nil && len(*list) > 0 {
|
|
|
+ keyword := []ViewKeyWord{}
|
|
|
+ if err := json.Unmarshal(kw, &keyword); err != nil {
|
|
|
+ return false, nil
|
|
|
+ }
|
|
|
+ //超过50条先处理50条 返回前50条
|
|
|
+ listOne := *list
|
|
|
+ if len(*list) > pageSize {
|
|
|
+ listOne = (*list)[:pageSize]
|
|
|
+ }
|
|
|
+ resultList = s.listManager(PushMysql, listOne, keyword, (len(listOne)+pageSize)/pageSize, entId, deptId, userId)
|
|
|
+ if len(*list) > pageSize {
|
|
|
+ isNext = true
|
|
|
+ listOther := (*list)[pageSize:]
|
|
|
+ go s.listManager(PushMysql, listOther, keyword, (len(listOther)+pageSize)/pageSize, entId, deptId, userId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println("第一批推送信息处理耗时:", time.Since(t1).Seconds(), len(resultList))
|
|
|
+ return isNext, resultList
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func (s *subscribePush) listManager(PushMysql *mysql.Mysql, list []map[string]interface{}, keyword []ViewKeyWord, ccount, entId, deptId int, userId string) (resultList []*SubPushList) {
|
|
|
+ t2 := time.Now()
|
|
|
+ now := time.Now()
|
|
|
+ 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", userId, ObjToString(v["_id"]))
|
|
|
+ title := strings.Replace(ObjToString(v["title"]), "\n", "", -1)
|
|
|
+ var myInsert = make(map[string]interface{})
|
|
|
+ myInsert["userid"] = userId
|
|
|
+ myInsert["infoid"] = ObjToString(v["_id"])
|
|
|
+ myInsert["date"] = now.Unix()
|
|
|
+ matchkeys := getKeys(title, keyword)
|
|
|
+ myInsert["matchkeys"] = strings.Join(matchkeys, " ")
|
|
|
+ if v["area"] != nil {
|
|
|
+ myInsert["area"] = If(ObjToString(v["area"]) == "A", 0, If(PushMapping.Area[ObjToString(v["area"])] > 0, PushMapping.Area[ObjToString(v["area"])], 0).(int)).(int)
|
|
|
+ }
|
|
|
+ if v["city"] != nil {
|
|
|
+ myInsert["city"] = If(PushMapping.City[ObjToString(v["city"])] > 0, PushMapping.City[ObjToString(v["city"])], 0).(int)
|
|
|
+ }
|
|
|
+ if v["subtype"] != nil {
|
|
|
+ myInsert["subtype"] = If(PushMapping.Subtype[ObjToString(v["subtype"])] > 0, PushMapping.Subtype[ObjToString(v["subtype"])], 0).(int)
|
|
|
+ }
|
|
|
+ if v["toptype"] != nil {
|
|
|
+ myInsert["toptype"] = If(PushMapping.Toptype[ObjToString(v["toptype"])] > 0, PushMapping.Toptype[ObjToString(v["toptype"])], 0).(int)
|
|
|
+ }
|
|
|
+ if v["buyerclass"] != nil {
|
|
|
+ myInsert["buyerclass"] = If(PushMapping.Buyerclass[ObjToString(v["buyerclass"])] > 0, PushMapping.Buyerclass[ObjToString(v["buyerclass"])], 0).(int)
|
|
|
+ }
|
|
|
+ if v["isValidFile"] != nil {
|
|
|
+ isValidFile, _ := v["isValidFile"].(bool)
|
|
|
+ myInsert["attachment_count"] = If(isValidFile, 1, 0).(int) //附件 :检索库 只有附件字段,无法识别附件数量 暂定为1;为识别有附件
|
|
|
+ }
|
|
|
+ if v["bidamount"] != nil {
|
|
|
+ myInsert["bidamount"] = Int64All(v["bidamount"])
|
|
|
+ }
|
|
|
+ if v["budget"] != nil {
|
|
|
+ myInsert["budget"] = Int64All(v["budget"])
|
|
|
+ }
|
|
|
+ if s_subscopeclass := ObjToString(v["s_subscopeclass"]); s_subscopeclass != "" {
|
|
|
+ subscopeclass := []string{}
|
|
|
+ for _, v := range strings.Split(s_subscopeclass, ",") {
|
|
|
+ if subscopeclass_mapping, ok := PushMapping.Subscopeclass[v]; ok {
|
|
|
+ subscopeclass = append(subscopeclass, fmt.Sprint(subscopeclass_mapping))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(subscopeclass) > 0 {
|
|
|
+ myInsert["subscopeclass"] = strings.Join(subscopeclass, ",")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //商机管理用户
|
|
|
+ if s.ModuleFlag == "s" {
|
|
|
+ myInsert["userid"] = userId
|
|
|
+ myInsert["entid"] = entId
|
|
|
+ myInsert["deptid"] = deptId
|
|
|
+ }
|
|
|
+ //保存推送表
|
|
|
+ id := PushMysql.Insert(aboutDbMsg[s.ModuleFlag].MysqlTable, myInsert)
|
|
|
+ if id > 0 {
|
|
|
+ redis.Put("pushcache_2_a", redisKey, 1, 86400)
|
|
|
+ resultList = append(resultList, s.InfoFormat(&PushCa{
|
|
|
+ InfoId: ObjToString(v["_id"]),
|
|
|
+ Date: now.Unix(),
|
|
|
+ Index: id,
|
|
|
+ Keys: matchkeys,
|
|
|
+ FileExists: v["filetext"] != nil,
|
|
|
+ }, &v))
|
|
|
+ }
|
|
|
+ }(v)
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ log.Println("数据处理耗时:", time.Since(t2))
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//获取匹配得关键词
|
|
|
+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
|
|
|
+}
|