update:调整数据同步用户-部门,用户-岗位同步顺序
This commit is contained in:
@@ -0,0 +1,81 @@
|
|||||||
|
package com.zt.plat.framework.databus.server.provider;
|
||||||
|
|
||||||
|
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||||
|
import com.zt.plat.framework.databus.server.core.provider.DataProvider;
|
||||||
|
import com.zt.plat.framework.databus.server.core.provider.DataProviderRegistry;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageReqDTO;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageResult;
|
||||||
|
import com.zt.plat.module.databus.api.data.DatabusUserDeptData;
|
||||||
|
import com.zt.plat.module.databus.api.provider.DatabusUserDeptProviderApi;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户-部门关系数据提供者
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class UserDeptDataFeignProvider implements DataProvider<DatabusUserDeptData> {
|
||||||
|
|
||||||
|
public static final String PROVIDER_TYPE = "USER_DEPT";
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DatabusUserDeptProviderApi userDeptProviderApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DataProviderRegistry dataProviderRegistry;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
dataProviderRegistry.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProviderType() {
|
||||||
|
return PROVIDER_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CursorPageData<DatabusUserDeptData> getPageByCursor(LocalDateTime cursorTime, Long cursorId,
|
||||||
|
int batchSize, Long tenantId) {
|
||||||
|
CursorPageReqDTO reqDTO = CursorPageReqDTO.builder()
|
||||||
|
.cursorTime(cursorTime)
|
||||||
|
.cursorId(cursorId)
|
||||||
|
.batchSize(batchSize)
|
||||||
|
.tenantId(tenantId)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
CommonResult<CursorPageResult<DatabusUserDeptData>> result = userDeptProviderApi.getPageByCursor(reqDTO);
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
throw new RuntimeException("获取用户-部门关系数据失败: " + result.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
CursorPageResult<DatabusUserDeptData> pageResult = result.getData();
|
||||||
|
return CursorPageData.of(
|
||||||
|
pageResult.getList(),
|
||||||
|
pageResult.getNextCursorTime(),
|
||||||
|
pageResult.getNextCursorId(),
|
||||||
|
pageResult.getCount(),
|
||||||
|
Boolean.TRUE.equals(pageResult.getHasMore()),
|
||||||
|
(pageResult.getTotal() != null ? pageResult.getTotal() : 0L)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long count(Long tenantId) {
|
||||||
|
CommonResult<Long> result = userDeptProviderApi.count(tenantId);
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
throw new RuntimeException("获取用户-部门关系总数失败: " + result.getMsg());
|
||||||
|
}
|
||||||
|
return result.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long extractUid(DatabusUserDeptData data) {
|
||||||
|
return data.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package com.zt.plat.framework.databus.server.provider;
|
||||||
|
|
||||||
|
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||||
|
import com.zt.plat.framework.databus.server.core.provider.DataProvider;
|
||||||
|
import com.zt.plat.framework.databus.server.core.provider.DataProviderRegistry;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageReqDTO;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageResult;
|
||||||
|
import com.zt.plat.module.databus.api.data.DatabusUserPostData;
|
||||||
|
import com.zt.plat.module.databus.api.provider.DatabusUserPostProviderApi;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户-岗位关系数据提供者
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class UserPostDataFeignProvider implements DataProvider<DatabusUserPostData> {
|
||||||
|
|
||||||
|
public static final String PROVIDER_TYPE = "USER_POST";
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DatabusUserPostProviderApi userPostProviderApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DataProviderRegistry dataProviderRegistry;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
dataProviderRegistry.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProviderType() {
|
||||||
|
return PROVIDER_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CursorPageData<DatabusUserPostData> getPageByCursor(LocalDateTime cursorTime, Long cursorId,
|
||||||
|
int batchSize, Long tenantId) {
|
||||||
|
CursorPageReqDTO reqDTO = CursorPageReqDTO.builder()
|
||||||
|
.cursorTime(cursorTime)
|
||||||
|
.cursorId(cursorId)
|
||||||
|
.batchSize(batchSize)
|
||||||
|
.tenantId(tenantId)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
CommonResult<CursorPageResult<DatabusUserPostData>> result = userPostProviderApi.getPageByCursor(reqDTO);
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
throw new RuntimeException("获取用户-岗位关系数据失败: " + result.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
CursorPageResult<DatabusUserPostData> pageResult = result.getData();
|
||||||
|
return CursorPageData.of(
|
||||||
|
pageResult.getList(),
|
||||||
|
pageResult.getNextCursorTime(),
|
||||||
|
pageResult.getNextCursorId(),
|
||||||
|
pageResult.getCount(),
|
||||||
|
Boolean.TRUE.equals(pageResult.getHasMore()),
|
||||||
|
(pageResult.getTotal() != null ? pageResult.getTotal() : 0L)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long count(Long tenantId) {
|
||||||
|
CommonResult<Long> result = userPostProviderApi.count(tenantId);
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
throw new RuntimeException("获取用户-岗位关系总数失败: " + result.getMsg());
|
||||||
|
}
|
||||||
|
return result.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long extractUid(DatabusUserPostData data) {
|
||||||
|
return data.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.zt.plat.module.databus.api.provider;
|
||||||
|
|
||||||
|
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||||
|
import com.zt.plat.module.databus.api.data.DatabusUserDeptData;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageReqDTO;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageResult;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Databus 用户-部门关系数据提供者 API
|
||||||
|
* <p>
|
||||||
|
* 供 Databus 调用,获取用户-部门关联数据用于全量/增量同步
|
||||||
|
*
|
||||||
|
* @author ZT
|
||||||
|
*/
|
||||||
|
@FeignClient(name = "${databus.provider.user-dept.service:system-server}")
|
||||||
|
@Tag(name = "RPC 服务 - Databus 用户-部门关系数据提供者")
|
||||||
|
public interface DatabusUserDeptProviderApi {
|
||||||
|
|
||||||
|
String PREFIX = "/rpc/databus/user-dept";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 游标分页查询用户-部门关系数据(用于全量同步)
|
||||||
|
*
|
||||||
|
* @param reqDTO 游标分页请求
|
||||||
|
* @return 用户-部门关系数据分页结果
|
||||||
|
*/
|
||||||
|
@PostMapping(PREFIX + "/page-by-cursor")
|
||||||
|
@Operation(summary = "游标分页查询用户-部门关系数据")
|
||||||
|
CommonResult<CursorPageResult<DatabusUserDeptData>> getPageByCursor(@RequestBody CursorPageReqDTO reqDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询用户-部门关系详情(用于增量同步)
|
||||||
|
*
|
||||||
|
* @param id 关系ID
|
||||||
|
* @return 用户-部门关系数据
|
||||||
|
*/
|
||||||
|
@GetMapping(PREFIX + "/get")
|
||||||
|
@Operation(summary = "查询用户-部门关系详情")
|
||||||
|
@Parameter(name = "id", description = "关系ID", required = true, example = "1001")
|
||||||
|
CommonResult<DatabusUserDeptData> getById(@RequestParam("id") Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量查询用户-部门关系详情(用于增量同步批量获取)
|
||||||
|
*
|
||||||
|
* @param ids 关系ID列表
|
||||||
|
* @return 用户-部门关系数据列表
|
||||||
|
*/
|
||||||
|
@GetMapping(PREFIX + "/list")
|
||||||
|
@Operation(summary = "批量查询用户-部门关系详情")
|
||||||
|
@Parameter(name = "ids", description = "关系ID列表", required = true, example = "1001,1002,1003")
|
||||||
|
CommonResult<List<DatabusUserDeptData>> getListByIds(@RequestParam("ids") List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计用户-部门关系总数(用于全量同步进度计算)
|
||||||
|
*
|
||||||
|
* @param tenantId 租户ID(可选)
|
||||||
|
* @return 用户-部门关系总数
|
||||||
|
*/
|
||||||
|
@GetMapping(PREFIX + "/count")
|
||||||
|
@Operation(summary = "统计用户-部门关系总数")
|
||||||
|
@Parameter(name = "tenantId", description = "租户ID", example = "1")
|
||||||
|
CommonResult<Long> count(@RequestParam(value = "tenantId", required = false) Long tenantId);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.zt.plat.module.databus.api.provider;
|
||||||
|
|
||||||
|
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||||
|
import com.zt.plat.module.databus.api.data.DatabusUserPostData;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageReqDTO;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageResult;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Databus 用户-岗位关系数据提供者 API
|
||||||
|
* <p>
|
||||||
|
* 供 Databus 调用,获取用户-岗位关联数据用于全量/增量同步
|
||||||
|
*
|
||||||
|
* @author ZT
|
||||||
|
*/
|
||||||
|
@FeignClient(name = "${databus.provider.user-post.service:system-server}")
|
||||||
|
@Tag(name = "RPC 服务 - Databus 用户-岗位关系数据提供者")
|
||||||
|
public interface DatabusUserPostProviderApi {
|
||||||
|
|
||||||
|
String PREFIX = "/rpc/databus/user-post";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 游标分页查询用户-岗位关系数据(用于全量同步)
|
||||||
|
*
|
||||||
|
* @param reqDTO 游标分页请求
|
||||||
|
* @return 用户-岗位关系数据分页结果
|
||||||
|
*/
|
||||||
|
@PostMapping(PREFIX + "/page-by-cursor")
|
||||||
|
@Operation(summary = "游标分页查询用户-岗位关系数据")
|
||||||
|
CommonResult<CursorPageResult<DatabusUserPostData>> getPageByCursor(@RequestBody CursorPageReqDTO reqDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询用户-岗位关系详情(用于增量同步)
|
||||||
|
*
|
||||||
|
* @param id 关系ID
|
||||||
|
* @return 用户-岗位关系数据
|
||||||
|
*/
|
||||||
|
@GetMapping(PREFIX + "/get")
|
||||||
|
@Operation(summary = "查询用户-岗位关系详情")
|
||||||
|
@Parameter(name = "id", description = "关系ID", required = true, example = "1001")
|
||||||
|
CommonResult<DatabusUserPostData> getById(@RequestParam("id") Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量查询用户-岗位关系详情(用于增量同步批量获取)
|
||||||
|
*
|
||||||
|
* @param ids 关系ID列表
|
||||||
|
* @return 用户-岗位关系数据列表
|
||||||
|
*/
|
||||||
|
@GetMapping(PREFIX + "/list")
|
||||||
|
@Operation(summary = "批量查询用户-岗位关系详情")
|
||||||
|
@Parameter(name = "ids", description = "关系ID列表", required = true, example = "1001,1002,1003")
|
||||||
|
CommonResult<List<DatabusUserPostData>> getListByIds(@RequestParam("ids") List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计用户-岗位关系总数(用于全量同步进度计算)
|
||||||
|
*
|
||||||
|
* @param tenantId 租户ID(可选)
|
||||||
|
* @return 用户-岗位关系总数
|
||||||
|
*/
|
||||||
|
@GetMapping(PREFIX + "/count")
|
||||||
|
@Operation(summary = "统计用户-岗位关系总数")
|
||||||
|
@Parameter(name = "tenantId", description = "租户ID", example = "1")
|
||||||
|
CommonResult<Long> count(@RequestParam(value = "tenantId", required = false) Long tenantId);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ import com.zt.plat.framework.common.biz.system.oauth2.OAuth2TokenCommonApi;
|
|||||||
import com.zt.plat.module.databus.api.provider.DatabusDeptProviderApi;
|
import com.zt.plat.module.databus.api.provider.DatabusDeptProviderApi;
|
||||||
import com.zt.plat.module.databus.api.provider.DatabusPostProviderApi;
|
import com.zt.plat.module.databus.api.provider.DatabusPostProviderApi;
|
||||||
import com.zt.plat.module.databus.api.provider.DatabusUserProviderApi;
|
import com.zt.plat.module.databus.api.provider.DatabusUserProviderApi;
|
||||||
|
import com.zt.plat.module.databus.api.provider.DatabusUserDeptProviderApi;
|
||||||
|
import com.zt.plat.module.databus.api.provider.DatabusUserPostProviderApi;
|
||||||
import com.zt.plat.module.system.api.dept.DeptApi;
|
import com.zt.plat.module.system.api.dept.DeptApi;
|
||||||
import com.zt.plat.module.system.api.dept.PostApi;
|
import com.zt.plat.module.system.api.dept.PostApi;
|
||||||
import com.zt.plat.module.system.api.user.AdminUserApi;
|
import com.zt.plat.module.system.api.user.AdminUserApi;
|
||||||
@@ -21,9 +23,10 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
DatabusDeptProviderApi.class,
|
DatabusDeptProviderApi.class,
|
||||||
DatabusUserProviderApi.class,
|
DatabusUserProviderApi.class,
|
||||||
DatabusPostProviderApi.class,
|
DatabusPostProviderApi.class,
|
||||||
PostApi.class,
|
DatabusUserDeptProviderApi.class,
|
||||||
DeptApi.class,
|
DatabusUserPostProviderApi.class,
|
||||||
AdminUserApi.class,
|
PostApi.class,
|
||||||
|
DeptApi.class,
|
||||||
})
|
})
|
||||||
public class RpcConfiguration {
|
public class RpcConfiguration {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package com.zt.plat.module.system.api.databus;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||||
|
import com.zt.plat.module.databus.api.data.DatabusUserDeptData;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageReqDTO;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageResult;
|
||||||
|
import com.zt.plat.module.databus.api.provider.DatabusUserDeptProviderApi;
|
||||||
|
import com.zt.plat.module.system.dal.dataobject.userdept.UserDeptDO;
|
||||||
|
import com.zt.plat.module.system.dal.mysql.userdept.UserDeptMapper;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Databus 用户-部门关系数据提供者 API 实现
|
||||||
|
*
|
||||||
|
* @author ZT
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@Validated
|
||||||
|
public class DatabusUserDeptProviderApiImpl implements DatabusUserDeptProviderApi {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserDeptMapper userDeptMapper;
|
||||||
|
|
||||||
|
@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);
|
||||||
|
|
||||||
|
// 判断是否有更多
|
||||||
|
boolean hasMore = list.size() > limit;
|
||||||
|
if (hasMore) {
|
||||||
|
list = list.subList(0, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CollUtil.isEmpty(list)) {
|
||||||
|
return success(CursorPageResult.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换为同步数据
|
||||||
|
List<DatabusUserDeptData> dataList = list.stream()
|
||||||
|
.map(this::convertToData)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 获取最后一条数据的游标
|
||||||
|
UserDeptDO last = list.get(list.size() - 1);
|
||||||
|
|
||||||
|
// 首次查询时返回总数
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success(CursorPageResult.of(
|
||||||
|
dataList,
|
||||||
|
last.getCreateTime(),
|
||||||
|
last.getId(),
|
||||||
|
hasMore,
|
||||||
|
total
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<DatabusUserDeptData> getById(Long id) {
|
||||||
|
UserDeptDO userDept = userDeptMapper.selectById(id);
|
||||||
|
if (userDept == null) {
|
||||||
|
return success(null);
|
||||||
|
}
|
||||||
|
return success(convertToData(userDept));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<List<DatabusUserDeptData>> getListByIds(List<Long> ids) {
|
||||||
|
if (CollUtil.isEmpty(ids)) {
|
||||||
|
return success(Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UserDeptDO> list = userDeptMapper.selectBatchIds(ids);
|
||||||
|
if (CollUtil.isEmpty(list)) {
|
||||||
|
return success(Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return success(list.stream()
|
||||||
|
.map(this::convertToData)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@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));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 UserDeptDO 转换为 DatabusUserDeptData
|
||||||
|
*/
|
||||||
|
private DatabusUserDeptData convertToData(UserDeptDO userDept) {
|
||||||
|
return DatabusUserDeptData.builder()
|
||||||
|
.id(userDept.getId())
|
||||||
|
.userId(userDept.getUserId())
|
||||||
|
.deptId(userDept.getDeptId())
|
||||||
|
.tenantId(userDept.getTenantId())
|
||||||
|
.remark(userDept.getRemark())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
package com.zt.plat.module.system.api.databus;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||||
|
import com.zt.plat.module.databus.api.data.DatabusUserPostData;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageReqDTO;
|
||||||
|
import com.zt.plat.module.databus.api.dto.CursorPageResult;
|
||||||
|
import com.zt.plat.module.databus.api.provider.DatabusUserPostProviderApi;
|
||||||
|
import com.zt.plat.module.system.dal.dataobject.dept.UserPostDO;
|
||||||
|
import com.zt.plat.module.system.dal.mysql.dept.UserPostMapper;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Databus 用户-岗位关系数据提供者 API 实现
|
||||||
|
*
|
||||||
|
* @author ZT
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@Validated
|
||||||
|
public class DatabusUserPostProviderApiImpl implements DatabusUserPostProviderApi {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserPostMapper userPostMapper;
|
||||||
|
|
||||||
|
@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);
|
||||||
|
|
||||||
|
// 判断是否有更多
|
||||||
|
boolean hasMore = list.size() > limit;
|
||||||
|
if (hasMore) {
|
||||||
|
list = list.subList(0, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CollUtil.isEmpty(list)) {
|
||||||
|
return success(CursorPageResult.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换为同步数据
|
||||||
|
List<DatabusUserPostData> dataList = list.stream()
|
||||||
|
.map(this::convertToData)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 获取最后一条数据的游标
|
||||||
|
UserPostDO last = list.get(list.size() - 1);
|
||||||
|
|
||||||
|
// 首次查询时返回总数
|
||||||
|
Long total = null;
|
||||||
|
if (reqDTO.isFirstPage()) {
|
||||||
|
total = userPostMapper.selectCount(new LambdaQueryWrapper<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
return success(CursorPageResult.of(
|
||||||
|
dataList,
|
||||||
|
last.getCreateTime(),
|
||||||
|
last.getId(),
|
||||||
|
hasMore,
|
||||||
|
total
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<DatabusUserPostData> getById(Long id) {
|
||||||
|
UserPostDO userPost = userPostMapper.selectById(id);
|
||||||
|
if (userPost == null) {
|
||||||
|
return success(null);
|
||||||
|
}
|
||||||
|
return success(convertToData(userPost));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<List<DatabusUserPostData>> getListByIds(List<Long> ids) {
|
||||||
|
if (CollUtil.isEmpty(ids)) {
|
||||||
|
return success(Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UserPostDO> list = userPostMapper.selectBatchIds(ids);
|
||||||
|
if (CollUtil.isEmpty(list)) {
|
||||||
|
return success(Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return success(list.stream()
|
||||||
|
.map(this::convertToData)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<Long> count(Long tenantId) {
|
||||||
|
// 注意:UserPostDO 没有租户字段,返回全量总数
|
||||||
|
return success(userPostMapper.selectCount(new LambdaQueryWrapper<>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 UserPostDO 转换为 DatabusUserPostData
|
||||||
|
*/
|
||||||
|
private DatabusUserPostData convertToData(UserPostDO userPost) {
|
||||||
|
return DatabusUserPostData.builder()
|
||||||
|
.id(userPost.getId())
|
||||||
|
.userId(userPost.getUserId())
|
||||||
|
.postId(userPost.getPostId())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import com.zt.plat.module.system.controller.admin.dept.vo.post.PostSaveReqVO;
|
|||||||
import com.zt.plat.module.system.dal.dataobject.dept.PostDO;
|
import com.zt.plat.module.system.dal.dataobject.dept.PostDO;
|
||||||
import com.zt.plat.module.system.service.dept.PostService;
|
import com.zt.plat.module.system.service.dept.PostService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@RestController // 提供 RESTful API 接口,给 Feign 调用
|
@RestController // 提供 RESTful API 接口,给 Feign 调用
|
||||||
@Validated
|
@Validated
|
||||||
public class PostApiImpl implements PostApi {
|
public class PostApiImpl implements PostApi {
|
||||||
@@ -36,6 +38,7 @@ public class PostApiImpl implements PostApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<Boolean> updatePost(PostSaveReqDTO updateReqVO) {
|
public CommonResult<Boolean> updatePost(PostSaveReqDTO updateReqVO) {
|
||||||
|
log.error("ssssssssss");
|
||||||
PostSaveReqVO reqVO = BeanUtils.toBean(updateReqVO, PostSaveReqVO.class);
|
PostSaveReqVO reqVO = BeanUtils.toBean(updateReqVO, PostSaveReqVO.class);
|
||||||
postService.updatePost(reqVO);
|
postService.updatePost(reqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
@@ -49,6 +52,7 @@ public class PostApiImpl implements PostApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<PostRespDTO> getPost(Long id) {
|
public CommonResult<PostRespDTO> getPost(Long id) {
|
||||||
|
log.error("cccccccc"+id);
|
||||||
PostDO post = postService.getPost(id);
|
PostDO post = postService.getPost(id);
|
||||||
return success(BeanUtils.toBean(post, PostRespDTO.class));
|
return success(BeanUtils.toBean(post, PostRespDTO.class));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user