/**
 * @ProjectName: 智慧评标-主观分助手
 * @Package: com.zhpb.gdyd_zhpb_zgf.entity.mysql
 * @ClassName: ComparisonTask
 * @Description: 对比分析任务实体
 * @Author: 张志锋
 * @Date: 2025-11-04
 * @Version: 1.0
 * @Copyright: © 2025 智慧评标-主观分助手
 */
package com.zhpb.gdyd_zhpb_zgf.entity.mysql;

import jakarta.persistence.*;
import java.time.LocalDateTime;

/**
 * 对比分析任务实体
 */
@Entity
@Table(name = "t_comparison_task")
public class ComparisonTask {

    @Id
    @Column(name = "task_id", length = 64)
    private String taskId;

    @Column(name = "project_id", length = 64, nullable = false)
    private String projectId;

    @Column(name = "user_id", length = 64, nullable = false)
    private String userId;

    @Column(name = "vendor_ids", columnDefinition = "TEXT")
    private String vendorIds; // JSON格式存储供应商ID列表

    @Column(name = "dimensions", columnDefinition = "TEXT")
    private String dimensions; // JSON格式存储对比维度

    @Column(name = "status", length = 32, nullable = false)
    private String status; // pending, processing, completed, failed

    @Lob
    @Column(name = "result", columnDefinition = "TEXT")
    private String result; // JSON格式存储对比结果

    @Column(name = "error_message", columnDefinition = "TEXT")
    private String errorMessage;

    @Column(name = "progress", nullable = false)
    private Integer progress = 0; // 进度百分比 0-100

    @Column(name = "create_time", nullable = false)
    private LocalDateTime createTime;

    @Column(name = "update_time")
    private LocalDateTime updateTime;

    @Column(name = "completed_time")
    private LocalDateTime completedTime;

    // Getters and Setters
    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getVendorIds() {
        return vendorIds;
    }

    public void setVendorIds(String vendorIds) {
        this.vendorIds = vendorIds;
    }

    public String getDimensions() {
        return dimensions;
    }

    public void setDimensions(String dimensions) {
        this.dimensions = dimensions;
    }

    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 String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public Integer getProgress() {
        return progress;
    }

    public void setProgress(Integer progress) {
        this.progress = progress;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public LocalDateTime getCompletedTime() {
        return completedTime;
    }

    public void setCompletedTime(LocalDateTime completedTime) {
        this.completedTime = completedTime;
    }

    @PrePersist
    protected void onCreate() {
        createTime = LocalDateTime.now();
        updateTime = LocalDateTime.now();
        if (progress == null) {
            progress = 0;
        }
    }

    @PreUpdate
    protected void onUpdate() {
        updateTime = LocalDateTime.now();
    }
}
