package thyyxxk.webserver.service.reports;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.dao.his.reports.PatientDistributionAddressDao;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.inpatient.patient.Patient;
import thyyxxk.webserver.utils.ListUtil;
import thyyxxk.webserver.utils.ResultVoUtil;
import thyyxxk.webserver.utils.StringUtil;

import java.util.List;

@Service
@Slf4j
public class PatientDistributionAddressServer {

    private final PatientDistributionAddressDao dao;

    public PatientDistributionAddressServer(PatientDistributionAddressDao dao) {
        this.dao = dao;
    }

    public ResultVo<List<Patient>> inpatientLocation(String tableName, String startTime, String endTime) {

        QueryWrapper<?> qw = new QueryWrapper<>();
        qw.eq("1", 1);

        if (StringUtil.notBlank(startTime) && "zy_inactpatient".equals(tableName)) {
            qw.ge("b.dis_date", startTime);
            qw.le("b.dis_date", endTime);
        }

        return adderss(dao.inpatientAddress(tableName, qw));
    }

    public ResultVo<List<Patient>> mzLocation(String startTime, String endTime) {
        return adderss(dao.mzAddress(startTime, endTime));
    }

    private ResultVo<List<Patient>> adderss(List<Patient> list) {
        if (ListUtil.isBlank(list)) {
            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
        }
        return ResultVoUtil.success(list);
    }


}
