新增IM群成员列表

This commit is contained in:
wanggeng888 2021-01-20 12:37:06 +08:00
parent e0dbaa1172
commit bca839bfcf
3 changed files with 118 additions and 26 deletions

View File

@ -8,6 +8,7 @@ import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
@ -35,4 +36,11 @@ public class UserImController {
return userImService.getInitData(); return userImService.getInitData();
} }
@ApiOperation(value = "获取组成员数据", notes = "获取组成员数据接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("getmemberdata")
public SuccessResultLayImData<SuccessResultLayImData.MemberData> getMemberData(@RequestParam(name = "id", required = true) String departmentId) {
return userImService.getMemberData(departmentId);
}
} }

View File

@ -31,4 +31,6 @@ public interface IUserImService {
* @return * @return
*/ */
List<SuccessResultLayImData.Friend> listDepartmentUser(Map<String, Object> params); List<SuccessResultLayImData.Friend> listDepartmentUser(Map<String, Object> params);
SuccessResultLayImData<SuccessResultLayImData.MemberData> getMemberData(String departmentId);
} }

View File

@ -9,6 +9,7 @@ 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.IUserImService;
import com.cm.common.plugin.oauth.service.user.IUserService; import com.cm.common.plugin.oauth.service.user.IUserService;
import com.cm.common.plugin.oauth.token.ClientTokenManager; import com.cm.common.plugin.oauth.token.ClientTokenManager;
import com.cm.common.plugin.pojo.bos.user.UserDepartmentResourceBO;
import com.cm.common.plugin.utils.RestTemplateUtil; import com.cm.common.plugin.utils.RestTemplateUtil;
import com.cm.common.pojo.bos.UserInfoBO; import com.cm.common.pojo.bos.UserInfoBO;
import com.cm.common.result.SuccessResultLayImData; import com.cm.common.result.SuccessResultLayImData;
@ -16,9 +17,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
/** /**
* When you feel like quitting. Think about why you started * When you feel like quitting. Think about why you started
@ -44,6 +43,7 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
@Override @Override
public SuccessResultLayImData<SuccessResultLayImData.InitData> getInitData() { public SuccessResultLayImData<SuccessResultLayImData.InitData> getInitData() {
try {
UserInfoBO currentUser = securityComponent.getCurrentUser(); UserInfoBO currentUser = securityComponent.getCurrentUser();
SuccessResultLayImData.User mine = new SuccessResultLayImData.User(); SuccessResultLayImData.User mine = new SuccessResultLayImData.User();
mine.setId(currentUser.getUserId()); mine.setId(currentUser.getUserId());
@ -54,7 +54,69 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
Map<String, Object> params = getHashMap(2); Map<String, Object> params = getHashMap(2);
// 用户所在部门ID集合
Set<String> userFriendIdSet = new HashSet<>();
List<SuccessResultLayImData.Friend> friends = listDepartmentUser(params); List<SuccessResultLayImData.Friend> friends = listDepartmentUser(params);
setFriends(currentUser, mine, friends, userFriendIdSet);
List<SuccessResultLayImData.Group> groups = new ArrayList<>();
setGroups(currentUser, friends, groups, userFriendIdSet);
SuccessResultLayImData.InitData initData = new SuccessResultLayImData.InitData();
initData.setMine(mine);
initData.setFriend(friends);
initData.setGroup(groups);
return new SuccessResultLayImData<>(0, "", initData);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return new SuccessResultLayImData<>(400, e.getMessage(), null);
}
}
@Override
public List<SuccessResultLayImData.Friend> listDepartmentUser(Map<String, Object> 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, "获取人员列表失败");
return JSONArray.parseArray(result, SuccessResultLayImData.Friend.class);
}
@Override
public SuccessResultLayImData<SuccessResultLayImData.MemberData> getMemberData(String departmentId) {
try {
List<String> departmentIds = new ArrayList<>();
departmentIds.add(departmentId);
List<UserDepartmentResourceBO> userDepartmentResourceBOS = userService.listUserDepartmentResourceByDepartmentIds(departmentIds);
SuccessResultLayImData.MemberData memberData = new SuccessResultLayImData.MemberData();
List<SuccessResultLayImData.User> list = new ArrayList<>();
memberData.setList(list);
for (UserDepartmentResourceBO userDepartmentResourceBO : userDepartmentResourceBOS) {
SuccessResultLayImData.User user = new SuccessResultLayImData.User();
user.setId(userDepartmentResourceBO.getUserId());
user.setUsername(userDepartmentResourceBO.getUserName());
user.setSign("暂无签名");
if (StringUtils.isBlank(userDepartmentResourceBO.getUserAvatar())) {
user.setAvatar("assets/images/chat_user.png");
} else {
user.setAvatar(apiPathProperties.getUserCenter() + "/route/file/downloadfile/true/" + user.getAvatar());
}
list.add(user);
}
return new SuccessResultLayImData<>(0, "", memberData);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return new SuccessResultLayImData<>(400, e.getMessage(), null);
}
}
/**
* 设置朋友列表
*
* @param currentUser
* @param mine
* @param friends
*/
private void setFriends(UserInfoBO currentUser, SuccessResultLayImData.User mine, List<SuccessResultLayImData.Friend> friends, Set<String> userFriendIdSet) {
// 非管理员添加系统管理员 // 非管理员添加系统管理员
if (!StringUtils.equals(ISystemConstant.ADMIN, currentUser.getUserUsername())) { if (!StringUtils.equals(ISystemConstant.ADMIN, currentUser.getUserUsername())) {
// 加载管理员 // 加载管理员
@ -76,15 +138,17 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
SuccessResultLayImData.User user = friend.getList().get(j); SuccessResultLayImData.User user = friend.getList().get(j);
// 删除自己 // 删除自己
if (StringUtils.equals(user.getId(), mine.getId())) { if (StringUtils.equals(user.getId(), mine.getId())) {
userFriendIdSet.add(friend.getId());
friend.getList().remove(j); friend.getList().remove(j);
j--; j--;
continue; continue;
} }
if (StringUtils.isBlank(user.getAvatar())) { if (StringUtils.isBlank(user.getAvatar())) {
user.setAvatar("assets/images/random-avatar1.jpg"); user.setAvatar("assets/images/chat_user.png");
} else { } else {
user.setAvatar(apiPathProperties.getUserCenter() + "/route/file/downloadfile/true/" + user.getAvatar()); user.setAvatar(apiPathProperties.getUserCenter() + "/route/file/downloadfile/true/" + user.getAvatar());
} }
// 默认离线
user.setStatus("offline"); user.setStatus("offline");
user.setSign("暂无签名"); user.setSign("暂无签名");
} }
@ -94,20 +158,38 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
i--; i--;
} }
} }
SuccessResultLayImData.InitData initData = new SuccessResultLayImData.InitData();
initData.setMine(mine);
initData.setFriend(friends);
initData.setGroup(new ArrayList<>());
return new SuccessResultLayImData<>(0, "", initData);
} }
@Override /**
public List<SuccessResultLayImData.Friend> listDepartmentUser(Map<String, Object> params) { * 设置组
params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken()); *
String result = restTemplateUtil.doGetFormNormal(String.format(IApiConsts.LIST_LAYIM_DEPARTMENT_USER, apiPathProperties.getUserCenter()), params); * @param currentUser
searchResourceResult(result, "获取人员列表失败"); * @param friends
List<SuccessResultLayImData.Friend> friends = JSONArray.parseArray(result, SuccessResultLayImData.Friend.class); * @param groups
return friends; * @param userFriendIdSet
*/
private void setGroups(UserInfoBO currentUser, List<SuccessResultLayImData.Friend> friends, List<SuccessResultLayImData.Group> groups, Set<String> userFriendIdSet) {
// 管理员添加所有组
if (StringUtils.equals(ISystemConstant.ADMIN, currentUser.getUserUsername())) {
for (SuccessResultLayImData.Friend friend : friends) {
SuccessResultLayImData.Group group = new SuccessResultLayImData.Group();
group.setId(friend.getId());
group.setGroupname(friend.getGroupname());
group.setAvatar("assets/images/chat_group.png");
groups.add(group);
}
return;
}
// 非管理员添加自己所在部门
for (SuccessResultLayImData.Friend friend : friends) {
if (!userFriendIdSet.contains(friend.getId())) {
continue;
}
SuccessResultLayImData.Group group = new SuccessResultLayImData.Group();
group.setId(friend.getId());
group.setGroupname(friend.getGroupname());
group.setAvatar("assets/images/chat_group.png");
groups.add(group);
}
} }
} }