浏览代码

add:添加了企业认证相关接口,调整了部分代码

xuexiaobo 6 年之前
父节点
当前提交
fb9c7d57a6

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

@@ -652,9 +652,9 @@ public class CrowdTestProject {
      */
     public CrowdTestProject finishCrowdTestProject(User user) {
         //判断用户是否认证
-        if(user.getPersonalAuthentication() == null && user.getEnterpriseAuthentication() == null && user.getRegionalManager() == null && user.getEvaluationAgency() == null){
-            throw new CrowdTestProjectException("当前用户未进行认证,无权限对项目操作");
-        }
+//        if(user.getPersonalAuthentication() == null && user.getEnterpriseAuthentication() == null && user.getRegionalManager() == null && user.getEvaluationAgency() == null){
+//            throw new CrowdTestProjectException("当前用户未进行认证,无权限对项目操作");
+//        }
         //判断是否为项目发起者
         if(!this.getUserId().equals(user.getId())){
             throw new CrowdTestProjectException("当前用户没有权限结束项目!");

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

@@ -57,7 +57,7 @@ public class PersonalAuthentication {
         if(this.getIsAuthentication() == AuthenticationStatus.isNotAuthenticated){
             throw new BaseException("当前是未通过认证状态,不可通过认证,需对认证信息进行修改后再提交认证申请");
         }else if(this.getIsAuthentication() == AuthenticationStatus.isAuthenticated){
-            throw new BaseException("当前已通过认证,不可再次进行认证");
+            throw new BaseException("当前已通过认证,请勿重复操作");
         }else{
             this.setIsAuthentication(AuthenticationStatus.isAuthenticated);
             this.setCheckTime(new Timestamp(System.currentTimeMillis()));

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

@@ -176,6 +176,8 @@ public class User {
      * @return
      */
     public User updatePersonalAuthInfo(PersonalAuthentication modifyAuth){
+        if (this.getPersonalAuthentication() == null)
+            throw new BaseException("当前用户未申请个人认证,无法修改");
         if (this.getEvaluationAgency()!=null || this.getEnterpriseAuthentication()!=null)
             throw new BaseException("已有其他认证信息,不可对个人认证进行操作");
         if (this.getPersonalAuthentication().getIsAuthentication() == AuthenticationStatus.isAuthenticated){
@@ -249,6 +251,9 @@ public class User {
      * @return
      */
     public User updateEnterpriseAuthInfo(EnterpriseAuthentication modifyAuth){
+        if (this.getEnterpriseAuthentication() == null){
+            throw new BaseException("该用户未申请企业认证,无法修改");
+        }
         if (this.getEvaluationAgency()!=null || this.getPersonalAuthentication()!=null)
             throw new BaseException("已有其他认证信息,不可对认证未企业用户");
         if (this.getEnterpriseAuthentication().getIsAuthentication() == AuthenticationStatus.isAuthenticated){

+ 16 - 0
site/src/main/java/com/mooctest/crowd/site/annotation/SysAdminRequired.java

@@ -0,0 +1,16 @@
+package com.mooctest.crowd.site.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-28 00:42
+ */
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface SysAdminRequired {
+}

+ 44 - 0
site/src/main/java/com/mooctest/crowd/site/command/ApplyEnterpriseAuthCommand.java

@@ -0,0 +1,44 @@
+package com.mooctest.crowd.site.command;
+
+import com.mooctest.crowd.domain.domainobject.EnterpriseAuthentication;
+import lombok.Data;
+import org.springframework.beans.BeanUtils;
+
+import javax.validation.constraints.NotNull;
+import java.sql.Timestamp;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-28 01:20
+ */
+@Data
+public class ApplyEnterpriseAuthCommand {
+    @NotNull(message = "用户ID不可为空")
+    private Long userId;
+
+    @NotNull(message = "企业名称不可为空")
+    private String enterpriseName;
+
+    @NotNull(message = "企业法人不可为空")
+    private String legalPersonName;
+
+    @NotNull(message = "请上传营业执照")
+    private String businessLicensePhoto;
+
+    @NotNull(message = "请填写社会统一信用代码")
+    private String unifiedSocialCreditCode;
+
+    @NotNull(message = "请填写对公账户")
+    private String bankAccount;
+
+    @NotNull(message = "地址不可为空")
+    private String address;
+
+    public EnterpriseAuthentication toEnterpriseAuth() {
+        EnterpriseAuthentication enterpriseAuthentication = new EnterpriseAuthentication();
+        BeanUtils.copyProperties(this, enterpriseAuthentication);
+        enterpriseAuthentication.setApplyTime(new Timestamp(System.currentTimeMillis()));
+        return enterpriseAuthentication;
+    }
+}

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

@@ -7,6 +7,7 @@ import org.springframework.beans.BeanUtils;
 
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
+import java.sql.Timestamp;
 
 /**
  * @author: Diors.Po
@@ -39,6 +40,7 @@ public class ApplyPersonalAuthCommand {
     public PersonalAuthentication toPersonalAuth(){
         PersonalAuthentication personalAuthentication = new PersonalAuthentication();
         BeanUtils.copyProperties(this, personalAuthentication);
+        personalAuthentication.setApplyTime(new Timestamp(System.currentTimeMillis()));
         return personalAuthentication;
     }
 }

+ 6 - 0
site/src/main/java/com/mooctest/crowd/site/configuration/WebMvcConfiguration.java

@@ -2,6 +2,7 @@ package com.mooctest.crowd.site.configuration;
 
 import com.mooctest.crowd.site.controller.interceptor.AuthCheckInterceptor;
 import com.mooctest.crowd.site.controller.interceptor.FileCheckInterceptor;
+import com.mooctest.crowd.site.controller.interceptor.SysAdminCheckInterceptor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
@@ -21,6 +22,9 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
     @Autowired
     private AuthCheckInterceptor authCheckInterceptor;
 
+    @Autowired
+    private SysAdminCheckInterceptor sysAdminCheckInterceptor;
+
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
         registry.addInterceptor(fileCheckInterceptor)
@@ -28,5 +32,7 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
         registry.addInterceptor(authCheckInterceptor)
                 .excludePathPatterns("/api/common/**")
                 .addPathPatterns("/**");
+        registry.addInterceptor(sysAdminCheckInterceptor)
+                .addPathPatterns("/api/user/**");
     }
 }

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

@@ -97,9 +97,9 @@ public class AgencyController {
 
     @LoginRequired
     @RequestMapping(value = "/user/{userId}/agency/status/reject", method = RequestMethod.PUT)
-    public void rejectAuth(@PathVariable("userId") Long userId, HttpSession session){
+    public AgencyVO rejectAuth(@PathVariable("userId") Long userId, HttpSession session){
         Long operatorId = Long.parseLong((String)session.getAttribute("userId"));
-        agencyService.rejectAuth(userId, operatorId);
+        return agencyService.rejectAuth(userId, operatorId);
     }
 
     /**

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

@@ -2,8 +2,10 @@ package com.mooctest.crowd.site.controller;
 
 import com.mooctest.crowd.domain.exception.*;
 import com.mooctest.crowd.site.annotation.LoginRequired;
+import com.mooctest.crowd.site.annotation.SysAdminRequired;
 import com.mooctest.crowd.site.command.*;
 import com.mooctest.crowd.site.data.dto.UserDTO;
+import com.mooctest.crowd.site.data.vo.EnterpriseAuthVO;
 import com.mooctest.crowd.site.data.vo.PersonalAuthVO;
 import com.mooctest.crowd.site.service.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -60,6 +62,14 @@ public class UserController {
         return userService.loginByMobileAndPwd(loginCommand);
     }
 
+    /**
+     * 申请个人实名认证
+     * @param userId
+     * @param command
+     * @param result
+     * @param session
+     * @return
+     */
     @LoginRequired
     @RequestMapping(value = "/user/{userId}/personalAuth", method = RequestMethod.POST)
     public PersonalAuthVO applyPersonalAuthentication(@PathVariable("userId")Long userId,
@@ -72,13 +82,133 @@ public class UserController {
         return userService.applyPersonalAuth(userId, command);
     }
 
+    /**
+     * 修改个人认证信息
+     * @param userId
+     * @param command
+     * @param result
+     * @return
+     */
     @LoginRequired
     @RequestMapping(value = "/user/{userId}/personalAuth", method = RequestMethod.PUT)
     public PersonalAuthVO updatePersonalAuthInfo(@PathVariable("userId")Long userId,
                                                  @Validated @RequestBody ApplyPersonalAuthCommand command,
+                                                 HttpSession session,
                                                  BindingResult result){
         if (result.hasErrors())
             throw new BaseException(result.getFieldError().getDefaultMessage());
         return userService.updatePersonalAuthInfo(userId, command);
     }
+
+
+    /**
+     * 个人认证:通过审核
+     * @param userId
+     * @param session
+     * @return
+     */
+    @LoginRequired
+    @RequestMapping(value = "/user/{userId}/personalAuth/status/accept", method = RequestMethod.PUT)
+    public PersonalAuthVO passPersonalAuth(@PathVariable("userId") Long userId, HttpSession session){
+        Long operatorId = Long.parseLong((String)session.getAttribute("userId"));
+        return userService.passPersonalAuth(userId, operatorId);
+    }
+
+    /**
+     * 个人认证:审核未通过
+     * @param userId
+     * @param session
+     * @return
+     */
+    @LoginRequired
+    @RequestMapping(value = "/user/{userId}/personalAuth/status/reject", method = RequestMethod.PUT)
+    public PersonalAuthVO rejectPersonalAuth(@PathVariable("userId") Long userId, HttpSession session){
+        Long operatorId = Long.parseLong((String)session.getAttribute("userId"));
+        return userService.rejectPersonalAuth(userId, operatorId);
+    }
+
+    /**
+     * 查看个人认证信息
+     * @param userId
+     * @return
+     */
+    @LoginRequired
+    @RequestMapping(value = "/user/{userId}/personalAuth", method = RequestMethod.GET)
+    public PersonalAuthVO getPersonalAuthInfo(@PathVariable("userId") Long userId){
+        return userService.getPersonalAuthInfo(userId);
+    }
+
+    /**
+     * 获取企业认证信息
+     * @param userId
+     * @return
+     */
+    @LoginRequired
+    @RequestMapping(value = "/user/{userId}/enterpriseAuth", method = RequestMethod.GET)
+    public EnterpriseAuthVO getEnterpriseAuthInfo(@PathVariable("userId") Long userId){
+        return userService.getEnterpriseAuthInfo(userId);
+    }
+
+    /**
+     * 申请企业认证接口
+     * @param userId
+     * @param command
+     * @param result
+     * @param session
+     * @return
+     */
+    @LoginRequired
+    @RequestMapping(value = "/user/{userId}/enterpriseAuth", method = RequestMethod.POST)
+    public EnterpriseAuthVO applyEnterpriseAuth(@PathVariable("userId")Long userId,
+                                                  @Validated @RequestBody ApplyEnterpriseAuthCommand 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.applyEnterpriseAuth(userId, command);
+    }
+
+    /**
+     * 更新企业认证信息
+     * @param userId
+     * @param command
+     * @param result
+     * @return
+     */
+    @LoginRequired
+    @RequestMapping(value = "/user/{userId}/enterpriseAuth", method = RequestMethod.PUT)
+    public EnterpriseAuthVO updatePersonalAuthInfo(@PathVariable("userId")Long userId,
+                                                 @Validated @RequestBody ApplyEnterpriseAuthCommand command,
+                                                 BindingResult result){
+        if (result.hasErrors())
+            throw new BaseException(result.getFieldError().getDefaultMessage());
+        return userService.updateEnterpriseAuthInfo(userId, command);
+    }
+
+    /**
+     * 企业认证:审核通过
+     * @param userId
+     * @return
+     */
+    @LoginRequired
+    @SysAdminRequired
+    @RequestMapping(value = "/user/{userId}/enterpriseAuth/status/accept", method = RequestMethod.PUT)
+    public EnterpriseAuthVO passEnterpriseAuth(@PathVariable("userId") Long userId){
+        return userService.passEnterpriseAuth(userId);
+    }
+
+    /**
+     * 企业认证:审核未通过
+     * @param userId
+     * @return
+     */
+    @LoginRequired
+    @RequestMapping(value = "/user/{userId}/enterpriseAuth/status/reject", method = RequestMethod.PUT)
+    public EnterpriseAuthVO rejectEnterpriseAuth(@PathVariable("userId") Long userId){
+        return userService.rejectEnterpriseAuth(userId);
+    }
+
+
+
 }

+ 57 - 0
site/src/main/java/com/mooctest/crowd/site/controller/interceptor/SysAdminCheckInterceptor.java

@@ -0,0 +1,57 @@
+package com.mooctest.crowd.site.controller.interceptor;
+
+import com.mooctest.crowd.domain.domainobject.User;
+import com.mooctest.crowd.domain.exception.UnauthorizedException;
+import com.mooctest.crowd.domain.repository.UserRepo;
+import com.mooctest.crowd.site.annotation.SysAdminRequired;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.method.HandlerMethod;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-28 00:42
+ */
+@Slf4j
+@Component
+public class SysAdminCheckInterceptor extends HandlerInterceptorAdapter {
+
+    @Autowired
+    private UserRepo userRepo;
+
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        if (hasSysAdminRequired(handler)){
+            log.info("系统管理员相关接口,进行身份检测");
+            if (request.getSession().getAttribute("userId") == null)
+                throw new UnauthorizedException("请登录后操作");
+            Long userId = Long.parseLong((String)request.getSession().getAttribute("userId"));
+            User user = userRepo.getByID(userId);
+            if (user.getRoleList().stream().anyMatch(role -> role.getName().equals("SystemAdministrator"))){
+                return true;
+            } else {
+                log.warn("无权限的访问,userId: " + userId);
+                throw new UnauthorizedException("仅有系统管理可进行此操作!");
+            }
+        }
+        return true;
+    }
+
+    private boolean hasSysAdminRequired(Object handler) {
+        if(handler instanceof HandlerMethod) {
+            HandlerMethod handlerMethod = (HandlerMethod) handler;
+            SysAdminRequired sysAdminRequired = handlerMethod.getMethod().getAnnotation(SysAdminRequired.class);
+            if(sysAdminRequired==null){
+                sysAdminRequired = handlerMethod.getBeanType().getAnnotation(SysAdminRequired.class);
+            }
+            return !(sysAdminRequired == null);
+        }
+        return false;
+    }
+}

+ 32 - 0
site/src/main/java/com/mooctest/crowd/site/data/enums/RoleType.java

@@ -0,0 +1,32 @@
+package com.mooctest.crowd.site.data.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-28 01:53
+ */
+@AllArgsConstructor
+@NoArgsConstructor
+public enum RoleType {
+
+    GENERAL_USER(1L, "generalUser"),
+    AGENCY(2L, "evaluationAgency"),
+    REGIONAL_MANAGER(3L, "RegionalManager"),
+    SYSTEM_ADMIN(4L, "SystemAdministrator"),
+    ENTERPRISE_USER(5L, "enterpriseUser");
+
+    private Long id;
+    private String name;
+
+    public Long getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+}

+ 36 - 0
site/src/main/java/com/mooctest/crowd/site/data/vo/EnterpriseAuthVO.java

@@ -0,0 +1,36 @@
+package com.mooctest.crowd.site.data.vo;
+
+import com.mooctest.crowd.domain.domainobject.EnterpriseAuthentication;
+import lombok.Data;
+import org.springframework.beans.BeanUtils;
+
+import java.sql.Timestamp;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-28 01:29
+ */
+@Data
+public class EnterpriseAuthVO {
+    private Long id;
+    private Long userId;
+    private String enterpriseName;
+    private String legalPersonName;
+    private String businessLicensePhoto;
+    private String unifiedSocialCreditCode;
+    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 EnterpriseAuthVO(EnterpriseAuthentication authentication){
+        BeanUtils.copyProperties(authentication, this);
+        this.authStatus = new StatusVO();
+        authStatus.initAuthStatus(this.isAuthentication);
+    }
+}

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

@@ -29,7 +29,7 @@ public interface AgencyService {
 
     AgencyVO passAuth(Long userId, Long operatorId);
 
-    void rejectAuth(Long userId, Long operatorId);
+    AgencyVO 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.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);

    PersonalAuthVO updatePersonalAuthInfo(Long userId, ApplyPersonalAuthCommand command);
}
+package com.mooctest.crowd.site.service;

import com.mooctest.crowd.site.command.ApplyEnterpriseAuthCommand;
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.EnterpriseAuthVO;
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);

    PersonalAuthVO updatePersonalAuthInfo(Long userId, ApplyPersonalAuthCommand command);

    PersonalAuthVO passPersonalAuth(Long userId, Long operatorId);

    PersonalAuthVO rejectPersonalAuth(Long userId, Long operatorId);

    PersonalAuthVO getPersonalAuthInfo(Long userId);

    EnterpriseAuthVO applyEnterpriseAuth(Long userId, ApplyEnterpriseAuthCommand command);

    EnterpriseAuthVO updateEnterpriseAuthInfo(Long userId, ApplyEnterpriseAuthCommand command);

    EnterpriseAuthVO getEnterpriseAuthInfo(Long userId);

    EnterpriseAuthVO passEnterpriseAuth(Long userId);

    EnterpriseAuthVO rejectEnterpriseAuth(Long userId);
}

+ 2 - 1
site/src/main/java/com/mooctest/crowd/site/service/impl/AgencyServiceImpl.java

@@ -128,7 +128,7 @@ public class AgencyServiceImpl implements AgencyService {
     }
 
     @Override
-    public void rejectAuth(Long userId, Long operatorId) {
+    public AgencyVO rejectAuth(Long userId, Long operatorId) {
         User operator = userRepo.getByID(operatorId);
         if (operator.getRoleList().stream().noneMatch(role -> role.getName().equals("SystemAdministrator")))
             throw new UnauthorizedException("无权限进行此操作");
@@ -136,6 +136,7 @@ public class AgencyServiceImpl implements AgencyService {
         if (user.getEvaluationAgency() == null)
             throw new BaseException("该用户未申请机构认证!");
         user.getEvaluationAgency().rejectAuthentication("");
+        return new AgencyVO(userRepo.saveUser(user).getEvaluationAgency());
     }
 
     @Override

文件差异内容过多而无法显示
+ 0 - 0
site/src/main/java/com/mooctest/crowd/site/service/impl/UserServiceImpl.java


部分文件因为文件数量过多而无法显示