Pārlūkot izejas kodu

feat:未登录搜索页面限制

duxin 2 gadi atpakaļ
vecāks
revīzija
62befca49d

+ 46 - 0
jyBXCore/rpc/etc/bxcore.yaml

@@ -42,3 +42,49 @@ DefaultTopTypes:
   - 拟建,采购意向
 JYKeyMark: " "
 ContextOldVipLimit: 1664553600
+DetailMosaicTxt: 略
+NeedMosaic:
+  Projectname: true
+  Projectcode: true
+  Budget: true
+  Bidamount: true
+  Buyer: true
+  Buyerperson: true
+  Buyertel: true
+  Buyeraddr: true
+  Agency: true
+  Agencyperson: true
+  Agencytel: true
+  Agencyaddr: true
+  Winner: true
+  S_winner: true
+  Winnerperson: true
+  Winnertel: true
+  Winneraddr: true
+  Docstarttime: true
+  Docendtime: true
+  Bidendtime: true
+  Bidstarttime: true
+  Bidopentime: true
+  Bidopenaddress: true
+  Contractcode: true
+  Signaturedate: true
+  Purchasinglist: true
+  Item: true
+  Purchasing: true
+  Itemname: true
+  Brandname: true
+  Specs: true
+  Model: true
+  Unitname: true
+  Dimensions: true
+  Number: true
+  Unitprice: true
+  Totalprice: true
+  Guaranteetime: true
+  Orderno: true
+  Procurementlist: true
+  Projectscope: true
+  Reserved_amount: true
+  Expurasingtime: true
+  WinnerMap: true

+ 48 - 0
jyBXCore/rpc/internal/config/config.go

@@ -44,6 +44,54 @@ type Config struct {
 	DefaultTopTypes    []string //信息类型初始值
 	JYKeyMark          string   //关键词分组标识
 	ContextOldVipLimit int64    //老版超级订阅 超前项目权限
+
+	DetailMosaicTxt string
+	NeedMosaic      struct {
+		Projectname     bool
+		Projectcode     bool
+		Budget          bool
+		Bidamount       bool
+		Buyer           bool
+		Buyerperson     bool
+		Buyertel        bool
+		Buyeraddr       bool
+		Agency          bool
+		Agencyperson    bool
+		Agencytel       bool
+		Agencyaddr      bool
+		Winner          bool
+		S_winner        bool
+		Winnerperson    bool
+		Winnertel       bool
+		Winneraddr      bool
+		Docstarttime    bool
+		Docendtime      bool
+		Bidendtime      bool
+		Bidstarttime    bool
+		Bidopentime     bool
+		Bidopenaddress  bool
+		Contractcode    bool
+		Signaturedate   bool
+		Purchasinglist  bool
+		Item            bool
+		Purchasing      bool
+		Itemname        bool
+		Brandname       bool
+		Specs           bool
+		Model           bool
+		Unitname        bool
+		Dimensions      bool
+		Number          bool
+		Unitprice       bool
+		Totalprice      bool
+		Guaranteetime   bool
+		Orderno         bool
+		Procurementlist bool
+		Projectscope    bool
+		Reserved_amount bool
+		Expurasingtime  bool
+		WinnerMap       bool
+	}
 }
 
 type Db struct {

+ 1 - 1
jyBXCore/rpc/service/search.go

@@ -43,7 +43,7 @@ func GetBidSearchData(in *bxcore.SearchReq, isCache bool) (count int64, list []*
 		count, repl = biddingSearch.GetAllByNgramWithCount()
 		if repl != nil && *repl != nil && len(*repl) > 0 {
 			//格式化查询结果
-			list = util.SearchListFormat(in.Industry, repl, strings.Contains(in.SelectType, "detail"))
+			list = util.SearchListFormat(in.UserId, in.Industry, repl, strings.Contains(in.SelectType, "detail"))
 		} else {
 			logx.Info("查询数据异常")
 		}

+ 92 - 1
jyBXCore/rpc/util/search.go

@@ -3,8 +3,10 @@ package util
 import (
 	MC "app.yhyue.com/moapp/jybase/common"
 	ME "app.yhyue.com/moapp/jybase/encrypt"
+	"app.yhyue.com/moapp/jybase/fsw"
 	"crypto/rand"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"github.com/zeromicro/go-zero/core/logx"
 	"io/ioutil"
@@ -14,6 +16,7 @@ import (
 	"math/big"
 	"net/http"
 	"net/url"
+	"reflect"
 	"regexp"
 	"strconv"
 	"strings"
@@ -241,7 +244,7 @@ func IndustryFormat(industry, subScopeClass string) (newIndustry string) {
 }
 
 // SearchListFormat  格式化数据
-func SearchListFormat(industry string, repl *[]map[string]interface{}, b bool) (list []*bxcore.SearchList) {
+func SearchListFormat(userid, industry string, repl *[]map[string]interface{}, b bool) (list []*bxcore.SearchList) {
 	for _, v := range *repl {
 		var searchList = &bxcore.SearchList{}
 		//正文
@@ -254,6 +257,9 @@ func SearchListFormat(industry string, repl *[]map[string]interface{}, b bool) (
 			}
 			searchList.Detail = detail
 		}
+		if userid == "" {
+			v = Filter(v)
+		}
 		searchList.Id = ME.EncodeArticleId2ByCheck(MC.ObjToString(v["_id"]))                                    //ME.EncodeArticleId2ByCheck(MC.ObjToString(v["_id"]))                                         //加密信息id
 		searchList.Area = MC.ObjToString(v["area"])                                                             //地区
 		searchList.AreaUrl = IC.LabelMap[searchList.Area].Url                                                   //地区分类链接
@@ -359,3 +365,88 @@ func GetPublishTime(y, m int, publishTime string) string {
 	}
 	return ""
 }
+
+// 未登录用户进行数据过滤
+func Filter(obj map[string]interface{}) map[string]interface{} {
+	detail := fmt.Sprint(obj["detail"])
+	mosaicText := IC.C.DetailMosaicTxt
+	for k, _ := range obj {
+		needMosaic := MC.StructToMapMore(IC.C.NeedMosaic)
+		if ok, _ := needMosaic[k].(bool); ok {
+			if MC.ObjToString(obj[k]) != "" {
+				detail = strings.ReplaceAll(detail, MC.ObjToString(obj[k]), mosaicText)
+				//敏感词过滤
+			}
+			if k == "winnerMap" {
+				winnerMap, _ := obj[k].(map[string]interface{})
+				mosaicMap := map[string]interface{}{}
+				for i := 0; i < len(winnerMap); i++ {
+					mosaicMap[mosaicText] = mosaicText
+				}
+				obj["winnerMap"] = mosaicMap
+			} else {
+				obj[k] = mosaicText
+			}
+		}
+	}
+	//数字打码
+	detail = RegDetail(detail)
+	detail = fsw.Repl(detail)
+	obj["detail"] = detail
+	return obj
+}
+
+// 分段匹配数字打码
+func RegDetail(html string) string {
+	mosaicText := IC.C.DetailMosaicTxt
+	reg := regexp.MustCompile("<[^<>]{1,1000}>") //分段正则
+	s := reg.FindAllStringIndex(html, -1)        //全文匹配分段
+	if len(s) > 0 {                              //走分段替换
+		arr := []string{}
+		index := 0
+		for _, v := range s {
+			if len(v) == 2 {
+				// log.Println(html[index:v[0]])
+				txt, _ := ReplaceStringByRegex(html[index:v[0]], "[0-9]+", mosaicText)
+				arr = append(arr, txt) //替换
+				arr = append(arr, html[v[0]:v[1]])
+				index = v[1]
+			}
+		}
+		return strings.Join(arr, "")
+	}
+	return ""
+}
+
+func ReplaceStringByRegex(str, rule, replace string) (string, error) {
+	reg, err := regexp.Compile(rule)
+	if reg == nil || err != nil {
+		return "", errors.New("正则MustCompile错误:" + err.Error())
+	}
+	return reg.ReplaceAllString(str, replace), nil
+}
+
+func Bind(data interface{}, ret interface{}) error {
+	v := reflect.ValueOf(ret)
+	if v.Kind() != reflect.Ptr {
+		return fmt.Errorf("ptr input ret needed as type as input type %s", v.Kind())
+	}
+	havdata := false
+	var bk interface{}
+	if v.Elem().Kind() == reflect.Slice {
+		t := reflect.Zero(reflect.TypeOf(v.Elem().Interface()))
+		bk = v.Elem().Interface()
+		v.Elem().Set(t)
+		havdata = true
+	}
+	_data, _ := json.MarshalIndent(data, "", "    ")
+	err := json.Unmarshal(_data, ret)
+	if err != nil {
+		fmt.Println(err)
+		if havdata {
+			v.Elem().Set(reflect.ValueOf(bk))
+		}
+		return err
+	}
+	return nil
+}