From a0c74cf02a1ea879649561f335cedc3d01da4e0b Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 6 Aug 2019 16:35:37 +0800 Subject: [PATCH] =?UTF-8?q?-=20GetUsers=E6=8E=A5=E5=8F=A3=E6=94=B9?= =?UTF-8?q?=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/authz.go | 2 +- business/jxstore/cms/user2.go | 4 ++-- business/model/dao/dao_user2.go | 15 ++++++++------- controllers/auth2.go | 6 +++--- controllers/cms_user2.go | 9 ++++++--- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/business/jxstore/cms/authz.go b/business/jxstore/cms/authz.go index 9392f6e48..5d61e8755 100644 --- a/business/jxstore/cms/authz.go +++ b/business/jxstore/cms/authz.go @@ -51,7 +51,7 @@ func TransferLegacyWeixins() (err error) { if user.Name == "" { user.Name = user.Mobile } - userList, err2 := dao.GetUsers(db, 0, "", "", v.Tel, "") + userList, err2 := dao.GetUsers(db, 0, "", nil, "", v.Tel) if err = err2; err != nil { return err } diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index e1764c898..5695b7f4b 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -153,6 +153,6 @@ func OnDingDingMsg(msg map[string]interface{}) (callbackResponse *dingdingapi.Ca return api.DingDingAPI.Err2CallbackResponse(nil) } -func GetUsers(ctx *jxcontext.Context, userType int, userID, userID2, mobile, userName string) (userList []*model.User, err error) { - return dao.GetUsers(dao.GetDB(), userType, userID, userID2, mobile, userName) +func GetUsers(ctx *jxcontext.Context, userType int, keyword string, userIDs []string, userID2, mobile string) (userList []*model.User, err error) { + return dao.GetUsers(dao.GetDB(), userType, keyword, userIDs, userID2, mobile) } diff --git a/business/model/dao/dao_user2.go b/business/model/dao/dao_user2.go index d6d01d4c3..cb7c2bf30 100644 --- a/business/model/dao/dao_user2.go +++ b/business/model/dao/dao_user2.go @@ -23,7 +23,7 @@ func GetUserByID(db *DaoDB, fieldName, fieldValue string) (user *model.User, err return user, err } -func GetUsers(db *DaoDB, userType int, userID, userID2, mobile, userName string) (userList []*model.User, err error) { +func GetUsers(db *DaoDB, userType int, keyword string, userIDs []string, userID2, mobile string) (userList []*model.User, err error) { if userType == 0 { userType = 255 } @@ -35,9 +35,9 @@ func GetUsers(db *DaoDB, userType int, userID, userID2, mobile, userName string) utils.DefaultTimeValue, userType, } - if userID != "" { - sql += " AND t1.user_id = ?" - sqlParams = append(sqlParams, userID) + if len(userIDs) > 0 { + sql += " AND t1.user_id IN (" + GenQuestionMarks(len(userIDs)) + ")" + sqlParams = append(sqlParams, userIDs) } if userID2 != "" { sql += " AND t1.user_id2 = ?" @@ -47,9 +47,10 @@ func GetUsers(db *DaoDB, userType int, userID, userID2, mobile, userName string) sql += " AND t1.mobile = ?" sqlParams = append(sqlParams, mobile) } - if userName != "" { - sql += " AND t1.name LIKE ?" - sqlParams = append(sqlParams, "%"+userName+"%") + if keyword != "" { + keywordLike := "%" + keyword + "%" + 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) } err = GetRows(db, &userList, sql, sqlParams...) return userList, err diff --git a/controllers/auth2.go b/controllers/auth2.go index 8e54b9f9c..4fa2b06c5 100644 --- a/controllers/auth2.go +++ b/controllers/auth2.go @@ -73,9 +73,9 @@ func (c *Auth2Controller) Login() { }) } -// @Title 钉钉认证回调接口 -// @Description 钉钉认证回调接口,自己不能直接调用 -// @Param token header string true "认证token" +// @Title 得到自己登录token的信息 +// @Description 得到自己登录token的信息 +// @Param token header string true "认证token" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /GetTokenInfo [get] diff --git a/controllers/cms_user2.go b/controllers/cms_user2.go index c45c444ca..27e9b1ccf 100644 --- a/controllers/cms_user2.go +++ b/controllers/cms_user2.go @@ -55,16 +55,19 @@ func (c *User2Controller) GetBindAuthInfo() { // @Description 得到用户列表 // @Param token header string true "认证token" // @Param userType query int true "用户类型(0表示全部)" -// @Param userID query string faslse "用户id,必须全匹配(内部唯一标识)" +// @Param keyword query string faslse "关键字,可以部分匹配" +// @Param userIDs query string faslse "用户id列表" // @Param userID2 query string faslse "用户id2,必须全匹配(外部唯一标识)" // @Param mobile query string faslse "用户手机,必须全匹配" -// @Param userName query string faslse "用户名,可以部分匹配" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /GetUsers [get] func (c *User2Controller) GetUsers() { c.callGetUsers(func(params *tUser2GetUsersParams) (retVal interface{}, errCode string, err error) { - retVal, err = cms.GetUsers(params.Ctx, params.UserType, params.UserID, params.UserID2, params.Mobile, params.UserName) + var userIDs []string + if err := jxutils.Strings2Objs(params.UserIDs, &userIDs); err == nil { + retVal, err = cms.GetUsers(params.Ctx, params.UserType, params.Keyword, userIDs, params.UserID2, params.Mobile) + } return retVal, "", err }) }