package com.chushang.system.remote;

import cn.hutool.core.collection.CollectionUtil;
import com.chushang.security.annotation.InnerAuth;
import com.chushang.security.entity.po.SysDept;
import com.chushang.system.feign.RemoteDeptService;
import com.chushang.system.service.ISysDeptService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @auther: zhao
 * @date: 2024/7/3 17:52
 */
@RestController
@RequestMapping(value = "/dept/remote")
public class RemoteDeptController implements RemoteDeptService {

    @Resource
    ISysDeptService deptService;

    @Override
    @GetMapping(value = "/getDeptNameByIds")
    @InnerAuth
    public Map<Long, String> getDeptNameByIds(@RequestParam Set<Long> deptIds, String source) {
        if (CollectionUtil.isEmpty(deptIds)) return Map.of();
        List<SysDept> sysDepts = deptService.listByIds(deptIds);
        if (CollectionUtil.isNotEmpty(sysDepts)){
            return sysDepts.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
        }
        return Map.of();
    }
}
