wangshan 4 luni în urmă
părinte
comite
a21b1a3cf8

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

@@ -1,34 +0,0 @@
-package v1
-
-import "github.com/gogf/gf/v2/frame/g"
-
-type PersonnelInsertReq struct {
-	g.Meta          `path:"/statistics" tags:"contract" method:"post" summary:"insert records"`
-	ActionId        string                 `json:"action_id" dc:"事件ID"`
-	ActionType      string                 `json:"action_type" dc:"事件类型"`
-	BreakerId       string                 `json:"breaker_id" dc:"断点ID"`
-	BreakerName     string                 `json:"breaker_name" dc:"断点名称"`
-	OrderId         string                 `json:"order_id" dc:"订单编号"`
-	OrderTime       string                 `json:"order_time" dc:"下单时间"`
-	PayTime         string                 `json:"pay_time" dc:"支付时间"`
-	PayWay          string                 `json:"pay_way" dc:"支付方式"`
-	Price           int                    `json:"price" dc:"金额(元)"`
-	Product         string                 `json:"product" dc:"产品类型"`
-	ProductName     string                 `json:"product_name" dc:"产品类型名称"`
-	PageId          string                 `json:"page_id" dc:"页面ID"`
-	PageName        string                 `json:"page_name" dc:"页面名称"`
-	BiddingId       string                 `json:"bidding_id" dc:"详情页id"`
-	Desc            string                 `json:"desc" dc:"页面功能简述"`
-	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:"pageRefer" dc:"跳转前页面"`
-	SearchWord      string                 `json:"search_word"  dc:"搜索词" `
-	Filter          string                 `json:"filter"  dc:"搜索条件"`
-	BreakData       map[string]interface{} `json:"breakData"  dc:"额外数据"`
-	AppId           string                 `json:"appId"  dc:"appid"`
-	AppVersion      string                 `json:"appVersion"  dc:"版本号"`
-	MiniProgramCode string                 `json:"miniProgramCode"  dc:"来源"`
-	Duration        int64                  `json:"duration"  dc:"页面停留时长 秒"`
-}

+ 1 - 0
api/personnel/v1/personnel.go

@@ -36,6 +36,7 @@ type Statistics struct {
 	SearchWord      string                 `json:"search_word"  dc:"搜索词" `
 	Filter          string                 `json:"filter"  dc:"搜索条件"`
 	BreakData       map[string]interface{} `json:"breakData"  dc:"额外数据"`
+	BData           string                 `json:"break_data"  dc:"额外数据"` // 字符串
 	AppId           string                 `json:"appId"  dc:"appid"`
 	AppVersion      string                 `json:"appVersion"  dc:"版本号"`
 	MiniProgramCode string                 `json:"miniProgramCode"  dc:"来源"`

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

@@ -5,6 +5,7 @@ import (
 	"app.yhyue.com/moapp/jybase/encrypt"
 	"context"
 	"encoding/json"
+	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	v1 "personnelBehavior/api/personnel/v1"
 	"personnelBehavior/internal/model"
@@ -91,6 +92,12 @@ func (p *personnel) Statistics(ctx context.Context, req *v1.PersonnelInsertReq)
 		breakData, _ := json.Marshal(req.BreakData)
 		in.BreakData = string(breakData)
 	}
+	if req.BData != "" {
+		if in.BreakData != "" {
+			in.BreakData += ","
+		}
+		in.BreakData += fmt.Sprintf("action_name=%s", req.BData)
+	}
 	// 小程序的refer是从body里面取的
 	if in.Refer == "" && req.Refer != "" && req.Refer != "undefined" {
 		in.Refer = req.Refer

+ 2 - 0
internal/dao/internal/personnel.go

@@ -12,6 +12,7 @@ import (
 	. "personnelBehavior/internal/common"
 	"personnelBehavior/internal/consts"
 	"personnelBehavior/internal/model"
+	"personnelBehavior/internal/utils"
 	"strconv"
 	"time"
 )
@@ -133,6 +134,7 @@ func (dao *PersonnelDao) BatchExecInsert(ctx context.Context, in []*model.Person
 	_, err = g.DB().Model(dao.Model()).Data(insertData).Insert()
 	if err != nil {
 		g.Log().Error(ctx, "batch insert false, --err:", err)
+		utils.SendMsgByWXURL(fmt.Sprintf("人员行为统计数据存储异常。\n错误信息:\n%s", err.Error()), g.Config().MustGet(ctx, "webhookURL").Strings())
 		return
 	}
 	return

+ 42 - 0
internal/utils/warn.go

@@ -0,0 +1,42 @@
+package utils
+
+import (
+	"bytes"
+	"encoding/json"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/os/gctx"
+	"net/http"
+)
+
+func SendMsgByWXURL(msg string, whs []string) {
+	for _, url := range whs {
+		if ok := SendBot(url, msg); !ok {
+			g.Log().Info(gctx.New(), "企业微信机器人提醒失败--:", url, msg)
+		}
+	}
+}
+
+func SendBot(webhookURL, msg string) (b bool) {
+	// 构造请求体
+	payload := map[string]interface{}{
+		"msgtype": "text",
+		"text": map[string]string{
+			"content": msg,
+		},
+	}
+	// 转换为 JSON 字符串
+	payloadBytes, err := json.Marshal(payload)
+	if err != nil {
+		g.Log().Info(gctx.New(), "Error :", err.Error())
+		return
+	}
+	// 发送 POST 请求
+	resp, err := http.Post(webhookURL, "application/json", bytes.NewReader(payloadBytes))
+	if err != nil {
+		g.Log().Info(gctx.New(), "Error :", err.Error())
+		return
+	}
+	defer resp.Body.Close()
+	b = true
+	return
+}

+ 1 - 1
manifest/config/config.yaml

@@ -41,6 +41,6 @@ cacheChanInfo:
   timeAfter: 2000   # 定时保存 毫秒
   timeout: 10000    # 缓存通道满时,超时丢弃
   sCSize: 3         # 数据库并发存储数据
-
+webhookURL: ["https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=24b0ac60-3a02-441f-842e-9cd3f75d1208"]