diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java index b94b5a6..f0cbade 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java @@ -59,6 +59,11 @@ public interface IApiConsts { */ String LIST_USER_BY_ID = "%s/resource/user/listuserbyids"; + /** + * 用户列表,通过用户名 + */ + String LIST_USER_BY_USERNAME = "%s/resource/user/listuserbyusernames"; + /** * 全部用户 */ diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java index 41fd31b..3d615a7 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java @@ -237,6 +237,16 @@ public interface IUserService { */ List listUserResourceByIds(List userIds) throws AccessTokenException, SearchException; + /** + * 用户列表 + * + * @param usernames 用户名列表 + * @return + * @throws AccessTokenException + * @throws SearchException + */ + List listUserResourceByUsernames(List usernames) throws AccessTokenException, SearchException; + /** * 用户动态详情列表(通过id列表) * diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java index dceb788..2269585 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java @@ -224,6 +224,26 @@ public class UserServiceImpl extends AbstractService implements IUserService { return JSONArray.parseArray(result, UserResourceBO.class); } + @Override + public List listUserResourceByUsernames(List usernames) throws AccessTokenException, SearchException { + if (usernames == null || usernames.isEmpty()) { + return new ArrayList<>(); + } + StringBuilder usernamesSB = new StringBuilder(); + for (String username : usernames) { + if (usernamesSB.length() > 0) { + usernamesSB.append("_"); + } + usernamesSB.append(username); + } + Map params = getHashMap(4); + params.put("usernames", usernamesSB.toString()); + params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken()); + String result = restTemplateUtil.doPostFormNormal(String.format(IApiConsts.LIST_USER_BY_USERNAME, apiPathProperties.getUserCenter()), params); + searchResourceResult(result, "获取人员列表失败"); + return JSONArray.parseArray(result, UserResourceBO.class); + } + @Override public JSONArray listDynamicUserInfoByIds(List userIds) throws AccessTokenException, SearchException { if (userIds == null || userIds.isEmpty()) {