package com.njcn.rdms.module.project.dal.mysql.overtime;

import com.njcn.rdms.framework.mybatis.core.mapper.BaseMapperX;
import com.njcn.rdms.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.njcn.rdms.module.project.dal.dataobject.overtime.OvertimeApplicationApprovalRecordDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface OvertimeApplicationApprovalRecordMapper extends BaseMapperX<OvertimeApplicationApprovalRecordDO> {

    default List<OvertimeApplicationApprovalRecordDO> selectListByApplicationId(Long applicationId) {
        return selectList(new LambdaQueryWrapperX<OvertimeApplicationApprovalRecordDO>()
                .eq(OvertimeApplicationApprovalRecordDO::getOvertimeApplicationId, applicationId)
                .orderByDesc(OvertimeApplicationApprovalRecordDO::getApprovalRound)
                .orderByDesc(OvertimeApplicationApprovalRecordDO::getId));
    }

    default int countByApplicationId(Long applicationId) {
        return Math.toIntExact(selectCount(new LambdaQueryWrapperX<OvertimeApplicationApprovalRecordDO>()
                .eq(OvertimeApplicationApprovalRecordDO::getOvertimeApplicationId, applicationId)));
    }
}
