深度解析后端代码提交
This commit is contained in:
parent
6b0b97d0a6
commit
dd2fec0507
|
@ -0,0 +1,27 @@
|
||||||
|
package com.bjtds.brichat.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务配置类
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class ScheduleConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置定时任务线程池
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public TaskScheduler taskScheduler() {
|
||||||
|
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||||
|
scheduler.setPoolSize(5); // 设置线程池大小
|
||||||
|
scheduler.setThreadNamePrefix("pdf-task-scheduler-");
|
||||||
|
scheduler.setAwaitTerminationSeconds(60);
|
||||||
|
scheduler.setWaitForTasksToCompleteOnShutdown(true);
|
||||||
|
scheduler.initialize();
|
||||||
|
return scheduler;
|
||||||
|
}
|
||||||
|
}
|
|
@ -234,4 +234,6 @@ public class DatasetDocController {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.bjtds.brichat.entity.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF转换API响应实体类
|
||||||
|
*/
|
||||||
|
public class PdfConversionResponse {
|
||||||
|
|
||||||
|
@JsonProperty("task_id")
|
||||||
|
private String taskId;
|
||||||
|
|
||||||
|
public PdfConversionResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public PdfConversionResponse(String taskId) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskId() {
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskId(String taskId) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PdfConversionResponse{" +
|
||||||
|
"taskId='" + taskId + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.bjtds.brichat.entity.dto;
|
||||||
|
|
||||||
|
import com.bjtds.brichat.entity.dataset.DocumentUploadReq;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF转换任务信息DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class PdfTaskDto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务ID
|
||||||
|
*/
|
||||||
|
@JsonProperty("task_id")
|
||||||
|
private String taskId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析百分比
|
||||||
|
*/
|
||||||
|
private Double percent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据集ID
|
||||||
|
*/
|
||||||
|
private String datasetId;
|
||||||
|
|
||||||
|
private String datasetName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Long createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传请求参数
|
||||||
|
*/
|
||||||
|
private DocumentUploadReq uploadReq;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PdfTaskDto{" +
|
||||||
|
"name='" + name + '\'' +
|
||||||
|
", taskId='" + taskId + '\'' +
|
||||||
|
", percent=" + percent +
|
||||||
|
", datasetId='" + datasetId + '\'' +
|
||||||
|
", createTime=" + createTime +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,155 @@
|
||||||
|
package com.bjtds.brichat.entity.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF任务状态查询响应实体类
|
||||||
|
*/
|
||||||
|
public class PdfTaskStatusResponse {
|
||||||
|
|
||||||
|
@JsonProperty("task_id")
|
||||||
|
private String taskId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务状态:PENDING/SUCCESS/FAILURE/STARTED
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换结果(仅SUCCESS时返回)
|
||||||
|
*/
|
||||||
|
private String result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进度信息
|
||||||
|
*/
|
||||||
|
private Progress progress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误信息(仅FAILURE时返回)
|
||||||
|
*/
|
||||||
|
private Object error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进度信息内部类
|
||||||
|
*/
|
||||||
|
public static class Progress {
|
||||||
|
@JsonProperty("total_pages")
|
||||||
|
private Integer totalPages;
|
||||||
|
|
||||||
|
@JsonProperty("success_pages")
|
||||||
|
private Integer successPages;
|
||||||
|
|
||||||
|
@JsonProperty("failed_pages")
|
||||||
|
private Integer failedPages;
|
||||||
|
|
||||||
|
@JsonProperty("failed_page_numbers")
|
||||||
|
private Object[] failedPageNumbers;
|
||||||
|
|
||||||
|
public Integer getTotalPages() {
|
||||||
|
return totalPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalPages(Integer totalPages) {
|
||||||
|
this.totalPages = totalPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSuccessPages() {
|
||||||
|
return successPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuccessPages(Integer successPages) {
|
||||||
|
this.successPages = successPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getFailedPages() {
|
||||||
|
return failedPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFailedPages(Integer failedPages) {
|
||||||
|
this.failedPages = failedPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getFailedPageNumbers() {
|
||||||
|
return failedPageNumbers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFailedPageNumbers(Object[] failedPageNumbers) {
|
||||||
|
this.failedPageNumbers = failedPageNumbers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算转换百分比
|
||||||
|
*/
|
||||||
|
public Double getPercent() {
|
||||||
|
if (totalPages == null || totalPages == 0) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
return (successPages != null ? successPages : 0) * 100.0 / totalPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Progress{" +
|
||||||
|
"totalPages=" + totalPages +
|
||||||
|
", successPages=" + successPages +
|
||||||
|
", failedPages=" + failedPages +
|
||||||
|
", percent=" + getPercent() + "%" +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PdfTaskStatusResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskId() {
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskId(String taskId) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResult(String result) {
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Progress getProgress() {
|
||||||
|
return progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgress(Progress progress) {
|
||||||
|
this.progress = progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getError() {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setError(Object error) {
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PdfTaskStatusResponse{" +
|
||||||
|
"taskId='" + taskId + '\'' +
|
||||||
|
", status='" + status + '\'' +
|
||||||
|
", progress=" + progress +
|
||||||
|
", hasResult=" + (result != null && !result.isEmpty()) +
|
||||||
|
", hasError=" + (error != null) +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue