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

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.ElderlyNursingLogRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.elderly.ElderlyNursingLogDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.List;

/**
 * 长者护理记录 Mapper
 */
@Mapper
public interface ElderlyNursingLogMapper extends BaseMapperX<ElderlyNursingLogDO> {

    default List<ElderlyNursingLogDO> selectByElderId(Long elderId, LocalDate start, LocalDate end) {
        return selectList(new LambdaQueryWrapperX<ElderlyNursingLogDO>()
                .eq(ElderlyNursingLogDO::getElderId, elderId)
                .leIfPresent(ElderlyNursingLogDO::getNurseDate, end)
                .ge(ElderlyNursingLogDO::getNurseDate, start)
                .orderByDesc(ElderlyNursingLogDO::getNurseDate)
                .orderByDesc(ElderlyNursingLogDO::getId));
    }

    default List<ElderlyNursingLogDO> selectList(String nurse, Long tenantId, LocalDate startDate, LocalDate endDate) {
        return selectList(new LambdaQueryWrapperX<ElderlyNursingLogDO>()
                .eqIfPresent(ElderlyNursingLogDO::getTenantId, tenantId)
                .likeIfPresent(ElderlyNursingLogDO::getNurse, nurse)
                .leIfPresent(ElderlyNursingLogDO::getNurseDate, endDate)
                .ge(ElderlyNursingLogDO::getNurseDate, startDate)
                .orderByDesc(ElderlyNursingLogDO::getNurseDate)
                .orderByDesc(ElderlyNursingLogDO::getId));
    }

    List<ElderlyNursingLogRespVO> selectListWithItemName(@Param("nurse") String nurse,
                                                        @Param("tenantId") Long tenantId,
                                                        @Param("startDate") LocalDate startDate,
                                                        @Param("endDate") LocalDate endDate);

    List<ElderlyNursingLogRespVO> selectByElderIdWithItemName(@Param("elderId") Long elderId,
                                                             @Param("startDate") LocalDate startDate,
                                                             @Param("endDate") LocalDate endDate);
}
