|
@@ -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;
|
|
|
}
|
|
|
}
|