mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
add 增加demo模块 树表演示案例(包含数据权限)
This commit is contained in:
@ -0,0 +1,39 @@
|
||||
package com.ruoyi.demo.bo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 测试树表添加对象 test_tree
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("测试树表添加对象")
|
||||
public class TestTreeAddBo {
|
||||
|
||||
/** 父id */
|
||||
@ApiModelProperty("父id")
|
||||
private Long parentId;
|
||||
|
||||
/** 部门id */
|
||||
@ApiModelProperty("部门id")
|
||||
private Long deptId;
|
||||
|
||||
/** 用户id */
|
||||
@ApiModelProperty("用户id")
|
||||
private Long userId;
|
||||
|
||||
/** 树节点名 */
|
||||
@ApiModelProperty("树节点名")
|
||||
@NotBlank(message = "树节点名不能为空")
|
||||
private String treeName;
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.ruoyi.demo.bo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
|
||||
/**
|
||||
* 测试树表编辑对象 test_tree
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("测试树表编辑对象")
|
||||
public class TestTreeEditBo {
|
||||
|
||||
|
||||
/** 主键 */
|
||||
@ApiModelProperty("主键")
|
||||
private Long id;
|
||||
|
||||
|
||||
/** 父id */
|
||||
@ApiModelProperty("父id")
|
||||
private Long parentId;
|
||||
|
||||
|
||||
/** 部门id */
|
||||
@ApiModelProperty("部门id")
|
||||
private Long deptId;
|
||||
|
||||
|
||||
/** 用户id */
|
||||
@ApiModelProperty("用户id")
|
||||
private Long userId;
|
||||
|
||||
|
||||
/** 树节点名 */
|
||||
@ApiModelProperty("树节点名")
|
||||
@NotBlank(message = "树节点名不能为空")
|
||||
private String treeName;
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.ruoyi.demo.bo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 测试树表分页查询对象 test_tree
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel("测试树表分页查询对象")
|
||||
public class TestTreeQueryBo extends BaseEntity {
|
||||
|
||||
/** 分页大小 */
|
||||
@ApiModelProperty("分页大小")
|
||||
private Integer pageSize;
|
||||
/** 当前页数 */
|
||||
@ApiModelProperty("当前页数")
|
||||
private Integer pageNum;
|
||||
/** 排序列 */
|
||||
@ApiModelProperty("排序列")
|
||||
private String orderByColumn;
|
||||
/** 排序的方向desc或者asc */
|
||||
@ApiModelProperty(value = "排序的方向", example = "asc,desc")
|
||||
private String isAsc;
|
||||
|
||||
|
||||
/** 树节点名 */
|
||||
@ApiModelProperty("树节点名")
|
||||
private String treeName;
|
||||
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package com.ruoyi.demo.controller;
|
||||
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.demo.bo.TestTreeAddBo;
|
||||
import com.ruoyi.demo.bo.TestTreeEditBo;
|
||||
import com.ruoyi.demo.bo.TestTreeQueryBo;
|
||||
import com.ruoyi.demo.service.ITestTreeService;
|
||||
import com.ruoyi.demo.vo.TestTreeVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试树表Controller
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
@Api(value = "测试树表控制器", tags = {"测试树表管理"})
|
||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||
@RestController
|
||||
@RequestMapping("/demo/tree")
|
||||
public class TestTreeController extends BaseController {
|
||||
|
||||
private final ITestTreeService iTestTreeService;
|
||||
|
||||
/**
|
||||
* 查询测试树表列表
|
||||
*/
|
||||
@ApiOperation("查询测试树表列表")
|
||||
@PreAuthorize("@ss.hasPermi('demo:tree:list')")
|
||||
@GetMapping("/list")
|
||||
public AjaxResult<List<TestTreeVo>> list(@Validated TestTreeQueryBo bo) {
|
||||
return AjaxResult.success(iTestTreeService.queryList(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出测试树表列表
|
||||
*/
|
||||
@ApiOperation("导出测试树表列表")
|
||||
@PreAuthorize("@ss.hasPermi('demo:tree:export')")
|
||||
@Log(title = "测试树表", businessType = BusinessType.EXPORT)
|
||||
@GetMapping("/export")
|
||||
public AjaxResult<TestTreeVo> export(@Validated TestTreeQueryBo bo) {
|
||||
List<TestTreeVo> list = iTestTreeService.queryList(bo);
|
||||
ExcelUtil<TestTreeVo> util = new ExcelUtil<TestTreeVo>(TestTreeVo.class);
|
||||
return util.exportExcel(list, "测试树表");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取测试树表详细信息
|
||||
*/
|
||||
@ApiOperation("获取测试树表详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('demo:tree:query')")
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult<TestTreeVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable("id") Long id) {
|
||||
return AjaxResult.success(iTestTreeService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增测试树表
|
||||
*/
|
||||
@ApiOperation("新增测试树表")
|
||||
@PreAuthorize("@ss.hasPermi('demo:tree:add')")
|
||||
@Log(title = "测试树表", businessType = BusinessType.INSERT)
|
||||
@PostMapping()
|
||||
public AjaxResult<Void> add(@Validated @RequestBody TestTreeAddBo bo) {
|
||||
return toAjax(iTestTreeService.insertByAddBo(bo) ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改测试树表
|
||||
*/
|
||||
@ApiOperation("修改测试树表")
|
||||
@PreAuthorize("@ss.hasPermi('demo:tree:edit')")
|
||||
@Log(title = "测试树表", businessType = BusinessType.UPDATE)
|
||||
@PutMapping()
|
||||
public AjaxResult<Void> edit(@Validated @RequestBody TestTreeEditBo bo) {
|
||||
return toAjax(iTestTreeService.updateByEditBo(bo) ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除测试树表
|
||||
*/
|
||||
@ApiOperation("删除测试树表")
|
||||
@PreAuthorize("@ss.hasPermi('demo:tree:remove')")
|
||||
@Log(title = "测试树表" , businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(iTestTreeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
|
||||
}
|
||||
}
|
67
ruoyi-demo/src/main/java/com/ruoyi/demo/domain/TestTree.java
Normal file
67
ruoyi-demo/src/main/java/com/ruoyi/demo/domain/TestTree.java
Normal file
@ -0,0 +1,67 @@
|
||||
package com.ruoyi.demo.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.math.BigDecimal;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
|
||||
/**
|
||||
* 测试树表对象 test_tree
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@TableName("test_tree")
|
||||
public class TestTree implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
|
||||
/** 主键 */
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
/** 父id */
|
||||
private Long parentId;
|
||||
|
||||
/** 部门id */
|
||||
private Long deptId;
|
||||
|
||||
/** 用户id */
|
||||
private Long userId;
|
||||
|
||||
/** 树节点名 */
|
||||
private String treeName;
|
||||
|
||||
/** 版本 */
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
/** 创建时间 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
/** 创建人 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createBy;
|
||||
|
||||
/** 更新时间 */
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
/** 更新人 */
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String updateBy;
|
||||
|
||||
/** 删除标志 */
|
||||
@TableLogic
|
||||
private Long delFlag;
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.ruoyi.demo.mapper;
|
||||
|
||||
import com.ruoyi.demo.domain.TestTree;
|
||||
import com.ruoyi.common.core.page.BaseMapperPlus;
|
||||
|
||||
/**
|
||||
* 测试树表Mapper接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
public interface TestTreeMapper extends BaseMapperPlus<TestTree> {
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.ruoyi.demo.service;
|
||||
|
||||
import com.ruoyi.common.core.page.IServicePlus;
|
||||
import com.ruoyi.demo.bo.TestTreeAddBo;
|
||||
import com.ruoyi.demo.bo.TestTreeEditBo;
|
||||
import com.ruoyi.demo.bo.TestTreeQueryBo;
|
||||
import com.ruoyi.demo.domain.TestTree;
|
||||
import com.ruoyi.demo.vo.TestTreeVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试树表Service接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
public interface ITestTreeService extends IServicePlus<TestTree> {
|
||||
/**
|
||||
* 查询单个
|
||||
* @return
|
||||
*/
|
||||
TestTreeVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
List<TestTreeVo> queryList(TestTreeQueryBo bo);
|
||||
|
||||
/**
|
||||
* 根据新增业务对象插入测试树表
|
||||
* @param bo 测试树表新增业务对象
|
||||
* @return
|
||||
*/
|
||||
Boolean insertByAddBo(TestTreeAddBo bo);
|
||||
|
||||
/**
|
||||
* 根据编辑业务对象修改测试树表
|
||||
* @param bo 测试树表编辑业务对象
|
||||
* @return
|
||||
*/
|
||||
Boolean updateByEditBo(TestTreeEditBo bo);
|
||||
|
||||
/**
|
||||
* 校验并删除数据
|
||||
* @param ids 主键集合
|
||||
* @param isValid 是否校验,true-删除前校验,false-不校验
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package com.ruoyi.demo.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.demo.bo.TestTreeAddBo;
|
||||
import com.ruoyi.demo.bo.TestTreeEditBo;
|
||||
import com.ruoyi.demo.bo.TestTreeQueryBo;
|
||||
import com.ruoyi.demo.domain.TestTree;
|
||||
import com.ruoyi.demo.mapper.TestTreeMapper;
|
||||
import com.ruoyi.demo.service.ITestTreeService;
|
||||
import com.ruoyi.demo.vo.TestTreeVo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 测试树表Service业务层处理
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
@Service
|
||||
public class TestTreeServiceImpl extends ServiceImpl<TestTreeMapper, TestTree> implements ITestTreeService {
|
||||
|
||||
@Override
|
||||
public TestTreeVo queryById(Long id) {
|
||||
return getVoById(id, TestTreeVo.class);
|
||||
}
|
||||
|
||||
@DataScope(isUser = true)
|
||||
@Override
|
||||
public List<TestTreeVo> queryList(TestTreeQueryBo bo) {
|
||||
return listVo(buildQueryWrapper(bo), TestTreeVo.class);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<TestTree> buildQueryWrapper(TestTreeQueryBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
Object dataScope = params.get("dataScope");
|
||||
LambdaQueryWrapper<TestTree> lqw = Wrappers.lambdaQuery();
|
||||
lqw.like(StrUtil.isNotBlank(bo.getTreeName()), TestTree::getTreeName, bo.getTreeName());
|
||||
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
|
||||
TestTree::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime"));
|
||||
lqw.apply(dataScope != null && StrUtil.isNotBlank(dataScope.toString()),
|
||||
dataScope != null ? dataScope.toString() : null);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insertByAddBo(TestTreeAddBo bo) {
|
||||
TestTree add = BeanUtil.toBean(bo, TestTree.class);
|
||||
validEntityBeforeSave(add);
|
||||
return save(add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateByEditBo(TestTreeEditBo bo) {
|
||||
TestTree update = BeanUtil.toBean(bo, TestTree.class);
|
||||
validEntityBeforeSave(update);
|
||||
return updateById(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*
|
||||
* @param entity 实体类数据
|
||||
*/
|
||||
private void validEntityBeforeSave(TestTree entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return removeByIds(ids);
|
||||
}
|
||||
}
|
55
ruoyi-demo/src/main/java/com/ruoyi/demo/vo/TestTreeVo.java
Normal file
55
ruoyi-demo/src/main/java/com/ruoyi/demo/vo/TestTreeVo.java
Normal file
@ -0,0 +1,55 @@
|
||||
package com.ruoyi.demo.vo;
|
||||
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 测试树表视图对象 test_tree
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("测试树表视图对象")
|
||||
public class TestTreeVo {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键 */
|
||||
@ApiModelProperty("主键")
|
||||
private Long id;
|
||||
|
||||
/** 父id */
|
||||
@Excel(name = "父id")
|
||||
@ApiModelProperty("父id")
|
||||
private Long parentId;
|
||||
|
||||
/** 部门id */
|
||||
@Excel(name = "部门id")
|
||||
@ApiModelProperty("部门id")
|
||||
private Long deptId;
|
||||
|
||||
/** 用户id */
|
||||
@Excel(name = "用户id")
|
||||
@ApiModelProperty("用户id")
|
||||
private Long userId;
|
||||
|
||||
/** 树节点名 */
|
||||
@Excel(name = "树节点名")
|
||||
@ApiModelProperty("树节点名")
|
||||
private String treeName;
|
||||
|
||||
/** 创建时间 */
|
||||
@Excel(name = "创建时间" , width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
|
||||
}
|
22
ruoyi-demo/src/main/resources/mapper/demo/TestTreeMapper.xml
Normal file
22
ruoyi-demo/src/main/resources/mapper/demo/TestTreeMapper.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?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.ruoyi.demo.mapper.TestTreeMapper">
|
||||
|
||||
<resultMap type="com.ruoyi.demo.domain.TestTree" id="TestTreeResult">
|
||||
<result property="id" column="id"/>
|
||||
<result property="parentId" column="parent_id"/>
|
||||
<result property="deptId" column="dept_id"/>
|
||||
<result property="userId" column="user_id"/>
|
||||
<result property="treeName" column="tree_name"/>
|
||||
<result property="version" column="version"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="delFlag" column="del_flag"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user