update:调整数据同步用户-部门,用户-岗位同步顺序
This commit is contained in:
@@ -35,34 +35,16 @@ public class DatabusUserDeptProviderApiImpl implements DatabusUserDeptProviderAp
|
||||
|
||||
@Override
|
||||
public CommonResult<CursorPageResult<DatabusUserDeptData>> getPageByCursor(CursorPageReqDTO reqDTO) {
|
||||
// 构建游标查询条件
|
||||
LambdaQueryWrapper<UserDeptDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 游标条件:create_time > cursorTime OR (create_time = cursorTime AND id > cursorId)
|
||||
if (!reqDTO.isFirstPage()) {
|
||||
queryWrapper.and(w -> w
|
||||
.gt(UserDeptDO::getCreateTime, reqDTO.getCursorTime())
|
||||
.or(o -> o
|
||||
.eq(UserDeptDO::getCreateTime, reqDTO.getCursorTime())
|
||||
.gt(UserDeptDO::getId, reqDTO.getCursorId())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// 租户过滤(如果指定)
|
||||
if (reqDTO.getTenantId() != null) {
|
||||
queryWrapper.eq(UserDeptDO::getTenantId, reqDTO.getTenantId());
|
||||
}
|
||||
|
||||
// 按 create_time, id 升序排列,确保顺序稳定
|
||||
queryWrapper.orderByAsc(UserDeptDO::getCreateTime)
|
||||
.orderByAsc(UserDeptDO::getId);
|
||||
|
||||
// 多查一条判断是否有更多数据
|
||||
int limit = reqDTO.getBatchSize() != null ? reqDTO.getBatchSize() : 100;
|
||||
queryWrapper.last("LIMIT " + (limit + 1));
|
||||
|
||||
List<UserDeptDO> list = userDeptMapper.selectList(queryWrapper);
|
||||
// ⚠️ 使用关联查询,只查询 userSource = 2 的用户的部门关系
|
||||
List<UserDeptDO> list = userDeptMapper.selectPageByCursorWithUserSource(
|
||||
reqDTO.isFirstPage() ? null : reqDTO.getCursorTime(),
|
||||
reqDTO.isFirstPage() ? null : reqDTO.getCursorId(),
|
||||
reqDTO.getTenantId(),
|
||||
limit + 1
|
||||
);
|
||||
|
||||
// 判断是否有更多
|
||||
boolean hasMore = list.size() > limit;
|
||||
@@ -82,14 +64,11 @@ public class DatabusUserDeptProviderApiImpl implements DatabusUserDeptProviderAp
|
||||
// 获取最后一条数据的游标
|
||||
UserDeptDO last = list.get(list.size() - 1);
|
||||
|
||||
// 首次查询时返回总数
|
||||
// 首次查询时返<EFBFBD><EFBFBD><EFBFBD>总数
|
||||
Long total = null;
|
||||
if (reqDTO.isFirstPage()) {
|
||||
LambdaQueryWrapper<UserDeptDO> countWrapper = new LambdaQueryWrapper<>();
|
||||
if (reqDTO.getTenantId() != null) {
|
||||
countWrapper.eq(UserDeptDO::getTenantId, reqDTO.getTenantId());
|
||||
}
|
||||
total = userDeptMapper.selectCount(countWrapper);
|
||||
// ⚠️ 只统计 userSource = 2 的用户的部门关系
|
||||
total = userDeptMapper.countWithUserSource(reqDTO.getTenantId());
|
||||
}
|
||||
|
||||
return success(CursorPageResult.of(
|
||||
@@ -128,11 +107,8 @@ public class DatabusUserDeptProviderApiImpl implements DatabusUserDeptProviderAp
|
||||
|
||||
@Override
|
||||
public CommonResult<Long> count(Long tenantId) {
|
||||
LambdaQueryWrapper<UserDeptDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (tenantId != null) {
|
||||
queryWrapper.eq(UserDeptDO::getTenantId, tenantId);
|
||||
}
|
||||
return success(userDeptMapper.selectCount(queryWrapper));
|
||||
// ⚠️ 只统计 userSource = 2 的用户的部门关系
|
||||
return success(userDeptMapper.countWithUserSource(tenantId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,31 +35,16 @@ public class DatabusUserPostProviderApiImpl implements DatabusUserPostProviderAp
|
||||
|
||||
@Override
|
||||
public CommonResult<CursorPageResult<DatabusUserPostData>> getPageByCursor(CursorPageReqDTO reqDTO) {
|
||||
// 构建游标查询条件
|
||||
LambdaQueryWrapper<UserPostDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 游标条件:create_time > cursorTime OR (create_time = cursorTime AND id > cursorId)
|
||||
if (!reqDTO.isFirstPage()) {
|
||||
queryWrapper.and(w -> w
|
||||
.gt(UserPostDO::getCreateTime, reqDTO.getCursorTime())
|
||||
.or(o -> o
|
||||
.eq(UserPostDO::getCreateTime, reqDTO.getCursorTime())
|
||||
.gt(UserPostDO::getId, reqDTO.getCursorId())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// 注意:UserPostDO 没有租户字段,忽略 tenantId 过滤
|
||||
|
||||
// 按 create_time, id 升序排列,确保顺序稳定
|
||||
queryWrapper.orderByAsc(UserPostDO::getCreateTime)
|
||||
.orderByAsc(UserPostDO::getId);
|
||||
|
||||
// 多查一条判断是否有更多数据
|
||||
int limit = reqDTO.getBatchSize() != null ? reqDTO.getBatchSize() : 100;
|
||||
queryWrapper.last("LIMIT " + (limit + 1));
|
||||
|
||||
List<UserPostDO> list = userPostMapper.selectList(queryWrapper);
|
||||
// ⚠️ 使用关联查询,只查询 userSource = 2 的用户的岗位关系
|
||||
List<UserPostDO> list = userPostMapper.selectPageByCursorWithUserSource(
|
||||
reqDTO.isFirstPage() ? null : reqDTO.getCursorTime(),
|
||||
reqDTO.isFirstPage() ? null : reqDTO.getCursorId(),
|
||||
reqDTO.getTenantId(),
|
||||
limit + 1
|
||||
);
|
||||
|
||||
// 判断是否有更多
|
||||
boolean hasMore = list.size() > limit;
|
||||
@@ -82,7 +67,8 @@ public class DatabusUserPostProviderApiImpl implements DatabusUserPostProviderAp
|
||||
// 首次查询时返回总数
|
||||
Long total = null;
|
||||
if (reqDTO.isFirstPage()) {
|
||||
total = userPostMapper.selectCount(new LambdaQueryWrapper<>());
|
||||
// ⚠️ 只统计 userSource = 2 的用户的岗位关系
|
||||
total = userPostMapper.countWithUserSource(reqDTO.getTenantId());
|
||||
}
|
||||
|
||||
return success(CursorPageResult.of(
|
||||
@@ -121,8 +107,8 @@ public class DatabusUserPostProviderApiImpl implements DatabusUserPostProviderAp
|
||||
|
||||
@Override
|
||||
public CommonResult<Long> count(Long tenantId) {
|
||||
// 注意:UserPostDO 没有租户字段,返回全量总数
|
||||
return success(userPostMapper.selectCount(new LambdaQueryWrapper<>()));
|
||||
// ⚠️ 只统计 userSource = 2 的用户的岗位关系
|
||||
return success(userPostMapper.countWithUserSource(tenantId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,6 +54,9 @@ public class DatabusUserProviderApiImpl implements DatabusUserProviderApi {
|
||||
// 构建游标查询条件
|
||||
LambdaQueryWrapper<AdminUserDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// ⚠️ 只同步 userSource = 2 的用户
|
||||
queryWrapper.eq(AdminUserDO::getUserSource, 2);
|
||||
|
||||
// 游标条件:create_time > cursorTime OR (create_time = cursorTime AND id > cursorId)
|
||||
if (!reqDTO.isFirstPage()) {
|
||||
queryWrapper.and(w -> w
|
||||
@@ -100,6 +103,8 @@ public class DatabusUserProviderApiImpl implements DatabusUserProviderApi {
|
||||
Long total = null;
|
||||
if (reqDTO.isFirstPage()) {
|
||||
LambdaQueryWrapper<AdminUserDO> countWrapper = new LambdaQueryWrapper<>();
|
||||
// ⚠️ 只统计 userSource = 2 的用户
|
||||
countWrapper.eq(AdminUserDO::getUserSource, 2);
|
||||
if (reqDTO.getTenantId() != null) {
|
||||
countWrapper.eq(AdminUserDO::getTenantId, reqDTO.getTenantId());
|
||||
}
|
||||
@@ -143,6 +148,8 @@ public class DatabusUserProviderApiImpl implements DatabusUserProviderApi {
|
||||
@Override
|
||||
public CommonResult<Long> count(Long tenantId) {
|
||||
LambdaQueryWrapper<AdminUserDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// ⚠️ 只统计 userSource = 2 的用户
|
||||
queryWrapper.eq(AdminUserDO::getUserSource, 2);
|
||||
if (tenantId != null) {
|
||||
queryWrapper.eq(AdminUserDO::getTenantId, tenantId);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.zt.plat.module.system.dal.dataobject.dept.UserPostDO;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,4 +32,44 @@ public interface UserPostMapper extends BaseMapperX<UserPostDO> {
|
||||
default void deleteByUserId(Long userId) {
|
||||
delete(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 游标分页查询用户-岗位关系(只查询 userSource = 2 的用户)
|
||||
* @param cursorTime 游标时间
|
||||
* @param cursorId 游标ID
|
||||
* @param tenantId 租户ID(可选)
|
||||
* @param limit 限制数量
|
||||
* @return 用户岗位关系列表
|
||||
*/
|
||||
@Select("<script>" +
|
||||
"SELECT up.* FROM system_user_post up " +
|
||||
"INNER JOIN system_users u ON up.user_id = u.id " +
|
||||
"WHERE u.user_source = 2 " +
|
||||
"AND up.deleted = 0 " +
|
||||
"<if test='tenantId != null'> AND up.tenant_id = #{tenantId} </if>" +
|
||||
"<if test='cursorTime != null'>" +
|
||||
" AND (up.create_time > #{cursorTime} " +
|
||||
" OR (up.create_time = #{cursorTime} AND up.id > #{cursorId}))" +
|
||||
"</if>" +
|
||||
"ORDER BY up.create_time ASC, up.id ASC " +
|
||||
"LIMIT #{limit}" +
|
||||
"</script>")
|
||||
List<UserPostDO> selectPageByCursorWithUserSource(@Param("cursorTime") LocalDateTime cursorTime,
|
||||
@Param("cursorId") Long cursorId,
|
||||
@Param("tenantId") Long tenantId,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
/**
|
||||
* 统计用户-岗位关系数量(只统计 userSource = 2 的用户)
|
||||
* @param tenantId 租户ID(可选)
|
||||
* @return 数量
|
||||
*/
|
||||
@Select("<script>" +
|
||||
"SELECT COUNT(*) FROM system_user_post up " +
|
||||
"INNER JOIN system_users u ON up.user_id = u.id " +
|
||||
"WHERE u.user_source = 2 " +
|
||||
"AND up.deleted = 0 " +
|
||||
"<if test='tenantId != null'> AND up.tenant_id = #{tenantId} </if>" +
|
||||
"</script>")
|
||||
Long countWithUserSource(@Param("tenantId") Long tenantId);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.zt.plat.module.system.dal.dataobject.userdept.UserDeptDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -45,4 +48,44 @@ public interface UserDeptMapper extends BaseMapperX<UserDeptDO> {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 游标分页查询用户-部门关系(只查询 userSource = 2 的用户)
|
||||
* @param cursorTime 游标时间
|
||||
* @param cursorId 游标ID
|
||||
* @param tenantId 租户ID(可选)
|
||||
* @param limit 限制数量
|
||||
* @return 用户部门关系列表
|
||||
*/
|
||||
@Select("<script>" +
|
||||
"SELECT ud.* FROM system_user_dept ud " +
|
||||
"INNER JOIN system_users u ON ud.user_id = u.id " +
|
||||
"WHERE u.user_source = 2 " +
|
||||
"AND ud.deleted = 0 " +
|
||||
"<if test='tenantId != null'> AND ud.tenant_id = #{tenantId} </if>" +
|
||||
"<if test='cursorTime != null'>" +
|
||||
" AND (ud.create_time > #{cursorTime} " +
|
||||
" OR (ud.create_time = #{cursorTime} AND ud.id > #{cursorId}))" +
|
||||
"</if>" +
|
||||
"ORDER BY ud.create_time ASC, ud.id ASC " +
|
||||
"LIMIT #{limit}" +
|
||||
"</script>")
|
||||
List<UserDeptDO> selectPageByCursorWithUserSource(@Param("cursorTime") LocalDateTime cursorTime,
|
||||
@Param("cursorId") Long cursorId,
|
||||
@Param("tenantId") Long tenantId,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
/**
|
||||
* 统计用户-部门关系数量(只统计 userSource = 2 的用户)
|
||||
* @param tenantId 租户ID(可选)
|
||||
* @return 数量
|
||||
*/
|
||||
@Select("<script>" +
|
||||
"SELECT COUNT(*) FROM system_user_dept ud " +
|
||||
"INNER JOIN system_users u ON ud.user_id = u.id " +
|
||||
"WHERE u.user_source = 2 " +
|
||||
"AND ud.deleted = 0 " +
|
||||
"<if test='tenantId != null'> AND ud.tenant_id = #{tenantId} </if>" +
|
||||
"</script>")
|
||||
Long countWithUserSource(@Param("tenantId") Long tenantId);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user