新增系统管理员岗位

This commit is contained in:
wh
2026-04-27 16:25:39 +08:00
parent 5662c1fda9
commit 79812b2c77
63 changed files with 609 additions and 495 deletions

View File

@@ -1,6 +1,7 @@
package com.labelsys.backend.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.labelsys.backend.common.ResultCode;
import com.labelsys.backend.common.exception.BusinessException;
import com.labelsys.backend.context.LoginUser;
@@ -13,44 +14,65 @@ import com.labelsys.backend.entity.SourceResource;
import com.labelsys.backend.enums.RuntimeResultStatus;
import com.labelsys.backend.mapper.AnnotationResultMapper;
import com.labelsys.backend.mapper.SourceResourceMapper;
import java.util.Comparator;
import com.labelsys.backend.service.DataPermissionService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
public class AnnotationResultService {
private final AnnotationResultMapper annotationResultMapper;
private final SourceResourceMapper sourceResourceMapper;
private final DataPermissionService dataPermissionService;
public PageResult<AnnotationResultResponse> pageResults(LoginUser currentUser, AnnotationResultPageQuery query) {
List<String> allowedRoles = dataPermissionService.getAllowedRoles(currentUser);
boolean shouldFilterByUserId = dataPermissionService.shouldFilterByUserId(currentUser);
LambdaQueryWrapper<AnnotationResult> wrapper = new LambdaQueryWrapper<AnnotationResult>()
.eq(AnnotationResult::getCompanyId, currentUser.companyId())
.eq(query.taskId() != null, AnnotationResult::getTaskId, query.taskId())
.eq(query.resourceId() != null, AnnotationResult::getResourceId, query.resourceId())
.eq(query.requiresManualReview() != null, AnnotationResult::getRequiresManualReview, query.requiresManualReview())
.orderByDesc(AnnotationResult::getCreatedAt);
List<AnnotationResultResponse> records = annotationResultMapper.selectList(wrapper).stream()
.eq(query.requiresManualReview() != null, AnnotationResult::getRequiresManualReview, query.requiresManualReview());
if (shouldFilterByUserId) {
wrapper.eq(AnnotationResult::getCreatorId, currentUser.userId());
} else if (!allowedRoles.isEmpty()) {
wrapper.in(AnnotationResult::getCreatorRole, allowedRoles);
}
wrapper.orderByDesc(AnnotationResult::getCreatedAt);
Page<AnnotationResult> page = new Page<>(query.pageNo(), query.pageSize());
Page<AnnotationResult> resultPage = annotationResultMapper.selectPage(page, wrapper);
List<AnnotationResultResponse> records = resultPage.getRecords().stream()
.map(this::toResponse)
.filter(response -> query.runtimeStatus() == null || query.runtimeStatus().equals(response.runtimeStatus()))
.sorted(Comparator.comparing(AnnotationResultResponse::createdAt, Comparator.nullsLast(Comparator.naturalOrder())).reversed())
.toList();
return paginate(records, query.pageNo(), query.pageSize());
return new PageResult<>(records, resultPage.getTotal(), (int) resultPage.getCurrent(), (int) resultPage.getSize());
}
public AnnotationResultResponse getResult(LoginUser currentUser, Long resultId) {
AnnotationResult result = annotationResultMapper.selectById(resultId);
if (result == null || !currentUser.companyId().equals(result.getCompanyId())) {
AnnotationResult result = annotationResultMapper.findActiveByIdAndCompanyId(resultId, currentUser.companyId());
if (result == null) {
log.warn("Result not found or cross-tenant access attempt: resultId={}, companyId={}, userId={}",
resultId, currentUser.companyId(), currentUser.userId());
throw new BusinessException(ResultCode.NOT_FOUND, "结果不存在");
}
return toResponse(result);
}
public AnnotationResultCompareResponse compareResult(LoginUser currentUser, Long resultId) {
AnnotationResult result = annotationResultMapper.selectById(resultId);
if (result == null || !currentUser.companyId().equals(result.getCompanyId())) {
AnnotationResult result = annotationResultMapper.findActiveByIdAndCompanyId(resultId, currentUser.companyId());
if (result == null) {
log.warn("Result not found or cross-tenant access attempt: resultId={}, companyId={}, userId={}",
resultId, currentUser.companyId(), currentUser.userId());
throw new BusinessException(ResultCode.NOT_FOUND, "结果不存在");
}
SourceResource resource = sourceResourceMapper.selectById(result.getResourceId());
@@ -88,12 +110,4 @@ public class AnnotationResultService {
}
return RuntimeResultStatus.AUTO_ARCHIVE_PENDING.name();
}
private <T> PageResult<T> paginate(List<T> records, Integer pageNo, Integer pageSize) {
int actualPageNo = pageNo == null || pageNo < 1 ? 1 : pageNo;
int actualPageSize = pageSize == null || pageSize < 1 ? 10 : pageSize;
int fromIndex = Math.min((actualPageNo - 1) * actualPageSize, records.size());
int toIndex = Math.min(fromIndex + actualPageSize, records.size());
return new PageResult<>(records.subList(fromIndex, toIndex), (long) records.size(), actualPageNo, actualPageSize);
}
}
}