From 289140c6c2650a10baaa988d381c7d6668788b43 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 31 三月 2021 16:04:55 +0800
Subject: [PATCH] #
---
src/main/java/zy/cloud/wms/manager/controller/TagController.java | 79 ++++++++++++++++++++++++++++++++-------
1 files changed, 64 insertions(+), 15 deletions(-)
diff --git a/src/main/java/zy/cloud/wms/manager/controller/TagController.java b/src/main/java/zy/cloud/wms/manager/controller/TagController.java
index 5ace47d..6ca7410 100644
--- a/src/main/java/zy/cloud/wms/manager/controller/TagController.java
+++ b/src/main/java/zy/cloud/wms/manager/controller/TagController.java
@@ -1,6 +1,5 @@
package zy.cloud.wms.manager.controller;
-import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
@@ -12,20 +11,23 @@
import com.core.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+import zy.cloud.wms.common.utils.ListUtils;
+import zy.cloud.wms.common.utils.TreeUtils;
import zy.cloud.wms.common.web.BaseController;
import zy.cloud.wms.manager.entity.Tag;
import zy.cloud.wms.manager.service.TagService;
+import zy.cloud.wms.manager.utils.NodeUtils;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.io.IOException;
+import java.util.*;
@RestController
public class TagController extends BaseController {
@Autowired
private TagService tagService;
+ @Autowired
+ private TreeUtils treeUtils;
@RequestMapping(value = "/tag/{id}/auth")
@ManagerAuth
@@ -44,7 +46,7 @@
excludeTrash(param);
convert(param, wrapper);
if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
- return R.ok(tagService.selectPage(new Page<>(curr, limit), wrapper));
+ return R.parse("0-鎿嶄綔鎴愬姛").add(tagService.selectList(wrapper));
}
private void convert(Map<String, Object> map, EntityWrapper wrapper){
@@ -63,6 +65,27 @@
@RequestMapping(value = "/tag/add/auth")
@ManagerAuth
public R add(Tag tag) {
+ tag.setLevel(1);
+ if (tag.getParentId() != null && tag.getParentId() > 0) {
+ Tag parent = tagService.selectById(tag.getParentId());
+ if (parent != null) {
+ tag.setParentName(parent.getName());
+ tag.setLevel(parent.getLevel() + 1);
+ }
+ } else {
+ tag.setParentId(0L);
+ }
+ // path
+ NodeUtils nodeUtils = new NodeUtils();
+ nodeUtils.executePath(tag);
+ tag.setPath(nodeUtils.path.toString());
+ tag.setPathName(nodeUtils.pathName.toString());
+
+ tag.setCreateBy(getUserId());
+ tag.setCreateTime(new Date());
+ tag.setUpdateBy(getUserId());
+ tag.setUpdateTime(new Date());
+ tag.setStatus(1);
tagService.insert(tag);
return R.ok();
}
@@ -73,19 +96,32 @@
if (Cools.isEmpty(tag) || null==tag.getId()){
return R.error();
}
+ if (tag.getParentId() != null && tag.getParentId() > 0) {
+ if (tag.getParentId().equals(tag.getId())) {
+ return R.error("鏁版嵁閿欒");
+ }
+ Tag parent = tagService.selectById(tag.getParentId());
+ if (parent != null) {
+ tag.setParentName(parent.getName());
+ tag.setLevel(parent.getLevel() + 1);
+ }
+ }
+ // path
+ NodeUtils nodeUtils = new NodeUtils();
+ nodeUtils.executePath(tag);
+ tag.setPath(nodeUtils.path.toString());
+ tag.setPathName(nodeUtils.pathName.toString());
+ tag.setUpdateBy(getUserId());
+ tag.setUpdateTime(new Date());
tagService.updateById(tag);
return R.ok();
}
@RequestMapping(value = "/tag/delete/auth")
@ManagerAuth
- public R delete(@RequestParam String param){
- List<Tag> list = JSONArray.parseArray(param, Tag.class);
- if (Cools.isEmpty(list)){
- return R.error();
- }
- for (Tag entity : list){
- tagService.delete(new EntityWrapper<>(entity));
+ public R delete(@RequestParam(value="ids[]") Long[] ids){
+ for (Long id : ids){
+ tagService.deleteById(id);
}
return R.ok();
}
@@ -105,13 +141,13 @@
@ManagerAuth
public R query(String condition) {
EntityWrapper<Tag> wrapper = new EntityWrapper<>();
- wrapper.like("id", condition);
+ wrapper.like("uuid", condition).or().like("name", condition);
Page<Tag> page = tagService.selectPage(new Page<>(0, 10), wrapper);
List<Map<String, Object>> result = new ArrayList<>();
for (Tag tag : page.getRecords()){
Map<String, Object> map = new HashMap<>();
map.put("id", tag.getId());
- map.put("value", tag.getId());
+ map.put("value", tag.getName());
result.add(map);
}
return R.ok(result);
@@ -127,4 +163,17 @@
return R.ok();
}
+ @PostMapping(value = "/tag/tree/auth")
+ @ManagerAuth
+ public R tree(@RequestParam(required = false, defaultValue = "") String condition) throws IOException, ClassNotFoundException {
+ ArrayList<Map> tree = treeUtils.getTree(String.valueOf(getOriginTag().getId()));
+ // 娣辨嫹璐�
+ List<Map> result = ListUtils.deepCopy(tree);
+ if (!Cools.isEmpty(condition)) {
+ treeUtils.remove(condition, result);
+ treeUtils.remove(condition, result);
+ }
+ return R.ok(result);
+ }
+
}
--
Gitblit v1.9.1