diff --git a/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/equip/IpcEquipInfoController.java b/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/equip/IpcEquipInfoController.java index caa9575..9702236 100644 --- a/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/equip/IpcEquipInfoController.java +++ b/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/equip/IpcEquipInfoController.java @@ -69,9 +69,18 @@ public class IpcEquipInfoController extends BaseController } @GetMapping("/getInfoByParentId") - public AjaxResult getInfoByParentId(@RequestParam String parentEquipId,String type) + public AjaxResult getInfoByParentId(@RequestParam String parentEquipId,String type,Long deptId) { - return AjaxResult.success(ipcEquipInfoService.selectIpcEquipInfoListByParentId(parentEquipId,type)); + return AjaxResult.success(ipcEquipInfoService.selectIpcEquipInfoListByParentId(parentEquipId,type,deptId)); + } + + /** + * 根据部门选择设备树 + */ + @GetMapping("/getEquipTreeByDept") + public AjaxResult getEquipTreeByDept(Long deptId) + { + return AjaxResult.success(ipcEquipInfoService.selectIpcEquipInfoTreeByDeptId(deptId)); } /** diff --git a/zfipc-server/zfipc-common/src/main/java/com/inspur/common/core/domain/TreeSelect.java b/zfipc-server/zfipc-common/src/main/java/com/inspur/common/core/domain/TreeSelect.java index 713781a..0a979bb 100644 --- a/zfipc-server/zfipc-common/src/main/java/com/inspur/common/core/domain/TreeSelect.java +++ b/zfipc-server/zfipc-common/src/main/java/com/inspur/common/core/domain/TreeSelect.java @@ -32,6 +32,11 @@ public class TreeSelect implements Serializable { */ private String remark; + /** + * 值 + */ + private Long value; + /** * 子节点 */ @@ -44,6 +49,7 @@ public class TreeSelect implements Serializable { public TreeSelect(SysDept dept) { this.id = dept.getDeptId(); + this.value = dept.getDeptId(); this.label = dept.getDeptName(); this.remark = dept.getRemark(); this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); @@ -85,6 +91,14 @@ public class TreeSelect implements Serializable { this.label = label; } + public Long getValue() { + return value; + } + + public void setValue(Long value) { + this.value = value; + } + public List getChildren() { return children; } diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/domain/EquipTreeSelect.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/domain/EquipTreeSelect.java index 917fb3b..edc71de 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/domain/EquipTreeSelect.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/domain/EquipTreeSelect.java @@ -49,6 +49,13 @@ public class EquipTreeSelect implements Serializable { this.children = equipCategory.getChildList().stream().map(EquipTreeSelect::new).collect(Collectors.toList()); } + public EquipTreeSelect(IpcEquipInfo equipInfo){ + this.id = equipInfo.getId(); + this.label = equipInfo.getEquipName(); + this.value = equipInfo.getId(); + this.children = equipInfo.getChildList().stream().map(EquipTreeSelect::new).collect(Collectors.toList()); + } + public String getId() { return id; } diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/domain/IpcEquipInfo.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/domain/IpcEquipInfo.java index 4fe176e..fefe3ee 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/domain/IpcEquipInfo.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/domain/IpcEquipInfo.java @@ -1,12 +1,14 @@ package com.inspur.equip.domain; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; import java.util.List; import com.fasterxml.jackson.annotation.JsonFormat; import com.inspur.common.annotation.Excel; import com.inspur.common.core.domain.BaseEntity; +import com.inspur.common.core.domain.entity.SysDept; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -114,13 +116,18 @@ public class IpcEquipInfo extends BaseEntity private String equipFilesPath; - private List childList; + private List childList = new ArrayList<>(); /** * 是否叶子节点 */ private boolean leaf; + /** + * 子设备 + */ + private List children; + public void setId(String id) { this.id = id; @@ -354,6 +361,14 @@ public class IpcEquipInfo extends BaseEntity this.leaf = leaf; } + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/mapper/IpcEquipInfoMapper.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/mapper/IpcEquipInfoMapper.java index e8a4e21..f82efdd 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/mapper/IpcEquipInfoMapper.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/mapper/IpcEquipInfoMapper.java @@ -6,6 +6,7 @@ import com.inspur.common.annotation.DataSource; import com.inspur.common.enums.DataSourceType; import com.inspur.equip.domain.EquipTreeSelect; import com.inspur.equip.domain.IpcEquipInfo; +import org.apache.ibatis.annotations.Param; public interface IpcEquipInfoMapper @@ -46,7 +47,8 @@ public interface IpcEquipInfoMapper /** * 通过父节点id获取设备信息 */ - public List selectIpcEquipInfoListByParentId(String parentEquipId); + public List selectIpcEquipInfoListByParentId(@Param("parentEquipId")String parentEquipId, + @Param("deptId")Long deptId); /** * 查询正常运行设备 diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/service/IIpcEquipInfoService.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/service/IIpcEquipInfoService.java index 2866129..4f84539 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/service/IIpcEquipInfoService.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/service/IIpcEquipInfoService.java @@ -1,6 +1,8 @@ package com.inspur.equip.service; import java.util.List; + +import com.inspur.equip.domain.EquipTreeSelect; import com.inspur.equip.domain.IpcEquipInfo; /** @@ -42,7 +44,12 @@ public interface IIpcEquipInfoService /** * 通过父节点id获取设备信息 */ - public List selectIpcEquipInfoListByParentId(String parentEquipId,String type); + public List selectIpcEquipInfoListByParentId(String parentEquipId,String type,Long deptId); + + /** + * 根据部门id获取设备树信息 + */ + public List selectIpcEquipInfoTreeByDeptId(Long deptId); /** * 新增设备信息 diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/service/impl/IpcEquipInfoServiceImpl.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/service/impl/IpcEquipInfoServiceImpl.java index b0356d5..5211d2b 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/service/impl/IpcEquipInfoServiceImpl.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/equip/service/impl/IpcEquipInfoServiceImpl.java @@ -1,12 +1,11 @@ package com.inspur.equip.service.impl; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; +import com.inspur.common.utils.StringUtils; import com.inspur.common.utils.uuid.IdUtils; +import com.inspur.equip.domain.EquipTreeSelect; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.inspur.equip.mapper.IpcEquipInfoMapper; @@ -71,6 +70,7 @@ public class IpcEquipInfoServiceImpl implements IIpcEquipInfoService * @param ipcEquipInfo * @return */ + @Override public List selectQueryIpcEquipInfoList(IpcEquipInfo ipcEquipInfo){ return ipcEquipInfoMapper.selectQueryIpcEquipInfoList(ipcEquipInfo); } @@ -78,15 +78,29 @@ public class IpcEquipInfoServiceImpl implements IIpcEquipInfoService /** * 通过父节点id获取设备信息 */ - public List selectIpcEquipInfoListByParentId(String parentEquipId,String type){ + @Override + public List selectIpcEquipInfoListByParentId(String parentEquipId,String type,Long deptId){ if(type == null){ - return ipcEquipInfoMapper.selectIpcEquipInfoListByParentId(parentEquipId); + return ipcEquipInfoMapper.selectIpcEquipInfoListByParentId(parentEquipId,deptId); }else { return ipcEquipInfoMapper.selectRunningIpcEquipInfoListByParentId(parentEquipId); } } + /** + * 根据部门id获取设备树信息 + */ + @Override + public List selectIpcEquipInfoTreeByDeptId(Long deptId){ + //根据deptId查询设备信息 + IpcEquipInfo query = new IpcEquipInfo(); + query.setDeptId(deptId); + List equipInfos = ipcEquipInfoMapper.selectIpcEquipInfoList(query); + List equipTrees = getEquipTree(equipInfos); + return equipTrees.stream().map(EquipTreeSelect :: new).collect(Collectors.toList()); + } + /** * 新增设备信息 * @@ -180,5 +194,74 @@ public class IpcEquipInfoServiceImpl implements IIpcEquipInfoService ).collect(Collectors.toList()); } + /** + * 获取设备树 + */ + private List getEquipTree(List equipInfos) { + List returnList = new ArrayList(); + List tempList = new ArrayList(); + for (IpcEquipInfo equipInfo : equipInfos) + { + tempList.add(equipInfo.getId()); + } + for (IpcEquipInfo equipInfo : equipInfos) + { + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(equipInfo.getParentEquipId())) + { + recursionFn(equipInfos, equipInfo); + returnList.add(equipInfo); + } + } + if (returnList.isEmpty()) + { + returnList = equipInfos; + } + return returnList; + } + + /** + * 递归列表 + */ + private void recursionFn(List list, IpcEquipInfo t) + { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (IpcEquipInfo tChild : childList) + { + if (hasChild(list, tChild)) + { + recursionFn(list, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List list, IpcEquipInfo t) + { + List tlist = new ArrayList(); + Iterator it = list.iterator(); + while (it.hasNext()) + { + IpcEquipInfo n = (IpcEquipInfo) it.next(); + if (StringUtils.isNotNull(n.getParentEquipId()) && n.getParentEquipId().equals(t.getId())) + { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, IpcEquipInfo t) + { + return getChildList(list, t).size() > 0; + } + } diff --git a/zfipc-server/zfipc-system/src/main/resources/mapper/equip/IpcEquipInfoMapper.xml b/zfipc-server/zfipc-system/src/main/resources/mapper/equip/IpcEquipInfoMapper.xml index 91cef83..f466661 100644 --- a/zfipc-server/zfipc-system/src/main/resources/mapper/equip/IpcEquipInfoMapper.xml +++ b/zfipc-server/zfipc-system/src/main/resources/mapper/equip/IpcEquipInfoMapper.xml @@ -136,6 +136,7 @@ SELECT a.*,(NOT EXISTS(SELECT * from `ipc_equip_info` b WHERE b.parent_equip_id = a.id )) as leaf FROM `ipc_equip_info` a WHERE parent_equip_id = #{parentEquipId} + and a.dept_id = #{deptId} diff --git a/zfipc-ui/src/views/eqmanagement/eqcategory/index.vue b/zfipc-ui/src/views/eqmanagement/eqcategory/index.vue index 6708253..606ed0c 100644 --- a/zfipc-ui/src/views/eqmanagement/eqcategory/index.vue +++ b/zfipc-ui/src/views/eqmanagement/eqcategory/index.vue @@ -704,6 +704,8 @@ export default { /** 重置按钮操作 */ resetQuery() { this.resetForm("queryForm"); + this.queryParams.deptId = null; + this.$refs.tree.setCurrentKey(null); this.handleQuery(); }, // 多选框选中数据 diff --git a/zfipc-ui/src/views/eqmanagement/eqinfo/index.vue b/zfipc-ui/src/views/eqmanagement/eqinfo/index.vue index a42efed..31f3da1 100644 --- a/zfipc-ui/src/views/eqmanagement/eqinfo/index.vue +++ b/zfipc-ui/src/views/eqmanagement/eqinfo/index.vue @@ -105,7 +105,7 @@ :gutter="10" class="mb8" > - + --> -