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.worktask.BpmOAWorkTaskPageReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAWorkTaskDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 分配任务 Mapper
 *
 * @author yj

 */
@Mapper
public interface BpmOAWorkTaskMapper extends BaseMapperX<BpmOAWorkTaskDO> {

    default PageResult<BpmOAWorkTaskDO> selectPage(Long userId, BpmOAWorkTaskPageReqVO reqVO) {

        if (reqVO.getIsMyTask() == 2) {
            userId = null;
        }

        return selectPage(reqVO, new LambdaQueryWrapperX<BpmOAWorkTaskDO>()
                .eqIfPresent(BpmOAWorkTaskDO::getFromUserId, reqVO.getFromUserId())
                .inIfPresent(BpmOAWorkTaskDO::getReceiverUserId, reqVO.getUserIdList())
                .eqIfPresent(BpmOAWorkTaskDO::getReceiverUserId, reqVO.getUserId())
                .likeIfPresent(BpmOAWorkTaskDO::getTaskName, reqVO.getTaskName())
                .eqIfPresent(BpmOAWorkTaskDO::getWorkTaskStatus, reqVO.getWorkTaskStatus())
                .betweenIfPresent(BpmOAWorkTaskDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BpmOAWorkTaskDO::getFromUserId, userId)
                .orderByDesc(BpmOAWorkTaskDO::getId));
    }

    default PageResult<BpmOAWorkTaskDO> selectMyPage(Long userId, BpmOAWorkTaskPageReqVO reqVO) {

        return selectPage(reqVO, new LambdaQueryWrapperX<BpmOAWorkTaskDO>()
                .eqIfPresent(BpmOAWorkTaskDO::getFromUserId, reqVO.getFromUserId())
                .likeIfPresent(BpmOAWorkTaskDO::getTaskName, reqVO.getTaskName())
                .eqIfPresent(BpmOAWorkTaskDO::getWorkTaskStatus, reqVO.getWorkTaskStatus())
                .betweenIfPresent(BpmOAWorkTaskDO::getCreateTime, reqVO.getCreateTime())
                .eq(BpmOAWorkTaskDO::getReceiverUserId, userId)
                .orderByDesc(BpmOAWorkTaskDO::getId));
    }
}
