Commit ca60e482 authored by sml's avatar sml

树树形结构

parent 27618cd1
package com.jz.dmp.modules.controller.bean;
import java.util.List;
import com.jz.dmp.modules.model.DmpNavigationTree;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**DMP资源导航树Dto
* @author ybz
......@@ -9,5 +12,21 @@ import io.swagger.annotations.ApiModel;
*/
@ApiModel(value = "DMP资源导航树Dto", description = "DMP资源导航树Dto")
public class DmpNavigationTreeDto extends DmpNavigationTree {
/**
*
*/
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "孩子节点")
private List<DmpNavigationTreeDto> children;
public List<DmpNavigationTreeDto> getChildren() {
return children;
}
public void setChildren(List<DmpNavigationTreeDto> children) {
this.children = children;
}
}
......@@ -42,121 +42,6 @@ public class DmpPermissionController {
@Autowired
private DmpPermissionService dmpPermissionService;
/**列表查询资源表
* @param dmpPermissionRequest
* @return
*/
//@RequestMapping(method = RequestMethod.POST, value = "/findList")
//@ApiOperation(value = "列表查询资源表", notes = "列表查询资源表")
public PageInfoResponse<DmpPermissionDto> findList(@RequestBody DmpPermissionRequest dmpPermissionRequest, HttpServletRequest httpRequest){
PageInfoResponse<DmpPermissionDto> pageInfo = new PageInfoResponse<DmpPermissionDto>();
try {
pageInfo = dmpPermissionService.findList(dmpPermissionRequest, httpRequest);
} catch (Exception e) {
pageInfo.setMessage("查询失败");
pageInfo.setCode(StatuConstant.FAILURE_CODE);
e.printStackTrace();
}
return pageInfo;
}
/**主键查询资源表
* @param dmpPermissionRequest
* @return
*/
//@RequestMapping(method = RequestMethod.POST, value = "/view")
//@ApiOperation(value = "主键查询资源表", notes = "主键查询资源表")
public BaseBeanResponse<DmpPermissionDto> view(@RequestBody DmpPermissionRequest dmpPermissionRequest, HttpServletRequest httpRequest){
BaseBeanResponse<DmpPermissionDto> baseBeanResponse = new BaseBeanResponse<DmpPermissionDto>();
try {
baseBeanResponse = dmpPermissionService.findById(dmpPermissionRequest, httpRequest);
} catch (Exception e) {
baseBeanResponse.setMessage("请求失败");
baseBeanResponse.setCode(StatuConstant.FAILURE_CODE);
e.printStackTrace();
}
return baseBeanResponse;
}
/**删除资源表
* @param dmpPermissionRequest
* @return
*/
//@RequestMapping(method = RequestMethod.POST, value = "/delete")
//@ApiOperation(value = "删除资源表", notes = "删除资源表")
public BaseResponse delete(@RequestBody DmpPermissionRequest dmpPermissionRequest, HttpServletRequest httpRequest){
BaseResponse baseResponse = new BaseResponse();
try {
baseResponse = dmpPermissionService.deleteById(dmpPermissionRequest, httpRequest);
} catch (Exception e) {
baseResponse.setMessage("删除失败");
baseResponse.setCode(StatuConstant.FAILURE_CODE);
e.printStackTrace();
}
return baseResponse;
}
/**新增资源表
* @param dmpPermissionRequest
* @return
*/
//@RequestMapping(method = RequestMethod.POST, value = "/add")
//@ApiOperation(value = "新增资源表", notes = "新增资源表")
public BaseBeanResponse<DmpPermission> add(@RequestBody DmpPermission dmpPermission, HttpServletRequest httpRequest){
BaseBeanResponse<DmpPermission> baseBeanResponse = new BaseBeanResponse<DmpPermission>();
try {
baseBeanResponse = dmpPermissionService.add(dmpPermission, httpRequest);
} catch (Exception e) {
baseBeanResponse.setMessage("新增失败");
baseBeanResponse.setCode(StatuConstant.FAILURE_CODE);
e.printStackTrace();
}
return baseBeanResponse;
}
/**批量新增资源表
* @param dmpPermissionRequest
* @return
*/
//@RequestMapping(method = RequestMethod.POST, value = "/addBatch")
//@ApiOperation(value = "批量新增资源表", notes = "批量新增资源表")
public BaseBeanResponse<DmpPermissionBatch> addBatch(@RequestBody DmpPermissionBatch dmpPermissionBatch, HttpServletRequest httpRequest){
BaseBeanResponse<DmpPermissionBatch> baseBeanResponse = new BaseBeanResponse<DmpPermissionBatch>();
try {
baseBeanResponse = dmpPermissionService.addBatch(dmpPermissionBatch, httpRequest);
} catch (Exception e) {
baseBeanResponse.setMessage("批量新增失败");
baseBeanResponse.setCode(StatuConstant.FAILURE_CODE);
e.printStackTrace();
}
return baseBeanResponse;
}
/**修改资源表
* @param dmpPermissionRequest
* @return
*/
//@RequestMapping(method = RequestMethod.POST, value = "/edit")
//@ApiOperation(value = "修改资源表", notes = "修改资源表")
public BaseBeanResponse<DmpPermission> edit(@RequestBody DmpPermission dmpPermission, HttpServletRequest httpRequest){
BaseBeanResponse<DmpPermission> baseBeanResponse = new BaseBeanResponse<DmpPermission>();
try {
baseBeanResponse = dmpPermissionService.edit(dmpPermission, httpRequest);
} catch (Exception e) {
baseBeanResponse.setMessage("修改失败");
baseBeanResponse.setCode(StatuConstant.FAILURE_CODE);
e.printStackTrace();
}
return baseBeanResponse;
}
/**根据父级资源编码,获取当前登录用户所有资源
* @param dmpPermissionRequest
* @return
......
package com.jz.dmp.modules.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.jz.common.bean.BaseBeanResponse;
......@@ -18,6 +22,7 @@ import com.jz.dmp.modules.controller.bean.DmpNavigationTreeRequest;
import com.jz.dmp.modules.controller.bean.MyDmpNavigationTreeConverter;
import com.jz.dmp.modules.dao.DmpNavigationTreeDao;
import com.jz.dmp.modules.model.DmpNavigationTree;
import com.jz.dmp.modules.model.DmpPermission;
import com.jz.dmp.modules.service.DmpNavigationTreeService;
/**
......@@ -145,10 +150,6 @@ public class DmpNavigationTreeServiceImpl extends BaseService implements DmpNavi
if (!StringUtils.isEmpty(dmpNavigationTreeRequest.getIsEnable())) {
dmpNavigationTree.setIsEnable(dmpNavigationTreeRequest.getIsEnable());
}
//父节点ID
if (dmpNavigationTreeRequest.getParentId() != null) {
dmpNavigationTree.setParentId(dmpNavigationTreeRequest.getParentId());
}
//数据状态
if (!StringUtils.isEmpty(dmpNavigationTreeRequest.getDataStatus())) {
dmpNavigationTree.setDataStatus(dmpNavigationTreeRequest.getDataStatus());
......@@ -165,12 +166,62 @@ public class DmpNavigationTreeServiceImpl extends BaseService implements DmpNavi
List<DmpNavigationTree> list = dmpNavigationTreeDao.queryAll(dmpNavigationTree);
List<DmpNavigationTreeDto> dtos = MyDmpNavigationTreeConverter.INSTANCE().domain2dto(list);
dtos = dmpArrangeTree(dmpNavigationTreeRequest.getParentId(), dtos);
baseBeanResponse.setCode(StatuConstant.SUCCESS_CODE);
baseBeanResponse.setMessage("查询成功");
baseBeanResponse.setDatas(dtos);
return baseBeanResponse;
}
/**
* @Title: treeArrangeTree
* @Description: TODO(将所有的树资源整理成树形结构)
* @param @param dmpNavigationTreeDtoes
* @param @return
* @param @throws Exception 参数
* @return List<DmpNavigationTreeDto> 返回类型
* @throws
*/
private List<DmpNavigationTreeDto> dmpArrangeTree(Integer parentId, List<DmpNavigationTreeDto> dmpNavigationTreeDtoes)throws Exception{
Map<Integer, List<DmpNavigationTreeDto>> dictMap = dmpNavigationTreeDtoes.stream().collect(Collectors.groupingBy(DmpNavigationTreeDto::getParentId));
List<DmpNavigationTreeDto> trees = dictMap.get(parentId);//获取顶层资源
if (!CollectionUtils.isEmpty(trees)) {
for (DmpNavigationTreeDto tree : trees) {
tree = arrangeChildren(tree, dictMap);
}
}
return trees;
}
/**
* @Title: arrangeChildren
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param treeDto
* @param @param dictMap
* @param @return
* @param @throws Exception 参数
* @return DmpNavigationTreeDto 返回类型
* @throws
*/
private DmpNavigationTreeDto arrangeChildren(DmpNavigationTreeDto treeDto, Map<Integer, List<DmpNavigationTreeDto>> dictMap)throws Exception{
Integer treeId = treeDto.getId();
List<DmpNavigationTreeDto> children = dictMap.get(treeId);
if (!CollectionUtils.isEmpty(children)) {
for (DmpNavigationTreeDto child : children) {
child = arrangeChildren(child, dictMap);
}
treeDto.setChildren(children);
}
return treeDto;
}
@Override
public DmpNavigationTree getByProjectIdAndName(Long projectId, String name) throws Exception {
......
......@@ -79,7 +79,7 @@
and UPDATE_TIME = #{updateTime}
</if>
<if test="projectId != null">
and PROJECT_ID = #{projectId}
and (PROJECT_ID = #{projectId} or PROJECT_ID = 0)
</if>
<if test="parentId != null">
and PARENT_ID = #{parentId}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment