Bladeren bron

feat: bigmember 潜在项目预测增加价格区间

fuwencai 1 jaar geleden
bovenliggende
commit
f591e7a11c
1 gewijzigde bestanden met toevoegingen van 27 en 7 verwijderingen
  1. 27 7
      src/jfw/modules/bigmember/src/service/analysis/forecastproject.go

+ 27 - 7
src/jfw/modules/bigmember/src/service/analysis/forecastproject.go

@@ -9,6 +9,7 @@ import (
 	"jy/src/jfw/modules/bigmember/src/util"
 	"log"
 	"sort"
+	"strconv"
 	"strings"
 	"time"
 
@@ -49,7 +50,7 @@ const (
 
 *
 */
-func getForecastProjectSql(scd *util.ViewCondition, startTime, endTime int, dataType string) string {
+func getForecastProjectSql(scd *util.ViewCondition, startTime, endTime int, dataType string, minPrice int, maxPrice int) string {
 	musts := []string{}
 	bools := []string{}
 	entTimeStr := ``
@@ -117,6 +118,21 @@ func getForecastProjectSql(scd *util.ViewCondition, startTime, endTime int, data
 		Buyerclass += `]}}`
 		musts = append(musts, Buyerclass)
 	}
+	//金额区间
+	if minPrice > 0 || maxPrice > 0 {
+		pricequery := `{"range":{"sortprice":{`
+		if minPrice > 0 {
+			pricequery += `"gte":` + strconv.Itoa(minPrice*10000)
+		}
+		if minPrice > 0 && maxPrice > 0 {
+			pricequery += `,`
+		}
+		if maxPrice > 0 {
+			pricequery += `"lt":` + strconv.Itoa(maxPrice*10000)
+		}
+		pricequery += `}}}`
+		musts = append(musts, pricequery)
+	}
 
 	//should
 	if len(scd.Keyword) > 0 {
@@ -302,6 +318,8 @@ func (this *Analysis) ForDerive() {
 	endTime, _ := this.GetInteger("endTime")
 	dataType := this.GetString("dataType")
 	area := this.GetString("area")
+	minPrice, _ := this.GetInteger("minprice")
+	maxPrice, _ := this.GetInteger("maxprice")
 	if area == "{}" {
 		area = ""
 	}
@@ -331,7 +349,7 @@ func (this *Analysis) ForDerive() {
 		if (*o_mb)["o_member_jy"] != nil {
 			o_member_jy = qutil.ObjToMap((*o_mb)["o_member_jy"])
 			//项目预测检索库
-			selectIds, sql = getNewForecastDerive(main_userId, *o_member_jy, startTime, endTime, count, dataType, area, selectIds)
+			selectIds, sql = getNewForecastDerive(main_userId, *o_member_jy, startTime, endTime, count, dataType, area, selectIds, minPrice, maxPrice)
 		}
 	}
 	if selectIds == nil || len(selectIds) == 0 || sql == nil {
@@ -412,6 +430,8 @@ func (this *Analysis) ForPList() {
 		dataType := this.GetString("dataType")
 		area := this.GetString("area")
 		total, _ := this.GetInteger("total")
+		minPrice, _ := this.GetInteger("minprice")
+		maxPrice, _ := this.GetInteger("maxprice")
 		if area == "{}" {
 			area = ""
 		}
@@ -431,7 +451,7 @@ func (this *Analysis) ForPList() {
 		o_mb := config.Compatible.Select(main_userId, `{"o_member_jy":1}`)
 		isKWD, o_member_jy := isKeWord(o_mb)
 		if isKWD {
-			flist, fcount, distinctCount = getNewForecast(main_userId, pageNum, *o_member_jy, pageSize, startTime, endTime, dataType, area)
+			flist, fcount, distinctCount = getNewForecast(main_userId, pageNum, *o_member_jy, pageSize, startTime, endTime, dataType, area, minPrice, maxPrice)
 			if pageNum == 1 {
 				if len(flist) == 0 {
 					if area != "" || startTime != 0 || endTime != 0 {
@@ -546,7 +566,7 @@ func forecastMerge(r, f []map[string]interface{}) []*ForecastInfo {
 
 var d = &dfa.DFA{}
 
-func getNewForecast(userId string, pageNum int, o_member_jy map[string]interface{}, pageSize int, startTime, endTime int, dataType, area string) (list []map[string]interface{}, count, distinctCount int64) {
+func getNewForecast(userId string, pageNum int, o_member_jy map[string]interface{}, pageSize int, startTime, endTime int, dataType, area string, minPrice, maxPrice int) (list []map[string]interface{}, count, distinctCount int64) {
 	if userId == "" {
 		return
 	}
@@ -574,7 +594,7 @@ func getNewForecast(userId string, pageNum int, o_member_jy map[string]interface
 		return
 	}
 	// qstr := GetMemberForecastSql(sql)
-	qstr := getForecastProjectSql(sql, startTime, endTime, dataType)
+	qstr := getForecastProjectSql(sql, startTime, endTime, dataType, minPrice, maxPrice)
 	count = elastic.Count(INDEX, TYPE, qstr)
 	distinctCount = count
 	if int(distinctCount) > config.Config.MsgMaxCount { //超过20000 计算去重后的实际标讯数据
@@ -634,7 +654,7 @@ type DistinctInfoidCount struct {
 	Value int `json:"value"`
 }
 
-func getNewForecastDerive(userId string, o_member_jy map[string]interface{}, startTime, endTime, count int, dataType, area string, selectIds []string) (ids []string, sql *util.ViewCondition) {
+func getNewForecastDerive(userId string, o_member_jy map[string]interface{}, startTime, endTime, count int, dataType, area string, selectIds []string, minPrice, maxPrice int) (ids []string, sql *util.ViewCondition) {
 	if userId == "" {
 		return
 	}
@@ -662,7 +682,7 @@ func getNewForecastDerive(userId string, o_member_jy map[string]interface{}, sta
 		return
 	}
 	// qstr := GetMemberForecastSql(sql)
-	qstr := getForecastProjectSql(sql, startTime, endTime, dataType)
+	qstr := getForecastProjectSql(sql, startTime, endTime, dataType, minPrice, maxPrice)
 	if count > config.Config.MsgMaxCount {
 		count = config.Config.MsgMaxCount
 	}