forked from free-lancers/electricity_bill_calc_service
feat(user):基本完成用户分页查询列表功能,待测。
This commit is contained in:
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/cache"
|
||||
"electricity_bill_calc/config"
|
||||
"electricity_bill_calc/global"
|
||||
"electricity_bill_calc/model"
|
||||
|
||||
@@ -50,3 +51,34 @@ func (_UserRepository) FindUserByID(uid string) (*model.User, error) {
|
||||
}
|
||||
return _postProcessSingle(user, has, err)
|
||||
}
|
||||
|
||||
func (_UserRepository) ListUserDetail(keyword string, userType int, userState *bool, page int) ([]*model.JoinedUserDetail, int64, error) {
|
||||
var cond = builder.NewCond()
|
||||
if len(keyword) != 0 {
|
||||
keywordCond := builder.NewCond().
|
||||
Or(builder.Like{"user.username", keyword}).
|
||||
Or(builder.Like{"user_detail.name", keyword})
|
||||
cond = cond.And(keywordCond)
|
||||
}
|
||||
if userType != -1 {
|
||||
cond = cond.And(builder.Eq{"user.type": userType})
|
||||
}
|
||||
if userState != nil {
|
||||
cond = cond.And(builder.Eq{"user.enabled": *userState})
|
||||
}
|
||||
startItem := (page - 1) * config.ServiceSettings.ItemsPageSize
|
||||
total, err := global.DBConn.
|
||||
Join("INNER", "user_detail", "user_detail.id=user.id").
|
||||
Where(cond).
|
||||
Count()
|
||||
if err != nil {
|
||||
return nil, -1, err
|
||||
}
|
||||
users := make([]*model.JoinedUserDetail, 0)
|
||||
err = global.DBConn.
|
||||
Join("INNER", "user_detail", "user_detail.id=user.id").
|
||||
Where(cond).
|
||||
Limit(config.ServiceSettings.ItemsPageSize, startItem).
|
||||
Find(users)
|
||||
return users, total, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user