...
|
...
|
@@ -78,10 +78,10 @@ func (repository *ObjectTableRepository) UpdateWithVersion(ctx context.Context, |
|
|
func (repository *ObjectTableRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.ObjectTable) (*domain.ObjectTable, error) {
|
|
|
var (
|
|
|
tx = conn.DB()
|
|
|
m = &models.ObjectTable{Id: dm.Identify().(int)}
|
|
|
m = &models.ObjectTable{Id: dm.Identify().(int), TableType: dm.TableType}
|
|
|
)
|
|
|
queryFunc := func() (interface{}, error) {
|
|
|
tx = tx.Where("id = ?", m.Id).Unscoped().Delete(m)
|
|
|
tx = tx.Where("id = ? and table_type = ?", m.Id, dm.TableType).Unscoped().Delete(m)
|
|
|
return m, tx.Error
|
|
|
}
|
|
|
if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
|
...
|
...
|
@@ -90,7 +90,7 @@ func (repository *ObjectTableRepository) Delete(ctx context.Context, conn transa |
|
|
return repository.ModelToDomainModel(m)
|
|
|
}
|
|
|
|
|
|
func (repository *ObjectTableRepository) FindOne(ctx context.Context, conn transaction.Conn, id int) (*domain.ObjectTable, error) {
|
|
|
func (repository *ObjectTableRepository) FindOne(ctx context.Context, conn transaction.Conn, id int, tableType string) (*domain.ObjectTable, error) {
|
|
|
var (
|
|
|
err error
|
|
|
tx = conn.DB()
|
...
|
...
|
@@ -135,6 +135,15 @@ func (repository *ObjectTableRepository) Find(ctx context.Context, conn transact |
|
|
if v, ok := queryOptions["companyId"]; ok {
|
|
|
tx = tx.Where("company_id = ?", v)
|
|
|
}
|
|
|
if v, ok := queryOptions["id"]; ok {
|
|
|
tx = tx.Where("id = ?", v)
|
|
|
}
|
|
|
if v, ok := queryOptions["flag"]; ok {
|
|
|
tx = tx.Where("flag = ?", v)
|
|
|
}
|
|
|
if v, ok := queryOptions["parentId"]; ok {
|
|
|
tx = tx.Where("parent_id = ?", v)
|
|
|
}
|
|
|
if v, ok := queryOptions["tableTypeIn"]; ok {
|
|
|
tx = tx.Where("table_type in ?", v)
|
|
|
}
|
...
|
...
|
@@ -158,6 +167,43 @@ func (repository *ObjectTableRepository) Find(ctx context.Context, conn transact |
|
|
return total, dms, nil
|
|
|
}
|
|
|
|
|
|
// DeleteGroup 删除分组
|
|
|
func (repository *ObjectTableRepository) DeleteGroup(ctx context.Context, conn transaction.Conn, companyId int64, parentId int) error {
|
|
|
//分组下是否有数据
|
|
|
_, list, err := repository.Find(ctx, conn, domain.NewQueryOptions().WithKV("companyId", companyId).WithKV("parentId", parentId))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
if len(list) > 0 {
|
|
|
return nil
|
|
|
}
|
|
|
_, items, err := repository.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 = repository.Delete(ctx, conn, item)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
//递归删除上级分组
|
|
|
err = repository.DeleteGroup(ctx, conn, companyId, item.ParentId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (repository *ObjectTableRepository) ModelToDomainModel(from *models.ObjectTable) (*domain.ObjectTable, error) {
|
|
|
to := &domain.ObjectTable{}
|
|
|
err := copier.Copy(to, from)
|
...
|
...
|
|