Explorar o código

fix:关键词格式化

duxin %!s(int64=2) %!d(string=hai) anos
pai
achega
8dc78301d2
Modificáronse 2 ficheiros con 85 adicións e 0 borrados
  1. 82 0
      common/advancedProject.go
  2. 3 0
      common/customizedAnalysis.go

+ 82 - 0
common/advancedProject.go

@@ -1,15 +1,24 @@
 package common
 
 import (
+	qutil "app.yhyue.com/moapp/jybase/common"
 	"encoding/json"
 	"fmt"
+	"leadGeneration/public"
 	"leadGeneration/util"
 	"log"
+	"regexp"
+	"strings"
+	"time"
 )
 
 func (mae *MarketAnalysisEntity) AdvancedProject() map[string]interface{} {
 	finalSql := fmt.Sprintf(mae.GetCommonQuerySqlWithAggs(), projectsNumber, mae.Size, projectsSort)
 	log.Println("定制化分析报告sql查询:", finalSql)
+	mae.Types = 2
+	mae.FormatParam.SubType = []string{"拟建", "采购意向"}
+	mae.Size = 2
+	mae.FormatParam.STime = time.Now().AddDate(0, -3, 0).Unix()
 	res, _, data := util.GetAggs("bidding", "bidding", finalSql)
 	if res == nil || len(res) == 0 || data == nil || len(data) == 0 {
 		return nil
@@ -28,13 +37,86 @@ func (mae *MarketAnalysisEntity) AdvancedProject() map[string]interface{} {
 	}
 	redisData := make(map[string]interface{})
 	for _, v := range thisRow.ProjectsNumber.Buckets {
+		if v.DocCount == 0 {
+			continue
+		}
 		redisData[v.Key] = v.DocCount
 	}
+	if len(redisData) == 0 {
+		return nil
+	}
 	resData := make([]map[string]interface{}, len(data))
 	for i, v := range data {
 		if json.Unmarshal(*v.Source, &resData[i]) != nil {
 			continue
 		}
 	}
+	log.Println("AdvancedProject redis data :", resData)
 	return nil
 }
+
+func KeyWordFormat(userid, keyWords string) string {
+	var (
+		arryMap []map[string]interface{}
+		key     string
+	)
+	if keyWords != "" {
+		var aItems []map[string]interface{}
+		for _, v := range strings.Split(keyWords, ",") {
+			arryMap = append(arryMap, map[string]interface{}{"from": 1, "appendkey": nil, "key": processKeyword(v), "notkey": nil, "updatetime": time.Now().Unix()})
+		}
+		item := map[string]interface{}{
+			"a_key":      arryMap,
+			"s_item":     "未分类",
+			"updatetime": time.Now().Unix(),
+		}
+		aItems = append(aItems, item)
+		dataType, _ := json.Marshal(aItems)
+		key = string(dataType)
+	} else {
+		data, ok := public.MQFW.FindById("user", userid, `{"o_jy":1,"o_vipjy":1,"o_member_jy":1,"i_vip_status":1,"i_member_status":1,"s_phone":1,"s_m_phone":1}`)
+		if ok && data != nil && len(*data) > 0 {
+			oJy, _ := (*data)["o_jy"].(map[string]interface{})             //免费用户关键词
+			vipJy, _ := (*data)["o_vipjy"].(map[string]interface{})        //超级订阅关键词
+			memberJy, _ := (*data)["o_member_jy"].(map[string]interface{}) //大会员关键词
+			var aItems []interface{}
+			if qutil.IntAll((*data)["i_member_status"]) > 0 {
+				aItems, _ = memberJy["a_items"].([]interface{})
+			} else if qutil.IntAll((*data)["i_vip_status"]) > 0 {
+				aItems, _ = vipJy["a_items"].([]interface{})
+			} else {
+				if oJy["a_key"] != nil && len(oJy["a_key"].([]interface{})) > 0 {
+					a_key, _ := oJy["a_key"].([]interface{})
+					for _, v := range a_key {
+						v1, _ := v.(map[string]interface{})
+						arryMap = append(arryMap, map[string]interface{}{"from": 1, "appendkey": nil, "key": processKeyword(qutil.InterfaceToStr(v1["key"])), "notkey": nil, "updatetime": time.Now().Unix()})
+					}
+					item := map[string]interface{}{
+						"a_key":      arryMap,
+						"s_item":     "未分类",
+						"updatetime": time.Now().Unix(),
+					}
+					aItems = append(aItems, item)
+				}
+			}
+			if len(aItems) > 0 {
+				dataType, _ := json.Marshal(aItems)
+				key = string(dataType)
+			}
+		}
+	}
+	return key
+}
+
+// 处理订阅的关键词
+func processKeyword(keyword string) []string {
+	keywordReg := regexp.MustCompile("([\\s\u3000\u2003\u00a0+,,])+")
+	spaceReg := regexp.MustCompile("\\s+")
+	keyword = keywordReg.ReplaceAllString(keyword, " ")
+	keyword = spaceReg.ReplaceAllString(keyword, " ")
+	keyword = strings.Trim(keyword, " ")
+	if keyword == "" {
+		return nil
+	}
+	return strings.Split(keyword, " ")
+}

+ 3 - 0
common/customizedAnalysis.go

@@ -6,6 +6,7 @@ import (
 	"leadGeneration/util"
 	"log"
 	"strings"
+	"time"
 )
 
 var Analysis = []string{"<10万", "10万-50万", "50万-100万", "100万-500万", "500万-1000万", "1000万-1亿", "≥1亿"}
@@ -13,6 +14,8 @@ var Analysis = []string{"<10万", "10万-50万", "50万-100万", "100万-500万"
 func (mae *MarketAnalysisEntity) PotentialCustomizeAnalysis() map[string]interface{} {
 	var aggs []string
 	aggs = append(aggs, aggs_buyerclass, buyer_procurement_scale, winner_procurement_scale)
+	mae.Types = 1
+	mae.FormatParam.STime = time.Now().AddDate(-1, 0, 0).Unix()
 	finalSql := fmt.Sprintf(mae.GetCommonQuerySqlWithAggs(), strings.Join(aggs, ","), mae.Size, "")
 	log.Println("定制化分析报告sql查询:", finalSql)
 	res, _, _ := util.GetAggs("projectset", "projectset", finalSql)