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

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

import java.util.List;

@Mapper
public interface PerformanceSheetResponseRecordMapper extends BaseMapperX<PerformanceSheetResponseRecordDO> {

    default List<PerformanceSheetResponseRecordDO> selectListBySheetId(Long sheetId) {
        return selectList(new LambdaQueryWrapperX<PerformanceSheetResponseRecordDO>()
                .eq(PerformanceSheetResponseRecordDO::getSheetId, sheetId)
                .orderByDesc(PerformanceSheetResponseRecordDO::getCreateTime)
                .orderByDesc(PerformanceSheetResponseRecordDO::getId));
    }

    default int countBySheetId(Long sheetId) {
        return Math.toIntExact(selectCount(new LambdaQueryWrapperX<PerformanceSheetResponseRecordDO>()
                .eq(PerformanceSheetResponseRecordDO::getSheetId, sheetId)));
    }
}
