根据树id查找对应层级的节点
This commit is contained in:
@@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -89,5 +90,12 @@ public class ZlTreeController extends BaseController<ZlTree> {
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/queryTree")
|
||||
@ApiOperation("根据树id判断树层级并查询对应的节点")
|
||||
public ResponseMessage<ZlTree> queryTree(@Param("treeId") String treeId){
|
||||
ZlTree zlTree = iZlTreeService.queryTree(treeId);
|
||||
return Result.success(zlTree);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -45,5 +45,10 @@ public interface IZlTreeService extends IService<ZlTree> {
|
||||
*/
|
||||
int topping(String id);
|
||||
|
||||
|
||||
/**
|
||||
* 根据树id判断树层级并查询对应的节点
|
||||
* @param treeId
|
||||
* @return
|
||||
*/
|
||||
ZlTree queryTree(String treeId);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -130,4 +131,27 @@ public class ZlTreeServiceImpl extends ServiceImpl<ZlTreeDao, ZlTree> implements
|
||||
public int topping(String id) {
|
||||
return zlTreeDao.topping(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据树id判断树层级并查询对应的节点
|
||||
* @param treeId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ZlTree queryTree(String treeId) {
|
||||
ZlTree zlTree = zlTreeDao.selectById(treeId);
|
||||
if (ObjectUtils.isNotEmpty(zlTree)) {
|
||||
if (ObjectUtils.isNotEmpty(zlTree.getParentId())) {
|
||||
ZlTree zlTreeParents = zlTreeDao.selectById(zlTree.getParentId());
|
||||
if (ObjectUtils.isEmpty(zlTreeParents.getParentId())) {
|
||||
return zlTree;
|
||||
} else {
|
||||
return zlTreeParents;
|
||||
}
|
||||
} else {
|
||||
return zlTree;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user