提交树形结构代码

This commit is contained in:
duanwenbin
2021-07-14 16:17:50 +08:00
parent 8aed75a8f0
commit 78b99accc9
9 changed files with 269 additions and 0 deletions
@@ -0,0 +1,51 @@
package com.adc.da.slrs.sarTree.controller;
import com.adc.da.base.web.BaseController;
import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result;
import com.adc.da.slrs.sarRole.entity.TsRole;
import com.adc.da.slrs.sarTree.entity.SarModel;
import com.adc.da.slrs.sarTree.entity.SarVPPS;
import com.adc.da.slrs.sarTree.service.SarModelService;
import com.adc.da.slrs.sarTree.service.SarVPPSService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@Api(tags = "|获取树列表|")
@RequestMapping("/api/sarVpps")
public class TreeController extends BaseController<SarVPPS> {
@Autowired
private SarVPPSService sarVPPSService;
@Autowired
private SarModelService sarModelService;
@ApiOperation("VPPS树列表")
@GetMapping("/tree/list1")
public ResponseMessage<List<SarVPPS>> getTreeList1(){
List<SarVPPS> sarVpps = sarVPPSService.findTreeAll();
return Result.success(sarVpps);
}
@ApiOperation("模块结构单元树列表")
@GetMapping("/tree/list2")
public ResponseMessage<List<SarModel>> getTreeList2(){
List<SarModel> sarVpps = sarModelService.findTreeAll();
return Result.success(sarVpps);
}
// @ApiOperation("根据角色名筛选角色")
// @GetMapping("/tree/node/list")
// public ResponseMessage<Map<String,Object>> getTreeNodeList(String code){
// Map<String,Object> map = sarVPPSService.findTreeAll(code);
// return Result.success(map);
// }
}
@@ -0,0 +1,15 @@
package com.adc.da.slrs.sarTree.dao;
import com.adc.da.slrs.sarTree.entity.SarModel;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface SarModelDao extends BaseMapper<SarModel> {
@Select("select id,pid,CONCAT(name,model) name,features from sar_model_tree where 1=1 and isnull(pid)")
List<SarModel> findTreeAll();
@Select("select id,pid,CONCAT(name,model) name,features from sar_model_tree where 1=1 and pid = #{pid}")
List<SarModel> selectList(@Param("pid") String pid);
}
@@ -0,0 +1,15 @@
package com.adc.da.slrs.sarTree.dao;
import com.adc.da.slrs.sarTree.entity.SarVPPS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface SarVPPSDao extends BaseMapper<SarVPPS> {
@Select("select id,pid,CONCAT(VPPS_CODE,CHINESE_NAME,ENGLISH_NAME) name,code from sar_vpps_tree where 1=1 and isnull(pid)")
List<SarVPPS> findTreeAll();
@Select("select id,pid,CONCAT(VPPS_CODE,CHINESE_NAME,ENGLISH_NAME) name,code from sar_vpps_tree where 1=1 and pid = #{pid}")
List<SarVPPS> selectList(@Param("pid") String pid);
}
@@ -0,0 +1,35 @@
package com.adc.da.slrs.sarTree.entity;
import com.adc.da.base.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Transient;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@ApiModel(value="SarModel对象", description="")
public class SarModel extends BaseEntity {
private static final long serialVersionUID = 1L;
private String id;
private String name;
private String pid;
private String model;
private String features;
private String delFlag;
@Transient
private List<SarModel> children;
}
@@ -0,0 +1,38 @@
package com.adc.da.slrs.sarTree.entity;
import com.adc.da.base.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Transient;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@ApiModel(value="SarVPPS对象", description="")
public class SarVPPS extends BaseEntity {
private static final long serialVersionUID = 1L;
private String id;
private String vppsCode;
private String pid;
private String code;
private String chineseName;
private String englishName;
private String delFlag;
@Transient
private List<SarVPPS> children;
@Transient
private String name;
}
@@ -0,0 +1,11 @@
package com.adc.da.slrs.sarTree.service;
import com.adc.da.slrs.sarTree.entity.SarModel;
import com.adc.da.slrs.sarTree.entity.SarVPPS;
import java.util.List;
public interface SarModelService {
List<SarModel> findTreeAll();
}
@@ -0,0 +1,9 @@
package com.adc.da.slrs.sarTree.service;
import com.adc.da.slrs.sarTree.entity.SarVPPS;
import java.util.List;
public interface SarVPPSService {
List<SarVPPS> findTreeAll();
}
@@ -0,0 +1,47 @@
package com.adc.da.slrs.sarTree.service.impl;
import com.adc.da.slrs.sarTree.dao.SarModelDao;
import com.adc.da.slrs.sarTree.entity.SarModel;
import com.adc.da.slrs.sarTree.service.SarModelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional(value = "transactionManager", readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
public class SarModelServiceImpl implements SarModelService {
private static final Logger logger = LoggerFactory.getLogger(SarModelServiceImpl.class);
@Autowired
private SarModelDao sarModelDao;
@Override
public List<SarModel> findTreeAll() {
//查询父级都为null的数据
List<SarModel> sarVppsList = sarModelDao.findTreeAll();
for (SarModel sarVppsOne : sarVppsList) {
sarVppsOne.setChildren(getChildren(sarVppsOne));
}
return sarVppsList;
}
/**
* 递归调用获取子节点
*
* @param parent:父节点
* @return List<TsResource>
*/
private List<SarModel> getChildren(SarModel parent) {
String pid = parent.getId();
List<SarModel> children = sarModelDao.selectList(pid);
for (SarModel sarVppsOne : children) {
sarVppsOne.setChildren(getChildren((sarVppsOne)));
}
return children;
}
}
@@ -0,0 +1,48 @@
package com.adc.da.slrs.sarTree.service.impl;
import com.adc.da.slrs.sarResource.entity.TsResource;
import com.adc.da.slrs.sarTree.dao.SarVPPSDao;
import com.adc.da.slrs.sarTree.entity.SarVPPS;
import com.adc.da.slrs.sarTree.service.SarVPPSService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional(value = "transactionManager", readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
public class SarVPPSServiceImpl implements SarVPPSService {
private static final Logger logger = LoggerFactory.getLogger(SarVPPSServiceImpl.class);
@Autowired
private SarVPPSDao sarVPPSDao;
@Override
public List<SarVPPS> findTreeAll() {
//查询父级都为null的数据
List<SarVPPS> sarVppsList = sarVPPSDao.findTreeAll();
for (SarVPPS sarVppsOne:sarVppsList) {
sarVppsOne.setChildren(getChildren(sarVppsOne));
}
return sarVppsList;
}
/**
* 递归调用获取子节点
* @param parent:父节点
* @return List<TsResource>
*/
private List<SarVPPS> getChildren(SarVPPS parent){
String pid = parent.getId();
List<SarVPPS> children = sarVPPSDao.selectList(pid);
for(SarVPPS sarVppsOne:children){
sarVppsOne.setChildren(getChildren((sarVppsOne)));
}
return children;
}
}