From ad3a651558900cefbdb01ddfbd9d0b7cbdd9d3e2 Mon Sep 17 00:00:00 2001 From: devad Date: Wed, 26 Jul 2023 18:28:36 +0800 Subject: [PATCH] :recycle: refactor RegisterParticipant impl Signed-off-by: devad Former-commit-id: 9ff3815f5643a7b10638528127129988c58c9772 --- .../participantservice/registerparticipantlogic.go | 10 ++++++++-- .../logic/participantservice/reportavailablelogic.go | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/rpc/internal/logic/participantservice/registerparticipantlogic.go b/rpc/internal/logic/participantservice/registerparticipantlogic.go index faa5ac67..9673d297 100644 --- a/rpc/internal/logic/participantservice/registerparticipantlogic.go +++ b/rpc/internal/logic/participantservice/registerparticipantlogic.go @@ -2,8 +2,10 @@ package participantservicelogic import ( "context" + "github.com/pkg/errors" "gitlink.org.cn/jcce-pcm/pcm-coordinator/model" "gitlink.org.cn/jcce-pcm/utils/tool" + "gorm.io/gorm" "time" "gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc" @@ -60,7 +62,9 @@ func (l *RegisterParticipantLogic) RegisterParticipant(in *pcmCore.ParticipantPh tool.Convert(info, nodeInfo) nodeInfo.CreatedTime = time.Now() nodeInfo.ParticipantId = participantInfo.Id - if nodeInfo.Id == 0 { + //查询节点name与ParticipantId是否存在 + nodeErr := db.Where(&model.ScNodePhyInfo{NodeName: nodeInfo.NodeName, ParticipantId: in.ParticipantId}).Take(nodeInfo) + if errors.Is(nodeErr.Error, gorm.ErrRecordNotFound) { nodeInfo.Id = tool.GenSnowflakeID() } nodeList = append(nodeList, nodeInfo) @@ -73,7 +77,9 @@ func (l *RegisterParticipantLogic) RegisterParticipant(in *pcmCore.ParticipantPh tool.Convert(label, labelInfo) labelInfo.CreatedTime = time.Now() labelInfo.ParticipantId = participantInfo.Id - if labelInfo.Id == 0 { + //查询标签key value与ParticipantId是否存在 + labelErr := db.Where(&model.ScParticipantLabelInfo{Key: labelInfo.Key, Value: labelInfo.Value, ParticipantId: in.ParticipantId}).Take(labelInfo) + if errors.Is(labelErr.Error, gorm.ErrRecordNotFound) { labelInfo.Id = tool.GenSnowflakeID() } labelList = append(labelList, labelInfo) diff --git a/rpc/internal/logic/participantservice/reportavailablelogic.go b/rpc/internal/logic/participantservice/reportavailablelogic.go index f0b713e8..08237e17 100644 --- a/rpc/internal/logic/participantservice/reportavailablelogic.go +++ b/rpc/internal/logic/participantservice/reportavailablelogic.go @@ -49,7 +49,6 @@ func (l *ReportAvailableLogic) ReportAvailable(in *pcmCore.ParticipantAvailReq) participantPhyInfo := &model.ScParticipantPhyInfo{} participantPhyInfo.Id = in.ParticipantId if errors.Is(db.Take(&participantPhyInfo).Error, gorm.ErrRecordNotFound) { - fmt.Println("sdsdfsdf ") return &pcmCore.ParticipantResp{ Code: 500, Msg: fmt.Sprintf("ParticipantInfo Does not exist, please check participantPhyId: %d", in.ParticipantId),