- GetUsers支持分页
This commit is contained in:
@@ -55,7 +55,7 @@ func TransferLegacyWeixins() (err error) {
|
|||||||
if user.Name == "" {
|
if user.Name == "" {
|
||||||
user.Name = user.Mobile
|
user.Name = user.Mobile
|
||||||
}
|
}
|
||||||
userList, err2 := dao.GetUsers(db, 0, "", nil, "", v.Tel)
|
userList, _, err2 := dao.GetUsers(db, 0, "", nil, "", v.Tel, 0, -1)
|
||||||
if err = err2; err != nil {
|
if err = err2; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,8 +265,8 @@ func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
|
|||||||
errList := errlist.New()
|
errList := errlist.New()
|
||||||
userIDs, err2 := api2.RoleMan.GetRoleUserList(autils.NewRole(key, 0))
|
userIDs, err2 := api2.RoleMan.GetRoleUserList(autils.NewRole(key, 0))
|
||||||
if err = err2; err == nil && len(userIDs) > 0 {
|
if err = err2; err == nil && len(userIDs) > 0 {
|
||||||
userList, err2 := GetUsers(ctx, 0, "", userIDs, "", "")
|
userList, totalCount, err2 := dao.GetUsers(dao.GetDB(), 0, "", userIDs, "", "", 0, -1)
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil && totalCount > 0 {
|
||||||
err = fmt.Errorf("还有人员在使用角色:%s,人员信息:%s", key, utils.MustMarshal(utils.Struct2Map(userList, "compact")))
|
err = fmt.Errorf("还有人员在使用角色:%s,人员信息:%s", key, utils.MustMarshal(utils.Struct2Map(userList, "compact")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,8 +155,15 @@ func OnDingDingMsg(msg map[string]interface{}) (callbackResponse *dingdingapi.Ca
|
|||||||
return api.DingDingAPI.Err2CallbackResponse(nil)
|
return api.DingDingAPI.Err2CallbackResponse(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUsers(ctx *jxcontext.Context, userType int, keyword string, userIDs []string, userID2, mobile string) (userList []*model.User, err error) {
|
func GetUsers(ctx *jxcontext.Context, userType int, keyword string, userIDs []string, userID2, mobile string, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||||
return dao.GetUsers(dao.GetDB(), userType, keyword, userIDs, userID2, mobile)
|
userList, totalCount, err := dao.GetUsers(dao.GetDB(), userType, keyword, userIDs, userID2, mobile, offset, pageSize)
|
||||||
|
if err == nil {
|
||||||
|
pagedInfo = &model.PagedInfo{
|
||||||
|
TotalCount: totalCount,
|
||||||
|
Data: userList,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pagedInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStoreList4User(ctx *jxcontext.Context, mobileNum, userID string) (storeList []*dao.StoreWithCityName, err error) {
|
func GetStoreList4User(ctx *jxcontext.Context, mobileNum, userID string) (storeList []*dao.StoreWithCityName, err error) {
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ func HandleUserWXRemark(db *dao.DaoDB, mobile string) (err error) {
|
|||||||
storeID = wxinfo.JxStoreID
|
storeID = wxinfo.JxStoreID
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
userList, err2 := dao.GetUsers(db, model.UserTypeStoreBoss, "", nil, "", mobile)
|
userList, _, err2 := dao.GetUsers(db, model.UserTypeStoreBoss, "", nil, "", mobile, 0, -1)
|
||||||
if err = err2; len(userList) > 0 {
|
if err = err2; len(userList) > 0 {
|
||||||
userID := userList[0].GetID()
|
userID := userList[0].GetID()
|
||||||
authBind, err2 := dao.GetAuthBind(db, userID, weixin.AuthTypeMP, "")
|
authBind, err2 := dao.GetAuthBind(db, userID, weixin.AuthTypeMP, "")
|
||||||
|
|||||||
@@ -23,12 +23,15 @@ func GetUserByID(db *DaoDB, fieldName, fieldValue string) (user *model.User, err
|
|||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUsers(db *DaoDB, userType int, keyword string, userIDs []string, userID2, mobile string) (userList []*model.User, err error) {
|
func GetUsers(db *DaoDB, userType int, keyword string, userIDs []string, userID2, mobile string, offset, pageSize int) (userList []*model.User, totalCount int, err error) {
|
||||||
|
offset = FormalizePageOffset(offset)
|
||||||
|
pageSize = FormalizePageSize(pageSize)
|
||||||
if userType == 0 {
|
if userType == 0 {
|
||||||
userType = 255
|
userType = 255
|
||||||
}
|
}
|
||||||
sql := `
|
sql := `
|
||||||
SELECT *
|
SELECT SQL_CALC_FOUND_ROWS
|
||||||
|
t1.*
|
||||||
FROM user t1
|
FROM user t1
|
||||||
WHERE t1.status = 1 AND t1.deleted_at = ? AND t1.type & ? <> 0`
|
WHERE t1.status = 1 AND t1.deleted_at = ? AND t1.type & ? <> 0`
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
@@ -52,6 +55,12 @@ func GetUsers(db *DaoDB, userType int, keyword string, userIDs []string, userID2
|
|||||||
sql += " AND (t1.user_id2 LIKE ? OR t1.mobile LIKE ? OR t1.email LIKE ? OR t1.name LIKE ?)"
|
sql += " AND (t1.user_id2 LIKE ? OR t1.mobile LIKE ? OR t1.email LIKE ? OR t1.name LIKE ?)"
|
||||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike)
|
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||||
}
|
}
|
||||||
err = GetRows(db, &userList, sql, sqlParams...)
|
sql += " LIMIT ? OFFSET ?"
|
||||||
return userList, err
|
sqlParams = append(sqlParams, pageSize, offset)
|
||||||
|
Begin(db)
|
||||||
|
defer Rollback(db)
|
||||||
|
if err = GetRows(db, &userList, sql, sqlParams...); err == nil {
|
||||||
|
totalCount = GetLastTotalRowCount(db)
|
||||||
|
}
|
||||||
|
return userList, totalCount, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ func (c *User2Controller) GetBindAuthInfo() {
|
|||||||
// @Param userIDs query string faslse "用户id列表"
|
// @Param userIDs query string faslse "用户id列表"
|
||||||
// @Param userID2 query string faslse "用户id2,必须全匹配(外部唯一标识)"
|
// @Param userID2 query string faslse "用户id2,必须全匹配(外部唯一标识)"
|
||||||
// @Param mobile query string faslse "用户手机,必须全匹配"
|
// @Param mobile query string faslse "用户手机,必须全匹配"
|
||||||
|
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||||
|
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /GetUsers [get]
|
// @router /GetUsers [get]
|
||||||
@@ -68,7 +70,7 @@ func (c *User2Controller) GetUsers() {
|
|||||||
c.callGetUsers(func(params *tUser2GetUsersParams) (retVal interface{}, errCode string, err error) {
|
c.callGetUsers(func(params *tUser2GetUsersParams) (retVal interface{}, errCode string, err error) {
|
||||||
var userIDs []string
|
var userIDs []string
|
||||||
if err = jxutils.Strings2Objs(params.UserIDs, &userIDs); err == nil {
|
if err = jxutils.Strings2Objs(params.UserIDs, &userIDs); err == nil {
|
||||||
retVal, err = cms.GetUsers(params.Ctx, params.UserType, params.Keyword, userIDs, params.UserID2, params.Mobile)
|
retVal, err = cms.GetUsers(params.Ctx, params.UserType, params.Keyword, userIDs, params.UserID2, params.Mobile, params.Offset, params.PageSize)
|
||||||
}
|
}
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user