From 6015dc6c90f0310fb92652781f6f58bbc8bafa07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?niohe=C2=B7erbao?= Date: Tue, 4 Apr 2023 10:52:08 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/user/manage/UserInfoManage.java | 54 +++++++++++++++------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java index eb633da..22a3070 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java @@ -74,6 +74,7 @@ public class UserInfoManage { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(DingEmployeeInfo.class) .eq(DingEmployeeInfo::getMainJob, "true") + .eq(DingEmployeeInfo::getStatus, "A") .eq(StringUtils.isNotBlank(orgCode), DingEmployeeInfo::getOrganizationCode, orgCode) .like(StringUtils.isNotBlank(phoneNo), DingEmployeeInfo::getBindUserMobile, phoneNo) .like(StringUtils.isNotBlank(name), DingEmployeeInfo::getEmployeeName, name) @@ -91,7 +92,7 @@ public class UserInfoManage { Map employeeCodeAvailableMap = new HashMap<>(16); if (CollUtil.isNotEmpty(employeeCodeList)) { employeeCodeAvailableMap = iUserInfoService.list(Wrappers.lambdaQuery(UserInfo.class) - .in(UserInfo::getEmployeeCode, employeeCodeList)) + .in(UserInfo::getEmployeeCode, employeeCodeList)) .stream().collect(Collectors.toMap(UserInfo::getEmployeeCode, Function.identity())); } List orgCodeList = records.stream() @@ -168,7 +169,7 @@ public class UserInfoManage { // TODO 这里过滤的非浙政钉用户的专家 后续需要增加补充逻辑 return iUserInfoService.list(Wrappers.lambdaQuery(UserInfo.class) - .in(UserInfo::getId, compliantUserIdList)) + .in(UserInfo::getId, compliantUserIdList)) .stream().map(UserInfo::getEmployeeCode) .filter(StringUtils::isNotBlank).collect(Collectors.toList()); @@ -256,23 +257,11 @@ public class UserInfoManage { @Transactional(rollbackFor = Exception.class) public void userInfoDetailEdit(ReqUserDetailEditPO reqUserDetailEditPO) { - String employeeCode = reqUserDetailEditPO.getEmployeeCode(); Long userId = generateUserId(reqUserDetailEditPO.getEmployeeCode()); UserInfo userInfo = iUserInfoService.getById(userId); + // 绑定用户手机号 + bandUserMobile(userInfo, reqUserDetailEditPO); - String mobile = userInfo.getMobile(); - if (StringUtils.isBlank(mobile)) { - String phoneNo = reqUserDetailEditPO.getPhoneNo(); - userInfo.setMobile(phoneNo); - // 更新浙政钉相关数据 - if (StringUtils.isNotBlank(phoneNo)) { - iDingEmployeeInfoService - .update(Wrappers.lambdaUpdate(DingEmployeeInfo.class) - .eq(DingEmployeeInfo::getMainJob, "true") - .eq(DingEmployeeInfo::getEmployeeCode, employeeCode) - .set(DingEmployeeInfo::getBindUserMobile, phoneNo)); - } - } userInfo.setAvailable(reqUserDetailEditPO.getStatus()); userInfo.setUpdateOn(LocalDateTime.now()); userInfo.setUpdateBy(LoginUserUtil.getUserId()); @@ -291,6 +280,39 @@ public class UserInfoManage { } } + /** + * 绑定用户手机号 + * + * @param userInfo + * @param reqUserDetailEditPO + */ + @Transactional(rollbackFor = Exception.class) + public void bandUserMobile(UserInfo userInfo, ReqUserDetailEditPO reqUserDetailEditPO) { + String employeeCode = reqUserDetailEditPO.getEmployeeCode(); + String mobile = userInfo.getMobile(); + Long userId = userInfo.getId(); + if (StringUtils.isBlank(mobile)) { + // 校验手机号是否重复 + UserInfo repeatMobileUserInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) + .eq(UserInfo::getMobile, mobile).ne(UserInfo::getId, userId)); + if (Objects.nonNull(repeatMobileUserInfo)) { + throw new BizException("该手机号码已被绑定,请问重复绑定"); + } + + String phoneNo = reqUserDetailEditPO.getPhoneNo(); + userInfo.setMobile(phoneNo); + // 更新浙政钉相关数据 + if (StringUtils.isNotBlank(phoneNo)) { + iDingEmployeeInfoService + .update(Wrappers.lambdaUpdate(DingEmployeeInfo.class) + .eq(DingEmployeeInfo::getMainJob, "true") + .eq(DingEmployeeInfo::getEmployeeCode, employeeCode) + .set(DingEmployeeInfo::getBindUserMobile, phoneNo)); + } + } + + } + @Transactional(rollbackFor = Exception.class) public Long generateUserId(String employeeCode) { UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) From 6363f78ff7668b049e77dbca28622505fc2a48a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?niohe=C2=B7erbao?= Date: Tue, 4 Apr 2023 11:14:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E9=99=86?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/user/controller/UserRoleController.java | 20 -------------------- .../user/security/auth/agent/AgentAuthFilter.java | 2 +- .../auth/credential/CredentialAuthFilter.java | 12 ++++++++---- .../auth/handler/DefaultLoginFailureHandler.java | 6 +++++- .../security/auth/validate/CommonLoginException.java | 17 +++++++++++++++++ .../security/auth/validate/DingQrLoginException.java | 4 ++++ 6 files changed, 35 insertions(+), 26 deletions(-) delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserRoleController.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/CommonLoginException.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserRoleController.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserRoleController.java deleted file mode 100644 index d1e51fa..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserRoleController.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ningdatech.pmapi.user.controller; - - -import org.springframework.web.bind.annotation.RequestMapping; - -import org.springframework.stereotype.Controller; - -/** - *

- * 用户角色表 前端控制器 - *

- * - * @author Liuxinxin - * @since 2023-01-05 - */ -@Controller -@RequestMapping("/pmapi.user/user-role") -public class UserRoleController { - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentAuthFilter.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentAuthFilter.java index e6a9128..b797168 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentAuthFilter.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentAuthFilter.java @@ -53,7 +53,7 @@ public class AgentAuthFilter extends AbstractAuthenticationProcessingFilter { setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); } catch (AuthenticationException e) { - throw new BadCredentialsException("账号或密码错误"); + throw new BadCredentialsException("用户id 不能为空"); } catch (BizException e) { throw new BadCredentialsException(e.getMessage()); } catch (Exception e) { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialAuthFilter.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialAuthFilter.java index 1ecfa09..671906b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialAuthFilter.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialAuthFilter.java @@ -2,6 +2,7 @@ package com.ningdatech.pmapi.user.security.auth.credential; import com.ningdatech.basic.exception.BizException; import com.ningdatech.pmapi.user.constant.LoginTypeEnum; +import com.ningdatech.pmapi.user.security.auth.validate.CommonLoginException; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.AuthenticationServiceException; @@ -53,7 +54,6 @@ public class CredentialAuthFilter extends AbstractAuthenticationProcessingFilter } paramValid(identifier, credential, loginType); - identifier = trim(identifier); credential = trim(credential); loginType = trim(loginType); @@ -62,6 +62,10 @@ public class CredentialAuthFilter extends AbstractAuthenticationProcessingFilter // Allow subclasses to set the "details" property setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); + } catch (CommonLoginException e) { + throw new CommonLoginException(e.getMessage()); + } catch (BadCredentialsException e) { + throw new BadCredentialsException(e.getMessage()); } catch (AuthenticationException e) { throw new BadCredentialsException("账号或密码错误"); } catch (BizException e) { @@ -80,19 +84,19 @@ public class CredentialAuthFilter extends AbstractAuthenticationProcessingFilter switch (loginTypeEnum) { case DING_QR_LOGIN: { if (StringUtils.isBlank(credential)) { - throw new BadCredentialsException("浙政钉扫码登陆 授权码 不能为空 credential"); + throw new CommonLoginException("浙政钉扫码登陆 授权码 不能为空 credential"); } } break; case USERNAME_PASSWORD_LOGIN: { if (StringUtils.isBlank(identifier) || StringUtils.isBlank(credential)) { - throw new BadCredentialsException("账号密码登陆 账号密码不能为空 identifier credential"); + throw new CommonLoginException("账号密码登陆 账号密码不能为空 identifier credential"); } } break; case PHONE_VERIFICATION_CODE_LOGIN: { if (StringUtils.isBlank(identifier) || StringUtils.isBlank(credential)) { - throw new BadCredentialsException("手机号验证码登陆 手机号或验证码不能为空 identifier credential"); + throw new CommonLoginException("手机号验证码登陆 手机号或验证码不能为空 identifier credential"); } } break; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/handler/DefaultLoginFailureHandler.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/handler/DefaultLoginFailureHandler.java index cf1ebc7..8b5d8fa 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/handler/DefaultLoginFailureHandler.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/handler/DefaultLoginFailureHandler.java @@ -3,6 +3,7 @@ package com.ningdatech.pmapi.user.security.auth.handler; import com.fasterxml.jackson.databind.ObjectMapper; import com.ningdatech.basic.model.ApiResponse; import com.ningdatech.pmapi.user.security.auth.errorcode.AuthErrorCodeEnum; +import com.ningdatech.pmapi.user.security.auth.validate.CommonLoginException; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -32,7 +33,10 @@ public class DefaultLoginFailureHandler extends SimpleUrlAuthenticationFailureHa String errorMsg; // 所有的认证异常都可以在这里添加,目前只支持用户名密码错误异常 - if (exception instanceof BadCredentialsException || exception instanceof UsernameNotFoundException) { + if (exception instanceof CommonLoginException) { + errorCode = 400; + errorMsg = exception.getMessage(); + } else if (exception instanceof BadCredentialsException || exception instanceof UsernameNotFoundException) { errorCode = AuthErrorCodeEnum.USERNAME_OR_PASSWORD_ERROR.getCode(); errorMsg = exception.getMessage(); } else { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/CommonLoginException.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/CommonLoginException.java new file mode 100644 index 0000000..a399f2e --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/CommonLoginException.java @@ -0,0 +1,17 @@ +package com.ningdatech.pmapi.user.security.auth.validate; + +import org.springframework.security.core.AuthenticationException; + +/** + * @author liuxinxin + * @date 2023/3/24 上午11:47 + * 通用登陆错误 + */ +public class CommonLoginException extends AuthenticationException { + + public CommonLoginException(String message) { + super(message); + } + + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/DingQrLoginException.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/DingQrLoginException.java index c9fb080..a7616ea 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/DingQrLoginException.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/DingQrLoginException.java @@ -1,10 +1,14 @@ package com.ningdatech.pmapi.user.security.auth.validate; +import lombok.Data; + /** * @author liuxinxin * @date 2023/3/24 上午11:47 + * 浙政钉扫码登陆错误 */ +@Data public class DingQrLoginException extends RuntimeException { private Integer code; From 89aae12b020a25f3a5d7a461acde7280d344d0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?niohe=C2=B7erbao?= Date: Tue, 4 Apr 2023 11:20:03 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=89=B4=E6=9D=83=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/credential/CredentialLoginUserDetailService.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java index 6cbfdfd..1d4ca2a 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java @@ -6,6 +6,7 @@ import com.ningdatech.pmapi.user.manage.UserAuthLoginManage; import com.ningdatech.pmapi.user.security.auth.constants.UserDeatilsServiceConstant; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; +import com.ningdatech.pmapi.user.security.auth.validate.CommonLoginException; import lombok.RequiredArgsConstructor; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -35,14 +36,23 @@ public class CredentialLoginUserDetailService implements UserDetailsService { switch (loginTypeEnum) { case PHONE_VERIFICATION_CODE_LOGIN: { userFullInfoDTO = userAuthLoginManage.queryUserInfoInPhoneNoAuth(username); + if (Objects.isNull(userFullInfoDTO)) { + throw new CommonLoginException("改手机号未绑定用户"); + } } break; case USERNAME_PASSWORD_LOGIN: { userFullInfoDTO = userAuthLoginManage.queryUserInfoInPasswordAuth(username); + if (Objects.isNull(userFullInfoDTO)) { + throw new UsernameNotFoundException(String.format("%s user not exist", username)); + } } break; case DING_QR_LOGIN: { userFullInfoDTO = userAuthLoginManage.queryUserInfoInAccountIdAuth(username); + if (Objects.isNull(userFullInfoDTO)) { + throw new CommonLoginException("浙政钉账号无法登陆"); + } } break; default: { @@ -50,9 +60,6 @@ public class CredentialLoginUserDetailService implements UserDetailsService { } } - if (Objects.isNull(userFullInfoDTO)) { - throw new UsernameNotFoundException(String.format("%s user not exist", username)); - } UserInfoDetails userInfoDetails = new UserInfoDetails(); userInfoDetails.setUserId(userFullInfoDTO.getUserId()); userInfoDetails.setUsername(userFullInfoDTO.getUsername()); From 1bb216262517b5f95263c1d5a89c47b74f43b4cd Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 4 Apr 2023 11:20:28 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=AF=B7=E5=81=87=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java index 9ab7e33..8246530 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java @@ -191,7 +191,7 @@ public class LeaveManage { } else if (type.equals(LeaveTypeEnum.TEMPORARY)) { // 临时请假 Meeting meeting = meetingService.getById(po.getMeetingId()); - if (meeting.getStatus().equals(MeetingStatusEnum.CANCELED.getCode())) { + if (MeetingStatusEnum.CANCELED.eq(meeting.getStatus())) { throw BizException.wrap("该会议已取消"); } po.setStartTime(meeting.getStartTime());