This commit is contained in:
20932067@zju.edu.cn 2021-01-23 17:46:35 +08:00
parent 60a78b7341
commit 2c8d458206
9 changed files with 846 additions and 1 deletions

View File

@ -0,0 +1,53 @@
import request from '@/utils/request'
// 查询树测试列表
export function listTree(query) {
return request({
url: '/test/tree/list',
method: 'get',
params: query
})
}
// 查询树测试详细
export function getTree(id) {
return request({
url: '/test/tree/' + id,
method: 'get'
})
}
// 新增树测试
export function addTree(data) {
return request({
url: '/test/tree',
method: 'post',
data: data
})
}
// 修改树测试
export function updateTree(data) {
return request({
url: '/test/tree',
method: 'put',
data: data
})
}
// 删除树测试
export function delTree(id) {
return request({
url: '/test/tree/' + id,
method: 'delete'
})
}
// 导出树测试
export function exportTree(query) {
return request({
url: '/test/tree/export',
method: 'get',
params: query
})
}

View File

@ -0,0 +1,227 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="内容" prop="content">
<el-input
v-model="queryParams.content"
placeholder="请输入内容"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['test:tree:add']"
>新增</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table
v-loading="loading"
:data="treeList"
row-key="id"
default-expand-all
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>
<el-table-column label="内容" align="center" prop="content" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['test:tree:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['test:tree:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 添加或修改树测试对话框 -->
<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="父id" prop="pId">
<treeselect v-model="form.pId" :options="treeOptions" :normalizer="normalizer" placeholder="请选择父id" />
</el-form-item>
<el-form-item label="内容" prop="content">
<el-input v-model="form.content" placeholder="请输入内容" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listTree, getTree, delTree, addTree, updateTree, exportTree } from "@/api/test/tree";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
name: "Tree",
components: {
Treeselect
},
data() {
return {
//
loading: true,
//
showSearch: true,
//
treeList: [],
//
treeOptions: [],
//
title: "",
//
open: false,
//
queryParams: {
content: null
},
//
form: {},
//
rules: {
content: [
{ required: true, message: "内容不能为空", trigger: "blur" }
]
}
};
},
created() {
this.getList();
},
methods: {
/** 查询树测试列表 */
getList() {
this.loading = true;
listTree(this.queryParams).then(response => {
this.treeList = this.handleTree(response.data, "id", "pId");
this.loading = false;
});
},
/** 转换树测试数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {
delete node.children;
}
return {
id: node.id,
label: node.content,
children: node.children
};
},
/** 查询部门下拉树结构 */
getTreeselect() {
listTree().then(response => {
this.treeOptions = [];
const data = { id: 0, content: '顶级节点', children: [] };
data.children = this.handleTree(response.data, "id", "pId");
this.treeOptions.push(data);
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: null,
pId: null,
content: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.getTreeselect();
this.open = true;
this.title = "添加树测试";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
this.getTreeselect();
if (row != null) {
this.form.pId = row.id;
}
getTree(row.id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改树测试";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateTree(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addTree(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
this.$confirm('是否确认删除树测试编号为"' + row.id + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delTree(row.id);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
})
}
}
};
</script>

View File

@ -116,7 +116,7 @@ public class SwaggerConfig
// 设置标题
.title("标题宏驰云管理系统_接口文档")
// 描述
.description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
.description("描述:系统接口模块管理")
// 作者信息
.contact(new Contact(hchYunConfig.getName(), null, null))
// 版本

View File

@ -0,0 +1,164 @@
package com.hchyun.test.controller;
import java.io.Serializable;
import java.util.List;
import java.util.regex.Pattern;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.common.core.controller.HcyBaseController;
import com.hchyun.common.utils.ServerResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hchyun.common.annotation.Log;
import com.hchyun.common.core.entity.AjaxResult;
import com.hchyun.common.enums.BusinessType;
import com.hchyun.test.entity.TestTree;
import com.hchyun.test.service.TestTreeService;
import com.hchyun.common.utils.poi.ExcelUtil;
/**
* 树测试Controller
*
* @author hchyun
* @date 2021-01-23
*/
@RestController
@RequestMapping("/test/tree")
public class TestTreeController extends HcyBaseController {
protected final Logger logger = LoggerFactory.getLogger(TestTreeController.class);
@Autowired
private TestTreeService testTreeService;
/**
* 查询树测试列表
*/
@PreAuthorize("@ss.hasPermi('test:tree:list')")
@GetMapping("/list")
public AjaxResult list(TestTree testTree)
{
ServerResult<List<TestTree>> serverResult = testTreeService.selectTestTreeList(testTree);
return AjaxResult.success(serverResult.getData());
}
/**
* 导出树测试列表
*/
@PreAuthorize("@ss.hasPermi('test:tree:export')")
@Log(title = "树测试", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(TestTree testTree) {
try {
ServerResult<List<TestTree>> serverResult = testTreeService.selectTestTreeList(testTree);
ExcelUtil<TestTree> util = new ExcelUtil<TestTree>(TestTree. class);
if (serverResult.isStart()) {
return util.exportExcel(serverResult.getData(), "tree");
} else {
return AjaxResult.error(serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
/**
* 获取树测试详细信息
*/
@PreAuthorize("@ss.hasPermi('test:tree:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
try {
ServerResult<TestTree> serverResult = testTreeService.selectTestTreeById(id);
if (serverResult.isStart()) {
return AjaxResult.success(serverResult.getData());
} else {
return AjaxResult.info(serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
/**
* 新增树测试
*/
@PreAuthorize("@ss.hasPermi('test:tree:add')")
@Log(title = "树测试", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody TestTree testTree) {
if (testTree.getContent() == null || testTree.getContent().equals("")) {
return AjaxResult.error("内容不能为空!");
}
try {
ServerResult<Integer> serverResult = testTreeService.insertTestTree(testTree);
if (serverResult.isStart()) {
return AjaxResult.success();
} else {
return AjaxResult.error(serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
/**
* 修改树测试
*/
@PreAuthorize("@ss.hasPermi('test:tree:edit')")
@Log(title = "树测试", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody TestTree testTree) {
try {
if (testTree.getContent() == null || testTree.getContent().equals("")) {
return AjaxResult.error("内容不能为空!");
}
ServerResult<Integer> serverResult = testTreeService.updateTestTree(testTree);
if (serverResult.isStart()) {
return AjaxResult.success();
} else {
return AjaxResult.error(serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
/**
* 删除树测试
*/
@PreAuthorize("@ss.hasPermi('test:tree:remove')")
@Log(title = "树测试", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
try {
if (ids.length<0){
return AjaxResult.error("id不能为空!");
}
ServerResult<Integer> serverResult = testTreeService.deleteTestTreeByIds(ids);
if (serverResult.isStart()) {
return AjaxResult.success();
} else {
return AjaxResult.error(serverResult.getMsg());
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return AjaxResult.error(ReturnConstants.SYS_ERROR);
}
}
}

View File

@ -0,0 +1,61 @@
package com.hchyun.test.dao;
import java.util.List;
import com.hchyun.test.entity.TestTree;
/**
* 树测试Mapper接口
*
* @author hchyun
* @date 2021-01-23
*/
public interface TestTreeDao
{
/**
* 查询树测试
*
* @param id 树测试ID
* @return 树测试
*/
TestTree selectTestTreeById(Long id);
/**
* 查询树测试列表
*
* @param testTree 树测试
* @return 树测试集合
*/
List<TestTree> selectTestTreeList(TestTree testTree);
/**
* 新增树测试
*
* @param testTree 树测试
* @return 结果
*/
int insertTestTree(TestTree testTree);
/**
* 修改树测试
*
* @param testTree 树测试
* @return 结果
*/
int updateTestTree(TestTree testTree);
/**
* 删除树测试
*
* @param id 树测试ID
* @return 结果
*/
int deleteTestTreeById(Long id);
/**
* 批量删除树测试
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteTestTreeByIds(Long[] ids);
}

View File

@ -0,0 +1,64 @@
package com.hchyun.test.entity;
import com.hchyun.common.annotation.Excel;
import com.hchyun.common.core.entity.TreeEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 树测试对象 test_tree
*
* @author hchyun
* @date 2021-01-23
*/
public class TestTree extends TreeEntity
{
private static final long serialVersionUID = 1L;
/** 主键id */
private Long id;
/** 父id */
private Long pId;
/** 内容 */
@Excel(name = "内容")
private String content;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setpId(Long pId)
{
this.pId = pId;
}
public Long getpId()
{
return pId;
}
public void setContent(String content)
{
this.content = content;
}
public String getContent()
{
return content;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("pId", getpId())
.append("content", getContent())
.toString();
}
}

View File

@ -0,0 +1,63 @@
package com.hchyun.test.service;
import java.util.List;
import com.hchyun.common.utils.ServerResult;
import com.hchyun.test.entity.TestTree;
/**
* 树测试Service接口
*
* @author hchyun
* @date 2021-01-23
*/
public interface TestTreeService
{
/**
* 查询树测试
*
* @param id 树测试ID
* @return 树测试
*/
ServerResult<TestTree> selectTestTreeById(Long id);
/**
* 查询树测试列表
*
* @param testTree 树测试
* @return 树测试集合
*/
ServerResult<List<TestTree>> selectTestTreeList(TestTree testTree);
/**
* 新增树测试
*
* @param testTree 树测试
* @return 结果
*/
ServerResult<Integer> insertTestTree(TestTree testTree);
/**
* 修改树测试
*
* @param testTree 树测试
* @return 结果
*/
ServerResult<Integer> updateTestTree(TestTree testTree);
/**
* 批量删除树测试
*
* @param ids 需要删除的树测试ID
* @return 结果
*/
ServerResult<Integer> deleteTestTreeByIds(Long[] ids);
/**
* 删除树测试信息
*
* @param id 树测试ID
* @return 结果
*/
ServerResult<Integer> deleteTestTreeById(Long id);
}

View File

@ -0,0 +1,153 @@
package com.hchyun.test.service.impl;
import java.util.List;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.common.utils.ServerResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hchyun.test.dao.TestTreeDao;
import com.hchyun.test.entity.TestTree;
import com.hchyun.test.service.TestTreeService;
/**
* 树测试Service业务层处理
*
* @author hchyun
* @date 2021-01-23
*/
@Service
public class TestTreeServiceImpl implements TestTreeService {
private Logger logger = LoggerFactory.getLogger(TestTreeServiceImpl.class);
@Autowired
private TestTreeDao testTreeDao;
/**
* 查询树测试
*
* @param id 树测试ID
* @return 树测试
*/
@Override
public ServerResult<TestTree> selectTestTreeById(Long id) {
try {
TestTree testTree = testTreeDao.selectTestTreeById(id);
if (testTree != null){
return new ServerResult<TestTree>(true,testTree);
}else {
return new ServerResult<TestTree>(false, ReturnConstants.RESULT_EMPTY);
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return new ServerResult<TestTree>(false,ReturnConstants.DB_EX);
}
}
/**
* 查询树测试列表
*
* @param testTree 树测试
* @return 树测试
*/
@Override
public ServerResult<List<TestTree>> selectTestTreeList(TestTree testTree) {
try {
List<TestTree> testTreeList = testTreeDao.selectTestTreeList(testTree);
if (testTreeList.size()>0){
return new ServerResult<List<TestTree>>(true,testTreeList);
}else {
return new ServerResult<List<TestTree>>(false,ReturnConstants.RESULT_EMPTY);
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return new ServerResult<List<TestTree>>(false,ReturnConstants.DB_EX);
}
}
/**
* 新增树测试
*
* @param testTree 树测试
* @return 结果
*/
@Override
public ServerResult<Integer> insertTestTree(TestTree testTree) {
try {
Integer renewal = testTreeDao.insertTestTree(testTree);
if (renewal >0){
return new ServerResult<Integer>(true,renewal);
}else {
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
}
}
/**
* 修改树测试
*
* @param testTree 树测试
* @return 结果
*/
@Override
public ServerResult<Integer> updateTestTree(TestTree testTree) {
try {
Integer renewal = testTreeDao.updateTestTree(testTree);
if (renewal >0){
return new ServerResult<Integer>(true,renewal);
}else {
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
}
}
/**
* 批量删除树测试
*
* @param ids 需要删除的树测试ID
* @return 结果
*/
@Override
public ServerResult<Integer> deleteTestTreeByIds(Long[] ids) {
try {
Integer renewal = testTreeDao.deleteTestTreeByIds(ids);
if (renewal >0){
return new ServerResult<Integer>(true,renewal);
}else {
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
}
}
/**
* 删除树测试信息
*
* @param id 树测试ID
* @return 结果
*/
@Override
public ServerResult<Integer> deleteTestTreeById(Long id) {
try {
Integer renewal = testTreeDao.deleteTestTreeById(id);
if (renewal >0){
return new ServerResult<Integer>(true,renewal);
}else {
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
}
}
}

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hchyun.test.dao.TestTreeDao">
<resultMap type="TestTree" id="TestTreeResult">
<result property="id" column="id" />
<result property="pId" column="p_id" />
<result property="content" column="content" />
</resultMap>
<sql id="selectTestTreeVo">
select id, p_id, content from test_tree
</sql>
<select id="selectTestTreeList" parameterType="TestTree" resultMap="TestTreeResult">
<include refid="selectTestTreeVo"/>
<where>
<if test="content != null and content != ''"> and content like concat('%', #{content}, '%')</if>
</where>
</select>
<select id="selectTestTreeById" parameterType="Long" resultMap="TestTreeResult">
<include refid="selectTestTreeVo"/>
where id = #{id}
</select>
<insert id="insertTestTree" parameterType="TestTree" useGeneratedKeys="true" keyProperty="id">
insert into test_tree
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="pId != null">p_id,</if>
<if test="content != null and content != ''">content,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="pId != null">#{pId},</if>
<if test="content != null and content != ''">#{content},</if>
</trim>
</insert>
<update id="updateTestTree" parameterType="TestTree">
update test_tree
<trim prefix="SET" suffixOverrides=",">
<if test="pId != null">p_id = #{pId},</if>
<if test="content != null and content != ''">content = #{content},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteTestTreeById" parameterType="Long">
delete from test_tree where id = #{id}
</delete>
<delete id="deleteTestTreeByIds" parameterType="String">
delete from test_tree where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>