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

import cn.iocoder.yudao.framework.common.pojo.PageResult;
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.loan.vo.LoanPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.loan.LoanDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;

/**
 * 借支管理 Mapper
 *
 * @author 符溶馨
 */
@Mapper
public interface LoanMapper extends BaseMapperX<LoanDO> {

    default PageResult<LoanDO> selectPage(LoanPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<LoanDO>()
                .eqIfPresent(LoanDO::getUserId, reqVO.getUserId())
                .eqIfPresent(LoanDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(LoanDO::getLoanType, reqVO.getLoanType())
                .ne(reqVO.getModel() == 0, LoanDO::getRemainingAmount, 0)
                .orderByDesc(LoanDO::getRemainingAmount)
                .orderByDesc(LoanDO::getUserId));
    }

    List<LoanDO> selectListByMonth(@Param("userId") Collection<Long> userId, @Param("month") String month);
}