作者 庄敏学

object_table改为双主键

... ... @@ -114,10 +114,10 @@ func DeleteObjectTable(ctx context.Context, svcCtx *svc.ServiceContext, conn tra
return err
}
//是否远程已删除
objectTable, err := svcCtx.ObjectTableRepository.FindOne(ctx, conn, sourceId)
objectTable, err := svcCtx.ObjectTableRepository.FindOneByTableId(ctx, conn, sourceId)
if err == nil && objectTable.Id > 0 && objectTable.RemoteDeleted == 1 {
//删除表
_, err = svcCtx.ObjectTableRepository.Delete(ctx, conn, &domain.ObjectTable{Id: sourceId})
_, err = svcCtx.ObjectTableRepository.Delete(ctx, conn, &domain.ObjectTable{Id: sourceId, TableType: objectTable.TableType})
if err != nil {
return err
}
... ... @@ -126,6 +126,48 @@ func DeleteObjectTable(ctx context.Context, svcCtx *svc.ServiceContext, conn tra
if err != nil {
return err
}
//删除分组
err = DeleteObjectGroup(ctx, svcCtx, conn, objectTable.CompanyId, objectTable.ParentId)
if err != nil {
return err
}
}
}
return nil
}
// DeleteObjectGroup 删除分组
func DeleteObjectGroup(ctx context.Context, svcCtx *svc.ServiceContext, conn transaction.Conn, companyId int64, parentId int) error {
//分组下是否有数据
_, list, err := svcCtx.ObjectTableRepository.Find(ctx, conn, domain.NewQueryOptions().WithKV("companyId", companyId).WithKV("parentId", parentId))
if err != nil {
return err
}
if len(list) > 0 {
return nil
}
_, items, err := svcCtx.ObjectTableRepository.Find(
ctx, conn,
domain.NewQueryOptions().
WithKV("companyId", companyId).
WithKV("id", parentId).
WithKV("flag", "Group"),
)
if err != nil {
return err
}
if len(items) > 0 {
for _, item := range items {
//删除分组
_, err = svcCtx.ObjectTableRepository.Delete(ctx, conn, item)
if err != nil {
return err
}
//递归删除上级分组
err = DeleteObjectGroup(ctx, svcCtx, conn, companyId, item.ParentId)
if err != nil {
return err
}
}
}
return nil
... ...
... ... @@ -132,9 +132,20 @@ func (l *SyncTableLogic) getFields(list []*domain.ObjectTable) []*domain.ObjectF
for _, item := range list {
accessToken, _ := types.TableAccessToken{CompanyId: item.CompanyId}.GenerateToken()
if item.TableId > 0 {
response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{
Token: accessToken,
TableId: item.TableId,
//response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{
// Token: accessToken,
// TableId: item.TableId,
//})
response, err := l.svcCtx.ByteMetadataService.TableDataPreview(l.ctx, &bytelib.TableDataPreviewRequest{
Token: accessToken,
ObjectId: int64(item.TableId),
ObjectType: bytelib.ObjectMetaTable,
Where: &bytelib.TableQueryWhere{
PageNumber: 1,
PageSize: 1,
},
UseCache: false,
HiddenData: false,
})
if err == nil {
fields = append(fields, &domain.ObjectField{
... ...
... ... @@ -9,20 +9,20 @@ import (
)
type ObjectTable struct {
Id int `json:"id" gorm:"primaryKey"` // ID
TableId int `json:"tableId" gorm:"index:idx_object_table_id"` //表ID
Name string `json:"name"` //表名
TableType string `json:"tableType" gorm:"index:idx_object_table_type"` //模块
CompanyId int64 `json:"companyId" gorm:"index:idx_object_table_company"` //公司id
ParentId int `json:"parentId" gorm:"default:0"` //父id
Flag string `json:"flag"` //分组:Group 集合:Set
Version int `json:",omitempty"` //版本
IsLocal bool `json:"isLocal" gorm:"default:false"` //是否有本地存储
RemoteDeleted int `json:"remoteDeleted"` //远端删除
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` //删除标记
CreatedAt int64 `json:",omitempty"` //创建时间
UpdatedAt int64 `json:",omitempty"` //更新时间
DeletedAt int64 `json:",omitempty"` //删除时间
Id int `json:"id" gorm:"primaryKey;autoIncrement:false"` // ID
TableId int `json:"tableId" gorm:"index:idx_object_table_id"` //表ID
Name string `json:"name"` //表名
TableType string `json:"tableType" gorm:"primaryKey;autoIncrement:false;index:idx_object_table_type"` //模块
CompanyId int64 `json:"companyId" gorm:"index:idx_object_table_company"` //公司id
ParentId int `json:"parentId" gorm:"default:0"` //父id
Flag string `json:"flag"` //分组:Group 集合:Set
Version int `json:",omitempty"` //版本
IsLocal bool `json:"isLocal" gorm:"default:false"` //是否有本地存储
RemoteDeleted int `json:"remoteDeleted"` //远端删除
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` //删除标记
CreatedAt int64 `json:",omitempty"` //创建时间
UpdatedAt int64 `json:",omitempty"` //更新时间
DeletedAt int64 `json:",omitempty"` //删除时间
}
func (m *ObjectTable) TableName() string {
... ...