Browse Source

♻️ refactor RegisterParticipant impl

Signed-off-by: devad <cossjie@foxmail.com>

Former-commit-id: 9ff3815f56
pull/9/head
devad 2 years ago
parent
commit
ad3a651558
2 changed files with 8 additions and 3 deletions
  1. +8
    -2
      rpc/internal/logic/participantservice/registerparticipantlogic.go
  2. +0
    -1
      rpc/internal/logic/participantservice/reportavailablelogic.go

+ 8
- 2
rpc/internal/logic/participantservice/registerparticipantlogic.go View File

@@ -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)


+ 0
- 1
rpc/internal/logic/participantservice/reportavailablelogic.go View File

@@ -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),


Loading…
Cancel
Save