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

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.weekly.WeeklyReportApprovalRecordDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface WeeklyReportApprovalRecordMapper extends BaseMapperX<WeeklyReportApprovalRecordDO> {

    default List<WeeklyReportApprovalRecordDO> selectListByWeeklyReportId(Long weeklyReportId) {
        return selectList(new LambdaQueryWrapperX<WeeklyReportApprovalRecordDO>()
                .eq(WeeklyReportApprovalRecordDO::getWeeklyReportId, weeklyReportId)
                .orderByDesc(WeeklyReportApprovalRecordDO::getApprovalRound)
                .orderByDesc(WeeklyReportApprovalRecordDO::getId));
    }

    default int countByWeeklyReportId(Long weeklyReportId) {
        return Math.toIntExact(selectCount(new LambdaQueryWrapperX<WeeklyReportApprovalRecordDO>()
                .eq(WeeklyReportApprovalRecordDO::getWeeklyReportId, weeklyReportId)));
    }

    default int deleteByWeeklyReportId(Long weeklyReportId) {
        return delete(new LambdaQueryWrapperX<WeeklyReportApprovalRecordDO>()
                .eq(WeeklyReportApprovalRecordDO::getWeeklyReportId, weeklyReportId));
    }
}
