package cn.iocoder.yudao.module.system.dal.mysql.biz;


import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.RoundRecordPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.WardRoundRecordDO;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalTime;


/**
 * 查房记录 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface WardRoundRecordMapper extends BaseMapperX<WardRoundRecordDO> {

    default PageResult<WardRoundRecordDO> selectPage(RoundRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WardRoundRecordDO>()
                .eqIfPresent(WardRoundRecordDO::getElderId, reqVO.getElderId())
                .eqIfPresent(WardRoundRecordDO::getRoundPerson, reqVO.getRoundPerson())
                .eqIfPresent(WardRoundRecordDO::getRoundContent, reqVO.getRoundContent())
                .eqIfPresent(WardRoundRecordDO::getRemarks, reqVO.getRemarks())
                .eqIfPresent(WardRoundRecordDO::getTenantId, reqVO.getTenantId())
                .likeIfPresent(WardRoundRecordDO::getElderName, reqVO.getElderName())
                .geIfPresent(WardRoundRecordDO::getRoundTime, reqVO.getRoundTime() != null && reqVO.getRoundTime().length >= 1 ? reqVO.getRoundTime()[0].atStartOfDay() : null)
                .leIfPresent(WardRoundRecordDO::getRoundTime, reqVO.getRoundTime() != null &&reqVO.getRoundTime().length == 2 ? reqVO.getRoundTime()[1].atTime(LocalTime.MAX) : null)
                .orderByDesc(WardRoundRecordDO::getRoundTime));
    }

}