Quellcode durchsuchen

add:申请个人认证接口

xuexiaobo vor 6 Jahren
Ursprung
Commit
bacafa95be

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

@@ -137,7 +137,7 @@ public class User {
      * @return
      */
     public User applyPersonalAuthentication(PersonalAuthentication personalAuth) {
-        if (this.getPersonalAuthentication()!=null || this.getEnterpriseAuthentication()!=null || this.getPersonalAuthentication() != null)
+        if (this.getPersonalAuthentication()!=null || this.getEnterpriseAuthentication()!=null || this.getEvaluationAgency() != null)
             throw new BaseException("已有认证信息,不可再次认证");
         this.setPersonalAuthentication(personalAuth.applyAuthentication(this.id));
         return this;

+ 6 - 0
core/src/main/java/com/mooctest/crowd/domain/exception/EvaluationAgencyNotExistException.java

@@ -1,8 +1,14 @@
 package com.mooctest.crowd.domain.exception;
 
+import lombok.NoArgsConstructor;
+
 /**
  * @author guochao
  * @date 2019-07-30 09:15
  */
+@NoArgsConstructor
 public class EvaluationAgencyNotExistException extends BaseException {
+    public EvaluationAgencyNotExistException(String msg){
+        super(msg);
+    }
 }

+ 3 - 2
site/src/main/java/com/mooctest/crowd/site/command/ApplyPersonalAuthCommand.java

@@ -1,13 +1,12 @@
 package com.mooctest.crowd.site.command;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
 import com.mooctest.crowd.domain.domainobject.PersonalAuthentication;
 import lombok.Data;
 import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
-import java.sql.Timestamp;
 
 /**
  * @author: Diors.Po
@@ -22,10 +21,12 @@ public class ApplyPersonalAuthCommand {
     @NotNull(message = "请填写真实姓名")
     private String realName;
 
+    @JsonProperty(value = "IDCard")
     @NotNull(message = "请填写身份证号码")
     @Pattern(regexp = "\\d{15}(\\d{2}[0-9xX])?", message = "身份证号格式错误")
     private String IDCard;
 
+    @JsonProperty(value = "IDCardPhoto")
     @NotNull(message = "请上传身份证图片")
     private String IDCardPhoto;
 

+ 0 - 1
site/src/main/java/com/mooctest/crowd/site/command/CrowdTestProjectCommand.java

@@ -1,6 +1,5 @@
 package com.mooctest.crowd.site.command;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
 

+ 12 - 0
site/src/main/java/com/mooctest/crowd/site/controller/AgencyController.java

@@ -6,14 +6,17 @@ import com.mooctest.crowd.site.command.AgencyUpdateCommand;
 import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
 import com.mooctest.crowd.site.command.GenerateAgencyCommand;
 import com.mooctest.crowd.site.data.dto.UserDTO;
+import com.mooctest.crowd.site.data.vo.AgencyVO;
 import com.mooctest.crowd.site.data.vo.EvolutionAgencyVO;
 import com.mooctest.crowd.site.service.AgencyService;
+import lombok.extern.java.Log;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpSession;
+import javax.validation.constraints.Pattern;
 import java.util.List;
 
 /**
@@ -46,6 +49,7 @@ public class AgencyController {
      * @param command
      * @return
      */
+    @LoginRequired
     @RequestMapping(value = "/user/{userId}/agency", method = RequestMethod.POST)
     public UserDTO authAgency(@PathVariable("userId") Long userId, @RequestBody @Validated ApplyAgencyAuthCommand command, BindingResult result){
         if (result.hasErrors())
@@ -59,6 +63,7 @@ public class AgencyController {
      * @param status
      * @return
      */
+    @LoginRequired
     @RequestMapping(value = "/user/{userId}/agency/status/", method = RequestMethod.PUT)
     public UserDTO checkAuth(@PathVariable("userId") Long userId, @PathVariable("status") Integer status){
         if (status > 1 || status < -1)
@@ -86,6 +91,7 @@ public class AgencyController {
      * @param command
      * @return
      */
+    @LoginRequired
     @RequestMapping(value = "/user/{userId}/updateAgency", method = RequestMethod.POST)
     public UserDTO updateAgencyInfo(@PathVariable("userId") Long userId, @RequestBody @Validated AgencyUpdateCommand command, BindingResult result){
         if (result.hasErrors())
@@ -93,6 +99,12 @@ public class AgencyController {
         return agencyService.updateAgencyInfo(userId, command);
     }
 
+    @LoginRequired
+    @RequestMapping(value = "/user/{userId}/agency", method = RequestMethod.GET)
+    public AgencyVO getAgencyInfo(@PathVariable("userId") Long userId){
+        return agencyService.getAgencyDetails(userId);
+    }
+
     @RequestMapping(value = "/agency/list", method = RequestMethod.GET)
     public List<EvolutionAgencyVO> getAgencyList(){
         return agencyService.getAgencyList();

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

@@ -1,20 +1,17 @@
 package com.mooctest.crowd.site.controller;
 
+import com.mooctest.crowd.domain.exception.*;
+import com.mooctest.crowd.site.annotation.LoginRequired;
 import com.mooctest.crowd.site.command.*;
 import com.mooctest.crowd.site.data.dto.UserDTO;
-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.mediator.ViewMediator;
+import com.mooctest.crowd.site.data.vo.PersonalAuthVO;
 import com.mooctest.crowd.site.service.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PathVariable;
-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.*;
 
+import javax.servlet.http.HttpSession;
 import java.util.List;
 
 /**
@@ -62,4 +59,16 @@ public class UserController {
             throw new BadRequestException(result.getFieldError().getDefaultMessage());
         return userService.loginByMobileAndPwd(loginCommand);
     }
+
+    @LoginRequired
+    @RequestMapping(value = "/user/{userId}/personalAuth", method = RequestMethod.POST)
+    public PersonalAuthVO applyPersonalAuthentication(@PathVariable("userId")Long userId,
+                                                      @Validated @RequestBody ApplyPersonalAuthCommand command,
+                                                      BindingResult result, HttpSession session){
+        if (!userId.equals(Long.parseLong((String)session.getAttribute("userId"))))
+            throw new UnauthorizedException("没有权限对他人账号进行操作!");
+        if (result.hasErrors())
+            throw new BaseException(result.getFieldError().getDefaultMessage());
+        return userService.applyPersonalAuth(userId, command);
+    }
 }

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

@@ -1,5 +1,6 @@
 package com.mooctest.crowd.site.data.vo;
 
+import com.mooctest.crowd.domain.domainobject.AuthenticationStatus;
 import com.mooctest.crowd.domain.domainobject.EvaluationAgency;
 import com.mooctest.crowd.domain.domainobject.EvaluationAgencyAbility;
 import lombok.Data;
@@ -26,10 +27,12 @@ public class AgencyVO {
     private List<AgencyResourceVO> evaluationAgencyResourceList;
     private String agencyPhoto;
     private Integer isAuthentication;
+    private String explain;
     private int isDeleted;
     private Timestamp updateTime;
     private Timestamp expireTime;
     private Timestamp createTime;
+    private StatusVO authStatus;
 
     public AgencyVO(EvaluationAgency agency){
         BeanUtils.copyProperties(agency, this, "evaluationAgencyResourceList", "evaluationAgencyAbilityList");
@@ -37,5 +40,7 @@ public class AgencyVO {
                 .stream().map(EvaluationAgencyAbility::getAbilityName).collect(Collectors.toList()));
         this.setEvaluationAgencyResourceList(agency.getEvaluationAgencyResourceList()
                 .stream().map(AgencyResourceVO::new).collect(Collectors.toList()));
+        this.authStatus = new StatusVO();
+        this.authStatus.initAuthStatus(this.isAuthentication);
     }
 }

+ 39 - 0
site/src/main/java/com/mooctest/crowd/site/data/vo/PersonalAuthVO.java

@@ -0,0 +1,39 @@
+package com.mooctest.crowd.site.data.vo;
+
+import com.mooctest.crowd.domain.domainobject.AuthenticationStatus;
+import com.mooctest.crowd.domain.domainobject.PersonalAuthentication;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.beans.BeanUtils;
+
+import java.sql.Timestamp;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-27 14:47
+ */
+@Data
+@NoArgsConstructor
+public class PersonalAuthVO {
+    private Long id;
+    private Long userId;
+    private String realName;
+    private String IDCard;
+    private String IDCardPhoto;
+    private String bankAccount;
+    private String address;
+    private int isDeleted;
+    private Integer isAuthentication;
+    private String explain;
+    private Timestamp applyTime;
+    private Timestamp checkTime;
+    private StatusVO authStatus;
+
+    public PersonalAuthVO(PersonalAuthentication personalAuthentication){
+        BeanUtils.copyProperties(personalAuthentication, this);
+        this.authStatus = new StatusVO();
+        this.authStatus.initAuthStatus(this.isAuthentication);
+    }
+
+}

+ 14 - 0
site/src/main/java/com/mooctest/crowd/site/data/vo/StatusVO.java

@@ -1,5 +1,6 @@
 package com.mooctest.crowd.site.data.vo;
 
+import com.mooctest.crowd.domain.domainobject.AuthenticationStatus;
 import lombok.Data;
 
 /**
@@ -11,4 +12,17 @@ import lombok.Data;
 public class StatusVO {
     String text;
     String style;
+
+    public void initAuthStatus(Integer status){
+        if (status.equals(AuthenticationStatus.isAuthenticated)){
+            this.setText("已认证");
+            this.setStyle("success");
+        } else if (status.equals(AuthenticationStatus.isAuthenIng)){
+            this.setText("审核中");
+            this.setStyle("warning");
+        } else if (status.equals(AuthenticationStatus.isNotAuthenticated)) {
+            this.setText("认证失败");
+            this.setStyle("info");
+        }
+    }
 }

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

@@ -4,6 +4,7 @@ import com.mooctest.crowd.site.command.AgencyUpdateCommand;
 import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
 import com.mooctest.crowd.site.command.GenerateAgencyCommand;
 import com.mooctest.crowd.site.data.dto.UserDTO;
+import com.mooctest.crowd.site.data.vo.AgencyVO;
 import com.mooctest.crowd.site.data.vo.EvolutionAgencyVO;
 
 import java.util.List;
@@ -28,4 +29,5 @@ public interface AgencyService {
 
     void rejectAuth(Long userId, Long operatorId);
 
+    AgencyVO getAgencyDetails(Long userId);
 }

+ 1 - 1
site/src/main/java/com/mooctest/crowd/site/service/UserService.java

@@ -1 +1 @@
-package com.mooctest.crowd.site.service;

import com.mooctest.crowd.site.command.LoginCommand;
import com.mooctest.crowd.site.command.RegisterCommand;
import com.mooctest.crowd.site.data.dto.UserDTO;
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.data.vo.EvolutionAgencyVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: xuexb
 * @Date: 2019.7.22 16:52
 */
public interface UserService {
    UserDTO register(RegisterCommand registerCommand) throws AccountNotExistException;

    UserDTO loginByMobileAndPwd(LoginCommand loginCommand) throws PasswordErrorException, AccountNotExistException, BadRequestException;

    List<EvolutionAgencyVO> getAgencies();

    UserDTO getUser(Long userId);
}
+package com.mooctest.crowd.site.service;

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.UserDTO;
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.data.vo.EvolutionAgencyVO;
import com.mooctest.crowd.site.data.vo.PersonalAuthVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: xuexb
 * @Date: 2019.7.22 16:52
 */
public interface UserService {
    UserDTO register(RegisterCommand registerCommand) throws AccountNotExistException;

    UserDTO loginByMobileAndPwd(LoginCommand loginCommand) throws PasswordErrorException, AccountNotExistException, BadRequestException;

    List<EvolutionAgencyVO> getAgencies();

    UserDTO getUser(Long userId);

    PersonalAuthVO applyPersonalAuth(Long userId, ApplyPersonalAuthCommand command);
}

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

@@ -2,6 +2,7 @@ package com.mooctest.crowd.site.service.impl;
 
 import com.mooctest.crowd.domain.domainobject.*;
 import com.mooctest.crowd.domain.exception.BaseException;
+import com.mooctest.crowd.domain.exception.EvaluationAgencyNotExistException;
 import com.mooctest.crowd.domain.exception.UnauthorizedException;
 import com.mooctest.crowd.domain.exception.UserNotExistException;
 import com.mooctest.crowd.domain.repository.EvaluationAgencyRepo;
@@ -133,5 +134,14 @@ public class AgencyServiceImpl implements AgencyService {
         user.getEvaluationAgency().rejectAuthentication("");
     }
 
+    @Override
+    public AgencyVO getAgencyDetails(Long userId) {
+        User user = userRepo.getByID(userId);
+        EvaluationAgency agency = user.getEvaluationAgency();
+        if (agency == null)
+            throw new EvaluationAgencyNotExistException("当前用户未申请机构认证");
+        return new AgencyVO(user.getEvaluationAgency());
+    }
+
 
 }

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 1
site/src/main/java/com/mooctest/crowd/site/service/impl/UserServiceImpl.java


Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.