package com.service;

import com.model.Dict;

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

public class DictService {

    public static final DictService me = new DictService();

    Dict dao = new Dict().dao();

    public List<Dict> list(Integer type){
        String sql ="SELECT * FROM t_dict where type=?";
        return  dao.find(sql,type);
    }

    public Map<String,Integer> dictnametokey(Integer type){
        String sql ="SELECT * FROM t_dict where type=?";
        List<Dict> dictList = dao.find(sql,type);
        Map<String,Integer> map = new HashMap<String, Integer>();
        for (Dict dict :dictList){
            map.put(dict.getName(),dict.getId());
        }
        return  map;
    }

    public Map<String,Integer> dictmap(){
        String sql ="SELECT * FROM t_dict";
        List<Dict> dictList = dao.find(sql);
        Map<String,Integer> map = new HashMap<String, Integer>();
        for (Dict dict :dictList){
            map.put(dict.getName(),dict.getId());
        }
        return  map;
    }
}
