Commit 7ca90fa8 authored by chenyuefang's avatar chenyuefang

工程类型

parent a2255d2f
package com.dsk.cscec.controller;
import com.dsk.common.core.domain.R;
import com.dsk.cscec.domain.DProjectType;
import com.dsk.cscec.domain.TreeSelect;
import com.dsk.cscec.service.DProjectTypeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* 维表:工程类型,源于IPM(DProjectType)表控制层
......@@ -13,7 +18,7 @@ import javax.annotation.Resource;
* @since 2024-01-05 11:45:43
*/
@RestController
@RequestMapping("dProjectType")
@RequestMapping("/dProjectType")
public class DProjectTypeController {
/**
* 服务对象
......@@ -21,6 +26,24 @@ public class DProjectTypeController {
@Resource
private DProjectTypeService dProjectTypeService;
/**
* 获取所有工程类型
* @param
* @return
*/
@GetMapping("/getAll")
public R<List<TreeSelect>> selectList() {
return R.ok(dProjectTypeService.getList(new DProjectType()));
}
/**
* 根据工程类型id获取子级
* @param projectTypeId
* @return
*/
@GetMapping("/getChildren")
public R<List<DProjectType>> getChildren(String projectTypeId) {
return R.ok(dProjectTypeService.getChildren(projectTypeId));
}
}
package com.dsk.cscec.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.util.ArrayList;
import java.util.Date;
import java.io.Serializable;
import java.util.List;
/**
* 维表:工程类型,源于IPM(DProjectType)实体类
......@@ -62,4 +65,7 @@ public class DProjectType implements Serializable {
* 数据加载时间
*/
private Date loadTime;
@TableField(exist = false)
private List<DProjectType> children = new ArrayList<DProjectType>();
}
......@@ -43,4 +43,10 @@ public class TreeSelect implements Serializable {
this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
public TreeSelect(DProjectType type) {
this.id = type.getProjectTypeId();
this.label = type.getProjectTypeName();
this.children = type.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
}
......@@ -2,6 +2,9 @@ package com.dsk.cscec.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.dsk.cscec.domain.DProjectType;
import com.dsk.cscec.domain.TreeSelect;
import java.util.List;
/**
* 维表:工程类型,源于IPM(DProjectType)表服务接口
......@@ -11,5 +14,13 @@ import com.dsk.cscec.domain.DProjectType;
*/
public interface DProjectTypeService extends IService<DProjectType> {
List<TreeSelect> getList(DProjectType type);
/**
* 根据工程类型id获取下一级
*
* @param projectTypeId
* @return
*/
List<DProjectType> getChildren(String projectTypeId);
}
package com.dsk.cscec.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsk.cscec.domain.DProjectType;
import com.dsk.cscec.domain.TreeSelect;
import com.dsk.cscec.mapper.DProjectTypeMapper;
import com.dsk.cscec.service.DProjectTypeService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 维表:工程类型,源于IPM(DProjectType)表服务实现类
......@@ -19,4 +27,85 @@ public class DProjectTypeServiceImpl extends ServiceImpl<DProjectTypeMapper, DPr
@Resource
private DProjectTypeMapper baseMapper;
@Override
public List<TreeSelect> getList(DProjectType bo) {
return buildTree(baseMapper.selectList(buildQueryWrapper(bo))).stream().map(TreeSelect::new).collect(Collectors.toList());
}
@Override
public List<DProjectType> getChildren(String projectTypeId) {
DProjectType bo = new DProjectType();
if (StringUtils.isNotBlank(projectTypeId)) {
bo.setParentId(projectTypeId);
} else {
bo.setLevelNo(1l);
}
return baseMapper.selectList(buildQueryWrapper(bo));
}
private LambdaQueryWrapper<DProjectType> buildQueryWrapper(DProjectType bo) {
LambdaQueryWrapper<DProjectType> lqw = Wrappers.lambdaQuery();
lqw.eq(ObjectUtil.isNotNull(bo.getProjectTypeKey()), DProjectType::getProjectTypeKey, bo.getProjectTypeKey());
// lqw.like(StringUtils.isNotBlank(bo.getProjectTypeName()), DProjectType::getProjectTypeName, bo.getProjectTypeName());
lqw.eq(ObjectUtil.isNotNull(bo.getLevelNo()), DProjectType::getLevelNo, bo.getLevelNo());
lqw.eq(StringUtils.isNotBlank(bo.getProjectTypeId()), DProjectType::getProjectTypeId, bo.getProjectTypeId());
lqw.eq(StringUtils.isNotBlank(bo.getParentId()), DProjectType::getParentId, bo.getParentId());
return lqw;
}
public List<DProjectType> buildTree(List<DProjectType> types) {
List<DProjectType> returnList = new ArrayList<DProjectType>();
List<String> tempList = new ArrayList<String>();
for (DProjectType type : types) {
tempList.add(type.getProjectTypeId());
}
for (DProjectType type : types) {
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(type.getParentId())) {
recursionFn(types, type);
returnList.add(type);
}
}
if (returnList.isEmpty()) {
returnList = types;
}
return returnList;
}
/**
* 递归列表
*/
private void recursionFn(List<DProjectType> list, DProjectType t) {
// 得到子节点列表
List<DProjectType> childList = getChildList(list, t);
t.setChildren(childList);
for (DProjectType tChild : childList) {
if (hasChild(list, tChild)) {
recursionFn(list, tChild);
}
}
}
/**
* 得到子节点列表
*/
private List<DProjectType> getChildList(List<DProjectType> list, DProjectType t) {
List<DProjectType> tlist = new ArrayList<DProjectType>();
for (DProjectType n : list) {
if (ObjectUtil.isNotNull(n.getParentId()) && n.getParentId().equals(t.getProjectTypeId())) {
tlist.add(n);
}
}
return tlist;
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<DProjectType> list, DProjectType t) {
return getChildList(list, t).size() > 0;
}
}
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