package com.backendsys.modules.system.service.impl;

import com.backendsys.modules.system.dao.SysDictionaryDao;
import com.backendsys.modules.system.entity.SysDictionary;
import com.backendsys.modules.system.entity.SysDictionaryKeys;
import com.backendsys.modules.system.service.SysDictionaryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class SysDictionaryServiceImpl implements SysDictionaryService {

    @Autowired
    private SysDictionaryDao sysDictionaryDao;

    @Override
    public Map<String, List<SysDictionaryKeys>> selectDictionaryList() {

        List<SysDictionary> sysDictionaryList = sysDictionaryDao.selectDictionaryList();
        // 对返回值进行分组，格式化
        Map<String, List<SysDictionaryKeys>> result = sysDictionaryList.stream().collect(Collectors.groupingBy(dictionary -> dictionary.getCategory_value(),
            Collectors.mapping(dictionary -> {
                SysDictionaryKeys sysDictionaryKeys = new SysDictionaryKeys();
                sysDictionaryKeys.setKey_value(dictionary.getKey_value());
                sysDictionaryKeys.setKey_translation(dictionary.getKey_translation());
                sysDictionaryKeys.setKey_translation_en(dictionary.getKey_translation_en());
                return sysDictionaryKeys;
            }, Collectors.toList())));

        return result;
    }

}
