package thyyxxk.webserver.entity.archive;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import thyyxxk.webserver.service.archive.TaskPatient;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "archive_task")
public class ArchiveTask implements Serializable {

    private static final long serialVersionUID = 974120735292108305L;

    /**
     * 用住院号和住院次数拼接的id
     */
    @TableId
    private String id;

    /**
     * createData
     */
    @TableField(value = "create_data")
    private Date createData;

    /**
     * 提交人
     */
    @TableField(value = "submit_code")
    private String submitCode;

    @TableField(value = "pass_task")
    private String passTask;

    public static LambdaQueryWrapper<ArchiveTask> lambdaQueryWrapper() {
        return new LambdaQueryWrapper<>();
    }

    public static QueryWrapper<ArchiveTask> queryWrapper() {
        return new QueryWrapper<>();
    }

    public static String setUid(String patNo, Integer times) {
        return patNo + "_" + times;
    }

    public TaskPatient conversionTask() {
        String[] split = id.split("_");

        List<String> passTaskList = new ArrayList<>();
        if (passTask != null) {
            Collections.addAll(passTaskList, passTask.split(","));
        }

        return TaskPatient.builder()
                .patNo(split[0])
                .times(Integer.parseInt(split[1]))
                .submitCode(submitCode)
                .passTaskName(passTaskList)
                .build();
    }

}
