添加游戏数学学习

This commit is contained in:
sk1551
2020-07-22 18:53:21 +08:00
parent bc17996e3f
commit 531c72c003
12 changed files with 334 additions and 117 deletions

View File

@ -5,6 +5,7 @@ import java.util.List;
import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonInclude;
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.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysMenu;
@ -59,6 +60,14 @@ public class TreeSelect implements Serializable
this.children = bytheme.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
//下拉树构造器
public TreeSelect(ByMath bymath) {
this.id = bymath.getId();
this.label = bymath.getName();
this.children = bymath.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
public Long getId()
{
return id;

View File

@ -61,13 +61,22 @@ public class ByMathController extends BaseController
/**
* 获取游戏数学详细信息
*/
@PreAuthorize("@ss.hasPermi('benyi:math:query')")
@PreAuthorize("@ss.hasPermi('benyi:math:query')" + "||@ss.hasPermi('benyi:theme:list')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(byMathService.selectByMathById(id));
}
/**
* 获取部门下拉树列表
*/
@GetMapping("/treeselect")
public AjaxResult treeselect(ByMath byMath) {
List<ByMath> byMathDetails = byMathService.selectByMathListTree(byMath);
return AjaxResult.success(byMathService.buildMathTreeSelect(byMathDetails));
}
/**
* 新增游戏数学
*/

View File

@ -6,7 +6,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.Date;
import java.util.List;
/**
* 游戏数学对象 by_math
@ -58,6 +60,12 @@ public class ByMath extends BaseEntity {
@Excel(name = "序号")
private Long sort;
/** 树状父类ID */
private Long parentId;
/** 树状子类 */
private List<ByMath> children = new ArrayList<ByMath>();
/**
* 创建时间
*/
@ -120,6 +128,30 @@ public class ByMath extends BaseEntity {
return sort;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public List<ByMath> getChildren() {
return children;
}
public void setChildren(List<ByMath> children) {
this.children = children;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
@ -131,14 +163,9 @@ public class ByMath extends BaseEntity {
.append("classtypeId", getClasstypeId())
.append("sort", getSort())
.append("createTime", getCreateTime())
.append("parentId", getParentId())
.toString();
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
}

View File

@ -27,6 +27,14 @@ public interface ByMathMapper
*/
public List<ByMath> selectByMathList(ByMath byMath);
/**
* 查询游戏数学树
*
* @param byMath 游戏数学
* @return 游戏数学树集合
*/
public List<ByMath> selectByMathListTree(ByMath byMath);
/**
* 新增游戏数学
*

View File

@ -1,6 +1,8 @@
package com.ruoyi.project.benyi.service;
import java.util.List;
import com.ruoyi.framework.web.domain.TreeSelect;
import com.ruoyi.project.benyi.domain.ByMath;
/**
@ -27,6 +29,33 @@ public interface IByMathService
*/
public List<ByMath> selectByMathList(ByMath byMath);
/**
* 查询游戏数学列表树
*
* @param byMath 游戏数学
* @return 游戏数学树集合
*/
public List<ByMath> selectByMathListTree(ByMath byMath);
/**
* 构建前端所需要树结构
*
* @param byMaths 部门列表
* @return 树结构列表
*/
public List<ByMath> buildMathDetailTree(List<ByMath> byMaths);
/**
* 构建前端所需要下拉树结构
*
* @param byMaths 部门列表
* @return 树结构列表
*/
public List<TreeSelect> buildMathTreeSelect(List<ByMath> byMaths);
/**
* 新增游戏数学
*

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 com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.benyi.mapper.ByMathMapper;
import com.ruoyi.project.benyi.domain.ByMath;
@ -15,8 +21,7 @@ import com.ruoyi.project.benyi.service.IByMathService;
* @date 2020-07-20
*/
@Service
public class ByMathServiceImpl implements IByMathService
{
public class ByMathServiceImpl implements IByMathService {
@Autowired
private ByMathMapper byMathMapper;
@ -27,8 +32,7 @@ public class ByMathServiceImpl implements IByMathService
* @return 游戏数学
*/
@Override
public ByMath selectByMathById(Long id)
{
public ByMath selectByMathById(Long id) {
return byMathMapper.selectByMathById(id);
}
@ -39,11 +43,105 @@ public class ByMathServiceImpl implements IByMathService
* @return 游戏数学
*/
@Override
public List<ByMath> selectByMathList(ByMath byMath)
{
public List<ByMath> selectByMathList(ByMath byMath) {
return byMathMapper.selectByMathList(byMath);
}
/**
* 查询游戏数学树列表
*
* @param byMath 游戏数学树
* @return 游戏数学树
*/
@Override
public List<ByMath> selectByMathListTree(ByMath byMath) {
return byMathMapper.selectByMathListTree(byMath);
}
/**
* 构建前端所需要树结构
*
* @param byMaths 部门列表
* @return 树结构列表
*/
@Override
public List<ByMath> buildMathDetailTree(List<ByMath> byMaths) {
//System.out.println("start---");
List<ByMath> returnList = new ArrayList<ByMath>();
List<Long> tempList = new ArrayList<Long>();
for (ByMath item : byMaths) {
tempList.add(item.getId());
}
for (Iterator<ByMath> iterator = byMaths.iterator(); iterator.hasNext(); ) {
ByMath item = (ByMath) iterator.next();
//System.out.println("test==="+!tempList.contains(byDayFlowDetail.getParentId()));
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(item.getParentId())) {
recursionFn(byMaths, item);
returnList.add(item);
}
}
if (returnList.isEmpty()) {
returnList = byMaths;
}
return returnList;
}
/**
* 构建前端所需要下拉树结构
*
* @param byMaths 部门列表
* @return 下拉树结构列表
*/
@Override
public List<TreeSelect> buildMathTreeSelect(List<ByMath> byMaths) {
List<ByMath> byMathTrees = buildMathDetailTree(byMaths);
return byMathTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
}
/**
* 递归列表
*/
private void recursionFn(List<ByMath> list, ByMath t) {
// 得到子节点列表
List<ByMath> childList = getChildList(list, t);
t.setChildren(childList);
for (ByMath tChild : childList) {
if (hasChild(list, tChild)) {
// 判断是否有子节点
Iterator<ByMath> it = childList.iterator();
while (it.hasNext()) {
ByMath n = (ByMath) it.next();
recursionFn(list, n);
}
}
}
}
/**
* 得到子节点列表
*/
private List<ByMath> getChildList(List<ByMath> list, ByMath t) {
List<ByMath> tlist = new ArrayList<ByMath>();
Iterator<ByMath> it = list.iterator();
while (it.hasNext()) {
ByMath n = (ByMath) 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<ByMath> list, ByMath t) {
return getChildList(list, t).size() > 0 ? true : false;
}
/**
* 新增游戏数学
*
@ -51,10 +149,9 @@ public class ByMathServiceImpl implements IByMathService
* @return 结果
*/
@Override
public int insertByMath(ByMath byMath)
{
byMath.setCreateTime(DateUtils.getNowDate());
return byMathMapper.insertByMath(byMath);
public int insertByMath(ByMath byMath) {
byMath.setCreateTime(DateUtils.getNowDate());
return byMathMapper.insertByMath(byMath);
}
/**
@ -64,9 +161,8 @@ public class ByMathServiceImpl implements IByMathService
* @return 结果
*/
@Override
public int updateByMath(ByMath byMath)
{
return byMathMapper.updateByMath(byMath);
public int updateByMath(ByMath byMath) {
return byMathMapper.updateByMath(byMath);
}
/**
@ -76,8 +172,7 @@ public class ByMathServiceImpl implements IByMathService
* @return 结果
*/
@Override
public int deleteByMathByIds(Long[] ids)
{
public int deleteByMathByIds(Long[] ids) {
return byMathMapper.deleteByMathByIds(ids);
}
@ -88,8 +183,7 @@ public class ByMathServiceImpl implements IByMathService
* @return 结果
*/
@Override
public int deleteByMathById(Long id)
{
public int deleteByMathById(Long id) {
return byMathMapper.deleteByMathById(id);
}
}

View File

@ -5,30 +5,49 @@
<mapper namespace="com.ruoyi.project.benyi.mapper.ByMathMapper">
<resultMap type="ByMath" id="ByMathResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="target" column="target" />
<result property="feature" column="feature" />
<result property="suggest" column="suggest" />
<result property="classtypeId" column="classtype_id" />
<result property="sort" column="sort" />
<result property="createTime" column="create_time" />
</resultMap>
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="target" column="target"/>
<result property="feature" column="feature"/>
<result property="suggest" column="suggest"/>
<result property="classtypeId" column="classtype_id"/>
<result property="sort" column="sort"/>
<result property="createTime" column="create_time"/>
</resultMap>
<sql id="selectByMathVo">
select id, name, target, feature, suggest, classtype_id, sort, create_time from by_math
</sql>
<sql id="selectByMathVoTree">
select dict_value+9999 id, 0 parent_id,dict_label name,dict_sort sort from sys_dict_data where dict_type='sys_yebjlx' and dict_label !='托班2-3岁'
union all
select id, classtype_id+9999, name, sort from by_math
order by sort
</sql>
<select id="selectByMathListTree" parameterType="ByMath" resultMap="ByMathResult">
<include refid="selectByMathVoTree"/>
<where>
<if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="target != null and target != ''">and target = #{target}</if>
<if test="feature != null and feature != ''">and feature = #{feature}</if>
<if test="suggest != null and suggest != ''">and suggest = #{suggest}</if>
<if test="classtypeId != null ">and classtype_id = #{classtypeId}</if>
<if test="sort != null ">and sort = #{sort}</if>
</where>
</select>
<select id="selectByMathList" parameterType="ByMath" resultMap="ByMathResult">
<include refid="selectByMathVo"/>
<where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="target != null and target != ''"> and target = #{target}</if>
<if test="feature != null and feature != ''"> and feature = #{feature}</if>
<if test="suggest != null and suggest != ''"> and suggest = #{suggest}</if>
<if test="classtypeId != null "> and classtype_id = #{classtypeId}</if>
<if test="sort != null "> and sort = #{sort}</if>
</where>
<if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="target != null and target != ''">and target = #{target}</if>
<if test="feature != null and feature != ''">and feature = #{feature}</if>
<if test="suggest != null and suggest != ''">and suggest = #{suggest}</if>
<if test="classtypeId != null ">and classtype_id = #{classtypeId}</if>
<if test="sort != null ">and sort = #{sort}</if>
</where>
</select>
<select id="selectByMathById" parameterType="Long" resultMap="ByMathResult">
@ -39,38 +58,38 @@
<insert id="insertByMath" parameterType="ByMath">
insert into by_math
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null ">id,</if>
<if test="name != null and name != ''">name,</if>
<if test="target != null and target != ''">target,</if>
<if test="feature != null and feature != ''">feature,</if>
<if test="suggest != null and suggest != ''">suggest,</if>
<if test="classtypeId != null ">classtype_id,</if>
<if test="sort != null ">sort,</if>
<if test="createTime != null ">create_time,</if>
</trim>
<if test="id != null ">id,</if>
<if test="name != null and name != ''">name,</if>
<if test="target != null and target != ''">target,</if>
<if test="feature != null and feature != ''">feature,</if>
<if test="suggest != null and suggest != ''">suggest,</if>
<if test="classtypeId != null ">classtype_id,</if>
<if test="sort != null ">sort,</if>
<if test="createTime != null ">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null ">#{id},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="target != null and target != ''">#{target},</if>
<if test="feature != null and feature != ''">#{feature},</if>
<if test="suggest != null and suggest != ''">#{suggest},</if>
<if test="classtypeId != null ">#{classtypeId},</if>
<if test="sort != null ">#{sort},</if>
<if test="createTime != null ">#{createTime},</if>
</trim>
<if test="id != null ">#{id},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="target != null and target != ''">#{target},</if>
<if test="feature != null and feature != ''">#{feature},</if>
<if test="suggest != null and suggest != ''">#{suggest},</if>
<if test="classtypeId != null ">#{classtypeId},</if>
<if test="sort != null ">#{sort},</if>
<if test="createTime != null ">#{createTime},</if>
</trim>
</insert>
<update id="updateByMath" parameterType="ByMath">
update by_math
<trim prefix="SET" suffixOverrides=",">
<if test="name != null and name != ''">name = #{name},</if>
<if test="target != null and target != ''">target = #{target},</if>
<if test="feature != null and feature != ''">feature = #{feature},</if>
<if test="suggest != null and suggest != ''">suggest = #{suggest},</if>
<if test="classtypeId != null ">classtype_id = #{classtypeId},</if>
<if test="sort != null ">sort = #{sort},</if>
<if test="createTime != null ">create_time = #{createTime},</if>
</trim>
<if test="name != null and name != ''">name = #{name},</if>
<if test="target != null and target != ''">target = #{target},</if>
<if test="feature != null and feature != ''">feature = #{feature},</if>
<if test="suggest != null and suggest != ''">suggest = #{suggest},</if>
<if test="classtypeId != null ">classtype_id = #{classtypeId},</if>
<if test="sort != null ">sort = #{sort},</if>
<if test="createTime != null ">create_time = #{createTime},</if>
</trim>
where id = #{id}
</update>