作者 庄敏学

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{
//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,
TableId: item.TableId,
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,10 +9,10 @@ import (
)
type ObjectTable struct {
Id int `json:"id" gorm:"primaryKey"` // ID
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:"index:idx_object_table_type"` //模块
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
... ...