Преглед изворни кода

Merge branch 'dev/v1.0.1_fu' of jianyu/personnelBehavior into feature/v1.0.1

fuwencai пре 1 година
родитељ
комит
038196adcf

+ 4 - 0
api/hello/v1/personnel.go

@@ -22,4 +22,8 @@ type PersonnelInsertReq struct {
 	Source      string `json:"source" dc:"来源名称"`
 	Url         string `json:"url" dc:"地址"`
 	ChainName   string `json:"chain_name" v:"required"  dc:"公链名称"`
+	Port        string `json:"port" `
+	Refer       string `json:"refer" dc:"跳转前页面"`
+	SearchWord  string `json:"search_word"  dc:"搜索词" `
+	Filter      string `json:"filter"  dc:"搜索条件"`
 }

+ 5 - 1
internal/common/common.go

@@ -33,7 +33,11 @@ var (
 								desc Nullable(String) DEFAULT NULL COMMENT '页面功能简述',
 								url Nullable(String) DEFAULT NULL COMMENT '页面URL',
 								source Nullable(String) DEFAULT NULL COMMENT '来源名称',
-								user_agent Nullable(String) DEFAULT NULL COMMENT 'header信息'
+								user_agent Nullable(String) DEFAULT NULL COMMENT 'header信息',
+								port Nullable(String) DEFAULT NULL  COMMENT '行为端口 wx,Android,ios,pc,h5',
+								refer  Nullable(String) DEFAULT NULL COMMENT '跳转前页面',
+								search_word  Nullable(String) DEFAULT NULL COMMENT '搜索词',
+								filter  Nullable(String) DEFAULT NULL COMMENT '搜索条件字段'
 							)
 							ENGINE = MergeTree
 							ORDER BY date

+ 5 - 0
internal/controller/personnel/personnel.go

@@ -67,6 +67,11 @@ func (p *personnel) Statistics(ctx context.Context, req *v1.PersonnelInsertReq)
 	in.Platform = userAgent.Platform
 	in.UserAgent = r.UserAgent()
 	in.ChainName = req.ChainName
+	//A24112  新增字段
+	in.Port = utils.GetUserPort(r) // 行为端口 wx,Android,ios,pc,h5
+	in.Refer = req.Refer           // 跳转前页面
+	in.SearchWord = req.SearchWord // 搜索词
+	in.Filter = req.Filter         // 搜索条件
 	err = service.Personnel().BatchInsertRecords(ctx, &in)
 	if err != nil {
 		res.Msg = err.Error()

+ 13 - 1
internal/dao/internal/personnel.go

@@ -116,6 +116,10 @@ func (dao *PersonnelDao) BatchExecInsert(ctx context.Context, in []*model.Person
 			"url":             i.Url,
 			"source":          i.Source,
 			"user_agent":      i.UserAgent,
+			"port":            i.Port,
+			"refer":           i.Refer,
+			"search_word":     i.SearchWord,
+			"filter":          i.Filter,
 		})
 	}
 	_, err = g.DB().Model(dao.Model()).Data(insertData).Insert()
@@ -137,7 +141,7 @@ func (dao *PersonnelDao) ExecInsert(ctx context.Context, in model.PersonnelInser
 	dimSqlDML.WriteString(" (jy_trusted_id,user_id,position_id,phone,ip,platform,os,os_version,browser," +
 		"browser_version,date,action_id,action_type,breaker_id,breaker_name,click_time,order_id," +
 		"order_time,pay_time,pay_way,price,product,product_name,page_id,page_name,bidding_id,desc," +
-		"url,source,user_agent) values ( ")
+		"url,source,user_agent,port,refer,search_word,filter) values ( ")
 	dimSqlDML.WriteString("'" + in.JYTrustedId + "'")
 	dimSqlDML.WriteString(",")
 	dimSqlDML.WriteString("'" + in.UserId + "'")
@@ -197,6 +201,14 @@ func (dao *PersonnelDao) ExecInsert(ctx context.Context, in model.PersonnelInser
 	dimSqlDML.WriteString("'" + in.Source + "'")
 	dimSqlDML.WriteString(",")
 	dimSqlDML.WriteString("'" + in.UserAgent + "'")
+	dimSqlDML.WriteString(",")
+	dimSqlDML.WriteString("'" + in.Port + "'")
+	dimSqlDML.WriteString(",")
+	dimSqlDML.WriteString("'" + in.Refer + "'")
+	dimSqlDML.WriteString(",")
+	dimSqlDML.WriteString("'" + in.SearchWord + "'")
+	dimSqlDML.WriteString(",")
+	dimSqlDML.WriteString("'" + in.Filter + "'")
 	dimSqlDML.WriteString(")")
 	_, err = g.DB().Exec(ctx, dimSqlDML.String())
 	if err != nil {

+ 4 - 0
internal/model/personnel.go

@@ -31,4 +31,8 @@ type PersonnelInsertInput struct {
 	UserAgent      string //header 信息
 	JYTrustedId    string //匿名用户id
 	ChainName      string //库信息
+	Port           string //行为端口
+	Refer          string //跳转前页面
+	SearchWord     string //搜索词
+	Filter         string //搜索条件
 }

+ 28 - 0
internal/utils/utils.go

@@ -7,6 +7,7 @@ import (
 	"net/http"
 	"net/url"
 	"personnelBehavior/internal/consts"
+	"regexp"
 	"strings"
 	"time"
 )
@@ -84,3 +85,30 @@ func GetDetailPageId(href string) (id, source string) {
 	}
 	return
 }
+
+// GetUserPort 获取用户行为端口
+func GetUserPort(r *http.Request) string {
+	var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
+	if mobileReg.MatchString(r.UserAgent()) {
+		if strings.Index(strings.ToLower(r.UserAgent()), "micromessenger") > -1 {
+			return "wx"
+		}
+		if strings.Contains(r.Host, "h5") {
+			return "h5"
+		}
+		return isAndroidOrIOS(r.UserAgent())
+	} else {
+		return "pc"
+	}
+}
+func isAndroidOrIOS(s string) string {
+	typ := ""
+	if strings.Contains(s, "Android") {
+		typ = "Android"
+	} else if strings.Contains(s, "iPhone") || strings.Contains(s, "iPad") {
+		typ = "IOS"
+	} else {
+		typ = "other"
+	}
+	return typ
+}

+ 11 - 0
test.http

@@ -0,0 +1,11 @@
+POST http://127.0.0.1:7072/personnel/statistics
+Content-Type: application/json
+Apikey: HhYvHgAGQV9fWxEDLw8HFw==
+
+{ "filter": "11",
+  "chain_name": "data_analysis",
+  "refer": "test",
+  "search_word": "search_value"
+}
+
+###