瀏覽代碼

用户认证

zhaops 6 年之前
父節點
當前提交
9f3a2dafce

+ 1 - 1
user-service/src/main/java/com/diagbot/dto/UserAuthenticationDTO.java

@@ -8,7 +8,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 /**
- * @Description:获取用户认证信息
+ * @Description:用户认证信息
  * @author: zhaops
  * @time: 2018/9/17 15:01
  */

+ 0 - 17
user-service/src/main/java/com/diagbot/dto/UserAuthenticationRespDTO.java

@@ -1,17 +0,0 @@
-package com.diagbot.dto;
-
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * @Description:用户认证返回结果
- * @author: zhaops
- * @time: 2018/9/17 19:52
- */
-@Getter
-@Setter
-public class UserAuthenticationRespDTO {
-    private UserAuthenticationDTO userAuthenticationDTO;
-    private String msg;
-    private Boolean isSuccess;
-}

+ 42 - 40
user-service/src/main/java/com/diagbot/facade/UserAuthenticationFacade.java

@@ -1,24 +1,23 @@
 package com.diagbot.facade;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
 import com.diagbot.dto.QueryAuthProgressDTO;
 import com.diagbot.dto.UserAuthenticationDTO;
-import com.diagbot.dto.UserAuthenticationRespDTO;
 import com.diagbot.entity.Organization;
 import com.diagbot.entity.User;
 import com.diagbot.entity.UserAuthentication;
 import com.diagbot.enums.AuthStatusEnum;
 import com.diagbot.enums.OrganizationTypeEnum;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
 import com.diagbot.service.impl.UserAuthenticationServiceImpl;
 import com.diagbot.util.UserUtils;
 import com.diagbot.vo.UserAuthenticationVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @Description:用户认证业务层
@@ -32,38 +31,38 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
     @Autowired
     private OrganizationFacade organizationFacade;
 
-    public UserAuthenticationRespDTO userAuthentication(UserAuthenticationVO userAuthenticationVO) {
-        UserAuthenticationRespDTO userAuthenticationRespDTO = new UserAuthenticationRespDTO();
+    /**
+     * @Description:用户认证
+     * @author: zhaops
+     * @time: 2018/9/13 19:30
+     */
+    public UserAuthenticationDTO userAuthentication(UserAuthenticationVO userAuthenticationVO) {
+        UserAuthenticationDTO userAuthenticationDTO = new UserAuthenticationDTO();
         Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
         User user_old = userFacade.getById(userId);
         User user = userFacade.findByName(userAuthenticationVO.getUserName());
         if (user == null) {
-            userAuthenticationRespDTO.setMsg("用户【" + userAuthenticationVO.getUserName() + "】不存在,不允许验证!");
-            userAuthenticationRespDTO.setIsSuccess(false);
-            return userAuthenticationRespDTO;
+            throw new CommonException(CommonErrorCode.NOT_EXISTS,
+                    "用户【" + userAuthenticationVO.getUserName() + "】不存在,不允许验证");
         } else if (user.getId() != userId) {
-            userAuthenticationRespDTO.setMsg("登录用户【" + user_old.getUsername() + "】与验证用户【" + user.getUsername() + "】不符,不允许验证!");
-            userAuthenticationRespDTO.setIsSuccess(false);
-            return userAuthenticationRespDTO;
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                    "登录用户【" + user_old.getUsername() + "】与验证用户【" + user.getUsername() + "】不符,不允许验证");
         }
 
         //判断该用户是否有关联机构
         Organization organization_old = organizationFacade.getByUserId(userId);
         if (organization_old == null) {
-            userAuthenticationRespDTO.setMsg("当前用户没有关联机构,不允许验证!");
-            userAuthenticationRespDTO.setIsSuccess(false);
-            return userAuthenticationRespDTO;
+            throw new CommonException(CommonErrorCode.NOT_EXISTS,
+                    "当前用户没有关联机构,不允许验证");
         }
         //更新机构信息
         Organization organization = organizationFacade.getByName(userAuthenticationVO.getOrganization());
         if (organization == null) {
-            userAuthenticationRespDTO.setMsg("找不到机构【" + userAuthenticationVO.getOrganization() + "】!");
-            userAuthenticationRespDTO.setIsSuccess(false);
-            return userAuthenticationRespDTO;
+            throw new CommonException(CommonErrorCode.NOT_EXISTS,
+                    "找不到机构【" + userAuthenticationVO.getOrganization() + "】");
         } else if (organization.getId() != organization_old.getId()) {
-            userAuthenticationRespDTO.setMsg("当前用户已关联到机构【" + organization_old.getName() + "】,不允许修改机构!");
-            userAuthenticationRespDTO.setIsSuccess(false);
-            return userAuthenticationRespDTO;
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                    "当前用户已关联到机构【" + organization_old.getName() + "】,不允许修改机构");
         }
         organization.setAddress(userAuthenticationVO.getOrganizationAddress());
         organization.setPrincipal(userAuthenticationVO.getOrganizationPrincipal());
@@ -81,13 +80,11 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
             userAuthentication.setGmtCreate(new Date());
             userAuthentication.setUserId(userId);
         } else if (userAuthentication.getStatus() == 1) {
-            userAuthenticationRespDTO.setMsg("用户【" + user.getUsername() + "】已认证,不允许重复认证!");
-            userAuthenticationRespDTO.setIsSuccess(false);
-            return userAuthenticationRespDTO;
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                    "用户【" + user.getUsername() + "】已认证,不允许重复认证");
         } else if (userAuthentication.getStatus() == 2) {
-            userAuthenticationRespDTO.setMsg("认证申请已提交,请耐心等待……");
-            userAuthenticationRespDTO.setIsSuccess(false);
-            return userAuthenticationRespDTO;
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                    "认证申请已提交,无需重复提交");
         }
         userAuthentication.setModifier(userId.toString());
         userAuthentication.setGmtModified(new Date());
@@ -95,16 +92,17 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
         userAuthentication.setStatus(2);  //状态设为认证中
         this.saveOrUpdate(userAuthentication);
 
-        userAuthenticationRespDTO.setMsg("认证申请已提交成功,请耐心等待1~2个工作日");
-        userAuthenticationRespDTO.setIsSuccess(true);
-        UserAuthenticationDTO userAuthenticationDTO = new UserAuthenticationDTO();
         userAuthenticationDTO.setUser(user);
         userAuthenticationDTO.setOrganization(organization);
         userAuthenticationDTO.setUserAuthentication(userAuthentication);
-        userAuthenticationRespDTO.setUserAuthenticationDTO(userAuthenticationDTO);
-        return userAuthenticationRespDTO;
+        return userAuthenticationDTO;
     }
 
+    /**
+     * @Description:获取用户认证信息
+     * @author: zhaops
+     * @time: 2018/9/13 19:30
+     */
     public UserAuthenticationDTO getuserAuthenticationInfo() {
         Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
         User user = userFacade.getById(userId);
@@ -122,6 +120,11 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
         return userAuthenticationDTO;
     }
 
+    /**
+     * @Description:获取用户认证状态
+     * @author: zhaops
+     * @time: 2018/9/13 19:30
+     */
     public Map<Integer, Object> getUserAuthenticationStatus() {
         Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
         UserAuthentication userAuthentication = this.getByUserId(userId);
@@ -152,13 +155,12 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
     public QueryAuthProgressDTO queryAuthProgress() {
         Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
         UserAuthentication userAuthentication = this.getByUserId(userId);
-        
+
         QueryAuthProgressDTO queryAuthProgressDTO = new QueryAuthProgressDTO();
         queryAuthProgressDTO.setStatus(userAuthentication.getStatus());
         queryAuthProgressDTO.setIsReject(userAuthentication.getIsReject());
         queryAuthProgressDTO.setRejectComment(userAuthentication.getRejectComment());
-        
+
         return queryAuthProgressDTO;
     }
-    
 }

+ 11 - 15
user-service/src/main/java/com/diagbot/web/UserAuthenticationController.java

@@ -1,26 +1,22 @@
 package com.diagbot.web;
 
 
-import java.util.Map;
-
-import javax.validation.Valid;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
 import com.diagbot.annotation.SysLogger;
 import com.diagbot.dto.QueryAuthProgressDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.dto.UserAuthenticationDTO;
-import com.diagbot.dto.UserAuthenticationRespDTO;
 import com.diagbot.facade.UserAuthenticationFacade;
 import com.diagbot.vo.UserAuthenticationVO;
-
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+import java.util.Map;
 
 /**
  * <p>
@@ -43,9 +39,9 @@ public class UserAuthenticationController {
                     "organization:组织机构,必填<br>")
     @PostMapping("/userAuthentication")
     @SysLogger("userAuthentication")
-    public RespDTO<UserAuthenticationRespDTO> userAuthentication(@RequestBody @Valid UserAuthenticationVO userAuthenticationVO) {
-        UserAuthenticationRespDTO userAuthenticationRespDTO = userAuthenticationFacade.userAuthentication(userAuthenticationVO);
-        return RespDTO.onSuc(userAuthenticationRespDTO);
+    public RespDTO<UserAuthenticationDTO> userAuthentication(@RequestBody @Valid UserAuthenticationVO userAuthenticationVO) {
+        UserAuthenticationDTO userAuthenticationDTO = userAuthenticationFacade.userAuthentication(userAuthenticationVO);
+        return RespDTO.onSuc(userAuthenticationDTO);
     }
 
     @ApiOperation(value = "获取当前用户信息")