微型课程学习

This commit is contained in:
zhanglipeng
2021-05-15 11:33:55 +08:00
parent 5003272c59
commit 7b2844b0c2
9 changed files with 395 additions and 4 deletions

View File

@ -4,10 +4,7 @@ import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.project.benyi.domain.ByAssessmentcontent;
import com.ruoyi.project.benyi.domain.ByDayFlowDetail;
import com.ruoyi.project.benyi.domain.ByMath;
import com.ruoyi.project.benyi.domain.ByTheme;
import com.ruoyi.project.benyi.domain.*;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysMenu;
@ -68,6 +65,14 @@ public class TreeSelect implements Serializable
this.children = bytheme.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
//下拉树构造器
public TreeSelect(ByMicrocourse byMicrocourse) {
this.id = byMicrocourse.getId();
this.label = byMicrocourse.getTitle();
this.children = byMicrocourse.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
//下拉树构造器
public TreeSelect(ByMath bymath) {

View File

@ -44,6 +44,16 @@ public class ByMicrocourseController extends BaseController {
return getDataTable(list);
}
/**
* 查询微型课程列表
*/
@Log(title = "微型课程学习", businessType = BusinessType.QUERY)
@GetMapping("/treeselect")
public AjaxResult treeselect(ByMicrocourse byMicrocourse) {
List<ByMicrocourse> list = byMicrocourseService.selectByMicrocourseListTree(byMicrocourse);
return AjaxResult.success(byMicrocourseService.buildMicrocourseTreeSelect(list));
}
/**
* 导出微型课程列表
*/

View File

@ -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_microcourse
*
@ -55,6 +58,16 @@ public class ByMicrocourse extends BaseEntity {
@Excel(name = "序号")
private Long sort;
/**
* 树状父类ID
*/
private Long parentId;
/**
* 树状子类
*/
private List<ByMicrocourse> children = new ArrayList<ByMicrocourse>();
public void setId(Long id) {
this.id = id;
}
@ -119,6 +132,22 @@ public class ByMicrocourse extends BaseEntity {
return sort;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public List<ByMicrocourse> getChildren() {
return children;
}
public void setChildren(List<ByMicrocourse> children) {
this.children = children;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
@ -131,6 +160,7 @@ public class ByMicrocourse extends BaseEntity {
.append("upanddown", getUpanddown())
.append("sort", getSort())
.append("createTime", getCreateTime())
.append("parentid", getParentId())
.toString();
}
}

View File

@ -27,6 +27,14 @@ public interface ByMicrocourseMapper {
*/
public List<ByMicrocourse> selectByMicrocourseList(ByMicrocourse byMicrocourse);
/**
* 查询微型课程列表
*
* @param byMicrocourse 微型课程
* @return 微型课程集合
*/
public List<ByMicrocourse> selectByMicrocourseListTree(ByMicrocourse byMicrocourse);
/**
* 新增微型课程
*

View File

@ -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.ByMicrocourse;
import com.ruoyi.project.benyi.domain.ByTheme;
/**
* 微型课程Service接口
@ -27,6 +29,30 @@ public interface IByMicrocourseService {
*/
public List<ByMicrocourse> selectByMicrocourseList(ByMicrocourse byMicrocourse);
/**
* 查询微型课程列表
*
* @param byMicrocourse 微型课程
* @return 微型课程集合
*/
public List<ByMicrocourse> selectByMicrocourseListTree(ByMicrocourse byMicrocourse);
/**
* 构建前端所需要树结构
*
* @param byMicrocourses 部门列表
* @return 树结构列表
*/
public List<ByMicrocourse> buildMicrocourseDetailTree(List<ByMicrocourse> byMicrocourses);
/**
* 构建前端所需要下拉树结构
*
* @param byMicrocourses 部门列表
* @return 下拉树结构列表
*/
public List<TreeSelect> buildMicrocourseTreeSelect(List<ByMicrocourse> byMicrocourses);
/**
* 新增微型课程
*

View File

@ -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.ByTheme;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.benyi.mapper.ByMicrocourseMapper;
@ -42,6 +48,100 @@ public class ByMicrocourseServiceImpl implements IByMicrocourseService {
return byMicrocourseMapper.selectByMicrocourseList(byMicrocourse);
}
/**
* 查询微型课程列表
*
* @param byMicrocourse 微型课程
* @return 微型课程集合
*/
@Override
public List<ByMicrocourse> selectByMicrocourseListTree(ByMicrocourse byMicrocourse){
return byMicrocourseMapper.selectByMicrocourseListTree(byMicrocourse);
}
/**
* 构建前端所需要树结构
*
* @param byMicrocourses 部门列表
* @return 树结构列表
*/
@Override
public List<ByMicrocourse> buildMicrocourseDetailTree(List<ByMicrocourse> byMicrocourses) {
//System.out.println("start---");
List<ByMicrocourse> returnList = new ArrayList<ByMicrocourse>();
List<Long> tempList = new ArrayList<Long>();
for (ByMicrocourse item : byMicrocourses) {
tempList.add(item.getId());
}
for (Iterator<ByMicrocourse> iterator = byMicrocourses.iterator(); iterator.hasNext(); ) {
ByMicrocourse item = (ByMicrocourse) iterator.next();
//System.out.println("test==="+!tempList.contains(item.getParentId()));
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(item.getParentId())) {
recursionFn(byMicrocourses, item);
returnList.add(item);
}
}
if (returnList.isEmpty()) {
returnList = byMicrocourses;
}
return returnList;
}
/**
* 构建前端所需要下拉树结构
*
* @param byMicrocourses 部门列表
* @return 下拉树结构列表
*/
@Override
public List<TreeSelect> buildMicrocourseTreeSelect(List<ByMicrocourse> byMicrocourses) {
List<ByMicrocourse> byMicrocourseTrees = buildMicrocourseDetailTree(byMicrocourses);
return byMicrocourseTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
}
/**
* 递归列表
*/
private void recursionFn(List<ByMicrocourse> list, ByMicrocourse t) {
// 得到子节点列表
List<ByMicrocourse> childList = getChildList(list, t);
t.setChildren(childList);
for (ByMicrocourse tChild : childList) {
if (hasChild(list, tChild)) {
// 判断是否有子节点
Iterator<ByMicrocourse> it = childList.iterator();
while (it.hasNext()) {
ByMicrocourse n = (ByMicrocourse) it.next();
recursionFn(list, n);
}
}
}
}
/**
* 得到子节点列表
*/
private List<ByMicrocourse> getChildList(List<ByMicrocourse> list, ByMicrocourse t) {
List<ByMicrocourse> tlist = new ArrayList<ByMicrocourse>();
Iterator<ByMicrocourse> it = list.iterator();
while (it.hasNext()) {
ByMicrocourse n = (ByMicrocourse) 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<ByMicrocourse> list, ByMicrocourse t) {
return getChildList(list, t).size() > 0 ? true : false;
}
/**
* 新增微型课程
*

View File

@ -14,12 +14,27 @@
<result property="upanddown" column="upanddown"/>
<result property="sort" column="sort"/>
<result property="createTime" column="create_time"/>
<result property="parentId" column="parent_id"/>
</resultMap>
<sql id="selectByMicrocourseVo">
select id, title, author, contents, type, scpoe, upanddown, sort, create_time from by_microcourse
</sql>
<sql id="selectByMicrocourseVoTree">
select dict_value+9999 id, 0 parent_id,dict_label title,dict_sort sort from sys_dict_data where dict_type='sys_yebjlx' and dict_label !='托班2-3岁'
union all
select id, scpoe+9999, title, sort from by_microcourse
</sql>
<select id="selectByMicrocourseListTree" parameterType="ByMicrocourse" resultMap="ByMicrocourseResult">
<include refid="selectByMicrocourseVoTree"/>
<where>
<if test="title != null and title != ''">and title like concat('%', #{title}, '%')</if>
</where>
order by sort
</select>
<select id="selectByMicrocourseList" parameterType="ByMicrocourse" resultMap="ByMicrocourseResult">
<include refid="selectByMicrocourseVo"/>
<where>