家庭教育手册-学习
This commit is contained in:
@ -73,6 +73,14 @@ public class TreeSelect implements Serializable
|
||||
this.children = byMicrocourse.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
//下拉树构造器
|
||||
public TreeSelect(ByFamilyedu byFamilyedu) {
|
||||
|
||||
this.id = byFamilyedu.getId();
|
||||
this.label = byFamilyedu.getTitle();
|
||||
this.children = byFamilyedu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
//下拉树构造器
|
||||
public TreeSelect(ByMath bymath) {
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.ruoyi.project.benyi.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.project.benyi.domain.ByMicrocourse;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -44,6 +45,16 @@ public class ByFamilyeduController extends BaseController {
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询微型课程列表
|
||||
*/
|
||||
@Log(title = "家庭教育", businessType = BusinessType.QUERY)
|
||||
@GetMapping("/treeselect")
|
||||
public AjaxResult treeselect(ByFamilyedu byFamilyedu) {
|
||||
List<ByFamilyedu> list = byFamilyeduService.selectByFamilyeduListTree(byFamilyedu);
|
||||
return AjaxResult.success(byFamilyeduService.buildFamilyeduTreeSelect(list));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出家庭教育列表
|
||||
*/
|
||||
|
@ -5,6 +5,9 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
|
||||
import com.ruoyi.framework.web.domain.BaseEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 家庭教育对象 by_familyedu
|
||||
*
|
||||
@ -43,6 +46,11 @@ public class ByFamilyedu extends BaseEntity {
|
||||
@Excel(name = "序号")
|
||||
private Long sort;
|
||||
|
||||
/**
|
||||
* 树状子类
|
||||
*/
|
||||
private List<ByFamilyedu> children = new ArrayList<ByFamilyedu>();
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
@ -83,6 +91,14 @@ public class ByFamilyedu extends BaseEntity {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public List<ByFamilyedu> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<ByFamilyedu> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
@ -3,6 +3,7 @@ package com.ruoyi.project.benyi.mapper;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.project.benyi.domain.ByFamilyedu;
|
||||
import com.ruoyi.project.benyi.domain.ByMicrocourse;
|
||||
|
||||
/**
|
||||
* 家庭教育Mapper接口
|
||||
@ -27,6 +28,14 @@ public interface ByFamilyeduMapper {
|
||||
*/
|
||||
public List<ByFamilyedu> selectByFamilyeduList(ByFamilyedu byFamilyedu);
|
||||
|
||||
/**
|
||||
* 查询家庭教育列表
|
||||
*
|
||||
* @param byFamilyedu 家庭教育
|
||||
* @return 家庭教育集合
|
||||
*/
|
||||
public List<ByFamilyedu> selectByFamilyeduListTree(ByFamilyedu byFamilyedu);
|
||||
|
||||
/**
|
||||
* 新增家庭教育
|
||||
*
|
||||
|
@ -2,7 +2,9 @@ package com.ruoyi.project.benyi.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.framework.web.domain.TreeSelect;
|
||||
import com.ruoyi.project.benyi.domain.ByFamilyedu;
|
||||
import com.ruoyi.project.benyi.domain.ByMicrocourse;
|
||||
|
||||
/**
|
||||
* 家庭教育Service接口
|
||||
@ -27,6 +29,31 @@ public interface IByFamilyeduService {
|
||||
*/
|
||||
public List<ByFamilyedu> selectByFamilyeduList(ByFamilyedu byFamilyedu);
|
||||
|
||||
/**
|
||||
* 查询家庭教育列表
|
||||
*
|
||||
* @param byFamilyedu 家庭教育
|
||||
* @return 家庭教育集合
|
||||
*/
|
||||
public List<ByFamilyedu> selectByFamilyeduListTree(ByFamilyedu byFamilyedu);
|
||||
|
||||
/**
|
||||
* 构建前端所需要树结构
|
||||
*
|
||||
* @param byFamilyedus 部门列表
|
||||
* @return 树结构列表
|
||||
*/
|
||||
public List<ByFamilyedu> buildFamilyeduDetailTree(List<ByFamilyedu> byFamilyedus);
|
||||
|
||||
/**
|
||||
* 构建前端所需要下拉树结构
|
||||
*
|
||||
* @param byFamilyedus 部门列表
|
||||
* @return 下拉树结构列表
|
||||
*/
|
||||
public List<TreeSelect> buildFamilyeduTreeSelect(List<ByFamilyedu> byFamilyedus);
|
||||
|
||||
|
||||
/**
|
||||
* 新增家庭教育
|
||||
*
|
||||
|
@ -1,8 +1,14 @@
|
||||
package com.ruoyi.project.benyi.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.web.domain.TreeSelect;
|
||||
import com.ruoyi.project.benyi.domain.ByMicrocourse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.project.benyi.mapper.ByFamilyeduMapper;
|
||||
@ -42,6 +48,101 @@ public class ByFamilyeduServiceImpl implements IByFamilyeduService {
|
||||
return byFamilyeduMapper.selectByFamilyeduList(byFamilyedu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询家庭教育列表
|
||||
*
|
||||
* @param byFamilyedu 家庭教育
|
||||
* @return 家庭教育集合
|
||||
*/
|
||||
@Override
|
||||
public List<ByFamilyedu> selectByFamilyeduListTree(ByFamilyedu byFamilyedu){
|
||||
return byFamilyeduMapper.selectByFamilyeduList(byFamilyedu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建前端所需要树结构
|
||||
*
|
||||
* @param byFamilyedus 家庭教育列表
|
||||
* @return 树结构列表
|
||||
*/
|
||||
@Override
|
||||
public List<ByFamilyedu> buildFamilyeduDetailTree(List<ByFamilyedu> byFamilyedus) {
|
||||
//System.out.println("start---");
|
||||
List<ByFamilyedu> returnList = new ArrayList<ByFamilyedu>();
|
||||
List<Long> tempList = new ArrayList<Long>();
|
||||
for (ByFamilyedu item : byFamilyedus) {
|
||||
tempList.add(item.getId());
|
||||
}
|
||||
for (Iterator<ByFamilyedu> iterator = byFamilyedus.iterator(); iterator.hasNext(); ) {
|
||||
ByFamilyedu item = (ByFamilyedu) iterator.next();
|
||||
//System.out.println("test==="+!tempList.contains(item.getParentId()));
|
||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
||||
if (!tempList.contains(item.getParentid())) {
|
||||
recursionFn(byFamilyedus, item);
|
||||
returnList.add(item);
|
||||
}
|
||||
}
|
||||
if (returnList.isEmpty()) {
|
||||
returnList = byFamilyedus;
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建前端所需要下拉树结构
|
||||
*
|
||||
* @param byFamilyedus 部门列表
|
||||
* @return 下拉树结构列表
|
||||
*/
|
||||
@Override
|
||||
public List<TreeSelect> buildFamilyeduTreeSelect(List<ByFamilyedu> byFamilyedus) {
|
||||
List<ByFamilyedu> byFamilyeduTrees = buildFamilyeduDetailTree(byFamilyedus);
|
||||
return byFamilyeduTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*/
|
||||
private void recursionFn(List<ByFamilyedu> list, ByFamilyedu t) {
|
||||
// 得到子节点列表
|
||||
List<ByFamilyedu> childList = getChildList(list, t);
|
||||
t.setChildren(childList);
|
||||
for (ByFamilyedu tChild : childList) {
|
||||
if (hasChild(list, tChild)) {
|
||||
// 判断是否有子节点
|
||||
Iterator<ByFamilyedu> it = childList.iterator();
|
||||
while (it.hasNext()) {
|
||||
ByFamilyedu n = (ByFamilyedu) it.next();
|
||||
recursionFn(list, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到子节点列表
|
||||
*/
|
||||
private List<ByFamilyedu> getChildList(List<ByFamilyedu> list, ByFamilyedu t) {
|
||||
List<ByFamilyedu> tlist = new ArrayList<ByFamilyedu>();
|
||||
Iterator<ByFamilyedu> it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
ByFamilyedu n = (ByFamilyedu) it.next();
|
||||
if (StringUtils.isNotNull(n.getParentid()) && n.getParentid().longValue() == t.getId().longValue()) {
|
||||
//System.out.println("parentid="+n.getParentId().longValue()+"---"+t.getId().longValue());
|
||||
tlist.add(n);
|
||||
}
|
||||
}
|
||||
return tlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有子节点
|
||||
*/
|
||||
private boolean hasChild(List<ByFamilyedu> list, ByFamilyedu t) {
|
||||
return getChildList(list, t).size() > 0 ? true : false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增家庭教育
|
||||
*
|
||||
|
Reference in New Issue
Block a user