|
|
@@ -1,16 +1,27 @@
|
|
|
package com.xunmei.system.controller;
|
|
|
|
|
|
|
|
|
+import com.xunmei.common.core.domain.device.domain.SysMultiLayerDictionary;
|
|
|
import com.xunmei.common.core.domain.device.vo.DictionaryTreeVo;
|
|
|
+import com.xunmei.common.core.web.controller.BaseController;
|
|
|
import com.xunmei.common.core.web.domain.AjaxResult;
|
|
|
+import com.xunmei.common.log.annotation.Log;
|
|
|
+import com.xunmei.common.log.enums.BusinessType;
|
|
|
+import com.xunmei.common.security.annotation.RequiresPermissions;
|
|
|
+import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
+import com.xunmei.system.api.domain.SysDictData;
|
|
|
import com.xunmei.system.service.ISysMultiLayerDictionaryService;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.BiConsumer;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -24,7 +35,7 @@ import java.util.List;
|
|
|
@RequestMapping("/dictionary")
|
|
|
public class SysMultiLayerDictionaryController {
|
|
|
|
|
|
- @Resource
|
|
|
+ @Autowired
|
|
|
private ISysMultiLayerDictionaryService sysMultiLayerDictionaryService;
|
|
|
|
|
|
@GetMapping("/list")
|
|
|
@@ -33,6 +44,60 @@ public class SysMultiLayerDictionaryController {
|
|
|
return AjaxResult.success(list);
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/tree/list")
|
|
|
+ private AjaxResult getDictionaryTreeList(){
|
|
|
+ final List<DictionaryTreeVo> list = sysMultiLayerDictionaryService.getDictionaryTree();
|
|
|
+ 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();
|
|
|
+ root.setName(childrenList.get(0).getTypeName());
|
|
|
+ root.setChildren(childrenList);
|
|
|
+ root.setCode(key);
|
|
|
+ result.add(root);
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增字典类型
|
|
|
+ */
|
|
|
+
|
|
|
+// @Log(title = "层级字典数据", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping
|
|
|
+ public AjaxResult add(@Validated @RequestBody SysMultiLayerDictionary dict) {
|
|
|
+ dict.setCreateTime(LocalDateTime.now());
|
|
|
+ final SysMultiLayerDictionary parentDict = sysMultiLayerDictionaryService.getById(dict.getParentId());
|
|
|
+ if(parentDict!=null)
|
|
|
+ {
|
|
|
+ dict.setType(parentDict.getType());
|
|
|
+ dict.setTypeName(parentDict.getTypeName());
|
|
|
+ dict.setLevel(parentDict.getLevel()+1);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ dict.setParentId(-1L);
|
|
|
+ dict.setLevel(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success(sysMultiLayerDictionaryService.save(dict));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改保存字典类型
|
|
|
+ */
|
|
|
+
|
|
|
+// @Log(title = "层级字典数据", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping
|
|
|
+ public AjaxResult edit(@Validated @RequestBody SysMultiLayerDictionary dict) {
|
|
|
+ dict.setModifiedName(SecurityUtils.getUsername());
|
|
|
+ dict.setUpdateTime(LocalDateTime.now());
|
|
|
+ return AjaxResult.success(sysMultiLayerDictionaryService.updateById(dict));
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping("/getDictTreeByParentId")
|
|
|
private AjaxResult getDictTreeByParentId(Long parentId){
|
|
|
final List<DictionaryTreeVo> list = sysMultiLayerDictionaryService.getDictTreeByParentId(parentId);
|