添加用户头像问题
This commit is contained in:
parent
6ee3e79c75
commit
321d29c43e
@ -57,6 +57,8 @@ public class ClientUserAuthConverter implements UserAuthenticationConverter {
|
||||
userInfoBO.setUserUsername(userInfo.get("username").toString());
|
||||
userInfoBO.setUserName(userInfo.get("userName").toString());
|
||||
userInfoBO.setUserPhone(userInfo.get("userPhone") == null ? "" : userInfo.get("userPhone").toString());
|
||||
userInfoBO.setUserAvatar(userInfo.get("userAvatar") == null ? "" : userInfo.get("userAvatar").toString());
|
||||
userInfoBO.setUserEmail(userInfo.get("userEmail") == null ? "" : userInfo.get("userEmail").toString());
|
||||
if (ISystemConstant.ADMIN.equals(principal.toString())) {
|
||||
authorities = new LinkedHashSet<>();
|
||||
authorities.add(new RoleGrantedAuthority("ROLE_ALL"));
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.cm.common.plugin.oauth.service.user;
|
||||
|
||||
import com.cm.common.plugin.pojo.bos.user.UserDepartmentResourceBO;
|
||||
import com.cm.common.result.SuccessResultLayImData;
|
||||
|
||||
import java.util.List;
|
||||
@ -17,6 +18,15 @@ import java.util.Map;
|
||||
*/
|
||||
public interface IUserImService {
|
||||
|
||||
/**
|
||||
* 用户默认头像
|
||||
*/
|
||||
String DEFAULT_USER_AVATAR = "assets/images/chat_user.png";
|
||||
/**
|
||||
* 组默认头像
|
||||
*/
|
||||
String DEFAULT_GROUP_AVATAR = "assets/images/chat_group.png";
|
||||
|
||||
/**
|
||||
* 获取初始化数据
|
||||
*
|
||||
@ -32,5 +42,19 @@ public interface IUserImService {
|
||||
*/
|
||||
List<SuccessResultLayImData.Friend> listDepartmentUser(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 获取成员数据
|
||||
*
|
||||
* @param departmentId
|
||||
* @return
|
||||
*/
|
||||
SuccessResultLayImData<SuccessResultLayImData.MemberData> getMemberData(String departmentId);
|
||||
|
||||
/**
|
||||
* 部门用户列表(包含系统管理员)
|
||||
*
|
||||
* @param departmentIds
|
||||
* @return
|
||||
*/
|
||||
List<UserDepartmentResourceBO> listUserDepartmentResource(List<String> departmentIds);
|
||||
}
|
||||
|
@ -44,23 +44,30 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
|
||||
@Override
|
||||
public SuccessResultLayImData<SuccessResultLayImData.InitData> getInitData() {
|
||||
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.setUsername(StringUtils.equals(currentUser.getUserUsername(), ISystemConstant.ADMIN) ? "系统管理员" : currentUser.getUserName());
|
||||
if (StringUtils.isBlank(currentUser.getUserAvatar())) {
|
||||
mine.setAvatar(DEFAULT_USER_AVATAR);
|
||||
} else {
|
||||
mine.setAvatar(apiPathProperties.getUserCenter() + "/route/file/downloadfile/true/" + currentUser.getUserAvatar());
|
||||
}
|
||||
mine.setStatus("online");
|
||||
mine.setSign("暂无签名");
|
||||
|
||||
Map<String, Object> params = getHashMap(2);
|
||||
// 用户所在部门集合
|
||||
Set<SuccessResultLayImData.Friend> userFriendSet = new HashSet<>();
|
||||
|
||||
// 用户所在部门ID集合
|
||||
Set<String> userFriendIdSet = new HashSet<>();
|
||||
// 朋友
|
||||
List<SuccessResultLayImData.Friend> friends = listDepartmentUser(params);
|
||||
setFriends(currentUser, mine, friends, userFriendIdSet);
|
||||
setFriends(currentUser, mine, friends, userFriendSet);
|
||||
|
||||
// 用户组
|
||||
List<SuccessResultLayImData.Group> groups = new ArrayList<>();
|
||||
setGroups(currentUser, friends, groups, userFriendIdSet);
|
||||
setGroups(currentUser, friends, groups, userFriendSet);
|
||||
|
||||
SuccessResultLayImData.InitData initData = new SuccessResultLayImData.InitData();
|
||||
initData.setMine(mine);
|
||||
@ -96,12 +103,16 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
|
||||
user.setUsername(userDepartmentResourceBO.getUserName());
|
||||
user.setSign("暂无签名");
|
||||
if (StringUtils.isBlank(userDepartmentResourceBO.getUserAvatar())) {
|
||||
user.setAvatar("assets/images/chat_user.png");
|
||||
user.setAvatar(DEFAULT_USER_AVATAR);
|
||||
} else {
|
||||
user.setAvatar(apiPathProperties.getUserCenter() + "/route/file/downloadfile/true/" + user.getAvatar());
|
||||
user.setAvatar(apiPathProperties.getUserCenter() + "/route/file/downloadfile/true/" + userDepartmentResourceBO.getUserAvatar());
|
||||
}
|
||||
list.add(user);
|
||||
}
|
||||
// 添加管理员
|
||||
SuccessResultLayImData.User adminUser = getAdminUser();
|
||||
adminUser.setAvatar(DEFAULT_USER_AVATAR);
|
||||
list.add(adminUser);
|
||||
return new SuccessResultLayImData<>(0, "", memberData);
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
@ -109,6 +120,19 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserDepartmentResourceBO> listUserDepartmentResource(List<String> departmentIds) {
|
||||
List<UserDepartmentResourceBO> userDepartmentResourceBOS = userService.listUserDepartmentResourceByDepartmentIds(departmentIds);
|
||||
// 添加系统管理员
|
||||
UserDepartmentResourceBO userDepartmentResourceBO = new UserDepartmentResourceBO();
|
||||
userDepartmentResourceBO.setUserId("1");
|
||||
userDepartmentResourceBO.setUserUsername(ISystemConstant.ADMIN);
|
||||
userDepartmentResourceBO.setUserName("系统管理员");
|
||||
userDepartmentResourceBO.setUserAvatar(DEFAULT_USER_AVATAR);
|
||||
userDepartmentResourceBOS.add(userDepartmentResourceBO);
|
||||
return userDepartmentResourceBOS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置朋友列表
|
||||
*
|
||||
@ -116,19 +140,15 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
|
||||
* @param mine
|
||||
* @param friends
|
||||
*/
|
||||
private void setFriends(UserInfoBO currentUser, SuccessResultLayImData.User mine, List<SuccessResultLayImData.Friend> friends, Set<String> userFriendIdSet) {
|
||||
private void setFriends(UserInfoBO currentUser, SuccessResultLayImData.User mine, List<SuccessResultLayImData.Friend> friends, Set<SuccessResultLayImData.Friend> userFriendSet) {
|
||||
// 非管理员添加系统管理员
|
||||
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");
|
||||
mine.setStatus("offline");
|
||||
user.setUsername("系统管理员");
|
||||
List<SuccessResultLayImData.User> users = new ArrayList<>();
|
||||
users.add(user);
|
||||
users.add(getAdminUser());
|
||||
adminFriend.setList(users);
|
||||
friends.add(adminFriend);
|
||||
}
|
||||
@ -138,13 +158,13 @@ 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());
|
||||
userFriendSet.add(friend);
|
||||
friend.getList().remove(j);
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isBlank(user.getAvatar())) {
|
||||
user.setAvatar("assets/images/chat_user.png");
|
||||
user.setAvatar(DEFAULT_USER_AVATAR);
|
||||
} else {
|
||||
user.setAvatar(apiPathProperties.getUserCenter() + "/route/file/downloadfile/true/" + user.getAvatar());
|
||||
}
|
||||
@ -160,6 +180,19 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统管理员
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private SuccessResultLayImData.User getAdminUser() {
|
||||
SuccessResultLayImData.User user = new SuccessResultLayImData.User();
|
||||
user.setId("1");
|
||||
user.setStatus("offline");
|
||||
user.setUsername("系统管理员");
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置组
|
||||
*
|
||||
@ -168,27 +201,24 @@ public class UserImServiceImpl extends AbstractService implements IUserImService
|
||||
* @param groups
|
||||
* @param userFriendIdSet
|
||||
*/
|
||||
private void setGroups(UserInfoBO currentUser, List<SuccessResultLayImData.Friend> friends, List<SuccessResultLayImData.Group> groups, Set<String> userFriendIdSet) {
|
||||
private void setGroups(UserInfoBO currentUser, List<SuccessResultLayImData.Friend> friends, List<SuccessResultLayImData.Group> groups, Set<SuccessResultLayImData.Friend> userFriendSet) {
|
||||
// 管理员添加所有组
|
||||
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");
|
||||
group.setAvatar(DEFAULT_GROUP_AVATAR);
|
||||
groups.add(group);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 非管理员添加自己所在部门
|
||||
for (SuccessResultLayImData.Friend friend : friends) {
|
||||
if (!userFriendIdSet.contains(friend.getId())) {
|
||||
continue;
|
||||
}
|
||||
for (SuccessResultLayImData.Friend friend : userFriendSet) {
|
||||
SuccessResultLayImData.Group group = new SuccessResultLayImData.Group();
|
||||
group.setId(friend.getId());
|
||||
group.setGroupname(friend.getGroupname());
|
||||
group.setAvatar("assets/images/chat_group.png");
|
||||
group.setAvatar(DEFAULT_GROUP_AVATAR);
|
||||
groups.add(group);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user