瀏覽代碼

用户认证

zhaops 6 年之前
父節點
當前提交
eda085412c

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

@@ -0,0 +1,20 @@
+package com.diagbot.dto;
+
+import com.diagbot.entity.Organization;
+import com.diagbot.entity.User;
+import com.diagbot.entity.UserAuthentication;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:获取用户认证信息
+ * @author: zhaops
+ * @time: 2018/9/17 15:01
+ */
+@Getter
+@Setter
+public class UserAuthenticationDTO {
+    private User user;
+    private Organization organization;
+    private UserAuthentication userAuthentication;
+}

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

@@ -0,0 +1,17 @@
+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;
+}

+ 98 - 7
user-service/src/main/java/com/diagbot/facade/UserAuthenticationFacade.java

@@ -1,25 +1,116 @@
 package com.diagbot.facade;
 
+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.entity.wrapper.UserWrapper;
 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;
+
 /**
  * @Description:用户认证业务层
  * @author: zhaops
  * @time: 2018/9/13 19:30
  */
 @Component
-public class UserAuthenticationFacade extends UserAuthenticationServiceImpl{
-    public UserAuthentication userAuthentication(UserAuthenticationVO userAuthenticationVO){
-        return null;
+public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
+    @Autowired
+    private UserFacade userFacade;
+    @Autowired
+    private OrganizationFacade organizationFacade;
+
+    public UserAuthenticationRespDTO userAuthentication(UserAuthenticationVO userAuthenticationVO) {
+        UserAuthenticationRespDTO userAuthenticationRespDTO = new UserAuthenticationRespDTO();
+        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;
+        } else if (user.getId() != userId) {
+            userAuthenticationRespDTO.setMsg("登录用户【" + user_old.getUsername() + "】与验证用户【" + user.getUsername() + "】不符,不允许验证!");
+            userAuthenticationRespDTO.setIsSuccess(false);
+            return userAuthenticationRespDTO;
+        }
+
+        //判断该用户是否有关联机构
+        Organization organization_old = organizationFacade.getByUserId(userId);
+        if (organization_old == null) {
+            userAuthenticationRespDTO.setMsg("当前用户没有关联机构,不允许验证!");
+            userAuthenticationRespDTO.setIsSuccess(false);
+            return userAuthenticationRespDTO;
+        }
+        //更新机构信息
+        Organization organization = organizationFacade.getByName(userAuthenticationVO.getOrganization());
+        if (organization == null) {
+            userAuthenticationRespDTO.setMsg("找不到机构【" + userAuthenticationVO.getOrganization() + "】!");
+            userAuthenticationRespDTO.setIsSuccess(false);
+            return userAuthenticationRespDTO;
+        } else if (organization.getId() != organization_old.getId()) {
+            userAuthenticationRespDTO.setMsg("当前用户已关联到机构【" + organization_old.getName() + "】,不允许修改机构!");
+            userAuthenticationRespDTO.setIsSuccess(false);
+            return userAuthenticationRespDTO;
+        }
+        organization.setAddress(userAuthenticationVO.getOrganizationAddress());
+        organization.setPrincipal(userAuthenticationVO.getOrganizationPrincipal());
+        organization.setType(userAuthenticationVO.getOrganizationType());
+        organization.setModifier(userId.toString());
+        organization.setGmtModified(new Date());
+        organization.setSubNum(userAuthenticationVO.getSubOrganizationNum());
+        organizationFacade.updateById(organization);
+
+        //更新验证信息
+        UserAuthentication userAuthentication = this.getByUserId(userId);
+        if (userAuthentication == null) {
+            userAuthentication = new UserAuthentication();
+            userAuthentication.setCreator(userId.toString());
+            userAuthentication.setGmtCreate(new Date());
+            userAuthentication.setUserId(userId);
+        } else if (userAuthentication.getStatus().equals("1")) {
+            userAuthenticationRespDTO.setMsg("用户【" + user.getUsername() + "】已认证,不允许重复认证!");
+            userAuthenticationRespDTO.setIsSuccess(false);
+            return userAuthenticationRespDTO;
+        } else if (userAuthentication.getStatus().equals("2")) {
+            userAuthenticationRespDTO.setMsg("认证申请已提交,请耐心等待……");
+            userAuthenticationRespDTO.setIsSuccess(false);
+            return userAuthenticationRespDTO;
+        }
+        userAuthentication.setModifier(userId.toString());
+        userAuthentication.setGmtModified(new Date());
+        userAuthentication.setPosition(userAuthenticationVO.getPosition());
+        userAuthentication.setStatus("2");  //状态设为认证中
+        this.saveOrUpdate(userAuthentication);
+
+        userAuthenticationRespDTO.setMsg("认证申请已提交成功,请耐心等待1~2个工作日");
+        userAuthenticationRespDTO.setIsSuccess(true);
+        userAuthenticationRespDTO.getUserAuthenticationDTO().setUser(user);
+        userAuthenticationRespDTO.getUserAuthenticationDTO().setOrganization(organization);
+        userAuthenticationRespDTO.getUserAuthenticationDTO().setUserAuthentication(userAuthentication);
+        return userAuthenticationRespDTO;
+    }
+
+    public UserAuthenticationDTO getuserAuthenticationInfo() {
+        Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
+        User user = userFacade.getById(userId);
+        Organization organization = organizationFacade.getByUserId(userId);
+        UserAuthentication userAuthentication = this.getByUserId(userId);
+        UserAuthenticationDTO userAuthenticationDTO = new UserAuthenticationDTO();
+        userAuthenticationDTO.setUser(user);
+        userAuthenticationDTO.setOrganization(organization);
+        userAuthenticationDTO.setUserAuthentication(userAuthentication);
+        return userAuthenticationDTO;
     }
 
-    public UserWrapper getuserAuthenticationInfo(){
-        //Long userId=UserUtils.getCurrentPrincipleID();
-        return null;
+    public UserAuthentication getUserAuthentication() {
+        Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
+        UserAuthentication userAuthentication = this.getByUserId(userId);
+        return userAuthentication;
     }
 }

+ 7 - 0
user-service/src/main/java/com/diagbot/mapper/OrganizationMapper.java

@@ -17,4 +17,11 @@ public interface OrganizationMapper extends BaseMapper<Organization> {
      */
     public Organization getByUserId(Long userId);
 
+    /**
+     * @Description: 通过机构名称获取组织结构
+     * @Author: zhaops
+     * @Date: 2018/9/13 19:24
+     */
+    public Organization getByName(String name);
+
 }

+ 1 - 1
user-service/src/main/java/com/diagbot/mapper/UserAuthenticationMapper.java

@@ -12,5 +12,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @since 2018-09-17
  */
 public interface UserAuthenticationMapper extends BaseMapper<UserAuthentication> {
-
+    UserAuthentication getByUserId(Long userId);
 }

+ 14 - 0
user-service/src/main/java/com/diagbot/service/OrganizationService.java

@@ -21,4 +21,18 @@ public interface OrganizationService extends IService<Organization> {
      */
     public List<Organization> selectByMap(Map map);
 
+    /**
+     * @Description: 通过用户id获取组织结构
+     * @Author: ztg
+     * @Date: 2018/9/13 19:24
+     */
+    public Organization getByUserId(Long userId);
+
+    /**
+     * @Description: 通过机构名称获取组织结构
+     * @Author: zhaops
+     * @Date: 2018/9/13 19:24
+     */
+    public Organization getByName(String name);
+
 }

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

@@ -12,5 +12,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @since 2018-09-17
  */
 public interface UserAuthenticationService extends IService<UserAuthentication> {
-
+    UserAuthentication getByUserId(Long userId);
 }

+ 21 - 4
user-service/src/main/java/com/diagbot/service/impl/OrganizationServiceImpl.java

@@ -20,11 +20,28 @@ import java.util.Map;
 @Slf4j
 public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements OrganizationService {
 
-    @Autowired
-    OrganizationMapper organizationMapper;
-
     @Override
     public List<Organization> selectByMap(Map map) {
-        return organizationMapper.selectByMap(map);
+        return baseMapper.selectByMap(map);
+    }
+
+    /**
+     * @Description: 通过用户id获取组织结构
+     * @Author: ztg
+     * @Date: 2018/9/13 19:24
+     */
+    public Organization getByUserId(Long userId){
+        return baseMapper.getByUserId(userId);
+    }
+    /**
+     * @Description: 通过机构名称获取组织结构
+     * @Author: zhaops
+     * @Date: 2018/9/13 19:24
+     */
+    public Organization getByName(String name){
+        return baseMapper.getByName(name);
     }
+
+
+
 }

+ 3 - 1
user-service/src/main/java/com/diagbot/service/impl/UserAuthenticationServiceImpl.java

@@ -16,5 +16,7 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class UserAuthenticationServiceImpl extends ServiceImpl<UserAuthenticationMapper, UserAuthentication> implements UserAuthenticationService {
-
+    public UserAuthentication getByUserId(Long userId) {
+        return baseMapper.getByUserId(userId);
+    }
 }

+ 2 - 4
user-service/src/main/java/com/diagbot/vo/UserAuthenticationVO.java

@@ -14,14 +14,12 @@ import java.util.Date;
 @Getter
 @Setter
 public class UserAuthenticationVO {
-    private Long id;
-    @NotBlank(message = "请输入岗位信息!")
-    private String position;
     @NotBlank(message = "请输入手机号!")
     private String userName;
+    private String position;
     @NotBlank(message = "请输入机构名称!")
     private String organization;
-    private String organization_linkName;
+    private String organizationPrincipal;
     private String organizationAddress;
     private Integer organizationType;
     private Integer subOrganizationNum;

+ 18 - 8
user-service/src/main/java/com/diagbot/web/UserAuthenticationController.java

@@ -3,9 +3,9 @@ package com.diagbot.web;
 
 import com.diagbot.annotation.SysLogger;
 import com.diagbot.dto.RespDTO;
+import com.diagbot.dto.UserAuthenticationDTO;
+import com.diagbot.dto.UserAuthenticationRespDTO;
 import com.diagbot.entity.UserAuthentication;
-import com.diagbot.entity.User;
-import com.diagbot.entity.wrapper.UserWrapper;
 import com.diagbot.facade.UserAuthenticationFacade;
 import com.diagbot.vo.UserAuthenticationVO;
 import io.swagger.annotations.ApiOperation;
@@ -13,6 +13,7 @@ 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.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
@@ -37,15 +38,24 @@ public class UserAuthenticationController {
                     "organization:组织机构,必填<br>")
     @PostMapping("/userAuthentication")
     @SysLogger("userAuthentication")
-    public RespDTO<Boolean> userAuthentication(@RequestBody @Valid UserAuthenticationVO userAuthenticationVO) {
-        UserAuthentication userAuthentication = userAuthenticationFacade.userAuthentication(userAuthenticationVO);
-        return RespDTO.onSuc(true);
+    public RespDTO<UserAuthenticationRespDTO> userAuthentication(@RequestBody @Valid UserAuthenticationVO userAuthenticationVO) {
+        UserAuthenticationRespDTO userAuthenticationRespDTO = userAuthenticationFacade.userAuthentication(userAuthenticationVO);
+        return RespDTO.onSuc(userAuthenticationRespDTO);
     }
 
+    @ApiOperation(value = "获取当前用户信息")
     @PostMapping("/getuserAuthenticationInfo")
     @SysLogger("getuserAuthenticationInfo")
-    public RespDTO<UserWrapper> getuserAuthenticationInfo() {
-        UserWrapper userWrapper = userAuthenticationFacade.getuserAuthenticationInfo();
-        return RespDTO.onSuc(userWrapper);
+    public RespDTO<UserAuthenticationDTO> getuserAuthenticationInfo() {
+        UserAuthenticationDTO userAuthenticationDTO = userAuthenticationFacade.getuserAuthenticationInfo();
+        return RespDTO.onSuc(userAuthenticationDTO);
+    }
+
+    @ApiOperation(value = "获取当前用户认证信息")
+    @PostMapping("/getUserAuthentication")
+    @SysLogger("getUserAuthentication")
+    public RespDTO<UserAuthentication> getUserAuthentication() {
+        UserAuthentication userAuthentication = userAuthenticationFacade.getUserAuthentication();
+        return RespDTO.onSuc(userAuthentication);
     }
 }

+ 5 - 0
user-service/src/main/resources/mapper/OrganizationMapper.xml

@@ -23,4 +23,9 @@
         SELECT a.* FROM `sys_organization` a, sys_user_organization b
         where a.id = b.organization_id and b.user_id = #{userId} and a.is_deleted = 'N' and b.is_deleted = 'N'
     </select>
+
+    <select id="getByName" resultMap="BaseResultMap">
+        SELECT a.* FROM `sys_organization` a
+        where a.name = #{name} and a.is_deleted = 'N'
+    </select>
 </mapper>

+ 5 - 0
user-service/src/main/resources/mapper/UserAuthenticationMapper.xml

@@ -19,4 +19,9 @@
         <result column="remark" property="remark" />
     </resultMap>
 
+    <select id="getByUserId" resultMap="BaseResultMap">
+        SELECT a.* FROM `sys_user_authentication` a
+        where a.user_id=#{userId} and  a.is_deleted = 'N'
+    </select>
+
 </mapper>