正在显示
3 个修改的文件
包含
72 行增加
和
19 行删除
@@ -114,10 +114,10 @@ func DeleteObjectTable(ctx context.Context, svcCtx *svc.ServiceContext, conn tra | @@ -114,10 +114,10 @@ func DeleteObjectTable(ctx context.Context, svcCtx *svc.ServiceContext, conn tra | ||
114 | return err | 114 | return err |
115 | } | 115 | } |
116 | //是否远程已删除 | 116 | //是否远程已删除 |
117 | - objectTable, err := svcCtx.ObjectTableRepository.FindOne(ctx, conn, sourceId) | 117 | + objectTable, err := svcCtx.ObjectTableRepository.FindOneByTableId(ctx, conn, sourceId) |
118 | if err == nil && objectTable.Id > 0 && objectTable.RemoteDeleted == 1 { | 118 | if err == nil && objectTable.Id > 0 && objectTable.RemoteDeleted == 1 { |
119 | //删除表 | 119 | //删除表 |
120 | - _, err = svcCtx.ObjectTableRepository.Delete(ctx, conn, &domain.ObjectTable{Id: sourceId}) | 120 | + _, err = svcCtx.ObjectTableRepository.Delete(ctx, conn, &domain.ObjectTable{Id: sourceId, TableType: objectTable.TableType}) |
121 | if err != nil { | 121 | if err != nil { |
122 | return err | 122 | return err |
123 | } | 123 | } |
@@ -126,6 +126,48 @@ func DeleteObjectTable(ctx context.Context, svcCtx *svc.ServiceContext, conn tra | @@ -126,6 +126,48 @@ func DeleteObjectTable(ctx context.Context, svcCtx *svc.ServiceContext, conn tra | ||
126 | if err != nil { | 126 | if err != nil { |
127 | return err | 127 | return err |
128 | } | 128 | } |
129 | + //删除分组 | ||
130 | + err = DeleteObjectGroup(ctx, svcCtx, conn, objectTable.CompanyId, objectTable.ParentId) | ||
131 | + if err != nil { | ||
132 | + return err | ||
133 | + } | ||
134 | + } | ||
135 | + } | ||
136 | + return nil | ||
137 | +} | ||
138 | + | ||
139 | +// DeleteObjectGroup 删除分组 | ||
140 | +func DeleteObjectGroup(ctx context.Context, svcCtx *svc.ServiceContext, conn transaction.Conn, companyId int64, parentId int) error { | ||
141 | + //分组下是否有数据 | ||
142 | + _, list, err := svcCtx.ObjectTableRepository.Find(ctx, conn, domain.NewQueryOptions().WithKV("companyId", companyId).WithKV("parentId", parentId)) | ||
143 | + if err != nil { | ||
144 | + return err | ||
145 | + } | ||
146 | + if len(list) > 0 { | ||
147 | + return nil | ||
148 | + } | ||
149 | + _, items, err := svcCtx.ObjectTableRepository.Find( | ||
150 | + ctx, conn, | ||
151 | + domain.NewQueryOptions(). | ||
152 | + WithKV("companyId", companyId). | ||
153 | + WithKV("id", parentId). | ||
154 | + WithKV("flag", "Group"), | ||
155 | + ) | ||
156 | + if err != nil { | ||
157 | + return err | ||
158 | + } | ||
159 | + if len(items) > 0 { | ||
160 | + for _, item := range items { | ||
161 | + //删除分组 | ||
162 | + _, err = svcCtx.ObjectTableRepository.Delete(ctx, conn, item) | ||
163 | + if err != nil { | ||
164 | + return err | ||
165 | + } | ||
166 | + //递归删除上级分组 | ||
167 | + err = DeleteObjectGroup(ctx, svcCtx, conn, companyId, item.ParentId) | ||
168 | + if err != nil { | ||
169 | + return err | ||
170 | + } | ||
129 | } | 171 | } |
130 | } | 172 | } |
131 | return nil | 173 | return nil |
@@ -132,9 +132,20 @@ func (l *SyncTableLogic) getFields(list []*domain.ObjectTable) []*domain.ObjectF | @@ -132,9 +132,20 @@ func (l *SyncTableLogic) getFields(list []*domain.ObjectTable) []*domain.ObjectF | ||
132 | for _, item := range list { | 132 | for _, item := range list { |
133 | accessToken, _ := types.TableAccessToken{CompanyId: item.CompanyId}.GenerateToken() | 133 | accessToken, _ := types.TableAccessToken{CompanyId: item.CompanyId}.GenerateToken() |
134 | if item.TableId > 0 { | 134 | if item.TableId > 0 { |
135 | - response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{ | ||
136 | - Token: accessToken, | ||
137 | - TableId: item.TableId, | 135 | + //response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{ |
136 | + // Token: accessToken, | ||
137 | + // TableId: item.TableId, | ||
138 | + //}) | ||
139 | + response, err := l.svcCtx.ByteMetadataService.TableDataPreview(l.ctx, &bytelib.TableDataPreviewRequest{ | ||
140 | + Token: accessToken, | ||
141 | + ObjectId: int64(item.TableId), | ||
142 | + ObjectType: bytelib.ObjectMetaTable, | ||
143 | + Where: &bytelib.TableQueryWhere{ | ||
144 | + PageNumber: 1, | ||
145 | + PageSize: 1, | ||
146 | + }, | ||
147 | + UseCache: false, | ||
148 | + HiddenData: false, | ||
138 | }) | 149 | }) |
139 | if err == nil { | 150 | if err == nil { |
140 | fields = append(fields, &domain.ObjectField{ | 151 | fields = append(fields, &domain.ObjectField{ |
@@ -9,20 +9,20 @@ import ( | @@ -9,20 +9,20 @@ import ( | ||
9 | ) | 9 | ) |
10 | 10 | ||
11 | type ObjectTable struct { | 11 | type ObjectTable struct { |
12 | - Id int `json:"id" gorm:"primaryKey"` // ID | ||
13 | - TableId int `json:"tableId" gorm:"index:idx_object_table_id"` //表ID | ||
14 | - Name string `json:"name"` //表名 | ||
15 | - TableType string `json:"tableType" gorm:"index:idx_object_table_type"` //模块 | ||
16 | - CompanyId int64 `json:"companyId" gorm:"index:idx_object_table_company"` //公司id | ||
17 | - ParentId int `json:"parentId" gorm:"default:0"` //父id | ||
18 | - Flag string `json:"flag"` //分组:Group 集合:Set | ||
19 | - Version int `json:",omitempty"` //版本 | ||
20 | - IsLocal bool `json:"isLocal" gorm:"default:false"` //是否有本地存储 | ||
21 | - RemoteDeleted int `json:"remoteDeleted"` //远端删除 | ||
22 | - IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` //删除标记 | ||
23 | - CreatedAt int64 `json:",omitempty"` //创建时间 | ||
24 | - UpdatedAt int64 `json:",omitempty"` //更新时间 | ||
25 | - DeletedAt int64 `json:",omitempty"` //删除时间 | 12 | + Id int `json:"id" gorm:"primaryKey;autoIncrement:false"` // ID |
13 | + TableId int `json:"tableId" gorm:"index:idx_object_table_id"` //表ID | ||
14 | + Name string `json:"name"` //表名 | ||
15 | + TableType string `json:"tableType" gorm:"primaryKey;autoIncrement:false;index:idx_object_table_type"` //模块 | ||
16 | + CompanyId int64 `json:"companyId" gorm:"index:idx_object_table_company"` //公司id | ||
17 | + ParentId int `json:"parentId" gorm:"default:0"` //父id | ||
18 | + Flag string `json:"flag"` //分组:Group 集合:Set | ||
19 | + Version int `json:",omitempty"` //版本 | ||
20 | + IsLocal bool `json:"isLocal" gorm:"default:false"` //是否有本地存储 | ||
21 | + RemoteDeleted int `json:"remoteDeleted"` //远端删除 | ||
22 | + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` //删除标记 | ||
23 | + CreatedAt int64 `json:",omitempty"` //创建时间 | ||
24 | + UpdatedAt int64 `json:",omitempty"` //更新时间 | ||
25 | + DeletedAt int64 `json:",omitempty"` //删除时间 | ||
26 | } | 26 | } |
27 | 27 | ||
28 | func (m *ObjectTable) TableName() string { | 28 | func (m *ObjectTable) TableName() string { |
-
请 注册 或 登录 后发表评论