From 0d3efe4f80073db60a0d016ee1422d1faa4b295f Mon Sep 17 00:00:00 2001
From: liuhongfeng <291117974@qq.com>
Date: Sun, 3 Dec 2023 17:25:32 +0800
Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91ureport2?=
=?UTF-8?q?=E8=8F=9C=E5=8D=95=EF=BC=8C=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE=EF=BC=8C=E6=8C=89=E7=85=A7=E8=A7=84=E8=8C=83=E9=87=8D?=
=?UTF-8?q?=E6=96=B0=E8=BF=9B=E8=A1=8C=E5=91=BD=E5=90=8D=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sql/mysql/Ureport.sql | 50 +++---
.../report/enums/ErrorCodeConstants.java | 4 +-
.../admin/ureport/UReportDataController.java | 95 ++++++++++++
.../admin/ureport/UreportFileController.java | 95 ------------
...geReqVO.java => UReportDataPageReqVO.java} | 8 +-
...FileRespVO.java => UReportDataRespVO.java} | 19 ++-
...veReqVO.java => UReportDataSaveReqVO.java} | 25 ++-
...{UreportFileDO.java => UReportDataDO.java} | 15 +-
.../dal/mysql/ureport/UReportDataMapper.java | 60 ++++++++
.../dal/mysql/ureport/UreportFileMapper.java | 29 ----
.../config/SecurityConfiguration.java | 22 +++
.../security/config/UReportFilter.java | 80 ++++++++++
.../security/config/UReportProperties.java | 17 +++
...uration.java => UReportConfiguration.java} | 12 +-
...DataSource.java => UReportDataSource.java} | 14 +-
.../ureport/core/UReportDatabaseProvider.java | 106 +++++++++++++
.../ureport/core/UreportDatabaseProvider.java | 142 ------------------
.../core/UreportFileReportProvider.java | 120 ---------------
...leService.java => UReportDataService.java} | 64 ++++----
.../ureport/UReportDataServiceImpl.java | 94 ++++++++++++
.../ureport/UreportFileServiceImpl.java | 110 --------------
.../mapper/ureport/UReportDataMapper.xml | 12 ++
.../ureport/UReportDataServiceImplTest.java | 135 +++++++++++++++++
.../ureport/UreportFileServiceImplTest.java | 136 -----------------
.../src/test/resources/sql/clean.sql | 2 +-
.../src/test/resources/sql/create_tables.sql | 24 +--
.../src/main/resources/application.yaml | 2 +-
27 files changed, 742 insertions(+), 750 deletions(-)
create mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UReportDataController.java
delete mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UreportFileController.java
rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/{UreportFilePageReqVO.java => UReportDataPageReqVO.java} (80%)
rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/{UreportFileRespVO.java => UReportDataRespVO.java} (72%)
rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/{UreportFileSaveReqVO.java => UReportDataSaveReqVO.java} (56%)
rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/{UreportFileDO.java => UReportDataDO.java} (63%)
create mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java
delete mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UreportFileMapper.java
create mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportFilter.java
create mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportProperties.java
rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/{UreportConfiguration.java => UReportConfiguration.java} (58%)
rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/{UreportDataSource.java => UReportDataSource.java} (61%)
create mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java
delete mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UreportDatabaseProvider.java
delete mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UreportFileReportProvider.java
rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/{UreportFileService.java => UReportDataService.java} (54%)
create mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java
delete mode 100644 yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java
create mode 100644 yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml
create mode 100644 yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java
delete mode 100644 yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImplTest.java
diff --git a/sql/mysql/Ureport.sql b/sql/mysql/Ureport.sql
index f75efb874..8d343960d 100644
--- a/sql/mysql/Ureport.sql
+++ b/sql/mysql/Ureport.sql
@@ -4,8 +4,8 @@ INSERT INTO system_menu(
path, icon, component, status, component_name
)
VALUES (
- 'Ureport2报表', '', 2, 0, 1281,
- 'ureport-file', '', 'report/ureport/index', 0, 'UreportFile'
+ 'Ureport2报表管理', '', 2, 0, 1281,
+ 'ureport-data', '', 'report/ureport/index', 0, 'UReportData'
);
-- 按钮父菜单ID
@@ -18,7 +18,7 @@ INSERT INTO system_menu(
path, icon, component, status
)
VALUES (
- 'Ureport2报表查询', 'report:ureport-file:query', 3, 1, @parentId,
+ 'Ureport2报表查询', 'report:ureport-data:query', 3, 1, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
@@ -26,7 +26,7 @@ INSERT INTO system_menu(
path, icon, component, status
)
VALUES (
- 'Ureport2报表创建', 'report:ureport-file:create', 3, 2, @parentId,
+ 'Ureport2报表创建', 'report:ureport-data:create', 3, 2, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
@@ -34,7 +34,7 @@ INSERT INTO system_menu(
path, icon, component, status
)
VALUES (
- 'Ureport2报表更新', 'report:ureport-file:update', 3, 3, @parentId,
+ 'Ureport2报表更新', 'report:ureport-data:update', 3, 3, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
@@ -42,7 +42,7 @@ INSERT INTO system_menu(
path, icon, component, status
)
VALUES (
- 'Ureport2报表删除', 'report:ureport-file:delete', 3, 4, @parentId,
+ 'Ureport2报表删除', 'report:ureport-data:delete', 3, 4, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
@@ -50,28 +50,28 @@ INSERT INTO system_menu(
path, icon, component, status
)
VALUES (
- 'Ureport2报表导出', 'report:ureport-file:export', 3, 5, @parentId,
+ 'Ureport2报表导出', 'report:ureport-data:export', 3, 5, @parentId,
'', '', '', 0
);
--- 创建数据库表
-DROP TABLE IF EXISTS `ureport_file`;
-CREATE TABLE `ureport_file` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
- `file_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '文件名称',
- `status` tinyint(4) NOT NULL COMMENT '状态',
- `file_content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '文件内容',
- `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
- `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
- `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
- `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
- `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
- `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
- `tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号',
- PRIMARY KEY (`id`) USING BTREE
+DROP TABLE IF EXISTS `report_ureport_data`;
+CREATE TABLE `report_ureport_data` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+ `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '文件名称',
+ `status` tinyint(4) NOT NULL COMMENT '状态',
+ `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '文件内容',
+ `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
+ `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
+ `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
+ `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+ `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
+ `tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号',
+ PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'Ureport2报表' ROW_FORMAT = Dynamic;
-
--- 插入测试报表
-INSERT INTO `ureport_file` (`id`, `file_name`, `status`, `file_content`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (7, '角色对应的用户列表.ureport.xml', 0, ' | | | | | | | | | | | | | | | | | | |
|
', NULL, NULL, '2023-11-22 22:02:44', NULL, '2023-11-22 22:06:51', b'0', 0);
+-- ----------------------------
+-- Records of report_ureport_data
+-- ----------------------------
+INSERT INTO `report_ureport_data` VALUES (11, 'role.ureport.xml', 0, ' | | | | | | | | | | | | |
|
', NULL, NULL, '2023-11-25 22:40:58', NULL, '2023-11-25 23:00:42', b'0', 0);
diff --git a/yudao-module-report/yudao-module-report-api/src/main/java/cn/iocoder/yudao/module/report/enums/ErrorCodeConstants.java b/yudao-module-report/yudao-module-report-api/src/main/java/cn/iocoder/yudao/module/report/enums/ErrorCodeConstants.java
index 4757908cd..206ceec63 100644
--- a/yudao-module-report/yudao-module-report-api/src/main/java/cn/iocoder/yudao/module/report/enums/ErrorCodeConstants.java
+++ b/yudao-module-report/yudao-module-report-api/src/main/java/cn/iocoder/yudao/module/report/enums/ErrorCodeConstants.java
@@ -13,7 +13,7 @@ public interface ErrorCodeConstants {
ErrorCode GO_VIEW_PROJECT_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在");
// ========== UREPORT 模块 1-003-001-000 ==========
- ErrorCode UREPORT_FILE_NOT_EXISTS = new ErrorCode(1_003_001_000, "打印文件不存在,请检查 UReport 报表文件");
- ErrorCode UREPORT_FILE_EXISTS = new ErrorCode(1_003_001_001, "报表名字已存在,请修改后再保存");
+ ErrorCode REPORT_DATA_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2报表不存在");
+ ErrorCode REPORT_DATABASE_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2报表数据源不存在");
}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UReportDataController.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UReportDataController.java
new file mode 100644
index 000000000..e6c0036f6
--- /dev/null
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UReportDataController.java
@@ -0,0 +1,95 @@
+package cn.iocoder.yudao.module.report.controller.admin.ureport;
+
+import org.springframework.web.bind.annotation.*;
+import javax.annotation.Resource;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.security.access.prepost.PreAuthorize;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Operation;
+
+import javax.validation.constraints.*;
+import javax.validation.*;
+import javax.servlet.http.*;
+import java.util.*;
+import java.io.IOException;
+
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+
+import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
+import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
+
+import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
+import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
+import cn.iocoder.yudao.module.report.service.ureport.UReportDataService;
+
+@Tag(name = "管理后台 - Ureport2报表")
+@RestController
+@RequestMapping("/report/ureport-data")
+@Validated
+public class UReportDataController {
+
+ @Resource
+ private UReportDataService uReportDataService;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建Ureport2报表")
+ @PreAuthorize("@ss.hasPermission('report:ureport-data:create')")
+ public CommonResult createUReportData(@Valid @RequestBody UReportDataSaveReqVO createReqVO) {
+ return success(uReportDataService.createUReportData(createReqVO));
+ }
+
+ @PutMapping("/update")
+ @Operation(summary = "更新Ureport2报表")
+ @PreAuthorize("@ss.hasPermission('report:ureport-data:update')")
+ public CommonResult updateUReportData(@Valid @RequestBody UReportDataSaveReqVO updateReqVO) {
+ uReportDataService.updateUReportData(updateReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除Ureport2报表")
+ @Parameter(name = "id", description = "编号", required = true)
+ @PreAuthorize("@ss.hasPermission('report:ureport-data:delete')")
+ public CommonResult deleteUReportData(@RequestParam("id") Long id) {
+ uReportDataService.deleteUReportData(id);
+ return success(true);
+ }
+
+ @GetMapping("/get")
+ @Operation(summary = "获得Ureport2报表")
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
+ @PreAuthorize("@ss.hasPermission('report:ureport-data:query')")
+ public CommonResult getUReportData(@RequestParam("id") Long id) {
+ UReportDataDO uReportData = uReportDataService.getUReportData(id);
+ return success(BeanUtils.toBean(uReportData, UReportDataRespVO.class));
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得Ureport2报表分页")
+ @PreAuthorize("@ss.hasPermission('report:ureport-data:query')")
+ public CommonResult> getUReportDataPage(@Valid UReportDataPageReqVO pageReqVO) {
+ PageResult pageResult = uReportDataService.getUReportDataPage(pageReqVO);
+ return success(BeanUtils.toBean(pageResult, UReportDataRespVO.class));
+ }
+
+ @GetMapping("/export-excel")
+ @Operation(summary = "导出Ureport2报表 Excel")
+ @PreAuthorize("@ss.hasPermission('report:ureport-data:export')")
+ @OperateLog(type = EXPORT)
+ public void exportUReportDataExcel(@Valid UReportDataPageReqVO pageReqVO,
+ HttpServletResponse response) throws IOException {
+ pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+ List list = uReportDataService.getUReportDataPage(pageReqVO).getList();
+ // 导出 Excel
+ ExcelUtils.write(response, "Ureport2报表.xls", "数据", UReportDataRespVO.class,
+ BeanUtils.toBean(list, UReportDataRespVO.class));
+ }
+
+}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UreportFileController.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UreportFileController.java
deleted file mode 100644
index cd2068d98..000000000
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UreportFileController.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package cn.iocoder.yudao.module.report.controller.admin.ureport;
-
-import cn.iocoder.yudao.framework.common.pojo.CommonResult;
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
-import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileRespVO;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
-import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
-import cn.iocoder.yudao.module.report.service.ureport.UreportFileService;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
-
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletResponse;
-import javax.validation.Valid;
-import java.io.IOException;
-import java.util.List;
-
-import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
-import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
-
-// TODO @赤焰: Ureport 改成 UReport
-@Tag(name = "管理后台 - UReport2 报表")
-@RestController
-@RequestMapping("/report/ureport-file")
-@Validated
-public class UreportFileController {
-
- @Resource
- private UreportFileService ureportFileService;
-
- @PostMapping("/create")
- @Operation(summary = "创建 UReport2 报表")
- @PreAuthorize("@ss.hasPermission('report:ureport-file:create')")
- public CommonResult createUreportFile(@Valid @RequestBody UreportFileSaveReqVO createReqVO) {
- return success(ureportFileService.createUreportFile(createReqVO));
- }
-
- @PutMapping("/update")
- @Operation(summary = "更新 UReport2 报表")
- @PreAuthorize("@ss.hasPermission('report:ureport-file:update')")
- public CommonResult updateUreportFile(@Valid @RequestBody UreportFileSaveReqVO updateReqVO) {
- ureportFileService.updateUreportFile(updateReqVO);
- return success(true);
- }
-
- @DeleteMapping("/delete")
- @Operation(summary = "删除 UReport2 报表")
- @Parameter(name = "id", description = "编号", required = true)
- @PreAuthorize("@ss.hasPermission('report:ureport-file:delete')")
- public CommonResult deleteUreportFile(@RequestParam("id") Long id) {
- ureportFileService.deleteUreportFile(id);
- return success(true);
- }
-
- @GetMapping("/get")
- @Operation(summary = "获得 UReport2 报表")
- @Parameter(name = "id", description = "编号", required = true, example = "1024")
- @PreAuthorize("@ss.hasPermission('report:ureport-file:query')")
- public CommonResult getUreportFile(@RequestParam("id") Long id) {
- UreportFileDO ureportFile = ureportFileService.getUreportFile(id);
- return success(BeanUtils.toBean(ureportFile, UreportFileRespVO.class));
- }
-
- @GetMapping("/page")
- @Operation(summary = "获得 UReport2 报表分页")
- @PreAuthorize("@ss.hasPermission('report:ureport-file:query')")
- public CommonResult> getUreportFilePage(@Valid UreportFilePageReqVO pageReqVO) {
- PageResult pageResult = ureportFileService.getUreportFilePage(pageReqVO);
- return success(BeanUtils.toBean(pageResult, UreportFileRespVO.class));
- }
-
- // TODO @赤焰:导出是必须的么?没用可以删除哈
- @GetMapping("/export-excel")
- @Operation(summary = "导出 UReport2 报表 Excel")
- @PreAuthorize("@ss.hasPermission('report:ureport-file:export')")
- @OperateLog(type = EXPORT)
- public void exportUreportFileExcel(@Valid UreportFilePageReqVO pageReqVO,
- HttpServletResponse response) throws IOException {
- pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
- List list = ureportFileService.getUreportFilePage(pageReqVO).getList();
- // 导出 Excel
- ExcelUtils.write(response, "Ureport2报表.xls", "数据", UreportFileRespVO.class,
- BeanUtils.toBean(list, UreportFileRespVO.class));
- }
-
-}
\ No newline at end of file
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFilePageReqVO.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataPageReqVO.java
similarity index 80%
rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFilePageReqVO.java
rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataPageReqVO.java
index 558b50fbf..a31b8c5b3 100644
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFilePageReqVO.java
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataPageReqVO.java
@@ -13,15 +13,15 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
-public class UreportFilePageReqVO extends PageParam {
+public class UReportDataPageReqVO extends PageParam {
- @Schema(description = "文件名称", example = "赵六")
- private String fileName;
+ @Schema(description = "文件名称", example = "李四")
+ private String name;
@Schema(description = "状态", example = "1")
private Integer status;
- @Schema(description = "备注", example = "随便")
+ @Schema(description = "备注", example = "你猜")
private String remark;
@Schema(description = "创建时间")
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFileRespVO.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataRespVO.java
similarity index 72%
rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFileRespVO.java
rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataRespVO.java
index 21dfcebcb..cea23829a 100644
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFileRespVO.java
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataRespVO.java
@@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.report.controller.admin.ureport.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
+import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
@@ -12,22 +13,26 @@ import java.time.LocalDateTime;
@Schema(description = "管理后台 - Ureport2报表 Response VO")
@Data
@ExcelIgnoreUnannotated
-public class UreportFileRespVO {
+public class UReportDataRespVO {
- @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9948")
+ @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26175")
@ExcelProperty("ID")
private Long id;
- @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
+ @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@ExcelProperty("文件名称")
- private String fileName;
+ private String name;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
- @ExcelProperty("状态")
+ @ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
- @Schema(description = "备注", example = "随便")
+ @Schema(description = "文件内容")
+ @ExcelProperty("文件内容")
+ private String content;
+
+ @Schema(description = "备注", example = "你猜")
@ExcelProperty("备注")
private String remark;
@@ -35,4 +40,4 @@ public class UreportFileRespVO {
@ExcelProperty("创建时间")
private LocalDateTime createTime;
-}
\ No newline at end of file
+}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFileSaveReqVO.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataSaveReqVO.java
similarity index 56%
rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFileSaveReqVO.java
rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataSaveReqVO.java
index 2eebca463..206796871 100644
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFileSaveReqVO.java
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataSaveReqVO.java
@@ -1,33 +1,30 @@
package cn.iocoder.yudao.module.report.controller.admin.ureport.vo;
-import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
-import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-
-import javax.validation.constraints.NotEmpty;
-import javax.validation.constraints.NotNull;
+import lombok.*;
+import java.util.*;
+import javax.validation.constraints.*;
+import java.util.*;
@Schema(description = "管理后台 - Ureport2报表新增/修改 Request VO")
@Data
-public class UreportFileSaveReqVO {
+public class UReportDataSaveReqVO {
- @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9948")
+ @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26175")
private Long id;
- @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
+ @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@NotEmpty(message = "文件名称不能为空")
- private String fileName;
+ private String name;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
- @InEnum(CommonStatusEnum.class)
private Integer status;
@Schema(description = "文件内容")
- private String fileContent;
+ private String content;
- @Schema(description = "备注", example = "随便")
+ @Schema(description = "备注", example = "你猜")
private String remark;
-}
+}
\ No newline at end of file
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UreportFileDO.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UReportDataDO.java
similarity index 63%
rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UreportFileDO.java
rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UReportDataDO.java
index f06744138..55bb2e2a7 100644
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UreportFileDO.java
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UReportDataDO.java
@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.report.dal.dataobject.ureport;
+import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
@@ -11,35 +12,35 @@ import lombok.*;
*
* @author 芋道源码
*/
-@TableName("ureport_file")
-@KeySequence("ureport_file_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@TableName("report_ureport_data")
+@KeySequence("report_ureport_data_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
-public class UreportFileDO extends BaseDO {
+public class UReportDataDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
- // TODO @赤焰:是不是用 name 就可以了。
/**
* 文件名称
*/
- private String fileName;
+ private String name;
/**
* 状态
+ *
+ * 枚举 {@link CommonStatusEnum#getStatus()}
*/
private Integer status;
- // TODO @赤焰:是不是用 string 就可以了。然后字段名用 content?
/**
* 文件内容
*/
- private byte[] fileContent;
+ private String content;
/**
* 备注
*/
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java
new file mode 100644
index 000000000..a91f8f141
--- /dev/null
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java
@@ -0,0 +1,60 @@
+package cn.iocoder.yudao.module.report.dal.mysql.ureport;
+
+import java.util.*;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
+import org.apache.ibatis.annotations.Mapper;
+import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
+
+/**
+ * Ureport2报表 Mapper
+ *
+ * @author 芋道源码
+ */
+@Mapper
+public interface UReportDataMapper extends BaseMapperX {
+
+ default PageResult selectPage(UReportDataPageReqVO reqVO) {
+ return selectPage(reqVO, new LambdaQueryWrapperX()
+ .likeIfPresent(UReportDataDO::getName, reqVO.getName())
+ .eqIfPresent(UReportDataDO::getStatus, reqVO.getStatus())
+ .eqIfPresent(UReportDataDO::getRemark, reqVO.getRemark())
+ .betweenIfPresent(UReportDataDO::getCreateTime, reqVO.getCreateTime())
+ .orderByDesc(UReportDataDO::getId));
+ }
+
+ /**
+ * 根据名字查询报表
+ * @param name 报表名字
+ * @return
+ */
+ default List selectByName(String name){
+ return selectList(new LambdaQueryWrapperX()
+ .eqIfPresent(UReportDataDO::getName,name));
+ }
+
+ /**
+ * 根据名字查询报表
+ * @param name 报表名字
+ * @return
+ */
+ default UReportDataDO selectOneByName(String name){
+ return selectOne(new LambdaQueryWrapperX()
+ .eqIfPresent(UReportDataDO::getName,name));
+ }
+
+
+ /**
+ * 根据名字删除报表
+ * @param name 报表名字
+ * @return
+ */
+ default int deleteByName(String name){
+ return delete(new LambdaQueryWrapperX()
+ .eqIfPresent(UReportDataDO::getName,name));
+ }
+
+}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UreportFileMapper.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UreportFileMapper.java
deleted file mode 100644
index 618b80414..000000000
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UreportFileMapper.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package cn.iocoder.yudao.module.report.dal.mysql.ureport;
-
-import java.util.*;
-
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
-import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
-import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
-import org.apache.ibatis.annotations.Mapper;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
-
-/**
- * Ureport2报表 Mapper
- *
- * @author 芋道源码
- */
-@Mapper
-public interface UreportFileMapper extends BaseMapperX {
-
- default PageResult selectPage(UreportFilePageReqVO reqVO) {
- return selectPage(reqVO, new LambdaQueryWrapperX()
- .likeIfPresent(UreportFileDO::getFileName, reqVO.getFileName())
- .eqIfPresent(UreportFileDO::getStatus, reqVO.getStatus())
- .eqIfPresent(UreportFileDO::getRemark, reqVO.getRemark())
- .betweenIfPresent(UreportFileDO::getCreateTime, reqVO.getCreateTime())
- .orderByDesc(UreportFileDO::getId));
- }
-
-}
\ No newline at end of file
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java
index f986f0d4d..1fc745f12 100644
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java
@@ -1,10 +1,17 @@
package cn.iocoder.yudao.module.report.framework.security.config;
+import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer;
+import cn.iocoder.yudao.framework.security.config.SecurityProperties;
+import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.Resource;
/**
* Report 模块的 Security 配置
@@ -12,6 +19,9 @@ import org.springframework.security.config.annotation.web.configurers.Expression
@Configuration("reportSecurityConfiguration")
public class SecurityConfiguration {
+ @Resource
+ private OAuth2TokenApi oauth2TokenApi;
+
@Bean("reportAuthorizeRequestsCustomizer")
public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {
return new AuthorizeRequestsCustomizer() {
@@ -25,4 +35,16 @@ public class SecurityConfiguration {
};
}
+
+ /**
+ * 创建 UReportFilter 过滤器,响应 header 设置 token
+ */
+ /*@Bean
+ public FilterRegistrationBean uReportFilterFilterRegistrationBean() {
+ FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
+ registrationBean.setFilter(new UReportFilter(oauth2TokenApi));
+ registrationBean.setOrder(WebFilterOrderEnum.TRACE_FILTER);
+ return registrationBean;
+ }*/
+
}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportFilter.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportFilter.java
new file mode 100644
index 000000000..5ff22d6f4
--- /dev/null
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportFilter.java
@@ -0,0 +1,80 @@
+package cn.iocoder.yudao.module.report.framework.security.config;
+
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
+import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
+import cn.iocoder.yudao.framework.security.core.LoginUser;
+import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
+import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
+import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
+import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
+import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
+import lombok.Data;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * UReport 认证过滤器
+ * @author 赤焰
+ */
+@Slf4j
+@RequiredArgsConstructor
+public class UReportFilter extends OncePerRequestFilter {
+
+ private final static String TOKEN = "token";
+
+ private final OAuth2TokenApi oauth2TokenApi;
+
+ @Override
+ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
+ throws ServletException, IOException {
+
+ if(log.isDebugEnabled()){
+ log.debug("UReportFilter自定义过滤器");
+ }
+
+ Map paramMap = ServletUtils.getParamMap(request);
+ String requestURI = request.getRequestURI();
+ boolean contains = requestURI.contains("/ureport");
+ if (paramMap.containsKey(TOKEN)&&contains) {
+ String token = request.getParameter(TOKEN);
+ if(log.isDebugEnabled()){
+ log.debug("UReportFilter自定义过滤器 token="+token);
+ }
+
+ response.addHeader(TOKEN,token);
+
+ TenantContextHolder.setIgnore(true); // 忽略租户,保证可查询到 token 信息
+ LoginUser user = null;
+ try {
+ OAuth2AccessTokenCheckRespDTO accessToken = oauth2TokenApi.checkAccessToken(token);
+ if (accessToken != null) {
+ user = new LoginUser().setId(accessToken.getUserId()).setUserType(accessToken.getUserType())
+ .setTenantId(accessToken.getTenantId()).setScopes(accessToken.getScopes());
+ if (user != null) {
+ SecurityFrameworkUtils.setLoginUser(user, WebFrameworkUtils.getRequest());
+
+ // ② 参考 TenantContextWebFilter 实现(Tenant 的上下文清理,交给 TenantContextWebFilter 完成)
+ // 目的:基于 LoginUser 获得到的租户编号,设置到 Tenant 上下文,避免查询数据库时的报错
+ TenantContextHolder.setIgnore(false);
+ TenantContextHolder.setTenantId(user.getTenantId());
+ }
+ }
+ } catch (ServiceException ignored) {
+ chain.doFilter(request, response);
+ }
+
+ }
+
+ // 继续过滤
+ chain.doFilter(request, response);
+
+ }
+}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportProperties.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportProperties.java
new file mode 100644
index 000000000..5bf5e20e4
--- /dev/null
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportProperties.java
@@ -0,0 +1,17 @@
+package cn.iocoder.yudao.module.report.framework.security.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * UReport配置类
+ *
+ * @author 赤焰
+ */
+@Data
+@ConfigurationProperties(prefix = "ureport.provider.database")
+public class UReportProperties {
+ private String name = "数据库文件系统";
+ private String prefix = "db-";
+ private boolean disabled = false;
+}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfiguration.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportConfiguration.java
similarity index 58%
rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfiguration.java
rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportConfiguration.java
index 0642bc30c..25c4b3a00 100644
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfiguration.java
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportConfiguration.java
@@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.report.framework.ureport.config;
+import cn.iocoder.yudao.module.report.framework.security.config.UReportProperties;
import com.bstek.ureport.console.UReportServlet;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -15,13 +17,13 @@ import javax.servlet.Servlet;
* @author 赤焰
*/
@Configuration
-@ImportResource({"classpath:ureport-console-context.xml"}) // Bean 配置
-@PropertySource(value = {"classpath:ureport.properties"}) // 配置文件
-public class UreportConfiguration {
+@ImportResource({"classpath:ureport-console-context.xml"})
+@PropertySource(value = {"classpath:ureport.properties"})
+@EnableConfigurationProperties({UReportProperties.class})
+public class UReportConfiguration {
- // TODO @赤焰:bean 是不是取个和 ureport 相关的名字好点哈?
@Bean
- public ServletRegistrationBean registrationBean() {
+ public ServletRegistrationBean uReportRegistrationBean() {
return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*");
}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportDataSource.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportDataSource.java
similarity index 61%
rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportDataSource.java
rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportDataSource.java
index 5d079e3c7..46e9e9e93 100644
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportDataSource.java
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportDataSource.java
@@ -9,14 +9,18 @@ import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.REPORT_DATABASE_NOT_EXISTS;
+
/**
* UReport 内置数据源
+ * @author 赤焰
*/
@Slf4j
@Component
-public class UreportDataSource implements BuildinDatasource {
+public class UReportDataSource implements BuildinDatasource {
- private static final String NAME = "UreportDataSource";
+ private static final String NAME = "UReportDataSource";
@Resource
private DataSource dataSource;
@@ -29,7 +33,6 @@ public class UreportDataSource implements BuildinDatasource {
return NAME;
}
- // TODO @赤焰:这个方法,如果拿不到连接,是不是抛出异常比较好?
/**
* @return 获取连接
*/
@@ -38,10 +41,9 @@ public class UreportDataSource implements BuildinDatasource {
try {
return dataSource.getConnection();
} catch (SQLException e) {
- log.error("Ureport 数据源 获取连接失败!");
- e.printStackTrace();
+ log.error("UReportDataSource获取连接失败!");
+ throw exception(REPORT_DATABASE_NOT_EXISTS);
}
- return null;
}
}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java
new file mode 100644
index 000000000..d06e9da54
--- /dev/null
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java
@@ -0,0 +1,106 @@
+package cn.iocoder.yudao.module.report.framework.ureport.core;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
+import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
+import cn.iocoder.yudao.framework.common.util.date.DateUtils;
+import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO;
+import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
+import cn.iocoder.yudao.module.report.framework.security.config.UReportProperties;
+import cn.iocoder.yudao.module.report.service.ureport.UReportDataService;
+import com.bstek.ureport.provider.report.ReportFile;
+import com.bstek.ureport.provider.report.ReportProvider;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * 基于数据库的 {@link ReportProvider} 实现类
+ *
+ * @author 赤焰
+ */
+@Component
+@Slf4j
+@Setter
+public class UReportDatabaseProvider implements ReportProvider {
+
+ @Autowired
+ private UReportProperties uReportProperties;
+ @Resource
+ private UReportDataService uReportDataService;
+
+ @Override
+ public InputStream loadReport(String name) {
+ uReportDataService.validateUReportDataExists(getCorrectName(name));
+ UReportDataDO uReportDataDO = uReportDataService.selectOneByName(getCorrectName(name));
+ String content = uReportDataDO.getContent();
+ return new ByteArrayInputStream(content.getBytes());
+ }
+
+ @Override
+ public void deleteReport(String name) {
+ uReportDataService.deleteByName(getCorrectName(name));
+ }
+
+ @Override
+ public List getReportFiles() {
+ List list = uReportDataService.getReportDataList();
+ if(CollUtil.isEmpty(list)) {
+ return Collections.emptyList();
+ }
+ return CollectionUtils.convertList(list, report -> new ReportFile(report.getName(), DateUtils.of(report.getUpdateTime())));
+
+ }
+
+ @Override
+ public void saveReport(String name, String content) {
+ name = getCorrectName(name);
+ UReportDataDO uReportDataDO = uReportDataService.selectOneByName(name);
+ UReportDataSaveReqVO saveReqVO = new UReportDataSaveReqVO();
+ if (uReportDataDO == null) {
+ saveReqVO.setName(name);
+ saveReqVO.setContent(content);
+ saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
+ uReportDataService.createUReportData(saveReqVO);
+ } else {
+ saveReqVO.setId(uReportDataDO.getId());
+ saveReqVO.setName(name);
+ saveReqVO.setContent(content);
+ saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
+ uReportDataService.updateUReportData(saveReqVO);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return uReportProperties.getName();
+ }
+
+ @Override
+ public boolean disabled() {
+ return uReportProperties.isDisabled();
+ }
+
+ @Override
+ public String getPrefix() {
+ return uReportProperties.getPrefix();
+ }
+
+ /**
+ * 去除存储媒介,获取报表名字
+ * @param name 前端传入的报表带存储媒介的名字
+ * @return
+ */
+ private String getCorrectName(String name) {
+ return StrUtil.removePrefix(name,getPrefix());
+ }
+
+}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UreportDatabaseProvider.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UreportDatabaseProvider.java
deleted file mode 100644
index f44b1874f..000000000
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UreportDatabaseProvider.java
+++ /dev/null
@@ -1,142 +0,0 @@
-package cn.iocoder.yudao.module.report.framework.ureport.core;
-
-import cn.hutool.core.collection.CollUtil;
-import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
-import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
-import cn.iocoder.yudao.module.report.service.ureport.UreportFileService;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.bstek.ureport.provider.report.ReportFile;
-import com.bstek.ureport.provider.report.ReportProvider;
-import lombok.Setter;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_EXISTS;
-import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS;
-
-// TODO @赤焰:有了这个功能,是不是就不需要 UreportFileController?
-/**
- * 基于数据库的 {@link ReportProvider} 实现类
- *
- * @author 赤焰
- */
-@Component
-@Slf4j
-@Setter
-@ConfigurationProperties(prefix = "ureport.provider.database") // TODO @赤焰:是不是单独搞个 UReportProperties 用来注入 prefix、disabled 等属性
-public class UreportDatabaseProvider implements ReportProvider {
-
- private static final String NAME = "mysql-provider";
-
- // TODO @赤焰:IdTypeEnvironmentPostProcessor 参考下,通过 primary 数据源获取
- private String prefix = "mysql:";
-
- private boolean disabled = false;
-
- @Resource
- private UreportFileService ureportFileService;
-
- @Override
- public InputStream loadReport(String file) {
- // TODO @赤焰:是不是不需要这个 check 接口?直接使用 name 查询就 ok 了?
- // TODO @赤焰:变量的命名要注意,这里 reportDo 是不是叫 count 就好了?还有,这个方法的命名也不太对。
- Long reportDo = ureportFileService.checkExistByName(getCorrectName(file));
- if (reportDo <=0) { // TODO 赤焰:<= 0 注释空格
- throw exception(UREPORT_FILE_NOT_EXISTS);
- }
- // TODO @赤焰:queryUreportFileDoByName 改成 getUreportFileDoByName 更合适,保持整个项目的命名风格一致性。
- UreportFileDO ureportFileDO = ureportFileService.queryUreportFileDoByName(getCorrectName(file));
- byte[] content = ureportFileDO.getFileContent();
- return new ByteArrayInputStream(content);
- }
-
- @Override
- public void deleteReport(String file) {
- ureportFileService.deleteReportFileByName(getCorrectName(file));
- }
-
- @Override
- public List getReportFiles() {
- // TODO @赤焰:queryReportFileList 改成 getReportFileList 更合适,保持整个项目的命名风格一致性。
- List list = ureportFileService.queryReportFileList();
- List reportList = new ArrayList<>();
- if(CollUtil.isEmpty(list)){ // TODO 赤焰:CollUtil.isEmpty(list) 注意空格
- // TODO @赤焰:这里可以直接返回 Collections.emptyList();
- return reportList;
- }
- // TODO 赤焰:可以使用 CollectionUtils.converList
- for (UreportFileDO reportFile : list) {
- // TODO 赤焰:可以使用 DateUtils.of() 么?
- LocalDateTime updateTime = reportFile.getUpdateTime();
- ZonedDateTime zdt = updateTime.atZone(ZoneId.systemDefault());
- Date date = Date.from(zdt.toInstant());
- reportList.add(new ReportFile(reportFile.getFileName(),date));
- }
- return reportList;
-
- }
-
- @Override
- public void saveReport(String file, String content) {
- file = getCorrectName(file);
- // TODO @赤焰:这里的逻辑,应该封装到 ureportFileService 中,这里只负责调用即可
- LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(UreportFileDO::getFileName, file);
- Long count = ureportFileService.checkExistByName(file);
- if(count>1){
- throw exception(UREPORT_FILE_EXISTS);
- }
- UreportFileDO ureportFileDO = ureportFileService.queryUreportFileDoByName(file);
- UreportFileSaveReqVO saveReqVO = new UreportFileSaveReqVO();
- if (ureportFileDO == null) {
- saveReqVO.setFileName(file);
- saveReqVO.setFileContent(content);
- saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
- ureportFileService.createUreportFile(saveReqVO);
- } else {
- saveReqVO.setId(ureportFileDO.getId());
- saveReqVO.setFileName(file);
- saveReqVO.setFileContent(content);
- saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
- ureportFileService.updateUreportFile(saveReqVO);
- }
- }
-
- @Override
- public String getName() {
- return NAME;
- }
-
- @Override
- public boolean disabled() {
- return disabled;
- }
-
- @Override
- public String getPrefix() {
- return prefix;
- }
-
- // TODO @赤焰:这个方法的注释,最好写下哈;
- private String getCorrectName(String name) {
- // TODO 赤焰:一些常用方法,可以用 hutool StrUtil.removePrefix()
- if (name.startsWith(getPrefix())) {
- name = name.substring(getPrefix().length());
- }
- return name;
- }
-
-}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UreportFileReportProvider.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UreportFileReportProvider.java
deleted file mode 100644
index 0ce10076f..000000000
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UreportFileReportProvider.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
-package cn.iocoder.yudao.module.report.framework.ureport.provider;
-
-import com.bstek.ureport.exception.ReportException;
-import com.bstek.ureport.provider.report.ReportFile;
-import com.bstek.ureport.provider.report.ReportProvider;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.IOUtils;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
-
-import java.io.*;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-import java.util.Objects;
-
-// TODO @赤焰:这个类的作用是?如果全部注释,是不是可以删除哈?
-*/
-/**
- * 自定义文件存储,可接入oss等
- * @author 赤焰
- *//*
-
-@Slf4j
-@Component
-@ConfigurationProperties(prefix = "ureport.provider.file")
-public class UreportFileReportProvider implements ReportProvider{
-
- private String prefix="reportFile:";
- private String fileStoreDir;
- private boolean disabled;
-
- @Override
- public InputStream loadReport(String file) {
- if(file.startsWith(prefix)){
- file=file.substring(prefix.length(),file.length());
- }
- String fullPath=fileStoreDir+"/"+file;
- try {
- return new FileInputStream(fullPath);
- } catch (FileNotFoundException e) {
- throw new ReportException(e);
- }
- }
-
- @Override
- public void deleteReport(String file) {
- if(file.startsWith(prefix)){
- file=file.substring(prefix.length(),file.length());
- }
- String fullPath=fileStoreDir+"/"+file;
- File f=new File(fullPath);
- if(f.exists()){
- f.delete();
- }
- }
-
- @Override
- public List getReportFiles() {
- File file=new File(fileStoreDir);
- List list= new ArrayList<>();
- for(File f: Objects.requireNonNull(file.listFiles())){
- Calendar calendar=Calendar.getInstance();
- calendar.setTimeInMillis(f.lastModified());
- list.add(new ReportFile(f.getName(),calendar.getTime()));
- }
- list.sort((f1, f2) -> f2.getUpdateDate().compareTo(f1.getUpdateDate()));
- return list;
- }
-
- @Override
- public String getName() {
- return "文件存储系统";
- }
-
- @Override
- public void saveReport(String file,String content) {
- if(file.startsWith(prefix)){
- file=file.substring(prefix.length(),file.length());
- }
- String fullPath=fileStoreDir+"/"+file;
- FileOutputStream outStream=null;
- try{
- outStream=new FileOutputStream(new File(fullPath));
- IOUtils.write(content, outStream,"utf-8");
- }catch(Exception ex){
- throw new ReportException(ex);
- }finally{
- if(outStream!=null){
- try {
- outStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- }
-
- @Override
- public boolean disabled() {
- return disabled;
- }
-
- public void setDisabled(boolean disabled) {
- this.disabled = disabled;
- }
-
- public void setFileStoreDir(String fileStoreDir) {
- this.fileStoreDir = fileStoreDir;
- }
-
- @Override
- public String getPrefix() {
- return prefix;
- }
-
-}
-*/
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileService.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataService.java
similarity index 54%
rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileService.java
rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataService.java
index ed26f187e..fcefb583d 100644
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileService.java
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataService.java
@@ -1,9 +1,9 @@
package cn.iocoder.yudao.module.report.service.ureport;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
-import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
+import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO;
+import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO;
+import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
import javax.validation.Valid;
import java.util.List;
@@ -13,7 +13,7 @@ import java.util.List;
*
* @author 芋道源码
*/
-public interface UreportFileService {
+public interface UReportDataService {
/**
* 创建Ureport2报表
@@ -21,21 +21,21 @@ public interface UreportFileService {
* @param createReqVO 创建信息
* @return 编号
*/
- Long createUreportFile(@Valid UreportFileSaveReqVO createReqVO);
+ Long createUReportData(@Valid UReportDataSaveReqVO createReqVO);
/**
* 更新Ureport2报表
*
* @param updateReqVO 更新信息
*/
- void updateUreportFile(@Valid UreportFileSaveReqVO updateReqVO);
+ void updateUReportData(@Valid UReportDataSaveReqVO updateReqVO);
/**
* 删除Ureport2报表
*
* @param id 编号
*/
- void deleteUreportFile(Long id);
+ void deleteUReportData(Long id);
/**
* 获得Ureport2报表
@@ -43,7 +43,7 @@ public interface UreportFileService {
* @param id 编号
* @return Ureport2报表
*/
- UreportFileDO getUreportFile(Long id);
+ UReportDataDO getUReportData(Long id);
/**
* 获得Ureport2报表分页
@@ -51,36 +51,32 @@ public interface UreportFileService {
* @param pageReqVO 分页查询
* @return Ureport2报表分页
*/
- PageResult getUreportFilePage(UreportFilePageReqVO pageReqVO);
-
+ PageResult getUReportDataPage(UReportDataPageReqVO pageReqVO);
/**
- * 根据报表名称检查报表是否存在
- * @param name 报表名称
- * @return
- */
- Long checkExistByName(String name);
-
- /**
- * 根据报表名称查询报表
- * @param name 报表名称
- * @return
- */
- UreportFileDO queryUreportFileDoByName(String name);
-
-
- /**
- * 查询全部报表
- * @return
- */
- List queryReportFileList();
-
-
- /**
- * 根据报表名称删除报表
+ * 根据名称删除报表
* @param name
* @return
*/
- int deleteReportFileByName(String name);
+ int deleteByName(String name);
+
+ /**
+ * 根据名称校验报表是否存在
+ * @param name
+ */
+ void validateUReportDataExists(String name);
+
+ /**
+ * 根据名称查询报表
+ * @param name
+ * @return
+ */
+ UReportDataDO selectOneByName(String name);
+
+ /**
+ * 获取全部报表
+ * @return
+ */
+ List getReportDataList();
}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java
new file mode 100644
index 000000000..c99ce7cf3
--- /dev/null
+++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java
@@ -0,0 +1,94 @@
+package cn.iocoder.yudao.module.report.service.ureport;
+
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import org.springframework.validation.annotation.Validated;
+
+import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
+import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+
+import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper;
+
+import java.util.List;
+
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*;
+
+/**
+ * Ureport2报表 Service 实现类
+ *
+ * @author 芋道源码
+ */
+@Service
+@Validated
+public class UReportDataServiceImpl implements UReportDataService {
+
+ @Resource
+ private UReportDataMapper uReportDataMapper;
+
+ @Override
+ public Long createUReportData(UReportDataSaveReqVO createReqVO) {
+ // 插入
+ UReportDataDO uReportData = BeanUtils.toBean(createReqVO, UReportDataDO.class);
+ uReportDataMapper.insert(uReportData);
+ // 返回
+ return uReportData.getId();
+ }
+
+ @Override
+ public void updateUReportData(UReportDataSaveReqVO updateReqVO) {
+ // 校验存在
+ validateUReportDataExists(updateReqVO.getId());
+ // 更新
+ UReportDataDO updateObj = BeanUtils.toBean(updateReqVO, UReportDataDO.class);
+ uReportDataMapper.updateById(updateObj);
+ }
+
+ @Override
+ public void deleteUReportData(Long id) {
+ // 校验存在
+ validateUReportDataExists(id);
+ // 删除
+ uReportDataMapper.deleteById(id);
+ }
+
+ private void validateUReportDataExists(Long id) {
+ if (uReportDataMapper.selectById(id) == null) {
+ throw exception(REPORT_DATA_NOT_EXISTS);
+ }
+ }
+
+ @Override
+ public void validateUReportDataExists(String name) {
+ if (uReportDataMapper.selectByName(name) == null) {
+ throw exception(REPORT_DATA_NOT_EXISTS);
+ }
+ }
+
+ @Override
+ public UReportDataDO getUReportData(Long id) {
+ return uReportDataMapper.selectById(id);
+ }
+
+ @Override
+ public PageResult getUReportDataPage(UReportDataPageReqVO pageReqVO) {
+ return uReportDataMapper.selectPage(pageReqVO);
+ }
+
+ @Override
+ public int deleteByName(String name) {
+ return uReportDataMapper.deleteByName(name);
+ }
+
+ @Override
+ public UReportDataDO selectOneByName(String name) {
+ return uReportDataMapper.selectOneByName(name);
+ }
+
+ @Override
+ public List getReportDataList() {
+ return uReportDataMapper.selectList();
+ }
+}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java
deleted file mode 100644
index 00939afb4..000000000
--- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package cn.iocoder.yudao.module.report.service.ureport;
-
-import cn.hutool.core.collection.CollectionUtil;
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
-import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
-import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import org.springframework.stereotype.Service;
-import org.springframework.validation.annotation.Validated;
-
-import javax.annotation.Resource;
-import java.util.List;
-
-import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS;
-
-/**
- * Ureport2报表 Service 实现类
- *
- * @author 芋道源码
- */
-@Service
-@Validated
-public class UreportFileServiceImpl implements UreportFileService {
-
- @Resource
- private UreportFileMapper ureportFileMapper;
-
- @Override
- public Long createUreportFile(UreportFileSaveReqVO createReqVO) {
- // 插入
- UreportFileDO ureportFile = BeanUtils.toBean(createReqVO, UreportFileDO.class);
- ureportFileMapper.insert(ureportFile);
- // 返回
- return ureportFile.getId();
- }
-
- @Override
- public void updateUreportFile(UreportFileSaveReqVO updateReqVO) {
- // 校验存在
- validateUreportFileExists(updateReqVO.getId());
- // 更新
- UreportFileDO updateObj = BeanUtils.toBean(updateReqVO, UreportFileDO.class);
- ureportFileMapper.updateById(updateObj);
- }
-
- @Override
- public void deleteUreportFile(Long id) {
- // 校验存在
- validateUreportFileExists(id);
- // 删除
- ureportFileMapper.deleteById(id);
- }
-
- private void validateUreportFileExists(Long id) {
- if (ureportFileMapper.selectById(id) == null) {
- throw exception(UREPORT_FILE_NOT_EXISTS);
- }
- }
-
- @Override
- public UreportFileDO getUreportFile(Long id) {
- return ureportFileMapper.selectById(id);
- }
-
- @Override
- public PageResult getUreportFilePage(UreportFilePageReqVO pageReqVO) {
- return ureportFileMapper.selectPage(pageReqVO);
- }
-
- @Override
- public Long checkExistByName(String name) {
- // TODO @赤焰:Service 处理业务逻辑,不能出现 Mapper 层的东西,收敛成 mapper 的一个操作方法
- LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(UreportFileDO::getFileName,name);
- return ureportFileMapper.selectCount(queryWrapper);
- }
-
- @Override
- public UreportFileDO queryUreportFileDoByName(String name) {
- // TODO @赤焰:Service 处理业务逻辑,不能出现 Mapper 层的东西,收敛成 mapper 的一个操作方法
- LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(UreportFileDO::getFileName,name);
- // TODO @赤焰:这里,可以用 selectByName 即可
- List list = ureportFileMapper.selectList(queryWrapper);
- if(CollectionUtil.isNotEmpty(list)){
- return list.get(0);
- }
- return null;
- }
-
- @Override
- public List queryReportFileList() {
- // TODO @赤焰:Service 处理业务逻辑,不能出现 Mapper 层的东西,收敛成 mapper 的一个操作方法
- LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
- return ureportFileMapper.selectList(queryWrapper);
- }
-
- @Override
- public int deleteReportFileByName(String name) {
- // TODO @赤焰:Service 处理业务逻辑,不能出现 Mapper 层的东西,收敛成 mapper 的一个操作方法
- LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(UreportFileDO::getFileName,name);
- return ureportFileMapper.delete(queryWrapper);
- }
-
-}
diff --git a/yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml b/yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml
new file mode 100644
index 000000000..8b545b3c5
--- /dev/null
+++ b/yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java b/yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java
new file mode 100644
index 000000000..b6fc8a657
--- /dev/null
+++ b/yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java
@@ -0,0 +1,135 @@
+package cn.iocoder.yudao.module.report.service.ureport;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import javax.annotation.Resource;
+
+import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
+
+import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
+import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
+import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+
+import org.springframework.context.annotation.Import;
+
+import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*;
+import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
+import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
+import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
+import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * {@link UReportDataServiceImpl} 的单元测试类
+ *
+ * @author 芋道源码
+ */
+@Import(UReportDataServiceImpl.class)
+public class UReportDataServiceImplTest extends BaseDbUnitTest {
+
+ @Resource
+ private UReportDataServiceImpl uReportDataService;
+
+ @Resource
+ private UReportDataMapper uReportDataMapper;
+
+ @Test
+ public void testCreateUReportData_success() {
+ // 准备参数
+ UReportDataSaveReqVO createReqVO = randomPojo(UReportDataSaveReqVO.class).setId(null);
+
+ // 调用
+ Long uReportDataId = uReportDataService.createUReportData(createReqVO);
+ // 断言
+ assertNotNull(uReportDataId);
+ // 校验记录的属性是否正确
+ UReportDataDO uReportData = uReportDataMapper.selectById(uReportDataId);
+ assertPojoEquals(createReqVO, uReportData, "id");
+ }
+
+ @Test
+ public void testUpdateUReportData_success() {
+ // mock 数据
+ UReportDataDO dbUReportData = randomPojo(UReportDataDO.class);
+ uReportDataMapper.insert(dbUReportData);// @Sql: 先插入出一条存在的数据
+ // 准备参数
+ UReportDataSaveReqVO updateReqVO = randomPojo(UReportDataSaveReqVO.class, o -> {
+ o.setId(dbUReportData.getId()); // 设置更新的 ID
+ });
+
+ // 调用
+ uReportDataService.updateUReportData(updateReqVO);
+ // 校验是否更新正确
+ UReportDataDO uReportData = uReportDataMapper.selectById(updateReqVO.getId()); // 获取最新的
+ assertPojoEquals(updateReqVO, uReportData);
+ }
+
+ @Test
+ public void testUpdateUReportData_notExists() {
+ // 准备参数
+ UReportDataSaveReqVO updateReqVO = randomPojo(UReportDataSaveReqVO.class);
+
+ // 调用, 并断言异常
+ assertServiceException(() -> uReportDataService.updateUReportData(updateReqVO), REPORT_DATA_NOT_EXISTS);
+ }
+
+ @Test
+ public void testDeleteUReportData_success() {
+ // mock 数据
+ UReportDataDO dbUReportData = randomPojo(UReportDataDO.class);
+ uReportDataMapper.insert(dbUReportData);// @Sql: 先插入出一条存在的数据
+ // 准备参数
+ Long id = dbUReportData.getId();
+
+ // 调用
+ uReportDataService.deleteUReportData(id);
+ // 校验数据不存在了
+ assertNull(uReportDataMapper.selectById(id));
+ }
+
+ @Test
+ public void testDeleteUReportData_notExists() {
+ // 准备参数
+ Long id = randomLongId();
+
+ // 调用, 并断言异常
+ assertServiceException(() -> uReportDataService.deleteUReportData(id), REPORT_DATA_NOT_EXISTS);
+ }
+
+ @Test
+ @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
+ public void testGetUReportDataPage() {
+ // mock 数据
+ UReportDataDO dbUReportData = randomPojo(UReportDataDO.class, o -> { // 等会查询到
+ o.setName(null);
+ o.setStatus(null);
+ o.setRemark(null);
+ o.setCreateTime(null);
+ });
+ uReportDataMapper.insert(dbUReportData);
+ // 测试 name 不匹配
+ uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setName(null)));
+ // 测试 status 不匹配
+ uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setStatus(null)));
+ // 测试 remark 不匹配
+ uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setRemark(null)));
+ // 测试 createTime 不匹配
+ uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setCreateTime(null)));
+ // 准备参数
+ UReportDataPageReqVO reqVO = new UReportDataPageReqVO();
+ reqVO.setName(null);
+ reqVO.setStatus(null);
+ reqVO.setRemark(null);
+ reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
+
+ // 调用
+ PageResult pageResult = uReportDataService.getUReportDataPage(reqVO);
+ // 断言
+ assertEquals(1, pageResult.getTotal());
+ assertEquals(1, pageResult.getList().size());
+ assertPojoEquals(dbUReportData, pageResult.getList().get(0));
+ }
+
+}
diff --git a/yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImplTest.java b/yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImplTest.java
deleted file mode 100644
index 1cb2f3ca9..000000000
--- a/yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImplTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-package cn.iocoder.yudao.module.report.service.ureport;
-
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO;
-import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
-import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
-import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-import org.springframework.context.annotation.Import;
-
-import javax.annotation.Resource;
-
-import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
-import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
-import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
-import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
-import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
-import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
-import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS;
-import static org.junit.jupiter.api.Assertions.*;
-
-// TODO 芋艿:但愿测试后面补
-/**
- * {@link UreportFileServiceImpl} 的单元测试类
- *
- * @author 芋道源码
- */
-@Import(UreportFileServiceImpl.class)
-public class UreportFileServiceImplTest extends BaseDbUnitTest {
-
- @Resource
- private UreportFileServiceImpl ureportFileService;
-
- @Resource
- private UreportFileMapper ureportFileMapper;
-
- @Test
- public void testCreateUreportFile_success() {
- // 准备参数
- UreportFileSaveReqVO createReqVO = randomPojo(UreportFileSaveReqVO.class).setId(null);
-
- // 调用
- Long ureportFileId = ureportFileService.createUreportFile(createReqVO);
- // 断言
- assertNotNull(ureportFileId);
- // 校验记录的属性是否正确
- UreportFileDO ureportFile = ureportFileMapper.selectById(ureportFileId);
- assertPojoEquals(createReqVO, ureportFile, "id");
- }
-
- @Test
- public void testUpdateUreportFile_success() {
- // mock 数据
- UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class);
- ureportFileMapper.insert(dbUreportFile);// @Sql: 先插入出一条存在的数据
- // 准备参数
- UreportFileSaveReqVO updateReqVO = randomPojo(UreportFileSaveReqVO.class, o -> {
- o.setId(dbUreportFile.getId()); // 设置更新的 ID
- });
-
- // 调用
- ureportFileService.updateUreportFile(updateReqVO);
- // 校验是否更新正确
- UreportFileDO ureportFile = ureportFileMapper.selectById(updateReqVO.getId()); // 获取最新的
- assertPojoEquals(updateReqVO, ureportFile);
- }
-
- @Test
- public void testUpdateUreportFile_notExists() {
- // 准备参数
- UreportFileSaveReqVO updateReqVO = randomPojo(UreportFileSaveReqVO.class);
-
- // 调用, 并断言异常
- assertServiceException(() -> ureportFileService.updateUreportFile(updateReqVO), UREPORT_FILE_NOT_EXISTS);
- }
-
- @Test
- public void testDeleteUreportFile_success() {
- // mock 数据
- UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class);
- ureportFileMapper.insert(dbUreportFile);// @Sql: 先插入出一条存在的数据
- // 准备参数
- Long id = dbUreportFile.getId();
-
- // 调用
- ureportFileService.deleteUreportFile(id);
- // 校验数据不存在了
- assertNull(ureportFileMapper.selectById(id));
- }
-
- @Test
- public void testDeleteUreportFile_notExists() {
- // 准备参数
- Long id = randomLongId();
-
- // 调用, 并断言异常
- assertServiceException(() -> ureportFileService.deleteUreportFile(id), UREPORT_FILE_NOT_EXISTS);
- }
-
- @Test
- @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
- public void testGetUreportFilePage() {
- // mock 数据
- UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class, o -> { // 等会查询到
- o.setFileName(null);
- o.setStatus(null);
- o.setRemark(null);
- o.setCreateTime(null);
- });
- ureportFileMapper.insert(dbUreportFile);
- // 测试 fileName 不匹配
- ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setFileName(null)));
- // 测试 status 不匹配
- ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setStatus(null)));
- // 测试 remark 不匹配
- ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setRemark(null)));
- // 测试 createTime 不匹配
- ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setCreateTime(null)));
- // 准备参数
- UreportFilePageReqVO reqVO = new UreportFilePageReqVO();
- reqVO.setFileName(null);
- reqVO.setStatus(null);
- reqVO.setRemark(null);
- reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
-
- // 调用
- PageResult pageResult = ureportFileService.getUreportFilePage(reqVO);
- // 断言
- assertEquals(1, pageResult.getTotal());
- assertEquals(1, pageResult.getList().size());
- assertPojoEquals(dbUreportFile, pageResult.getList().get(0));
- }
-
-}
\ No newline at end of file
diff --git a/yudao-module-report/yudao-module-report-biz/src/test/resources/sql/clean.sql b/yudao-module-report/yudao-module-report-biz/src/test/resources/sql/clean.sql
index 6ffc3c6ac..a55f807a1 100644
--- a/yudao-module-report/yudao-module-report-biz/src/test/resources/sql/clean.sql
+++ b/yudao-module-report/yudao-module-report-biz/src/test/resources/sql/clean.sql
@@ -1,2 +1,2 @@
DELETE FROM "report_go_view_project";
-DELETE FROM "ureport_file";
+DELETE FROM "report_ureport_data";
diff --git a/yudao-module-report/yudao-module-report-biz/src/test/resources/sql/create_tables.sql b/yudao-module-report/yudao-module-report-biz/src/test/resources/sql/create_tables.sql
index 1c2dab730..bc2a21fbe 100644
--- a/yudao-module-report/yudao-module-report-biz/src/test/resources/sql/create_tables.sql
+++ b/yudao-module-report/yudao-module-report-biz/src/test/resources/sql/create_tables.sql
@@ -12,16 +12,16 @@ CREATE TABLE IF NOT EXISTS "report_go_view_project" (
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT 'GoView 项目表';
-CREATE TABLE IF NOT EXISTS "ureport_file" (
- "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
- "file_name" varchar NOT NULL,
- "status" int NOT NULL,
- "file_content" varchar,
- "remark" varchar,
- "creator" varchar DEFAULT '',
- "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "updater" varchar DEFAULT '',
- "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- "deleted" bit NOT NULL DEFAULT FALSE,
- PRIMARY KEY ("id")
+CREATE TABLE IF NOT EXISTS "report_ureport_data" (
+ "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+ "name" varchar NOT NULL,
+ "status" int NOT NULL,
+ "content" varchar,
+ "remark" varchar,
+ "creator" varchar DEFAULT '',
+ "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updater" varchar DEFAULT '',
+ "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ "deleted" bit NOT NULL DEFAULT FALSE,
+ PRIMARY KEY ("id")
) COMMENT 'Ureport2报表';
diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml
index 6aceca427..627028bdd 100644
--- a/yudao-server/src/main/resources/application.yaml
+++ b/yudao-server/src/main/resources/application.yaml
@@ -229,7 +229,7 @@ yudao:
- jimu_report_link
- jimu_report_map
- jimu_report_share
- - ureport_file
+ - report_ureport_data
- rep_demo_dxtj
- rep_demo_employee
- rep_demo_gongsi