package com.ssm.manage.dao.impl;

import com.github.pagehelper.PageInfo;
import com.ssm.core.impl.BaseDaoImpl;
import com.ssm.manage.dao.RlRoleStaffDao;
import com.ssm.manage.dao.SsmSysMenuPowerDao;
import com.ssm.manage.dao.SsmSysMuenRoleDao;
import com.ssm.manage.entity.*;
import com.ssm.manage.mapper.SysMuenRoleMapper;
import com.ssm.manage.mapper.SysPowerMapper;
import com.ssm.manage.query.SysMuenRoleRequest;
import com.ssm.manage.query.SysRoleStoreRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


@Component
@Slf4j
public class SsmSysMuenRoleDaoImpl  extends BaseDaoImpl<SysMuenRole> implements SsmSysMuenRoleDao {

    @Autowired
    SysMuenRoleMapper mapper;

    @Autowired
    RlRoleStaffDao rlRoleStaffDao;

    @Override
    public SysMuenRoleMapper getMapper() {
        return mapper;
    }

    @Override
    public PageInfo<SysMuenRole> selectPage(SysMuenRole sysStoreRole) {
        Example example = new Example(SysMuenRole.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("roleId",sysStoreRole.getRoleId());
        List<SysMuenRole> list =  selectByExample(example);
        PageInfo<SysMuenRole> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


    @Override
    public boolean checkRole(SysMuenRole sysStoreRole) {
        Example example = new Example(SysMuenRole.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("roleId",sysStoreRole.getRoleId());
        criteria.andEqualTo("powerId","4001003");
        List<SysMuenRole> list =  selectByExample(example);
        if(list.size()==1){
            return true;
        }else{
            return false;
        }

    }

    @Override
    public int saveAll(List<SysMuenRole> sysMuenRoles) {
        return mapper.saveAll(sysMuenRoles);
    }
}
