package com.diagbot.facade;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.dto.CheckInfoDTO;
import com.diagbot.dto.DoctorAdviceDTO;
import com.diagbot.exception.CommonErrorCode;
import com.diagbot.exception.CommonException;
import com.diagbot.service.impl.MedPacsInfoServiceImpl;
import com.diagbot.util.DateUtil;
import com.diagbot.util.SysUserUtils;
import com.diagbot.vo.CheckInfoVO;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @author: cy
 * @time: 2020/9/04 15:49
 */
@Component
public class MedPacsInfoFacade extends MedPacsInfoServiceImpl {
    /**
     * 获取检查信息翻页
     * @param checkInfoVO 获取检查信息入参
     * @return 检查翻页信息
     */
    public IPage<CheckInfoDTO> getCheckPage(CheckInfoVO checkInfoVO) {
        checkInfoVO.setHospitalId(Long.valueOf(SysUserUtils.getCurrentHospitalID()));
        if (null != checkInfoVO.getJxDateStart()) {
            checkInfoVO.setJxDateStart(DateUtil.getFirstTimeOfDay(checkInfoVO.getJxDateStart()));
        }
        if (null != checkInfoVO.getJxDateEnd()) {
            checkInfoVO.setJxDateEnd(DateUtil.getFirstTimeOfDay(DateUtil.addDay(checkInfoVO.getJxDateEnd(), 1)));
        }
        if (null != checkInfoVO.getJxDateStart() && null != checkInfoVO.getJxDateEnd()) {
            if (DateUtil.after(checkInfoVO.getJxDateStart(), checkInfoVO.getJxDateEnd())) {
                throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "开始时间必须小于结束时间！");
            }
        }
        return this.getCheckInfo(checkInfoVO);
    }
}
