package cn.iocoder.yudao.module.bpm.dal.mysql.oa;

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.bpm.controller.admin.oa.vo.payment.BpmOAPaymentPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.payment.BpmOAPaymentRespVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAPaymentDO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface BpmOAPaymentMapper extends BaseMapperX<BpmOAPaymentDO> {

    List<BpmOAPaymentRespVO> selectPaymentList(@Param("type") Integer type,
                                               @Param("deptId") Long deptId,
                                               @Param("method") Integer method);

    default PageResult<BpmOAPaymentDO> selectTicketsPage(BpmOAPaymentPageReqVO pageReqVO, Long userId) {

        return selectPage(pageReqVO, new LambdaQueryWrapperX<BpmOAPaymentDO>()
                .eq(BpmOAPaymentDO::getResult, BpmProcessInstanceResultEnum.APPROVE.getResult())
                .eq(BpmOAPaymentDO::getIsTickets, 1)
                .eqIfPresent(BpmOAPaymentDO::getStatus, pageReqVO.getStatus())
                .betweenIfPresent(BpmOAPaymentDO::getCreateTime, pageReqVO.getCreateTime())
                .eqIfPresent(BpmOAPaymentDO::getUserId, pageReqVO.getUserId())
                .eq(pageReqVO.getIsMy(), BpmOAPaymentDO::getUserId, userId)
                .orderByAsc(BpmOAPaymentDO::getStatus)
                .orderByDesc(BpmOAPaymentDO::getId));
    }
}
