浏览代码

临时暂存

boweniac 2 天之前
父节点
当前提交
659db53c8c

+ 1 - 1
crontask/contact_form.go

@@ -24,5 +24,5 @@ type FormData struct {
 }
 
 func (l *CronTask) analyze() {
-	wechat.NewAnalyzeContactField(l.ctx, l.svcCtx).Analyze()
+	wechat.NewAnalyzeContactField(l.ctx, l.svcCtx).Analyze(nil, nil)
 }

+ 14 - 0
desc/wechat/contact.api

@@ -129,6 +129,16 @@ type (
 		CidcardNo *string `json:"cidcardNo,optional"`
 		Ctitle *string `json:"ctitle,optional"`
 	}
+
+	AnalyzeContactFieldReq {
+		WxWxid  *string `json:"wxWxid,optional"`
+
+        Wxid  *string `json:"wxid,optional"`
+	}
+
+	AnalyzeContactFieldResp {
+	    CustomFields []ContactFieldTemplate `json:"customFields,optional"`
+	}
 )
 
 @server(
@@ -191,4 +201,8 @@ service Wechat {
 	// Whatsapp联系人详情
 	@handler getWhatsappContact
 	post /contact/getWhatsappContact (IDReq) returns (ContactInfoResp)
+
+	// 分析联系人自定义字段
+    @handler analyzeContactField
+    post /contact/analyzeContactField (AnalyzeContactFieldReq) returns (BaseMsgResp)
 }

+ 44 - 0
internal/handler/contact/analyze_contact_field_handler.go

@@ -0,0 +1,44 @@
+package contact
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/contact"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /contact/analyzeContactField contact AnalyzeContactField
+//
+// 分析联系人自定义字段
+//
+// 分析联系人自定义字段
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: AnalyzeContactFieldReq
+//
+// Responses:
+//  200: AnalyzeContactFieldResp
+
+func AnalyzeContactFieldHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.AnalyzeContactFieldReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := contact.NewAnalyzeContactFieldLogic(r.Context(), svcCtx)
+		resp, err := l.AnalyzeContactField(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 5 - 0
internal/handler/routes.go

@@ -448,6 +448,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 					Path:    "/contact/getWhatsappContact",
 					Handler: contact.GetWhatsappContactHandler(serverCtx),
 				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/contact/analyzeContactField",
+					Handler: contact.AnalyzeContactFieldHandler(serverCtx),
+				},
 			}...,
 		),
 		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),

+ 31 - 0
internal/logic/contact/analyze_contact_field_logic.go

@@ -0,0 +1,31 @@
+package contact
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/internal/service/wechat"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type AnalyzeContactFieldLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewAnalyzeContactFieldLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AnalyzeContactFieldLogic {
+	return &AnalyzeContactFieldLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *AnalyzeContactFieldLogic) AnalyzeContactField(req *types.AnalyzeContactFieldReq) (resp *types.BaseMsgResp, err error) {
+	wechat.NewAnalyzeContactField(l.ctx, l.svcCtx).Analyze(req.WxWxid, req.Wxid)
+
+	return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
+}

+ 5 - 1
internal/service/wechat/analyze_contact_field.go

@@ -53,7 +53,7 @@ func NewAnalyzeContactField(ctx context.Context, svcCtx *svc.ServiceContext) *An
 	}
 }
 
-func (l *AnalyzeContactField) Analyze() {
+func (l *AnalyzeContactField) Analyze(bot_wxid *string, contact_wxid *string) {
 	usageDetails := make(map[string]map[string]string)
 	contactFieldTemplates := make(map[string][]custom_types.ContactFieldTemplate)
 	template_type_text := "text"
@@ -151,6 +151,10 @@ func (l *AnalyzeContactField) Analyze() {
 	yesterdayStart := yesterdayEnd.AddDate(0, 0, -2)
 	predicates = append(predicates, usagedetail.CreatedAtGTE(yesterdayStart))
 	predicates = append(predicates, usagedetail.CreatedAtLT(yesterdayEnd))
+	if bot_wxid != nil && *bot_wxid != "" && contact_wxid != nil && *contact_wxid != "" {
+		predicates = append(predicates, usagedetail.BotIDEQ(*bot_wxid))
+		predicates = append(predicates, usagedetail.ReceiverIDEQ(*contact_wxid))
+	}
 
 	//todayStart := time.Now().AddDate(0, 0, 0).Truncate(24 * time.Hour)
 	//todayEnd := todayStart.Add(24 * time.Hour)

+ 11 - 0
internal/types/types.go

@@ -1156,6 +1156,17 @@ type CreateWhatsappContactReq struct {
 	Ctitle     *string `json:"ctitle,optional"`
 }
 
+// swagger:model AnalyzeContactFieldReq
+type AnalyzeContactFieldReq struct {
+	WxWxid *string `json:"wxWxid,optional"`
+	Wxid   *string `json:"wxid,optional"`
+}
+
+// swagger:model AnalyzeContactFieldResp
+type AnalyzeContactFieldResp struct {
+	CustomFields []ContactFieldTemplate `json:"customFields,optional"`
+}
+
 // The response data of message information | Message信息
 // swagger:model MessageInfo
 type MessageInfo struct {