新增系统管理员岗位

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

@@ -11,13 +11,13 @@ import lombok.NoArgsConstructor;
@Schema(description = "统一返回结果")
public class Result<T> {
@Schema(description = "业务状态码")
@Schema(description = "业务状态码", example = "0")
private Integer code;
@Schema(description = "返回消息")
@Schema(description = "返回消息", example = "success")
private String message;
@Schema(description = "返回数据")
@Schema(description = "返回数据", example = "{}")
private T data;
public static <T> Result<T> success() {

View File

@@ -1,17 +1,23 @@
package com.labelsys.backend.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.POSTGRE_SQL);
paginationInnerInterceptor.setOverflow(false);
paginationInnerInterceptor.setMaxLimit(200L);
interceptor.addInnerInterceptor(paginationInnerInterceptor);
return interceptor;
}
}

View File

@@ -7,37 +7,28 @@ import com.labelsys.backend.enums.UserRole;
import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "当前登录用户上下文")
public record LoginUser(
@Schema(description = "用户ID") Long userId,
@Schema(description = "公司ID") Long companyId,
@Schema(description = "公司编码") String companyCode,
@Schema(description = "公司名称") String companyName,
public record LoginUser(@Schema(description = "用户ID") Long userId, @Schema(description = "公司ID") Long companyId,
@Schema(description = "公司编码") String companyCode, @Schema(description = "公司名称") String companyName,
@Schema(description = "手机号") String phone,
@Schema(description = "用户名,可为空", example = "alpha-reviewer") String username,
@Schema(description = "真实姓名") String realName,
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员") UserPosition position,
@Schema(
description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员、SUPER_ADMIN系统管理员") UserPosition position,
@Schema(description = "是否必须修改密码") boolean mustChangePassword,
@Schema(description = "会话版本") Integer sessionVersion
) {
@Schema(description = "会话版本") Integer sessionVersion) {
public static LoginUser from(SysUser user, SysCompany company) {
return new LoginUser(
user.getId(),
company.getId(),
company.getCompanyCode(),
company.getCompanyName(),
user.getPhone(),
user.getUsername(),
user.getRealName(),
user.getRole(),
user.getPosition(),
Boolean.TRUE.equals(user.getMustChangePassword()),
user.getSessionVersion()
);
return new LoginUser(user.getId(), company.getId(), company.getCompanyCode(), company.getCompanyName(),
user.getPhone(), user.getUsername(), user.getRealName(), user.getRole(), user.getPosition(),
Boolean.TRUE.equals(user.getMustChangePassword()), user.getSessionVersion());
}
public boolean isPlatformAdmin() {
return "PLATFORM".equals(companyCode) && position == UserPosition.ADMIN;
// public boolean isPlatformAdmin() {
// return "PLATFORM".equals(companyCode) && position == UserPosition.ADMIN;
// }
public boolean isSuperAdmin() {
return position == UserPosition.SUPER_ADMIN;
}
}

View File

@@ -13,9 +13,11 @@ import com.labelsys.backend.enums.UserPosition;
import com.labelsys.backend.service.AnnotationResultArchiveService;
import com.labelsys.backend.service.AnnotationResultService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -34,28 +36,37 @@ public class AnnotationResultController {
@Operation(summary = "分页查询标注结果")
@GetMapping
public Result<PageResult<AnnotationResultResponse>> page(AnnotationResultPageQuery query) {
public Result<PageResult<AnnotationResultResponse>> page(@ParameterObject AnnotationResultPageQuery query) {
return Result.success(annotationResultService.pageResults(UserContext.requireUser(), query));
}
@Operation(summary = "查询标注结果详情")
@GetMapping("/{id}")
public Result<AnnotationResultResponse> detail(@PathVariable Long id) {
public Result<AnnotationResultResponse> detail(
@Parameter(description = "结果ID", example = "191000000000000401")
@PathVariable Long id
) {
return Result.success(annotationResultService.getResult(UserContext.requireUser(), id));
}
@Operation(summary = "查询标注结果比对信息")
@RequirePosition(UserPosition.REVIEWER)
@GetMapping("/{id}/compare")
public Result<AnnotationResultCompareResponse> compare(@PathVariable Long id) {
public Result<AnnotationResultCompareResponse> compare(
@Parameter(description = "结果ID", example = "191000000000000401")
@PathVariable Long id
) {
return Result.success(annotationResultService.compareResult(UserContext.requireUser(), id));
}
@Operation(summary = "提交合并审核结果")
@RequirePosition(UserPosition.REVIEWER)
@PostMapping("/{id}/merge-review")
public Result<MergeReviewResultResponse> mergeReview(@PathVariable Long id,
@Valid @RequestBody MergeReviewResultRequest request) {
public Result<MergeReviewResultResponse> mergeReview(
@Parameter(description = "结果ID", example = "191000000000000401")
@PathVariable Long id,
@Valid @RequestBody MergeReviewResultRequest request
) {
return Result.success(annotationResultArchiveService.mergeReview(UserContext.requireUser(), id, request));
}
}

View File

@@ -9,9 +9,11 @@ import com.labelsys.backend.dto.request.UpdateAnnotationTaskRequest;
import com.labelsys.backend.dto.response.AnnotationTaskResponse;
import com.labelsys.backend.service.AnnotationTaskService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -37,25 +39,35 @@ public class AnnotationTaskController {
@Operation(summary = "更新标注任务")
@PutMapping("/{id}")
public Result<AnnotationTaskResponse> update(@PathVariable Long id, @Valid @RequestBody UpdateAnnotationTaskRequest request) {
public Result<AnnotationTaskResponse> update(
@Parameter(description = "任务ID", example = "191000000000000301")
@PathVariable Long id,
@Valid @RequestBody UpdateAnnotationTaskRequest request
) {
return Result.success(annotationTaskService.updateTask(UserContext.requireUser(), id, request));
}
@Operation(summary = "分页查询标注任务")
@GetMapping
public Result<PageResult<AnnotationTaskResponse>> page(AnnotationTaskPageQuery query) {
public Result<PageResult<AnnotationTaskResponse>> page(@ParameterObject AnnotationTaskPageQuery query) {
return Result.success(annotationTaskService.pageTasks(UserContext.requireUser(), query));
}
@Operation(summary = "查询标注任务详情")
@GetMapping("/{id}")
public Result<AnnotationTaskResponse> detail(@PathVariable Long id) {
public Result<AnnotationTaskResponse> detail(
@Parameter(description = "任务ID", example = "191000000000000301")
@PathVariable Long id
) {
return Result.success(annotationTaskService.getTask(UserContext.requireUser(), id));
}
@Operation(summary = "删除标注任务")
@DeleteMapping("/{id}")
public Result<Void> delete(@PathVariable Long id) {
public Result<Void> delete(
@Parameter(description = "任务ID", example = "191000000000000301")
@PathVariable Long id
) {
annotationTaskService.deleteTask(UserContext.requireUser(), id);
return Result.success();
}

View File

@@ -10,6 +10,7 @@ import com.labelsys.backend.dto.response.CurrentUserResponse;
import com.labelsys.backend.dto.response.LoginResponse;
import com.labelsys.backend.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
@@ -33,7 +34,10 @@ public class AuthController {
@Operation(summary = "根据手机号查询可登录公司")
@GetMapping("/companies")
public Result<List<CompanyOptionResponse>> listCompanies(@RequestParam String phone) {
public Result<List<CompanyOptionResponse>> listCompanies(
@Parameter(description = "手机号", example = "13800138000")
@RequestParam String phone
) {
return Result.success(authService.listAvailableCompanies(phone));
}
@@ -52,7 +56,10 @@ public class AuthController {
@Operation(summary = "退出登录")
@PostMapping("/logout")
public Result<Void> logout(@RequestHeader(HttpHeaders.AUTHORIZATION) String authorization) {
public Result<Void> logout(
@Parameter(description = "Bearer 访问令牌", example = "Bearer eyJhbGciOiJIUzI1NiJ9.demo.token")
@RequestHeader(HttpHeaders.AUTHORIZATION) String authorization
) {
authService.logout(extractToken(authorization));
return Result.success();
}

View File

@@ -10,6 +10,7 @@ import com.labelsys.backend.dto.response.UserResponse;
import com.labelsys.backend.enums.UserPosition;
import com.labelsys.backend.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
@@ -45,14 +46,22 @@ public class CompanyUserController {
@Operation(summary = "修改员工角色和岗位")
@PutMapping("/{userId}/assignment")
public Result<Void> updateAssignment(@PathVariable Long userId, @Valid @RequestBody UpdateUserAssignmentRequest request) {
public Result<Void> updateAssignment(
@Parameter(description = "用户ID", example = "191000000000000021")
@PathVariable Long userId,
@Valid @RequestBody UpdateUserAssignmentRequest request
) {
userService.updateAssignment(UserContext.requireUser(), userId, request);
return Result.success();
}
@Operation(summary = "修改员工状态")
@PutMapping("/{userId}/status")
public Result<Void> updateStatus(@PathVariable Long userId, @Valid @RequestBody UpdateUserStatusRequest request) {
public Result<Void> updateStatus(
@Parameter(description = "用户ID", example = "191000000000000021")
@PathVariable Long userId,
@Valid @RequestBody UpdateUserStatusRequest request
) {
userService.updateStatus(UserContext.requireUser(), userId, request);
return Result.success();
}

View File

@@ -4,11 +4,13 @@ import com.labelsys.backend.annotation.RequirePosition;
import com.labelsys.backend.common.Result;
import com.labelsys.backend.context.UserContext;
import com.labelsys.backend.dto.request.CreateCompanyAdminRequest;
import com.labelsys.backend.dto.request.CreateSystemEngineerAdminRequest;
import com.labelsys.backend.dto.request.UpdateUserStatusRequest;
import com.labelsys.backend.dto.response.UserResponse;
import com.labelsys.backend.enums.UserPosition;
import com.labelsys.backend.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
@@ -25,7 +27,7 @@ import org.springframework.web.bind.annotation.RestController;
@Tag(name = "平台公司管理员管理")
@RestController
@RequestMapping("/api/platform/company-admins")
@RequirePosition(UserPosition.ADMIN)
@RequirePosition(UserPosition.SUPER_ADMIN)
@RequiredArgsConstructor
public class PlatformCompanyAdminController {
@@ -33,20 +35,37 @@ public class PlatformCompanyAdminController {
@Operation(summary = "查询指定公司管理员列表")
@GetMapping
public Result<List<UserResponse>> listCompanyAdmins(@RequestParam Long companyId) {
public Result<List<UserResponse>> listCompanyAdmins(
@Parameter(description = "公司ID", example = "191000000000000001")
@RequestParam Long companyId
) {
return Result.success(userService.listCompanyAdmins(UserContext.requireUser(), companyId).stream().map(UserResponse::from).toList());
}
@Operation(summary = "查询所有公司用户列表")
@GetMapping("/all")
public Result<List<UserResponse>> listAllUsers() {
return Result.success(userService.listAllUsers(UserContext.requireUser()).stream().map(UserResponse::from).toList());
}
@Operation(summary = "创建公司管理员")
@PostMapping
public Result<UserResponse> createCompanyAdmin(@Valid @RequestBody CreateCompanyAdminRequest request) {
return Result.success(UserResponse.from(userService.createCompanyAdmin(UserContext.requireUser(), request)));
}
@Operation(summary = "创建系统工程师管理员")
@PostMapping("/system-engineer")
public Result<UserResponse> createSystemEngineerAdmin(@Valid @RequestBody CreateSystemEngineerAdminRequest request) {
return Result.success(UserResponse.from(userService.createSystemEngineerAdmin(UserContext.requireUser(), request)));
}
@Operation(summary = "修改公司管理员状态")
@PutMapping("/{companyId}/{userId}/status")
public Result<Void> updateCompanyAdminStatus(
@Parameter(description = "公司ID", example = "191000000000000001")
@PathVariable Long companyId,
@Parameter(description = "用户ID", example = "191000000000000021")
@PathVariable Long userId,
@Valid @RequestBody UpdateUserStatusRequest request
) {

View File

@@ -9,6 +9,7 @@ import com.labelsys.backend.dto.response.CompanyResponse;
import com.labelsys.backend.enums.UserPosition;
import com.labelsys.backend.service.CompanyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
@@ -24,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
@Tag(name = "平台公司管理")
@RestController
@RequestMapping("/api/platform/companies")
@RequirePosition(UserPosition.ADMIN)
@RequirePosition(UserPosition.SUPER_ADMIN)
@RequiredArgsConstructor
public class PlatformCompanyController {
@@ -44,7 +45,11 @@ public class PlatformCompanyController {
@Operation(summary = "修改公司状态")
@PutMapping("/{companyId}/status")
public Result<Void> updateCompanyStatus(@PathVariable Long companyId, @Valid @RequestBody UpdateCompanyStatusRequest request) {
public Result<Void> updateCompanyStatus(
@Parameter(description = "公司ID", example = "191000000000000001")
@PathVariable Long companyId,
@Valid @RequestBody UpdateCompanyStatusRequest request
) {
companyService.updateStatus(UserContext.requireUser(), companyId, request);
return Result.success();
}

View File

@@ -9,8 +9,10 @@ import com.labelsys.backend.dto.response.SourceResourceResponse;
import com.labelsys.backend.dto.response.SourceUploadResponse;
import com.labelsys.backend.service.SourceResourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
@@ -29,25 +31,31 @@ public class SourceResourceController {
@Operation(summary = "上传资源")
@PostMapping("/upload")
public Result<SourceUploadResponse> upload(@ModelAttribute SourceUploadRequest request) {
public Result<SourceUploadResponse> upload(@ParameterObject @ModelAttribute SourceUploadRequest request) {
return Result.success(sourceResourceService.upload(UserContext.requireUser(), request));
}
@Operation(summary = "分页查询资源")
@GetMapping
public Result<PageResult<SourceResourceResponse>> page(SourceResourcePageQuery query) {
public Result<PageResult<SourceResourceResponse>> page(@ParameterObject SourceResourcePageQuery query) {
return Result.success(sourceResourceService.pageResources(UserContext.requireUser(), query));
}
@Operation(summary = "查询资源详情")
@GetMapping("/{id}")
public Result<SourceResourceResponse> detail(@PathVariable Long id) {
public Result<SourceResourceResponse> detail(
@Parameter(description = "资源ID", example = "191000000000000101")
@PathVariable Long id
) {
return Result.success(sourceResourceService.getResource(UserContext.requireUser(), id));
}
@Operation(summary = "删除资源")
@DeleteMapping("/{id}")
public Result<Void> delete(@PathVariable Long id) {
public Result<Void> delete(
@Parameter(description = "资源ID", example = "191000000000000101")
@PathVariable Long id
) {
sourceResourceService.deleteResource(UserContext.requireUser(), id);
return Result.success();
}

View File

@@ -10,9 +10,11 @@ import com.labelsys.backend.dto.response.SysConfigResponse;
import com.labelsys.backend.enums.UserPosition;
import com.labelsys.backend.service.SysConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -39,19 +41,26 @@ public class SysConfigController {
@Operation(summary = "更新系统配置")
@RequirePosition(UserPosition.ADMIN)
@PutMapping("/{id}")
public Result<SysConfigResponse> update(@PathVariable Long id, @Valid @RequestBody SaveSysConfigRequest request) {
public Result<SysConfigResponse> update(
@Parameter(description = "配置ID", example = "191000000000000501")
@PathVariable Long id,
@Valid @RequestBody SaveSysConfigRequest request
) {
return Result.success(sysConfigService.toResponse(sysConfigService.updateConfig(UserContext.requireUser(), id, request)));
}
@Operation(summary = "分页查询系统配置")
@GetMapping
public Result<PageResult<SysConfigResponse>> page(SysConfigPageQuery query) {
public Result<PageResult<SysConfigResponse>> page(@ParameterObject SysConfigPageQuery query) {
return Result.success(sysConfigService.pageConfigs(UserContext.requireUser(), query));
}
@Operation(summary = "查询系统配置详情")
@GetMapping("/{id}")
public Result<SysConfigResponse> detail(@PathVariable Long id) {
public Result<SysConfigResponse> detail(
@Parameter(description = "配置ID", example = "191000000000000501")
@PathVariable Long id
) {
return Result.success(sysConfigService.getConfig(UserContext.requireUser(), id));
}
}

View File

@@ -6,10 +6,10 @@ import java.util.List;
@Schema(description = "分页结果")
public record PageResult<T>(
@Schema(description = "当前页记录") List<T> records,
@Schema(description = "总记录数") Long total,
@Schema(description = "页码") Integer pageNo,
@Schema(description = "每页数量") Integer pageSize
@Schema(description = "当前页记录", example = "[]") List<T> records,
@Schema(description = "总记录数", example = "2") Long total,
@Schema(description = "页码", example = "1") Integer pageNo,
@Schema(description = "每页数量", example = "10") Integer pageSize
) {
public static <T> PageResult<T> from(IPage<T> page) {
return new PageResult<>(page.getRecords(), page.getTotal(), (int) page.getCurrent(), (int) page.getSize());

View File

@@ -4,11 +4,11 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "标注结果分页查询请求")
public record AnnotationResultPageQuery(
@Schema(description = "任务ID") Long taskId,
@Schema(description = "资源ID") Long resourceId,
@Schema(description = "是否需要人工审核") Boolean requiresManualReview,
@Schema(description = "运行态状态") String runtimeStatus,
@Schema(description = "页码") Integer pageNo,
@Schema(description = "每页数量") Integer pageSize
@Schema(description = "任务ID", example = "191000000000000301") Long taskId,
@Schema(description = "资源ID", example = "191000000000000101") Long resourceId,
@Schema(description = "是否需要人工审核", example = "true") Boolean requiresManualReview,
@Schema(description = "运行态状态", example = "MANUAL_REVIEW_PENDING") String runtimeStatus,
@Schema(description = "页码", example = "1") Integer pageNo,
@Schema(description = "每页数量", example = "10") Integer pageSize
) {
}

View File

@@ -4,12 +4,12 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "标注任务分页查询请求")
public record AnnotationTaskPageQuery(
@Schema(description = "关键字") String keyword,
@Schema(description = "任务类型") String taskType,
@Schema(description = "任务状态") String taskStatus,
@Schema(description = "资源ID") Long resourceId,
@Schema(description = "是否已删除") Boolean isDeleted,
@Schema(description = "页码") Integer pageNo,
@Schema(description = "每页数量") Integer pageSize
@Schema(description = "关键字", example = "运输") String keyword,
@Schema(description = "任务类型", example = "EXTRACT_QA") String taskType,
@Schema(description = "任务状态", example = "PENDING") String taskStatus,
@Schema(description = "资源ID", example = "191000000000000101") Long resourceId,
@Schema(description = "是否已删除", example = "false") Boolean isDeleted,
@Schema(description = "页码", example = "1") Integer pageNo,
@Schema(description = "每页数量", example = "10") Integer pageSize
) {
}

View File

@@ -5,8 +5,8 @@ import jakarta.validation.constraints.NotBlank;
@Schema(description = "修改密码请求")
public record ChangePasswordRequest(
@Schema(description = "旧密码") @NotBlank(message = "不能为空") String oldPassword,
@Schema(description = "新密码") @NotBlank(message = "不能为空") String newPassword,
@Schema(description = "确认新密码") @NotBlank(message = "不能为空") String confirmPassword
@Schema(description = "旧密码", example = "P@ssw0rd!") @NotBlank(message = "不能为空") String oldPassword,
@Schema(description = "新密码", example = "N3wP@ssw0rd!") @NotBlank(message = "不能为空") String newPassword,
@Schema(description = "确认新密码", example = "N3wP@ssw0rd!") @NotBlank(message = "不能为空") String confirmPassword
) {
}

View File

@@ -8,13 +8,13 @@ import java.util.List;
@Schema(description = "创建标注任务请求")
public record CreateAnnotationTaskRequest(
@Schema(description = "任务名称") @NotBlank(message = "任务名称不能为空") String taskName,
@Schema(description = "行业类型") String industryType,
@Schema(description = "任务类型") String taskType,
@Schema(description = "资源ID列表") @NotEmpty(message = "资源列表不能为空") List<Long> resourceIds,
@Schema(description = "抽取模型配置") @Valid TaskModelConfigRequest extractModel,
@Schema(description = "校验模型配置") @Valid TaskModelConfigRequest verifyModel,
@Schema(description = "抽取提示词配置") @Valid PromptConfigOptionRequest extractPrompt,
@Schema(description = "校验提示词配置") @Valid PromptConfigOptionRequest verifyPrompt
@Schema(description = "任务名称", example = "运输文档问答抽取任务") @NotBlank(message = "任务名称不能为空") String taskName,
@Schema(description = "行业类型", example = "transport") String industryType,
@Schema(description = "任务类型", example = "EXTRACT_QA") String taskType,
@Schema(description = "资源ID列表", example = "[191000000000000101,191000000000000102]") @NotEmpty(message = "资源列表不能为空") List<Long> resourceIds,
@Schema(description = "抽取模型配置", example = "{\"mode\":\"SELECT\",\"selectedConfigName\":\"qwen-plus-extract\"}") @Valid TaskModelConfigRequest extractModel,
@Schema(description = "校验模型配置", example = "{\"mode\":\"MANUAL\",\"manualConfig\":{\"modelName\":\"qwen-max\",\"modelUrl\":\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\"apiKey\":\"sk-demo5678\"}}") @Valid TaskModelConfigRequest verifyModel,
@Schema(description = "抽取提示词配置", example = "{\"selectedConfigName\":\"qa-extract-v1\"}") @Valid PromptConfigOptionRequest extractPrompt,
@Schema(description = "校验提示词配置", example = "{\"promptText\":\"请对抽取结果进行逐项校验,并输出差异说明。\"}") @Valid PromptConfigOptionRequest verifyPrompt
) {
}

View File

@@ -6,9 +6,9 @@ import jakarta.validation.constraints.NotNull;
@Schema(description = "创建公司管理员请求")
public record CreateCompanyAdminRequest(
@Schema(description = "公司ID") @NotNull(message = "不能为空") Long companyId,
@Schema(description = "手机号") @NotBlank(message = "不能为空") String phone,
@Schema(description = "公司ID", example = "191000000000000001") @NotNull(message = "不能为空") Long companyId,
@Schema(description = "手机号", example = "13800138001") @NotBlank(message = "不能为空") String phone,
@Schema(description = "用户名,前端展示用,可为空", example = "platform-ops") String username,
@Schema(description = "真实姓名") @NotBlank(message = "不能为空") String realName
@Schema(description = "真实姓名", example = "平台运维") @NotBlank(message = "不能为空") String realName
) {
}

View File

@@ -5,7 +5,7 @@ import jakarta.validation.constraints.NotBlank;
@Schema(description = "创建公司请求")
public record CreateCompanyRequest(
@Schema(description = "公司编码") @NotBlank(message = "不能为空") String companyCode,
@Schema(description = "公司名称") @NotBlank(message = "不能为空") String companyName
@Schema(description = "公司编码", example = "ALPHA") @NotBlank(message = "不能为空") String companyCode,
@Schema(description = "公司名称", example = "阿尔法标注有限公司") @NotBlank(message = "不能为空") String companyName
) {
}

View File

@@ -0,0 +1,10 @@
package com.labelsys.backend.dto.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
@Schema(description = "创建系统工程师管理员请求")
public record CreateSystemEngineerAdminRequest(
@Schema(description = "手机号", example = "13800138002") @NotBlank(message = "不能为空") String phone,
@Schema(description = "用户名,前端展示用,可为空", example = "system-engineer") String username,
@Schema(description = "真实姓名", example = "系统工程师") @NotBlank(message = "不能为空") String realName) {}

View File

@@ -8,10 +8,10 @@ import jakarta.validation.constraints.NotNull;
@Schema(description = "创建员工请求")
public record CreateUserRequest(
@Schema(description = "手机号") @NotBlank(message = "不能为空") String phone,
@Schema(description = "手机号", example = "13800138002") @NotBlank(message = "不能为空") String phone,
@Schema(description = "用户名,前端展示用,可为空", example = "alpha-admin") String username,
@Schema(description = "真实姓名") @NotBlank(message = "不能为空") String realName,
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师") @NotNull(message = "不能为空") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员") @NotNull(message = "不能为空") UserPosition position
@Schema(description = "真实姓名", example = "张审核") @NotBlank(message = "不能为空") String realName,
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师", example = "EMPLOYEE") @NotNull(message = "不能为空") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员", example = "ANNOTATOR") @NotNull(message = "不能为空") UserPosition position
) {
}

View File

@@ -5,8 +5,8 @@ import jakarta.validation.constraints.NotBlank;
@Schema(description = "登录请求")
public record LoginRequest(
@Schema(description = "手机号") @NotBlank(message = "不能为空") String phone,
@Schema(description = "公司编码") @NotBlank(message = "不能为空") String companyCode,
@Schema(description = "登录密码") @NotBlank(message = "不能为空") String password
@Schema(description = "手机号", example = "平台管理员:13900000000") @NotBlank(message = "不能为空") String phone,
@Schema(description = "公司编码", example = "平台编号:PLATFORM") @NotBlank(message = "不能为空") String companyCode,
@Schema(description = "登录密码", example = "平台密码:admin@123") @NotBlank(message = "不能为空") String password
) {
}

View File

@@ -5,8 +5,8 @@ import jakarta.validation.constraints.NotBlank;
@Schema(description = "手动模型配置请求")
public record ManualModelConfigRequest(
@Schema(description = "模型名称") @NotBlank(message = "模型名称不能为空") String modelName,
@Schema(description = "模型地址") @NotBlank(message = "模型地址不能为空") String modelUrl,
@Schema(description = "模型密钥") @NotBlank(message = "模型密钥不能为空") String apiKey
@Schema(description = "模型名称", example = "qwen-plus") @NotBlank(message = "模型名称不能为空") String modelName,
@Schema(description = "模型地址", example = "https://dashscope.aliyuncs.com/compatible-mode/v1") @NotBlank(message = "模型地址不能为空") String modelUrl,
@Schema(description = "模型密钥", example = "sk-demo1234") @NotBlank(message = "模型密钥不能为空") String apiKey
) {
}

View File

@@ -5,8 +5,8 @@ import jakarta.validation.constraints.NotBlank;
@Schema(description = "合并审核结果请求")
public record MergeReviewResultRequest(
@Schema(description = "差异摘要 JSON") @NotBlank(message = "差异摘要不能为空") String diffSummary,
@Schema(description = "最终问答内容 JSON") @NotBlank(message = "问答内容不能为空") String qaContentJson,
@Schema(description = "审核备注") String reviewComment
@Schema(description = "差异摘要 JSON", example = "{\"changed\":[{\"field\":\"answer\",\"from\":\"3天\",\"to\":\"72小时\"}],\"summary\":\"统一时间表达\"}") @NotBlank(message = "差异摘要不能为空") String diffSummary,
@Schema(description = "最终问答内容 JSON", example = "[{\"question\":\"运输时效是多久?\",\"answer\":\"72小时\"}]") @NotBlank(message = "问答内容不能为空") String qaContentJson,
@Schema(description = "审核备注", example = "已按审核意见合并,统一为小时口径。") String reviewComment
) {
}

View File

@@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "任务提示词配置请求")
public record PromptConfigOptionRequest(
@Schema(description = "已选择的提示词配置名称") String selectedConfigName,
@Schema(description = "手动输入的提示词内容") String promptText
@Schema(description = "已选择的提示词配置名称", example = "qa-extract-v1") String selectedConfigName,
@Schema(description = "手动输入的提示词内容", example = "请抽取文档中的问答对,并按 JSON 数组输出。") String promptText
) {
}

View File

@@ -5,9 +5,9 @@ import jakarta.validation.constraints.NotBlank;
@Schema(description = "保存系统配置请求")
public record SaveSysConfigRequest(
@Schema(description = "配置类型") @NotBlank(message = "配置类型不能为空") String configType,
@Schema(description = "配置名称") @NotBlank(message = "配置名称不能为空") String configName,
@Schema(description = "配置值") @NotBlank(message = "配置值不能为空") String configValue,
@Schema(description = "配置状态") @NotBlank(message = "配置状态不能为空") String status
@Schema(description = "配置类型", example = "MODEL") @NotBlank(message = "配置类型不能为空") String configType,
@Schema(description = "配置名称", example = "qwen-plus-extract") @NotBlank(message = "配置名称不能为空") String configName,
@Schema(description = "配置值", example = "{\"modelName\":\"qwen-plus\",\"modelUrl\":\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\"apiKey\":\"sk-demo1234\"}") @NotBlank(message = "配置值不能为空") String configValue,
@Schema(description = "配置状态", example = "ENABLED") @NotBlank(message = "配置状态不能为空") String status
) {
}

View File

@@ -4,10 +4,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "资源分页查询请求")
public record SourceResourcePageQuery(
@Schema(description = "关键字") String keyword,
@Schema(description = "资源类型") String resourceType,
@Schema(description = "资源状态") String sourceStatus,
@Schema(description = "页码") Integer pageNo,
@Schema(description = "每页数量") Integer pageSize
@Schema(description = "关键字", example = "运输") String keyword,
@Schema(description = "资源类型", example = "TEXT") String resourceType,
@Schema(description = "资源状态", example = "READY") String sourceStatus,
@Schema(description = "页码", example = "1") Integer pageNo,
@Schema(description = "每页数量", example = "10") Integer pageSize
) {
}

View File

@@ -8,15 +8,15 @@ import org.springframework.web.multipart.MultipartFile;
@Schema(description = "资源上传请求")
public class SourceUploadRequest {
@Schema(description = "资源名称")
@Schema(description = "资源名称", example = "2026年4月运输巡检记录")
private String resourceName;
@Schema(description = "资源类型TEXT、IMAGE、VIDEO")
@Schema(description = "资源类型TEXT、IMAGE、VIDEO", example = "TEXT")
private String resourceType;
@Schema(description = "备注")
@Schema(description = "备注", example = "第一批导入样本")
private String remark;
@Schema(description = "上传文件")
@Schema(description = "上传文件", example = "inspection-record.txt")
private MultipartFile file;
}

View File

@@ -4,10 +4,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "系统配置分页查询请求")
public record SysConfigPageQuery(
@Schema(description = "配置类型") String configType,
@Schema(description = "配置名称") String configName,
@Schema(description = "配置状态") String status,
@Schema(description = "页码") Integer pageNo,
@Schema(description = "每页数量") Integer pageSize
@Schema(description = "配置类型", example = "MODEL") String configType,
@Schema(description = "配置名称", example = "qwen-plus-extract") String configName,
@Schema(description = "配置状态", example = "ENABLED") String status,
@Schema(description = "页码", example = "1") Integer pageNo,
@Schema(description = "每页数量", example = "10") Integer pageSize
) {
}

View File

@@ -6,8 +6,8 @@ import jakarta.validation.constraints.NotBlank;
@Schema(description = "任务模型配置请求")
public record TaskModelConfigRequest(
@Schema(description = "配置模式SELECT 或 MANUAL") @NotBlank(message = "配置模式不能为空") String mode,
@Schema(description = "已选择的配置名称") String selectedConfigName,
@Schema(description = "手动录入的模型配置") @Valid ManualModelConfigRequest manualConfig
@Schema(description = "配置模式SELECT 或 MANUAL", example = "SELECT") @NotBlank(message = "配置模式不能为空") String mode,
@Schema(description = "已选择的配置名称", example = "qwen-plus-extract") String selectedConfigName,
@Schema(description = "手动录入的模型配置", example = "{\"modelName\":\"qwen-plus\",\"modelUrl\":\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\"apiKey\":\"sk-demo1234\"}") @Valid ManualModelConfigRequest manualConfig
) {
}

View File

@@ -7,12 +7,12 @@ import java.util.List;
@Schema(description = "更新标注任务请求")
public record UpdateAnnotationTaskRequest(
@Schema(description = "行业类型") String industryType,
@Schema(description = "任务类型") String taskType,
@Schema(description = "资源ID列表") @NotEmpty(message = "资源列表不能为空") List<Long> resourceIds,
@Schema(description = "抽取模型配置") @Valid TaskModelConfigRequest extractModel,
@Schema(description = "校验模型配置") @Valid TaskModelConfigRequest verifyModel,
@Schema(description = "抽取提示词配置") @Valid PromptConfigOptionRequest extractPrompt,
@Schema(description = "校验提示词配置") @Valid PromptConfigOptionRequest verifyPrompt
@Schema(description = "行业类型", example = "transport") String industryType,
@Schema(description = "任务类型", example = "EXTRACT_QA") String taskType,
@Schema(description = "资源ID列表", example = "[191000000000000101,191000000000000102]") @NotEmpty(message = "资源列表不能为空") List<Long> resourceIds,
@Schema(description = "抽取模型配置", example = "{\"mode\":\"SELECT\",\"selectedConfigName\":\"qwen-plus-extract\"}") @Valid TaskModelConfigRequest extractModel,
@Schema(description = "校验模型配置", example = "{\"mode\":\"MANUAL\",\"manualConfig\":{\"modelName\":\"qwen-max\",\"modelUrl\":\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\"apiKey\":\"sk-demo5678\"}}") @Valid TaskModelConfigRequest verifyModel,
@Schema(description = "抽取提示词配置", example = "{\"selectedConfigName\":\"qa-extract-v1\"}") @Valid PromptConfigOptionRequest extractPrompt,
@Schema(description = "校验提示词配置", example = "{\"promptText\":\"请对抽取结果进行逐项校验,并输出差异说明。\"}") @Valid PromptConfigOptionRequest verifyPrompt
) {
}

View File

@@ -6,6 +6,6 @@ import jakarta.validation.constraints.NotNull;
@Schema(description = "修改公司状态请求")
public record UpdateCompanyStatusRequest(
@Schema(description = "公司状态枚举值ENABLED启用、DISABLED禁用") @NotNull(message = "不能为空") CompanyStatus status
@Schema(description = "公司状态枚举值ENABLED启用、DISABLED禁用", example = "ENABLED") @NotNull(message = "不能为空") CompanyStatus status
) {
}

View File

@@ -7,7 +7,7 @@ import jakarta.validation.constraints.NotNull;
@Schema(description = "修改员工角色岗位请求")
public record UpdateUserAssignmentRequest(
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师") @NotNull(message = "不能为空") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员") @NotNull(message = "不能为空") UserPosition position
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师", example = "EMPLOYEE") @NotNull(message = "不能为空") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员", example = "REVIEWER") @NotNull(message = "不能为空") UserPosition position
) {
}

View File

@@ -6,6 +6,6 @@ import jakarta.validation.constraints.NotNull;
@Schema(description = "修改员工状态请求")
public record UpdateUserStatusRequest(
@Schema(description = "用户状态枚举值ENABLED启用、DISABLED禁用") @NotNull(message = "不能为空") UserStatus status
@Schema(description = "用户状态枚举值ENABLED启用、DISABLED禁用", example = "DISABLED") @NotNull(message = "不能为空") UserStatus status
) {
}

View File

@@ -4,13 +4,13 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "标注结果比对响应")
public record AnnotationResultCompareResponse(
@Schema(description = "结果ID") Long id,
@Schema(description = "任务ID") Long taskId,
@Schema(description = "资源ID") Long resourceId,
@Schema(description = "问答内容 JSON") String qaContentJson,
@Schema(description = "差异摘要 JSON") String diffSummary,
@Schema(description = "问答存储模式") String qaContentStorageMode,
@Schema(description = "外置问答文件路径") String qaContentFilePath,
@Schema(description = "资源预览路径") String sourcePreviewPath
@Schema(description = "结果ID", example = "191000000000000401") Long id,
@Schema(description = "任务ID", example = "191000000000000301") Long taskId,
@Schema(description = "资源ID", example = "191000000000000101") Long resourceId,
@Schema(description = "问答内容 JSON", example = "[{\"question\":\"运输时效是多久?\",\"answer\":\"3天\"}]") String qaContentJson,
@Schema(description = "差异摘要 JSON", example = "{\"changed\":[{\"field\":\"answer\",\"from\":\"3天\",\"to\":\"72小时\"}],\"summary\":\"统一时间表达\"}") String diffSummary,
@Schema(description = "问答存储模式", example = "EXTERNAL") String qaContentStorageMode,
@Schema(description = "外置问答文件路径", example = "review/191000000000000401/qa-content.json") String qaContentFilePath,
@Schema(description = "资源预览路径", example = "preview/191000000000000101/index.html") String sourcePreviewPath
) {
}

View File

@@ -5,15 +5,15 @@ import java.time.LocalDateTime;
@Schema(description = "标注结果响应")
public record AnnotationResultResponse(
@Schema(description = "结果ID") Long id,
@Schema(description = "任务ID") Long taskId,
@Schema(description = "资源ID") Long resourceId,
@Schema(description = "运行态状态") String runtimeStatus,
@Schema(description = "是否需要人工审核") Boolean requiresManualReview,
@Schema(description = "是否已删除") Boolean isDeleted,
@Schema(description = "问答存储模式") String qaContentStorageMode,
@Schema(description = "审核备注") String reviewComment,
@Schema(description = "审核时间") LocalDateTime reviewedAt,
@Schema(description = "创建时间") LocalDateTime createdAt
@Schema(description = "结果ID", example = "191000000000000401") Long id,
@Schema(description = "任务ID", example = "191000000000000301") Long taskId,
@Schema(description = "资源ID", example = "191000000000000101") Long resourceId,
@Schema(description = "运行态状态", example = "MANUAL_REVIEW_PENDING") String runtimeStatus,
@Schema(description = "是否需要人工审核", example = "true") Boolean requiresManualReview,
@Schema(description = "是否已删除", example = "false") Boolean isDeleted,
@Schema(description = "问答存储模式", example = "INLINE") String qaContentStorageMode,
@Schema(description = "审核备注", example = "需统一时间字段口径。") String reviewComment,
@Schema(description = "审核时间", example = "2026-04-27T11:00:00") LocalDateTime reviewedAt,
@Schema(description = "创建时间", example = "2026-04-27T10:40:00") LocalDateTime createdAt
) {
}

View File

@@ -6,17 +6,17 @@ import java.util.List;
@Schema(description = "标注任务响应")
public record AnnotationTaskResponse(
@Schema(description = "任务ID") Long id,
@Schema(description = "任务名称") String taskName,
@Schema(description = "行业类型") String industryType,
@Schema(description = "任务类型") String taskType,
@Schema(description = "任务状态") String taskStatus,
@Schema(description = "资源ID列表") List<Long> resourceIds,
@Schema(description = "抽取模型配置") TaskModelConfigResponse extractModel,
@Schema(description = "校验模型配置") TaskModelConfigResponse verifyModel,
@Schema(description = "抽取提示词配置") TaskPromptConfigResponse extractPrompt,
@Schema(description = "校验提示词配置") TaskPromptConfigResponse verifyPrompt,
@Schema(description = "创建时间") LocalDateTime createdAt,
@Schema(description = "更新时间") LocalDateTime updatedAt
@Schema(description = "任务ID", example = "191000000000000301") Long id,
@Schema(description = "任务名称", example = "运输文档问答抽取任务") String taskName,
@Schema(description = "行业类型:默认值transport暂不显示", example = "transport") String industryType,
@Schema(description = "任务类型:暂不显示", example = "EXTRACT_QA") String taskType,
@Schema(description = "任务状态", example = "PENDING") String taskStatus,
@Schema(description = "资源ID列表", example = "[191000000000000101,191000000000000102]") List<Long> resourceIds,
@Schema(description = "抽取模型配置", example = "{\"configId\":191000000000000511,\"configName\":\"qwen-plus-extract\",\"modelName\":\"qwen-plus\",\"modelUrl\":\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\"maskedApiKey\":\"****1234\"}") TaskModelConfigResponse extractModel,
@Schema(description = "校验模型配置", example = "{\"configId\":191000000000000512,\"configName\":\"qwen-max-verify\",\"modelName\":\"qwen-max\",\"modelUrl\":\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\"maskedApiKey\":\"****5678\"}") TaskModelConfigResponse verifyModel,
@Schema(description = "抽取提示词配置", example = "{\"configId\":191000000000000521,\"configName\":\"qa-extract-v1\",\"promptText\":\"请抽取文档中的问答对,并按 JSON 数组输出。\"}") TaskPromptConfigResponse extractPrompt,
@Schema(description = "校验提示词配置", example = "{\"configId\":191000000000000522,\"configName\":\"qa-verify-v1\",\"promptText\":\"请对抽取结果进行逐项校验,并输出差异说明。\"}") TaskPromptConfigResponse verifyPrompt,
@Schema(description = "创建时间", example = "2026-04-27T10:20:00") LocalDateTime createdAt,
@Schema(description = "更新时间", example = "2026-04-27T10:30:00") LocalDateTime updatedAt
) {
}

View File

@@ -5,9 +5,9 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "可登录公司选项")
public record CompanyOptionResponse(
@Schema(description = "公司ID") Long companyId,
@Schema(description = "公司编码") String companyCode,
@Schema(description = "公司名称") String companyName
@Schema(description = "公司ID", example = "191000000000000001") Long companyId,
@Schema(description = "公司编码", example = "ALPHA") String companyCode,
@Schema(description = "公司名称", example = "阿尔法标注有限公司") String companyName
) {
public static CompanyOptionResponse from(SysCompany company) {
return new CompanyOptionResponse(company.getId(), company.getCompanyCode(), company.getCompanyName());

View File

@@ -6,10 +6,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "公司响应")
public record CompanyResponse(
@Schema(description = "公司ID") Long companyId,
@Schema(description = "公司编码") String companyCode,
@Schema(description = "公司名称") String companyName,
@Schema(description = "公司状态枚举值ENABLED启用、DISABLED禁用") CompanyStatus status
@Schema(description = "公司ID", example = "191000000000000001") Long companyId,
@Schema(description = "公司编码", example = "ALPHA") String companyCode,
@Schema(description = "公司名称", example = "阿尔法标注有限公司") String companyName,
@Schema(description = "公司状态枚举值ENABLED启用、DISABLED禁用", example = "ENABLED") CompanyStatus status
) {
public static CompanyResponse from(SysCompany company) {
return new CompanyResponse(company.getId(), company.getCompanyCode(), company.getCompanyName(), company.getStatus());

View File

@@ -7,16 +7,16 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "当前登录用户响应")
public record CurrentUserResponse(
@Schema(description = "用户ID") Long userId,
@Schema(description = "公司ID") Long companyId,
@Schema(description = "公司编码") String companyCode,
@Schema(description = "公司名称") String companyName,
@Schema(description = "手机号") String phone,
@Schema(description = "用户ID", example = "191000000000000021") Long userId,
@Schema(description = "公司ID", example = "191000000000000001") Long companyId,
@Schema(description = "公司编码", example = "ALPHA") String companyCode,
@Schema(description = "公司名称", example = "阿尔法标注有限公司") String companyName,
@Schema(description = "手机号", example = "13800138002") String phone,
@Schema(description = "用户名,可为空", example = "alpha-admin") String username,
@Schema(description = "真实姓名") String realName,
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员") UserPosition position,
@Schema(description = "是否必须修改密码") boolean mustChangePassword
@Schema(description = "真实姓名", example = "张审核") String realName,
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师", example = "EMPLOYEE") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员", example = "REVIEWER") UserPosition position,
@Schema(description = "是否必须修改密码", example = "false") boolean mustChangePassword
) {
public static CurrentUserResponse from(LoginUser loginUser) {
return new CurrentUserResponse(

View File

@@ -8,14 +8,14 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "登录响应")
public record LoginResponse(
@Schema(description = "访问令牌") String token,
@Schema(description = "当前公司信息") CompanyOptionResponse company,
@Schema(description = "手机号") String phone,
@Schema(description = "访问令牌", example = "eyJhbGciOiJIUzI1NiJ9.demo.token") String token,
@Schema(description = "当前公司信息", example = "{\"companyId\":191000000000000001,\"companyCode\":\"ALPHA\",\"companyName\":\"阿尔法标注有限公司\"}") CompanyOptionResponse company,
@Schema(description = "手机号", example = "13800138002") String phone,
@Schema(description = "用户名,可为空", example = "alpha-admin") String username,
@Schema(description = "真实姓名") String realName,
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员") UserPosition position,
@Schema(description = "是否必须修改密码") boolean mustChangePassword
@Schema(description = "真实姓名", example = "张审核") String realName,
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师", example = "EMPLOYEE") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员", example = "REVIEWER") UserPosition position,
@Schema(description = "是否必须修改密码", example = "false") boolean mustChangePassword
) {
public static LoginResponse from(String token, LoginUser loginUser, SysCompany company) {
return new LoginResponse(

View File

@@ -5,10 +5,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "菜单响应")
public record MenuResponse(
@Schema(description = "菜单编码") String menuCode,
@Schema(description = "菜单名称") String menuName,
@Schema(description = "菜单路径") String path,
@Schema(description = "排序") Integer sortOrder
@Schema(description = "菜单编码", example = "annotation.task.list") String menuCode,
@Schema(description = "菜单名称", example = "标注任务") String menuName,
@Schema(description = "菜单路径", example = "/annotation/tasks") String path,
@Schema(description = "排序", example = "10") Integer sortOrder
) {
public static MenuResponse from(SysMenu menu) {
return new MenuResponse(menu.getMenuCode(), menu.getMenuName(), menu.getPath(), menu.getSortOrder());

View File

@@ -5,9 +5,9 @@ import java.time.LocalDateTime;
@Schema(description = "合并审核结果响应")
public record MergeReviewResultResponse(
@Schema(description = "运行态结果ID") Long resultId,
@Schema(description = "历史结果ID") Long historyId,
@Schema(description = "归档原因") String archiveReason,
@Schema(description = "归档时间") LocalDateTime archivedAt
@Schema(description = "运行态结果ID", example = "191000000000000401") Long resultId,
@Schema(description = "历史结果ID", example = "191000000000000451") Long historyId,
@Schema(description = "归档原因", example = "MANUAL_REVIEW_MERGED") String archiveReason,
@Schema(description = "归档时间", example = "2026-04-27T11:05:00") LocalDateTime archivedAt
) {
}

View File

@@ -5,17 +5,17 @@ import java.time.LocalDateTime;
@Schema(description = "资源响应")
public record SourceResourceResponse(
@Schema(description = "资源ID") Long id,
@Schema(description = "资源名称") String resourceName,
@Schema(description = "资源类型") String resourceType,
@Schema(description = "桶名称") String bucketName,
@Schema(description = "文件路径") String filePath,
@Schema(description = "文件大小") Long fileSize,
@Schema(description = "资源状态") String sourceStatus,
@Schema(description = "存储提供方") String storageProvider,
@Schema(description = "备注") String remark,
@Schema(description = "创建人名称") String creatorName,
@Schema(description = "创建时间") LocalDateTime createdAt,
@Schema(description = "更新时间") LocalDateTime updatedAt
@Schema(description = "资源ID", example = "191000000000000101") Long id,
@Schema(description = "资源名称", example = "2026年4月运输巡检记录") String resourceName,
@Schema(description = "资源类型", example = "TEXT") String resourceType,
@Schema(description = "桶名称", example = "annotation-source") String bucketName,
@Schema(description = "文件路径", example = "company/191000000000000001/text/191000000000000101.txt") String filePath,
@Schema(description = "文件大小", example = "20480") Long fileSize,
@Schema(description = "资源状态", example = "READY") String sourceStatus,
@Schema(description = "存储提供方", example = "rustfs") String storageProvider,
@Schema(description = "备注", example = "第一批导入样本") String remark,
@Schema(description = "创建人名称", example = "张审核") String creatorName,
@Schema(description = "创建时间", example = "2026-04-27T10:00:00") LocalDateTime createdAt,
@Schema(description = "更新时间", example = "2026-04-27T10:05:00") LocalDateTime updatedAt
) {
}

View File

@@ -5,13 +5,13 @@ import java.time.LocalDateTime;
@Schema(description = "资源上传响应")
public record SourceUploadResponse(
@Schema(description = "资源ID") Long id,
@Schema(description = "资源名称") String resourceName,
@Schema(description = "资源类型") String resourceType,
@Schema(description = "桶名称") String bucketName,
@Schema(description = "文件路径") String filePath,
@Schema(description = "文件大小") Long fileSize,
@Schema(description = "资源状态") String sourceStatus,
@Schema(description = "创建时间") LocalDateTime createdAt
@Schema(description = "资源ID", example = "191000000000000101") Long id,
@Schema(description = "资源名称", example = "2026年4月运输巡检记录") String resourceName,
@Schema(description = "资源类型", example = "TEXT") String resourceType,
@Schema(description = "桶名称", example = "annotation-source") String bucketName,
@Schema(description = "文件路径", example = "company/191000000000000001/text/191000000000000101.txt") String filePath,
@Schema(description = "文件大小", example = "20480") Long fileSize,
@Schema(description = "资源状态", example = "READY") String sourceStatus,
@Schema(description = "创建时间", example = "2026-04-27T10:00:00") LocalDateTime createdAt
) {
}

View File

@@ -5,13 +5,13 @@ import java.time.LocalDateTime;
@Schema(description = "系统配置响应")
public record SysConfigResponse(
@Schema(description = "配置ID") Long id,
@Schema(description = "配置类型") String configType,
@Schema(description = "配置名称") String configName,
@Schema(description = "配置值") String configValue,
@Schema(description = "配置状态") String status,
@Schema(description = "创建人ID") Long creatorId,
@Schema(description = "创建时间") LocalDateTime createdAt,
@Schema(description = "更新时间") LocalDateTime updatedAt
@Schema(description = "配置ID", example = "191000000000000501") Long id,
@Schema(description = "配置类型", example = "MODEL") String configType,
@Schema(description = "配置名称", example = "qwen-plus-extract") String configName,
@Schema(description = "配置值", example = "{\"modelName\":\"qwen-plus\",\"modelUrl\":\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\"apiKey\":\"sk-demo1234\"}") String configValue,
@Schema(description = "配置状态", example = "ENABLED") String status,
@Schema(description = "创建人ID", example = "191000000000000021") Long creatorId,
@Schema(description = "创建时间", example = "2026-04-27T09:50:00") LocalDateTime createdAt,
@Schema(description = "更新时间", example = "2026-04-27T10:15:00") LocalDateTime updatedAt
) {
}

View File

@@ -4,10 +4,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "任务模型配置响应")
public record TaskModelConfigResponse(
@Schema(description = "配置ID") Long configId,
@Schema(description = "配置名称") String configName,
@Schema(description = "模型名称") String modelName,
@Schema(description = "模型地址") String modelUrl,
@Schema(description = "脱敏后的模型密钥") String maskedApiKey
@Schema(description = "配置ID", example = "191000000000000511") Long configId,
@Schema(description = "配置名称", example = "qwen-plus-extract") String configName,
@Schema(description = "模型名称", example = "qwen-plus") String modelName,
@Schema(description = "模型地址", example = "https://dashscope.aliyuncs.com/compatible-mode/v1") String modelUrl,
@Schema(description = "脱敏后的模型密钥", example = "****1234") String maskedApiKey
) {
}

View File

@@ -4,8 +4,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "任务提示词配置响应")
public record TaskPromptConfigResponse(
@Schema(description = "配置ID") Long configId,
@Schema(description = "配置名称") String configName,
@Schema(description = "提示词内容") String promptText
@Schema(description = "配置ID", example = "191000000000000521") Long configId,
@Schema(description = "配置名称", example = "qa-extract-v1") String configName,
@Schema(description = "提示词内容", example = "请抽取文档中的问答对,并按 JSON 数组输出。") String promptText
) {
}

View File

@@ -8,15 +8,15 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "用户响应")
public record UserResponse(
@Schema(description = "用户ID") Long userId,
@Schema(description = "公司ID") Long companyId,
@Schema(description = "手机号") String phone,
@Schema(description = "用户ID", example = "191000000000000021") Long userId,
@Schema(description = "公司ID", example = "191000000000000001") Long companyId,
@Schema(description = "手机号", example = "13800138002") String phone,
@Schema(description = "用户名,可为空", example = "alpha-admin") String username,
@Schema(description = "真实姓名") String realName,
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员") UserPosition position,
@Schema(description = "用户状态枚举值ENABLED启用、DISABLED禁用") UserStatus status,
@Schema(description = "是否必须修改密码") boolean mustChangePassword
@Schema(description = "真实姓名", example = "张审核") String realName,
@Schema(description = "角色枚举值EMPLOYEE员工、MANAGER部门经理、ENGINEER总工程师", example = "EMPLOYEE") UserRole role,
@Schema(description = "岗位枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员", example = "REVIEWER") UserPosition position,
@Schema(description = "用户状态枚举值ENABLED启用、DISABLED禁用", example = "ENABLED") UserStatus status,
@Schema(description = "是否必须修改密码", example = "false") boolean mustChangePassword
) {
public static UserResponse from(SysUser user) {
return new UserResponse(

View File

@@ -6,13 +6,13 @@ import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
@Schema(description = "岗位枚举枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN超级管理员")
@Schema(description = "岗位枚举枚举值ANNOTATOR标注员、DATA_TRAINER数据训练师、REVIEWER审核员、ADMIN公司管理员、SUPER_ADMIN超级管理员")
public enum UserPosition {
ANNOTATOR(1), DATA_TRAINER(2), REVIEWER(3), ADMIN(4);
ANNOTATOR(1), DATA_TRAINER(2), REVIEWER(3), ADMIN(4), SUPER_ADMIN(5);
private final int level;
public boolean canAccess(UserPosition required) {
return this.level >= required.level;
}
}
}

View File

@@ -14,4 +14,4 @@ public interface AnnotationResultMapper extends BaseMapper<AnnotationResult> {
@Param("reviewerId") Long reviewerId,
@Param("reviewComment") String reviewComment,
@Param("reviewedAt") LocalDateTime reviewedAt);
}
}

View File

@@ -1,10 +1,11 @@
package com.labelsys.backend.mapper;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.labelsys.backend.entity.AnnotationTask;
import org.apache.ibatis.annotations.Param;
public interface AnnotationTaskMapper extends BaseMapper<AnnotationTask> {
AnnotationTask findByIdAndCompanyId(@Param("id") Long id, @Param("companyId") Long companyId);
}
}

View File

@@ -8,4 +8,4 @@ import org.apache.ibatis.annotations.Param;
public interface SourceResourceMapper extends BaseMapper<SourceResource> {
List<SourceResource> selectByCompanyIdAndIds(@Param("companyId") Long companyId, @Param("resourceIds") List<Long> resourceIds);
}
}

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);
}
}
}

View File

@@ -1,6 +1,17 @@
package com.labelsys.backend.service;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
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;
@@ -20,16 +31,9 @@ import com.labelsys.backend.mapper.AnnotationTaskMapper;
import com.labelsys.backend.mapper.AnnotationTaskResourceMapper;
import com.labelsys.backend.mapper.SourceResourceMapper;
import com.labelsys.backend.util.IdGenerator;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
@Slf4j
@Service
@@ -136,20 +140,35 @@ public class AnnotationTaskService {
}
public PageResult<AnnotationTaskResponse> pageTasks(LoginUser currentUser, AnnotationTaskPageQuery query) {
List<String> allowedRoles = dataPermissionService.getAllowedRoles(currentUser);
boolean shouldFilterByUserId = dataPermissionService.shouldFilterByUserId(currentUser);
LambdaQueryWrapper<AnnotationTask> wrapper = new LambdaQueryWrapper<AnnotationTask>()
.eq(AnnotationTask::getCompanyId, currentUser.companyId())
.eq(StringUtils.hasText(query.taskType()), AnnotationTask::getTaskType, query.taskType())
.eq(StringUtils.hasText(query.taskStatus()), AnnotationTask::getTaskStatus, query.taskStatus())
.eq(query.isDeleted() != null, AnnotationTask::getIsDeleted, query.isDeleted())
.like(StringUtils.hasText(query.keyword()), AnnotationTask::getTaskName, query.keyword())
.orderByDesc(AnnotationTask::getCreatedAt);
List<AnnotationTaskResponse> records = annotationTaskMapper.selectList(wrapper).stream()
.filter(task -> dataPermissionService.canAccessCreator(currentUser, task.getCreatorId(), task.getCreatorRole()))
.filter(task -> query.resourceId() == null || annotationTaskResourceMapper.listResourceIdsByTaskId(task.getId()).contains(query.resourceId()))
.sorted(Comparator.comparing(AnnotationTask::getCreatedAt, Comparator.nullsLast(Comparator.naturalOrder())).reversed())
.map(task -> buildTaskResponse(task, normalizeIds(annotationTaskResourceMapper.listResourceIdsByTaskId(task.getId()))))
.like(StringUtils.hasText(query.keyword()), AnnotationTask::getTaskName, query.keyword());
if (shouldFilterByUserId) {
wrapper.eq(AnnotationTask::getCreatorId, currentUser.userId());
} else if (!allowedRoles.isEmpty()) {
wrapper.in(AnnotationTask::getCreatorRole, allowedRoles);
}
wrapper.orderByDesc(AnnotationTask::getCreatedAt);
Page<AnnotationTask> page = new Page<>(query.pageNo(), query.pageSize());
Page<AnnotationTask> resultPage = annotationTaskMapper.selectPage(page, wrapper);
List<AnnotationTaskResponse> records = resultPage.getRecords().stream()
.filter(task -> query.resourceId() == null ||
annotationTaskResourceMapper.listResourceIdsByTaskId(task.getId()).contains(query.resourceId()))
.map(task -> buildTaskResponse(task,
normalizeIds(annotationTaskResourceMapper.listResourceIdsByTaskId(task.getId()))))
.toList();
return paginate(records, query.pageNo(), query.pageSize());
return new PageResult<>(records, resultPage.getTotal(), (int) resultPage.getCurrent(), (int) resultPage.getSize());
}
@Transactional
@@ -273,12 +292,4 @@ public class AnnotationTaskService {
}
return "****" + secret.substring(secret.length() - 4);
}
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);
}
}

View File

@@ -47,8 +47,8 @@ public class CompanyService {
}
private void assertPlatformAdmin(LoginUser currentUser) {
if (!currentUser.isPlatformAdmin()) {
throw new ForbiddenException("平台管理员可操作");
if (!currentUser.isSuperAdmin()) {
throw new ForbiddenException("系统管理员可操作");
}
}
}

View File

@@ -1,8 +1,18 @@
package com.labelsys.backend.service;
import java.io.IOException;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
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.config.ObjectStorageProperties;
import com.labelsys.backend.context.LoginUser;
import com.labelsys.backend.dto.common.PageResult;
import com.labelsys.backend.dto.request.SourceResourcePageQuery;
@@ -18,15 +28,9 @@ import com.labelsys.backend.mapper.SourceResourceMapper;
import com.labelsys.backend.mapper.SysUserMapper;
import com.labelsys.backend.util.IdGenerator;
import com.labelsys.backend.util.ObjectStoragePathBuilder;
import java.io.IOException;
import java.util.Comparator;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
@Slf4j
@Service
@@ -51,69 +55,64 @@ public class SourceResourceService {
}
long resourceId = IdGenerator.nextId();
String extension = resolveExtension(file.getOriginalFilename(), request.getResourceType());
String objectKey = ObjectStoragePathBuilder.sourceObjectKey(
currentUser.companyId(), request.getResourceType(), resourceId, extension);
String objectKey = ObjectStoragePathBuilder.sourceObjectKey(currentUser.companyId(), request.getResourceType(),
resourceId, extension);
try {
objectStorageService.upload(
objectStorageProperties.getSourceBucket(),
objectKey,
file.getBytes(),
objectStorageService.upload(objectStorageProperties.getSourceBucket(), objectKey, file.getBytes(),
file.getContentType());
} catch (IOException ex) {
throw new BusinessException(ResultCode.BAD_REQUEST, "读取上传文件失败");
}
SourceResource resource = SourceResource.builder()
.id(resourceId)
.companyId(currentUser.companyId())
.creatorId(currentUser.userId())
.creatorRole(currentUser.role())
.resourceName(StringUtils.hasText(request.getResourceName()) ? request.getResourceName() : file.getOriginalFilename())
.resourceType(request.getResourceType())
.bucketName(objectStorageProperties.getSourceBucket())
.filePath(objectKey)
.fileSize(file.getSize())
.sourceStatus(SourceStatus.READY.name())
.storageProvider("rustfs")
.remark(request.getRemark())
.build();
SourceResource resource = SourceResource.builder().id(resourceId).companyId(currentUser.companyId())
.creatorId(currentUser.userId()).creatorRole(currentUser.role())
.resourceName(
StringUtils.hasText(request.getResourceName()) ? request.getResourceName() : file.getOriginalFilename())
.resourceType(request.getResourceType()).bucketName(objectStorageProperties.getSourceBucket())
.filePath(objectKey).fileSize(file.getSize()).sourceStatus(SourceStatus.READY.name())
.storageProvider("rustfs").remark(request.getRemark()).build();
sourceResourceMapper.insert(resource);
log.info("uploaded source resource, companyId={}, userId={}, resourceId={}",
currentUser.companyId(), currentUser.userId(), resourceId);
return new SourceUploadResponse(
resource.getId(),
resource.getResourceName(),
resource.getResourceType(),
resource.getBucketName(),
resource.getFilePath(),
resource.getFileSize(),
resource.getSourceStatus(),
log.info("uploaded source resource, companyId={}, userId={}, resourceId={}", currentUser.companyId(),
currentUser.userId(), resourceId);
return new SourceUploadResponse(resource.getId(), resource.getResourceName(), resource.getResourceType(),
resource.getBucketName(), resource.getFilePath(), resource.getFileSize(), resource.getSourceStatus(),
resource.getCreatedAt());
}
public PageResult<SourceResourceResponse> pageResources(LoginUser currentUser, SourceResourcePageQuery query) {
LambdaQueryWrapper<SourceResource> wrapper = new LambdaQueryWrapper<SourceResource>()
.eq(SourceResource::getCompanyId, currentUser.companyId())
.eq(StringUtils.hasText(query.resourceType()), SourceResource::getResourceType, query.resourceType())
.eq(StringUtils.hasText(query.sourceStatus()), SourceResource::getSourceStatus, query.sourceStatus())
.like(StringUtils.hasText(query.keyword()), SourceResource::getResourceName, query.keyword())
.orderByDesc(SourceResource::getCreatedAt);
List<SourceResourceResponse> records = sourceResourceMapper.selectList(wrapper).stream()
.filter(resource -> dataPermissionService.canAccessCreator(currentUser, resource.getCreatorId(), resource.getCreatorRole()))
.sorted(Comparator.comparing(SourceResource::getCreatedAt, Comparator.nullsLast(Comparator.naturalOrder())).reversed())
.map(this::toResponse)
.toList();
return paginate(records, query.pageNo(), query.pageSize());
List<String> allowedRoles = dataPermissionService.getAllowedRoles(currentUser);
boolean shouldFilterByUserId = dataPermissionService.shouldFilterByUserId(currentUser);
LambdaQueryWrapper<SourceResource> wrapper =
new LambdaQueryWrapper<SourceResource>().eq(SourceResource::getCompanyId, currentUser.companyId())
.eq(StringUtils.hasText(query.resourceType()), SourceResource::getResourceType, query.resourceType())
.eq(StringUtils.hasText(query.sourceStatus()), SourceResource::getSourceStatus, query.sourceStatus())
.like(StringUtils.hasText(query.keyword()), SourceResource::getResourceName, query.keyword());
if (shouldFilterByUserId) {
wrapper.eq(SourceResource::getCreatorId, currentUser.userId());
} else if (!allowedRoles.isEmpty()) {
wrapper.in(SourceResource::getCreatorRole, allowedRoles);
}
wrapper.orderByDesc(SourceResource::getCreatedAt);
Page<SourceResource> page = new Page<>(query.pageNo(), query.pageSize());
Page<SourceResource> resultPage = sourceResourceMapper.selectPage(page, wrapper);
List<SourceResourceResponse> records = resultPage.getRecords().stream().map(this::toResponse).toList();
return new PageResult<>(records, resultPage.getTotal(), (int)resultPage.getCurrent(),
(int)resultPage.getSize());
}
public SourceResourceResponse getResource(LoginUser currentUser, Long resourceId) {
SourceResource resource = sourceResourceMapper.selectById(resourceId);
if (resource == null || !currentUser.companyId().equals(resource.getCompanyId())) {
log.warn("Resource not found or cross-tenant access attempt: resourceId={}, companyId={}, userId={}",
resourceId, currentUser.companyId(), currentUser.userId());
throw new BusinessException(ResultCode.NOT_FOUND, "资源不存在");
}
if (!dataPermissionService.canAccessCreator(currentUser, resource.getCreatorId(), resource.getCreatorRole())) {
throw new BusinessException(ResultCode.FORBIDDEN, "无权访问资源");
}
return toResponse(resource);
}
@@ -136,25 +135,16 @@ public class SourceResourceService {
}
objectStorageService.delete(resource.getBucketName(), resource.getFilePath());
sourceResourceMapper.deleteById(resourceId);
log.info("deleted source resource, companyId={}, userId={}, resourceId={}",
currentUser.companyId(), currentUser.userId(), resourceId);
log.info("deleted source resource, companyId={}, userId={}, resourceId={}", currentUser.companyId(),
currentUser.userId(), resourceId);
}
private SourceResourceResponse toResponse(SourceResource resource) {
SysUser creator = sysUserMapper.selectById(resource.getCreatorId());
return new SourceResourceResponse(
resource.getId(),
resource.getResourceName(),
resource.getResourceType(),
resource.getBucketName(),
resource.getFilePath(),
resource.getFileSize(),
resource.getSourceStatus(),
resource.getStorageProvider(),
resource.getRemark(),
creator == null ? null : creator.getRealName(),
resource.getCreatedAt(),
resource.getUpdatedAt());
return new SourceResourceResponse(resource.getId(), resource.getResourceName(), resource.getResourceType(),
resource.getBucketName(), resource.getFilePath(), resource.getFileSize(), resource.getSourceStatus(),
resource.getStorageProvider(), resource.getRemark(), creator == null ? null : creator.getRealName(),
resource.getCreatedAt(), resource.getUpdatedAt());
}
private String resolveExtension(String originalFilename, String resourceType) {
@@ -168,12 +158,4 @@ public class SourceResourceService {
default -> "bin";
};
}
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);
}
}

View File

@@ -12,6 +12,7 @@ import com.labelsys.backend.common.exception.BusinessException;
import com.labelsys.backend.common.exception.ForbiddenException;
import com.labelsys.backend.context.LoginUser;
import com.labelsys.backend.dto.request.CreateCompanyAdminRequest;
import com.labelsys.backend.dto.request.CreateSystemEngineerAdminRequest;
import com.labelsys.backend.dto.request.CreateUserRequest;
import com.labelsys.backend.dto.request.UpdateUserAssignmentRequest;
import com.labelsys.backend.dto.request.UpdateUserStatusRequest;
@@ -39,6 +40,12 @@ public class UserService {
private final PasswordEncoder passwordEncoder;
private final TokenSessionRepository tokenSessionRepository;
public List<SysUser> listAllUsers(LoginUser currentUser) {
assertSystemAdmin(currentUser);
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<SysUser>().orderByAsc(SysUser::getId);
return sysUserMapper.selectList(wrapper);
}
public List<SysUser> listCompanyUsers(LoginUser currentUser) {
assertCompanyAdmin(currentUser);
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<SysUser>()
@@ -47,17 +54,32 @@ public class UserService {
}
public List<SysUser> listCompanyAdmins(LoginUser currentUser, Long companyId) {
assertPlatformAdmin(currentUser);
assertSystemAdmin(currentUser);
return sysUserMapper.listCompanyAdmins(companyId);
}
public SysUser createCompanyAdmin(LoginUser currentUser, CreateCompanyAdminRequest request) {
assertPlatformAdmin(currentUser);
assertSystemAdmin(currentUser);
ensureEnabledCompany(request.companyId());
return createUser(
request.companyId(),
new CreateUserRequest(request.phone(), request.username(), request.realName(), UserRole.EMPLOYEE, UserPosition.ADMIN)
);
return createUser(request.companyId(), new CreateUserRequest(request.phone(), request.username(),
request.realName(), UserRole.EMPLOYEE, UserPosition.ADMIN));
}
public SysUser createSystemEngineerAdmin(LoginUser currentUser, CreateSystemEngineerAdminRequest request) {
assertSystemAdmin(currentUser);
Long systemCompanyId = 1L;
ensureEnabledCompany(systemCompanyId);
if (sysUserMapper.findByCompanyIdAndPhone(systemCompanyId, request.phone()) != null) {
throw new BusinessException(ResultCode.CONFLICT, "同一公司内手机号已存在");
}
SysUser user = SysUser.builder().id(IdGenerator.nextId()).companyId(systemCompanyId).phone(request.phone())
.username(request.username()).realName(request.realName()).role(UserRole.ENGINEER)
.position(UserPosition.SUPER_ADMIN).passwordHash(passwordEncoder.encode(DEFAULT_PASSWORD))
.mustChangePassword(true).status(UserStatus.ENABLED).sessionVersion(1).build();
sysUserMapper.insert(user);
return user;
}
public SysUser createCompanyUser(LoginUser currentUser, CreateUserRequest request) {
@@ -66,7 +88,7 @@ public class UserService {
}
public SysUser createCompanyUser(LoginUser currentUser, Long companyId, CreateUserRequest request) {
assertPlatformAdmin(currentUser);
assertSystemAdmin(currentUser);
ensureEnabledCompany(companyId);
return createUser(companyId, request);
}
@@ -90,8 +112,9 @@ public class UserService {
}
@Transactional
public void updateCompanyAdminStatus(LoginUser currentUser, Long companyId, Long userId, UpdateUserStatusRequest request) {
assertPlatformAdmin(currentUser);
public void updateCompanyAdminStatus(LoginUser currentUser, Long companyId, Long userId,
UpdateUserStatusRequest request) {
assertSystemAdmin(currentUser);
if (sysUserMapper.updateStatus(userId, companyId, request.status()) == 0) {
throw new BusinessException(ResultCode.NOT_FOUND, "用户不存在");
}
@@ -102,19 +125,10 @@ public class UserService {
if (sysUserMapper.findByCompanyIdAndPhone(companyId, request.phone()) != null) {
throw new BusinessException(ResultCode.CONFLICT, "同一公司内手机号已存在");
}
SysUser user = SysUser.builder()
.id(IdGenerator.nextId())
.companyId(companyId)
.phone(request.phone())
.username(request.username())
.realName(request.realName())
.role(request.role())
.position(request.position())
.passwordHash(passwordEncoder.encode(DEFAULT_PASSWORD))
.mustChangePassword(true)
.status(UserStatus.ENABLED)
.sessionVersion(1)
.build();
SysUser user = SysUser.builder().id(IdGenerator.nextId()).companyId(companyId).phone(request.phone())
.username(request.username()).realName(request.realName()).role(request.role()).position(request.position())
.passwordHash(passwordEncoder.encode(DEFAULT_PASSWORD)).mustChangePassword(true).status(UserStatus.ENABLED)
.sessionVersion(1).build();
sysUserMapper.insert(user);
return user;
}
@@ -126,14 +140,20 @@ public class UserService {
}
}
private void assertPlatformAdmin(LoginUser currentUser) {
if (!currentUser.isPlatformAdmin()) {
throw new ForbiddenException("仅平台管理员可操作");
// private void assertPlatformAdmin(LoginUser currentUser) {
// if (!currentUser.isPlatformAdmin()) {
// throw new ForbiddenException("仅平台管理员可操作");
// }
// }
private void assertSystemAdmin(LoginUser currentUser) {
if (!currentUser.isSuperAdmin()) {
throw new ForbiddenException("仅超级管理员可操作");
}
}
private void assertCompanyAdmin(LoginUser currentUser) {
if (currentUser.isPlatformAdmin() || currentUser.position() != UserPosition.ADMIN) {
if (currentUser.isSuperAdmin() || currentUser.position() != UserPosition.ADMIN) {
throw new ForbiddenException("仅公司管理员可操作");
}
}