package com.hz.pm.api.leave.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.pm.api.leave.entity.domain.ExpertLeave;
import com.hz.pm.api.leave.entity.enumeration.LeaveStatusEnum;
import com.hz.pm.api.leave.mapper.ExpertLeaveMapper;
import com.hz.pm.api.leave.service.IExpertLeaveService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author WendyYang
 * @since 2022-08-11
 */
@Service
public class ExpertLeaveServiceImpl extends ServiceImpl<ExpertLeaveMapper, ExpertLeave> implements IExpertLeaveService {

    @Override
    public ExpertLeave getByAuditId(Long auditId) {
        if (auditId == 0) {
            return null;
        }
        LambdaQueryWrapper<ExpertLeave> query = Wrappers.lambdaQuery(ExpertLeave.class)
                .eq(ExpertLeave::getAuditId, auditId);
        return getOne(query);
    }

    @Override
    public boolean existsToBeReviewed(Long expertId) {
        LambdaQueryWrapper<ExpertLeave> query = Wrappers.lambdaQuery(ExpertLeave.class)
                .eq(ExpertLeave::getLeaveUserId, expertId)
                .eq(ExpertLeave::getStatus, LeaveStatusEnum.APPLYING.getCode());
        return baseMapper.exists(query);
    }

}
