Commit 7eba48b8f41e175d4b890732723576b0f61fd1f5

Authored by yiming
1 parent 72bc4b39

库房维护2.0

ruoyi-service/src/main/java/com/ruoyi/service/controller/DeptNodeController.java 0 → 100644
  1 +package com.ruoyi.service.controller;
  2 +
  3 +import com.ruoyi.common.annotation.Log;
  4 +import com.ruoyi.common.core.controller.BaseController;
  5 +import com.ruoyi.common.core.domain.AjaxResult;
  6 +import com.ruoyi.common.enums.BusinessType;
  7 +import com.ruoyi.common.utils.StringUtils;
  8 +import com.ruoyi.common.utils.poi.ExcelUtil;
  9 +import com.ruoyi.service.domain.DepotNode;
  10 +import com.ruoyi.service.service.DepotNodeService;
  11 +import org.apache.commons.lang3.ArrayUtils;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.security.access.prepost.PreAuthorize;
  14 +import org.springframework.web.bind.annotation.*;
  15 +
  16 +import javax.servlet.http.HttpServletResponse;
  17 +import java.util.Iterator;
  18 +import java.util.List;
  19 +
  20 +/**
  21 + * 库房维护 控制层
  22 + *
  23 + * @author ym
  24 + * @date 2022-08-19
  25 + */
  26 +@RestController
  27 +@RequestMapping("/service/depotNode")
  28 +public class DeptNodeController extends BaseController
  29 +{
  30 + @Autowired
  31 + private DepotNodeService depotNodeService;
  32 +
  33 + /**
  34 + * 查询库房列表
  35 + */
  36 + @PreAuthorize("@ss.hasPermi('service:depotNode:list')")
  37 + @GetMapping("/list")
  38 + public AjaxResult list(DepotNode depotNode)
  39 + {
  40 + startPage();
  41 + List<DepotNode> list = depotNodeService.selectDepotNodeList(depotNode);
  42 + return AjaxResult.success(list);
  43 + }
  44 +
  45 + /**
  46 + * 导出库房列表
  47 + */
  48 + @PreAuthorize("@ss.hasPermi('service:depotNode:export')")
  49 + @Log(title = "库房", businessType = BusinessType.EXPORT)
  50 + @PostMapping("/export")
  51 + public void export(HttpServletResponse response, DepotNode serviceDept)
  52 + {
  53 + List<DepotNode> list = depotNodeService.selectDepotNodeList(serviceDept);
  54 + ExcelUtil<DepotNode> util = new ExcelUtil<DepotNode>(DepotNode.class);
  55 + util.exportExcel(response, list, "库房数据");
  56 + }
  57 +
  58 + /**
  59 + * 获取库房详细信息
  60 + */
  61 + @PreAuthorize("@ss.hasPermi('service:depotNode:query')")
  62 + @GetMapping(value = "/{id}")
  63 + public AjaxResult getInfo(@PathVariable("id") Long id)
  64 + {
  65 + DepotNode serviceDept=depotNodeService.selectDepotNodeById(id);
  66 + System.out.println(serviceDept);
  67 + return AjaxResult.success(depotNodeService.selectDepotNodeById(id));
  68 + }
  69 +
  70 + /**
  71 + * 新增库房
  72 + */
  73 + @PreAuthorize("@ss.hasPermi('service:depotNode:add')")
  74 + @Log(title = "库房", businessType = BusinessType.INSERT)
  75 + @PostMapping
  76 + public AjaxResult add(@RequestBody DepotNode serviceDept)
  77 + {
  78 + return toAjax(depotNodeService.insertDepotNode(serviceDept));
  79 + }
  80 +
  81 + /**
  82 + * 修改库房
  83 + */
  84 + @PreAuthorize("@ss.hasPermi('service:depotNode:edit')")
  85 + @Log(title = "库房", businessType = BusinessType.UPDATE)
  86 + @PutMapping
  87 + public AjaxResult edit(@RequestBody DepotNode serviceDept)
  88 + {
  89 + return toAjax(depotNodeService.updateDepotNode(serviceDept));
  90 + }
  91 +
  92 + /**
  93 + * 删除库房
  94 + */
  95 + @PreAuthorize("@ss.hasPermi('service:depotNode:remove')")
  96 + @Log(title = "库房", businessType = BusinessType.DELETE)
  97 + @DeleteMapping("/{depotNodeIds}")
  98 + public AjaxResult remove(@PathVariable Long[] depotNodeIds)
  99 + {
  100 + return toAjax(depotNodeService.deleteDepotNodeByIds(depotNodeIds));
  101 + }
  102 +
  103 + @GetMapping("/treeselect")
  104 + public AjaxResult treeselect(DepotNode serviceDept)
  105 + {
  106 + List<DepotNode> depotNodes = depotNodeService.selectDepotNodeList(serviceDept);
  107 + return AjaxResult.success(depotNodeService.buildDepotNodeTreeSelect(depotNodes));
  108 + }
  109 +
  110 +
  111 + /**
  112 + * 查询库房列表(排除节点)
  113 + */
  114 + @PreAuthorize("@ss.hasPermi('system:depotNode:list')")
  115 + @GetMapping("/list/exclude/{depotNodeId}")
  116 + public AjaxResult excludeChild(@PathVariable(value = "depotNodeId", required = false) Long depotNodeId)
  117 + {
  118 + List<DepotNode> depotNodes = depotNodeService.selectDepotNodeList(new DepotNode());
  119 + Iterator<DepotNode> it = depotNodes.iterator();
  120 + while (it.hasNext())
  121 + {
  122 + DepotNode d = (DepotNode) it.next();
  123 + if (d.getId().intValue() == depotNodeId
  124 + || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), depotNodeId + ""))
  125 + {
  126 + it.remove();
  127 + }
  128 + }
  129 + return AjaxResult.success(depotNodes);
  130 + }
  131 +
  132 +}
... ...
ruoyi-service/src/main/java/com/ruoyi/service/domain/DepotNode.java 0 → 100644
  1 +package com.ruoyi.service.domain;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.ruoyi.common.annotation.Excel;
  5 +import com.ruoyi.common.core.domain.BaseEntity;
  6 +import org.apache.commons.lang3.builder.ToStringBuilder;
  7 +import org.apache.commons.lang3.builder.ToStringStyle;
  8 +
  9 +import java.util.ArrayList;
  10 +import java.util.Date;
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * 库房 depot_node
  15 + *
  16 + * @author ym
  17 + * @date 2022-08-19
  18 + */
  19 +public class DepotNode extends BaseEntity
  20 +{
  21 + private static final long serialVersionUID = 1L;
  22 +
  23 + private Long id;
  24 +
  25 + /** 父id */
  26 + private Long parentId;
  27 +
  28 + /** 祖级列表 */
  29 + private String ancestors;
  30 +
  31 + /** 节点名称 */
  32 + private String nodeName;
  33 +
  34 + /** 显示顺序 */
  35 + private Integer orderNum;
  36 +
  37 + /** 状态(0正常 1停用) */
  38 + private String status;
  39 +
  40 + /** 删除标志(0代表存在 2代表删除) */
  41 + private String delFlag;
  42 +
  43 + /** 是否是架子(0不是 1是) */
  44 + private String nodeFlag;
  45 +
  46 + /** 库位码 */
  47 + private String depotCode;
  48 +
  49 + private String createUser;
  50 +
  51 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  52 + private Date createTime;
  53 +
  54 + private String updateUser;
  55 +
  56 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  57 + private Date updateTime;
  58 +
  59 + /** 子部门 */
  60 + private List<DepotNode> children = new ArrayList<DepotNode>();
  61 +
  62 + public Long getId() {
  63 + return id;
  64 + }
  65 +
  66 + public void setId(Long id) {
  67 + this.id = id;
  68 + }
  69 +
  70 + public Long getParentId() {
  71 + return parentId;
  72 + }
  73 +
  74 + public void setParentId(Long parentId) {
  75 + this.parentId = parentId;
  76 + }
  77 +
  78 + public String getAncestors() {
  79 + return ancestors;
  80 + }
  81 +
  82 + public void setAncestors(String ancestors) {
  83 + this.ancestors = ancestors;
  84 + }
  85 +
  86 + public String getNodeName() {
  87 + return nodeName;
  88 + }
  89 +
  90 + public void setNodeName(String nodeName) {
  91 + this.nodeName = nodeName;
  92 + }
  93 +
  94 + public Integer getOrderNum() {
  95 + return orderNum;
  96 + }
  97 +
  98 + public void setOrderNum(Integer orderNum) {
  99 + this.orderNum = orderNum;
  100 + }
  101 +
  102 + public String getStatus() {
  103 + return status;
  104 + }
  105 +
  106 + public void setStatus(String status) {
  107 + this.status = status;
  108 + }
  109 +
  110 + public String getDelFlag() {
  111 + return delFlag;
  112 + }
  113 +
  114 + public void setDelFlag(String delFlag) {
  115 + this.delFlag = delFlag;
  116 + }
  117 +
  118 + public String getNodeFlag() {
  119 + return nodeFlag;
  120 + }
  121 +
  122 + public void setNodeFlag(String nodeFlag) {
  123 + this.nodeFlag = nodeFlag;
  124 + }
  125 +
  126 + public String getDepotCode() {
  127 + return depotCode;
  128 + }
  129 +
  130 + public void setDepotCode(String depotCode) {
  131 + this.depotCode = depotCode;
  132 + }
  133 +
  134 + public String getCreateUser() {
  135 + return createUser;
  136 + }
  137 +
  138 + public void setCreateUser(String createUser) {
  139 + this.createUser = createUser;
  140 + }
  141 +
  142 + @Override
  143 + public Date getCreateTime() {
  144 + return createTime;
  145 + }
  146 +
  147 + @Override
  148 + public void setCreateTime(Date createTime) {
  149 + this.createTime = createTime;
  150 + }
  151 +
  152 + public String getUpdateUser() {
  153 + return updateUser;
  154 + }
  155 +
  156 + public void setUpdateUser(String updateUser) {
  157 + this.updateUser = updateUser;
  158 + }
  159 +
  160 + @Override
  161 + public Date getUpdateTime() {
  162 + return updateTime;
  163 + }
  164 +
  165 + @Override
  166 + public void setUpdateTime(Date updateTime) {
  167 + this.updateTime = updateTime;
  168 + }
  169 +
  170 + public List<DepotNode> getChildren() {
  171 + return children;
  172 + }
  173 +
  174 + public void setChildren(List<DepotNode> children) {
  175 + this.children = children;
  176 + }
  177 +}
... ...
ruoyi-service/src/main/java/com/ruoyi/service/mapper/DepotNodeMapper.java 0 → 100644
  1 +package com.ruoyi.service.mapper;
  2 +
  3 +import com.ruoyi.service.domain.DepotNode;
  4 +import java.util.List;
  5 +
  6 +/**
  7 + * 库房管理 数据层
  8 + *
  9 + * @author ym
  10 + * @date 2022-08-19
  11 + */
  12 +public interface DepotNodeMapper
  13 +{
  14 + /**
  15 + * 查询库房
  16 + *
  17 + * @param id 库房主键
  18 + * @return 库房
  19 + */
  20 + DepotNode selectDepotNodeById(Long id);
  21 +
  22 + /**
  23 + * 查询库房列表
  24 + *
  25 + * @param depotNode 库房
  26 + * @return 库房集合
  27 + */
  28 + List<DepotNode> selectDepotNodeList(DepotNode depotNode);
  29 +
  30 + /**
  31 + * 新增库房
  32 + *
  33 + * @param depotNode 库房
  34 + * @return 结果
  35 + */
  36 + int insertDepotNode(DepotNode depotNode);
  37 +
  38 + /**
  39 + * 修改库房
  40 + *
  41 + * @param depotNode 库房
  42 + * @return 结果
  43 + */
  44 + int updateDepotNode(DepotNode depotNode);
  45 +
  46 + /**
  47 + * 删除库房
  48 + *
  49 + * @param deptId 库房主键
  50 + * @return 结果
  51 + */
  52 + int deleteDepotNodeById(Long deptId);
  53 +
  54 + /**
  55 + * 批量删除库房
  56 + *
  57 + * @param deptIds 需要删除的数据主键集合
  58 + * @return 结果
  59 + */
  60 + int deleteDepotNodeByIds(Long[] deptIds);
  61 +
  62 +}
... ...
ruoyi-service/src/main/java/com/ruoyi/service/service/DepotNodeService.java 0 → 100644
  1 +package com.ruoyi.service.service;
  2 +
  3 +
  4 +import com.ruoyi.service.domain.DepotNode;
  5 +import com.ruoyi.service.util.TreeSelect;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * 库房管理 服务层
  11 + *
  12 + * @author ym
  13 + * @date 2022-08-19
  14 + */
  15 +public interface DepotNodeService
  16 +{
  17 + /**
  18 + * 查询库房
  19 + *
  20 + * @param id 库房主键
  21 + * @return 库房
  22 + */
  23 + DepotNode selectDepotNodeById(Long id);
  24 +
  25 + /**
  26 + * 查询库房列表
  27 + *
  28 + * @param depotNode 库房
  29 + * @return 库房集合
  30 + */
  31 + List<DepotNode> selectDepotNodeList(DepotNode depotNode);
  32 +
  33 + /**
  34 + * 新增库房
  35 + *
  36 + * @param depotNode 库房
  37 + * @return 结果
  38 + */
  39 + int insertDepotNode(DepotNode depotNode);
  40 +
  41 + /**
  42 + * 修改库房
  43 + *
  44 + * @param depotNode 库房
  45 + * @return 结果
  46 + */
  47 + int updateDepotNode(DepotNode depotNode);
  48 +
  49 + /**
  50 + * 批量删除库房
  51 + *
  52 + * @param ids 需要删除的库房主键集合
  53 + * @return 结果
  54 + */
  55 + int deleteDepotNodeByIds(Long[] ids);
  56 +
  57 + /**
  58 + * 删除库房信息
  59 + *
  60 + * @param id 库房主键
  61 + * @return 结果
  62 + */
  63 + int deleteDepotNodeById(Long id);
  64 +
  65 +
  66 + List<DepotNode> buildDepotNodeTree(List<DepotNode> depotNodes);
  67 + /**
  68 + * 构建前端所需要下拉树结构
  69 + *
  70 + * @param depotNodes 库房列表
  71 + * @return 下拉树结构列表
  72 + */
  73 + List<TreeSelect> buildDepotNodeTreeSelect(List<DepotNode> depotNodes);
  74 +
  75 +}
... ...
ruoyi-service/src/main/java/com/ruoyi/service/service/impl/DepotNodeServiceImpl.java 0 → 100644
  1 +package com.ruoyi.service.service.impl;
  2 +
  3 +import com.ruoyi.common.utils.DateUtils;
  4 +import com.ruoyi.common.utils.StringUtils;
  5 +import com.ruoyi.service.domain.DepotNode;
  6 +import com.ruoyi.service.mapper.DepotNodeMapper;
  7 +import com.ruoyi.service.service.DepotNodeService;
  8 +import com.ruoyi.service.util.TreeSelect;
  9 +import org.springframework.stereotype.Service;
  10 +import org.springframework.transaction.annotation.Transactional;
  11 +
  12 +import javax.annotation.Resource;
  13 +import java.util.ArrayList;
  14 +import java.util.Iterator;
  15 +import java.util.List;
  16 +import java.util.stream.Collectors;
  17 +
  18 +/**
  19 + * 库房管理 服务实现
  20 + *
  21 + * @author ym
  22 + * @date 2022-08-19
  23 + */
  24 +@Service
  25 +public class DepotNodeServiceImpl implements DepotNodeService
  26 +{
  27 + @Resource
  28 + private DepotNodeMapper depotNodeMapper;
  29 + /**
  30 + * 查询库房
  31 + *
  32 + * @param id 库房主键
  33 + * @return 库房
  34 + */
  35 + @Override
  36 + public DepotNode selectDepotNodeById(Long id)
  37 + {
  38 + return depotNodeMapper.selectDepotNodeById(id);
  39 + }
  40 +
  41 + /**
  42 + * 查询库房列表
  43 + *
  44 + * @param depotNode 库房
  45 + * @return 库房
  46 + */
  47 + @Override
  48 + public List<DepotNode> selectDepotNodeList(DepotNode depotNode)
  49 + {
  50 + return depotNodeMapper.selectDepotNodeList(depotNode);
  51 + }
  52 +
  53 + /**
  54 + * 新增库房
  55 + *
  56 + * @param depotNode 库房
  57 + * @return 结果
  58 + */
  59 + @Override
  60 + @Transactional
  61 + public int insertDepotNode(DepotNode depotNode)
  62 + {
  63 + DepotNode DepotNodeP=depotNodeMapper.selectDepotNodeById(depotNode.getParentId());
  64 + String ancestors=DepotNodeP.getAncestors()+","+DepotNodeP.getId();
  65 + depotNode.setAncestors(ancestors);
  66 + int i=depotNodeMapper.insertDepotNode(depotNode);
  67 + String depotCode=ancestors.replace(",","-")+"-"+depotNode.getId();
  68 + depotNode.setDepotCode(depotCode);
  69 + depotNodeMapper.updateDepotNode(depotNode);
  70 + return i;
  71 + }
  72 +
  73 + /**
  74 + * 修改库房
  75 + *
  76 + * @param depotNode 库房
  77 + * @return 结果
  78 + */
  79 + @Override
  80 + public int updateDepotNode(DepotNode depotNode)
  81 + {
  82 + depotNode.setUpdateTime(DateUtils.getNowDate());
  83 + return depotNodeMapper.updateDepotNode(depotNode);
  84 + }
  85 +
  86 + /**
  87 + * 批量删除库房
  88 + *
  89 + * @param ids 需要删除的库房主键
  90 + * @return 结果
  91 + */
  92 + @Override
  93 + public int deleteDepotNodeByIds(Long[] ids)
  94 + {
  95 + return depotNodeMapper.deleteDepotNodeByIds(ids);
  96 + }
  97 +
  98 + /**
  99 + * 删除库房信息
  100 + *
  101 + * @param id 库房主键
  102 + * @return 结果
  103 + */
  104 + @Override
  105 + public int deleteDepotNodeById(Long id)
  106 + {
  107 + return depotNodeMapper.deleteDepotNodeById(id);
  108 + }
  109 +
  110 +
  111 +
  112 + /**
  113 + * 构建前端所需要下拉树结构
  114 + *
  115 + * @param depotNodes 库房列表
  116 + * @return 下拉树结构列表
  117 + */
  118 + public List<TreeSelect> buildDepotNodeTreeSelect(List<DepotNode> depotNodes){
  119 +
  120 + List<DepotNode> depotNodeTrees = buildDepotNodeTree(depotNodes);
  121 + return depotNodeTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
  122 + }
  123 + /**
  124 + * 构建前端所需要树结构
  125 + *
  126 + * @param depotNodes 库房列表
  127 + * @return 树结构列表
  128 + */
  129 + @Override
  130 + public List<DepotNode> buildDepotNodeTree(List<DepotNode> depotNodes)
  131 + {
  132 + List<DepotNode> returnList = new ArrayList<DepotNode>();
  133 + List<Long> tempList = new ArrayList<Long>();
  134 + for (DepotNode dept : depotNodes)
  135 + {
  136 + tempList.add(dept.getId());
  137 + }
  138 + for (DepotNode dept : depotNodes)
  139 + {
  140 + // 如果是顶级节点, 遍历该父节点的所有子节点
  141 + if (!tempList.contains(dept.getParentId()))
  142 + {
  143 + recursionFn(depotNodes, dept);
  144 + returnList.add(dept);
  145 + }
  146 + }
  147 + if (returnList.isEmpty())
  148 + {
  149 + returnList = depotNodes;
  150 + }
  151 + return returnList;
  152 + }
  153 + /**
  154 + * 递归列表
  155 + */
  156 + private void recursionFn(List<DepotNode> list, DepotNode t)
  157 + {
  158 + // 得到子节点列表
  159 + List<DepotNode> childList = getChildList(list, t);
  160 + t.setChildren(childList);
  161 + for (DepotNode tChild : childList)
  162 + {
  163 + if (hasChild(list, tChild))
  164 + {
  165 + recursionFn(list, tChild);
  166 + }
  167 + }
  168 + }
  169 +
  170 + /**
  171 + * 得到子节点列表
  172 + */
  173 + private List<DepotNode> getChildList(List<DepotNode> list, DepotNode t)
  174 + {
  175 + List<DepotNode> tlist = new ArrayList<DepotNode>();
  176 + Iterator<DepotNode> it = list.iterator();
  177 + while (it.hasNext())
  178 + {
  179 + DepotNode n = (DepotNode) it.next();
  180 + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue())
  181 + {
  182 + tlist.add(n);
  183 + }
  184 + }
  185 + return tlist;
  186 + }
  187 +
  188 + /**
  189 + * 判断是否有子节点
  190 + */
  191 + private boolean hasChild(List<DepotNode> list, DepotNode t)
  192 + {
  193 + return getChildList(list, t).size() > 0;
  194 + }
  195 +
  196 +
  197 +
  198 +}
... ...
ruoyi-service/src/main/java/com/ruoyi/service/util/TreeSelect.java 0 → 100644
  1 +package com.ruoyi.service.util;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonInclude;
  4 +import com.ruoyi.common.core.domain.entity.SysMenu;
  5 +import com.ruoyi.domain.ArchivesDept;
  6 +import com.ruoyi.service.domain.DepotNode;
  7 +
  8 +import java.io.Serializable;
  9 +import java.util.List;
  10 +import java.util.stream.Collectors;
  11 +
  12 +/**
  13 + * Treeselect树结构实体类 common copy过来的
  14 + *
  15 + * @author ruoyi
  16 + */
  17 +public class TreeSelect implements Serializable
  18 +{
  19 + private static final long serialVersionUID = 1L;
  20 +
  21 + /** 节点ID */
  22 + private Long id;
  23 +
  24 + /** 节点名称 */
  25 + private String label;
  26 +
  27 + /** 子节点 */
  28 + @JsonInclude(JsonInclude.Include.NON_EMPTY)
  29 + private List<TreeSelect> children;
  30 +
  31 + public TreeSelect()
  32 + {
  33 +
  34 + }
  35 +
  36 + public TreeSelect(DepotNode depotNode)
  37 + {
  38 + this.id = depotNode.getId();
  39 + this.label = depotNode.getNodeName();
  40 + this.children = depotNode.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
  41 + }
  42 +
  43 +
  44 +
  45 + public TreeSelect(SysMenu menu)
  46 + {
  47 + this.id = menu.getMenuId();
  48 + this.label = menu.getMenuName();
  49 + this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
  50 + }
  51 +
  52 + public Long getId()
  53 + {
  54 + return id;
  55 + }
  56 +
  57 + public void setId(Long id)
  58 + {
  59 + this.id = id;
  60 + }
  61 +
  62 + public String getLabel()
  63 + {
  64 + return label;
  65 + }
  66 +
  67 + public void setLabel(String label)
  68 + {
  69 + this.label = label;
  70 + }
  71 +
  72 + public List<TreeSelect> getChildren()
  73 + {
  74 + return children;
  75 + }
  76 +
  77 + public void setChildren(List<TreeSelect> children)
  78 + {
  79 + this.children = children;
  80 + }
  81 +}
... ...
ruoyi-service/src/main/resources/mapper/sevice/DepotNodeMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper
  3 +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 +"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.ruoyi.service.mapper.DepotNodeMapper">
  6 +
  7 + <select id="selectDepotNodeList" parameterType="com.ruoyi.service.domain.DepotNode" resultType="com.ruoyi.service.domain.DepotNode">
  8 + select * from depot_node
  9 + <where>
  10 + <if test="parentId != null "> and parentId = #{parentId}</if>
  11 + <if test="ancestors != null and ancestors != ''"> and ancestors = #{ancestors}</if>
  12 + <if test="nodeName != null and nodeName != ''"> and nodeName like concat('%', #{nodeName}, '%')</if>
  13 + <if test="orderNum != null "> and orderNum = #{orderNum}</if>
  14 + <if test="status != null and status != ''"> and status = #{status}</if>
  15 + </where>
  16 + </select>
  17 +
  18 + <select id="selectDepotNodeById" parameterType="Long" resultType="com.ruoyi.service.domain.DepotNode">
  19 + select * from depot_node
  20 + where id = #{id}
  21 + </select>
  22 +
  23 + <insert id="insertDepotNode" parameterType="com.ruoyi.service.domain.DepotNode" useGeneratedKeys="true" keyProperty="id">
  24 + insert into depot_node
  25 + <trim prefix="(" suffix=")" suffixOverrides=",">
  26 + <if test="parentId != null">parentId,</if>
  27 + <if test="ancestors != null">ancestors,</if>
  28 + <if test="nodeName != null">nodeName,</if>
  29 + <if test="orderNum != null">orderNum,</if>
  30 + <if test="status != null">status,</if>
  31 + <if test="delFlag != null">delFlag,</if>
  32 + <if test="nodeFlag != null">nodeFlag,</if>
  33 + <if test="depotCode != null">depotCode,</if>
  34 + <if test="createUser != null">createUser,</if>
  35 + createTime
  36 + </trim>
  37 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  38 + <if test="parentId != null">#{parentId},</if>
  39 + <if test="ancestors != null">#{ancestors},</if>
  40 + <if test="nodeName != null">#{nodeName},</if>
  41 + <if test="orderNum != null">#{orderNum},</if>
  42 + <if test="status != null">#{status},</if>
  43 + <if test="delFlag != null">#{delFlag},</if>
  44 + <if test="nodeFlag != null">#{nodeFlag},</if>
  45 + <if test="depotCode != null">#{depotCode},</if>
  46 + <if test="createUser != null">#{createUser},</if>
  47 + sysdate()
  48 + </trim>
  49 + </insert>
  50 +
  51 + <update id="updateDepotNode" parameterType="com.ruoyi.service.domain.DepotNode">
  52 + update depot_node
  53 + <trim prefix="SET" suffixOverrides=",">
  54 + <if test="parentId != null">parentId = #{parentId},</if>
  55 + <if test="ancestors != null">ancestors = #{ancestors},</if>
  56 + <if test="nodeName != null">nodeName = #{nodeName},</if>
  57 + <if test="orderNum != null">orderNum = #{orderNum},</if>
  58 + <if test="depotCode != null">depotCode = #{depotCode},</if>
  59 + <if test="status != null">status = #{status},</if>
  60 + <if test="delFlag != null">delFlag = #{delFlag},</if>
  61 + <if test="nodeFlag != null">nodeFlag = #{nodeFlag},</if>
  62 + <if test="updateUser != null">updateUser = #{updateUser},</if>
  63 + updateTime = sysdate()
  64 + </trim>
  65 + where id = #{id}
  66 + </update>
  67 +
  68 + <delete id="deleteDepotNodeById" parameterType="Long">
  69 + delete from depot_node where id = #{id}
  70 + </delete>
  71 +
  72 + <delete id="deleteDepotNodeByIds" parameterType="String">
  73 + delete from depot_node where id in
  74 + <foreach item="id" collection="array" open="(" separator="," close=")">
  75 + #{id}
  76 + </foreach>
  77 + </delete>
  78 +
  79 +</mapper>
0 80 \ No newline at end of file
... ...
ruoyi-ui/src/api/service/depotNode.js 0 → 100644
  1 +import request from '@/utils/request'
  2 +
  3 +// 查询部门列表
  4 +export function listDept(query) {
  5 + return request({
  6 + url: '/service/depotNode/list',
  7 + method: 'get',
  8 + params: query
  9 + })
  10 +}
  11 +
  12 +// 查询部门详细
  13 +export function getDepotNode(id) {
  14 + return request({
  15 + url: '/service/depotNode/' + id,
  16 + method: 'get'
  17 + })
  18 +}
  19 +
  20 +// 新增部门
  21 +export function addDept(data) {
  22 + return request({
  23 + url: '/service/depotNode',
  24 + method: 'post',
  25 + data: data
  26 + })
  27 +}
  28 +
  29 +// 修改部门
  30 +export function updateDept(data) {
  31 + return request({
  32 + url: '/service/depotNode',
  33 + method: 'put',
  34 + data: data
  35 + })
  36 +}
  37 +
  38 +// 删除部门
  39 +export function delDept(id) {
  40 + return request({
  41 + url: '/service/depotNode/' + id,
  42 + method: 'delete'
  43 + })
  44 +}
  45 +// 查询部门下拉树结构
  46 +export function treeselect() {
  47 + return request({
  48 + url: '/service/depotNode/treeselect',
  49 + method: 'get'
  50 + })
  51 +}
  52 +// 查询部门列表(排除节点)
  53 +export function listDeptExcludeChild(id) {
  54 + return request({
  55 + url: '/service/depotNode/list/exclude/' + id,
  56 + method: 'get'
  57 + })
  58 +}
  59 +
  60 +
... ...
ruoyi-ui/src/views/service/depotNode/index.vue 0 → 100644
  1 +<template>
  2 + <div class="app-container">
  3 + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
  4 + <el-form-item label="部门名称" prop="nodeName">
  5 + <el-input
  6 + v-model="queryParams.nodeName"
  7 + placeholder="请输入部门名称"
  8 + clearable
  9 + @keyup.enter.native="handleQuery"
  10 + />
  11 + </el-form-item>
  12 + <el-form-item label="状态" prop="status">
  13 + <el-select v-model="queryParams.status" placeholder="部门状态" clearable>
  14 + <el-option
  15 + v-for="dict in dict.type.sys_normal_disable"
  16 + :key="dict.value"
  17 + :label="dict.label"
  18 + :value="dict.value"
  19 + />
  20 + </el-select>
  21 + </el-form-item>
  22 + <el-form-item>
  23 + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  24 + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  25 + </el-form-item>
  26 + </el-form>
  27 +
  28 + <el-row :gutter="10" class="mb8">
  29 + <el-col :span="1.5">
  30 + <el-button
  31 + type="primary"
  32 + plain
  33 + icon="el-icon-plus"
  34 + size="mini"
  35 + @click="handleAdd"
  36 + v-hasPermi="['system:dept:add']"
  37 + >新增</el-button>
  38 + </el-col>
  39 + <el-col :span="1.5">
  40 + <el-button
  41 + type="info"
  42 + plain
  43 + icon="el-icon-sort"
  44 + size="mini"
  45 + @click="toggleExpandAll"
  46 + >展开/折叠</el-button>
  47 + </el-col>
  48 + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  49 + </el-row>
  50 +
  51 + <el-table
  52 + v-if="refreshTable"
  53 + v-loading="loading"
  54 + :data="deptList"
  55 + row-key="id"
  56 + :default-expand-all="isExpandAll"
  57 + :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  58 + >
  59 + <el-table-column prop="nodeName" label="名称" width="260"></el-table-column>
  60 + <el-table-column prop="orderNum" label="排序" width="200"></el-table-column>
  61 + <el-table-column prop="status" label="状态" width="100">
  62 + <template slot-scope="scope">
  63 + <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
  64 + </template>
  65 + </el-table-column>
  66 +
  67 + <el-table-column label="创建时间" align="center" prop="createTime" width="200">
  68 + <template slot-scope="scope">
  69 + <span>{{ parseTime(scope.row.createTime) }}</span>
  70 + </template>
  71 + </el-table-column>
  72 + <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  73 + <template slot-scope="scope">
  74 + <el-button
  75 + size="mini"
  76 + type="text"
  77 + icon="el-icon-edit"
  78 + @click="handleUpdate(scope.row)"
  79 + v-hasPermi="['service:depotNode:edit']"
  80 + >修改</el-button>
  81 + <el-button
  82 + size="mini"
  83 + type="text"
  84 + icon="el-icon-plus"
  85 + @click="handleAdd(scope.row)"
  86 + v-hasPermi="['service:depotNode:add']"
  87 + >新增</el-button>
  88 + <el-button
  89 + v-if="scope.row.parentId != 0"
  90 + size="mini"
  91 + type="text"
  92 + icon="el-icon-delete"
  93 + @click="handleDelete(scope.row)"
  94 + v-hasPermi="['service:depotNode:remove']"
  95 + >删除</el-button>
  96 + </template>
  97 + </el-table-column>
  98 + </el-table>
  99 +
  100 + <!-- 添加或修改部门对话框 -->
  101 + <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  102 + <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  103 + <el-row>
  104 + <el-col :span="24" v-if="form.parentId !== 0" >
  105 + <el-form-item label="上级" prop="parentId" >
  106 + <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" :disabled="type==2"/>
  107 + </el-form-item>
  108 + </el-col>
  109 + </el-row>
  110 + <el-row>
  111 + <el-col :span="12">
  112 + <el-form-item label="名称" prop="nodeName">
  113 + <el-input v-model="form.nodeName" placeholder="请输入部门名称" />
  114 + </el-form-item>
  115 + </el-col>
  116 + <el-col :span="12">
  117 + <el-form-item label="显示排序" prop="orderNum">
  118 + <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
  119 + </el-form-item>
  120 + </el-col>
  121 + </el-row>
  122 + <el-row>
  123 + <el-col :span="12">
  124 + <el-form-item label="档案架">
  125 + <el-radio-group v-model="form.nodeFlag">
  126 + <el-radio
  127 + v-for="dict in dict.type.yes_no"
  128 + :key="dict.value"
  129 + :label="dict.value"
  130 + >{{dict.label}}</el-radio>
  131 + </el-radio-group>
  132 + </el-form-item>
  133 + </el-col>
  134 + <el-col :span="12">
  135 + <el-form-item label="部门状态">
  136 + <el-radio-group v-model="form.status">
  137 + <el-radio
  138 + v-for="dict in dict.type.sys_normal_disable"
  139 + :key="dict.value"
  140 + :label="dict.value"
  141 + >{{dict.label}}</el-radio>
  142 + </el-radio-group>
  143 + </el-form-item>
  144 + </el-col>
  145 + </el-row>
  146 + </el-form>
  147 + <div slot="footer" class="dialog-footer">
  148 + <el-button type="primary" @click="submitForm">确 定</el-button>
  149 + <el-button @click="cancel">取 消</el-button>
  150 + </div>
  151 + </el-dialog>
  152 + </div>
  153 +</template>
  154 +
  155 +<script>
  156 +import { listDept, getDepotNode, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/service/depotNode";
  157 +import Treeselect from "@riophae/vue-treeselect";
  158 +import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  159 +
  160 +export default {
  161 + name: "Dept",
  162 + dicts: ['sys_normal_disable','yes_no'],
  163 + components: { Treeselect },
  164 + data() {
  165 + return {
  166 + // 遮罩层
  167 + loading: true,
  168 + // 显示搜索条件
  169 + showSearch: true,
  170 + // 表格树数据
  171 + deptList: [],
  172 + // 部门树选项
  173 + deptOptions: [],
  174 + // 弹出层标题
  175 + title: "",
  176 + // 是否显示弹出层
  177 + open: false,
  178 + // 是否展开,默认全部展开
  179 + isExpandAll: true,
  180 + // 重新渲染表格状态
  181 + refreshTable: true,
  182 + // 查询参数
  183 + queryParams: {
  184 + nodeName: undefined,
  185 + status: undefined
  186 + },
  187 + // 表单参数
  188 + form: {},
  189 + // 表单校验
  190 + rules: {
  191 + parentId: [
  192 + { required: true, message: "上级部门不能为空", trigger: "blur" }
  193 + ],
  194 + nodeName: [
  195 + { required: true, message: "部门名称不能为空", trigger: "blur" }
  196 + ],
  197 + orderNum: [
  198 + { required: true, message: "显示排序不能为空", trigger: "blur" }
  199 + ],
  200 + email: [
  201 + {
  202 + type: "email",
  203 + message: "请输入正确的邮箱地址",
  204 + trigger: ["blur", "change"]
  205 + }
  206 + ],
  207 + phone: [
  208 + {
  209 + pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  210 + message: "请输入正确的手机号码",
  211 + trigger: "blur"
  212 + }
  213 + ]
  214 + },
  215 + type:undefined
  216 + };
  217 + },
  218 + created() {
  219 + this.getList();
  220 + },
  221 + methods: {
  222 + /** 查询部门列表 */
  223 + getList() {
  224 + this.loading = true;
  225 + listDept(this.queryParams).then(response => {
  226 + this.deptList = this.handleTree(response.data, "id");
  227 + this.loading = false;
  228 + });
  229 + },
  230 + /** 转换部门数据结构 */
  231 + normalizer(node) {
  232 + if (node.children && !node.children.length) {
  233 + delete node.children;
  234 + }
  235 + return {
  236 + id: node.id,
  237 + label: node.nodeName,
  238 + children: node.children
  239 + };
  240 + },
  241 + // 取消按钮
  242 + cancel() {
  243 + this.open = false;
  244 + this.reset();
  245 + },
  246 + // 表单重置
  247 + reset() {
  248 + this.form = {
  249 + id: undefined,
  250 + parentId: undefined,
  251 + nodeName: undefined,
  252 + orderNum: undefined,
  253 + leader: undefined,
  254 + phone: undefined,
  255 + email: undefined,
  256 + status: "0"
  257 + };
  258 + this.resetForm("form");
  259 + },
  260 + /** 搜索按钮操作 */
  261 + handleQuery() {
  262 + this.getList();
  263 + },
  264 + /** 重置按钮操作 */
  265 + resetQuery() {
  266 + this.resetForm("queryForm");
  267 + this.handleQuery();
  268 + },
  269 + /** 新增按钮操作 */
  270 + handleAdd(row) {
  271 + this.reset();
  272 + this.type=1;
  273 + if (row != undefined) {
  274 + this.form.parentId = row.id;
  275 + }
  276 + this.open = true;
  277 + this.title = "添加部门";
  278 + listDept().then(response => {
  279 + this.deptOptions = this.handleTree(response.data, "id");
  280 + });
  281 + },
  282 + /** 展开/折叠操作 */
  283 + toggleExpandAll() {
  284 + this.refreshTable = false;
  285 + this.isExpandAll = !this.isExpandAll;
  286 + this.$nextTick(() => {
  287 + this.refreshTable = true;
  288 + });
  289 + },
  290 + /** 修改按钮操作 */
  291 + handleUpdate(row) {
  292 + this.reset();
  293 + this.type=2;
  294 + getDepotNode(row.id).then(response => {
  295 + this.form = response.data;
  296 + this.open = true;
  297 + this.title = "修改";
  298 + });
  299 +
  300 + listDeptExcludeChild(row.id).then(response => {
  301 + this.deptOptions = this.handleTree(response.data, "id");
  302 + });
  303 + },
  304 + /** 提交按钮 */
  305 + submitForm: function() {
  306 + this.$refs["form"].validate(valid => {
  307 + if (valid) {
  308 + if (this.form.id != undefined) {
  309 + updateDept(this.form).then(response => {
  310 + this.$modal.msgSuccess("修改成功");
  311 + this.open = false;
  312 + this.getList();
  313 + });
  314 + } else {
  315 + addDept(this.form).then(response => {
  316 + this.$modal.msgSuccess("新增成功");
  317 + this.open = false;
  318 + this.getList();
  319 + });
  320 + }
  321 + }
  322 + });
  323 + },
  324 + /** 删除按钮操作 */
  325 + handleDelete(row) {
  326 + this.$modal.confirm('是否确认删除名称为"' + row.nodeName + '"的数据项?').then(function() {
  327 + return delDept(row.id);
  328 + }).then(() => {
  329 + this.getList();
  330 + this.$modal.msgSuccess("删除成功");
  331 + }).catch(() => {});
  332 + }
  333 + }
  334 +};
  335 +</script>
... ...