报表模板维护;
This commit is contained in:
parent
14916c59d9
commit
212f453e41
@ -6,6 +6,7 @@ import cn.hutool.core.lang.Validator;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.boot.configurationprocessor.json.JSONTokener;
|
||||||
import org.springframework.util.AntPathMatcher;
|
import org.springframework.util.AntPathMatcher;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -347,4 +348,18 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||||||
return str.matches("[a-zA-Z]+");
|
return str.matches("[a-zA-Z]+");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否为JSON
|
||||||
|
* @param jsonString
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isJsonString(String jsonString) {
|
||||||
|
try {
|
||||||
|
new JSONTokener(jsonString).nextValue();
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
package com.das.modules.page.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import com.das.common.constant.SysAuthorityIds;
|
||||||
|
import com.das.common.exceptions.ServiceException;
|
||||||
|
import com.das.common.result.R;
|
||||||
|
import com.das.common.utils.PageDataInfo;
|
||||||
|
import com.das.modules.page.domian.dto.SysReportTemplateDto;
|
||||||
|
import com.das.modules.page.domian.vo.SysReportTemplateVo;
|
||||||
|
import com.das.modules.page.service.ReportTemplateService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表相关Controller
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequestMapping("/api/report/template")
|
||||||
|
@RestController
|
||||||
|
public class ReportTemplateController {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReportTemplateService reportTemplateService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据模板分类查询模板列表
|
||||||
|
* @return 模板列表
|
||||||
|
*/
|
||||||
|
@PostMapping("/getList")
|
||||||
|
public R<PageDataInfo<SysReportTemplateVo>> getReportTemplateList(@RequestBody SysReportTemplateDto sysReportTemplateDto) {
|
||||||
|
if (sysReportTemplateDto.getPageNum() == null) {
|
||||||
|
sysReportTemplateDto.setPageNum(1);
|
||||||
|
}
|
||||||
|
if (sysReportTemplateDto.getPageSize() == null) {
|
||||||
|
sysReportTemplateDto.setPageSize(30);
|
||||||
|
}
|
||||||
|
PageDataInfo<SysReportTemplateVo> reportTemplateList = reportTemplateService.getReportTemplateList(sysReportTemplateDto);
|
||||||
|
return R.success(reportTemplateList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增报表模板;
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
public R<SysReportTemplateVo> addReportTemplate(@RequestBody SysReportTemplateDto sysReportTemplateDto) {
|
||||||
|
//判断是否有权限
|
||||||
|
boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_CTRL.toString());
|
||||||
|
if(!hasPermission){
|
||||||
|
return R.fail("没有控制权限");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(sysReportTemplateDto.getTemplate()) || StringUtils.isBlank(sysReportTemplateDto.getCategory())){
|
||||||
|
throw new ServiceException("参数缺失");
|
||||||
|
}
|
||||||
|
SysReportTemplateVo sysReportTemplateVo = reportTemplateService.addReportTemplate(sysReportTemplateDto);
|
||||||
|
return R.success(sysReportTemplateVo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增报表模板;
|
||||||
|
*/
|
||||||
|
@PostMapping("/del")
|
||||||
|
public R<Void> delReportTemplate(@RequestBody SysReportTemplateDto sysReportTemplateDto) {
|
||||||
|
//判断是否有权限
|
||||||
|
boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_CTRL.toString());
|
||||||
|
if(!hasPermission){
|
||||||
|
return R.fail("没有控制权限");
|
||||||
|
}
|
||||||
|
if (sysReportTemplateDto.getId() ==null){
|
||||||
|
throw new ServiceException("参数缺失");
|
||||||
|
}
|
||||||
|
reportTemplateService.delReportTemplate(sysReportTemplateDto);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.das.modules.page.domian.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SysReportTemplateDto implements Serializable {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*报表分类;如:单机报表;多机报表
|
||||||
|
*/
|
||||||
|
private String category;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板内容
|
||||||
|
*/
|
||||||
|
private String template;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页大小
|
||||||
|
*/
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前页数
|
||||||
|
*/
|
||||||
|
private Integer pageNum;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.das.modules.page.domian.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SysReportTemplateVo {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*报表分类;如:单机报表;多机报表
|
||||||
|
*/
|
||||||
|
private String category;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板内容
|
||||||
|
*/
|
||||||
|
private String template;
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.das.modules.page.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.das.common.constant.BaseEntity;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
@TableName("sys_report_template")
|
||||||
|
@Data
|
||||||
|
public class SysReportTemplate extends BaseEntity {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*报表分类;如:单机报表;多机报表
|
||||||
|
*/
|
||||||
|
@TableField("category")
|
||||||
|
private String category;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板内容
|
||||||
|
*/
|
||||||
|
@TableField("template")
|
||||||
|
private String template;
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.das.modules.page.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.das.modules.auth.mapper.BaseMapperPlus;
|
||||||
|
import com.das.modules.page.domian.dto.SysReportTemplateDto;
|
||||||
|
import com.das.modules.page.domian.vo.SysReportTemplateVo;
|
||||||
|
import com.das.modules.page.entity.SysReportTemplate;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface SysReportTemplateMapper extends BaseMapperPlus<SysReportTemplate,SysReportTemplate> {
|
||||||
|
|
||||||
|
IPage<SysReportTemplateVo> queryReportTemplateListInPage(IPage<SysReportTemplateVo> page, @Param("info") SysReportTemplateDto sysReportTemplateDto);
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.das.modules.page.service;
|
||||||
|
|
||||||
|
import com.das.common.utils.PageDataInfo;
|
||||||
|
import com.das.modules.page.domian.dto.SysReportTemplateDto;
|
||||||
|
import com.das.modules.page.domian.vo.SysReportTemplateVo;
|
||||||
|
|
||||||
|
public interface ReportTemplateService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据模板分类查询模板列表
|
||||||
|
* @return 模板列表
|
||||||
|
*/
|
||||||
|
PageDataInfo<SysReportTemplateVo> getReportTemplateList( SysReportTemplateDto sysReportTemplateDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增报表模板
|
||||||
|
* @param sysReportTemplateDto
|
||||||
|
* @return报表模板
|
||||||
|
*/
|
||||||
|
SysReportTemplateVo addReportTemplate(SysReportTemplateDto sysReportTemplateDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除模板
|
||||||
|
* @param sysReportTemplateDto
|
||||||
|
*/
|
||||||
|
void delReportTemplate(SysReportTemplateDto sysReportTemplateDto);
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.das.modules.page.service.impl;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.das.common.config.SessionUtil;
|
||||||
|
import com.das.common.exceptions.ServiceException;
|
||||||
|
import com.das.common.utils.BeanCopyUtils;
|
||||||
|
import com.das.common.utils.PageDataInfo;
|
||||||
|
import com.das.common.utils.PageQuery;
|
||||||
|
import com.das.common.utils.StringUtils;
|
||||||
|
import com.das.modules.auth.domain.vo.SysUserVo;
|
||||||
|
import com.das.modules.page.domian.dto.SysReportTemplateDto;
|
||||||
|
import com.das.modules.page.domian.vo.SysReportTemplateVo;
|
||||||
|
import com.das.modules.page.entity.SysReportTemplate;
|
||||||
|
import com.das.modules.page.mapper.SysReportTemplateMapper;
|
||||||
|
import com.das.modules.page.service.ReportTemplateService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ReportTemplateServiceImpl implements ReportTemplateService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysReportTemplateMapper sysReportTemplateMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageDataInfo<SysReportTemplateVo> getReportTemplateList(SysReportTemplateDto sysReportTemplateDto) {
|
||||||
|
PageQuery pageQuery = new PageQuery();
|
||||||
|
pageQuery.setPageNum(sysReportTemplateDto.getPageNum());
|
||||||
|
pageQuery.setPageSize(sysReportTemplateDto.getPageSize());
|
||||||
|
IPage<SysReportTemplateVo> iPage = sysReportTemplateMapper.queryReportTemplateListInPage(pageQuery.build(), sysReportTemplateDto);
|
||||||
|
return PageDataInfo.build(iPage.getRecords(), iPage.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysReportTemplateVo addReportTemplate(SysReportTemplateDto sysReportTemplateDto) {
|
||||||
|
if (!StringUtils.isJsonString(sysReportTemplateDto.getTemplate())){
|
||||||
|
throw new ServiceException("模板内容格式错误");
|
||||||
|
}
|
||||||
|
SysReportTemplate sysReportTemplate = new SysReportTemplate();
|
||||||
|
BeanCopyUtils.copy(sysReportTemplateDto, sysReportTemplate);
|
||||||
|
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
|
||||||
|
sysReportTemplate.setCreatedBy(sysUserVo.getAccount());
|
||||||
|
sysReportTemplate.setUpdatedBy(sysUserVo.getAccount());
|
||||||
|
sysReportTemplate.setCreatedTime(new Date());
|
||||||
|
sysReportTemplate.setUpdatedTime(new Date());
|
||||||
|
sysReportTemplate.setRevision(1);
|
||||||
|
sysReportTemplateMapper.insert(sysReportTemplate);
|
||||||
|
SysReportTemplateVo sysReportTemplateVo = new SysReportTemplateVo();
|
||||||
|
BeanCopyUtils.copy(sysReportTemplate, sysReportTemplateVo);
|
||||||
|
return sysReportTemplateVo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delReportTemplate(SysReportTemplateDto sysReportTemplateDto) {
|
||||||
|
sysReportTemplateMapper.deleteById(sysReportTemplateDto.getId());
|
||||||
|
}
|
||||||
|
}
|
22
das/src/main/resources/mapper/SysReportTemplateMapper.xml
Normal file
22
das/src/main/resources/mapper/SysReportTemplateMapper.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.das.modules.page.mapper.SysReportTemplateMapper">
|
||||||
|
|
||||||
|
<resultMap type="com.das.modules.page.domian.vo.SysReportTemplateVo" id="ReportValuesMap">
|
||||||
|
<result property="id" column="id" jdbcType="BIGINT"/>
|
||||||
|
<result property="category" column="category" jdbcType="VARCHAR"/>
|
||||||
|
<result property="template" column="template" jdbcType="VARCHAR"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="queryReportTemplateListInPage" resultMap="ReportValuesMap">
|
||||||
|
select e.* from sys_report_template e
|
||||||
|
<where>
|
||||||
|
<if test="info.category != null and info.category != ''">
|
||||||
|
and e.category =#{info.category}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
141
docs/api/pages/report.md
Normal file
141
docs/api/pages/report.md
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
# 首页
|
||||||
|
|
||||||
|
## API接口-报表模板
|
||||||
|
|
||||||
|
| 接口分类 | 接口描述 | API接口 | 权限 |
|
||||||
|
|----------|--------------------|------------------------------| ---------------------------- |
|
||||||
|
| 2.1 报表模板 | 2.1.1 新增报表模板 | /api/report/template/add | SYS_AUTHORITY_ID_DEVICE_CTRL |
|
||||||
|
| | 2.1.2 根据模板分类查询模板列表 | /api/report/template/getList | |
|
||||||
|
| | 2.1.3 删除报表模板 | /api/report/template/del | SYS_AUTHORITY_ID_DEVICE_CTRL|
|
||||||
|
|
||||||
|
|
||||||
|
## 2.1 报表模板相关接口
|
||||||
|
|
||||||
|
### 2.1.1 新增报表模板
|
||||||
|
|
||||||
|
POST 请求接口
|
||||||
|
|
||||||
|
> /api/report/template/add
|
||||||
|
|
||||||
|
请求参数
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"category": "单机报表",
|
||||||
|
"template": "{\"name\":\"测试模板1\",\"startTime\":\"2024-11-04 14:15:00\"}"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
入参描述
|
||||||
|
|
||||||
|
| 参数名 | 参数类型 | 可选 | 描述 |
|
||||||
|
| ------------ |--------|----|------------------|
|
||||||
|
| category | String | NO | 报表分类;如:单机报表;多机报表 |
|
||||||
|
| template | String | NO | 模板内容(必须为:JSON格式) |
|
||||||
|
|
||||||
|
返回报文
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"id": "1853330292178747393",
|
||||||
|
"category": "单机报表",
|
||||||
|
"template": "{\"name\":\"测试模板1\",\"startTime\":\"2024-11-04 14:15:00\"}"
|
||||||
|
},
|
||||||
|
"msg": "操作成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
返参描述
|
||||||
|
|
||||||
|
| 参数名 | 参数类型 | 可选 | 描述 |
|
||||||
|
| ------------ |--------| ---- |--------|
|
||||||
|
| category | String | 否 | 报表分类 |
|
||||||
|
| template | String | 否 | 模板内容 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 2.1.2 根据模板分类查询模板列表
|
||||||
|
|
||||||
|
POST 请求接口
|
||||||
|
|
||||||
|
> /api/report/template/getList
|
||||||
|
|
||||||
|
请求参数
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"category": "单机报表",
|
||||||
|
"pageNum":1,
|
||||||
|
"pageSize":2
|
||||||
|
}
|
||||||
|
```
|
||||||
|
入参描述
|
||||||
|
|
||||||
|
| 参数名 | 参数类型 | 可选 | 描述 |
|
||||||
|
| ------------ |---------|-----|------------------|
|
||||||
|
| category | String | YES | 报表分类;如:单机报表;多机报表 |
|
||||||
|
| pageNum | Integer | NO | 当前页 |
|
||||||
|
| pageSize | Integer | NO | 每页显示大小|
|
||||||
|
|
||||||
|
返回报文
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"total": 3,
|
||||||
|
"rows": [
|
||||||
|
{
|
||||||
|
"id": "1853320886498217986",
|
||||||
|
"category": "单机报表",
|
||||||
|
"template": "{\"name\":\"测试模板2\",\"startTime\":\"2024-11-04 14:15:00\"}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1853328049337548801",
|
||||||
|
"category": "单机报表",
|
||||||
|
"template": "{\"name\":\"测试模板3\",\"startTime\":\"2024-11-04 14:15:00\"}"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"code": 200,
|
||||||
|
"msg": "查询成功"
|
||||||
|
},
|
||||||
|
"msg": "操作成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
返参描述
|
||||||
|
|
||||||
|
| 参数名 | 参数类型 | 可选 | 描述 |
|
||||||
|
| ------------ |--------| ---- |--------|
|
||||||
|
| category | String | 否 | 报表分类 |
|
||||||
|
| template | String | 否 | 模板内容 |
|
||||||
|
|
||||||
|
### 2.1.3 删除报表模板
|
||||||
|
|
||||||
|
POST 请求接口
|
||||||
|
|
||||||
|
> /api/report/template/del
|
||||||
|
|
||||||
|
请求参数
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "1853320886498217986"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
入参描述
|
||||||
|
|
||||||
|
| 参数名 | 参数类型 | 可选 | 描述 |
|
||||||
|
| ------------ | -------- | ---- |------------------------------------------------------------------|
|
||||||
|
| id | String | no | 报表模板id |
|
||||||
|
|
||||||
|
返回报文
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"success": true,
|
||||||
|
"msg": "操作成功"
|
||||||
|
}
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user