Browse Source

复制Package的事件增加ObjectID

gitlink
Sydonian 8 months ago
parent
commit
527d64c157
2 changed files with 12 additions and 3 deletions
  1. +5
    -3
      common/models/datamap.go
  2. +7
    -0
      coordinator/internal/mq/package.go

+ 5
- 3
common/models/datamap.go View File

@@ -458,9 +458,11 @@ func (b *BodyNewPackage) OnUnionSerializing() {
// Package克隆的事件
type BodyPackageCloned struct {
serder.Metadata `union:"PackageCloned"`
Type string `json:"type"`
SourcePackageID cdssdk.PackageID `json:"sourcePackageID"`
NewPackage cdssdk.Package `json:"newPackage"`
Type string `json:"type"`
SourcePackageID cdssdk.PackageID `json:"sourcePackageID"`
NewPackage cdssdk.Package `json:"newPackage"`
SourceObjectIDs []cdssdk.ObjectID `json:"sourceObjectIDs"` // 原本的ObjectID
NewObjectIDs []cdssdk.ObjectID `json:"newObjectIDs"` // 复制后的新ObjectID,与SourceObjectIDs一一对应
}

func (b *BodyPackageCloned) GetBodyType() string {


+ 7
- 0
coordinator/internal/mq/package.go View File

@@ -160,6 +160,8 @@ func (svc *Service) DeletePackage(msg *coormq.DeletePackage) (*coormq.DeletePack

func (svc *Service) ClonePackage(msg *coormq.ClonePackage) (*coormq.ClonePackageResp, *mq.CodeMessage) {
var pkg cdssdk.Package
var oldObjIDs []cdssdk.ObjectID
var newObjIDs []cdssdk.ObjectID
err := svc.db2.DoTx(func(tx db2.SQLContext) error {
var err error

@@ -198,6 +200,9 @@ func (svc *Service) ClonePackage(msg *coormq.ClonePackage) (*coormq.ClonePackage
oldToNew := make(map[cdssdk.ObjectID]cdssdk.ObjectID)
for i, obj := range clonedObjs {
oldToNew[objs[i].ObjectID] = obj.ObjectID

oldObjIDs = append(oldObjIDs, objs[i].ObjectID)
newObjIDs = append(newObjIDs, obj.ObjectID)
}

clonedBlks := make([]stgmod.ObjectBlock, len(objBlks))
@@ -224,6 +229,8 @@ func (svc *Service) ClonePackage(msg *coormq.ClonePackage) (*coormq.ClonePackage
svc.evtPub.Publish(&stgmod.BodyPackageCloned{
SourcePackageID: msg.PackageID,
NewPackage: pkg,
SourceObjectIDs: oldObjIDs,
NewObjectIDs: newObjIDs,
})

return mq.ReplyOK(coormq.RespClonePackage(pkg))


Loading…
Cancel
Save