|
|
@@ -14,6 +14,11 @@ import com.xunmei.system.service.ISysMultiLayerDictionaryService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
@@ -25,7 +30,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 前端控制器
|
|
|
+ * 前端控制器
|
|
|
* </p>
|
|
|
*
|
|
|
* @author jingYuanChao
|
|
|
@@ -38,21 +43,22 @@ public class SysMultiLayerDictionaryController {
|
|
|
@Autowired
|
|
|
private ISysMultiLayerDictionaryService sysMultiLayerDictionaryService;
|
|
|
|
|
|
- @GetMapping("/list")
|
|
|
- private AjaxResult getDictionaryList(){
|
|
|
+ @ApiOperation("字典树")
|
|
|
+ @GetMapping("/tree")
|
|
|
+ private AjaxResult getDicTree() {
|
|
|
final List<DictionaryTreeVo> list = sysMultiLayerDictionaryService.getDictionaryTree();
|
|
|
return AjaxResult.success(list);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/tree/list")
|
|
|
- private AjaxResult getDictionaryTreeList(){
|
|
|
+ private AjaxResult getDictionaryTreeList() {
|
|
|
final List<DictionaryTreeVo> list = sysMultiLayerDictionaryService.getDictionaryTree();
|
|
|
- List<DictionaryTreeVo> result =new ArrayList<>();
|
|
|
+ List<DictionaryTreeVo> result = new ArrayList<>();
|
|
|
final Map<String, List<DictionaryTreeVo>> mapCollect = list.stream().collect(Collectors.groupingBy(DictionaryTreeVo::getType));
|
|
|
for (Map.Entry<String, List<DictionaryTreeVo>> entry : mapCollect.entrySet()) {
|
|
|
String key = entry.getKey();
|
|
|
List<DictionaryTreeVo> childrenList = entry.getValue();
|
|
|
- DictionaryTreeVo root=new DictionaryTreeVo();
|
|
|
+ DictionaryTreeVo root = new DictionaryTreeVo();
|
|
|
root.setName(childrenList.get(0).getTypeName());
|
|
|
root.setChildren(childrenList);
|
|
|
root.setCode(key);
|
|
|
@@ -72,13 +78,11 @@ public class SysMultiLayerDictionaryController {
|
|
|
public AjaxResult add(@Validated @RequestBody SysMultiLayerDictionary dict) {
|
|
|
dict.setCreateTime(LocalDateTime.now());
|
|
|
final SysMultiLayerDictionary parentDict = sysMultiLayerDictionaryService.getById(dict.getParentId());
|
|
|
- if(parentDict!=null)
|
|
|
- {
|
|
|
+ if (parentDict != null) {
|
|
|
dict.setType(parentDict.getType());
|
|
|
dict.setTypeName(parentDict.getTypeName());
|
|
|
- dict.setLevel(parentDict.getLevel()+1);
|
|
|
- }
|
|
|
- else {
|
|
|
+ dict.setLevel(parentDict.getLevel() + 1);
|
|
|
+ } else {
|
|
|
dict.setParentId(-1L);
|
|
|
dict.setLevel(1);
|
|
|
}
|
|
|
@@ -98,8 +102,18 @@ public class SysMultiLayerDictionaryController {
|
|
|
return AjaxResult.success(sysMultiLayerDictionaryService.updateById(dict));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @ApiOperation("字典数组,平铺结构")
|
|
|
+ @GetMapping("/list")
|
|
|
+ private AjaxResult getDictList() {
|
|
|
+ final List<DictionaryTreeVo> list = sysMultiLayerDictionaryService.selectList();
|
|
|
+ return AjaxResult.success(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("根据父节点获取字典数据")
|
|
|
@GetMapping("/getDictTreeByParentId")
|
|
|
- private AjaxResult getDictTreeByParentId(Long parentId){
|
|
|
+
|
|
|
+ private AjaxResult getDictTreeByParentId(Long parentId) {
|
|
|
final List<DictionaryTreeVo> list = sysMultiLayerDictionaryService.getDictTreeByParentId(parentId);
|
|
|
return AjaxResult.success(list);
|
|
|
}
|