mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-12 12:20:25 +08:00
refactor: 新增base.Repo与base.App,重构repo与app层代码
This commit is contained in:
@@ -3,35 +3,18 @@ package persistence
|
||||
import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/gormx"
|
||||
)
|
||||
|
||||
type resourceRepoImpl struct{}
|
||||
type resourceRepoImpl struct {
|
||||
base.RepoImpl[*entity.Resource]
|
||||
}
|
||||
|
||||
func newResourceRepo() repository.Resource {
|
||||
return new(resourceRepoImpl)
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetResourceList(condition *entity.Resource, toEntity any, orderBy ...string) {
|
||||
gormx.ListByOrder(condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetById(id uint64, cols ...string) *entity.Resource {
|
||||
res := new(entity.Resource)
|
||||
if err := gormx.GetById(res, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
return &resourceRepoImpl{
|
||||
base.RepoImpl[*entity.Resource]{M: new(entity.Resource)},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNil(gormx.DeleteById(new(entity.Resource), id), "删除失败")
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetByCondition(condition *entity.Resource, cols ...string) error {
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetChildren(uiPath string) []entity.Resource {
|
||||
@@ -41,12 +24,12 @@ func (r *resourceRepoImpl) GetChildren(uiPath string) []entity.Resource {
|
||||
return rs
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) UpdateByUiPathLike(resource *entity.Resource) {
|
||||
func (r *resourceRepoImpl) UpdateByUiPathLike(resource *entity.Resource) error {
|
||||
sql := "UPDATE t_sys_resource SET status=? WHERE (ui_path LIKE ?)"
|
||||
gormx.ExecSql(sql, resource.Status, resource.UiPath+"%")
|
||||
return gormx.ExecSql(sql, resource.Status, resource.UiPath+"%")
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity any) {
|
||||
func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity any) error {
|
||||
sql := `SELECT
|
||||
m.id,
|
||||
m.pid,
|
||||
@@ -80,5 +63,5 @@ func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity any) {
|
||||
ORDER BY
|
||||
m.pid ASC,
|
||||
m.weight ASC`
|
||||
biz.ErrIsNilAppendErr(gormx.GetListBySql2Model(sql, toEntity, accountId), "查询账号资源失败: %s")
|
||||
return gormx.GetListBySql2Model(sql, toEntity, accountId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user