|
@@ -1,6 +1,5 @@
|
|
|
package com.mooctest.crowd.domain.repository;
|
|
|
|
|
|
-import com.google.common.collect.Lists;
|
|
|
import com.mooctest.crowd.domain.dao.*;
|
|
|
import com.mooctest.crowd.domain.domainobject.*;
|
|
|
import com.mooctest.crowd.domain.exception.RoleNotFoundException;
|
|
@@ -173,44 +172,6 @@ public class UserRepo implements IUserRepo {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<User> getByIdList(List<Long> ids) throws RoleNotFoundException {
|
|
|
- Iterable<UserPO> allUserPOById = userDao.findAllById(ids);
|
|
|
- ArrayList<UserPO> userPOArrayList = Lists.newArrayList(allUserPOById);
|
|
|
- List<User> allUserResult = getUserAndRoleAndPermissionListByUserPOList(userPOArrayList);
|
|
|
- return allUserResult;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取机构认证的申请
|
|
|
- *
|
|
|
- * @return
|
|
|
- * @throws RoleNotFoundException
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<User> getApplyEvaluationAgencyByIsAuthenticated() {
|
|
|
- List<UserPO> userPOList = new ArrayList<>();
|
|
|
- evaluationAgencyDao.findByIsAuthentication(AuthenticationStatus.isNotAuthenticated).forEach(evaluationAgencyPO -> {
|
|
|
- userPOList.add(userDao.findById(evaluationAgencyPO.getUserId()).get());
|
|
|
- });
|
|
|
- List<User> allUserResult = getUserAndRoleAndPermissionListByUserPOList(userPOList);
|
|
|
- return allUserResult;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<User> getAllUser() throws RoleNotFoundException {
|
|
|
- Iterable<UserPO> allUserPO = userDao.findAll();
|
|
|
- ArrayList<UserPO> userPOArrayList = Lists.newArrayList(allUserPO);
|
|
|
- List<User> userListByIds = getUserAndRoleAndPermissionListByUserPOList(userPOArrayList);
|
|
|
- return userListByIds;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ArrayList<UserPO> getAllUserInfo() throws RoleNotFoundException {
|
|
|
- Iterable<UserPO> allUserPO = userDao.findAll();
|
|
|
- ArrayList<UserPO> userPOArrayList = Lists.newArrayList(allUserPO);
|
|
|
- return userPOArrayList;
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public UserTaskCount getUserTaskCountByUserId(Long userId) {
|
|
@@ -222,22 +183,6 @@ public class UserRepo implements IUserRepo {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void removeUser(User user) {
|
|
|
- UserPO userPO = Converter.convert(UserPO.class, user);
|
|
|
- userDao.delete(userPO);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void removeUserList(List<User> userList) {
|
|
|
- List<UserPO> userPOList = new ArrayList<>();
|
|
|
- for (User user : userList) {
|
|
|
- UserPO userPO = Converter.convert(UserPO.class, user);
|
|
|
- userPOList.add(userPO);
|
|
|
- }
|
|
|
- userDao.deleteAll(userPOList);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 注册用户时默认为普通用户,分配角色后存入数据库
|
|
|
*
|
|
@@ -257,11 +202,8 @@ public class UserRepo implements IUserRepo {
|
|
|
RolePO rolePO = roleDao.findByName(role.getName());
|
|
|
Role roleConvert = Converter.convert(Role.class, rolePO);
|
|
|
|
|
|
- UserToRolePO userToRolePO = new UserToRolePO();
|
|
|
- userToRolePO.setRoleId(roleConvert.getId());
|
|
|
- userToRolePO.setUserId(saveResultUser.getId());
|
|
|
- userToRolePO.setCreateTime(currentTime);
|
|
|
- userToRoleDao.save(userToRolePO);
|
|
|
+ UserToRole userToRole = new UserToRole(roleConvert.getId(), saveResultUser.getId(), currentTime);
|
|
|
+ userToRoleDao.save(Converter.convert(UserToRolePO.class, userToRole));
|
|
|
|
|
|
Role roleResult = getPermissionByRole(roleConvert);
|
|
|
roleListResult.add(roleResult);
|
|
@@ -322,36 +264,31 @@ public class UserRepo implements IUserRepo {
|
|
|
*/
|
|
|
private User saveRoleAndPermissionAndEvaluationAgencyByUser(User user) throws RoleNotFoundException {
|
|
|
UserPO userPO = userDao.save(Converter.convert(UserPO.class, user));
|
|
|
- User userResult = Converter.convert(User.class, userPO);
|
|
|
- List<Role> roleList = userResult.getRoleList();
|
|
|
+ user.setId(userPO.getId());
|
|
|
|
|
|
- // 新注册用户默认给
|
|
|
- if (roleList == null || roleList.size() == 0) {
|
|
|
- UserToRolePO u2r = new UserToRolePO();
|
|
|
- u2r.setUserId(userResult.getId());
|
|
|
- u2r.setRoleId(1L);
|
|
|
- userToRoleDao.save(u2r);
|
|
|
- }
|
|
|
+ List<Long> roleIdList = userToRoleDao.findByUserId(user.getId()).stream().map(UserToRolePO::getRoleId).collect(Collectors.toList());
|
|
|
|
|
|
- List<UserToRolePO> userToRolePOList = userToRoleDao.findByUserId(userResult.getId());
|
|
|
- if (roleList != null) {
|
|
|
- for (Role role : roleList) {
|
|
|
- if (userToRolePOList.stream().noneMatch(userToRolePO -> userToRolePO.getRoleId().equals(role.getId()))) {
|
|
|
- UserToRolePO userToRolePO = new UserToRolePO();
|
|
|
- userToRolePO.setRoleId(role.getId());
|
|
|
- userToRolePO.setUserId(userResult.getId());
|
|
|
- userToRoleDao.save(userToRolePO);
|
|
|
- }
|
|
|
- }
|
|
|
+ // 新注册用户默认给
|
|
|
+ if (roleIdList == null || roleIdList.size() == 0) {
|
|
|
+ UserToRole userToRole = new UserToRole(1L, user.getId(), new Timestamp(System.currentTimeMillis()));
|
|
|
+ userToRoleDao.save(Converter.convert(UserToRolePO.class, userToRole));
|
|
|
+ }else{
|
|
|
+ List<Role> roleList = user.getRoleList();
|
|
|
+ List<Role> roleListNeedAdd = Optional.ofNullable(roleList).orElse(new ArrayList<>()).stream()
|
|
|
+ .filter(role -> !roleIdList.contains(role.getId())).collect(Collectors.toList());
|
|
|
+ // 判断如果数据库中不存在对应的role就保存
|
|
|
+ Optional.ofNullable(roleListNeedAdd).orElse(new ArrayList<>()).forEach(role -> {
|
|
|
+ UserToRole userToRole = new UserToRole(role.getId(), user.getId(), new Timestamp(System.currentTimeMillis()));
|
|
|
+ userToRoleDao.save(Converter.convert(UserToRolePO.class, userToRole));
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/*机构认证保存机构信息*/
|
|
|
- this.saveEvaluationAgencyInfo(userResult);
|
|
|
+ this.saveEvaluationAgencyInfo(user);
|
|
|
|
|
|
/*实名认证保存个人信息*/
|
|
|
this.savePersonalAuth(user);
|
|
|
-
|
|
|
- return getByID(userPO.getId());
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
private void savePersonalAuth(User user) {
|