#
luxiaotao1123
2021-03-24 454e10394b27f49b21e808bb2a5f30ffc91c2240
src/main/java/zy/cloud/wms/manager/controller/TagController.java
@@ -11,11 +11,14 @@
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.io.IOException;
import java.util.*;
@RestController
@@ -23,6 +26,8 @@
    @Autowired
    private TagService tagService;
    @Autowired
    private TreeUtils treeUtils;
    @RequestMapping(value = "/tag/{id}/auth")
    @ManagerAuth
@@ -67,6 +72,8 @@
                tag.setParentName(parent.getName());
                tag.setLevel(parent.getLevel() + 1);
            }
        } else {
            tag.setParentId(0L);
        }
        // path
        NodeUtils nodeUtils = new NodeUtils();
@@ -89,6 +96,23 @@
        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();
    }
@@ -117,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);
@@ -139,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);
    }
}