package com.njzscloud.supervisory.user.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njzscloud.supervisory.role.pojo.RoleDetailResult;
import com.njzscloud.supervisory.user.pojo.SysUserRoleEntity;
import com.njzscloud.supervisory.user.mapper.SysUserRoleMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>用户-角色关系表</p>
 */
@Slf4j
@Service
public class SysUserRoleService extends ServiceImpl<SysUserRoleMapper, SysUserRoleEntity> implements IService<SysUserRoleEntity> {

    /**
     * 新增
     *
     * @param sysUserRoleEntity 数据
     * @return boolean 结果; true-->成功、false-->失败
     */

    public boolean add(SysUserRoleEntity sysUserRoleEntity) {
        return this.save(sysUserRoleEntity);
    }

    /**
     * 修改
     *
     * @param sysUserRoleEntity 数据
     * @return boolean 结果; true-->成功、false-->失败
     */

    public boolean modify(SysUserRoleEntity sysUserRoleEntity) {
        return this.updateById(sysUserRoleEntity);
    }

    /**
     * 删除
     *
     * @param id Id
     * @return boolean 结果; true-->成功、false-->失败
     */

    public boolean del(Long id) {
        return this.removeById(id);
    }

    /**
     * 详情
     *
     * @param id Id
     * @return SysUserRoleEntity 结果
     */

    public SysUserRoleEntity detail(Long id) {
        return this.getById(id);
    }


    public void delByUserIds(List<Long> userIdList) {
        this.remove(Wrappers.<SysUserRoleEntity>lambdaQuery().in(SysUserRoleEntity::getUserId, userIdList));
    }


    public List<RoleDetailResult> listRole(Long userId) {
        return baseMapper.listRole(Wrappers.<SysUserRoleEntity>query().eq("a.user_id", userId));
    }


}
