package com.hdkj.lt.core.sys.service.impl;

import com.hdkj.lt.core.sys.dao.SysDictMapper;
import com.hdkj.lt.core.sys.model.po.DicSingle;
import com.hdkj.lt.core.sys.model.vo.DicLevelTreeVo;
import com.hdkj.lt.core.sys.model.vo.DicVo;
import com.hdkj.lt.core.sys.model.vo.DictVo;
import com.hdkj.lt.core.sys.service.ISysDicRefService;
import com.ruoyi.system.api.domain.SysDictData;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * @author rj
 * @date 2026/1/30 9:13
 * @description
 */
@Service
@RequiredArgsConstructor
public class SysDicRefServiceImpl implements ISysDicRefService {

    private final SysDictMapper sysDictMapper;


    //todo: 需要重写
    @Override
    public List<DicVo> getDicListByType(String typeName) {
        return new ArrayList<>();
    }

    @Override
    public List<DictVo> getDictVosByTypeNames(List<String> typeNames) {
        List<SysDictData> listByTypeName = sysDictMapper.getListByTypeName(typeNames);
        List<DicSingle> dicSingles = new ArrayList<>();
        listByTypeName.forEach(i -> {
            DicSingle dicSingle = new DicSingle();
            dicSingle.setTypeName(i.getDictType());
            dicSingle.setValue(i.getDictValue());
            dicSingle.setLabel(i.getDictLabel());
            dicSingle.setSort(i.getDictSort().intValue());
            dicSingles.add(dicSingle);
        });
        Map<String, List<DicSingle>> collect = dicSingles.stream().collect(Collectors.groupingBy(DicSingle::getTypeName));
        List<DictVo> dictVoList = new ArrayList<>();
        for (String key : collect.keySet()) {
            DictVo dictVo = new DictVo();
            dictVo.setTypeName(key);
            dictVo.setSingleList(collect.get(key));
            dictVoList.add(dictVo);
        }
        return dictVoList;
    }

    @Override
    public List<DicLevelTreeVo> getLevelDictByTypeName(String typeName) {
        return new ArrayList<>();
    }
}
