1. 修复用户信息未同步人力资源编号的问题

This commit is contained in:
chenbowen
2025-12-02 11:13:33 +08:00
parent 55dd8df69c
commit a689a3ffe4
13 changed files with 96 additions and 26 deletions

View File

@@ -50,6 +50,9 @@ public class AuthPermissionInfoRespVO {
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "zt")
private String username;
@Schema(description = "工号", example = "A00123")
private String workcode;
@Schema(description = "用户邮箱", example = "zt@iocoder.cn")
private String email;

View File

@@ -22,6 +22,9 @@ public class UserProfileRespVO {
@Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "zt")
private String username;
@Schema(description = "工号", example = "A00123")
private String workcode;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "ZT")
private String nickname;

View File

@@ -23,6 +23,9 @@ public class UserPageReqVO extends PageParam {
@Schema(description = "用户账号,模糊匹配", example = "zt")
private String username;
@Schema(description = "工号,模糊匹配", example = "A00123")
private String workcode;
@Schema(description = "手机号码,模糊匹配", example = "zt")
private String mobile;

View File

@@ -25,6 +25,10 @@ public class UserRespVO{
@ExcelProperty("用户名称")
private String username;
@Schema(description = "工号", example = "A00123")
@ExcelProperty("工号")
private String workcode;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "ZT")
@ExcelProperty("用户昵称")
private String nickname;

View File

@@ -33,6 +33,11 @@ public class UserSaveReqVO {
@DiffLogField(name = "用户账号")
private String username;
@Schema(description = "工号", example = "A00123")
@Length(max = 64, message = "工号长度不能超过64个字符")
@DiffLogField(name = "工号")
private String workcode;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "ZT")
@Size(max = 30, message = "用户昵称长度不能超过30个字符")
@DiffLogField(name = "用户昵称")

View File

@@ -38,6 +38,10 @@ public class AdminUserDO extends TenantBaseDO {
*/
@NotEmpty
private String username;
/**
* 工号
*/
private String workcode;
/**
* 加密后的密码
*

View File

@@ -23,6 +23,10 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
return selectOne(AdminUserDO::getUsername, username);
}
default AdminUserDO selectByWorkcode(String workcode) {
return selectOne(AdminUserDO::getWorkcode, workcode);
}
default AdminUserDO selectByEmail(String email) {
return selectOne(AdminUserDO::getEmail, email);
}
@@ -36,6 +40,7 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
return selectJoinPage(reqVO, AdminUserDO.class, new MPJLambdaWrapperX<AdminUserDO>()
.leftJoin(UserDeptDO.class, UserDeptDO::getUserId, AdminUserDO::getId)
.likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername())
.likeIfPresent(AdminUserDO::getWorkcode, reqVO.getWorkcode())
.likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile())
.eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus())
.betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime())

View File

@@ -435,6 +435,7 @@ public class IWorkSyncProcessorImpl implements IWorkSyncProcessor {
CommonStatusEnum status) {
UserSaveReqVO req = new UserSaveReqVO();
req.setUsername(username);
req.setWorkcode(trimToNull(source.getWorkcode()));
req.setNickname(limitLength(StrUtil.blankToDefault(source.getLastname(), username), 30));
req.setRemark(buildUserRemark(source));
if (deptId != null) {

View File

@@ -72,16 +72,16 @@ public class EbanOAuth2ServiceImpl implements EbanOAuth2Service {
throw exception(AUTH_LOGIN_EBAN_TOKEN_INVALID);
}
String username = StrUtil.trim(StrUtil.blankToDefault(userInfo.getLoginName(), userInfo.getUsername()));
if (StrUtil.isBlank(username)) {
log.error("E办OAuth2用户信息缺少 username 与 loginName无法匹配账号: {}", JSONUtil.toJsonStr(userInfo));
String workcode = StrUtil.trim(StrUtil.blankToDefault(userInfo.getLoginName(), userInfo.getUsername()));
if (StrUtil.isBlank(workcode)) {
log.error("E办OAuth2用户信息缺少工号(loginName),无法匹配账号: {}", JSONUtil.toJsonStr(userInfo));
throw exception(AUTH_LOGIN_EBAN_TOKEN_INVALID);
}
AdminUserDO user = userService.getUserByUsername(username);
AdminUserDO user = userService.getUserByWorkcode(workcode);
if (user == null) {
createLoginLog(null, username, LoginLogTypeEnum.LOGIN_SOCIAL, LoginResultEnum.BAD_CREDENTIALS);
log.warn("E办OAuth2用户displayName未在系统中找到对应账号: {}", username);
createLoginLog(null, workcode, LoginLogTypeEnum.LOGIN_SOCIAL, LoginResultEnum.BAD_CREDENTIALS);
log.warn("E办OAuth2用户工号未在系统中找到对应账号: {}", workcode);
throw exception(AUTH_LOGIN_EBAN_USER_NOT_SYNC);
}
@@ -92,7 +92,7 @@ public class EbanOAuth2ServiceImpl implements EbanOAuth2Service {
EbanTokenInfo tokenInfo = userInfo.getTokenInfo();
if (tokenInfo == null || StrUtil.isBlank(tokenInfo.getAccessToken())) {
log.error("E办OAuth2回调缺少有效的token信息uid={}, username={}", userInfo.getUid(), username);
log.error("E办OAuth2回调缺少有效的token信息uid={}, username={}", userInfo.getUid(), userInfo.getUsername());
throw exception(AUTH_LOGIN_EBAN_TOKEN_INVALID);
}
@@ -105,7 +105,7 @@ public class EbanOAuth2ServiceImpl implements EbanOAuth2Service {
tokenInfo.getExpiresIn(),
userInfo
);
log.info("成功保存E办tokenuserId={}, uid={}, username={}", user.getId(), userInfo.getUid(), username);
log.info("成功保存E办tokenuserId={}, uid={}, workcode={}", user.getId(), userInfo.getUid(), workcode);
return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL, ebanAccessTokenDO);

View File

@@ -101,6 +101,14 @@ public interface AdminUserService {
*/
AdminUserDO getUserByUsername(String username);
/**
* 通过工号查询用户
*
* @param workcode 工号
* @return 用户对象信息
*/
AdminUserDO getUserByWorkcode(String workcode);
/**
* 通过手机号获取用户
*

View File

@@ -125,6 +125,7 @@ public class AdminUserServiceImpl implements AdminUserService {
if (user.getUserSource() == null) {
user.setUserSource(UserSourceEnum.EXTERNAL.getSource());
}
user.setWorkcode(normalizeWorkcode(createReqVO.getWorkcode()));
PasswordStrategyEnum passwordStrategy = determinePasswordStrategy(user.getUserSource());
user.setAvatar(normalizeAvatarValue(createReqVO.getAvatar()));
user.setPassword(encodePassword(createReqVO.getPassword(), passwordStrategy));
@@ -190,6 +191,9 @@ public class AdminUserServiceImpl implements AdminUserService {
if (StrUtil.isNotBlank(updateReqVO.getNickname())) {
updateObj.setNickname(updateReqVO.getNickname());
}
if (updateReqVO.getWorkcode() != null) {
updateObj.setWorkcode(normalizeWorkcode(updateReqVO.getWorkcode()));
}
if (StrUtil.isNotBlank(updateReqVO.getMobile())) {
updateObj.setMobile(updateReqVO.getMobile());
}
@@ -330,6 +334,19 @@ public class AdminUserServiceImpl implements AdminUserService {
return user;
}
@Override
public AdminUserDO getUserByWorkcode(String workcode) {
String normalized = normalizeWorkcode(workcode);
if (StrUtil.isBlank(normalized)) {
return null;
}
AdminUserDO user = userMapper.selectByWorkcode(normalized);
if (user != null) {
fillUserDeptInfo(Collections.singletonList(user));
}
return user;
}
@Override
public AdminUserDO getUserByMobile(String mobile) {
AdminUserDO user = userMapper.selectByMobile(mobile);
@@ -510,6 +527,13 @@ public class AdminUserServiceImpl implements AdminUserService {
return StrUtil.isBlank(avatarValue) ? null : avatarValue.trim();
}
private String normalizeWorkcode(String workcode) {
if (StrUtil.isBlank(workcode)) {
return null;
}
return workcode.trim();
}
private AdminUserDO validateUserForCreateOrUpdate(Long id, String username, String mobile, String email,
Set<Long> deptIds, Set<Long> postIds, boolean skipAssociationValidation,
boolean skipMobileValidation, boolean skipEmailValidation) {