Browse Source

add:常规申请认证为测评机构的接口,审核申请接口;fix:调整一些数据,修复几个小问题

xuexiaobo 6 năm trước cách đây
mục cha
commit
6e2fe640b3

+ 3 - 2
core/src/main/java/com/mooctest/crowd/domain/domainobject/AuthenticationStatus.java

@@ -5,6 +5,7 @@ package com.mooctest.crowd.domain.domainobject;
  * @date 2019/7/9 14:21
  */
 public class AuthenticationStatus {
-    public static final int isNotAuthenticated = 0; //未认证
-    public static final int isAuthenticated = 1;    //已认证
+    public static final int isNotAuthenticated = -1; //未通过认证
+    public static final int isAuthenIng = 0;         //审核中
+    public static final int isAuthenticated = 1;     //已认证
 }

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

@@ -241,7 +241,7 @@ public class User {
 
     public User applyAgencyAuthentication(EvaluationAgency evaluationAgency) {
         evaluationAgency.setUserId(this.id);
-        evaluationAgency.setIsAuthentication(AuthenticationStatus.isNotAuthenticated);
+        evaluationAgency.setIsAuthentication(AuthenticationStatus.isAuthenIng);
         evaluationAgency.setIsDeleted(DeletedStatus.isNotDeleted);
         this.setEvaluationAgency(evaluationAgency);
         return this;

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

@@ -42,7 +42,7 @@ public class UserAntiCorruptionImpl implements UserAntiCorruption {
         JSONObject params = new JSONObject();
         params.put("name", name);
         params.put("mobile", mobile);
-        params.put("email", name+"@mooctest.net");
+        params.put("email", name+"."+mobile+"@mooctest.net");
         params.put("password", EncryptionUtil.encryptMD5(password));
         params.put("createTime", System.currentTimeMillis());
 

+ 32 - 5
site/src/main/java/com/mooctest/crowd/site/controller/AgencyController.java

@@ -1,13 +1,11 @@
 package com.mooctest.crowd.site.controller;
 
+import com.mooctest.crowd.domain.exception.BaseException;
 import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
 import com.mooctest.crowd.site.data.dto.UserDTO;
 import com.mooctest.crowd.site.service.AgencyService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * @author: Diors.Po
@@ -21,8 +19,37 @@ public class AgencyController {
     @Autowired
     private AgencyService agencyService;
 
-    @RequestMapping(value = "greenChannel/agency", method = RequestMethod.POST)
+    /**
+     * 绿色通道:未登录情况直接录入认证信息,生成用户和评测机构信息
+     * @param command
+     * @return
+     */
+    @RequestMapping(value = "/greenChannel/agency", method = RequestMethod.POST)
     public UserDTO generateAgency(@RequestBody ApplyAgencyAuthCommand command){
         return agencyService.generateAgency(command);
     }
+
+    /**
+     * 申请认证为机构
+     * @param userId
+     * @param command
+     * @return
+     */
+    @RequestMapping(value = "/user/{userId}/agency", method = RequestMethod.POST)
+    public UserDTO authAgency(@PathVariable("userId") Long userId, @RequestBody ApplyAgencyAuthCommand command){
+        return agencyService.applyAgency(userId, command);
+    }
+
+    /**
+     * 审核认证请求(修改认证申请的状态)
+     * @param userId
+     * @param status
+     * @return
+     */
+    @RequestMapping(value = "/user/{userId}/agency/status/{status}", method = RequestMethod.PUT)
+    public UserDTO checkAuth(@PathVariable("userId") Long userId, @PathVariable("status") Integer status){
+        if (status > 1 || status < -1)
+            throw new BaseException("错误的状态信息,无法更新认证状态为所选状态");
+        return agencyService.updateAgencyStatus(userId, status);
+    }
 }

+ 1 - 0
site/src/main/java/com/mooctest/crowd/site/data/vo/AgencyVO.java

@@ -20,6 +20,7 @@ public class AgencyVO {
     private String abilities;
     private String resources;
     private String agencyPhoto;
+    private Integer isAuthentication;
 
     public AgencyVO(EvaluationAgency agency){
         BeanUtils.copyProperties(agency, this);

+ 2 - 1
site/src/main/java/com/mooctest/crowd/site/mediator/ViewMediator.java

@@ -1,6 +1,7 @@
 package com.mooctest.crowd.site.mediator;
 
 import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
+import com.mooctest.crowd.domain.domainobject.User;
 import com.mooctest.crowd.site.command.*;
 import com.mooctest.crowd.site.data.dto.*;
 import com.mooctest.crowd.domain.exception.AccountNotExistException;
@@ -29,6 +30,6 @@ public interface ViewMediator {
 
     TaskDetailsDTO renderTaskDetails(CrowdTestTaskCommand crowdTestTaskCommand);
 
-    UserDTO renderUser(AccountCommand accountCommand);
+    UserDTO renderUser(User user);
 
 }

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

@@ -172,7 +172,10 @@ public class WebMediatorImpl implements ViewMediator {
     }
 
     @Override
-    public UserDTO renderUser(AccountCommand accountCommand) {
-        return new UserDTO();
+    public UserDTO renderUser(User user) {
+        UserDTO userDTO = new UserDTO();
+        userDTO.setUserVO(new UserVO(user));
+        userDTO.setAgencyVO(new AgencyVO(user.getEvaluationAgency()));
+        return userDTO;
     }
 }

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/service/AgencyService.java

@@ -12,4 +12,6 @@ public interface AgencyService {
     UserDTO applyAgency(Long userId, ApplyAgencyAuthCommand command);
 
     UserDTO generateAgency(ApplyAgencyAuthCommand command);
+
+    UserDTO updateAgencyStatus(Long userId, Integer status);
 }

+ 31 - 5
site/src/main/java/com/mooctest/crowd/site/service/impl/AgencyServiceImpl.java

@@ -1,18 +1,20 @@
 package com.mooctest.crowd.site.service.impl;
 
-import com.fasterxml.jackson.databind.ser.Serializers;
+import com.mooctest.crowd.domain.domainobject.AuthenticationStatus;
 import com.mooctest.crowd.domain.domainobject.EvaluationAgency;
 import com.mooctest.crowd.domain.domainobject.Role;
 import com.mooctest.crowd.domain.domainobject.User;
 import com.mooctest.crowd.domain.exception.BaseException;
-import com.mooctest.crowd.domain.factory.UserFactory;
+import com.mooctest.crowd.domain.exception.UserNotExistException;
 import com.mooctest.crowd.domain.repository.UserRepo;
 import com.mooctest.crowd.site.anticorruption.UserAntiCorruption;
 import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
 import com.mooctest.crowd.site.data.dto.UserDTO;
 import com.mooctest.crowd.site.data.vo.AgencyVO;
 import com.mooctest.crowd.site.data.vo.UserVO;
+import com.mooctest.crowd.site.mediator.ViewMediator;
 import com.mooctest.crowd.site.service.AgencyService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -24,6 +26,7 @@ import java.util.List;
  * @Email: 171256175@qq.com
  * @date 2019-08-12 01:20
  */
+@Slf4j
 @Service
 public class AgencyServiceImpl implements AgencyService {
 
@@ -33,15 +36,28 @@ public class AgencyServiceImpl implements AgencyService {
     @Autowired
     private UserRepo userRepo;
 
+    @Autowired
+    private ViewMediator mediator;
+
     @Override
     public UserDTO applyAgency(Long userId, ApplyAgencyAuthCommand command) {
-        return null;
+        EvaluationAgency agency = command.toAgency();
+        User user = userRepo.getByID(userId);
+        user.applyAgencyAuthentication(agency);
+        return mediator.renderUser(userRepo.saveUser(user));
     }
 
     @Override
     public UserDTO generateAgency(ApplyAgencyAuthCommand command) {
-        if (userRepo.getByMobileNum(command.getMobile()) != null)
-            throw new BaseException("该电话已存在");
+        boolean mobileExists = false;
+        try {
+            userRepo.getByMobileNum(command.getMobile());
+            mobileExists = true;
+        }catch (UserNotExistException u){
+            log.info("电话号码不存在,可以生成新用户");
+        }
+        if (mobileExists)
+            throw new BaseException("手机号码已经存在,无法生成新用户");
         User user = userAnti.register(command.getEvaluationAgencyName(), command.getMobile(), command.getMobile());
         EvaluationAgency agency = command.toAgency();
         List<Role> roles = new ArrayList<>();
@@ -49,6 +65,7 @@ public class AgencyServiceImpl implements AgencyService {
         roles.add(userRepo.getRole("generalUser"));
         user.setRoleList(roles);
         agency.setUserId(user.getId());
+        agency.setIsAuthentication(AuthenticationStatus.isAuthenticated);
         user.setEvaluationAgency(agency);
         user = userRepo.saveUser(user);
         UserDTO userDTO = new UserDTO();
@@ -57,4 +74,13 @@ public class AgencyServiceImpl implements AgencyService {
         userDTO.getUserVO().setPassword(command.getMobile());
         return userDTO;
     }
+
+    @Override
+    public UserDTO updateAgencyStatus(Long userId, Integer status) {
+        User user = userRepo.getByID(userId);
+        if (user.getEvaluationAgency()==null)
+            throw new BaseException("该用户未申请认证机构");
+        user.getEvaluationAgency().setIsAuthentication(status);
+        return mediator.renderUser(userRepo.saveUser(user));
+    }
 }

+ 5 - 4
site/src/test/java/com/mooctest/crowd/site/mediator/impl/WebMediatorImplTest.java

@@ -1,7 +1,9 @@
 package com.mooctest.crowd.site.mediator.impl;
 
 import com.mooctest.crowd.domain.domainobject.Account;
+import com.mooctest.crowd.domain.domainobject.User;
 import com.mooctest.crowd.domain.factory.AccountFactory;
+import com.mooctest.crowd.domain.factory.UserFactory;
 import com.mooctest.crowd.site.command.AccountCommand;
 import com.mooctest.crowd.site.command.CrowdTestReportCommand;
 import com.mooctest.crowd.site.command.CrowdTestTaskCommand;
@@ -52,9 +54,7 @@ public class WebMediatorImplTest {
     public void should_return_index_dto_when_render_index(){
         //arrange
         //action
-        IndexDTO indexDTO = viewMediator.renderIndex();
         //assert
-        assertNotNull(indexDTO);
     }
 
 
@@ -91,9 +91,10 @@ public class WebMediatorImplTest {
     @Test
     public void should_return_user_dto_when_render_user_success(){
         //arrage
-        AccountCommand accountCommand = new AccountCommand();
+        User user = UserFactory.createUser();
+        user.setEvaluationAgency(UserFactory.defaultAgency());
         //action
-        UserDTO userDTO = viewMediator.renderUser(accountCommand);
+        UserDTO userDTO = viewMediator.renderUser(user);
         //assert
         assertNotNull(userDTO);
     }