package com.ruoyi.hywz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.hywz.entity.AdsMatHyxtInvoiceUserApplyPermissionD;
import com.ruoyi.hywz.entity.vo.UserPermissionVo;
import com.ruoyi.hywz.mapper.AdsMatHyxtInvoiceUserApplyPermissionDMapper;
import com.ruoyi.hywz.service.IAdsMatHyxtInvoiceUserApplyPermissionDService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户申请权限表 服务实现类
 * </p>
 *
 * @author mybatisplus-generator
 * @date 2024-04-08 14:25:45
 */
@Service
public class AdsMatHyxtInvoiceUserApplyPermissionDServiceImpl extends ServiceImpl<AdsMatHyxtInvoiceUserApplyPermissionDMapper, AdsMatHyxtInvoiceUserApplyPermissionD> implements IAdsMatHyxtInvoiceUserApplyPermissionDService {

    @Resource
    private AdsMatHyxtInvoiceUserApplyPermissionDMapper adsMatHyxtInvoiceUserApplyPermissionDMapper;

    @Override
    public IPage<UserPermissionVo> queryPage(Page page, QueryWrapper<UserPermissionVo> queryWrapper) {
        return adsMatHyxtInvoiceUserApplyPermissionDMapper.queryPage(page, queryWrapper);
    }

    @Override
    public Integer checkHaveCommitPermission(Long userId) {
        LambdaQueryWrapper<AdsMatHyxtInvoiceUserApplyPermissionD> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(AdsMatHyxtInvoiceUserApplyPermissionD::getUserId, userId);
        queryWrapper.eq(AdsMatHyxtInvoiceUserApplyPermissionD::getApplyPermission, 1);
        Long count = baseMapper.selectCount(queryWrapper);
        return count > 0 ? 1 : 0;
    }
}
