| package com.xzx.gc.role.service; | 
|   | 
|   | 
| import com.github.pagehelper.PageHelper; | 
| import com.github.pagehelper.PageInfo; | 
| import com.xzx.gc.entity.CoreDict; | 
| import com.xzx.gc.model.query.CoreDictQuery; | 
| import com.xzx.gc.role.mapper.CoreDictMapper; | 
| import com.xzx.gc.role.model.CoreDictQueryModel; | 
| import com.xzx.gc.util.enums.DelFlagEnum; | 
| import org.slf4j.Logger; | 
| import org.slf4j.LoggerFactory; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.cache.annotation.Cacheable; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.HashMap; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * 描述: 字典 service,包含常规字典和级联字典的操作。 | 
|  * @author : xiandafu | 
|  */ | 
| @Service | 
| @Transactional | 
| public class CoreDictService{ | 
|   | 
|     private static final Logger LOGGER = LoggerFactory.getLogger(CoreDictService.class); | 
|   | 
|     @Autowired | 
|     private CoreDictMapper dictMapper; | 
|   | 
|     @Autowired | 
|     CorePlatformService platformService; | 
|      | 
|     @Autowired  | 
|     CoreDictService self ; | 
|     private String type; | 
|   | 
|   | 
|     /** | 
|      * 根据类型获取字典集合 | 
|      * @param type 字典类型, | 
|      * @return List | 
|      */ | 
|     //@Cacheable(value = CorePlatformService.DICT_CACHE_TYPE) | 
|     public List<CoreDict> findAllByType(String type) { | 
|         return dictMapper.findAllList(type); | 
|     } | 
|      | 
|     /** | 
|      * 级联字典查询,必须提供一个字典类型 | 
|      * @param type | 
|      * @param value | 
|      * @return | 
|      */ | 
|     //@Cacheable(value = CorePlatformService.DICT_CACHE_CHILDREN) | 
|     public List<CoreDict> findAllByGroup(String type,String value) { | 
|        List<CoreDict> list = self.findAllByType(type); | 
|        return  _search(list,value); | 
|          | 
|     } | 
|      | 
|     /** | 
|      * 级联字段下一级的字段列表 | 
|      * @param id | 
|      * @return | 
|      */ | 
|     //@Cacheable(value = CorePlatformService.DICT_CACHE_CHILDREN) | 
|     public List<CoreDict> findChildByParent(Long id) { | 
|         return dictMapper.findChildByParent(id); | 
|     } | 
|   | 
|     //@Cacheable(value = CorePlatformService.DICT_CACHE_VALUE) | 
|     public CoreDict findCoreDict(String type,String value) { | 
|        List<CoreDict> list = self.findAllByGroup(type, value); | 
|        if(list==null) { | 
|            return null; | 
|        } | 
|        for(CoreDict dict:list) { | 
|            if(dict.getValue().equals(value)) { | 
|                return dict; | 
|            } | 
|        } | 
|         | 
|         return null; | 
|     } | 
|      | 
|     /*通过名字反向查找数据字典,通常用于excel导入*/ | 
|     public Map<String,CoreDict> mapDictByName(String type){ | 
|         List<CoreDict> list = self.findAllByType(type); | 
|         Map<String,CoreDict> map = new HashMap<String,CoreDict>(); | 
|         for(CoreDict dict:list) { | 
|             map.put(dict.getName(), dict); | 
|         } | 
|         return  map; | 
|     } | 
|      | 
|     | 
|      | 
|    /*递归查找*/  | 
|     private List<CoreDict> _search(List<CoreDict> list,String value) { | 
|         for(CoreDict dict:list) { | 
|             if(dict.getValue().equals(value)) { | 
|                 return list; | 
|             }else { | 
|                 List<CoreDict> children = findChildByParent(dict.getId()); | 
|                 if(children.isEmpty()) { | 
|                     continue; | 
|                 }else { | 
|                     List<CoreDict> ret = _search(children,value); | 
|                     if(ret!=null) { | 
|                         return ret; | 
|                     } | 
|                 } | 
|                  | 
|             } | 
|         } | 
|         return null; | 
|     } | 
|   | 
|     | 
|     /** | 
|      * 查询字段类型列表 | 
|      * @return | 
|      */ | 
|     public List<Map<String, String>> findTypeList() { | 
|         return dictMapper.findTypeList(DelFlagEnum.NORMAL.getValue()); | 
|     } | 
|   | 
|     | 
|    public String findNameByType(String value){ | 
|        return dictMapper.findNameByType(value); | 
|    } | 
|   | 
|   | 
|     public PageInfo<CoreDict> queryByCondition(CoreDictQueryModel query){ | 
|         PageHelper.startPage(query.getPage(),query.getLimit()); | 
|         List<CoreDict> ret =  dictMapper.queryByCondition(query); | 
|         PageInfo info = new PageInfo(ret); | 
|         //queryListAfter(ret.getList()); | 
|         return info; | 
|     } | 
| } |