package xiaoqu.home.open.service.db2.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import xiaoqu.home.open.model.db2.WebpageAuthority;
import xiaoqu.home.open.mapper.db2.WebpageAuthorityMapper;
import xiaoqu.home.open.service.db2.WebpageAuthorityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 权限组页面 服务实现类
 * </p>
 *
 * @author mk
 * @since 2022-03-21
 */
@Service
public class WebpageAuthorityServiceImpl extends ServiceImpl<WebpageAuthorityMapper, WebpageAuthority> implements WebpageAuthorityService {
    /**
     * @param authorityId   必选
     * @param checkStatus 0否1是，可选
     * @return
     */
    public Boolean checkAuthorityByAuthorityId(Long authorityId, Integer checkStatus) {

        QueryWrapper<WebpageAuthority> wrapper = new QueryWrapper<WebpageAuthority>();
        wrapper.eq("authority_id", authorityId);

        if(checkStatus!=null){
            wrapper.eq("check_status", checkStatus);
        }
        wrapper.eq("soft_delete", 0);
        int count = this.count(wrapper);
        if (count > 0) {
            return true;
        } else {
            return false;
        }
    }


    /**
     *
     * @param authorityId   必选
     * @param checkStatus 0否1是，可选
     * @return
     */
    public List<WebpageAuthority> getWebAuthorityByUserIdAndParentId(Long authorityId, Integer checkStatus) {

        QueryWrapper<WebpageAuthority> wrapper = new QueryWrapper<WebpageAuthority>();
        wrapper.eq("authority_id", authorityId);

        if(checkStatus!=null){
            wrapper.eq("check_status", checkStatus);
        }
        wrapper.eq("soft_delete", 0);
        List<WebpageAuthority> list = this.list(wrapper);
        return list;

    }
}
