Commit 0d3efe4f80073db60a0d016ee1422d1faa4b295f

Authored by liuhongfeng
Committed by YunaiV
1 parent 5e9cbb9c

【优化】ureport2菜单,初始化数据,按照规范重新进行命名处理

Showing 24 changed files with 560 additions and 568 deletions
sql/mysql/Ureport.sql
... ... @@ -4,8 +4,8 @@ INSERT INTO system_menu(
4 4 path, icon, component, status, component_name
5 5 )
6 6 VALUES (
7   - 'Ureport2报表', '', 2, 0, 1281,
8   - 'ureport-file', '', 'report/ureport/index', 0, 'UreportFile'
  7 + 'Ureport2报表管理', '', 2, 0, 1281,
  8 + 'ureport-data', '', 'report/ureport/index', 0, 'UReportData'
9 9 );
10 10  
11 11 -- 按钮父菜单ID
... ... @@ -18,7 +18,7 @@ INSERT INTO system_menu(
18 18 path, icon, component, status
19 19 )
20 20 VALUES (
21   - 'Ureport2报表查询', 'report:ureport-file:query', 3, 1, @parentId,
  21 + 'Ureport2报表查询', 'report:ureport-data:query', 3, 1, @parentId,
22 22 '', '', '', 0
23 23 );
24 24 INSERT INTO system_menu(
... ... @@ -26,7 +26,7 @@ INSERT INTO system_menu(
26 26 path, icon, component, status
27 27 )
28 28 VALUES (
29   - 'Ureport2报表创建', 'report:ureport-file:create', 3, 2, @parentId,
  29 + 'Ureport2报表创建', 'report:ureport-data:create', 3, 2, @parentId,
30 30 '', '', '', 0
31 31 );
32 32 INSERT INTO system_menu(
... ... @@ -34,7 +34,7 @@ INSERT INTO system_menu(
34 34 path, icon, component, status
35 35 )
36 36 VALUES (
37   - 'Ureport2报表更新', 'report:ureport-file:update', 3, 3, @parentId,
  37 + 'Ureport2报表更新', 'report:ureport-data:update', 3, 3, @parentId,
38 38 '', '', '', 0
39 39 );
40 40 INSERT INTO system_menu(
... ... @@ -42,7 +42,7 @@ INSERT INTO system_menu(
42 42 path, icon, component, status
43 43 )
44 44 VALUES (
45   - 'Ureport2报表删除', 'report:ureport-file:delete', 3, 4, @parentId,
  45 + 'Ureport2报表删除', 'report:ureport-data:delete', 3, 4, @parentId,
46 46 '', '', '', 0
47 47 );
48 48 INSERT INTO system_menu(
... ... @@ -50,28 +50,28 @@ INSERT INTO system_menu(
50 50 path, icon, component, status
51 51 )
52 52 VALUES (
53   - 'Ureport2报表导出', 'report:ureport-file:export', 3, 5, @parentId,
  53 + 'Ureport2报表导出', 'report:ureport-data:export', 3, 5, @parentId,
54 54 '', '', '', 0
55 55 );
56 56  
57 57  
58   --- 创建数据库表
59   -DROP TABLE IF EXISTS `ureport_file`;
60   -CREATE TABLE `ureport_file` (
61   - `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
62   - `file_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '文件名称',
63   - `status` tinyint(4) NOT NULL COMMENT '状态',
64   - `file_content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '文件内容',
65   - `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
66   - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
67   - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
68   - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
69   - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
70   - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
71   - `tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号',
72   - PRIMARY KEY (`id`) USING BTREE
  58 +DROP TABLE IF EXISTS `report_ureport_data`;
  59 +CREATE TABLE `report_ureport_data` (
  60 + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  61 + `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '文件名称',
  62 + `status` tinyint(4) NOT NULL COMMENT '状态',
  63 + `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '文件内容',
  64 + `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
  65 + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
  66 + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  67 + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
  68 + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  69 + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  70 + `tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号',
  71 + PRIMARY KEY (`id`) USING BTREE
73 72 ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'Ureport2报表' ROW_FORMAT = Dynamic;
74 73  
75   -
76   --- 插入测试报表
77   -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, '<?xml version=\"1.0\" encoding=\"UTF-8\"?><ureport><cell expand=\"None\" name=\"A1\" row=\"1\" col=\"1\"><cell-style font-size=\"10\" font-family=\"黑体\" bold=\"true\" align=\"center\" valign=\"middle\"><left-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><right-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><top-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><bottom-border width=\"1\" style=\"solid\" color=\"0,0,0\"/></cell-style><simple-value><![CDATA[角色名称]]></simple-value></cell><cell expand=\"None\" name=\"B1\" row=\"1\" col=\"2\"><cell-style font-size=\"10\" font-family=\"黑体\" bold=\"true\" align=\"center\" valign=\"middle\"><left-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><right-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><top-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><bottom-border width=\"1\" style=\"solid\" color=\"0,0,0\"/></cell-style><simple-value><![CDATA[角色编码]]></simple-value></cell><cell expand=\"None\" name=\"C1\" row=\"1\" col=\"3\"><cell-style font-size=\"10\" font-family=\"黑体\" bold=\"true\" align=\"center\" valign=\"middle\"><left-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><right-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><top-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><bottom-border width=\"1\" style=\"solid\" color=\"0,0,0\"/></cell-style><simple-value><![CDATA[昵称]]></simple-value></cell><cell expand=\"None\" name=\"D1\" row=\"1\" col=\"4\"><cell-style font-size=\"10\" font-family=\"黑体\" bold=\"true\" align=\"center\" valign=\"middle\"><left-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><right-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><top-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><bottom-border width=\"1\" style=\"solid\" color=\"0,0,0\"/></cell-style><simple-value><![CDATA[邮箱]]></simple-value></cell><cell expand=\"None\" name=\"E1\" row=\"1\" col=\"5\"><cell-style font-size=\"9\" forecolor=\"0,0,0\" font-family=\"黑体\" bold=\"true\" align=\"center\" valign=\"middle\"><left-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><right-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><top-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><bottom-border width=\"1\" style=\"solid\" color=\"0,0,0\"/></cell-style><simple-value><![CDATA[手机]]></simple-value></cell><cell expand=\"None\" name=\"F1\" row=\"1\" col=\"6\"><cell-style font-size=\"9\" forecolor=\"0,0,0\" font-family=\"宋体\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"Down\" name=\"A2\" row=\"2\" col=\"1\"><cell-style font-size=\"10\" font-family=\"黑体\" align=\"center\" valign=\"middle\"><left-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><right-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><top-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><bottom-border width=\"1\" style=\"solid\" color=\"0,0,0\"/></cell-style><dataset-value dataset-name=\"sys_role\" aggregate=\"group\" property=\"role_name\" order=\"none\" mapping-type=\"simple\"></dataset-value></cell><cell expand=\"Down\" name=\"B2\" row=\"2\" col=\"2\"><cell-style font-size=\"10\" font-family=\"黑体\" align=\"center\" valign=\"middle\"><left-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><right-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><top-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><bottom-border width=\"1\" style=\"solid\" color=\"0,0,0\"/></cell-style><dataset-value dataset-name=\"sys_role\" aggregate=\"group\" property=\"role_code\" order=\"none\" mapping-type=\"simple\"></dataset-value></cell><cell expand=\"Down\" name=\"C2\" row=\"2\" col=\"3\"><cell-style font-size=\"10\" font-family=\"黑体\" align=\"center\" valign=\"middle\"><left-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><right-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><top-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><bottom-border width=\"1\" style=\"solid\" color=\"0,0,0\"/></cell-style><dataset-value dataset-name=\"sys_role\" aggregate=\"group\" property=\"nickname\" order=\"none\" mapping-type=\"simple\"></dataset-value></cell><cell expand=\"Down\" name=\"D2\" row=\"2\" col=\"4\"><cell-style font-size=\"10\" font-family=\"黑体\" align=\"center\" valign=\"middle\"><left-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><right-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><top-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><bottom-border width=\"1\" style=\"solid\" color=\"0,0,0\"/></cell-style><dataset-value dataset-name=\"sys_role\" aggregate=\"group\" property=\"email\" order=\"none\" mapping-type=\"simple\"></dataset-value></cell><cell expand=\"Down\" name=\"E2\" row=\"2\" col=\"5\"><cell-style font-size=\"9\" forecolor=\"0,0,0\" font-family=\"黑体\" align=\"center\" valign=\"middle\"><left-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><right-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><top-border width=\"1\" style=\"solid\" color=\"0,0,0\"/><bottom-border width=\"1\" style=\"solid\" color=\"0,0,0\"/></cell-style><dataset-value dataset-name=\"sys_role\" aggregate=\"group\" property=\"mobile\" order=\"none\" mapping-type=\"simple\"></dataset-value></cell><cell expand=\"None\" name=\"F2\" row=\"2\" col=\"6\"><cell-style font-size=\"9\" forecolor=\"0,0,0\" font-family=\"宋体\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"A3\" row=\"3\" col=\"1\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"B3\" row=\"3\" col=\"2\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"C3\" row=\"3\" col=\"3\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"D3\" row=\"3\" col=\"4\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"E3\" row=\"3\" col=\"5\"><cell-style font-size=\"9\" forecolor=\"0,0,0\" font-family=\"宋体\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"F3\" row=\"3\" col=\"6\"><cell-style font-size=\"9\" forecolor=\"0,0,0\" font-family=\"宋体\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><row row-number=\"1\" height=\"18\"/><row row-number=\"2\" height=\"18\"/><row row-number=\"3\" height=\"18\"/><column col-number=\"1\" width=\"80\"/><column col-number=\"2\" width=\"80\"/><column col-number=\"3\" width=\"80\"/><column col-number=\"4\" width=\"80\"/><column col-number=\"5\" width=\"74\"/><column col-number=\"6\" width=\"74\"/><datasource name=\"UreportDataSource\" type=\"buildin\"><dataset name=\"sys_role\" type=\"sql\"><sql><![CDATA[SELECT sr.name as role_name ,sr.code as role_code,su.username ,su.nickname ,su.email,su.mobile \nFROM system_role sr\nLEFT JOIN system_user_role sur ON sr.id = sur.role_id\nLEFT JOIN system_users su ON sur.user_id = su.id]]></sql><field name=\"role_name\"/><field name=\"role_code\"/><field name=\"username\"/><field name=\"nickname\"/><field name=\"email\"/><field name=\"mobile\"/></dataset></datasource><paper type=\"A4\" left-margin=\"90\" right-margin=\"90\"\n top-margin=\"72\" bottom-margin=\"72\" paging-mode=\"fitpage\" fixrows=\"0\"\n width=\"595\" height=\"842\" orientation=\"portrait\" html-report-align=\"left\" bg-image=\"\" html-interval-refresh-value=\"0\" column-enabled=\"false\"></paper></ureport>', NULL, NULL, '2023-11-22 22:02:44', NULL, '2023-11-22 22:06:51', b'0', 0);
  74 +-- ----------------------------
  75 +-- Records of report_ureport_data
  76 +-- ----------------------------
  77 +INSERT INTO `report_ureport_data` VALUES (11, 'role.ureport.xml', 0, '<?xml version=\"1.0\" encoding=\"UTF-8\"?><ureport><cell expand=\"Down\" name=\"A1\" row=\"1\" col=\"1\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><dataset-value dataset-name=\"role\" aggregate=\"group\" property=\"name\" order=\"none\" mapping-type=\"simple\"></dataset-value></cell><cell expand=\"Down\" name=\"B1\" row=\"1\" col=\"2\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><dataset-value dataset-name=\"role\" aggregate=\"group\" property=\"code\" order=\"none\" mapping-type=\"simple\"></dataset-value></cell><cell expand=\"Down\" name=\"C1\" row=\"1\" col=\"3\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><dataset-value dataset-name=\"role\" aggregate=\"group\" property=\"status\" order=\"none\" mapping-type=\"simple\"></dataset-value></cell><cell expand=\"None\" name=\"D1\" row=\"1\" col=\"4\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"A2\" row=\"2\" col=\"1\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"B2\" row=\"2\" col=\"2\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"C2\" row=\"2\" col=\"3\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"D2\" row=\"2\" col=\"4\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"A3\" row=\"3\" col=\"1\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"B3\" row=\"3\" col=\"2\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"C3\" row=\"3\" col=\"3\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><cell expand=\"None\" name=\"D3\" row=\"3\" col=\"4\"><cell-style font-size=\"10\" align=\"center\" valign=\"middle\"></cell-style><simple-value><![CDATA[]]></simple-value></cell><row row-number=\"1\" height=\"18\"/><row row-number=\"2\" height=\"18\"/><row row-number=\"3\" height=\"18\"/><column col-number=\"1\" width=\"80\"/><column col-number=\"2\" width=\"80\"/><column col-number=\"3\" width=\"80\"/><column col-number=\"4\" width=\"80\"/><datasource name=\"UReportDataSource\" type=\"buildin\"><dataset name=\"role\" type=\"sql\"><sql><![CDATA[select * from system_role]]></sql><field name=\"id\"/><field name=\"name\"/><field name=\"code\"/><field name=\"sort\"/><field name=\"data_scope\"/><field name=\"data_scope_dept_ids\"/><field name=\"status\"/><field name=\"type\"/><field name=\"remark\"/><field name=\"creator\"/><field name=\"create_time\"/><field name=\"updater\"/><field name=\"update_time\"/><field name=\"deleted\"/><field name=\"tenant_id\"/></dataset></datasource><paper type=\"A4\" left-margin=\"90\" right-margin=\"90\"\n top-margin=\"72\" bottom-margin=\"72\" paging-mode=\"fitpage\" fixrows=\"0\"\n width=\"595\" height=\"842\" orientation=\"portrait\" html-report-align=\"left\" bg-image=\"\" html-interval-refresh-value=\"0\" column-enabled=\"false\"></paper></ureport>', NULL, NULL, '2023-11-25 22:40:58', NULL, '2023-11-25 23:00:42', b'0', 0);
... ...
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 {
13 13 ErrorCode GO_VIEW_PROJECT_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在");
14 14  
15 15 // ========== UREPORT 模块 1-003-001-000 ==========
16   - ErrorCode UREPORT_FILE_NOT_EXISTS = new ErrorCode(1_003_001_000, "打印文件不存在,请检查 UReport 报表文件");
17   - ErrorCode UREPORT_FILE_EXISTS = new ErrorCode(1_003_001_001, "报表名字已存在,请修改后再保存");
  16 + ErrorCode REPORT_DATA_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2报表不存在");
18 17  
  18 + ErrorCode REPORT_DATABASE_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2报表数据源不存在");
19 19 }
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UreportFileController.java renamed to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UReportDataController.java
1 1 package cn.iocoder.yudao.module.report.controller.admin.ureport;
2 2  
3   -import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  3 +import org.springframework.web.bind.annotation.*;
  4 +import javax.annotation.Resource;
  5 +import org.springframework.validation.annotation.Validated;
  6 +import org.springframework.security.access.prepost.PreAuthorize;
  7 +import io.swagger.v3.oas.annotations.tags.Tag;
  8 +import io.swagger.v3.oas.annotations.Parameter;
  9 +import io.swagger.v3.oas.annotations.Operation;
  10 +
  11 +import javax.validation.constraints.*;
  12 +import javax.validation.*;
  13 +import javax.servlet.http.*;
  14 +import java.util.*;
  15 +import java.io.IOException;
  16 +
4 17 import cn.iocoder.yudao.framework.common.pojo.PageParam;
5 18 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  19 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
6 20 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  21 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  22 +
7 23 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
8   -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
9   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO;
10   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileRespVO;
11   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
12   -import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
13   -import cn.iocoder.yudao.module.report.service.ureport.UreportFileService;
14   -import io.swagger.v3.oas.annotations.Operation;
15   -import io.swagger.v3.oas.annotations.Parameter;
16   -import io.swagger.v3.oas.annotations.tags.Tag;
17   -import org.springframework.security.access.prepost.PreAuthorize;
18   -import org.springframework.validation.annotation.Validated;
19   -import org.springframework.web.bind.annotation.*;
20 24  
21   -import javax.annotation.Resource;
22   -import javax.servlet.http.HttpServletResponse;
23   -import javax.validation.Valid;
24   -import java.io.IOException;
25   -import java.util.List;
  25 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  26 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
26 27  
27   -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
28   -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  28 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
  29 +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
  30 +import cn.iocoder.yudao.module.report.service.ureport.UReportDataService;
29 31  
30   -// TODO @赤焰: Ureport 改成 UReport
31   -@Tag(name = "管理后台 - UReport2 报表")
  32 +@Tag(name = "管理后台 - Ureport2报表")
32 33 @RestController
33   -@RequestMapping("/report/ureport-file")
  34 +@RequestMapping("/report/ureport-data")
34 35 @Validated
35   -public class UreportFileController {
  36 +public class UReportDataController {
36 37  
37 38 @Resource
38   - private UreportFileService ureportFileService;
  39 + private UReportDataService uReportDataService;
39 40  
40 41 @PostMapping("/create")
41   - @Operation(summary = "创建 UReport2 报表")
42   - @PreAuthorize("@ss.hasPermission('report:ureport-file:create')")
43   - public CommonResult<Long> createUreportFile(@Valid @RequestBody UreportFileSaveReqVO createReqVO) {
44   - return success(ureportFileService.createUreportFile(createReqVO));
  42 + @Operation(summary = "创建Ureport2报表")
  43 + @PreAuthorize("@ss.hasPermission('report:ureport-data:create')")
  44 + public CommonResult<Long> createUReportData(@Valid @RequestBody UReportDataSaveReqVO createReqVO) {
  45 + return success(uReportDataService.createUReportData(createReqVO));
45 46 }
46 47  
47 48 @PutMapping("/update")
48   - @Operation(summary = "更新 UReport2 报表")
49   - @PreAuthorize("@ss.hasPermission('report:ureport-file:update')")
50   - public CommonResult<Boolean> updateUreportFile(@Valid @RequestBody UreportFileSaveReqVO updateReqVO) {
51   - ureportFileService.updateUreportFile(updateReqVO);
  49 + @Operation(summary = "更新Ureport2报表")
  50 + @PreAuthorize("@ss.hasPermission('report:ureport-data:update')")
  51 + public CommonResult<Boolean> updateUReportData(@Valid @RequestBody UReportDataSaveReqVO updateReqVO) {
  52 + uReportDataService.updateUReportData(updateReqVO);
52 53 return success(true);
53 54 }
54 55  
55 56 @DeleteMapping("/delete")
56   - @Operation(summary = "删除 UReport2 报表")
  57 + @Operation(summary = "删除Ureport2报表")
57 58 @Parameter(name = "id", description = "编号", required = true)
58   - @PreAuthorize("@ss.hasPermission('report:ureport-file:delete')")
59   - public CommonResult<Boolean> deleteUreportFile(@RequestParam("id") Long id) {
60   - ureportFileService.deleteUreportFile(id);
  59 + @PreAuthorize("@ss.hasPermission('report:ureport-data:delete')")
  60 + public CommonResult<Boolean> deleteUReportData(@RequestParam("id") Long id) {
  61 + uReportDataService.deleteUReportData(id);
61 62 return success(true);
62 63 }
63 64  
64 65 @GetMapping("/get")
65   - @Operation(summary = "获得 UReport2 报表")
  66 + @Operation(summary = "获得Ureport2报表")
66 67 @Parameter(name = "id", description = "编号", required = true, example = "1024")
67   - @PreAuthorize("@ss.hasPermission('report:ureport-file:query')")
68   - public CommonResult<UreportFileRespVO> getUreportFile(@RequestParam("id") Long id) {
69   - UreportFileDO ureportFile = ureportFileService.getUreportFile(id);
70   - return success(BeanUtils.toBean(ureportFile, UreportFileRespVO.class));
  68 + @PreAuthorize("@ss.hasPermission('report:ureport-data:query')")
  69 + public CommonResult<UReportDataRespVO> getUReportData(@RequestParam("id") Long id) {
  70 + UReportDataDO uReportData = uReportDataService.getUReportData(id);
  71 + return success(BeanUtils.toBean(uReportData, UReportDataRespVO.class));
71 72 }
72 73  
73 74 @GetMapping("/page")
74   - @Operation(summary = "获得 UReport2 报表分页")
75   - @PreAuthorize("@ss.hasPermission('report:ureport-file:query')")
76   - public CommonResult<PageResult<UreportFileRespVO>> getUreportFilePage(@Valid UreportFilePageReqVO pageReqVO) {
77   - PageResult<UreportFileDO> pageResult = ureportFileService.getUreportFilePage(pageReqVO);
78   - return success(BeanUtils.toBean(pageResult, UreportFileRespVO.class));
  75 + @Operation(summary = "获得Ureport2报表分页")
  76 + @PreAuthorize("@ss.hasPermission('report:ureport-data:query')")
  77 + public CommonResult<PageResult<UReportDataRespVO>> getUReportDataPage(@Valid UReportDataPageReqVO pageReqVO) {
  78 + PageResult<UReportDataDO> pageResult = uReportDataService.getUReportDataPage(pageReqVO);
  79 + return success(BeanUtils.toBean(pageResult, UReportDataRespVO.class));
79 80 }
80 81  
81   - // TODO @赤焰:导出是必须的么?没用可以删除哈
82 82 @GetMapping("/export-excel")
83   - @Operation(summary = "导出 UReport2 报表 Excel")
84   - @PreAuthorize("@ss.hasPermission('report:ureport-file:export')")
  83 + @Operation(summary = "导出Ureport2报表 Excel")
  84 + @PreAuthorize("@ss.hasPermission('report:ureport-data:export')")
85 85 @OperateLog(type = EXPORT)
86   - public void exportUreportFileExcel(@Valid UreportFilePageReqVO pageReqVO,
  86 + public void exportUReportDataExcel(@Valid UReportDataPageReqVO pageReqVO,
87 87 HttpServletResponse response) throws IOException {
88 88 pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
89   - List<UreportFileDO> list = ureportFileService.getUreportFilePage(pageReqVO).getList();
  89 + List<UReportDataDO> list = uReportDataService.getUReportDataPage(pageReqVO).getList();
90 90 // 导出 Excel
91   - ExcelUtils.write(response, "Ureport2报表.xls", "数据", UreportFileRespVO.class,
92   - BeanUtils.toBean(list, UreportFileRespVO.class));
  91 + ExcelUtils.write(response, "Ureport2报表.xls", "数据", UReportDataRespVO.class,
  92 + BeanUtils.toBean(list, UReportDataRespVO.class));
93 93 }
94 94  
95   -}
96 95 \ No newline at end of file
  96 +}
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFilePageReqVO.java renamed to 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_
13 13 @Data
14 14 @EqualsAndHashCode(callSuper = true)
15 15 @ToString(callSuper = true)
16   -public class UreportFilePageReqVO extends PageParam {
  16 +public class UReportDataPageReqVO extends PageParam {
17 17  
18   - @Schema(description = "文件名称", example = "赵六")
19   - private String fileName;
  18 + @Schema(description = "文件名称", example = "李四")
  19 + private String name;
20 20  
21 21 @Schema(description = "状态", example = "1")
22 22 private Integer status;
23 23  
24   - @Schema(description = "备注", example = "随便")
  24 + @Schema(description = "备注", example = "你猜")
25 25 private String remark;
26 26  
27 27 @Schema(description = "创建时间")
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFileRespVO.java renamed to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataRespVO.java
1 1 package cn.iocoder.yudao.module.report.controller.admin.ureport.vo;
2 2  
3 3 import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
4 5 import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
5 6 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
6 7 import com.alibaba.excel.annotation.ExcelProperty;
... ... @@ -12,22 +13,26 @@ import java.time.LocalDateTime;
12 13 @Schema(description = "管理后台 - Ureport2报表 Response VO")
13 14 @Data
14 15 @ExcelIgnoreUnannotated
15   -public class UreportFileRespVO {
  16 +public class UReportDataRespVO {
16 17  
17   - @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9948")
  18 + @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26175")
18 19 @ExcelProperty("ID")
19 20 private Long id;
20 21  
21   - @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
  22 + @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
22 23 @ExcelProperty("文件名称")
23   - private String fileName;
  24 + private String name;
24 25  
25 26 @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
26   - @ExcelProperty("状态")
  27 + @ExcelProperty(value = "状态", converter = DictConvert.class)
27 28 @DictFormat(DictTypeConstants.COMMON_STATUS)
28 29 private Integer status;
29 30  
30   - @Schema(description = "备注", example = "随便")
  31 + @Schema(description = "文件内容")
  32 + @ExcelProperty("文件内容")
  33 + private String content;
  34 +
  35 + @Schema(description = "备注", example = "你猜")
31 36 @ExcelProperty("备注")
32 37 private String remark;
33 38  
... ... @@ -35,4 +40,4 @@ public class UreportFileRespVO {
35 40 @ExcelProperty("创建时间")
36 41 private LocalDateTime createTime;
37 42  
38   -}
39 43 \ No newline at end of file
  44 +}
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFileSaveReqVO.java renamed to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataSaveReqVO.java
1 1 package cn.iocoder.yudao.module.report.controller.admin.ureport.vo;
2 2  
3   -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4   -import cn.iocoder.yudao.framework.common.validation.InEnum;
5 3 import io.swagger.v3.oas.annotations.media.Schema;
6   -import lombok.Data;
7   -
8   -import javax.validation.constraints.NotEmpty;
9   -import javax.validation.constraints.NotNull;
  4 +import lombok.*;
  5 +import java.util.*;
  6 +import javax.validation.constraints.*;
  7 +import java.util.*;
10 8  
11 9 @Schema(description = "管理后台 - Ureport2报表新增/修改 Request VO")
12 10 @Data
13   -public class UreportFileSaveReqVO {
  11 +public class UReportDataSaveReqVO {
14 12  
15   - @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9948")
  13 + @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26175")
16 14 private Long id;
17 15  
18   - @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
  16 + @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
19 17 @NotEmpty(message = "文件名称不能为空")
20   - private String fileName;
  18 + private String name;
21 19  
22 20 @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
23 21 @NotNull(message = "状态不能为空")
24   - @InEnum(CommonStatusEnum.class)
25 22 private Integer status;
26 23  
27 24 @Schema(description = "文件内容")
28   - private String fileContent;
  25 + private String content;
29 26  
30   - @Schema(description = "备注", example = "随便")
  27 + @Schema(description = "备注", example = "你猜")
31 28 private String remark;
32 29  
33 30 -}
  31 +}
34 32 \ No newline at end of file
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UreportFileDO.java renamed to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UReportDataDO.java
1 1 package cn.iocoder.yudao.module.report.dal.dataobject.ureport;
2 2  
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
3 4 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
4 5 import com.baomidou.mybatisplus.annotation.KeySequence;
5 6 import com.baomidou.mybatisplus.annotation.TableId;
... ... @@ -11,35 +12,35 @@ import lombok.*;
11 12 *
12 13 * @author 芋道源码
13 14 */
14   -@TableName("ureport_file")
15   -@KeySequence("ureport_file_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  15 +@TableName("report_ureport_data")
  16 +@KeySequence("report_ureport_data_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
16 17 @Data
17 18 @EqualsAndHashCode(callSuper = true)
18 19 @ToString(callSuper = true)
19 20 @Builder
20 21 @NoArgsConstructor
21 22 @AllArgsConstructor
22   -public class UreportFileDO extends BaseDO {
  23 +public class UReportDataDO extends BaseDO {
23 24  
24 25 /**
25 26 * ID
26 27 */
27 28 @TableId
28 29 private Long id;
29   - // TODO @赤焰:是不是用 name 就可以了。
30 30 /**
31 31 * 文件名称
32 32 */
33   - private String fileName;
  33 + private String name;
34 34 /**
35 35 * 状态
  36 + *
  37 + * 枚举 {@link CommonStatusEnum#getStatus()}
36 38 */
37 39 private Integer status;
38   - // TODO @赤焰:是不是用 string 就可以了。然后字段名用 content?
39 40 /**
40 41 * 文件内容
41 42 */
42   - private byte[] fileContent;
  43 + private String content;
43 44 /**
44 45 * 备注
45 46 */
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.report.dal.mysql.ureport;
  2 +
  3 +import java.util.*;
  4 +
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  7 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  8 +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
  9 +import org.apache.ibatis.annotations.Mapper;
  10 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
  11 +
  12 +/**
  13 + * Ureport2报表 Mapper
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface UReportDataMapper extends BaseMapperX<UReportDataDO> {
  19 +
  20 + default PageResult<UReportDataDO> selectPage(UReportDataPageReqVO reqVO) {
  21 + return selectPage(reqVO, new LambdaQueryWrapperX<UReportDataDO>()
  22 + .likeIfPresent(UReportDataDO::getName, reqVO.getName())
  23 + .eqIfPresent(UReportDataDO::getStatus, reqVO.getStatus())
  24 + .eqIfPresent(UReportDataDO::getRemark, reqVO.getRemark())
  25 + .betweenIfPresent(UReportDataDO::getCreateTime, reqVO.getCreateTime())
  26 + .orderByDesc(UReportDataDO::getId));
  27 + }
  28 +
  29 + /**
  30 + * 根据名字查询报表
  31 + * @param name 报表名字
  32 + * @return
  33 + */
  34 + default List<UReportDataDO> selectByName(String name){
  35 + return selectList(new LambdaQueryWrapperX<UReportDataDO>()
  36 + .eqIfPresent(UReportDataDO::getName,name));
  37 + }
  38 +
  39 + /**
  40 + * 根据名字查询报表
  41 + * @param name 报表名字
  42 + * @return
  43 + */
  44 + default UReportDataDO selectOneByName(String name){
  45 + return selectOne(new LambdaQueryWrapperX<UReportDataDO>()
  46 + .eqIfPresent(UReportDataDO::getName,name));
  47 + }
  48 +
  49 +
  50 + /**
  51 + * 根据名字删除报表
  52 + * @param name 报表名字
  53 + * @return
  54 + */
  55 + default int deleteByName(String name){
  56 + return delete(new LambdaQueryWrapperX<UReportDataDO>()
  57 + .eqIfPresent(UReportDataDO::getName,name));
  58 + }
  59 +
  60 +}
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UreportFileMapper.java deleted
1   -package cn.iocoder.yudao.module.report.dal.mysql.ureport;
2   -
3   -import java.util.*;
4   -
5   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
7   -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
8   -import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
9   -import org.apache.ibatis.annotations.Mapper;
10   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
11   -
12   -/**
13   - * Ureport2报表 Mapper
14   - *
15   - * @author 芋道源码
16   - */
17   -@Mapper
18   -public interface UreportFileMapper extends BaseMapperX<UreportFileDO> {
19   -
20   - default PageResult<UreportFileDO> selectPage(UreportFilePageReqVO reqVO) {
21   - return selectPage(reqVO, new LambdaQueryWrapperX<UreportFileDO>()
22   - .likeIfPresent(UreportFileDO::getFileName, reqVO.getFileName())
23   - .eqIfPresent(UreportFileDO::getStatus, reqVO.getStatus())
24   - .eqIfPresent(UreportFileDO::getRemark, reqVO.getRemark())
25   - .betweenIfPresent(UreportFileDO::getCreateTime, reqVO.getCreateTime())
26   - .orderByDesc(UreportFileDO::getId));
27   - }
28   -
29   -}
30 0 \ No newline at end of file
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java
1 1 package cn.iocoder.yudao.module.report.framework.security.config;
2 2  
  3 +import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
3 4 import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer;
  5 +import cn.iocoder.yudao.framework.security.config.SecurityProperties;
  6 +import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
  7 +import org.springframework.boot.web.servlet.FilterRegistrationBean;
4 8 import org.springframework.context.annotation.Bean;
5 9 import org.springframework.context.annotation.Configuration;
6 10 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7 11 import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
  12 +import org.springframework.util.StringUtils;
  13 +
  14 +import javax.annotation.Resource;
8 15  
9 16 /**
10 17 * Report 模块的 Security 配置
... ... @@ -12,6 +19,9 @@ import org.springframework.security.config.annotation.web.configurers.Expression
12 19 @Configuration("reportSecurityConfiguration")
13 20 public class SecurityConfiguration {
14 21  
  22 + @Resource
  23 + private OAuth2TokenApi oauth2TokenApi;
  24 +
15 25 @Bean("reportAuthorizeRequestsCustomizer")
16 26 public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {
17 27 return new AuthorizeRequestsCustomizer() {
... ... @@ -25,4 +35,16 @@ public class SecurityConfiguration {
25 35 };
26 36 }
27 37  
  38 +
  39 + /**
  40 + * 创建 UReportFilter 过滤器,响应 header 设置 token
  41 + */
  42 + /*@Bean
  43 + public FilterRegistrationBean<UReportFilter> uReportFilterFilterRegistrationBean() {
  44 + FilterRegistrationBean<UReportFilter> registrationBean = new FilterRegistrationBean<>();
  45 + registrationBean.setFilter(new UReportFilter(oauth2TokenApi));
  46 + registrationBean.setOrder(WebFilterOrderEnum.TRACE_FILTER);
  47 + return registrationBean;
  48 + }*/
  49 +
28 50 }
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportFilter.java 0 → 100644
  1 +package cn.iocoder.yudao.module.report.framework.security.config;
  2 +
  3 +import cn.iocoder.yudao.framework.common.exception.ServiceException;
  4 +import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
  5 +import cn.iocoder.yudao.framework.security.core.LoginUser;
  6 +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
  7 +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
  8 +import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
  9 +import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
  10 +import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
  11 +import lombok.Data;
  12 +import lombok.RequiredArgsConstructor;
  13 +import lombok.extern.slf4j.Slf4j;
  14 +import org.springframework.web.filter.OncePerRequestFilter;
  15 +
  16 +import javax.servlet.FilterChain;
  17 +import javax.servlet.ServletException;
  18 +import javax.servlet.http.HttpServletRequest;
  19 +import javax.servlet.http.HttpServletResponse;
  20 +import java.io.IOException;
  21 +import java.util.Map;
  22 +
  23 +/**
  24 + * UReport 认证过滤器
  25 + * @author 赤焰
  26 + */
  27 +@Slf4j
  28 +@RequiredArgsConstructor
  29 +public class UReportFilter extends OncePerRequestFilter {
  30 +
  31 + private final static String TOKEN = "token";
  32 +
  33 + private final OAuth2TokenApi oauth2TokenApi;
  34 +
  35 + @Override
  36 + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
  37 + throws ServletException, IOException {
  38 +
  39 + if(log.isDebugEnabled()){
  40 + log.debug("UReportFilter自定义过滤器");
  41 + }
  42 +
  43 + Map<String, String> paramMap = ServletUtils.getParamMap(request);
  44 + String requestURI = request.getRequestURI();
  45 + boolean contains = requestURI.contains("/ureport");
  46 + if (paramMap.containsKey(TOKEN)&&contains) {
  47 + String token = request.getParameter(TOKEN);
  48 + if(log.isDebugEnabled()){
  49 + log.debug("UReportFilter自定义过滤器 token="+token);
  50 + }
  51 +
  52 + response.addHeader(TOKEN,token);
  53 +
  54 + TenantContextHolder.setIgnore(true); // 忽略租户,保证可查询到 token 信息
  55 + LoginUser user = null;
  56 + try {
  57 + OAuth2AccessTokenCheckRespDTO accessToken = oauth2TokenApi.checkAccessToken(token);
  58 + if (accessToken != null) {
  59 + user = new LoginUser().setId(accessToken.getUserId()).setUserType(accessToken.getUserType())
  60 + .setTenantId(accessToken.getTenantId()).setScopes(accessToken.getScopes());
  61 + if (user != null) {
  62 + SecurityFrameworkUtils.setLoginUser(user, WebFrameworkUtils.getRequest());
  63 +
  64 + // ② 参考 TenantContextWebFilter 实现(Tenant 的上下文清理,交给 TenantContextWebFilter 完成)
  65 + // 目的:基于 LoginUser 获得到的租户编号,设置到 Tenant 上下文,避免查询数据库时的报错
  66 + TenantContextHolder.setIgnore(false);
  67 + TenantContextHolder.setTenantId(user.getTenantId());
  68 + }
  69 + }
  70 + } catch (ServiceException ignored) {
  71 + chain.doFilter(request, response);
  72 + }
  73 +
  74 + }
  75 +
  76 + // 继续过滤
  77 + chain.doFilter(request, response);
  78 +
  79 + }
  80 +}
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportProperties.java 0 → 100644
  1 +package cn.iocoder.yudao.module.report.framework.security.config;
  2 +
  3 +import lombok.Data;
  4 +import org.springframework.boot.context.properties.ConfigurationProperties;
  5 +
  6 +/**
  7 + * UReport配置类
  8 + *
  9 + * @author 赤焰
  10 + */
  11 +@Data
  12 +@ConfigurationProperties(prefix = "ureport.provider.database")
  13 +public class UReportProperties {
  14 + private String name = "数据库文件系统";
  15 + private String prefix = "db-";
  16 + private boolean disabled = false;
  17 +}
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfiguration.java renamed to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportConfiguration.java
1 1 package cn.iocoder.yudao.module.report.framework.ureport.config;
2 2  
  3 +import cn.iocoder.yudao.module.report.framework.security.config.UReportProperties;
3 4 import com.bstek.ureport.console.UReportServlet;
  5 +import org.springframework.boot.context.properties.EnableConfigurationProperties;
4 6 import org.springframework.boot.web.servlet.ServletRegistrationBean;
5 7 import org.springframework.context.annotation.Bean;
6 8 import org.springframework.context.annotation.Configuration;
... ... @@ -15,13 +17,13 @@ import javax.servlet.Servlet;
15 17 * @author 赤焰
16 18 */
17 19 @Configuration
18   -@ImportResource({"classpath:ureport-console-context.xml"}) // Bean 配置
19   -@PropertySource(value = {"classpath:ureport.properties"}) // 配置文件
20   -public class UreportConfiguration {
  20 +@ImportResource({"classpath:ureport-console-context.xml"})
  21 +@PropertySource(value = {"classpath:ureport.properties"})
  22 +@EnableConfigurationProperties({UReportProperties.class})
  23 +public class UReportConfiguration {
21 24  
22   - // TODO @赤焰:bean 是不是取个和 ureport 相关的名字好点哈?
23 25 @Bean
24   - public ServletRegistrationBean<Servlet> registrationBean() {
  26 + public ServletRegistrationBean<Servlet> uReportRegistrationBean() {
25 27 return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*");
26 28 }
27 29  
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportDataSource.java renamed to 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;
9 9 import java.sql.Connection;
10 10 import java.sql.SQLException;
11 11  
  12 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  13 +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.REPORT_DATABASE_NOT_EXISTS;
  14 +
12 15 /**
13 16 * UReport 内置数据源
  17 + * @author 赤焰
14 18 */
15 19 @Slf4j
16 20 @Component
17   -public class UreportDataSource implements BuildinDatasource {
  21 +public class UReportDataSource implements BuildinDatasource {
18 22  
19   - private static final String NAME = "UreportDataSource";
  23 + private static final String NAME = "UReportDataSource";
20 24  
21 25 @Resource
22 26 private DataSource dataSource;
... ... @@ -29,7 +33,6 @@ public class UreportDataSource implements BuildinDatasource {
29 33 return NAME;
30 34 }
31 35  
32   - // TODO @赤焰:这个方法,如果拿不到连接,是不是抛出异常比较好?
33 36 /**
34 37 * @return 获取连接
35 38 */
... ... @@ -38,10 +41,9 @@ public class UreportDataSource implements BuildinDatasource {
38 41 try {
39 42 return dataSource.getConnection();
40 43 } catch (SQLException e) {
41   - log.error("Ureport 数据源 获取连接失败!");
42   - e.printStackTrace();
  44 + log.error("UReportDataSource获取连接失败!");
  45 + throw exception(REPORT_DATABASE_NOT_EXISTS);
43 46 }
44   - return null;
45 47 }
46 48  
47 49 }
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java 0 → 100644
  1 +package cn.iocoder.yudao.module.report.framework.ureport.core;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.StrUtil;
  5 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  6 +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
  7 +import cn.iocoder.yudao.framework.common.util.date.DateUtils;
  8 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO;
  9 +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
  10 +import cn.iocoder.yudao.module.report.framework.security.config.UReportProperties;
  11 +import cn.iocoder.yudao.module.report.service.ureport.UReportDataService;
  12 +import com.bstek.ureport.provider.report.ReportFile;
  13 +import com.bstek.ureport.provider.report.ReportProvider;
  14 +import lombok.Setter;
  15 +import lombok.extern.slf4j.Slf4j;
  16 +import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.stereotype.Component;
  18 +
  19 +import javax.annotation.Resource;
  20 +import java.io.ByteArrayInputStream;
  21 +import java.io.InputStream;
  22 +import java.util.Collections;
  23 +import java.util.List;
  24 +
  25 +/**
  26 + * 基于数据库的 {@link ReportProvider} 实现类
  27 + *
  28 + * @author 赤焰
  29 + */
  30 +@Component
  31 +@Slf4j
  32 +@Setter
  33 +public class UReportDatabaseProvider implements ReportProvider {
  34 +
  35 + @Autowired
  36 + private UReportProperties uReportProperties;
  37 + @Resource
  38 + private UReportDataService uReportDataService;
  39 +
  40 + @Override
  41 + public InputStream loadReport(String name) {
  42 + uReportDataService.validateUReportDataExists(getCorrectName(name));
  43 + UReportDataDO uReportDataDO = uReportDataService.selectOneByName(getCorrectName(name));
  44 + String content = uReportDataDO.getContent();
  45 + return new ByteArrayInputStream(content.getBytes());
  46 + }
  47 +
  48 + @Override
  49 + public void deleteReport(String name) {
  50 + uReportDataService.deleteByName(getCorrectName(name));
  51 + }
  52 +
  53 + @Override
  54 + public List<ReportFile> getReportFiles() {
  55 + List<UReportDataDO> list = uReportDataService.getReportDataList();
  56 + if(CollUtil.isEmpty(list)) {
  57 + return Collections.emptyList();
  58 + }
  59 + return CollectionUtils.convertList(list, report -> new ReportFile(report.getName(), DateUtils.of(report.getUpdateTime())));
  60 +
  61 + }
  62 +
  63 + @Override
  64 + public void saveReport(String name, String content) {
  65 + name = getCorrectName(name);
  66 + UReportDataDO uReportDataDO = uReportDataService.selectOneByName(name);
  67 + UReportDataSaveReqVO saveReqVO = new UReportDataSaveReqVO();
  68 + if (uReportDataDO == null) {
  69 + saveReqVO.setName(name);
  70 + saveReqVO.setContent(content);
  71 + saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
  72 + uReportDataService.createUReportData(saveReqVO);
  73 + } else {
  74 + saveReqVO.setId(uReportDataDO.getId());
  75 + saveReqVO.setName(name);
  76 + saveReqVO.setContent(content);
  77 + saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
  78 + uReportDataService.updateUReportData(saveReqVO);
  79 + }
  80 + }
  81 +
  82 + @Override
  83 + public String getName() {
  84 + return uReportProperties.getName();
  85 + }
  86 +
  87 + @Override
  88 + public boolean disabled() {
  89 + return uReportProperties.isDisabled();
  90 + }
  91 +
  92 + @Override
  93 + public String getPrefix() {
  94 + return uReportProperties.getPrefix();
  95 + }
  96 +
  97 + /**
  98 + * 去除存储媒介,获取报表名字
  99 + * @param name 前端传入的报表带存储媒介的名字
  100 + * @return
  101 + */
  102 + private String getCorrectName(String name) {
  103 + return StrUtil.removePrefix(name,getPrefix());
  104 + }
  105 +
  106 +}
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UreportDatabaseProvider.java deleted
1   -package cn.iocoder.yudao.module.report.framework.ureport.core;
2   -
3   -import cn.hutool.core.collection.CollUtil;
4   -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
5   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
6   -import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
7   -import cn.iocoder.yudao.module.report.service.ureport.UreportFileService;
8   -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
9   -import com.bstek.ureport.provider.report.ReportFile;
10   -import com.bstek.ureport.provider.report.ReportProvider;
11   -import lombok.Setter;
12   -import lombok.extern.slf4j.Slf4j;
13   -import org.springframework.boot.context.properties.ConfigurationProperties;
14   -import org.springframework.stereotype.Component;
15   -
16   -import javax.annotation.Resource;
17   -import java.io.ByteArrayInputStream;
18   -import java.io.InputStream;
19   -import java.time.LocalDateTime;
20   -import java.time.ZoneId;
21   -import java.time.ZonedDateTime;
22   -import java.util.ArrayList;
23   -import java.util.Date;
24   -import java.util.List;
25   -
26   -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
27   -import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_EXISTS;
28   -import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS;
29   -
30   -// TODO @赤焰:有了这个功能,是不是就不需要 UreportFileController?
31   -/**
32   - * 基于数据库的 {@link ReportProvider} 实现类
33   - *
34   - * @author 赤焰
35   - */
36   -@Component
37   -@Slf4j
38   -@Setter
39   -@ConfigurationProperties(prefix = "ureport.provider.database") // TODO @赤焰:是不是单独搞个 UReportProperties 用来注入 prefix、disabled 等属性
40   -public class UreportDatabaseProvider implements ReportProvider {
41   -
42   - private static final String NAME = "mysql-provider";
43   -
44   - // TODO @赤焰:IdTypeEnvironmentPostProcessor 参考下,通过 primary 数据源获取
45   - private String prefix = "mysql:";
46   -
47   - private boolean disabled = false;
48   -
49   - @Resource
50   - private UreportFileService ureportFileService;
51   -
52   - @Override
53   - public InputStream loadReport(String file) {
54   - // TODO @赤焰:是不是不需要这个 check 接口?直接使用 name 查询就 ok 了?
55   - // TODO @赤焰:变量的命名要注意,这里 reportDo 是不是叫 count 就好了?还有,这个方法的命名也不太对。
56   - Long reportDo = ureportFileService.checkExistByName(getCorrectName(file));
57   - if (reportDo <=0) { // TODO 赤焰:<= 0 注释空格
58   - throw exception(UREPORT_FILE_NOT_EXISTS);
59   - }
60   - // TODO @赤焰:queryUreportFileDoByName 改成 getUreportFileDoByName 更合适,保持整个项目的命名风格一致性。
61   - UreportFileDO ureportFileDO = ureportFileService.queryUreportFileDoByName(getCorrectName(file));
62   - byte[] content = ureportFileDO.getFileContent();
63   - return new ByteArrayInputStream(content);
64   - }
65   -
66   - @Override
67   - public void deleteReport(String file) {
68   - ureportFileService.deleteReportFileByName(getCorrectName(file));
69   - }
70   -
71   - @Override
72   - public List<ReportFile> getReportFiles() {
73   - // TODO @赤焰:queryReportFileList 改成 getReportFileList 更合适,保持整个项目的命名风格一致性。
74   - List<UreportFileDO> list = ureportFileService.queryReportFileList();
75   - List<ReportFile> reportList = new ArrayList<>();
76   - if(CollUtil.isEmpty(list)){ // TODO 赤焰:CollUtil.isEmpty(list) 注意空格
77   - // TODO @赤焰:这里可以直接返回 Collections.emptyList();
78   - return reportList;
79   - }
80   - // TODO 赤焰:可以使用 CollectionUtils.converList
81   - for (UreportFileDO reportFile : list) {
82   - // TODO 赤焰:可以使用 DateUtils.of() 么?
83   - LocalDateTime updateTime = reportFile.getUpdateTime();
84   - ZonedDateTime zdt = updateTime.atZone(ZoneId.systemDefault());
85   - Date date = Date.from(zdt.toInstant());
86   - reportList.add(new ReportFile(reportFile.getFileName(),date));
87   - }
88   - return reportList;
89   -
90   - }
91   -
92   - @Override
93   - public void saveReport(String file, String content) {
94   - file = getCorrectName(file);
95   - // TODO @赤焰:这里的逻辑,应该封装到 ureportFileService 中,这里只负责调用即可
96   - LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
97   - queryWrapper.eq(UreportFileDO::getFileName, file);
98   - Long count = ureportFileService.checkExistByName(file);
99   - if(count>1){
100   - throw exception(UREPORT_FILE_EXISTS);
101   - }
102   - UreportFileDO ureportFileDO = ureportFileService.queryUreportFileDoByName(file);
103   - UreportFileSaveReqVO saveReqVO = new UreportFileSaveReqVO();
104   - if (ureportFileDO == null) {
105   - saveReqVO.setFileName(file);
106   - saveReqVO.setFileContent(content);
107   - saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
108   - ureportFileService.createUreportFile(saveReqVO);
109   - } else {
110   - saveReqVO.setId(ureportFileDO.getId());
111   - saveReqVO.setFileName(file);
112   - saveReqVO.setFileContent(content);
113   - saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
114   - ureportFileService.updateUreportFile(saveReqVO);
115   - }
116   - }
117   -
118   - @Override
119   - public String getName() {
120   - return NAME;
121   - }
122   -
123   - @Override
124   - public boolean disabled() {
125   - return disabled;
126   - }
127   -
128   - @Override
129   - public String getPrefix() {
130   - return prefix;
131   - }
132   -
133   - // TODO @赤焰:这个方法的注释,最好写下哈;
134   - private String getCorrectName(String name) {
135   - // TODO 赤焰:一些常用方法,可以用 hutool StrUtil.removePrefix()
136   - if (name.startsWith(getPrefix())) {
137   - name = name.substring(getPrefix().length());
138   - }
139   - return name;
140   - }
141   -
142   -}
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UreportFileReportProvider.java deleted
1   -/*
2   -package cn.iocoder.yudao.module.report.framework.ureport.provider;
3   -
4   -import com.bstek.ureport.exception.ReportException;
5   -import com.bstek.ureport.provider.report.ReportFile;
6   -import com.bstek.ureport.provider.report.ReportProvider;
7   -import lombok.extern.slf4j.Slf4j;
8   -import org.apache.commons.io.IOUtils;
9   -import org.springframework.boot.context.properties.ConfigurationProperties;
10   -import org.springframework.stereotype.Component;
11   -
12   -import java.io.*;
13   -import java.util.ArrayList;
14   -import java.util.Calendar;
15   -import java.util.List;
16   -import java.util.Objects;
17   -
18   -// TODO @赤焰:这个类的作用是?如果全部注释,是不是可以删除哈?
19   -*/
20   -/**
21   - * 自定义文件存储,可接入oss等
22   - * @author 赤焰
23   - *//*
24   -
25   -@Slf4j
26   -@Component
27   -@ConfigurationProperties(prefix = "ureport.provider.file")
28   -public class UreportFileReportProvider implements ReportProvider{
29   -
30   - private String prefix="reportFile:";
31   - private String fileStoreDir;
32   - private boolean disabled;
33   -
34   - @Override
35   - public InputStream loadReport(String file) {
36   - if(file.startsWith(prefix)){
37   - file=file.substring(prefix.length(),file.length());
38   - }
39   - String fullPath=fileStoreDir+"/"+file;
40   - try {
41   - return new FileInputStream(fullPath);
42   - } catch (FileNotFoundException e) {
43   - throw new ReportException(e);
44   - }
45   - }
46   -
47   - @Override
48   - public void deleteReport(String file) {
49   - if(file.startsWith(prefix)){
50   - file=file.substring(prefix.length(),file.length());
51   - }
52   - String fullPath=fileStoreDir+"/"+file;
53   - File f=new File(fullPath);
54   - if(f.exists()){
55   - f.delete();
56   - }
57   - }
58   -
59   - @Override
60   - public List<ReportFile> getReportFiles() {
61   - File file=new File(fileStoreDir);
62   - List<ReportFile> list= new ArrayList<>();
63   - for(File f: Objects.requireNonNull(file.listFiles())){
64   - Calendar calendar=Calendar.getInstance();
65   - calendar.setTimeInMillis(f.lastModified());
66   - list.add(new ReportFile(f.getName(),calendar.getTime()));
67   - }
68   - list.sort((f1, f2) -> f2.getUpdateDate().compareTo(f1.getUpdateDate()));
69   - return list;
70   - }
71   -
72   - @Override
73   - public String getName() {
74   - return "文件存储系统";
75   - }
76   -
77   - @Override
78   - public void saveReport(String file,String content) {
79   - if(file.startsWith(prefix)){
80   - file=file.substring(prefix.length(),file.length());
81   - }
82   - String fullPath=fileStoreDir+"/"+file;
83   - FileOutputStream outStream=null;
84   - try{
85   - outStream=new FileOutputStream(new File(fullPath));
86   - IOUtils.write(content, outStream,"utf-8");
87   - }catch(Exception ex){
88   - throw new ReportException(ex);
89   - }finally{
90   - if(outStream!=null){
91   - try {
92   - outStream.close();
93   - } catch (IOException e) {
94   - e.printStackTrace();
95   - }
96   - }
97   - }
98   -
99   - }
100   -
101   - @Override
102   - public boolean disabled() {
103   - return disabled;
104   - }
105   -
106   - public void setDisabled(boolean disabled) {
107   - this.disabled = disabled;
108   - }
109   -
110   - public void setFileStoreDir(String fileStoreDir) {
111   - this.fileStoreDir = fileStoreDir;
112   - }
113   -
114   - @Override
115   - public String getPrefix() {
116   - return prefix;
117   - }
118   -
119   -}
120   -*/
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileService.java renamed to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataService.java
1 1 package cn.iocoder.yudao.module.report.service.ureport;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO;
5   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
6   -import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
  4 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO;
  5 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO;
  6 +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
7 7  
8 8 import javax.validation.Valid;
9 9 import java.util.List;
... ... @@ -13,7 +13,7 @@ import java.util.List;
13 13 *
14 14 * @author 芋道源码
15 15 */
16   -public interface UreportFileService {
  16 +public interface UReportDataService {
17 17  
18 18 /**
19 19 * 创建Ureport2报表
... ... @@ -21,21 +21,21 @@ public interface UreportFileService {
21 21 * @param createReqVO 创建信息
22 22 * @return 编号
23 23 */
24   - Long createUreportFile(@Valid UreportFileSaveReqVO createReqVO);
  24 + Long createUReportData(@Valid UReportDataSaveReqVO createReqVO);
25 25  
26 26 /**
27 27 * 更新Ureport2报表
28 28 *
29 29 * @param updateReqVO 更新信息
30 30 */
31   - void updateUreportFile(@Valid UreportFileSaveReqVO updateReqVO);
  31 + void updateUReportData(@Valid UReportDataSaveReqVO updateReqVO);
32 32  
33 33 /**
34 34 * 删除Ureport2报表
35 35 *
36 36 * @param id 编号
37 37 */
38   - void deleteUreportFile(Long id);
  38 + void deleteUReportData(Long id);
39 39  
40 40 /**
41 41 * 获得Ureport2报表
... ... @@ -43,7 +43,7 @@ public interface UreportFileService {
43 43 * @param id 编号
44 44 * @return Ureport2报表
45 45 */
46   - UreportFileDO getUreportFile(Long id);
  46 + UReportDataDO getUReportData(Long id);
47 47  
48 48 /**
49 49 * 获得Ureport2报表分页
... ... @@ -51,36 +51,32 @@ public interface UreportFileService {
51 51 * @param pageReqVO 分页查询
52 52 * @return Ureport2报表分页
53 53 */
54   - PageResult<UreportFileDO> getUreportFilePage(UreportFilePageReqVO pageReqVO);
55   -
  54 + PageResult<UReportDataDO> getUReportDataPage(UReportDataPageReqVO pageReqVO);
56 55  
57 56 /**
58   - * 根据报表名称检查报表是否存在
59   - * @param name 报表名称
  57 + * 根据名称删除报表
  58 + * @param name
60 59 * @return
61 60 */
62   - Long checkExistByName(String name);
  61 + int deleteByName(String name);
63 62  
64 63 /**
65   - * 根据报表名称查询报表
66   - * @param name 报表名称
67   - * @return
  64 + * 根据名称校验报表是否存在
  65 + * @param name
68 66 */
69   - UreportFileDO queryUreportFileDoByName(String name);
70   -
  67 + void validateUReportDataExists(String name);
71 68  
72 69 /**
73   - * 查询全部报表
  70 + * 根据名称查询报表
  71 + * @param name
74 72 * @return
75 73 */
76   - List<UreportFileDO> queryReportFileList();
77   -
  74 + UReportDataDO selectOneByName(String name);
78 75  
79 76 /**
80   - * 根据报表名称删除报表
81   - * @param name
  77 + * 获取全部报表
82 78 * @return
83 79 */
84   - int deleteReportFileByName(String name);
  80 + List<UReportDataDO> getReportDataList();
85 81  
86 82 }
... ...
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java renamed to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java
1 1 package cn.iocoder.yudao.module.report.service.ureport;
2 2  
3   -import cn.hutool.core.collection.CollectionUtil;
4   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
5   -import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO;
7   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
8   -import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
9   -import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper;
10   -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
11 3 import org.springframework.stereotype.Service;
  4 +import javax.annotation.Resource;
12 5 import org.springframework.validation.annotation.Validated;
13 6  
14   -import javax.annotation.Resource;
  7 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
  8 +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
  9 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  10 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  11 +
  12 +import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper;
  13 +
15 14 import java.util.List;
16 15  
17 16 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
18   -import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS;
  17 +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*;
19 18  
20 19 /**
21 20 * Ureport2报表 Service 实现类
... ... @@ -24,87 +23,72 @@ import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FI
24 23 */
25 24 @Service
26 25 @Validated
27   -public class UreportFileServiceImpl implements UreportFileService {
  26 +public class UReportDataServiceImpl implements UReportDataService {
28 27  
29 28 @Resource
30   - private UreportFileMapper ureportFileMapper;
  29 + private UReportDataMapper uReportDataMapper;
31 30  
32 31 @Override
33   - public Long createUreportFile(UreportFileSaveReqVO createReqVO) {
  32 + public Long createUReportData(UReportDataSaveReqVO createReqVO) {
34 33 // 插入
35   - UreportFileDO ureportFile = BeanUtils.toBean(createReqVO, UreportFileDO.class);
36   - ureportFileMapper.insert(ureportFile);
  34 + UReportDataDO uReportData = BeanUtils.toBean(createReqVO, UReportDataDO.class);
  35 + uReportDataMapper.insert(uReportData);
37 36 // 返回
38   - return ureportFile.getId();
  37 + return uReportData.getId();
39 38 }
40 39  
41 40 @Override
42   - public void updateUreportFile(UreportFileSaveReqVO updateReqVO) {
  41 + public void updateUReportData(UReportDataSaveReqVO updateReqVO) {
43 42 // 校验存在
44   - validateUreportFileExists(updateReqVO.getId());
  43 + validateUReportDataExists(updateReqVO.getId());
45 44 // 更新
46   - UreportFileDO updateObj = BeanUtils.toBean(updateReqVO, UreportFileDO.class);
47   - ureportFileMapper.updateById(updateObj);
  45 + UReportDataDO updateObj = BeanUtils.toBean(updateReqVO, UReportDataDO.class);
  46 + uReportDataMapper.updateById(updateObj);
48 47 }
49 48  
50 49 @Override
51   - public void deleteUreportFile(Long id) {
  50 + public void deleteUReportData(Long id) {
52 51 // 校验存在
53   - validateUreportFileExists(id);
  52 + validateUReportDataExists(id);
54 53 // 删除
55   - ureportFileMapper.deleteById(id);
  54 + uReportDataMapper.deleteById(id);
56 55 }
57 56  
58   - private void validateUreportFileExists(Long id) {
59   - if (ureportFileMapper.selectById(id) == null) {
60   - throw exception(UREPORT_FILE_NOT_EXISTS);
  57 + private void validateUReportDataExists(Long id) {
  58 + if (uReportDataMapper.selectById(id) == null) {
  59 + throw exception(REPORT_DATA_NOT_EXISTS);
61 60 }
62 61 }
63 62  
64 63 @Override
65   - public UreportFileDO getUreportFile(Long id) {
66   - return ureportFileMapper.selectById(id);
  64 + public void validateUReportDataExists(String name) {
  65 + if (uReportDataMapper.selectByName(name) == null) {
  66 + throw exception(REPORT_DATA_NOT_EXISTS);
  67 + }
67 68 }
68 69  
69 70 @Override
70   - public PageResult<UreportFileDO> getUreportFilePage(UreportFilePageReqVO pageReqVO) {
71   - return ureportFileMapper.selectPage(pageReqVO);
  71 + public UReportDataDO getUReportData(Long id) {
  72 + return uReportDataMapper.selectById(id);
72 73 }
73 74  
74 75 @Override
75   - public Long checkExistByName(String name) {
76   - // TODO @赤焰:Service 处理业务逻辑,不能出现 Mapper 层的东西,收敛成 mapper 的一个操作方法
77   - LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
78   - queryWrapper.eq(UreportFileDO::getFileName,name);
79   - return ureportFileMapper.selectCount(queryWrapper);
  76 + public PageResult<UReportDataDO> getUReportDataPage(UReportDataPageReqVO pageReqVO) {
  77 + return uReportDataMapper.selectPage(pageReqVO);
80 78 }
81 79  
82 80 @Override
83   - public UreportFileDO queryUreportFileDoByName(String name) {
84   - // TODO @赤焰:Service 处理业务逻辑,不能出现 Mapper 层的东西,收敛成 mapper 的一个操作方法
85   - LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
86   - queryWrapper.eq(UreportFileDO::getFileName,name);
87   - // TODO @赤焰:这里,可以用 selectByName 即可
88   - List<UreportFileDO> list = ureportFileMapper.selectList(queryWrapper);
89   - if(CollectionUtil.isNotEmpty(list)){
90   - return list.get(0);
91   - }
92   - return null;
  81 + public int deleteByName(String name) {
  82 + return uReportDataMapper.deleteByName(name);
93 83 }
94 84  
95 85 @Override
96   - public List<UreportFileDO> queryReportFileList() {
97   - // TODO @赤焰:Service 处理业务逻辑,不能出现 Mapper 层的东西,收敛成 mapper 的一个操作方法
98   - LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
99   - return ureportFileMapper.selectList(queryWrapper);
  86 + public UReportDataDO selectOneByName(String name) {
  87 + return uReportDataMapper.selectOneByName(name);
100 88 }
101 89  
102 90 @Override
103   - public int deleteReportFileByName(String name) {
104   - // TODO @赤焰:Service 处理业务逻辑,不能出现 Mapper 层的东西,收敛成 mapper 的一个操作方法
105   - LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
106   - queryWrapper.eq(UreportFileDO::getFileName,name);
107   - return ureportFileMapper.delete(queryWrapper);
  91 + public List<UReportDataDO> getReportDataList() {
  92 + return uReportDataMapper.selectList();
108 93 }
109   -
110 94 }
... ...
yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper">
  4 +
  5 + <!--
  6 + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  7 + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  8 + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  9 + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  10 + -->
  11 +
  12 +</mapper>
0 13 \ No newline at end of file
... ...
yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImplTest.java renamed to yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java
1 1 package cn.iocoder.yudao.module.report.service.ureport;
2 2  
3   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
5   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO;
6   -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
7   -import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
8   -import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper;
9 3 import org.junit.jupiter.api.Disabled;
10 4 import org.junit.jupiter.api.Test;
11   -import org.springframework.context.annotation.Import;
12 5  
13 6 import javax.annotation.Resource;
14 7  
15   -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
16   -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
17   -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
18   -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
19   -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
20   -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
21   -import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS;
  8 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  9 +
  10 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
  11 +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
  12 +import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper;
  13 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  14 +
  15 +import org.springframework.context.annotation.Import;
  16 +
  17 +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*;
  18 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
  19 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
  20 +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
  21 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
22 22 import static org.junit.jupiter.api.Assertions.*;
23 23  
24   -// TODO 芋艿:但愿测试后面补
25 24 /**
26   - * {@link UreportFileServiceImpl} 的单元测试类
  25 + * {@link UReportDataServiceImpl} 的单元测试类
27 26 *
28 27 * @author 芋道源码
29 28 */
30   -@Import(UreportFileServiceImpl.class)
31   -public class UreportFileServiceImplTest extends BaseDbUnitTest {
  29 +@Import(UReportDataServiceImpl.class)
  30 +public class UReportDataServiceImplTest extends BaseDbUnitTest {
32 31  
33 32 @Resource
34   - private UreportFileServiceImpl ureportFileService;
  33 + private UReportDataServiceImpl uReportDataService;
35 34  
36 35 @Resource
37   - private UreportFileMapper ureportFileMapper;
  36 + private UReportDataMapper uReportDataMapper;
38 37  
39 38 @Test
40   - public void testCreateUreportFile_success() {
  39 + public void testCreateUReportData_success() {
41 40 // 准备参数
42   - UreportFileSaveReqVO createReqVO = randomPojo(UreportFileSaveReqVO.class).setId(null);
  41 + UReportDataSaveReqVO createReqVO = randomPojo(UReportDataSaveReqVO.class).setId(null);
43 42  
44 43 // 调用
45   - Long ureportFileId = ureportFileService.createUreportFile(createReqVO);
  44 + Long uReportDataId = uReportDataService.createUReportData(createReqVO);
46 45 // 断言
47   - assertNotNull(ureportFileId);
  46 + assertNotNull(uReportDataId);
48 47 // 校验记录的属性是否正确
49   - UreportFileDO ureportFile = ureportFileMapper.selectById(ureportFileId);
50   - assertPojoEquals(createReqVO, ureportFile, "id");
  48 + UReportDataDO uReportData = uReportDataMapper.selectById(uReportDataId);
  49 + assertPojoEquals(createReqVO, uReportData, "id");
51 50 }
52 51  
53 52 @Test
54   - public void testUpdateUreportFile_success() {
  53 + public void testUpdateUReportData_success() {
55 54 // mock 数据
56   - UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class);
57   - ureportFileMapper.insert(dbUreportFile);// @Sql: 先插入出一条存在的数据
  55 + UReportDataDO dbUReportData = randomPojo(UReportDataDO.class);
  56 + uReportDataMapper.insert(dbUReportData);// @Sql: 先插入出一条存在的数据
58 57 // 准备参数
59   - UreportFileSaveReqVO updateReqVO = randomPojo(UreportFileSaveReqVO.class, o -> {
60   - o.setId(dbUreportFile.getId()); // 设置更新的 ID
  58 + UReportDataSaveReqVO updateReqVO = randomPojo(UReportDataSaveReqVO.class, o -> {
  59 + o.setId(dbUReportData.getId()); // 设置更新的 ID
61 60 });
62 61  
63 62 // 调用
64   - ureportFileService.updateUreportFile(updateReqVO);
  63 + uReportDataService.updateUReportData(updateReqVO);
65 64 // 校验是否更新正确
66   - UreportFileDO ureportFile = ureportFileMapper.selectById(updateReqVO.getId()); // 获取最新的
67   - assertPojoEquals(updateReqVO, ureportFile);
  65 + UReportDataDO uReportData = uReportDataMapper.selectById(updateReqVO.getId()); // 获取最新的
  66 + assertPojoEquals(updateReqVO, uReportData);
68 67 }
69 68  
70 69 @Test
71   - public void testUpdateUreportFile_notExists() {
  70 + public void testUpdateUReportData_notExists() {
72 71 // 准备参数
73   - UreportFileSaveReqVO updateReqVO = randomPojo(UreportFileSaveReqVO.class);
  72 + UReportDataSaveReqVO updateReqVO = randomPojo(UReportDataSaveReqVO.class);
74 73  
75 74 // 调用, 并断言异常
76   - assertServiceException(() -> ureportFileService.updateUreportFile(updateReqVO), UREPORT_FILE_NOT_EXISTS);
  75 + assertServiceException(() -> uReportDataService.updateUReportData(updateReqVO), REPORT_DATA_NOT_EXISTS);
77 76 }
78 77  
79 78 @Test
80   - public void testDeleteUreportFile_success() {
  79 + public void testDeleteUReportData_success() {
81 80 // mock 数据
82   - UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class);
83   - ureportFileMapper.insert(dbUreportFile);// @Sql: 先插入出一条存在的数据
  81 + UReportDataDO dbUReportData = randomPojo(UReportDataDO.class);
  82 + uReportDataMapper.insert(dbUReportData);// @Sql: 先插入出一条存在的数据
84 83 // 准备参数
85   - Long id = dbUreportFile.getId();
  84 + Long id = dbUReportData.getId();
86 85  
87 86 // 调用
88   - ureportFileService.deleteUreportFile(id);
  87 + uReportDataService.deleteUReportData(id);
89 88 // 校验数据不存在了
90   - assertNull(ureportFileMapper.selectById(id));
  89 + assertNull(uReportDataMapper.selectById(id));
91 90 }
92 91  
93 92 @Test
94   - public void testDeleteUreportFile_notExists() {
  93 + public void testDeleteUReportData_notExists() {
95 94 // 准备参数
96 95 Long id = randomLongId();
97 96  
98 97 // 调用, 并断言异常
99   - assertServiceException(() -> ureportFileService.deleteUreportFile(id), UREPORT_FILE_NOT_EXISTS);
  98 + assertServiceException(() -> uReportDataService.deleteUReportData(id), REPORT_DATA_NOT_EXISTS);
100 99 }
101 100  
102 101 @Test
103 102 @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
104   - public void testGetUreportFilePage() {
  103 + public void testGetUReportDataPage() {
105 104 // mock 数据
106   - UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class, o -> { // 等会查询到
107   - o.setFileName(null);
  105 + UReportDataDO dbUReportData = randomPojo(UReportDataDO.class, o -> { // 等会查询到
  106 + o.setName(null);
108 107 o.setStatus(null);
109 108 o.setRemark(null);
110 109 o.setCreateTime(null);
111 110 });
112   - ureportFileMapper.insert(dbUreportFile);
113   - // 测试 fileName 不匹配
114   - ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setFileName(null)));
  111 + uReportDataMapper.insert(dbUReportData);
  112 + // 测试 name 不匹配
  113 + uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setName(null)));
115 114 // 测试 status 不匹配
116   - ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setStatus(null)));
  115 + uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setStatus(null)));
117 116 // 测试 remark 不匹配
118   - ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setRemark(null)));
  117 + uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setRemark(null)));
119 118 // 测试 createTime 不匹配
120   - ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setCreateTime(null)));
  119 + uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setCreateTime(null)));
121 120 // 准备参数
122   - UreportFilePageReqVO reqVO = new UreportFilePageReqVO();
123   - reqVO.setFileName(null);
  121 + UReportDataPageReqVO reqVO = new UReportDataPageReqVO();
  122 + reqVO.setName(null);
124 123 reqVO.setStatus(null);
125 124 reqVO.setRemark(null);
126 125 reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
127 126  
128 127 // 调用
129   - PageResult<UreportFileDO> pageResult = ureportFileService.getUreportFilePage(reqVO);
  128 + PageResult<UReportDataDO> pageResult = uReportDataService.getUReportDataPage(reqVO);
130 129 // 断言
131 130 assertEquals(1, pageResult.getTotal());
132 131 assertEquals(1, pageResult.getList().size());
133   - assertPojoEquals(dbUreportFile, pageResult.getList().get(0));
  132 + assertPojoEquals(dbUReportData, pageResult.getList().get(0));
134 133 }
135 134  
136   -}
137 135 \ No newline at end of file
  136 +}
... ...
yudao-module-report/yudao-module-report-biz/src/test/resources/sql/clean.sql
1 1 DELETE FROM "report_go_view_project";
2   -DELETE FROM "ureport_file";
  2 +DELETE FROM "report_ureport_data";
... ...
yudao-module-report/yudao-module-report-biz/src/test/resources/sql/create_tables.sql
... ... @@ -12,16 +12,16 @@ CREATE TABLE IF NOT EXISTS &quot;report_go_view_project&quot; (
12 12 "deleted" bit NOT NULL DEFAULT FALSE,
13 13 PRIMARY KEY ("id")
14 14 ) COMMENT 'GoView 项目表';
15   -CREATE TABLE IF NOT EXISTS "ureport_file" (
16   - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
17   - "file_name" varchar NOT NULL,
18   - "status" int NOT NULL,
19   - "file_content" varchar,
20   - "remark" varchar,
21   - "creator" varchar DEFAULT '',
22   - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
23   - "updater" varchar DEFAULT '',
24   - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
25   - "deleted" bit NOT NULL DEFAULT FALSE,
26   - PRIMARY KEY ("id")
  15 +CREATE TABLE IF NOT EXISTS "report_ureport_data" (
  16 + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  17 + "name" varchar NOT NULL,
  18 + "status" int NOT NULL,
  19 + "content" varchar,
  20 + "remark" varchar,
  21 + "creator" varchar DEFAULT '',
  22 + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  23 + "updater" varchar DEFAULT '',
  24 + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  25 + "deleted" bit NOT NULL DEFAULT FALSE,
  26 + PRIMARY KEY ("id")
27 27 ) COMMENT 'Ureport2报表';
... ...
yudao-server/src/main/resources/application.yaml
... ... @@ -229,7 +229,7 @@ yudao:
229 229 - jimu_report_link
230 230 - jimu_report_map
231 231 - jimu_report_share
232   - - ureport_file
  232 + - report_ureport_data
233 233 - rep_demo_dxtj
234 234 - rep_demo_employee
235 235 - rep_demo_gongsi
... ...