package com.storlead.system.service.impl;

import com.storlead.framework.mybatis.service.impl.MyBaseServiceImpl;
import com.storlead.system.pojo.entity.DeptRoleEntity;
import com.storlead.system.mapper.DeptRoleMapper;
import com.storlead.system.pojo.entity.RoleMenuEntity;
import com.storlead.system.service.DeptRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.crypto.Mac;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 部门角色权限 服务实现类
 * </p>
 *
 * @author chenkq
 * @since 2024-04-02
 */
@Service
public class DeptRoleServiceImpl extends MyBaseServiceImpl<DeptRoleMapper, DeptRoleEntity> implements DeptRoleService {

    @Override
    public void updateDeptRole(Long roleId, Set<Long> deptIds) {
        if (Objects.nonNull(roleId) && !CollectionUtils.isEmpty(deptIds)) {
            this.removeByMap(Map.of("role_id", roleId));
            Set<DeptRoleEntity> collect = deptIds.stream().map(deptId -> new DeptRoleEntity(roleId, deptId)).collect(Collectors.toSet());
            this.saveBatch(collect);
        }
    }
}
