refactor: 代码重构、分页数据组件支持多选

This commit is contained in:
meilin.huang
2023-07-01 14:34:42 +08:00
parent d423572e01
commit ce32fc7f2c
81 changed files with 937 additions and 759 deletions

View File

@@ -4,6 +4,7 @@ import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
@@ -13,12 +14,13 @@ func newRoleRepo() repository.Role {
return new(roleRepoImpl)
}
func (m *roleRepoImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
func (m *roleRepoImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
func (m *roleRepoImpl) Delete(id uint64) {
biz.ErrIsNil(model.DeleteById(new(entity.Role), id), "删除角色失败")
biz.ErrIsNil(gormx.DeleteById(new(entity.Role), id), "删除角色失败")
}
// 获取角色拥有的资源id数组从role_resource表获取
@@ -26,7 +28,7 @@ func (m *roleRepoImpl) GetRoleResourceIds(roleId uint64) []uint64 {
var rrs []entity.RoleResource
condtion := &entity.RoleResource{RoleId: roleId}
model.ListBy(condtion, &rrs, "ResourceId")
gormx.ListBy(condtion, &rrs, "ResourceId")
var rids []uint64
for _, v := range rrs {
@@ -41,22 +43,22 @@ func (m *roleRepoImpl) GetRoleResources(roleId uint64, toEntity any) {
"FROM t_sys_role_resource rr JOIN t_sys_resource r ON rr.resource_id = r.id " +
"WHERE rr.role_id = ? " +
"ORDER BY r.pid ASC, r.weight ASC"
model.GetListBySql2Model(sql, toEntity, roleId)
gormx.GetListBySql2Model(sql, toEntity, roleId)
}
func (m *roleRepoImpl) SaveRoleResource(rr *entity.RoleResource) {
model.Insert(rr)
gormx.Insert(rr)
}
func (m *roleRepoImpl) DeleteRoleResource(roleId uint64, resourceId uint64) {
model.DeleteByCondition(&entity.RoleResource{RoleId: roleId, ResourceId: resourceId})
gormx.DeleteByCondition(&entity.RoleResource{RoleId: roleId, ResourceId: resourceId})
}
func (m *roleRepoImpl) GetAccountRoleIds(accountId uint64) []uint64 {
var rrs []entity.AccountRole
condtion := &entity.AccountRole{AccountId: accountId}
model.ListBy(condtion, &rrs, "RoleId")
gormx.ListBy(condtion, &rrs, "RoleId")
var rids []uint64
for _, v := range rrs {
@@ -66,11 +68,11 @@ func (m *roleRepoImpl) GetAccountRoleIds(accountId uint64) []uint64 {
}
func (m *roleRepoImpl) SaveAccountRole(ar *entity.AccountRole) {
model.Insert(ar)
gormx.Insert(ar)
}
func (m *roleRepoImpl) DeleteAccountRole(accountId, roleId uint64) {
model.DeleteByCondition(&entity.AccountRole{RoleId: roleId, AccountId: accountId})
gormx.DeleteByCondition(&entity.AccountRole{RoleId: roleId, AccountId: accountId})
}
// 获取账号角色信息列表
@@ -78,5 +80,5 @@ func (m *roleRepoImpl) GetAccountRoles(accountId uint64, toEntity any) {
sql := "SELECT r.status, r.name, ar.create_time AS CreateTime, ar.creator AS creator " +
"FROM t_sys_role r JOIN t_sys_account_role ar ON r.id = ar.role_id AND ar.account_id = ? " +
"ORDER BY ar.create_time DESC"
model.GetListBySql2Model(sql, toEntity, accountId)
gormx.GetListBySql2Model(sql, toEntity, accountId)
}