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.TrainingRecordsPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.TrainingRecordsDO;
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 TrainingRecordsMapper extends BaseMapperX<TrainingRecordsDO> {

    default PageResult<TrainingRecordsDO> selectPage(TrainingRecordsPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TrainingRecordsDO>()
                .eqIfPresent(TrainingRecordsDO::getElderId, reqVO.getElderId())
                .eqIfPresent(TrainingRecordsDO::getTherapist, reqVO.getTherapist())
                .eqIfPresent(TrainingRecordsDO::getRecordContent, reqVO.getRecordContent())
                .eqIfPresent(TrainingRecordsDO::getTenantId,reqVO.getTenantId())
                .likeIfPresent(TrainingRecordsDO::getElderName,reqVO.getElderName())
                .geIfPresent(TrainingRecordsDO::getTrainingTime, reqVO.getTrainingTime() != null && reqVO.getTrainingTime().length >= 1 ? reqVO.getTrainingTime()[0].atStartOfDay() : null)
                .leIfPresent(TrainingRecordsDO::getTrainingTime, reqVO.getTrainingTime() != null && reqVO.getTrainingTime().length == 2 ? reqVO.getTrainingTime()[1].atTime(LocalTime.MAX) : null)
                .orderByDesc(TrainingRecordsDO::getCreateTime));
    }

}