|
@@ -8,10 +8,13 @@ import com.diagbot.dto.WaitAuthenDTO;
|
|
|
import com.diagbot.entity.Organization;
|
|
|
import com.diagbot.entity.User;
|
|
|
import com.diagbot.entity.UserAuthentication;
|
|
|
+import com.diagbot.enums.AuthHandleEnum;
|
|
|
import com.diagbot.enums.AuthStatusEnum;
|
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.enums.VisibleIdTypeEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.idc.VisibleIdCreater;
|
|
|
import com.diagbot.service.impl.UserAuthenticationServiceImpl;
|
|
|
import com.diagbot.util.UserUtils;
|
|
|
import com.diagbot.vo.UserAuthenticationVO;
|
|
@@ -19,6 +22,8 @@ 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:用户认证业务层
|
|
@@ -31,6 +36,8 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
|
|
|
private UserFacade userFacade;
|
|
|
@Autowired
|
|
|
private OrganizationFacade organizationFacade;
|
|
|
+ @Autowired
|
|
|
+ private VisibleIdCreater visibleIdCreater;
|
|
|
|
|
|
/**
|
|
|
* 用户认证
|
|
@@ -50,6 +57,14 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
|
|
|
"登录用户【" + user_old.getUsername() + "】与验证用户【" + user.getUsername() + "】不符,不允许验证");
|
|
|
}
|
|
|
|
|
|
+ if (user.getAuthStatus().equals(AuthStatusEnum.Authorized.getKey())) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
|
|
|
+ "用户【" + user.getUsername() + "】已认证,不允许重复认证");
|
|
|
+ } else if (user.getAuthStatus().equals(AuthStatusEnum.Authorizing.getKey())) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
|
|
|
+ "认证申请已提交,无需重复提交");
|
|
|
+ }
|
|
|
+
|
|
|
//判断该用户是否有关联机构
|
|
|
Organization organization_old = organizationFacade.getByUserId(userId);
|
|
|
if (organization_old == null) {
|
|
@@ -79,24 +94,29 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
|
|
|
//更新验证信息
|
|
|
QueryWrapper<UserAuthentication> qwAuthentication = new QueryWrapper<>();
|
|
|
qwAuthentication.eq("user_id", userId).
|
|
|
+ eq("status", AuthHandleEnum.UNHandle.getKey()).
|
|
|
eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
UserAuthentication userAuthentication = this.getOne(qwAuthentication);
|
|
|
- if (userAuthentication == null) {
|
|
|
- userAuthentication = new UserAuthentication();
|
|
|
- userAuthentication.setCreator(userId.toString());
|
|
|
- userAuthentication.setGmtCreate(new Date());
|
|
|
- userAuthentication.setUserId(userId);
|
|
|
- } else if (userAuthentication.getStatus().equals(AuthStatusEnum.Authorized.getKey())) {
|
|
|
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
|
|
|
- "用户【" + user.getUsername() + "】已认证,不允许重复认证");
|
|
|
- } else if (userAuthentication.getStatus().equals(AuthStatusEnum.Authorizing.getKey())) {
|
|
|
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
|
|
|
- "认证申请已提交,无需重复提交");
|
|
|
+ //有未处理的认证信息,先做已处理
|
|
|
+ if (userAuthentication != null) {
|
|
|
+ userAuthentication.setStatus(AuthHandleEnum.Handled.getKey());
|
|
|
+ this.updateById(userAuthentication);
|
|
|
}
|
|
|
+ //更新用户状态
|
|
|
+ user.setPosition(userAuthenticationVO.getPosition());
|
|
|
+ user.setAuthStatus(AuthStatusEnum.Authorizing.getKey());
|
|
|
+ userFacade.updateById(user);
|
|
|
+
|
|
|
+ //插入新的认证信息
|
|
|
+ userAuthentication = new UserAuthentication();
|
|
|
+ userAuthentication.setCreator(userId.toString());
|
|
|
+ userAuthentication.setGmtCreate(new Date());
|
|
|
+ userAuthentication.setUserId(userId);
|
|
|
userAuthentication.setModifier(userId.toString());
|
|
|
userAuthentication.setGmtModified(new Date());
|
|
|
- userAuthentication.setPosition(userAuthenticationVO.getPosition());
|
|
|
- userAuthentication.setStatus(AuthStatusEnum.Authorizing.getKey()); //状态设为认证中
|
|
|
+ userAuthentication.setStatus(AuthHandleEnum.UNHandle.getKey()); //状态设为未处理
|
|
|
+ userAuthentication.setOrderNum(visibleIdCreater.getNextId(VisibleIdTypeEnum.IS_AUTH.getKey())); //认证申请单号
|
|
|
+
|
|
|
this.saveOrUpdate(userAuthentication);
|
|
|
|
|
|
AuthStatusDTO authStatusDTO = new AuthStatusDTO();
|
|
@@ -118,29 +138,30 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
|
|
|
Organization organization = organizationFacade.getByUserId(userId);
|
|
|
QueryWrapper<UserAuthentication> qw = new QueryWrapper<>();
|
|
|
qw.eq("user_id", userId).
|
|
|
- eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+ eq("status", AuthHandleEnum.Handled.getKey()).
|
|
|
+ eq("is_deleted", IsDeleteEnum.N.getKey()).
|
|
|
+ orderByDesc("gmt_create");
|
|
|
UserAuthentication userAuthentication = this.getOne(qw);
|
|
|
UserAuthenticationDTO userAuthenticationDTO = new UserAuthenticationDTO();
|
|
|
- //userAuthenticationDTO.setUser(user);
|
|
|
userAuthenticationDTO.setUserId(user.getId());
|
|
|
userAuthenticationDTO.setUsername(user.getUsername());
|
|
|
userAuthenticationDTO.setLinkman(user.getLinkman());
|
|
|
userAuthenticationDTO.setEmail(user.getEmail());
|
|
|
userAuthenticationDTO.setUserType(user.getType());
|
|
|
- //userAuthenticationDTO.setOrganization(organization);
|
|
|
+ userAuthenticationDTO.setPosition(user.getPosition());
|
|
|
+ userAuthenticationDTO.setAuthStatus(user.getAuthStatus());
|
|
|
+ userAuthenticationDTO.setAuthStatusName(AuthStatusEnum.getName(user.getAuthStatus()));
|
|
|
userAuthenticationDTO.setOrganizationId(organization.getId());
|
|
|
userAuthenticationDTO.setOrganizationName(organization.getName());
|
|
|
userAuthenticationDTO.setOrganizationType(organization.getType());
|
|
|
userAuthenticationDTO.setPrincipal(organization.getPrincipal());
|
|
|
userAuthenticationDTO.setSubNum(organization.getSubNum());
|
|
|
userAuthenticationDTO.setAddress(organization.getAddress());
|
|
|
- //userAuthenticationDTO.setUserAuthentication(userAuthentication);
|
|
|
- userAuthenticationDTO.setPosition(userAuthentication.getPosition());
|
|
|
- userAuthenticationDTO.setIsReject(userAuthentication.getIsReject());
|
|
|
- userAuthenticationDTO.setRejectType(userAuthentication.getRejectType());
|
|
|
- userAuthenticationDTO.setRejectComment(userAuthentication.getRejectComment());
|
|
|
- userAuthenticationDTO.setAuthStatus(userAuthentication.getStatus());
|
|
|
- userAuthenticationDTO.setAuthStatusName(AuthStatusEnum.getName(userAuthentication.getStatus()));
|
|
|
+ if (userAuthentication != null) {
|
|
|
+ userAuthenticationDTO.setIsReject(userAuthentication.getIsReject());
|
|
|
+ userAuthenticationDTO.setRejectType(userAuthentication.getRejectType());
|
|
|
+ userAuthenticationDTO.setRejectComment(userAuthentication.getRejectComment());
|
|
|
+ }
|
|
|
return userAuthenticationDTO;
|
|
|
}
|
|
|
|
|
@@ -150,9 +171,10 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
|
|
|
* @return
|
|
|
*/
|
|
|
public AuthStatusDTO getUserAuthenticationStatus() {
|
|
|
- UserAuthentication userAuthentication = this.getUserAuthentication();
|
|
|
+ Map<String, Object> map = this.getUserAuthentication();
|
|
|
+ User user = (User) map.get("user");
|
|
|
AuthStatusDTO authStatusDTO = new AuthStatusDTO();
|
|
|
- Integer status = userAuthentication.getStatus();
|
|
|
+ Integer status = user.getAuthStatus();
|
|
|
String statusName = AuthStatusEnum.getName(status);
|
|
|
authStatusDTO.setAuthStatus(status);
|
|
|
authStatusDTO.setAuthStatusName(statusName);
|
|
@@ -165,11 +187,13 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
|
|
|
* @return 包含当前账号的认证状态
|
|
|
*/
|
|
|
public QueryAuthProgressDTO queryAuthProgress() {
|
|
|
- UserAuthentication userAuthentication = this.getUserAuthentication();
|
|
|
+ Map<String, Object> map = this.getUserAuthentication();
|
|
|
+ User user = (User) map.get("user");
|
|
|
+ UserAuthentication userAuthentication = (UserAuthentication) map.get("userAuthentication");
|
|
|
|
|
|
QueryAuthProgressDTO queryAuthProgressDTO = new QueryAuthProgressDTO();
|
|
|
- queryAuthProgressDTO.setUserStatus(userAuthentication.getStatus());
|
|
|
- queryAuthProgressDTO.setUserStatusMsg(AuthStatusEnum.getName(userAuthentication.getStatus()));
|
|
|
+ queryAuthProgressDTO.setUserStatus(user.getAuthStatus());
|
|
|
+ queryAuthProgressDTO.setUserStatusMsg(AuthStatusEnum.getName(user.getAuthStatus()));
|
|
|
queryAuthProgressDTO.setRejectComment(userAuthentication.getRejectComment());
|
|
|
|
|
|
return queryAuthProgressDTO;
|
|
@@ -180,16 +204,26 @@ public class UserAuthenticationFacade extends UserAuthenticationServiceImpl {
|
|
|
*
|
|
|
* @return 用户认证信息
|
|
|
*/
|
|
|
- private UserAuthentication getUserAuthentication() {
|
|
|
+ private Map<String, Object> getUserAuthentication() {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
Long userId = Long.parseLong(UserUtils.getCurrentPrincipleID());
|
|
|
+ User user = userFacade.getById(userId);
|
|
|
+ if (user.getIsDeleted().equals(IsDeleteEnum.Y.getKey()) || user == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "用户不存在");
|
|
|
+ } else {
|
|
|
+ map.put("user", user);
|
|
|
+ }
|
|
|
QueryWrapper<UserAuthentication> qw = new QueryWrapper<>();
|
|
|
qw.eq("user_id", userId).
|
|
|
- eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+ eq("is_deleted", IsDeleteEnum.N.getKey()).
|
|
|
+ orderByDesc("gmt_create");
|
|
|
UserAuthentication userAuthentication = this.getOne(qw);
|
|
|
if (userAuthentication == null) {
|
|
|
throw new CommonException(CommonErrorCode.NOT_EXISTS, "当前用户没有认证信息");
|
|
|
+ } else {
|
|
|
+ map.put("userAuthentication", userAuthentication);
|
|
|
}
|
|
|
- return userAuthentication;
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
/**
|