|
@@ -11,8 +11,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -60,17 +61,17 @@ public class DictServiceImpl implements DictService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Dict> queryByParentId(Integer parentId) {
|
|
|
+ public Map<String, Dict> queryByParentId(Integer parentId) {
|
|
|
//存放节点数据
|
|
|
- List<Dict> dictAll = new ArrayList<>();
|
|
|
+ Map<String, Dict> map = new HashMap<>();
|
|
|
//根据父节点获取子节点对象
|
|
|
List<Dict> dictSon = dictDao.queryByParentId(parentId);
|
|
|
//判断子节点是否为其他节点的父节点
|
|
|
- for (Dict d : dictSon){
|
|
|
+ for (Dict d:dictSon){
|
|
|
d.setChildren(queryByParentId(d.getId()));
|
|
|
- dictAll.add(d);
|
|
|
+ map.put(d.getDictKey(),d);
|
|
|
}
|
|
|
- return dictAll;
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -78,6 +79,9 @@ public class DictServiceImpl implements DictService {
|
|
|
if (Blank.isEmpty(dict.getParentId(),dict.getDictKey(),dict.getDictValue(),dict.getSortNum())){
|
|
|
return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "父id,字典key,字典值以及序号不能为空");
|
|
|
}
|
|
|
+ if (Blank.isNotEmpty(dictDao.queryByDictKeyIsExist(dict.getDictKey()))){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "字典key已存在");
|
|
|
+ }
|
|
|
dictDao.addDict(dict);
|
|
|
return Result.ok("新增成功");
|
|
|
}
|
|
@@ -92,6 +96,10 @@ public class DictServiceImpl implements DictService {
|
|
|
if (dictShow==null){
|
|
|
return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "修改失败");
|
|
|
}
|
|
|
+ //判断key是否重复
|
|
|
+ if (Blank.isNotEmpty(dictDao.queryByDictKeyIsExist(dict.getDictKey()))){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "key已存在,修改失败");
|
|
|
+ }
|
|
|
if (dictDao.updataById(dict)<=0){
|
|
|
throw new ClassCastException("修改失败");
|
|
|
}
|
|
@@ -106,4 +114,16 @@ public class DictServiceImpl implements DictService {
|
|
|
Integer integer = dictDao.deleteByid(ids);
|
|
|
return Result.ok(integer);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> queryByDictKey(List<String> dictKeys) {
|
|
|
+ //存储数据
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<Dict> dicts = dictDao.queryByDictKey(dictKeys);
|
|
|
+ for (Dict d:dicts){
|
|
|
+ d.setChildren(queryByParentId(d.getId()));
|
|
|
+ map.put(d.getDictKey(),d);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|