Pārlūkot izejas kodu

Merge branch 'dev_v1.1.45_wh' of BaseService/jyMicroservices into feature/v1.1.45

王浩 1 gadu atpakaļ
vecāks
revīzija
221d581866

+ 2 - 1
jyBXSubscribe/rpc/internal/logic/bypushhistorylogic.go

@@ -92,10 +92,11 @@ func (l *ByPushHistoryLogic) ByPushHistory(in *bxsubscribe.SubscribeInfosReq) (*
 	var (
 		ids, keyWords []string
 	)
+	bsp := model.NewSubscribePush(vipType).GetUserInfo(spqp)
 	if len(spqp.SelectInfoIds) > 0 {
 		ids, keyWords = spqp.ExportPushFormat()
 	} else {
-		_, _, list := model.NewSubscribePush(vipType).Datas(spqp)
+		_, _, list := model.NewSubscribePush(vipType).Datas(spqp, bsp)
 		if list == nil || len(list) == 0 {
 			return &bxsubscribe.ByPushHistoryResp{
 				ErrorCode: 1,

+ 1 - 1
jyBXSubscribe/rpc/internal/logic/getsublistlogic.go

@@ -107,7 +107,7 @@ func (l *GetSubListLogic) GetSubList(in *bxsubscribe.SubscribeInfosReq) (*bxsubs
 	sp := model.NewSubscribePush(in.UserType)
 	//用户信息
 	bsp := sp.GetUserInfo(spqp)
-	hasNextPage, total, list := sp.Datas(spqp, bsp)
+	hasNextPage, total, list := model.NewSubscribePush(in.UserType).Datas(spqp, bsp)
 	start1 := time.Now().Unix()
 	logx.Info("1、查询数据用户", start1-start)
 	/*

+ 233 - 7
jyBXSubscribe/rpc/model/push.go

@@ -292,10 +292,6 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam, bsp *ViewCondition) (hasN
 	logx.Info(spqp.UserId, spqp.NewUserId, s.ModuleFlag, "subscribePush query param:", "SelectTime:", spqp.SelectTime, "Area:", spqp.Area, "District:", spqp.District, "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.UserType == "" && spqp.PositionType == 0 {
-
 	}
 	if spqp.PageNum < 1 {
 		spqp.PageNum = 1
@@ -322,6 +318,15 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam, bsp *ViewCondition) (hasN
 			}
 		}
 	}
+	/*result, total = s.inactiveQuery(spqp, bsp)
+	hasNextPage = len(result) >= spqp.PageSize
+	return*/
+	//不活跃用户处理
+	if spqp.UserType == "fType" && spqp.PositionType == 0 && spqp.SubPushInactive == "1" {
+		result, total = s.inactiveQuery(spqp, bsp)
+		hasNextPage = len(result) >= spqp.PageSize
+		return
+	}
 	nowFormat := date.NowFormat(date.Date_Short_Layout)
 	start := (spqp.PageNum - 1) * spqp.PageSize
 	end := start + spqp.PageSize
@@ -404,7 +409,104 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam, bsp *ViewCondition) (hasN
 	hasNextPage = len(result) >= spqp.PageSize
 	return
 }
-
+func (s *subscribePush) inactiveQuery(spqp *SubPushQueryParam, bsp *ViewCondition) ([]*bxsubscribe.SubscribeInfo, int64) {
+	list := &[]map[string]interface{}{}
+	count := int64(0)
+	if len(spqp.SelectInfoIds) > 0 {
+		//通过infoId查数据
+		list = elastic.Get("bidding", "bidding", fmt.Sprintf(query, strings.Join(spqp.SelectInfoIds, `","`), len(spqp.SelectInfoIds)))
+		count = gconv.Int64(len(*list))
+	} else {
+		//通过条件查询
+		starttime := int64(0)
+		endtime := int64(0)
+		if len(strings.Split(spqp.SelectTime, "_")) == 2 {
+			st := strings.Split(spqp.SelectTime, "_")[0]
+			et := strings.Split(spqp.SelectTime, "_")[1]
+			if st == "" {
+				time.Now().AddDate(0, 0, -15).Unix()
+			} else {
+				starttime, _ = strconv.ParseInt(st, 0, 64)
+			}
+			if et == "" {
+				time.Now().Unix()
+			} else {
+				endtime, _ = strconv.ParseInt(et, 0, 64)
+			}
+		}
+		qstr := s.getFreeDatasSQL(bsp, starttime, endtime, (spqp.PageNum-1)*spqp.PageSize, spqp.PageSize)
+		//list = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSort, bidField, 0, 4500, 0, false)
+		count, list = elastic.GetWithCount(INDEX, TYPE, "", qstr)
+	}
+	if count > 4500 {
+		count = 4500
+	}
+	log.Println(count, list)
+	//数据清洗
+	size := spqp.PageSize
+	if spqp.PageSize == 0 {
+		size = len(spqp.SelectInfoIds)
+	}
+	array := make([]*bxsubscribe.SubscribeInfo, size)
+	for i, m := range *list {
+		if i == size {
+			break
+		}
+		formatInfo := &bxsubscribe.SubscribeInfo{}
+		infoid := common.InterfaceToStr(m["_id"])
+		matchkeys := getKeys(common.InterfaceToStr(m["title"]), bsp.Keyword)
+		if len(spqp.SelectInfoIds) > 0 {
+			formatInfo = &bxsubscribe.SubscribeInfo{XId: encrypt.EncodeArticleId2ByCheck(infoid), MatchKeys: matchkeys}
+		} else {
+			industry := common.ObjToString(m["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(m["subtype"])
+			if infotype == "" {
+				infotype = common.ObjToString(m["toptype"])
+			}
+			area := common.If(m["area"] == nil, nil, common.If(common.ObjToString(m["area"]) == "A", "全国", ""))
+			formatInfo = &bxsubscribe.SubscribeInfo{
+				XId:          encrypt.EncodeArticleId2ByCheck(infoid),
+				Title:        common.InterfaceToStr(m["title"]),
+				Area:         gconv.String(area),
+				City:         common.InterfaceToStr(m["city"]),
+				BuyerClass:   common.InterfaceToStr(m["buyerclass"]),
+				Subtype:      infotype,
+				Industry:     industry,
+				PublishTime:  common.Int64All(m["publishtime"]),
+				CaDate:       gconv.Int64(m["publishtime"]),
+				CaIsvisit:    0,
+				CaIsvip:      0,
+				CaType:       0,
+				MatchKeys:    matchkeys,
+				Budget:       common.Float64All(m["budget"]),
+				BidAmount:    common.Float64All(m["bidamount"]),
+				Buyer:        common.InterfaceToStr(m["buyer"]),
+				ProjectName:  common.InterfaceToStr(m["projectname"]),
+				Winner:       common.InterfaceToStr(m["s_winner"]),
+				BidOpenTime:  common.Int64All(m["bidopentime"]),
+				CaFileExists: m["filetext"] != nil,
+				Source:       1,
+				Site:         common.InterfaceToStr(m["site"]),
+				SpiderCode:   common.InterfaceToStr(m["spidercode"]),
+				Toptype:      common.InterfaceToStr(m["toptype"]),
+				IsValidFile:  m["filetext"] != nil,
+				SourceAll:    "1",
+			}
+		}
+		array[i] = formatInfo
+	}
+	return array, count
+}
 func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, endtime int64, size int, isLimit bool) (result []*bxsubscribe.SubscribeInfo, count int64) {
 	start := time.Now().Unix()
 	querys := []string{}
@@ -1231,6 +1333,131 @@ func getKeys(title string, keywords []ViewKeyWord) (str []string) {
 	return
 }
 
+// 获取查询语句
+func (s *subscribePush) getFreeDatasSQL(bsp *ViewCondition, startTime, endTime int64, startNumb, size int) (str string) {
+	query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}},"_source":[%s],"sort": [{"publishtime": "desc"}],"from":%d,"size":%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_bool_must_and_district := `{"bool":{"must":[{"terms":{"city":["%s"]}},{"terms":{"district":["%s"]}}]}}`
+	publishtime := `{"range":{"publishtime":{"gt":%d,"lt":%d}}}`
+	bools := []string{}
+	musts := []string{}
+	//发布时间最新15天(正式环境需要修改)
+	musts = append(musts, fmt.Sprintf(publishtime, startTime, endTime))
+	//省份
+	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(bsp.District) > 0 {
+		for _, v := range bsp.District {
+			cityName := strings.Split(v, "_")[0]
+			districtName := strings.Split(v, "_")[1]
+			areaCity = append(areaCity, fmt.Sprintf(query_bool_must_and_district, cityName, districtName))
+		}
+	}
+	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 _, 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+"\""))
+			}
+
+			//添加
+			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, bidField, startNumb, size)
+	logx.Info("----", qstr)
+	return qstr
+}
+
 // 获取查询语句
 func (s *subscribePush) getDefaultDatasSQL(bsp *ViewCondition) (str string) {
 	query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}}`
@@ -1241,7 +1468,7 @@ func (s *subscribePush) getDefaultDatasSQL(bsp *ViewCondition) (str string) {
 
 	bools := []string{}
 	musts := []string{}
-	//发布时间最新7天(正式环境需要修改)
+	//发布时间最新15天(正式环境需要修改)
 	musts = append(musts, fmt.Sprintf(bidTime, time.Now().AddDate(0, 0, -15).Unix()))
 	//省份
 	areaCity := []string{}
@@ -1480,7 +1707,6 @@ func (s *subscribePush) GetUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition)
 	} else {
 		vc.Size = IC.C.DefaulCount.Free
 		vc.Keyword = getKeyWordArrFromDbResultByFree(tmpInfo.Items, "", -1)
-		//vc.Keyword = getKeyWordArrFromDbResult(tmpInfo.Items, "", -1)
 	}
 	return
 }