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

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.elderly.vo.ElderlyRestraintPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.elderly.ElderlyRestraintDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 约束观察记录 Mapper
 */
@Mapper
public interface ElderlyRestraintMapper extends BaseMapperX<ElderlyRestraintDO> {

    default PageResult<ElderlyRestraintDO> selectPage(ElderlyRestraintPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ElderlyRestraintDO>()
                .betweenIfPresent(ElderlyRestraintDO::getRecordDate, reqVO.getRecordDate())
                .inIfPresent(ElderlyRestraintDO::getTenantId, reqVO.getTenantIds())
                .orderByDesc(ElderlyRestraintDO::getRecordDate)
                .orderByDesc(ElderlyRestraintDO::getId)
        );
    }

    default List<ElderlyRestraintDO> selectByElderId(Long elderId) {
        return selectList(new LambdaQueryWrapper<ElderlyRestraintDO>()
                .eq(ElderlyRestraintDO::getElderId, elderId)
                .orderByDesc(ElderlyRestraintDO::getRecordDate)
        );
    }
}

