Merge remote-tracking branch 'base-version/test' into dev
This commit is contained in:
@@ -48,4 +48,9 @@ public class OAuth2TokenApiImpl implements OAuth2TokenCommonApi {
|
||||
return success(BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> removeAccessTokensByUserIdAndClientId(Long userId, String clientId) {
|
||||
return success(oauth2TokenService.removeAccessTokensByUserIdAndClientId(userId, clientId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ public class AuthLoginReqVO extends CaptchaVerificationReqVO {
|
||||
// @Length(min = 4, max = 16, message = "密码长度为 4-16 位")
|
||||
private String password;
|
||||
|
||||
@Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "default")
|
||||
private String clientId;
|
||||
|
||||
// ========== 绑定社交登录时,需要传递如下参数 ==========
|
||||
|
||||
@Schema(description = "社交平台的类型,参见 SocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
|
||||
@@ -24,4 +24,7 @@ public class AuthSmsLoginReqVO {
|
||||
@NotEmpty(message = "验证码不能为空")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "default")
|
||||
private String clientId;
|
||||
|
||||
}
|
||||
|
||||
@@ -30,4 +30,7 @@ public class AuthSocialLoginReqVO {
|
||||
@NotEmpty(message = "state 不能为空")
|
||||
private String state;
|
||||
|
||||
@Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "default")
|
||||
private String clientId;
|
||||
|
||||
}
|
||||
|
||||
@@ -26,4 +26,7 @@ public class AuthTestLoginReqVO {
|
||||
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
|
||||
private String password;
|
||||
|
||||
@Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "default")
|
||||
private String clientId;
|
||||
|
||||
}
|
||||
@@ -176,16 +176,43 @@ public class IWorkIntegrationController {
|
||||
return success(syncService.fullSyncUsers(reqVO));
|
||||
}
|
||||
|
||||
// ----------------- 根据ID同步到本地 -----------------
|
||||
// ----------------- 根据ID同步到本地(仅传 ID) -----------------
|
||||
|
||||
@PostMapping("/syncById")
|
||||
@Operation(summary = "根据ID触发 iWork 同步公司")
|
||||
public CommonResult<IWorkFullSyncRespVO> syncById(@Valid @RequestBody IWorkSyncByIdReqVO reqVO) {
|
||||
|
||||
log.error("IWork集成后端手动录入syncById{}",reqVO);
|
||||
return success(syncService.manuallySyncData(reqVO));
|
||||
@PostMapping("/sync/user-by-id")
|
||||
@Operation(summary = "根据ID同步 iWork 人员(单条)")
|
||||
public CommonResult<IWorkFullSyncRespVO> syncUserById(@Valid @RequestBody IWorkSyncByIdReqVO reqVO) {
|
||||
IWorkFullSyncReqVO fullReq = new IWorkFullSyncReqVO();
|
||||
fullReq.setId(reqVO.getId());
|
||||
fullReq.setStartPage(1);
|
||||
fullReq.setPageSize(1);
|
||||
fullReq.setMaxPages(1);
|
||||
fullReq.setAllowUpdate(Boolean.TRUE);
|
||||
return success(syncService.fullSyncUsers(fullReq));
|
||||
}
|
||||
|
||||
@PostMapping("/sync/department-by-id")
|
||||
@Operation(summary = "根据ID同步 iWork 部门(单条)")
|
||||
public CommonResult<IWorkFullSyncRespVO> syncDepartmentById(@Valid @RequestBody IWorkSyncByIdReqVO reqVO) {
|
||||
IWorkFullSyncReqVO fullReq = new IWorkFullSyncReqVO();
|
||||
fullReq.setId(reqVO.getId());
|
||||
fullReq.setStartPage(1);
|
||||
fullReq.setPageSize(1);
|
||||
fullReq.setMaxPages(1);
|
||||
fullReq.setAllowUpdate(Boolean.TRUE);
|
||||
return success(syncService.fullSyncDepartments(fullReq));
|
||||
}
|
||||
|
||||
@PostMapping("/sync/subcompany-by-id")
|
||||
@Operation(summary = "根据ID同步 iWork 分部(单条)")
|
||||
public CommonResult<IWorkFullSyncRespVO> syncSubcompanyById(@Valid @RequestBody IWorkSyncByIdReqVO reqVO) {
|
||||
IWorkFullSyncReqVO fullReq = new IWorkFullSyncReqVO();
|
||||
fullReq.setId(reqVO.getId());
|
||||
fullReq.setStartPage(1);
|
||||
fullReq.setPageSize(1);
|
||||
fullReq.setMaxPages(1);
|
||||
fullReq.setAllowUpdate(Boolean.TRUE);
|
||||
return success(syncService.fullSyncSubcompanies(fullReq));
|
||||
}
|
||||
|
||||
private ResponseEntity<String> buildOaResponse(IWorkOaRawResponse resp) {
|
||||
if (resp == null) {
|
||||
|
||||
@@ -1,99 +1,15 @@
|
||||
package com.zt.plat.module.system.controller.admin.integration.iwork.vo;
|
||||
|
||||
import com.zt.plat.module.system.enums.integration.IWorkSyncEntityTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* iWork 手动同步请求
|
||||
*/
|
||||
@Data
|
||||
public class IWorkSyncByIdReqVO {
|
||||
|
||||
|
||||
@Schema(description = "起始页码,从 1 开始", example = "1")
|
||||
@Min(1)
|
||||
private Integer startPage = 1;
|
||||
|
||||
@Schema(description = "最大处理页数,null 表示处理至 iWork 返回的末页", example = "10")
|
||||
@Min(1)
|
||||
private Integer maxPages;
|
||||
|
||||
@Schema(description = "每次分页从 iWork 拉取的记录数", example = "100")
|
||||
@Min(1)
|
||||
@Max(500)
|
||||
private Integer pageSize = 100;
|
||||
|
||||
@Schema(description = "同步范围列表,默认同步全部。可选:subcompany、department、jobTitle、user")
|
||||
private List<String> scopes;
|
||||
|
||||
@Schema(description = "是否包含已失效(canceled=1)的记录", example = "false")
|
||||
private Boolean includeCanceled = Boolean.FALSE;
|
||||
|
||||
@Schema(description = "是否允许更新已存在的本地实体", example = "false")
|
||||
private Boolean allowUpdate = Boolean.FALSE;
|
||||
|
||||
|
||||
@Schema(description = "指定同步记录的 iWork ID。传入后仅同步对应记录", example = "12345")
|
||||
@NotBlank(message = "ID不能为空")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "部门编码", example = "ZT001")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "部门名称", example = "ZT")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "部门简称", example = "技术")
|
||||
private String shortName;
|
||||
|
||||
@Schema(description = "父部门 ID", example = "1024")
|
||||
private String parentId;
|
||||
|
||||
@Schema(description = "负责人的用户编号", example = "2048")
|
||||
private String leaderUserId;
|
||||
|
||||
@Schema(description = "联系电话", example = "15601691000")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "邮箱", example = "zt@iocoder.cn")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "状态,见 CommonStatusEnum 枚举0 开启 1 关闭", example = "0")
|
||||
private Integer status;
|
||||
|
||||
private Long tenantId;
|
||||
|
||||
@Schema(description = "是否公司", example = "false")
|
||||
private boolean isCompany;
|
||||
|
||||
@Schema(description = "是否集团", example = "false")
|
||||
private boolean isGroup;
|
||||
|
||||
private boolean hasChildren;
|
||||
|
||||
|
||||
public Set<IWorkSyncEntityTypeEnum> resolveScopes() {
|
||||
EnumSet<IWorkSyncEntityTypeEnum> defaults = EnumSet.allOf(IWorkSyncEntityTypeEnum.class);
|
||||
if (scopes == null || scopes.isEmpty()) {
|
||||
return defaults;
|
||||
}
|
||||
Set<IWorkSyncEntityTypeEnum> resolved = scopes.stream()
|
||||
.map(IWorkSyncEntityTypeEnum::fromCode)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.collect(Collectors.toCollection(() -> EnumSet.noneOf(IWorkSyncEntityTypeEnum.class)));
|
||||
if (resolved.isEmpty()) {
|
||||
return defaults;
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,12 @@ public interface OAuth2AccessTokenMapper extends BaseMapperX<OAuth2AccessTokenDO
|
||||
.eq(OAuth2AccessTokenDO::getClientId, clientId));
|
||||
}
|
||||
|
||||
default List<OAuth2AccessTokenDO> selectListByUserIdAndClientId(Long userId, String clientId) {
|
||||
return selectList(new LambdaQueryWrapperX<OAuth2AccessTokenDO>()
|
||||
.eq(OAuth2AccessTokenDO::getUserId, userId)
|
||||
.eq(OAuth2AccessTokenDO::getClientId, clientId));
|
||||
}
|
||||
|
||||
default List<OAuth2AccessTokenDO> selectListByRefreshToken(String refreshToken) {
|
||||
return selectList(OAuth2AccessTokenDO::getRefreshToken, refreshToken);
|
||||
}
|
||||
|
||||
@@ -19,4 +19,10 @@ public interface OAuth2RefreshTokenMapper extends BaseMapperX<OAuth2RefreshToken
|
||||
return selectOne(OAuth2RefreshTokenDO::getRefreshToken, refreshToken);
|
||||
}
|
||||
|
||||
default int deleteByUserIdAndClientId(Long userId, String clientId) {
|
||||
return delete(new LambdaQueryWrapperX<OAuth2RefreshTokenDO>()
|
||||
.eq(OAuth2RefreshTokenDO::getUserId, userId)
|
||||
.eq(OAuth2RefreshTokenDO::getClientId, clientId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState()));
|
||||
}
|
||||
// 创建 Token 令牌,记录登录日志
|
||||
return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
|
||||
return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME, reqVO.getClientId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,7 +167,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
}
|
||||
|
||||
// 创建 Token 令牌,记录登录日志
|
||||
return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
|
||||
return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME, reqVO.getClientId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,7 +200,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
}
|
||||
|
||||
// 创建 Token 令牌,记录登录日志
|
||||
return createTokenAfterLoginSuccess(user.getId(), reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE);
|
||||
return createTokenAfterLoginSuccess(user.getId(), reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE, reqVO.getClientId());
|
||||
}
|
||||
|
||||
private void createLoginLog(Long userId, String username,
|
||||
@@ -238,7 +238,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
}
|
||||
|
||||
// 创建 Token 令牌,记录登录日志
|
||||
return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL);
|
||||
return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL, reqVO.getClientId());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -267,16 +267,25 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
return captchaService.verification(captchaVO);
|
||||
}
|
||||
|
||||
private AuthLoginRespVO createTokenAfterLoginSuccess(Long userId, String username, LoginLogTypeEnum logType) {
|
||||
private AuthLoginRespVO createTokenAfterLoginSuccess(Long userId, String username, LoginLogTypeEnum logType,
|
||||
String clientId) {
|
||||
// 插入登陆日志
|
||||
createLoginLog(userId, username, logType, LoginResultEnum.SUCCESS);
|
||||
// 创建访问令牌
|
||||
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, getUserType().getValue(),
|
||||
OAuth2ClientConstants.CLIENT_ID_DEFAULT, null);
|
||||
resolveClientId(clientId), null);
|
||||
// 构建返回结果
|
||||
return AuthConvert.INSTANCE.convert(accessTokenDO);
|
||||
}
|
||||
|
||||
private AuthLoginRespVO createTokenAfterLoginSuccess(Long userId, String username, LoginLogTypeEnum logType) {
|
||||
return createTokenAfterLoginSuccess(userId, username, logType, OAuth2ClientConstants.CLIENT_ID_DEFAULT);
|
||||
}
|
||||
|
||||
private String resolveClientId(String clientId) {
|
||||
return StringUtils.isBlank(clientId) ? OAuth2ClientConstants.CLIENT_ID_DEFAULT : clientId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthLoginRespVO refreshToken(String refreshToken) {
|
||||
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, OAuth2ClientConstants.CLIENT_ID_DEFAULT);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user