| | |
| | | import zy.cloud.wms.common.web.BaseController; |
| | | import zy.cloud.wms.manager.entity.Node; |
| | | import zy.cloud.wms.manager.service.NodeService; |
| | | 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.util.*; |
| | | |
| | | @RestController |
| | | public class NodeController extends BaseController { |
| | |
| | | @RequestMapping(value = "/node/add/auth") |
| | | @ManagerAuth |
| | | public R add(Node node) { |
| | | if (node.getType() != 1) { |
| | | Node parentNode = nodeService.selectById(node.getParentId()); |
| | | if (parentNode == null || parentNode.getStatus() == 0) { |
| | | return R.error(node.getType()==2?"所属仓库不存在":"所属库区不存在"); |
| | | } |
| | | node.setParentName(parentNode.getName()); |
| | | node.setLevel(parentNode.getLevel() + 1); |
| | | } |
| | | // path |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.executePath(node); |
| | | node.setPath(nodeUtils.path.toString()); |
| | | node.setNamePath(nodeUtils.pathName.toString()); |
| | | |
| | | node.setLevel(node.getType()); |
| | | node.setCreateBy(getUserId()); |
| | | node.setCreateTime(new Date()); |
| | | node.setUpdateBy(getUserId()); |
| | | node.setUpdateTime(new Date()); |
| | | node.setStatus(1); |
| | | nodeService.insert(node); |
| | | return R.ok(); |
| | | } |
| | |
| | | if (Cools.isEmpty(node) || null==node.getId()){ |
| | | return R.error(); |
| | | } |
| | | if (node.getType() != 1) { |
| | | Node parentNode = nodeService.selectById(node.getParentId()); |
| | | if (parentNode == null || parentNode.getStatus() == 0) { |
| | | return R.error(node.getType()==2?"所属仓库不存在":"所属库区不存在"); |
| | | } |
| | | node.setParentName(parentNode.getName()); |
| | | node.setLevel(parentNode.getLevel() + 1); |
| | | } |
| | | // path |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.executePath(node); |
| | | node.setPath(nodeUtils.path.toString()); |
| | | node.setNamePath(nodeUtils.pathName.toString()); |
| | | |
| | | node.setUpdateBy(getUserId()); |
| | | node.setUpdateTime(new Date()); |
| | | nodeService.updateById(node); |
| | | return R.ok(); |
| | | } |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping(value = "/parent/node/group") |
| | | public R getParentNodeGroup(@RequestParam(required = false) String condition, |
| | | @RequestParam Integer type) { |
| | | List<Node> nodes = nodeService.selectList(new EntityWrapper<Node>().eq("type", type).eq("status", 1)); |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (Node node : nodes) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("key", node.getId()); |
| | | map.put("val", node.getName()); |
| | | result.add(map); |
| | | } |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | } |