浏览代码

feat:推送

wangshan 3 年之前
父节点
当前提交
37c716ba75
共有 2 个文件被更改,包括 100 次插入81 次删除
  1. 98 79
      jyBXSubscribe/rpc/model/push.go
  2. 2 2
      jyBXSubscribe/rpc/model/service/matchjob.go

+ 98 - 79
jyBXSubscribe/rpc/model/push.go

@@ -739,88 +739,106 @@ func (s *subscribePush) DefaultDatas(spqp *SubPushQueryParam) (hasNextPage bool,
 		list := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSort, bidField, 0, scd.Size, 0, false)
 		logx.Info(time.Since(t1), "count:", len(*list))
 		if list != nil && len(*list) > 0 {
-			now := time.Now()
-			var (
-				wg = &sync.WaitGroup{}
-				wc = make(chan bool, scd.Size/pageSize)
-			)
-			for _, v := range *list {
-				go func(v map[string]interface{}) {
-					wg.Add(1)
-					wc <- true
-					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 myInsert = make(map[string]interface{})
-					myInsert["userid"] = spqp.UserId
-					myInsert["infoid"] = common.ObjToString(v["_id"])
-					myInsert["date"] = now.Unix()
-					matchkeys := getKeys(title, scd.Keyword)
-					myInsert["matchkeys"] = strings.Join(matchkeys, " ")
-					if v["area"] != nil {
-						myInsert["area"] = common.If(common.ObjToString(v["area"]) == "A", 0, common.If(IC.PushMapping.Area[common.ObjToString(v["area"])] > 0, IC.PushMapping.Area[common.ObjToString(v["area"])], 0).(int)).(int)
-					}
-					if v["city"] != nil {
-						myInsert["city"] = common.If(IC.PushMapping.City[common.ObjToString(v["city"])] > 0, IC.PushMapping.City[common.ObjToString(v["city"])], 0).(int)
-					}
-					if v["subtype"] != nil {
-						myInsert["subtype"] = common.If(IC.PushMapping.Subtype[common.ObjToString(v["subtype"])] > 0, IC.PushMapping.Subtype[common.ObjToString(v["subtype"])], 0).(int)
-					}
-					if v["toptype"] != nil {
-						myInsert["toptype"] = common.If(IC.PushMapping.Toptype[common.ObjToString(v["toptype"])] > 0, IC.PushMapping.Toptype[common.ObjToString(v["toptype"])], 0).(int)
-					}
-					if v["buyerclass"] != nil {
-						myInsert["buyerclass"] = common.If(IC.PushMapping.Buyerclass[common.ObjToString(v["buyerclass"])] > 0, IC.PushMapping.Buyerclass[common.ObjToString(v["buyerclass"])], 0).(int)
-					}
-					if v["filetext"] != nil {
-						myInsert["attachment_count"] = common.If(v["filetext"] != nil, 1, 0).(int) //附件 :检索库 只有附件字段,无法识别附件数量 暂定为1;为识别有附件
-					}
-					if v["bidamount"] != nil {
-						myInsert["bidamount"] = common.Int64All(v["bidamount"])
-					}
-					if v["budget"] != nil {
-						myInsert["budget"] = common.Int64All(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 {
-							myInsert["subscopeclass"] = strings.Join(subscopeclass, ",")
-						}
-					}
-					//商机管理用户
-					if s.ModuleFlag == "eType" {
-						myInsert["userid"] = spqp.EntUserId
-						myInsert["entid"] = spqp.EntId
-						myInsert["deptid"] = spqp.DeptId
-					}
-					//保存推送表
-					id := spqp.PushMysql.Insert(aboutDbMsg[s.ModuleFlag].MysqlTable, myInsert)
-					if id > 0 {
-						redis.Put("pushcache_2_a", redisKey, 1, 86400)
-						result = append(result, s.InfoFormat(&PushCa{
-							InfoId:     common.ObjToString(v["_id"]),
-							Date:       now.Unix(),
-							Index:      id,
-							Keys:       matchkeys,
-							FileExists: v["filetext"] != nil,
-						}, &v))
-					}
-				}(v)
+			total = int64(len(*list))
+			//超过50条先处理50条 返回前50条
+			listOne := *list
+			if len(*list) > pageSize {
+				listOne = (*list)[:pageSize]
+			}
+			result = s.listManager(spqp, listOne, scd.Keyword, (len(listOne)+pageSize)/pageSize)
+			if len(*list) > pageSize {
+				hasNextPage = true
+				listOther := (*list)[pageSize:]
+				go s.listManager(spqp, listOther, scd.Keyword, (len(listOther)+pageSize)/pageSize)
 			}
-			wg.Wait()
 		}
 	}
 	logx.Info("请求耗时:", time.Since(t2))
-	hasNextPage = len(result) > pageSize
-	total = int64(len(result))
+	return
+}
+
+//
+func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]interface{}, keyword []ViewKeyWord, ccount int) (resultList []*bxsubscribe.SubscribeInfo) {
+	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", spqp.UserId, common.ObjToString(v["_id"]))
+			title := strings.Replace(common.ObjToString(v["title"]), "\n", "", -1)
+			var myInsert = make(map[string]interface{})
+			myInsert["userid"] = spqp.UserId
+			myInsert["infoid"] = common.ObjToString(v["_id"])
+			myInsert["date"] = now.Unix()
+			matchkeys := getKeys(title, keyword)
+			myInsert["matchkeys"] = strings.Join(matchkeys, " ")
+			if v["area"] != nil {
+				myInsert["area"] = common.If(common.ObjToString(v["area"]) == "A", 0, common.If(IC.PushMapping.Area[common.ObjToString(v["area"])] > 0, IC.PushMapping.Area[common.ObjToString(v["area"])], 0).(int)).(int)
+			}
+			if v["city"] != nil {
+				myInsert["city"] = common.If(IC.PushMapping.City[common.ObjToString(v["city"])] > 0, IC.PushMapping.City[common.ObjToString(v["city"])], 0).(int)
+			}
+			if v["subtype"] != nil {
+				myInsert["subtype"] = common.If(IC.PushMapping.Subtype[common.ObjToString(v["subtype"])] > 0, IC.PushMapping.Subtype[common.ObjToString(v["subtype"])], 0).(int)
+			}
+			if v["toptype"] != nil {
+				myInsert["toptype"] = common.If(IC.PushMapping.Toptype[common.ObjToString(v["toptype"])] > 0, IC.PushMapping.Toptype[common.ObjToString(v["toptype"])], 0).(int)
+			}
+			if v["buyerclass"] != nil {
+				myInsert["buyerclass"] = common.If(IC.PushMapping.Buyerclass[common.ObjToString(v["buyerclass"])] > 0, IC.PushMapping.Buyerclass[common.ObjToString(v["buyerclass"])], 0).(int)
+			}
+			if v["isValidFile"] != nil {
+				isValidFile, _ := v["isValidFile"].(bool)
+				myInsert["attachment_count"] = common.If(isValidFile, 1, 0).(int) //附件 :检索库 只有附件字段,无法识别附件数量 暂定为1;为识别有附件
+			}
+			if v["bidamount"] != nil {
+				myInsert["bidamount"] = common.Int64All(v["bidamount"])
+			}
+			if v["budget"] != nil {
+				myInsert["budget"] = common.Int64All(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 {
+					myInsert["subscopeclass"] = strings.Join(subscopeclass, ",")
+				}
+			}
+			//商机管理用户
+			if s.ModuleFlag == "s" {
+				myInsert["userid"] = spqp.EntUserId
+				myInsert["entid"] = spqp.EntId
+				myInsert["deptid"] = spqp.DeptId
+			}
+			//保存推送表
+			id := spqp.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:     common.ObjToString(v["_id"]),
+					Date:       now.Unix(),
+					Index:      id,
+					Keys:       matchkeys,
+					FileExists: v["filetext"] != nil,
+				}, &v))
+			}
+		}(v)
+	}
+	wg.Wait()
+	log.Println("数据处理耗时:", time.Since(t2))
 	return
 }
 
@@ -1024,8 +1042,9 @@ func (s *subscribePush) getUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition)
 		//商机管理
 		entUserId, _ := strconv.Atoi(spqp.EntUserId)
 		entId, _ := strconv.Atoi(spqp.EntId)
-		entInfo := (&ms.MatchJob{}).Start(entId, entUserId)
+		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{})

+ 2 - 2
jyBXSubscribe/rpc/model/service/matchjob.go

@@ -29,12 +29,12 @@ type Entniche struct {
 type MatchJob struct {
 }
 
-func (m *MatchJob) Start(entId, entUserId int) map[string]interface{} {
+func (m *MatchJob) Start(entId, entUserId int) (map[string]interface{}, int) {
 	defer util.Catch()
 	defer ClearEnt()
 	InitEnt(IC.MainMysql, &IC.Mgo, "qfw", entId, entUserId)
 	users := m.LoadSubSet(entId)
-	return FinalSub(entUserId, users)
+	return FinalSub(entUserId, users), EntUserDept[entUserId].DeptId
 }
 
 func (m *MatchJob) LoadSubSet(entId int) map[*UserInfo]bool {