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,43 @@
|
||||
package com.ruoyi.demo.bo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 测试单表添加对象 test_demo
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("测试单表添加对象")
|
||||
public class TestDemoAddBo {
|
||||
|
||||
/** 部门id */
|
||||
@ApiModelProperty("部门id")
|
||||
private Long deptId;
|
||||
|
||||
/** 用户id */
|
||||
@ApiModelProperty("用户id")
|
||||
private Long userId;
|
||||
|
||||
/** 排序号 */
|
||||
@ApiModelProperty("排序号")
|
||||
private Long orderNum;
|
||||
|
||||
/** key键 */
|
||||
@ApiModelProperty("key键")
|
||||
@NotBlank(message = "key键不能为空")
|
||||
private String testKey;
|
||||
|
||||
/** 值 */
|
||||
@ApiModelProperty("值")
|
||||
@NotBlank(message = "值不能为空")
|
||||
private String value;
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.ruoyi.demo.bo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
|
||||
/**
|
||||
* 测试单表编辑对象 test_demo
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("测试单表编辑对象")
|
||||
public class TestDemoEditBo {
|
||||
|
||||
|
||||
/** 主键 */
|
||||
@ApiModelProperty("主键")
|
||||
private Long id;
|
||||
|
||||
|
||||
/** 部门id */
|
||||
@ApiModelProperty("部门id")
|
||||
private Long deptId;
|
||||
|
||||
|
||||
/** 用户id */
|
||||
@ApiModelProperty("用户id")
|
||||
private Long userId;
|
||||
|
||||
|
||||
/** 排序号 */
|
||||
@ApiModelProperty("排序号")
|
||||
private Long orderNum;
|
||||
|
||||
|
||||
/** key键 */
|
||||
@ApiModelProperty("key键")
|
||||
@NotBlank(message = "key键不能为空")
|
||||
private String testKey;
|
||||
|
||||
|
||||
/** 值 */
|
||||
@ApiModelProperty("值")
|
||||
@NotBlank(message = "值不能为空")
|
||||
private String value;
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.ruoyi.demo.bo;
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 测试单表分页查询对象 test_demo
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel("测试单表分页查询对象")
|
||||
public class TestDemoQueryBo extends BaseEntity {
|
||||
|
||||
/** 分页大小 */
|
||||
@ApiModelProperty("分页大小")
|
||||
private Integer pageSize;
|
||||
/** 当前页数 */
|
||||
@ApiModelProperty("当前页数")
|
||||
private Integer pageNum;
|
||||
/** 排序列 */
|
||||
@ApiModelProperty("排序列")
|
||||
private String orderByColumn;
|
||||
/** 排序的方向desc或者asc */
|
||||
@ApiModelProperty(value = "排序的方向", example = "asc,desc")
|
||||
private String isAsc;
|
||||
|
||||
|
||||
/** key键 */
|
||||
@ApiModelProperty("key键")
|
||||
private String testKey;
|
||||
/** 值 */
|
||||
@ApiModelProperty("值")
|
||||
private String value;
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
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.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.demo.bo.TestDemoAddBo;
|
||||
import com.ruoyi.demo.bo.TestDemoEditBo;
|
||||
import com.ruoyi.demo.bo.TestDemoQueryBo;
|
||||
import com.ruoyi.demo.service.ITestDemoService;
|
||||
import com.ruoyi.demo.vo.TestDemoVo;
|
||||
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/demo")
|
||||
public class TestDemoController extends BaseController {
|
||||
|
||||
private final ITestDemoService iTestDemoService;
|
||||
|
||||
/**
|
||||
* 查询测试单表列表
|
||||
*/
|
||||
@ApiOperation("查询测试单表列表")
|
||||
@PreAuthorize("@ss.hasPermi('demo:demo:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<TestDemoVo> list(@Validated TestDemoQueryBo bo) {
|
||||
return iTestDemoService.queryPageList(bo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出测试单表列表
|
||||
*/
|
||||
@ApiOperation("导出测试单表列表")
|
||||
@PreAuthorize("@ss.hasPermi('demo:demo:export')")
|
||||
@Log(title = "测试单表", businessType = BusinessType.EXPORT)
|
||||
@GetMapping("/export")
|
||||
public AjaxResult<TestDemoVo> export(@Validated TestDemoQueryBo bo) {
|
||||
List<TestDemoVo> list = iTestDemoService.queryList(bo);
|
||||
ExcelUtil<TestDemoVo> util = new ExcelUtil<TestDemoVo>(TestDemoVo.class);
|
||||
return util.exportExcel(list, "测试单表");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取测试单表详细信息
|
||||
*/
|
||||
@ApiOperation("获取测试单表详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('demo:demo:query')")
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult<TestDemoVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable("id") Long id) {
|
||||
return AjaxResult.success(iTestDemoService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增测试单表
|
||||
*/
|
||||
@ApiOperation("新增测试单表")
|
||||
@PreAuthorize("@ss.hasPermi('demo:demo:add')")
|
||||
@Log(title = "测试单表", businessType = BusinessType.INSERT)
|
||||
@PostMapping()
|
||||
public AjaxResult<Void> add(@Validated @RequestBody TestDemoAddBo bo) {
|
||||
return toAjax(iTestDemoService.insertByAddBo(bo) ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改测试单表
|
||||
*/
|
||||
@ApiOperation("修改测试单表")
|
||||
@PreAuthorize("@ss.hasPermi('demo:demo:edit')")
|
||||
@Log(title = "测试单表", businessType = BusinessType.UPDATE)
|
||||
@PutMapping()
|
||||
public AjaxResult<Void> edit(@Validated @RequestBody TestDemoEditBo bo) {
|
||||
return toAjax(iTestDemoService.updateByEditBo(bo) ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除测试单表
|
||||
*/
|
||||
@ApiOperation("删除测试单表")
|
||||
@PreAuthorize("@ss.hasPermi('demo:demo:remove')")
|
||||
@Log(title = "测试单表" , businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(iTestDemoService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
|
||||
}
|
||||
}
|
70
ruoyi-demo/src/main/java/com/ruoyi/demo/domain/TestDemo.java
Normal file
70
ruoyi-demo/src/main/java/com/ruoyi/demo/domain/TestDemo.java
Normal file
@ -0,0 +1,70 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* 测试单表对象 test_demo
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@TableName("test_demo")
|
||||
public class TestDemo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
|
||||
/** 主键 */
|
||||
@TableId(value = "id")
|
||||
private Long id;
|
||||
|
||||
/** 部门id */
|
||||
private Long deptId;
|
||||
|
||||
/** 用户id */
|
||||
private Long userId;
|
||||
|
||||
/** 排序号 */
|
||||
@OrderBy(isDesc = false, sort = 1)
|
||||
private Long orderNum;
|
||||
|
||||
/** key键 */
|
||||
private String testKey;
|
||||
|
||||
/** 值 */
|
||||
private String value;
|
||||
|
||||
/** 版本 */
|
||||
@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.TestDemo;
|
||||
import com.ruoyi.common.core.page.BaseMapperPlus;
|
||||
|
||||
/**
|
||||
* 测试单表Mapper接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
public interface TestDemoMapper extends BaseMapperPlus<TestDemo> {
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.ruoyi.demo.service;
|
||||
|
||||
import com.ruoyi.demo.domain.TestDemo;
|
||||
import com.ruoyi.demo.vo.TestDemoVo;
|
||||
import com.ruoyi.demo.bo.TestDemoQueryBo;
|
||||
import com.ruoyi.demo.bo.TestDemoAddBo;
|
||||
import com.ruoyi.demo.bo.TestDemoEditBo;
|
||||
import com.ruoyi.common.core.page.IServicePlus;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试单表Service接口
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
public interface ITestDemoService extends IServicePlus<TestDemo> {
|
||||
/**
|
||||
* 查询单个
|
||||
* @return
|
||||
*/
|
||||
TestDemoVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
TableDataInfo<TestDemoVo> queryPageList(TestDemoQueryBo bo);
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
List<TestDemoVo> queryList(TestDemoQueryBo bo);
|
||||
|
||||
/**
|
||||
* 根据新增业务对象插入测试单表
|
||||
* @param bo 测试单表新增业务对象
|
||||
* @return
|
||||
*/
|
||||
Boolean insertByAddBo(TestDemoAddBo bo);
|
||||
|
||||
/**
|
||||
* 根据编辑业务对象修改测试单表
|
||||
* @param bo 测试单表编辑业务对象
|
||||
* @return
|
||||
*/
|
||||
Boolean updateByEditBo(TestDemoEditBo bo);
|
||||
|
||||
/**
|
||||
* 校验并删除数据
|
||||
* @param ids 主键集合
|
||||
* @param isValid 是否校验,true-删除前校验,false-不校验
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
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.common.core.page.PagePlus;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.PageUtils;
|
||||
import com.ruoyi.demo.bo.TestDemoAddBo;
|
||||
import com.ruoyi.demo.bo.TestDemoEditBo;
|
||||
import com.ruoyi.demo.bo.TestDemoQueryBo;
|
||||
import com.ruoyi.demo.domain.TestDemo;
|
||||
import com.ruoyi.demo.mapper.TestDemoMapper;
|
||||
import com.ruoyi.demo.service.ITestDemoService;
|
||||
import com.ruoyi.demo.vo.TestDemoVo;
|
||||
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 TestDemoServiceImpl extends ServiceImpl<TestDemoMapper, TestDemo> implements ITestDemoService {
|
||||
|
||||
@Override
|
||||
public TestDemoVo queryById(Long id) {
|
||||
return getVoById(id, TestDemoVo.class);
|
||||
}
|
||||
|
||||
@DataScope(isUser = true)
|
||||
@Override
|
||||
public TableDataInfo<TestDemoVo> queryPageList(TestDemoQueryBo bo) {
|
||||
PagePlus<TestDemo, TestDemoVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), TestDemoVo.class);
|
||||
return PageUtils.buildDataInfo(result);
|
||||
}
|
||||
|
||||
@DataScope(isUser = true)
|
||||
@Override
|
||||
public List<TestDemoVo> queryList(TestDemoQueryBo bo) {
|
||||
return listVo(buildQueryWrapper(bo), TestDemoVo.class);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<TestDemo> buildQueryWrapper(TestDemoQueryBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
Object dataScope = params.get("dataScope");
|
||||
LambdaQueryWrapper<TestDemo> lqw = Wrappers.lambdaQuery();
|
||||
lqw.like(StrUtil.isNotBlank(bo.getTestKey()), TestDemo::getTestKey, bo.getTestKey());
|
||||
lqw.eq(StrUtil.isNotBlank(bo.getValue()), TestDemo::getValue, bo.getValue());
|
||||
lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
|
||||
TestDemo::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(TestDemoAddBo bo) {
|
||||
TestDemo add = BeanUtil.toBean(bo, TestDemo.class);
|
||||
validEntityBeforeSave(add);
|
||||
return save(add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateByEditBo(TestDemoEditBo bo) {
|
||||
TestDemo update = BeanUtil.toBean(bo, TestDemo.class);
|
||||
validEntityBeforeSave(update);
|
||||
return updateById(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*
|
||||
* @param entity 实体类数据
|
||||
*/
|
||||
private void validEntityBeforeSave(TestDemo entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return removeByIds(ids);
|
||||
}
|
||||
}
|
76
ruoyi-demo/src/main/java/com/ruoyi/demo/vo/TestDemoVo.java
Normal file
76
ruoyi-demo/src/main/java/com/ruoyi/demo/vo/TestDemoVo.java
Normal file
@ -0,0 +1,76 @@
|
||||
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_demo
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2021-05-30
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("测试单表视图对象")
|
||||
public class TestDemoVo {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键 */
|
||||
@ApiModelProperty("主键")
|
||||
private Long id;
|
||||
|
||||
/** 部门id */
|
||||
@Excel(name = "部门id")
|
||||
@ApiModelProperty("部门id")
|
||||
private Long deptId;
|
||||
|
||||
/** 用户id */
|
||||
@Excel(name = "用户id")
|
||||
@ApiModelProperty("用户id")
|
||||
private Long userId;
|
||||
|
||||
/** 排序号 */
|
||||
@Excel(name = "排序号")
|
||||
@ApiModelProperty("排序号")
|
||||
private Long orderNum;
|
||||
|
||||
/** key键 */
|
||||
@Excel(name = "key键")
|
||||
@ApiModelProperty("key键")
|
||||
private String testKey;
|
||||
|
||||
/** 值 */
|
||||
@Excel(name = "值")
|
||||
@ApiModelProperty("值")
|
||||
private String value;
|
||||
|
||||
/** 创建时间 */
|
||||
@Excel(name = "创建时间" , width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/** 创建人 */
|
||||
@Excel(name = "创建人")
|
||||
@ApiModelProperty("创建人")
|
||||
private String createBy;
|
||||
|
||||
/** 更新时间 */
|
||||
@Excel(name = "更新时间" , width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty("更新时间")
|
||||
private Date updateTime;
|
||||
|
||||
/** 更新人 */
|
||||
@Excel(name = "更新人")
|
||||
@ApiModelProperty("更新人")
|
||||
private String updateBy;
|
||||
|
||||
|
||||
}
|
23
ruoyi-demo/src/main/resources/mapper/demo/TestDemoMapper.xml
Normal file
23
ruoyi-demo/src/main/resources/mapper/demo/TestDemoMapper.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?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.TestDemoMapper">
|
||||
|
||||
<resultMap type="com.ruoyi.demo.domain.TestDemo" id="TestDemoResult">
|
||||
<result property="id" column="id"/>
|
||||
<result property="deptId" column="dept_id"/>
|
||||
<result property="userId" column="user_id"/>
|
||||
<result property="orderNum" column="order_num"/>
|
||||
<result property="testKey" column="test_key"/>
|
||||
<result property="value" column="value"/>
|
||||
<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