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

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.evection.BpmOAEvectionCreateReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAEvectionDO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Arrays;
import java.util.List;

/**
 * 出差申请 Mapper
 *
 * @author 符溶馨

 */
@Mapper
public interface BpmOAEvectionMapper extends BaseMapperX<BpmOAEvectionDO> {


    default Long selectIsExist(Long userId, BpmOAEvectionCreateReqVO createReqVO) {
        return selectCount(new LambdaQueryWrapperX<BpmOAEvectionDO>()
                .eq(BpmOAEvectionDO::getUserId, userId)
                .leIfPresent(BpmOAEvectionDO::getStartTime, createReqVO.getEndTime())
                .geIfPresent(BpmOAEvectionDO::getEndTime, createReqVO.getStartTime())
                .in(BpmOAEvectionDO::getResult, Arrays.asList(BpmProcessInstanceResultEnum.PROCESS.getResult(), BpmProcessInstanceResultEnum.APPROVE.getResult())));
    }

    List<BpmOAEvectionDO> selectEvectionList(@Param("userId") Long userId);
}
