package com.diagbot.facade;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.dto.DoctorAdviceDTO;
import com.diagbot.entity.DoctorAdvice;
import com.diagbot.exception.CommonErrorCode;
import com.diagbot.exception.CommonException;
import com.diagbot.service.impl.DoctorAdviceServiceImpl;
import com.diagbot.util.DateUtil;
import com.diagbot.util.SysUserUtils;
import com.diagbot.vo.DoctorAdviceVO;
import com.diagbot.vo.FilterVO;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @author: zhoutg
 * @time: 2024/4/12 11:39
 */
@Component
public class DoctorAdviceFacade extends DoctorAdviceServiceImpl {

    /**
     * 获取医嘱信息翻页
     *
     * @param doctorAdviceVO 获取医嘱信息入参
     * @return 医嘱翻页信息
     */
    public IPage<DoctorAdviceDTO> getPageFac(DoctorAdviceVO doctorAdviceVO) {
        doctorAdviceVO.setHospitalId(Long.valueOf(SysUserUtils.getCurrentHospitalID()));
        if (null != doctorAdviceVO.getDaStartDateStart()) {
            doctorAdviceVO.setDaStartDateStart(DateUtil.getFirstTimeOfDay(doctorAdviceVO.getDaStartDateStart()));
        }
        if (null != doctorAdviceVO.getDaStartDateEnd()) {
            doctorAdviceVO.setDaStartDateEnd(DateUtil.getFirstTimeOfDay(DateUtil.addDay(doctorAdviceVO.getDaStartDateEnd(), 1)));
        }
        if (null != doctorAdviceVO.getDaStartDateStart() && null != doctorAdviceVO.getDaStartDateEnd()) {
            if (DateUtil.after(doctorAdviceVO.getDaStartDateStart(), doctorAdviceVO.getDaStartDateEnd())) {
                throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "开始时间必须小于结束时间！");
            }
        }
        return this.getPage(doctorAdviceVO);
    }

    /**
     * 获取医嘱
     * @param filterVO
     * @return
     */
    public List<Map<String, String>> getDoctorAdviceNum(FilterVO filterVO){
        return baseMapper.getDoctorAdviceNum(filterVO);

    }
}
