package com.chushang.system.remote;

import cn.hutool.core.collection.CollectionUtil;
import com.chushang.common.core.web.Result;
import com.chushang.common.dict.feign.RemoteDictDataService;
import com.chushang.security.annotation.InnerAuth;
import com.chushang.system.entity.po.SysDictData;
import com.chushang.system.service.SysDictDataService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @auther: zhao
 * @date: 2024/6/7 14:39
 */
@RestController
@RequestMapping(value = "/dict/data/remote")
public class RemoteDictDataController implements RemoteDictDataService {
    @Resource
    SysDictDataService dictDataService;
    /**
     * 获取字典数据值
     */
    @GetMapping(value = "/type/{dictType}")
    @InnerAuth
    public Result<Map<String, String>> getInfo(@PathVariable String dictType, String source)
    {
        List<SysDictData> sysDictData = dictDataService.selectDictDataByType(dictType);
        Map<String, String> resultMap = new HashMap<>();
        if (CollectionUtil.isNotEmpty(sysDictData)){
            resultMap = sysDictData.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel, (o,n)->n));
        }
        return Result.ok(resultMap);
    }
}
