Преглед на файлове

校验认证相关接口,进行优化

郭超 преди 4 години
родител
ревизия
2264f8eb72

+ 4 - 1
core/src/main/java/com/mooctest/crowd/domain/domainobject/User.java

@@ -4,6 +4,7 @@ import com.mooctest.crowd.domain.exception.BaseException;
 import com.mooctest.crowd.domain.exception.SystemAdministratorException;
 import com.mooctest.crowd.domain.model.UserPO;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 import org.springframework.beans.BeanUtils;
 
 import java.sql.Date;
@@ -15,7 +16,7 @@ import java.util.List;
  * @date 2019/7/6 18:17
  */
 @Data
-
+@NoArgsConstructor
 public class User {
     private Long id;
     private String name;
@@ -47,6 +48,8 @@ public class User {
         BeanUtils.copyProperties(userPO,this);
     }
 
+
+
     /**
      * 机构认证——申请
      * @param evaluationAgency

+ 28 - 0
core/src/main/java/com/mooctest/crowd/domain/domainobject/UserToRole.java

@@ -0,0 +1,28 @@
+package com.mooctest.crowd.domain.domainobject;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.sql.Timestamp;
+
+/**
+ * @author guochao
+ * @date 2019/7/6 17:54
+ */
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class UserToRole {
+    private Long id;
+    private Long roleId;
+    private Long userId;
+    private Timestamp createTime;
+
+    public UserToRole(Long roleId, Long userId, Timestamp createTime) {
+        this.roleId = roleId;
+        this.userId = userId;
+        this.createTime = createTime;
+    }
+}

+ 0 - 35
core/src/main/java/com/mooctest/crowd/domain/domainservice/RegisterDService.java

@@ -1,35 +0,0 @@
-package com.mooctest.crowd.domain.domainservice;
-
-import com.mooctest.crowd.domain.domainobject.Role;
-import com.mooctest.crowd.domain.domainobject.User;
-import com.mooctest.crowd.domain.factory.UserFactory;
-import com.mooctest.crowd.domain.util.EncryptionUtil;
-import org.springframework.stereotype.Service;
-
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @Author: xuexb
- * @Date: 2019.7.5 14:05
- */
-@Service
-public class RegisterDService {
-
-    public User register(String mobile, String password) {
-        User user = UserFactory.createUser();
-        user.setMobile(mobile);
-        user.setPassword(EncryptionUtil.encryptMD5(password));
-        user.setIsAvailable(1);
-        user.setIsDeleted(0);
-        user.setCreateTime(new Timestamp(System.currentTimeMillis()));
-        List<Role> roleList = new ArrayList<Role>();
-        Role role = new Role();
-        role.setName("generalUser");
-        roleList.add(role);
-        user.setRoleList(roleList);
-        return user;
-    }
-
-}

+ 2 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/IUserRepo.java

@@ -28,6 +28,8 @@ public interface IUserRepo {
 
     UserTaskCount getUserTaskCountByUserId(Long userId);
 
+    User saveUserAndRole(User user);
+
     User saveUser(User user) throws RoleNotFoundException;
 
     User saveUserJustInfo(User user);

+ 19 - 82
core/src/main/java/com/mooctest/crowd/domain/repository/UserRepo.java

@@ -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) {

+ 4 - 3
site/src/main/java/com/mooctest/crowd/site/anticorruption/impl/UserAntiCorruptionImpl.java

@@ -9,6 +9,7 @@ import com.mooctest.crowd.domain.factory.UserFactory;
 import com.mooctest.crowd.domain.repository.UserRepo;
 import com.mooctest.crowd.site.anticorruption.UserAntiCorruption;
 import com.mooctest.crowd.site.anticorruption.impl.data.UserInfo;
+import com.mooctest.crowd.site.data.enums.RoleType;
 import com.mooctest.crowd.site.util.EncryptionUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -73,15 +74,15 @@ public class UserAntiCorruptionImpl implements UserAntiCorruption {
         log.info("userInfo: " + userInfo.toString());
         try{
             //将用户中心的用户中心的用户数据对本系统内同步,直同步用户邮箱、手机号、密码
-            User oldUser = userRepo.getByID(userId);
+            User oldUser = userRepo.getByIDJustInfo(userId);
             oldUser.setEmail(userInfo.getEmail());
             oldUser.setMobile(userInfo.getMobile());
             oldUser.setPassword(userInfo.getPassword());
-            userRepo.saveUser(oldUser);
+            userRepo.saveUserJustInfo(oldUser);
         }catch (UserNotExistException e){   //本站不存在该用户,是未同步信息的新用户,初始化角色
             User user = userInfo.toUser();
             List<Role> roles = new ArrayList<>();
-            roles.add(userRepo.getRole("generalUser"));
+            roles.add(userRepo.getRole(RoleType.GENERAL_USER.getName()));
             user.setRoleList(roles);
             userRepo.saveUser(user);
         }

+ 1 - 1
site/src/main/java/com/mooctest/crowd/site/controller/UserController.java

@@ -108,7 +108,7 @@ public class UserController extends BaseController{
      * 获取邮箱验证码
      */
     @RequestMapping(value = "/verify/email", method = RequestMethod.PUT)
-    public ResponseVO<Object> verifyMail(@RequestBody ModifyCommand modifyCommand, HttpServletRequest request) throws InvocationTargetException, IllegalAccessException {
+    public ResponseVO<Object> verifyEmail(@RequestBody ModifyCommand modifyCommand, HttpServletRequest request) throws InvocationTargetException, IllegalAccessException {
         return userService.verifyMail(modifyCommand, request);
     }
 

+ 0 - 9
site/src/main/java/com/mooctest/crowd/site/data/vo/BaseAuthVO.java

@@ -1,6 +1,5 @@
 package com.mooctest.crowd.site.data.vo;
 
-import com.mooctest.crowd.domain.domainobject.EnterpriseAuthentication;
 import com.mooctest.crowd.domain.domainobject.EvaluationAgency;
 import com.mooctest.crowd.domain.domainobject.PersonalAuthentication;
 import lombok.Data;
@@ -28,14 +27,6 @@ public class BaseAuthVO {
         this.authStatus = new StatusVO(personalAuthentication.getIsAuthentication());
     }
 
-    public BaseAuthVO(EnterpriseAuthentication enterpriseAuthentication){
-
-        this.applytime = enterpriseAuthentication.getApplyTime();
-        this.userId = enterpriseAuthentication.getUserId();
-        this.type = "enterprise";
-        this.authStatus = new StatusVO(enterpriseAuthentication.getIsAuthentication());
-    }
-
     public BaseAuthVO(EvaluationAgency agency){
         this.userName = agency.getEvaluationAgencyName();
         this.applytime = agency.getApplyTime();

+ 0 - 3
site/src/main/java/com/mooctest/crowd/site/mediator/ViewMediator.java

@@ -6,7 +6,6 @@ import com.mooctest.crowd.domain.domainobject.User;
 import com.mooctest.crowd.domain.exception.AccountNotExistException;
 import com.mooctest.crowd.domain.exception.BadRequestException;
 import com.mooctest.crowd.domain.exception.PasswordErrorException;
-import com.mooctest.crowd.site.command.ApplyPersonalAuthCommand;
 import com.mooctest.crowd.site.command.LoginCommand;
 import com.mooctest.crowd.site.command.RegisterCommand;
 import com.mooctest.crowd.site.data.dto.*;
@@ -23,8 +22,6 @@ import java.util.Map;
  */
 public interface ViewMediator {
 
-    void saveUserRole(User user, ApplyPersonalAuthCommand command);
-
     List<UserVO> renderMoreUser(Pageable pageable, String keyword);
 
     List<CrowdTaskVO> findMoreHotTasks();

+ 5 - 52
site/src/main/java/com/mooctest/crowd/site/mediator/impl/WebMediatorImpl.java

@@ -9,7 +9,6 @@ import com.mooctest.crowd.domain.factory.CrowdTestProjectFactory;
 import com.mooctest.crowd.domain.model.*;
 import com.mooctest.crowd.domain.repository.*;
 import com.mooctest.crowd.domain.util.Converter;
-import com.mooctest.crowd.site.command.ApplyPersonalAuthCommand;
 import com.mooctest.crowd.site.command.LoginCommand;
 import com.mooctest.crowd.site.command.RegisterCommand;
 import com.mooctest.crowd.site.data.ProjectOperationControl;
@@ -161,39 +160,6 @@ public class WebMediatorImpl implements ViewMediator {
     private String indexResourceCount;
 
     @Override
-    public void saveUserRole(User user, ApplyPersonalAuthCommand command) {
-        if (command.getRoleList().size() == 0 || command.getRoleList() == null) {
-            throw new BaseException("请选择成为发包或者接包用户");
-        }
-        UserPO userPO = userDao.save(Converter.convert(UserPO.class, user));
-        //如果两个都选择那么权限都给
-        if (command.getRoleList().contains(1) && command.getRoleList().contains(0)) {
-            UserToRolePO u2r = new UserToRolePO();
-            u2r.setUserId(userPO.getId());
-            u2r.setRoleId(RoleType.PARTY_USER.getId());
-            userToRoleDao.save(u2r);
-            UserToRolePO u2rl = new UserToRolePO();
-            u2rl.setUserId(userPO.getId());
-            u2rl.setRoleId(RoleType.EVALUATION_USER.getId());
-            userToRoleDao.save(u2rl);
-        }
-        //如果选择成为发包用户
-        else if (command.getRoleList().contains(0)) {
-            UserToRolePO u2r = new UserToRolePO();
-            u2r.setUserId(userPO.getId());
-            u2r.setRoleId(RoleType.PARTY_USER.getId());
-            userToRoleDao.save(u2r);
-        }
-        //如果选择成为接包用户
-        else if (command.getRoleList().contains(1)) {
-            UserToRolePO u2r = new UserToRolePO();
-            u2r.setUserId(userPO.getId());
-            u2r.setRoleId(RoleType.EVALUATION_USER.getId());
-            userToRoleDao.save(u2r);
-        }
-    }
-
-    @Override
     public List<UserVO> renderMoreUser(Pageable pageable,String keyword) {
         //获取众测人员排名
 //        String agencyName = agencyDao.findById(Long.parseLong(agencyId)).get().getEvaluationAgencyName();
@@ -975,8 +941,6 @@ public class WebMediatorImpl implements ViewMediator {
             userDTO.setAgencyVO(new AgencyVO(user.getEvaluationAgency()));
         if (user.getPersonalAuthentication() != null)
             userDTO.setPersonalAuthVO(new PersonalAuthVO(user.getPersonalAuthentication()));
-//        if (user.getEnterpriseAuthentication() != null)
-//            userDTO.setEnterpriseAuthVO(new EnterpriseAuthVO(user.getEnterpriseAuthentication()));
         List<PermissionVO> permissionList = new ArrayList<>();
         user.getRoleList().forEach(role -> role.getPermissionList().forEach(permission -> permissionList.add(new PermissionVO(permission))));
         userDTO.setPermissions(permissionList);
@@ -1006,24 +970,13 @@ public class WebMediatorImpl implements ViewMediator {
     @Override
     public List<BaseAuthVO> renderAuthingList() {
         List<BaseAuthVO> resultList = new ArrayList<>();
-        resultList.addAll(personalAuthenticationDao.findByIsAuthentication(AuthenticationStatus.isAuthenIng).stream().map(personalAuthenticationPO -> {
-            PersonalAuthentication personalAuthentication = new PersonalAuthentication();
-            BeanUtils.copyProperties(personalAuthenticationPO, personalAuthentication);
-            return new BaseAuthVO(personalAuthentication);
-        }).collect(Collectors.toList()));
+        resultList.addAll(personalAuthenticationDao.findByIsAuthentication(AuthenticationStatus.isAuthenIng).stream()
+                .map(personalAuthenticationPO -> new BaseAuthVO(Converter.convert(PersonalAuthentication.class, personalAuthenticationPO))).collect(Collectors.toList()));
 
-//        resultList.addAll(enterpriseAuthenticationDao.findByIsAuthentication(AuthenticationStatus.isAuthenIng).stream().map(enterpriseAuthenticationPO -> {
-//            EnterpriseAuthentication enterpriseAuthentication = new EnterpriseAuthentication();
-//            BeanUtils.copyProperties(enterpriseAuthenticationPO, enterpriseAuthentication);
-//            return new BaseAuthVO(enterpriseAuthentication);
-//        }).collect(Collectors.toList()));
+        resultList.addAll(agencyDao.findByIsAuthentication(AuthenticationStatus.isAuthenIng).stream()
+                .map(evaluationAgencyPO -> new BaseAuthVO(Converter.convert(EvaluationAgency.class, evaluationAgencyPO))).collect(Collectors.toList()));
 
-        resultList.addAll(agencyDao.findByIsAuthentication(AuthenticationStatus.isAuthenIng).stream().map(evaluationAgencyPO -> {
-            EvaluationAgency agency = new EvaluationAgency();
-            BeanUtils.copyProperties(evaluationAgencyPO, agency);
-            return new BaseAuthVO(agency);
-        }).collect(Collectors.toList()));
-        if(resultList.size() > 0 && resultList != null) {
+        if(resultList != null && resultList.size() > 0) {
             resultList.sort(Comparator.comparing(BaseAuthVO::getApplytime).reversed());
         }
         return resultList;

+ 10 - 11
site/src/main/java/com/mooctest/crowd/site/service/impl/AgencyServiceImpl.java

@@ -129,7 +129,10 @@ public class AgencyServiceImpl implements AgencyService {
         User user = userRepo.getInfoAndEvaluationAgencyByID(userId);
         user.applyAgencyAuthentication(agency);
         user.setEvaluationAgency(agency);
-        return mediator.renderUser(userRepo.saveEvaluationAgencyByUser(user));
+        userRepo.saveEvaluationAgencyByUser(user);
+        UserDTO userDTO = new UserDTO();
+        userDTO.setAgencyVO(new AgencyVO(agency));
+        return userDTO;
     }
 
     @Override
@@ -146,8 +149,8 @@ public class AgencyServiceImpl implements AgencyService {
         User user = userAnti.register(command.getEvaluationAgencyName(), command.getEmail(), command.getMobile(), command.getMobile());
         EvaluationAgency agency = command.toAgency();
         List<Role> roles = new ArrayList<>();
-        roles.add(userRepo.getRole("evaluationAgency"));
-        roles.add(userRepo.getRole("generalUser"));
+        roles.add(userRepo.getRole(RoleType.AGENCY.getName()));
+        roles.add(userRepo.getRole(RoleType.GENERAL_USER.getName()));
         user.setRoleList(roles);
         agency.setUserId(user.getId());
         agency.setIsAuthentication(AuthenticationStatus.isAuthenticated);
@@ -206,18 +209,14 @@ public class AgencyServiceImpl implements AgencyService {
         if (user.getEvaluationAgency() == null)
             throw new BaseException("该用户未申请机构认证!");
         user.getEvaluationAgency().passAuthentication();
-        if (user.getEvaluationAgency().getType().contains("0") && user.getEvaluationAgency().getType().contains("1")) {
+        //1是发包机构0是接包机构
+        if (user.getEvaluationAgency().getType().contains("1")) {
             user.getRoleList().add(userRepo.getRole(RoleType.PARTY_AGENCY.getName()));
-            user.getRoleList().add(userRepo.getRole(RoleType.AGENCY.getName()));
         }
-        //1是认证为研发机构0是认证为评测机构
-        else if (user.getEvaluationAgency().getType().contains("1")) {
-            user.getRoleList().add(userRepo.getRole(RoleType.PARTY_AGENCY.getName()));
-        } else if (user.getEvaluationAgency().getType().contains("0")) {
-            //给接包角色
+        if (user.getEvaluationAgency().getType().contains("0")) {
             user.getRoleList().add(userRepo.getRole(RoleType.AGENCY.getName()));
         }
-        return new AgencyVO(userRepo.saveEvaluationAgencyByUser(user).getEvaluationAgency());
+        return new AgencyVO(userRepo.saveUser(user).getEvaluationAgency());
     }
 
     @Override

Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
site/src/main/java/com/mooctest/crowd/site/service/impl/UserServiceImpl.java


Някои файлове не бяха показани, защото твърде много файлове са промени