diff --git a/ruoyi-ui/src/api/benyi/assessmentcontent.js b/ruoyi-ui/src/api/benyi/assessmentcontent.js index e0559c694..671f894d3 100644 --- a/ruoyi-ui/src/api/benyi/assessmentcontent.js +++ b/ruoyi-ui/src/api/benyi/assessmentcontent.js @@ -2,52 +2,61 @@ import request from '@/utils/request' // 查询评估内容列表 export function listAssessmentcontent(query) { - return request({ - url: '/benyi/assessmentcontent/list', - method: 'get', - params: query - }) + return request({ + url: '/benyi/assessmentcontent/list', + method: 'get', + params: query + }) } +// 查询部门下拉树结构 +export function treeselect() { + return request({ + url: '/benyi/assessmentcontent/treeselect', + method: 'get' + }) +} + + // 查询评估内容详细 export function getAssessmentcontent(id) { - return request({ - url: '/benyi/assessmentcontent/' + id, - method: 'get' - }) + return request({ + url: '/benyi/assessmentcontent/' + id, + method: 'get' + }) } // 新增评估内容 export function addAssessmentcontent(data) { - return request({ - url: '/benyi/assessmentcontent', - method: 'post', - data: data - }) + return request({ + url: '/benyi/assessmentcontent', + method: 'post', + data: data + }) } // 修改评估内容 export function updateAssessmentcontent(data) { - return request({ - url: '/benyi/assessmentcontent', - method: 'put', - data: data - }) + return request({ + url: '/benyi/assessmentcontent', + method: 'put', + data: data + }) } // 删除评估内容 export function delAssessmentcontent(id) { - return request({ - url: '/benyi/assessmentcontent/' + id, - method: 'delete' - }) + return request({ + url: '/benyi/assessmentcontent/' + id, + method: 'delete' + }) } // 导出评估内容 export function exportAssessmentcontent(query) { - return request({ - url: '/benyi/assessmentcontent/export', - method: 'get', - params: query - }) -} + return request({ + url: '/benyi/assessmentcontent/export', + method: 'get', + params: query + }) +} \ No newline at end of file diff --git a/ruoyi-ui/src/views/benyi/assessmentcontent/index.vue b/ruoyi-ui/src/views/benyi/assessmentcontent/index.vue index b9c54d82e..67c7a309d 100644 --- a/ruoyi-ui/src/views/benyi/assessmentcontent/index.vue +++ b/ruoyi-ui/src/views/benyi/assessmentcontent/index.vue @@ -54,8 +54,6 @@ @selection-change="handleSelectionChange" > <el-table-column type="selection" width="55" align="center" /> - <!-- <el-table-column label="编号" align="center" prop="id" /> --> - <!-- <el-table-column label="父id" align="center" prop="parentid" /> --> <el-table-column label="名称" align="center" prop="name" /> <el-table-column label="是否元素" align="center" prop="iselement" :formatter="iselementFormat" /> <el-table-column label="适用范围" align="center" prop="scope" :formatter="scopeFormat" /> @@ -90,15 +88,13 @@ <!-- 添加或修改评估内容对话框 --> <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> <el-form ref="form" :model="form" :rules="rules" label-width="80px"> - <el-form-item label="所属模块" prop="parentid"> - <el-select v-model="form.parentid" placeholder="请输入所属模块"> - <el-option - v-for="dict in parentidOptions" - :key="dict.id" - :label="dict.name" - :value="dict.id" - ></el-option> - </el-select> + <el-form-item label="所属模块" prop="parentId"> + <treeselect + v-model="form.parentId" + :options="parentidOptions" + :normalizer="normalizer" + placeholder="选择上级部门" + /> </el-form-item> <el-form-item label="名称" prop="name"> <el-input v-model="form.name" type="textarea" placeholder="请输入内容" /> @@ -114,7 +110,7 @@ </el-select> </el-form-item> <el-form-item label="适用范围" prop="scope"> - <el-select v-model="form.scope" placeholder="请选择元素适用范围" > + <el-select v-model="form.scope" placeholder="请选择元素适用范围"> <el-option v-for="dict in scopeOptions" :key="dict.dictValue" @@ -140,9 +136,12 @@ import { addAssessmentcontent, updateAssessmentcontent } from "@/api/benyi/assessmentcontent"; +import Treeselect from "@riophae/vue-treeselect"; +import "@riophae/vue-treeselect/dist/vue-treeselect.css"; export default { name: "Assessmentcontent", + components: { Treeselect }, data() { return { // 遮罩层 @@ -171,7 +170,7 @@ export default { queryParams: { pageNum: 1, pageSize: 10, - parentid: undefined, + parentId: undefined, name: undefined, iselement: undefined, scope: undefined @@ -180,18 +179,14 @@ export default { form: {}, // 表单校验 rules: { - parentid: [ + parentId: [ { required: true, message: "所属模块不能为空", trigger: "blur" } ], - name: [ - { required: true, message: "名称不能为空", trigger: "blur" } - ], + name: [{ required: true, message: "名称不能为空", trigger: "blur" }], iselement: [ { required: true, message: "是否元素不能为空", trigger: "blur" } ], - scope: [ - { required: true, message: "范围不能为空", trigger: "blur" } - ], + scope: [{ required: true, message: "范围不能为空", trigger: "blur" }] } }; }, @@ -203,7 +198,6 @@ export default { this.getDicts("sys_yes_no").then(response => { this.iselementOptions = response.data; }); - this.getPartntid(); }, methods: { // 性别字典翻译 @@ -224,13 +218,27 @@ export default { this.loading = false; }); }, - getPartntid() { + + /** 查询部门下拉树结构 */ + getTreeselect() { listAssessmentcontent(null).then(response => { - this.parentidOptions = response.rows; + this.parentidOptions = this.handleTree(response.rows, "id"); console.log(this.parentidOptions); }); }, + /** 转换部门数据结构 */ + normalizer(node) { + if (node.children && !node.children.length) { + delete node.children; + } + return { + id: node.id, + label: node.name, + children: node.children + }; + }, + // 取消按钮 cancel() { this.open = false; @@ -240,7 +248,7 @@ export default { reset() { this.form = { id: undefined, - parentid: undefined, + parentId: undefined, name: undefined, iselement: undefined, scope: undefined, @@ -265,14 +273,19 @@ export default { this.multiple = !selection.length; }, /** 新增按钮操作 */ - handleAdd() { + handleAdd(row) { this.reset(); + this.getTreeselect(); + if (row != undefined) { + this.form.parentId = row.id; + } this.open = true; this.title = "添加评估内容"; }, /** 修改按钮操作 */ handleUpdate(row) { this.reset(); + this.getTreeselect(); const id = row.id || this.ids; getAssessmentcontent(id).then(response => { this.form = response.data; diff --git a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/TreeSelect.java b/ruoyi/src/main/java/com/ruoyi/framework/web/domain/TreeSelect.java index a9743f62a..3061da598 100644 --- a/ruoyi/src/main/java/com/ruoyi/framework/web/domain/TreeSelect.java +++ b/ruoyi/src/main/java/com/ruoyi/framework/web/domain/TreeSelect.java @@ -4,6 +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; @@ -37,6 +38,13 @@ public class TreeSelect implements Serializable this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); } + public TreeSelect(ByAssessmentcontent byAssessmentcontent) + { + this.id = byAssessmentcontent.getId(); + this.label = byAssessmentcontent.getName(); + this.children = byAssessmentcontent.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); + } + public TreeSelect(SysMenu menu) { this.id = menu.getMenuId(); diff --git a/ruoyi/src/main/java/com/ruoyi/project/benyi/controller/ByAssessmentcontentController.java b/ruoyi/src/main/java/com/ruoyi/project/benyi/controller/ByAssessmentcontentController.java index fc674f405..677575647 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/benyi/controller/ByAssessmentcontentController.java +++ b/ruoyi/src/main/java/com/ruoyi/project/benyi/controller/ByAssessmentcontentController.java @@ -1,6 +1,10 @@ package com.ruoyi.project.benyi.controller; import java.util.List; + +import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.framework.security.LoginUser; +import com.ruoyi.framework.security.service.TokenService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -32,6 +36,8 @@ public class ByAssessmentcontentController extends BaseController { @Autowired private IByAssessmentcontentService byAssessmentcontentService; + @Autowired + private TokenService tokenService; /** * 查询评估内容列表 @@ -68,6 +74,18 @@ public class ByAssessmentcontentController extends BaseController return AjaxResult.success(byAssessmentcontentService.selectByAssessmentcontentById(id)); } + + + /** + * 获取部门下拉树列表 + */ + @GetMapping("/treeselect") + public AjaxResult treeselect(ByAssessmentcontent byAssessmentcontent) { + List<ByAssessmentcontent> byAssessmentcontents = byAssessmentcontentService.selectByAssessmentcontentList(byAssessmentcontent); + return AjaxResult.success(byAssessmentcontentService.buildByAssessmentcontentTreeSelect(byAssessmentcontents)); + } + + /** * 新增评估内容 */ diff --git a/ruoyi/src/main/java/com/ruoyi/project/benyi/domain/ByAssessmentcontent.java b/ruoyi/src/main/java/com/ruoyi/project/benyi/domain/ByAssessmentcontent.java index 929f8659c..8ba49b17b 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/benyi/domain/ByAssessmentcontent.java +++ b/ruoyi/src/main/java/com/ruoyi/project/benyi/domain/ByAssessmentcontent.java @@ -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_assessmentcontent * @@ -23,7 +26,7 @@ public class ByAssessmentcontent extends BaseEntity { * 父id */ @Excel(name = "父id") - private Long parentid; + private Long parentId; /** * 名称 @@ -37,6 +40,28 @@ public class ByAssessmentcontent extends BaseEntity { @Excel(name = "是否元素") private String iselement; + public String getParentName() { + return parentName; + } + + public void setParentName(String parentName) { + this.parentName = parentName; + } + + public List<ByAssessmentcontent> getChildren() { + return children; + } + + public void setChildren(List<ByAssessmentcontent> children) { + this.children = children; + } + + /** 父部门名称 */ + private String parentName; + + /** 子部门 */ + private List<ByAssessmentcontent> children = new ArrayList<ByAssessmentcontent>(); + /** * 元素才有适用范围;应该以幼儿的岁数为准 */ @@ -51,14 +76,6 @@ public class ByAssessmentcontent extends BaseEntity { return id; } - public void setParentid(Long parentid) { - this.parentid = parentid; - } - - public Long getParentid() { - return parentid; - } - public void setName(String name) { this.name = name; } @@ -87,11 +104,19 @@ public class ByAssessmentcontent extends BaseEntity { public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) .append("id", getId()) - .append("parentid", getParentid()) + .append("parentId", getParentId()) .append("name", getName()) .append("iselement", getIselement()) .append("scope", getScope()) .append("createTime", getCreateTime()) .toString(); } + + public Long getParentId() { + return parentId; + } + + public void setParentId(Long parentId) { + this.parentId = parentId; + } } diff --git a/ruoyi/src/main/java/com/ruoyi/project/benyi/service/IByAssessmentcontentService.java b/ruoyi/src/main/java/com/ruoyi/project/benyi/service/IByAssessmentcontentService.java index f8701b3f3..639d01098 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/benyi/service/IByAssessmentcontentService.java +++ b/ruoyi/src/main/java/com/ruoyi/project/benyi/service/IByAssessmentcontentService.java @@ -2,6 +2,7 @@ package com.ruoyi.project.benyi.service; import java.util.List; +import com.ruoyi.framework.web.domain.TreeSelect; import com.ruoyi.project.benyi.domain.ByAssessmentcontent; /** @@ -27,6 +28,22 @@ public interface IByAssessmentcontentService { */ public List<ByAssessmentcontent> selectByAssessmentcontentList(ByAssessmentcontent byAssessmentcontent); + /** + * 构建前端所需要树结构 + * + * @param byAssessmentcontents 部门列表 + * @return 树结构列表 + */ + List<ByAssessmentcontent> buildbyAssessmentcontentTree(List<ByAssessmentcontent> byAssessmentcontents); + + /** + * 构建前端所需要下拉树结构 + * + * @param byAssessmentcontents 部门列表 + * @return 下拉树结构列表 + */ + public List<TreeSelect> buildByAssessmentcontentTreeSelect(List<ByAssessmentcontent> byAssessmentcontents); + /** * 新增评估内容 * diff --git a/ruoyi/src/main/java/com/ruoyi/project/benyi/service/impl/ByAssessmentcontentServiceImpl.java b/ruoyi/src/main/java/com/ruoyi/project/benyi/service/impl/ByAssessmentcontentServiceImpl.java index 589981410..339681ae2 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/benyi/service/impl/ByAssessmentcontentServiceImpl.java +++ b/ruoyi/src/main/java/com/ruoyi/project/benyi/service/impl/ByAssessmentcontentServiceImpl.java @@ -1,8 +1,13 @@ 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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.project.benyi.mapper.ByAssessmentcontentMapper; @@ -42,6 +47,44 @@ public class ByAssessmentcontentServiceImpl implements IByAssessmentcontentServi return byAssessmentcontentMapper.selectByAssessmentcontentList(byAssessmentcontent); } + /** + * 构建前端所需要树结构 + * + * @param byAssessmentcontents 部门列表 + * @return 树结构列表 + */ + @Override + public List<ByAssessmentcontent> buildbyAssessmentcontentTree(List<ByAssessmentcontent> byAssessmentcontents) + { + List<ByAssessmentcontent> returnList = new ArrayList<ByAssessmentcontent>(); + List<Long> tempList = new ArrayList<Long>(); + for (ByAssessmentcontent byAssessmentcontent : byAssessmentcontents) + { + tempList.add(byAssessmentcontent.getId()); + } + for (Iterator<ByAssessmentcontent> iterator = byAssessmentcontents.iterator(); iterator.hasNext();) + { + ByAssessmentcontent byAssessmentcontent = (ByAssessmentcontent) iterator.next(); + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(byAssessmentcontent.getParentId())) + { + recursionFn(byAssessmentcontents, byAssessmentcontent); + returnList.add(byAssessmentcontent); + } + } + if (returnList.isEmpty()) + { + returnList = byAssessmentcontents; + } + return returnList; + } + + @Override + public List<TreeSelect> buildByAssessmentcontentTreeSelect(List<ByAssessmentcontent> byAssessmentcontents) { + List<ByAssessmentcontent> byAssessmentcontentTrees = buildbyAssessmentcontentTree(byAssessmentcontents); + return byAssessmentcontentTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + /** * 新增评估内容 * @@ -86,4 +129,54 @@ public class ByAssessmentcontentServiceImpl implements IByAssessmentcontentServi public int deleteByAssessmentcontentById(Long id) { return byAssessmentcontentMapper.deleteByAssessmentcontentById(id); } + + /** + * 递归列表 + */ + private void recursionFn(List<ByAssessmentcontent> list, ByAssessmentcontent t) + { + // 得到子节点列表 + List<ByAssessmentcontent> childList = getChildList(list, t); + t.setChildren(childList); + for (ByAssessmentcontent tChild : childList) + { + if (hasChild(list, tChild)) + { + // 判断是否有子节点 + Iterator<ByAssessmentcontent> it = childList.iterator(); + while (it.hasNext()) + { + ByAssessmentcontent n = (ByAssessmentcontent) it.next(); + recursionFn(list, n); + } + } + } + } + + /** + * 得到子节点列表 + */ + private List<ByAssessmentcontent> getChildList(List<ByAssessmentcontent> list, ByAssessmentcontent t) + { + List<ByAssessmentcontent> tlist = new ArrayList<ByAssessmentcontent>(); + Iterator<ByAssessmentcontent> it = list.iterator(); + while (it.hasNext()) + { + ByAssessmentcontent n = (ByAssessmentcontent) it.next(); + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) + { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List<ByAssessmentcontent> list, ByAssessmentcontent t) + { + return getChildList(list, t).size() > 0 ? true : false; + } + } diff --git a/ruoyi/src/main/resources/mybatis/benyi/ByAssessmentcontentMapper.xml b/ruoyi/src/main/resources/mybatis/benyi/ByAssessmentcontentMapper.xml index 954e3bd4d..28d682b42 100644 --- a/ruoyi/src/main/resources/mybatis/benyi/ByAssessmentcontentMapper.xml +++ b/ruoyi/src/main/resources/mybatis/benyi/ByAssessmentcontentMapper.xml @@ -6,7 +6,7 @@ <resultMap type="ByAssessmentcontent" id="ByAssessmentcontentResult"> <result property="id" column="id"/> - <result property="parentid" column="parentId"/> + <result property="parentId" column="parentId"/> <result property="name" column="name"/> <result property="iselement" column="iselement"/> <result property="scope" column="scope"/> @@ -21,7 +21,7 @@ resultMap="ByAssessmentcontentResult"> <include refid="selectByAssessmentcontentVo"/> <where> - <if test="parentid != null ">and parentId = #{parentid}</if> + <if test="parentId != null ">and parentId = #{parentId}</if> <if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if> <if test="iselement != null and iselement != ''">and iselement = #{iselement}</if> <if test="scope != null and scope != ''">and scope = #{scope}</if> @@ -36,14 +36,14 @@ <insert id="insertByAssessmentcontent" parameterType="ByAssessmentcontent" useGeneratedKeys="true" keyProperty="id"> insert into by_assessmentcontent <trim prefix="(" suffix=")" suffixOverrides=","> - <if test="parentid != null ">parentId,</if> + <if test="parentId != null ">parentId,</if> <if test="name != null and name != ''">name,</if> <if test="iselement != null and iselement != ''">iselement,</if> <if test="scope != null and scope != ''">scope,</if> <if test="createTime != null ">create_time,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> - <if test="parentid != null ">#{parentid},</if> + <if test="parentId != null ">#{parentId},</if> <if test="name != null and name != ''">#{name},</if> <if test="iselement != null and iselement != ''">#{iselement},</if> <if test="scope != null and scope != ''">#{scope},</if> @@ -54,7 +54,7 @@ <update id="updateByAssessmentcontent" parameterType="ByAssessmentcontent"> update by_assessmentcontent <trim prefix="SET" suffixOverrides=","> - <if test="parentid != null ">parentId = #{parentid},</if> + <if test="parentId != null ">parentId = #{parentId},</if> <if test="name != null and name != ''">name = #{name},</if> <if test="iselement != null and iselement != ''">iselement = #{iselement},</if> <if test="scope != null and scope != ''">scope = #{scope},</if>