作者 郑周

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

@@ -5,8 +5,8 @@ import "github.com/beego/beego/v2/core/validation" @@ -5,8 +5,8 @@ import "github.com/beego/beego/v2/core/validation"
5 // QueryRoleUserCommand 查询角色列表(关联用户) 5 // QueryRoleUserCommand 查询角色列表(关联用户)
6 type QueryRoleUserCommand struct { 6 type QueryRoleUserCommand struct {
7 CompanyId int64 `cname:"公司ID" json:"companyId"` 7 CompanyId int64 `cname:"公司ID" json:"companyId"`
8 - PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`  
9 - PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"` 8 + PageNumber int64 `cname:"分页页码" json:"pageNumber"`
  9 + PageSize int64 `cname:"分页数量" json:"pageSize"`
10 } 10 }
11 11
12 func (in *QueryRoleUserCommand) Valid(validation *validation.Validation) { 12 func (in *QueryRoleUserCommand) Valid(validation *validation.Validation) {
@@ -190,7 +190,7 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{ @@ -190,7 +190,7 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
190 190
191 for i := range roles { 191 for i := range roles {
192 v := roles[i] 192 v := roles[i]
193 - tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, v.Id) 193 + _, tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, v.Id)
194 if err != nil { 194 if err != nil {
195 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 195 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
196 } 196 }
@@ -104,12 +104,12 @@ func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface @@ -104,12 +104,12 @@ func (rs *RoleUserService) ListRole(in *command.UserRoleQueryCommand) (interface
104 }() 104 }()
105 ruRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext}) 105 ruRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
106 106
107 - tempList, err := ruRepository.FindAllContainUser(in.PageNumber, in.PageSize, in.CompanyId, in.RoleId) 107 + total, tempList, err := ruRepository.FindAllContainUser(in.PageNumber, in.PageSize, in.CompanyId, in.RoleId)
108 if err != nil { 108 if err != nil {
109 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 109 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
110 } 110 }
111 if err := transactionContext.CommitTransaction(); err != nil { 111 if err := transactionContext.CommitTransaction(); err != nil {
112 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 112 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
113 } 113 }
114 - return tool_funs.SimpleWrapGridMap(int64(len(tempList)), tempList), nil 114 + return tool_funs.SimpleWrapGridMap(total, tempList), nil
115 } 115 }
@@ -28,5 +28,5 @@ type RoleUserRepository interface { @@ -28,5 +28,5 @@ type RoleUserRepository interface {
28 Find(queryOptions map[string]interface{}) (int64, []*RoleUser, error) 28 Find(queryOptions map[string]interface{}) (int64, []*RoleUser, error)
29 Count(queryOptions map[string]interface{}) (int64, error) 29 Count(queryOptions map[string]interface{}) (int64, error)
30 BatchDeleteById(ids []int64) error 30 BatchDeleteById(ids []int64) error
31 - FindAllContainUser(pageSize int, pageNumber int, companyId int64, roleId int64) ([]*RoleContainUser, error) 31 + FindAllContainUser(pageSize int, pageNumber int, companyId int64, roleId int64) (int64, []*RoleContainUser, error)
32 } 32 }
@@ -182,7 +182,7 @@ func (repo *RoleUserRepository) BatchDeleteById(ids []int64) error { @@ -182,7 +182,7 @@ func (repo *RoleUserRepository) BatchDeleteById(ids []int64) error {
182 return err 182 return err
183 } 183 }
184 184
185 -func (repo *RoleUserRepository) FindAllContainUser(pageNumber int, pageSize int, companyId int64, roleId int64) ([]*domain.RoleContainUser, error) { 185 +func (repo *RoleUserRepository) FindAllContainUser(pageNumber int, pageSize int, companyId int64, roleId int64) (int64, []*domain.RoleContainUser, error) {
186 limit := pageSize 186 limit := pageSize
187 offset := limit * (pageNumber - 1) 187 offset := limit * (pageNumber - 1)
188 if offset < 0 { 188 if offset < 0 {
@@ -210,9 +210,15 @@ func (repo *RoleUserRepository) FindAllContainUser(pageNumber int, pageSize int, @@ -210,9 +210,15 @@ func (repo *RoleUserRepository) FindAllContainUser(pageNumber int, pageSize int,
210 } 210 }
211 dataSql += whereFrom 211 dataSql += whereFrom
212 dataSql = fmt.Sprintf("%s limit %d offset %d", dataSql, limit, offset) 212 dataSql = fmt.Sprintf("%s limit %d offset %d", dataSql, limit, offset)
  213 + countSql := ` SELECT COUNT(*) ` + whereFrom
213 214
214 tx := repo.transactionContext.PgTx 215 tx := repo.transactionContext.PgTx
  216 +
  217 + var total int64
215 var dataList = make([]*domain.RoleContainUser, 0) 218 var dataList = make([]*domain.RoleContainUser, 0)
216 _, err := tx.Query(&dataList, dataSql, param...) 219 _, err := tx.Query(&dataList, dataSql, param...)
217 - return dataList, err 220 +
  221 + // 获取总数量
  222 + _, _ = tx.QueryOne(pg.Scan(&total), countSql, param...)
  223 + return total, dataList, err
218 } 224 }