소스 검색

修复打标因sop造成死循环问题

boweniac 4 달 전
부모
커밋
30458a8609

+ 3 - 0
desc/wechat/agent.api

@@ -56,6 +56,9 @@ type (
 
 		// status | 状态 1-可用 2-不可用
 		Status  *int `json:"status,optional"`
+
+		// 租户id
+        OrganizationId  *uint64 `json:"organizationId,optional"`
     }
 
     // Agent information response | Agent信息返回体

+ 11 - 2
internal/logic/agent/get_agent_list_logic.go

@@ -30,9 +30,18 @@ func NewGetAgentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetA
 }
 
 func (l *GetAgentListLogic) GetAgentList(req *types.AgentListReq) (*types.AgentListResp, error) {
-	organizationId := l.ctx.Value("organizationId").(uint64)
+	orgId := l.ctx.Value("organizationId").(uint64)
 	var predicates []predicate.Agent
-	predicates = append(predicates, agent.OrganizationID(organizationId))
+	if req.OrganizationId != nil && *req.OrganizationId != 0 {
+		isAdmin := l.ctx.Value("isAdmin").(bool)
+		if isAdmin {
+			predicates = append(predicates, agent.OrganizationIDEQ(*req.OrganizationId))
+		} else {
+			predicates = append(predicates, agent.OrganizationIDEQ(orgId))
+		}
+	} else {
+		predicates = append(predicates, agent.OrganizationID(orgId))
+	}
 	if req.Name != nil {
 		predicates = append(predicates, agent.NameContains(*req.Name))
 	}

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

@@ -104,21 +104,24 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
 	}
 
 	// 获取所有 filteredSopTasks 的 sop_stages
-	var sopStages []*ent.SopStage
+	stageMap := make(map[uint64]*ent.SopStage)
 	for _, task := range filteredSopTasks {
 		stages, err := task.QueryTaskStages().All(l.ctx)
 		if err != nil {
 			_ = tx.Rollback()
 			return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 		}
-		sopStages = append(sopStages, stages...)
+		for _, stage := range stages {
+			stageMap[stage.ID] = stage
+		}
+		//sopStages = append(sopStages, stages...)
 	}
 	// 所有操作成功,提交事务
 	err = tx.Commit()
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
-	err = l.AddLabelRelationships(sopStages, *c, req.LabelIds, organizationId)
+	err = l.AddLabelRelationships(stageMap, *c, req.LabelIds, organizationId)
 
 	if err != nil {
 		return nil, err
@@ -127,10 +130,10 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
 	return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
 }
 
-func (l *UpdateLabelRelationshipsLogic) AddLabelRelationships(sopStages []*ent.SopStage, contact ent.Contact, currentLabelIds []uint64, organizationId uint64) (err error) {
+func (l *UpdateLabelRelationshipsLogic) AddLabelRelationships(sopStages map[uint64]*ent.SopStage, contact ent.Contact, currentLabelIds []uint64, organizationId uint64) (err error) {
 	// 遍历 sop_stages,找出满足条件的 stage
-	for _, stage := range sopStages {
-		if stage.ConditionType == 1 && isLabelIdListMatchFilter(currentLabelIds, stage.ConditionOperator, stage.ConditionList) {
+	for key, stage := range sopStages {
+		if stage != nil && stage.ConditionType == 1 && isLabelIdListMatchFilter(currentLabelIds, stage.ConditionOperator, stage.ConditionList) {
 			// 开始事务
 			tx, err := l.svcCtx.DB.Tx(context.Background())
 			if err != nil {
@@ -285,6 +288,7 @@ func (l *UpdateLabelRelationshipsLogic) AddLabelRelationships(sopStages []*ent.S
 				}
 
 				// 递归调用 AddLabelRelationships
+				sopStages[key] = nil
 				err = l.AddLabelRelationships(sopStages, contact, finalLabelIds, organizationId)
 				if err != nil {
 					return err

+ 2 - 0
internal/types/types.go

@@ -471,6 +471,8 @@ type AgentListReq struct {
 	Background *string `json:"background,optional"`
 	// status | 状态 1-可用 2-不可用
 	Status *int `json:"status,optional"`
+	// 租户id
+	OrganizationId *uint64 `json:"organizationId,optional"`
 }
 
 // Agent information response | Agent信息返回体