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

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.workreport.project.ProjectReportApprovalRecordDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface ProjectReportApprovalRecordMapper extends BaseMapperX<ProjectReportApprovalRecordDO> {

    default List<ProjectReportApprovalRecordDO> selectListByProjectReportId(Long projectReportId) {
        return selectList(new LambdaQueryWrapperX<ProjectReportApprovalRecordDO>()
                .eq(ProjectReportApprovalRecordDO::getProjectReportId, projectReportId)
                .orderByDesc(ProjectReportApprovalRecordDO::getApprovalRound)
                .orderByDesc(ProjectReportApprovalRecordDO::getId));
    }

    default int countByProjectReportId(Long projectReportId) {
        return Math.toIntExact(selectCount(new LambdaQueryWrapperX<ProjectReportApprovalRecordDO>()
                .eq(ProjectReportApprovalRecordDO::getProjectReportId, projectReportId)));
    }

    default int deleteByProjectReportId(Long projectReportId) {
        return delete(new LambdaQueryWrapperX<ProjectReportApprovalRecordDO>()
                .eq(ProjectReportApprovalRecordDO::getProjectReportId, projectReportId));
    }
}
