From a6ff68ab82ef49a26f1d03a341b5ca01d7feb86d Mon Sep 17 00:00:00 2001 From: wanggeng888 <450292408@qq.com> Date: Mon, 18 Jan 2021 13:02:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8D=B3=E4=BD=BF=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cm/common/plugin/IApiConsts.java | 5 + .../apis/user/UserImController.java | 38 +++++++ .../oauth/service/user/IUserImService.java | 34 +++++++ .../oauth/service/user/IUserService.java | 1 + .../service/user/impl/UserImServiceImpl.java | 99 +++++++++++++++++++ 5 files changed, 177 insertions(+) create mode 100644 cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserImController.java create mode 100644 cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserImService.java create mode 100644 cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserImServiceImpl.java 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 0675467..b94b5a6 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 @@ -201,4 +201,9 @@ public interface IApiConsts { */ String LIST_USER_RESOURCE_BY_KEYWORDS = "%s/resource/user/listresourcebykeywords/%s"; + /** + * LayIM 部门用户 + */ + String LIST_LAYIM_DEPARTMENT_USER = "%s/resource/user/im/listdepartmentuser"; + } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserImController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserImController.java new file mode 100644 index 0000000..a9c6e47 --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserImController.java @@ -0,0 +1,38 @@ +package com.cm.common.plugin.oauth.controller.apis.user; + +import com.cm.common.constants.ISystemConstant; +import com.cm.common.plugin.oauth.service.user.IUserImService; +import com.cm.common.result.ErrorResult; +import com.cm.common.result.SuccessResultLayImData; +import io.swagger.annotations.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: DepartmentUserController + * @Description: 用户即时消息 + * @Author: wanggeng + * @Date: 2021/1/15 10:03 上午 + * @Version: 1.0 + */ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "用户即时消息") +@RestController +@RequestMapping(ISystemConstant.API_PREFIX + "/user/im") +public class UserImController { + + @Autowired + private IUserImService userImService; + + @ApiOperation(value = "获取初始化数据", notes = "获取初始化数据接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("getinitdata") + public SuccessResultLayImData getInitData() { + return userImService.getInitData(); + } + +} diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserImService.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserImService.java new file mode 100644 index 0000000..030a160 --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserImService.java @@ -0,0 +1,34 @@ +package com.cm.common.plugin.oauth.service.user; + +import com.cm.common.result.SuccessResultLayImData; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IUserDepartmentService + * @Description: 用户即时消息 + * @Author: wanggeng + * @Date: 2021/1/15 10:05 上午 + * @Version: 1.0 + */ +public interface IUserImService { + + /** + * 获取初始化数据 + * + * @return + */ + SuccessResultLayImData getInitData(); + + /** + * 部门用户列表 + * + * @param params + * @return + */ + List listDepartmentUser(Map params); +} 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 19cd083..41fd31b 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 @@ -8,6 +8,7 @@ import com.cm.common.plugin.pojo.bos.UserResourceBO; import com.cm.common.plugin.pojo.bos.user.UserDepartmentResourceBO; import com.cm.common.pojo.ListPage; import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultLayImData; import com.cm.common.result.SuccessResultList; import org.aspectj.lang.annotation.DeclareError; diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserImServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserImServiceImpl.java new file mode 100644 index 0000000..81aedd4 --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserImServiceImpl.java @@ -0,0 +1,99 @@ +package com.cm.common.plugin.oauth.service.user.impl; + +import com.alibaba.fastjson.JSONArray; +import com.cm.common.base.AbstractService; +import com.cm.common.config.properties.ApiPathProperties; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.plugin.IApiConsts; +import com.cm.common.plugin.oauth.service.department.IDepartmentService; +import com.cm.common.plugin.oauth.service.user.IUserImService; +import com.cm.common.plugin.oauth.service.user.IUserService; +import com.cm.common.plugin.oauth.token.ClientTokenManager; +import com.cm.common.plugin.utils.RestTemplateUtil; +import com.cm.common.pojo.bos.UserInfoBO; +import com.cm.common.result.SuccessResultLayImData; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: UserDepartmentServiceImpl + * @Description: 用户即时消息 + * @Author: wanggeng + * @Date: 2021/1/15 10:05 上午 + * @Version: 1.0 + */ +@Service +public class UserImServiceImpl extends AbstractService implements IUserImService { + + @Autowired + private IUserService userService; + @Autowired + private IDepartmentService departmentService; + @Autowired + private RestTemplateUtil restTemplateUtil; + @Autowired + private ApiPathProperties apiPathProperties; + + @Override + public SuccessResultLayImData getInitData() { + UserInfoBO currentUser = securityComponent.getCurrentUser(); + SuccessResultLayImData.User mine = new SuccessResultLayImData.User(); + mine.setId(currentUser.getUserId()); + mine.setUsername(currentUser.getUserName()); + mine.setAvatar("assets/images/random-avatar1.jpg"); + mine.setStatus("online"); + mine.setSign(""); + + Map params = getHashMap(2); + + List friends = listDepartmentUser(params); + // 非管理员添加系统管理员 + if(!StringUtils.equals(ISystemConstant.ADMIN, currentUser.getUserUsername())) { + // 加载管理员 + SuccessResultLayImData.Friend adminFriend = new SuccessResultLayImData.Friend(); + adminFriend.setId("admin"); + adminFriend.setGroupname("管理员"); + SuccessResultLayImData.User user = new SuccessResultLayImData.User(); + user.setId("1"); + user.setUsername("系统管理员"); + List users = new ArrayList<>(); + users.add(user); + adminFriend.setList(users); + friends.add(adminFriend); + } + for (SuccessResultLayImData.Friend friend : friends) { + for (SuccessResultLayImData.User user : friend.getList()) { + if (StringUtils.isBlank(user.getAvatar())) { + user.setAvatar("assets/images/random-avatar1.jpg"); + } else { + user.setAvatar(apiPathProperties.getUserCenter() + "/route/file/downloadfile/true/" + user.getAvatar()); + } + user.setStatus("online"); + user.setSign(""); + } + } + + SuccessResultLayImData.InitData initData = new SuccessResultLayImData.InitData(); + initData.setMine(mine); + initData.setFriend(friends); + initData.setGroup(new ArrayList<>()); + return new SuccessResultLayImData<>(0, "", initData); + } + + @Override + public List listDepartmentUser(Map params) { + params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken()); + String result = restTemplateUtil.doGetFormNormal(String.format(IApiConsts.LIST_LAYIM_DEPARTMENT_USER, apiPathProperties.getUserCenter()), params); + searchResourceResult(result, "获取人员列表失败"); + List friends = JSONArray.parseArray(result, SuccessResultLayImData.Friend.class); + return friends; + } +}