package thyyxxk.webserver.dao.his.archive;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import thyyxxk.webserver.entity.archive.PatientArchive;

import java.util.List;

public interface PatientArchiveDao extends BaseMapper<PatientArchive> {

    default List<PatientArchive> getPatientList(String patNo, Integer times) {
        LambdaQueryWrapper<PatientArchive> eq = PatientArchive
                .lambdaQueryWrapper()
                .eq(PatientArchive::getPatNo, patNo)
                .eq(PatientArchive::getTimes, times);
        return this.selectList(eq);
    }

    default boolean hasDir(String patNo, Integer times, String id) {
        LambdaQueryWrapper<PatientArchive> eq = PatientArchive
                .lambdaQueryWrapper()
                .eq(PatientArchive::getPatNo, patNo)
                .eq(PatientArchive::getTimes, times)
                .eq(PatientArchive::getParentId, id);

        return this.selectCount(eq) > 0;
    }

    default boolean dirNameRepeat(PatientArchive data) {
        LambdaQueryWrapper<PatientArchive> eq = PatientArchive
                .lambdaQueryWrapper()
                .eq(PatientArchive::getPatNo, data.getPatNo())
                .eq(PatientArchive::getTimes, data.getTimes())
                .eq(PatientArchive::getName, data.getName());

        if (data.getParentId() == null) {
            eq.isNull(PatientArchive::getParentId);
        } else {
            eq.eq(PatientArchive::getParentId, data.getParentId());
        }

        return this.selectCount(eq) > 0;
    }

}
