package com.hz.pm.api.meta.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.pm.api.meta.assembler.MetaDictionaryAssembler;
import com.hz.pm.api.meta.mapper.MetaDictionaryMapper;
import com.hz.pm.api.meta.model.dto.DictionaryDTO;
import com.hz.pm.api.meta.model.entity.MetaDictionary;
import com.hz.pm.api.meta.service.IMetaDictionaryService;
import com.ningdatech.basic.util.CollUtils;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 字典服务实现类
 * </p>
 *
 * @author Liuxinxin
 * @since 2023-02-22
 */
@Service
public class MetaDictionaryServiceImpl extends ServiceImpl<MetaDictionaryMapper, MetaDictionary> implements IMetaDictionaryService {

    @Override
    public List<DictionaryDTO> queryAll() {
        List<MetaDictionary> dicts = this.lambdaQuery()
                .ne(MetaDictionary::getId, -1)
                .list();
        return CollUtils.convert(dicts, MetaDictionaryAssembler::toDictionaryDTO);
    }

    @Override
    public List<DictionaryDTO> queryByDictType(String dictType) {
        List<MetaDictionary> dicts = this.lambdaQuery()
                .ne(MetaDictionary::getId, -1)
                .eq(MetaDictionary::getDictionaryType, dictType)
                .list();
        return CollUtils.convert(dicts, MetaDictionaryAssembler::toDictionaryDTO);
    }

    @Override
    public List<DictionaryDTO> queryByDictTypes(Collection<String> dictTypes) {
        List<MetaDictionary> dicts = this.lambdaQuery()
                .ne(MetaDictionary::getId, -1)
                .in(MetaDictionary::getDictionaryType, dictTypes)
                .list();
        return CollUtils.convert(dicts, MetaDictionaryAssembler::toDictionaryDTO);
    }

}
