作者 郑周

1. 修复 权限管理人员 分页BUG

... ... @@ -5,8 +5,8 @@ import "github.com/beego/beego/v2/core/validation"
// QueryRoleUserCommand 查询角色列表(关联用户)
type QueryRoleUserCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
PageNumber int64 `cname:"分页页码" json:"pageNumber"`
PageSize int64 `cname:"分页数量" json:"pageSize"`
}
func (in *QueryRoleUserCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -190,7 +190,7 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
for i := range roles {
v := roles[i]
tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, v.Id)
_, tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, v.Id)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -104,12 +104,12 @@ func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface
}()
ruRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
tempList, err := ruRepository.FindAllContainUser(in.PageNumber, in.PageSize, in.CompanyId, in.RoleId)
total, tempList, err := ruRepository.FindAllContainUser(in.PageNumber, in.PageSize, in.CompanyId, in.RoleId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(len(tempList)), tempList), nil
return tool_funs.SimpleWrapGridMap(total, tempList), nil
}
... ...
... ... @@ -28,5 +28,5 @@ type RoleUserRepository interface {
Find(queryOptions map[string]interface{}) (int64, []*RoleUser, error)
Count(queryOptions map[string]interface{}) (int64, error)
BatchDeleteById(ids []int64) error
FindAllContainUser(pageSize int, pageNumber int, companyId int64, roleId int64) ([]*RoleContainUser, error)
FindAllContainUser(pageSize int, pageNumber int, companyId int64, roleId int64) (int64, []*RoleContainUser, error)
}
... ...
... ... @@ -182,7 +182,7 @@ func (repo *RoleUserRepository) BatchDeleteById(ids []int64) error {
return err
}
func (repo *RoleUserRepository) FindAllContainUser(pageNumber int, pageSize int, companyId int64, roleId int64) ([]*domain.RoleContainUser, error) {
func (repo *RoleUserRepository) FindAllContainUser(pageNumber int, pageSize int, companyId int64, roleId int64) (int64, []*domain.RoleContainUser, error) {
limit := pageSize
offset := limit * (pageNumber - 1)
if offset < 0 {
... ... @@ -210,9 +210,15 @@ func (repo *RoleUserRepository) FindAllContainUser(pageNumber int, pageSize int,
}
dataSql += whereFrom
dataSql = fmt.Sprintf("%s limit %d offset %d", dataSql, limit, offset)
countSql := ` SELECT COUNT(*) ` + whereFrom
tx := repo.transactionContext.PgTx
var total int64
var dataList = make([]*domain.RoleContainUser, 0)
_, err := tx.Query(&dataList, dataSql, param...)
return dataList, err
// 获取总数量
_, _ = tx.QueryOne(pg.Scan(&total), countSql, param...)
return total, dataList, err
}
... ...