|
@@ -104,21 +104,24 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
|
|
}
|
|
}
|
|
|
|
|
|
// 获取所有 filteredSopTasks 的 sop_stages
|
|
// 获取所有 filteredSopTasks 的 sop_stages
|
|
- var sopStages []*ent.SopStage
|
|
|
|
|
|
+ stageMap := make(map[uint64]*ent.SopStage)
|
|
for _, task := range filteredSopTasks {
|
|
for _, task := range filteredSopTasks {
|
|
stages, err := task.QueryTaskStages().All(l.ctx)
|
|
stages, err := task.QueryTaskStages().All(l.ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
_ = tx.Rollback()
|
|
_ = tx.Rollback()
|
|
return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
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()
|
|
err = tx.Commit()
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
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 {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
@@ -127,10 +130,10 @@ func (l *UpdateLabelRelationshipsLogic) UpdateLabelRelationships(req *types.Labe
|
|
return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
|
|
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
|
|
// 遍历 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())
|
|
tx, err := l.svcCtx.DB.Tx(context.Background())
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -285,6 +288,7 @@ func (l *UpdateLabelRelationshipsLogic) AddLabelRelationships(sopStages []*ent.S
|
|
}
|
|
}
|
|
|
|
|
|
// 递归调用 AddLabelRelationships
|
|
// 递归调用 AddLabelRelationships
|
|
|
|
+ sopStages[key] = nil
|
|
err = l.AddLabelRelationships(sopStages, contact, finalLabelIds, organizationId)
|
|
err = l.AddLabelRelationships(sopStages, contact, finalLabelIds, organizationId)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|