Преглед на файлове

设备分类-树状结构列表查询

LLL преди 1 година
родител
ревизия
c1692a2eb6

+ 33 - 18
jeecg_module_ems/src/main/java/org/jeecg/modules/tpmEquipmentTree/controller/TpmEquipmentTreeController.java

@@ -1,31 +1,31 @@
 package org.jeecg.modules.tpmEquipmentTree.controller;
 
-import java.util.Arrays;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.jeecg.common.api.vo.Result;
-import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.common.util.oConvertUtils;
-import org.jeecg.common.system.vo.SelectTreeModel;
-import org.jeecg.modules.tpmEquipment.entity.TpmEquipment;
-import org.jeecg.modules.tpmEquipmentTree.entity.TpmEquipmentTree;
-import org.jeecg.modules.tpmEquipmentTree.service.ITpmEquipmentTreeService;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.system.vo.SelectTreeModel;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.tpmEquipmentTree.convert.TpmEquipmentTreeConvert;
+import org.jeecg.modules.tpmEquipmentTree.entity.TpmEquipmentTree;
+import org.jeecg.modules.tpmEquipmentTree.service.ITpmEquipmentTreeService;
+import org.jeecg.modules.tpmEquipmentTree.vo.TpmEquipmentTreeNodeVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.servlet.ModelAndView;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.jeecg.common.aspect.annotation.AutoLog;
 
- /**
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Arrays;
+import java.util.List;
+
+/**
  * @Description: 设备树
  * @Author: jeecg-boot
  * @Date:   2024-01-09
@@ -39,9 +39,24 @@ public class TpmEquipmentTreeController extends JeecgController<TpmEquipmentTree
 	@Autowired
 	private ITpmEquipmentTreeService tpmEquipmentTreeService;
 
+	 @ApiOperation(value="设备分类-树状结构列表查询", notes="设备分类-树状结构列表查询")
+	 @GetMapping(value = "/treeList")
+	 public Result<List<TpmEquipmentTreeNodeVO>> treeList(TpmEquipmentTree tpmEquipmentTree){
+		 if(tpmEquipmentTree.getName()!=null && !"".equals(tpmEquipmentTree.getName())){
+			 QueryWrapper<TpmEquipmentTree> queryWrapper = new QueryWrapper<>();
+			 queryWrapper.like(tpmEquipmentTree.getName() != null && !tpmEquipmentTree.getName().equals("name"),"name",tpmEquipmentTree.getName());
+			 List<TpmEquipmentTree> list = tpmEquipmentTreeService.list(queryWrapper);
+			 List<TpmEquipmentTreeNodeVO> list1 = TpmEquipmentTreeConvert.INSTANCE.convert(list);
+			 return Result.OK(list1);
+		 }else {
+			 List<TpmEquipmentTreeNodeVO> list = tpmEquipmentTreeService.getChildrenNode("0");
+			 return Result.OK(list);
+		 }
+	 }
+
 	 @ApiOperation(value="设备分类-列表查询", notes="设备分类-列表查询")
 	 @GetMapping(value = "/list")
-	 public Result<List<TpmEquipmentTree>> queryList(TpmEquipmentTree tpmEquipmentTree,HttpServletRequest req){
+	 public Result<List<TpmEquipmentTree>> queryList(TpmEquipmentTree tpmEquipmentTree){
 		 QueryWrapper<TpmEquipmentTree> queryWrapper = new QueryWrapper<>();
 		 queryWrapper.like(tpmEquipmentTree.getName() != null && !tpmEquipmentTree.getName().equals("name"),"name",tpmEquipmentTree.getName());
 		 List<TpmEquipmentTree> list = tpmEquipmentTreeService.list(queryWrapper);

+ 20 - 0
jeecg_module_ems/src/main/java/org/jeecg/modules/tpmEquipmentTree/convert/TpmEquipmentTreeConvert.java

@@ -0,0 +1,20 @@
+package org.jeecg.modules.tpmEquipmentTree.convert;
+
+import org.jeecg.modules.tpmEquipmentTree.entity.TpmEquipmentTree;
+import org.jeecg.modules.tpmEquipmentTree.vo.TpmEquipmentTreeNodeVO;
+import org.mapstruct.Mapper;
+import org.mapstruct.ReportingPolicy;
+import org.mapstruct.factory.Mappers;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE,imports ={ CollectionUtils.class, Collectors.class})
+public interface TpmEquipmentTreeConvert {
+
+    TpmEquipmentTreeConvert INSTANCE = Mappers.getMapper(TpmEquipmentTreeConvert.class);
+
+    List<TpmEquipmentTreeNodeVO> convert(List<TpmEquipmentTree> equipmentTreeList);
+
+}

+ 7 - 0
jeecg_module_ems/src/main/java/org/jeecg/modules/tpmEquipmentTree/service/ITpmEquipmentTreeService.java

@@ -5,6 +5,8 @@ import org.jeecg.modules.tpmEquipmentTree.entity.TpmEquipmentTree;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.common.exception.JeecgBootException;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import org.jeecg.modules.tpmEquipmentTree.vo.TpmEquipmentTreeNodeVO;
+
 import java.util.List;
 
 /**
@@ -24,6 +26,11 @@ public interface ITpmEquipmentTreeService extends IService<TpmEquipmentTree> {
 	/**树节点无子节点状态值*/
 	public static final String NOCHILD = "0";
 
+	/**
+	 * 递归获取子节点下的子节点
+	 */
+	public List<TpmEquipmentTreeNodeVO> getChildrenNode(String pid);
+
 
 	/**
 	 * 获取设备树及设备列表

+ 30 - 0
jeecg_module_ems/src/main/java/org/jeecg/modules/tpmEquipmentTree/service/impl/TpmEquipmentTreeServiceImpl.java

@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.common.system.vo.SelectTreeModel;
+import org.jeecg.modules.tpmEquipmentTree.convert.TpmEquipmentTreeConvert;
 import org.jeecg.modules.tpmEquipmentTree.entity.TpmEquipmentTree;
 import org.jeecg.modules.tpmEquipmentTree.mapper.TpmEquipmentTreeMapper;
 import org.jeecg.modules.tpmEquipmentTree.service.ITpmEquipmentTreeService;
+import org.jeecg.modules.tpmEquipmentTree.vo.TpmEquipmentTreeNodeVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -30,6 +32,34 @@ public class TpmEquipmentTreeServiceImpl extends ServiceImpl<TpmEquipmentTreeMap
     private TpmEquipmentTreeMapper tpmEquipmentTreeMapper;
 
     /**
+     * 递归获取子节点下的子节点 	1是0否
+     */
+    public List<TpmEquipmentTreeNodeVO> getChildrenNode(String pid){
+        List<TpmEquipmentTreeNodeVO> newTrees = new ArrayList<>();
+
+        TpmEquipmentTree equipmentTree = new TpmEquipmentTree();
+        equipmentTree.setParentid(pid);
+        QueryWrapper<TpmEquipmentTree> queryWrapper = new QueryWrapper(equipmentTree);
+        List<TpmEquipmentTree> list = tpmEquipmentTreeMapper.selectList(queryWrapper);
+
+        if(list!=null && list.size()>0){
+            List<TpmEquipmentTreeNodeVO> list1 = TpmEquipmentTreeConvert.INSTANCE.convert(list);
+            for (TpmEquipmentTreeNodeVO vo :list1){
+                if("1".equals(vo.getHasChild())){//有子节点
+                    List<TpmEquipmentTreeNodeVO> children = getChildrenNode(vo.getId());//通过pid查询获取列表,递归
+                    vo.setChildren(children);
+                    newTrees.add(vo);
+                }else if("0".equals(vo.getHasChild())) {//无子节点
+                    newTrees.add(vo);
+                }
+            }
+        }
+
+
+        return newTrees;
+    }
+
+    /**
      * 获取设备树及设备列表
      */
     public List<TpmEquipmentTree> selectTreeAndEquipList(TpmEquipmentTree tpmEquipmentTree){

+ 43 - 0
jeecg_module_ems/src/main/java/org/jeecg/modules/tpmEquipmentTree/vo/TpmEquipmentTreeNodeVO.java

@@ -0,0 +1,43 @@
+package org.jeecg.modules.tpmEquipmentTree.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.jeecg.common.aspect.annotation.Dict;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class TpmEquipmentTreeNodeVO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**主键*/
+    @TableId(type = IdType.ASSIGN_ID)
+    @ApiModelProperty(value = "主键")
+    private java.lang.String id;
+    /**设备分类名称*/
+    @Excel(name = "设备分类名称", width = 15)
+    @ApiModelProperty(value = "设备分类名称")
+    private java.lang.String name;
+    /**上级ID*/
+    @Excel(name = "上级ID", width = 15)
+    @ApiModelProperty(value = "上级ID")
+    private java.lang.String parentid;
+    /**是否有子节点*/
+    @Excel(name = "是否有子节点", width = 15, dicCode = "yn")
+    @Dict(dicCode = "yn")
+    @ApiModelProperty(value = "是否有子节点")
+    private java.lang.String hasChild;
+
+    /**
+     *
+     * 子集
+     */
+    private List<TpmEquipmentTreeNodeVO> children;
+
+}