新增IM群成员列表
This commit is contained in:
parent
e0dbaa1172
commit
bca839bfcf
@ -8,6 +8,7 @@ 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.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
@ -35,4 +36,11 @@ public class UserImController {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,4 +31,6 @@ public interface IUserImService {
|
||||
* @return
|
||||
*/
|
||||
List<SuccessResultLayImData.Friend> listDepartmentUser(Map<String, Object> params);
|
||||
|
||||
SuccessResultLayImData<SuccessResultLayImData.MemberData> getMemberData(String departmentId);
|
||||
}
|
||||
|
@ -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.IUserService;
|
||||
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.pojo.bos.UserInfoBO;
|
||||
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.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
@ -44,17 +43,80 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
|
||||
|
||||
@Override
|
||||
public SuccessResultLayImData<SuccessResultLayImData.InitData> 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("暂无签名");
|
||||
try {
|
||||
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<String, Object> params = getHashMap(2);
|
||||
Map<String, Object> params = getHashMap(2);
|
||||
|
||||
List<SuccessResultLayImData.Friend> friends = listDepartmentUser(params);
|
||||
// 用户所在部门ID集合
|
||||
Set<String> userFriendIdSet = new HashSet<>();
|
||||
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())) {
|
||||
// 加载管理员
|
||||
@ -76,15 +138,17 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
|
||||
SuccessResultLayImData.User user = friend.getList().get(j);
|
||||
// 删除自己
|
||||
if (StringUtils.equals(user.getId(), mine.getId())) {
|
||||
userFriendIdSet.add(friend.getId());
|
||||
friend.getList().remove(j);
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isBlank(user.getAvatar())) {
|
||||
user.setAvatar("assets/images/random-avatar1.jpg");
|
||||
user.setAvatar("assets/images/chat_user.png");
|
||||
} else {
|
||||
user.setAvatar(apiPathProperties.getUserCenter() + "/route/file/downloadfile/true/" + user.getAvatar());
|
||||
}
|
||||
// 默认离线
|
||||
user.setStatus("offline");
|
||||
user.setSign("暂无签名");
|
||||
}
|
||||
@ -94,20 +158,38 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
|
||||
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);
|
||||
searchResourceResult(result, "获取人员列表失败");
|
||||
List<SuccessResultLayImData.Friend> friends = JSONArray.parseArray(result, SuccessResultLayImData.Friend.class);
|
||||
return friends;
|
||||
/**
|
||||
* 设置组
|
||||
*
|
||||
* @param currentUser
|
||||
* @param friends
|
||||
* @param groups
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user