package thyyxxk.webserver.dao.his.archive;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import thyyxxk.webserver.entity.archive.ArchiveTask;
import thyyxxk.webserver.service.archive.TaskPatient;

import java.util.Date;
import java.util.List;

@Mapper
public interface ArchiveTaskDao extends BaseMapper<ArchiveTask> {

    default ArchiveTask hasData(String id) {
        return this.selectOne(ArchiveTask.lambdaQueryWrapper().eq(ArchiveTask::getId, id));
    }

    default void setData(TaskPatient data) {
        String id = ArchiveTask.setUid(data.getPatNo(), data.getTimes());
        String pass = data.getPassTaskName() == null ? null :
                String.join(",", data.getPassTaskName());
        ArchiveTask build = ArchiveTask
                .builder()
                .id(id)
                .createData(new Date())
                .submitCode(data.getSubmitCode())
                .passTask(pass)
                .build();
        this.insert(build);
    }

    default void delData(String id) {
        this.deleteById(id);
    }

    default List<ArchiveTask> getAllData() {
        return this.selectList(null);
    }

    default void delAll() {
        this.delete(null);
    }

}
