Browse Source

Merge branch 'feature/587-bowen-label-elationship'

* feature/587-bowen-label-elationship:
  fixbug
  增加标签日志页面
  临时提交
boweniac 5 days ago
parent
commit
1cb1010da8

+ 26 - 1
desc/wechat/label_relationship.api

@@ -123,6 +123,8 @@ type (
         // Status 1: normal 2: ban | 状态 1 正常 2 禁用
         Status  *uint8 `json:"status,optional"`
 
+
+
         // 标签 ID
         LabelId  *uint64 `json:"labelId,optional"`
 
@@ -176,12 +178,35 @@ type (
         BaseListInfo
 
         // The API list data | LabelRelationship列表数据
-        Data  []LabelRelationshipInfo  `json:"data"`
+        Data  []ContactInfo  `json:"data"`
     }
 
     // Get label relationship list request params | LabelRelationship列表请求参数
     LabelRelationshipListReq {
         PageInfo
+
+        // 内容类型:1-个微 3-企微
+        Ctype *uint64 `json:"ctype,optional"`
+
+        // 属主微信id
+        WxWxid  *string `json:"wxWxid,optional"`
+
+        // 联系人类型:1好友,2群组,3公众号,4企业微信联系人
+        Type  *int `json:"type,optional"`
+
+        // 微信id 公众号微信ID
+        Wxid  *string `json:"wxid,optional"`
+
+        // 昵称
+        Nickname  *string `json:"nickname,optional"`
+
+        // Label ID list | 标签ID列表
+        LabelIDs []uint64 `json:"labelIDs,optional"`
+
+        //标签搜索开始结束日期
+        SearchDate []*string `json:"date,optional"`
+
+
     }
 
     // LabelRelationship information response | LabelRelationship信息返回体

+ 129 - 6
internal/logic/label_relationship/get_label_relationship_list_logic.go

@@ -2,7 +2,12 @@ package label_relationship
 
 import (
 	"context"
+	"time"
+	"wechat-api/ent"
+	"wechat-api/ent/contact"
+	"wechat-api/ent/label"
 	"wechat-api/ent/labelrelationship"
+	"wechat-api/ent/wx"
 
 	"wechat-api/ent/predicate"
 	"wechat-api/internal/svc"
@@ -31,9 +36,73 @@ func NewGetLabelRelationshipListLogic(ctx context.Context, svcCtx *svc.ServiceCo
 
 func (l *GetLabelRelationshipListLogic) GetLabelRelationshipList(req *types.LabelRelationshipListReq) (*types.LabelRelationshipListResp, error) {
 	organizationId := l.ctx.Value("organizationId").(uint64)
+	var labPreds []predicate.Label
+	labPreds = append(labPreds, label.OrganizationIDEQ(organizationId))
+
 	var predicates []predicate.LabelRelationship
-	predicates = append(predicates, labelrelationship.OrganizationIDEQ(organizationId))
-	data, err := l.svcCtx.DB.LabelRelationship.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
+	layout := "2006-01-02 15:04:05"
+	var startTime, endTime *time.Time
+
+	if req.SearchDate != nil && len(req.SearchDate) == 2 {
+		startStr := *req.SearchDate[0] + " 00:00:00"
+		if t, err := time.Parse(layout, startStr); err == nil {
+			//t = t.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
+			startTime = &t
+		} else {
+			l.Logger.Errorf("invalid startDate: %v", err)
+		}
+		endStr := *req.SearchDate[1] + " 23:59:59"
+		if t, err := time.Parse(layout, endStr); err == nil {
+			//t = t.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
+			endTime = &t
+		} else {
+			l.Logger.Errorf("invalid endDate: %v", err)
+		}
+	}
+
+	if startTime != nil {
+		predicates = append(predicates, labelrelationship.CreatedAtGTE(*startTime))
+	}
+	if endTime != nil {
+		predicates = append(predicates, labelrelationship.CreatedAtLTE(*endTime))
+	}
+
+	if len(req.LabelIDs) > 0 {
+		predicates = append(predicates,
+			labelrelationship.HasLabelsWith(label.IDIn(req.LabelIDs...)),
+		)
+	}
+
+	var conPreds []predicate.Contact
+	if req.Ctype != nil {
+		conPreds = append(conPreds, contact.Ctype(*req.Ctype))
+	} else {
+		conPreds = append(conPreds, contact.Ctype(1)) // 默认 Ctype = 1
+	}
+
+	if req.WxWxid != nil {
+		conPreds = append(conPreds, contact.WxWxidContains(*req.WxWxid))
+	}
+	if req.Wxid != nil {
+		conPreds = append(conPreds, contact.WxidContains(*req.Wxid))
+	}
+
+	if req.Type != nil {
+		conPreds = append(conPreds, contact.TypeEQ(*req.Type))
+	} else {
+		conPreds = append(conPreds, contact.Or(contact.TypeEQ(1), contact.TypeEQ(2)))
+	}
+
+	if req.Nickname != nil {
+		conPreds = append(conPreds, contact.NicknameContains(*req.Nickname))
+	}
+
+	predicates = append(predicates, labelrelationship.HasLabelsWith(labPreds...))
+	if len(conPreds) > 0 {
+		predicates = append(predicates, labelrelationship.HasContactsWith(conPreds...))
+	}
+
+	data, err := l.svcCtx.DB.LabelRelationship.Query().Where(predicates...).WithContacts().WithLabels().Page(l.ctx, req.Page, req.PageSize)
 
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
@@ -43,17 +112,71 @@ func (l *GetLabelRelationshipListLogic) GetLabelRelationshipList(req *types.Labe
 	resp.Msg = errormsg.Success
 	resp.Data.Total = data.PageDetails.Total
 
+	wxWxids := []string{}
+	wxWxidsSet := make(map[string]*ent.Wx)
+	logx.Info("data.List", data.List)
+	for _, v := range data.List {
+		logx.Info("v.Edges.Contacts", v.Edges.Contacts)
+		if v.Edges.Contacts != nil {
+			wxWxids = append(wxWxids, v.Edges.Contacts.WxWxid)
+		}
+	}
+	logx.Info("wxWxids", wxWxids)
+	wxs, err := l.svcCtx.DB.Wx.Query().Where(wx.WxidIn(wxWxids...)).All(l.ctx)
+	for _, w := range wxs {
+		wxWxidsSet[w.Wxid] = w
+	}
+
 	for _, v := range data.List {
+		c := v.Edges.Contacts
+		label := v.Edges.Labels
+		wwx := wxWxidsSet[c.WxWxid]
+		logx.Info("c", c)
+		logx.Info("label", label)
+		logx.Info("wwx", wwx)
+		if c == nil || label == nil || wwx == nil {
+			continue
+		}
+		labelRelationships := make([]types.ContactLabelList, 0)
+		labelRelationships = append(labelRelationships, types.ContactLabelList{
+			Label: &label.Name,
+			Value: &label.ID,
+		})
 		resp.Data.Data = append(resp.Data.Data,
-			types.LabelRelationshipInfo{
+			types.ContactInfo{
 				BaseIDInfo: types.BaseIDInfo{
 					Id:        &v.ID,
 					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
 					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
 				},
-				Status:    &v.Status,
-				LabelId:   &v.LabelID,
-				ContactId: &v.ContactID,
+				Status:             &v.Status,
+				WxWxid:             &c.WxWxid,
+				WxWxidNickname:     &wwx.Nickname,
+				Type:               &c.Type,
+				Wxid:               &c.Wxid,
+				Account:            &c.Account,
+				Nickname:           &c.Nickname,
+				Markname:           &c.Markname,
+				Headimg:            &c.Headimg,
+				Sex:                &c.Sex,
+				Starrole:           &c.Starrole,
+				Dontseeit:          &c.Dontseeit,
+				Dontseeme:          &c.Dontseeme,
+				Lag:                &c.Lag,
+				Gid:                &c.Gid,
+				Gname:              &c.Gname,
+				V3:                 &c.V3,
+				Ctype:              &c.Ctype,
+				Cname:              &c.Cname,
+				Cage:               &c.Cage,
+				Carea:              &c.Carea,
+				Cc:                 &c.Cc,
+				Phone:              &c.Phone,
+				Cbirthday:          &c.Cbirthday,
+				Cbirtharea:         &c.Cbirtharea,
+				CidcardNo:          &c.CidcardNo,
+				Ctitle:             &c.Ctitle,
+				LabelRelationships: labelRelationships,
 			})
 	}
 

+ 15 - 1
internal/types/types.go

@@ -907,13 +907,27 @@ type LabelRelationshipListResp struct {
 type LabelRelationshipListInfo struct {
 	BaseListInfo
 	// The API list data | LabelRelationship列表数据
-	Data []LabelRelationshipInfo `json:"data"`
+	Data []ContactInfo `json:"data"`
 }
 
 // Get label relationship list request params | LabelRelationship列表请求参数
 // swagger:model LabelRelationshipListReq
 type LabelRelationshipListReq struct {
 	PageInfo
+	// 内容类型:1-个微 3-企微
+	Ctype *uint64 `json:"ctype,optional"`
+	// 属主微信id
+	WxWxid *string `json:"wxWxid,optional"`
+	// 联系人类型:1好友,2群组,3公众号,4企业微信联系人
+	Type *int `json:"type,optional"`
+	// 微信id 公众号微信ID
+	Wxid *string `json:"wxid,optional"`
+	// 昵称
+	Nickname *string `json:"nickname,optional"`
+	// Label ID list | 标签ID列表
+	LabelIDs []uint64 `json:"labelIDs,optional"`
+	//标签搜索开始结束日期
+	SearchDate []*string `json:"date,optional"`
 }
 
 // LabelRelationship information response | LabelRelationship信息返回体