Browse Source

1. 刷新联系人时,发送工作手机群组刷新sw请求
2. 修复sop逻辑相关bug

boweniac 4 months ago
parent
commit
77ea41bf85

+ 2 - 3
crontask/send_wx_on_timeout.go

@@ -90,9 +90,8 @@ func (l *CronTask) sendWxOnTimeout() {
 			latest, _ := l.svcCtx.DB.MessageRecords.Query().
 				Where(messagerecords.ContactIDEQ(s.ContactID)).
 				Where(messagerecords.StatusEQ(3)).
-				Order(ent.Desc(messagerecords.FieldCreatedAt)).
+				Order(ent.Desc(messagerecords.FieldID)).
 				First(ctx)
-
 			if latest.ID == s.ID {
 				// 创建 MessageRecords 记录
 				if node.ActionMessage != nil {
@@ -250,7 +249,7 @@ func (l *CronTask) AddLabelRelationships(sopStages map[uint64]*ent.SopStage, con
 		// 遍历 delLabelIds,找出在 currentLabelIds 中的元素
 		for _, id := range delLabelIds {
 			if _, exists := currentLabelIdSet[id]; exists {
-				remLabelIds = append(newLabelIds, id)
+				remLabelIds = append(remLabelIds, id)
 				delete(currentLabelIdSet, id)
 			}
 		}

+ 34 - 0
hook/contact.go

@@ -89,6 +89,7 @@ func (h *Hook) RequestChatRoomInfo(ChatRoomId, wxWxid string) error {
 		"MsgType": "RequestChatRoomInfoTask",
 		"Content": map[string]interface{}{
 			"WeChatId":   wxWxid,
+			"Flag":       1,
 			"ChatRoomId": ChatRoomId,
 		},
 	}
@@ -104,3 +105,36 @@ func (h *Hook) RequestChatRoomInfo(ChatRoomId, wxWxid string) error {
 
 	return nil
 }
+
+func (h *Hook) TriggerChatroomPush(wxWxid string) error {
+	conn, err := h.connWorkPhone()
+	if err != nil {
+		err = fmt.Errorf("TriggerChatroomPush failed")
+		return err
+	}
+	defer func(conn *websocket.Conn) {
+		err = conn.Close()
+		if err != nil {
+			err = fmt.Errorf("TriggerChatroomPush failed")
+		}
+	}(conn)
+
+	message := map[string]interface{}{
+		"MsgType": "TriggerChatroomPushTask",
+		"Content": map[string]interface{}{
+			"WeChatId": wxWxid,
+			"Flag":     1,
+		},
+	}
+	transportMessageJSON, err := json.Marshal(message)
+	if err != nil {
+		return err
+	}
+	// 发送 JSON 消息
+	err = conn.WriteMessage(websocket.TextMessage, transportMessageJSON)
+	if err != nil {
+		return fmt.Errorf("failed to send message: %v", err)
+	}
+
+	return nil
+}

+ 0 - 4
internal/logic/User/get_user_info_logic.go

@@ -25,16 +25,12 @@ func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUs
 }
 
 func (l *GetUserInfoLogic) GetUserInfo() (resp *types.UserBaseIDInfoResp, err error) {
-	l.Logger.Errorf("------------------------GetUserInfo---------------------------")
-	l.Logger.Errorf("------------------------userId--------------------------- %+v", l.ctx.Value("userId").(string))
 	user, err := l.svcCtx.CoreRpc.GetUserById(l.ctx,
 		&core.UUIDReq{Id: l.ctx.Value("userId").(string)})
 	if err != nil {
 		return nil, err
 	}
-	l.Logger.Errorf("------------------------user--------------------------- %+v", user)
 	departmentInfo, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: user.GetDepartmentId()})
-	l.Logger.Errorf("------------------------departmentInfo--------------------------- %+v", departmentInfo)
 	if err != nil {
 		return nil, err
 	}

+ 0 - 2
internal/logic/Wx/update_block_and_allow_list_logic.go

@@ -2,7 +2,6 @@ package Wx
 
 import (
 	"context"
-	"fmt"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"wechat-api/ent/wx"
 	"wechat-api/internal/utils/dberrorhandler"
@@ -47,7 +46,6 @@ func (l *UpdateBlockAndAllowListLogic) UpdateBlockAndAllowList(req *types.Update
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
-	fmt.Printf("------------------------wxinfo.Wxid------------------------: %+v\n", wxinfo.Wxid)
 	l.svcCtx.Rds.HDel(l.ctx, "wx_info", wxinfo.Wxid)
 	return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
 }

+ 1 - 0
internal/logic/Wxhook/get_friends_and_groups_logic.go

@@ -210,6 +210,7 @@ func (l *GetFriendsAndGroupsLogic) GetFriendsAndGroups(req *types.IDReq) (resp *
 			l.Error("GetWechatFriendList 请求失败", err)
 			return nil, err
 		}
+		_ = hookClient.TriggerChatroomPush(wxInfo.Wxid)
 		for _, friend := range result.Data {
 			friendType := 1
 			if friend.Type == 1 {

+ 0 - 2
internal/logic/label/get_label_batch_select_list_logic.go

@@ -2,7 +2,6 @@ package label
 
 import (
 	"context"
-	"fmt"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"wechat-api/ent/label"
 	"wechat-api/ent/predicate"
@@ -29,7 +28,6 @@ func NewGetLabelBatchSelectListLogic(ctx context.Context, svcCtx *svc.ServiceCon
 
 func (l *GetLabelBatchSelectListLogic) GetLabelBatchSelectList(req *types.LabelListReq) (resp *types.LabelBatchSelectListResp, err error) {
 	organizationId := l.ctx.Value("organizationId").(uint64)
-	fmt.Printf("------------------------organizationId------------------------: %+v\n", organizationId)
 	var predicates []predicate.Label
 	predicates = append(predicates, label.OrganizationIDEQ(organizationId))
 	if req.Name != nil {

+ 6 - 3
internal/logic/label_relationship/update_label_relationships_logic.go

@@ -59,6 +59,7 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
 	// 如果 req.UpdateType 为空,或 req.UpdateType 的值为 “all” 时
 	if req.UpdateType == nil || *req.UpdateType == "all" {
 		// 删除需要移除的标签关系
+		l.Logger.Errorf("------------------------removeLabelIds--------------------------- %+v\n", removeLabelIds)
 		for _, id := range removeLabelIds {
 			_, err := tx.LabelRelationship.
 				Delete().
@@ -75,6 +76,7 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
 	}
 
 	// 创建需要新增的标签关系
+	l.Logger.Errorf("------------------------addLabelIds--------------------------- %+v\n", addLabelIds)
 	for _, id := range addLabelIds {
 		_, _ = tx.LabelRelationship.Create().
 			SetLabelID(id).
@@ -259,13 +261,14 @@ func (l *UpdateLabelRelationshipsLogic) AddLabelRelationships(sopStages map[uint
 					// 遍历 delLabelIds,找出在 currentLabelIds 中的元素
 					for _, id := range stage.ActionLabelDel {
 						if _, exists := currentLabelIdSet[id]; exists {
-							remLabelIds = append(newLabelIds, id)
+							remLabelIds = append(remLabelIds, id)
 							delete(currentLabelIdSet, id)
 						}
 					}
-
+					l.Logger.Errorf("------------------------stage.ActionLabelDel--------------------------- %+v\n", stage.ActionLabelDel)
+					l.Logger.Errorf("------------------------remLabelIds--------------------------- %+v\n", stage.ActionLabelDel)
 					if len(remLabelIds) > 0 {
-						_, err = tx.LabelRelationship.Delete().Where(labelrelationship.IDIn(remLabelIds...), labelrelationship.ContactIDEQ(contact.ID), labelrelationship.OrganizationIDEQ(organizationId)).Exec(l.ctx)
+						_, err = tx.LabelRelationship.Delete().Where(labelrelationship.LabelIDIn(remLabelIds...), labelrelationship.ContactIDEQ(contact.ID), labelrelationship.OrganizationIDEQ(organizationId)).Exec(l.ctx)
 						if err != nil {
 							//_ = tx.Rollback()
 							return dberrorhandler.DefaultEntError(l.Logger, err, nil)

+ 3 - 4
internal/logic/sop_task/publish_sop_task_logic.go

@@ -238,8 +238,7 @@ func (l *PublishSopTaskLogic) AddLabelRelationships(sopStages map[uint64]*ent.So
 	for _, id := range delLabelIds {
 		delLabelIdSet[id] = struct{}{}
 	}
-
-	if addLabelIds != nil {
+	if addLabelIds != nil && len(addLabelIds) > 0 {
 		// 遍历 addLabelIds,找出不在 currentLabelIds 中的元素
 		for _, id := range addLabelIds {
 			if _, ce := currentLabelIdSet[id]; !ce {
@@ -269,11 +268,11 @@ func (l *PublishSopTaskLogic) AddLabelRelationships(sopStages map[uint64]*ent.So
 		}
 	}
 
-	if delLabelIds != nil {
+	if delLabelIds != nil && len(delLabelIds) > 0 {
 		// 遍历 delLabelIds,找出在 currentLabelIds 中的元素
 		for _, id := range delLabelIds {
 			if _, exists := currentLabelIdSet[id]; exists {
-				remLabelIds = append(newLabelIds, id)
+				remLabelIds = append(remLabelIds, id)
 				delete(currentLabelIdSet, id)
 			}
 		}

+ 0 - 4
internal/logic/token/update_token_logic.go

@@ -45,12 +45,9 @@ func (l *UpdateTokenLogic) UpdateToken(req *types.TokenInfo) (*types.BaseMsgResp
 		}
 		expireAt = &expireAtdata
 	}
-	l.Logger.Errorf("------------------------item--------------------------- %+v", expireAt)
 
 	if req.Token != nil {
 		item, err := l.svcCtx.DB.Token.Query().Where(token.IDNEQ(*req.Id)).Where(token.TokenEQ(*req.Token)).First(l.ctx)
-		l.Logger.Errorf("------------------------err--------------------------- %+v", err)
-		l.Logger.Errorf("------------------------item--------------------------- %+v", item)
 		if err != nil && !ent.IsNotFound(err) {
 			return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 		}
@@ -58,7 +55,6 @@ func (l *UpdateTokenLogic) UpdateToken(req *types.TokenInfo) (*types.BaseMsgResp
 			return nil, errorx.NewCodeInvalidArgumentError("Token已经存在")
 		}
 	}
-	l.Logger.Errorf("------------------------item2--------------------------- %+v")
 	err = l.svcCtx.DB.Token.UpdateOneID(*req.Id).
 		SetNotNilExpireAt(expireAt).
 		SetNotNilToken(req.Token).