123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- package matcher
- import (
- "fmt"
- "testing"
- util "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/logger"
- . "app.yhyue.com/moapp/jybase/mongodb"
- . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
- )
- func TestMatch(t *testing.T) {
- m := &matchJob{}
- m.mgo = &MongodbSim{
- MongodbAddr: "192.168.3.206:27080",
- Size: 2,
- DbName: "qfw",
- }
- m.mgo.InitPool()
- bidMgo := &MongodbSim{
- MongodbAddr: "192.168.3.206:27002",
- Size: 2,
- DbName: "qfw",
- UserName: "jyDevGroup",
- Password: "jy@DevGroup",
- }
- bidMgo.InitPool()
- query := map[string]interface{}{
- "_id": map[string]interface{}{
- "$in": ToObjectIds([]string{"665cc37666cf0db42a7f7981"}),
- },
- }
- datas, _ := LoadBidding(bidMgo, "qfw_data", "bidding", 0, false, query, nil)
- m.Start(datas)
- }
- type matchJob struct {
- mgo *MongodbSim
- }
- func (m *matchJob) Start(datas *[]map[string]interface{}) {
- defer util.Catch()
- allSubSet := NewPayUser()
- //标题匹配
- title_key := make(map[string]*[]*UserInfo)
- title_notkey := make(map[string]*[]*UserInfo)
- title_pjob := &KeyDfa{
- Key_user: &title_key,
- Notkey_user: &title_notkey,
- }
- //正文匹配
- detail_key := make(map[string]*[]*UserInfo)
- detail_notkey := make(map[string]*[]*UserInfo)
- detail_pjob := &KeyDfa{
- Key_user: &detail_key,
- Notkey_user: &detail_notkey,
- }
- //附件匹配
- filetext_key := make(map[string]*[]*UserInfo)
- filetext_notkey := make(map[string]*[]*UserInfo)
- filetext_pjob := &KeyDfa{
- Key_user: &filetext_key,
- Notkey_user: &filetext_notkey,
- }
- //项目名称/标的物匹配
- pnp_key := make(map[string]*[]*UserInfo)
- pnp_notkey := make(map[string]*[]*UserInfo)
- pnp_pjob := &KeyDfa{
- Key_user: &pnp_key,
- Notkey_user: &pnp_notkey,
- }
- m.LoadMySubSet(allSubSet, title_pjob, detail_pjob, filetext_pjob, pnp_pjob)
- //
- title_pjob.CreateDaf()
- detail_pjob.CreateDaf()
- filetext_pjob.CreateDaf()
- pnp_pjob.CreateDaf()
- allSubSet.Title_KeyDfa = title_pjob
- allSubSet.Detail_KeyDfa = detail_pjob
- allSubSet.Filetext_KeyDfa = filetext_pjob
- allSubSet.PnP_KeyDfa = pnp_pjob
- //
- allSubSet.Match(1, datas)
- }
- //我的订阅设置
- func (m *matchJob) LoadMySubSet(allSubSet *PayUser, title_pjob, detail_pjob, filetext_pjob, pnp_pjob *KeyDfa) {
- defer util.Catch()
- sess := m.mgo.GetMgoConn()
- defer m.mgo.DestoryMongoConn(sess)
- query := map[string]interface{}{
- "_id": StringTOBsonId("665a8ba6842ed1e25c138ac7"),
- }
- logger.Info("我的订阅设置", query)
- it := sess.DB("qfw").C("entniche_rule").Find(query).Select(map[string]interface{}{
- "i_entid": 1,
- "i_deptid": 1,
- "i_userid": 1,
- "o_entniche": 1,
- "i_type": 1,
- }).Iter()
- for temp := make(map[string]interface{}); it.Next(&temp); {
- entId := util.IntAll(temp["i_entid"])
- userId := util.IntAll(temp["i_userid"])
- user := &UserInfo{
- Entniche: &Entniche{
- UserId: userId,
- IsNew: 1,
- },
- }
- subSetType := util.IntAllDef(temp["i_type"], -1)
- subSet, _ := temp["o_entniche"].(map[string]interface{})
- user.GetSubSet(subSetType == 2, fmt.Sprint(userId), subSet)
- if user.SubSet.Switch == 0 {
- logger.Info("订阅开关没有开启,过滤掉", entId, userId)
- continue
- }
- if subSetType == 2 && len(user.SubSet.Keys) == 0 {
- logger.Info("过滤掉,没有关键词", entId, userId)
- continue
- } else if subSetType != 2 && len(user.SubSet.Keys) == 0 && user.SubSet.Subtype == nil && user.SubSet.Area == nil && user.SubSet.Buyerclass == nil {
- logger.Info("没有订阅,过滤掉", entId, userId)
- continue
- }
- if subSetType == 2 {
- user.PushSet.SubSet.RateMode = 0
- }
- m.InitSubSet(allSubSet, user, title_pjob, detail_pjob, filetext_pjob, pnp_pjob)
- allSubSet.Users[user] = true
- temp = make(map[string]interface{})
- }
- }
- func (m *matchJob) InitSubSet(allSubSet *PayUser, user *UserInfo, title_pjob, detail_pjob, filetext_pjob, pnp_pjob *KeyDfa) {
- user.AddBuyerclass(&allSubSet.BuyerclassUsers)
- user.AddAreaCityDistrict(&allSubSet.AreaUsers, &allSubSet.CityUsers, &allSubSet.DistrictUsers)
- user.AddSubtype(&allSubSet.SubtypeUsers)
- user.MakeKeyUserByMatchMode(title_pjob, detail_pjob, filetext_pjob, pnp_pjob)
- }
|