Commit 076bf136876c004e99a2e0bb5aa3e0933786edf8

Authored by YunaiV
1 parent 0d3efe4f

📈 REPORT:code review ureport2 实现

Showing 18 changed files with 134 additions and 142 deletions
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 <module>yudao-module-infra</module> 17 <module>yudao-module-infra</module>
18 <!-- <module>yudao-module-member</module>--> 18 <!-- <module>yudao-module-member</module>-->
19 <!-- <module>yudao-module-bpm</module>--> 19 <!-- <module>yudao-module-bpm</module>-->
20 -<!-- <module>yudao-module-report</module>--> 20 + <module>yudao-module-report</module>
21 <!-- <module>yudao-module-mp</module>--> 21 <!-- <module>yudao-module-mp</module>-->
22 <!-- <module>yudao-module-pay</module>--> 22 <!-- <module>yudao-module-pay</module>-->
23 <!-- <module>yudao-module-mall</module>--> 23 <!-- <module>yudao-module-mall</module>-->
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,7 +13,7 @@ public interface ErrorCodeConstants {
13 ErrorCode GO_VIEW_PROJECT_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在"); 13 ErrorCode GO_VIEW_PROJECT_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在");
14 14
15 // ========== UREPORT 模块 1-003-001-000 ========== 15 // ========== UREPORT 模块 1-003-001-000 ==========
16 - ErrorCode REPORT_DATA_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2报表不存在"); 16 + ErrorCode UREPORT_DATA_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2 报表不存在");
  17 + ErrorCode UREPORT_DATABASE_NOT_EXISTS = new ErrorCode(1_003_001_002, "Ureport2 报表数据源不存在");
17 18
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/UReportDataController.java
1 package cn.iocoder.yudao.module.report.controller.admin.ureport; 1 package cn.iocoder.yudao.module.report.controller.admin.ureport;
2 2
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 - 3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
17 import cn.iocoder.yudao.framework.common.pojo.PageParam; 4 import cn.iocoder.yudao.framework.common.pojo.PageParam;
18 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
19 -import cn.iocoder.yudao.framework.common.pojo.CommonResult;  
20 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
21 -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;  
22 -  
23 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 7 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
24 -  
25 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; 8 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
26 -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;  
27 -  
28 -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; 9 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO;
  10 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataRespVO;
  11 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO;
29 import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; 12 import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
30 import cn.iocoder.yudao.module.report.service.ureport.UReportDataService; 13 import cn.iocoder.yudao.module.report.service.ureport.UReportDataService;
  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 +
  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;
  26 +
  27 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  28 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
31 29
32 -@Tag(name = "管理后台 - Ureport2报表") 30 +@Tag(name = "管理后台 - Ureport2 报表")
33 @RestController 31 @RestController
34 @RequestMapping("/report/ureport-data") 32 @RequestMapping("/report/ureport-data")
35 @Validated 33 @Validated
@@ -39,14 +37,14 @@ public class UReportDataController { @@ -39,14 +37,14 @@ public class UReportDataController {
39 private UReportDataService uReportDataService; 37 private UReportDataService uReportDataService;
40 38
41 @PostMapping("/create") 39 @PostMapping("/create")
42 - @Operation(summary = "创建Ureport2报表") 40 + @Operation(summary = "创建 Ureport2 报表")
43 @PreAuthorize("@ss.hasPermission('report:ureport-data:create')") 41 @PreAuthorize("@ss.hasPermission('report:ureport-data:create')")
44 public CommonResult<Long> createUReportData(@Valid @RequestBody UReportDataSaveReqVO createReqVO) { 42 public CommonResult<Long> createUReportData(@Valid @RequestBody UReportDataSaveReqVO createReqVO) {
45 return success(uReportDataService.createUReportData(createReqVO)); 43 return success(uReportDataService.createUReportData(createReqVO));
46 } 44 }
47 45
48 @PutMapping("/update") 46 @PutMapping("/update")
49 - @Operation(summary = "更新Ureport2报表") 47 + @Operation(summary = "更新 Ureport2 报表")
50 @PreAuthorize("@ss.hasPermission('report:ureport-data:update')") 48 @PreAuthorize("@ss.hasPermission('report:ureport-data:update')")
51 public CommonResult<Boolean> updateUReportData(@Valid @RequestBody UReportDataSaveReqVO updateReqVO) { 49 public CommonResult<Boolean> updateUReportData(@Valid @RequestBody UReportDataSaveReqVO updateReqVO) {
52 uReportDataService.updateUReportData(updateReqVO); 50 uReportDataService.updateUReportData(updateReqVO);
@@ -54,7 +52,7 @@ public class UReportDataController { @@ -54,7 +52,7 @@ public class UReportDataController {
54 } 52 }
55 53
56 @DeleteMapping("/delete") 54 @DeleteMapping("/delete")
57 - @Operation(summary = "删除Ureport2报表") 55 + @Operation(summary = "删除 Ureport2 报表")
58 @Parameter(name = "id", description = "编号", required = true) 56 @Parameter(name = "id", description = "编号", required = true)
59 @PreAuthorize("@ss.hasPermission('report:ureport-data:delete')") 57 @PreAuthorize("@ss.hasPermission('report:ureport-data:delete')")
60 public CommonResult<Boolean> deleteUReportData(@RequestParam("id") Long id) { 58 public CommonResult<Boolean> deleteUReportData(@RequestParam("id") Long id) {
@@ -80,7 +78,7 @@ public class UReportDataController { @@ -80,7 +78,7 @@ public class UReportDataController {
80 } 78 }
81 79
82 @GetMapping("/export-excel") 80 @GetMapping("/export-excel")
83 - @Operation(summary = "导出Ureport2报表 Excel") 81 + @Operation(summary = "导出 Ureport2 报表 Excel")
84 @PreAuthorize("@ss.hasPermission('report:ureport-data:export')") 82 @PreAuthorize("@ss.hasPermission('report:ureport-data:export')")
85 @OperateLog(type = EXPORT) 83 @OperateLog(type = EXPORT)
86 public void exportUReportDataExcel(@Valid UReportDataPageReqVO pageReqVO, 84 public void exportUReportDataExcel(@Valid UReportDataPageReqVO pageReqVO,
@@ -88,7 +86,7 @@ public class UReportDataController { @@ -88,7 +86,7 @@ public class UReportDataController {
88 pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); 86 pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
89 List<UReportDataDO> list = uReportDataService.getUReportDataPage(pageReqVO).getList(); 87 List<UReportDataDO> list = uReportDataService.getUReportDataPage(pageReqVO).getList();
90 // 导出 Excel 88 // 导出 Excel
91 - ExcelUtils.write(response, "Ureport2报表.xls", "数据", UReportDataRespVO.class, 89 + ExcelUtils.write(response, "Ureport2 报表.xls", "数据", UReportDataRespVO.class,
92 BeanUtils.toBean(list, UReportDataRespVO.class)); 90 BeanUtils.toBean(list, UReportDataRespVO.class));
93 } 91 }
94 92
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataPageReqVO.java
1 package cn.iocoder.yudao.module.report.controller.admin.ureport.vo; 1 package cn.iocoder.yudao.module.report.controller.admin.ureport.vo;
2 2
3 -import lombok.*;  
4 -import java.util.*;  
5 -import io.swagger.v3.oas.annotations.media.Schema;  
6 import cn.iocoder.yudao.framework.common.pojo.PageParam; 3 import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
7 import org.springframework.format.annotation.DateTimeFormat; 8 import org.springframework.format.annotation.DateTimeFormat;
  9 +
8 import java.time.LocalDateTime; 10 import java.time.LocalDateTime;
9 11
10 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; 12 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
11 13
12 -@Schema(description = "管理后台 - Ureport2报表分页 Request VO") 14 +@Schema(description = "管理后台 - Ureport2 报表分页 Request VO")
13 @Data 15 @Data
14 @EqualsAndHashCode(callSuper = true) 16 @EqualsAndHashCode(callSuper = true)
15 @ToString(callSuper = true) 17 @ToString(callSuper = true)
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataRespVO.java
@@ -10,7 +10,7 @@ import lombok.Data; @@ -10,7 +10,7 @@ import lombok.Data;
10 10
11 import java.time.LocalDateTime; 11 import java.time.LocalDateTime;
12 12
13 -@Schema(description = "管理后台 - Ureport2报表 Response VO") 13 +@Schema(description = "管理后台 - Ureport2 报表 Response VO")
14 @Data 14 @Data
15 @ExcelIgnoreUnannotated 15 @ExcelIgnoreUnannotated
16 public class UReportDataRespVO { 16 public class UReportDataRespVO {
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataSaveReqVO.java
1 package cn.iocoder.yudao.module.report.controller.admin.ureport.vo; 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;
3 import io.swagger.v3.oas.annotations.media.Schema; 5 import io.swagger.v3.oas.annotations.media.Schema;
4 -import lombok.*;  
5 -import java.util.*;  
6 -import javax.validation.constraints.*;  
7 -import java.util.*; 6 +import lombok.Data;
8 7
9 -@Schema(description = "管理后台 - Ureport2报表新增/修改 Request VO") 8 +import javax.validation.constraints.NotEmpty;
  9 +import javax.validation.constraints.NotNull;
  10 +
  11 +@Schema(description = "管理后台 - Ureport2 报表新增/修改 Request VO")
10 @Data 12 @Data
11 public class UReportDataSaveReqVO { 13 public class UReportDataSaveReqVO {
12 14
@@ -19,6 +21,7 @@ public class UReportDataSaveReqVO { @@ -19,6 +21,7 @@ public class UReportDataSaveReqVO {
19 21
20 @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") 22 @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
21 @NotNull(message = "状态不能为空") 23 @NotNull(message = "状态不能为空")
  24 + @InEnum(CommonStatusEnum.class)
22 private Integer status; 25 private Integer status;
23 26
24 @Schema(description = "文件内容") 27 @Schema(description = "文件内容")
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UReportDataDO.java
@@ -7,8 +7,9 @@ import com.baomidou.mybatisplus.annotation.TableId; @@ -7,8 +7,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
7 import com.baomidou.mybatisplus.annotation.TableName; 7 import com.baomidou.mybatisplus.annotation.TableName;
8 import lombok.*; 8 import lombok.*;
9 9
  10 +// TODO @赤焰:这个是不是可以支持多租户?
10 /** 11 /**
11 - * Ureport2报表 DO 12 + * Ureport2 报表 DO
12 * 13 *
13 * @author 芋道源码 14 * @author 芋道源码
14 */ 15 */
@@ -34,7 +35,7 @@ public class UReportDataDO extends BaseDO { @@ -34,7 +35,7 @@ public class UReportDataDO extends BaseDO {
34 /** 35 /**
35 * 状态 36 * 状态
36 * 37 *
37 - * 枚举 {@link CommonStatusEnum#getStatus()} 38 + * 枚举 {@link CommonStatusEnum#getStatus()}
38 */ 39 */
39 private Integer status; 40 private Integer status;
40 /** 41 /**
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java
1 package cn.iocoder.yudao.module.report.dal.mysql.ureport; 1 package cn.iocoder.yudao.module.report.dal.mysql.ureport;
2 2
3 -import java.util.*;  
4 -  
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 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; 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO;
8 import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; 7 import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
9 import org.apache.ibatis.annotations.Mapper; 8 import org.apache.ibatis.annotations.Mapper;
10 -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; 9 +
  10 +import java.util.List;
11 11
12 /** 12 /**
13 * Ureport2报表 Mapper 13 * Ureport2报表 Mapper
@@ -26,33 +26,17 @@ public interface UReportDataMapper extends BaseMapperX&lt;UReportDataDO&gt; { @@ -26,33 +26,17 @@ public interface UReportDataMapper extends BaseMapperX&lt;UReportDataDO&gt; {
26 .orderByDesc(UReportDataDO::getId)); 26 .orderByDesc(UReportDataDO::getId));
27 } 27 }
28 28
29 - /**  
30 - * 根据名字查询报表  
31 - * @param name 报表名字  
32 - * @return  
33 - */  
34 - default List<UReportDataDO> selectByName(String name){ 29 + default List<UReportDataDO> selectListByName(String name) {
35 return selectList(new LambdaQueryWrapperX<UReportDataDO>() 30 return selectList(new LambdaQueryWrapperX<UReportDataDO>()
36 .eqIfPresent(UReportDataDO::getName,name)); 31 .eqIfPresent(UReportDataDO::getName,name));
37 } 32 }
38 33
39 - /**  
40 - * 根据名字查询报表  
41 - * @param name 报表名字  
42 - * @return  
43 - */  
44 - default UReportDataDO selectOneByName(String name){ 34 + default UReportDataDO selectByName(String name){
45 return selectOne(new LambdaQueryWrapperX<UReportDataDO>() 35 return selectOne(new LambdaQueryWrapperX<UReportDataDO>()
46 .eqIfPresent(UReportDataDO::getName,name)); 36 .eqIfPresent(UReportDataDO::getName,name));
47 } 37 }
48 38
49 -  
50 - /**  
51 - * 根据名字删除报表  
52 - * @param name 报表名字  
53 - * @return  
54 - */  
55 - default int deleteByName(String name){ 39 + default int deleteByName(String name) {
56 return delete(new LambdaQueryWrapperX<UReportDataDO>() 40 return delete(new LambdaQueryWrapperX<UReportDataDO>()
57 .eqIfPresent(UReportDataDO::getName,name)); 41 .eqIfPresent(UReportDataDO::getName,name));
58 } 42 }
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportConfiguration.java
1 package cn.iocoder.yudao.module.report.framework.ureport.config; 1 package cn.iocoder.yudao.module.report.framework.ureport.config;
2 2
3 -import cn.iocoder.yudao.module.report.framework.security.config.UReportProperties;  
4 import com.bstek.ureport.console.UReportServlet; 3 import com.bstek.ureport.console.UReportServlet;
5 import org.springframework.boot.context.properties.EnableConfigurationProperties; 4 import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 import org.springframework.boot.web.servlet.ServletRegistrationBean; 5 import org.springframework.boot.web.servlet.ServletRegistrationBean;
@@ -18,7 +17,7 @@ import javax.servlet.Servlet; @@ -18,7 +17,7 @@ import javax.servlet.Servlet;
18 */ 17 */
19 @Configuration 18 @Configuration
20 @ImportResource({"classpath:ureport-console-context.xml"}) 19 @ImportResource({"classpath:ureport-console-context.xml"})
21 -@PropertySource(value = {"classpath:ureport.properties"}) 20 +@PropertySource(value = {"classpath:ureport.properties"}) // TODO @赤焰:这个可以搞到 application.yaml 里么?
22 @EnableConfigurationProperties({UReportProperties.class}) 21 @EnableConfigurationProperties({UReportProperties.class})
23 public class UReportConfiguration { 22 public class UReportConfiguration {
24 23
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportProperties.java renamed to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportProperties.java
1 -package cn.iocoder.yudao.module.report.framework.security.config; 1 +package cn.iocoder.yudao.module.report.framework.ureport.config;
2 2
3 import lombok.Data; 3 import lombok.Data;
4 import org.springframework.boot.context.properties.ConfigurationProperties; 4 import org.springframework.boot.context.properties.ConfigurationProperties;
5 5
6 /** 6 /**
7 - * UReport配置类 7 + * UReport2 配置类
8 * 8 *
9 * @author 赤焰 9 * @author 赤焰
10 */ 10 */
11 @Data 11 @Data
12 @ConfigurationProperties(prefix = "ureport.provider.database") 12 @ConfigurationProperties(prefix = "ureport.provider.database")
13 public class UReportProperties { 13 public class UReportProperties {
  14 +
  15 + // TODO @赤焰:每个字段的注释写下哈;
14 private String name = "数据库文件系统"; 16 private String name = "数据库文件系统";
15 - private String prefix = "db-"; 17 +
  18 + private String prefix = "db-";
  19 +
16 private boolean disabled = false; 20 private boolean disabled = false;
  21 +
17 } 22 }
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/core/UReportDataSource.java
1 -package cn.iocoder.yudao.module.report.framework.ureport.config; 1 +package cn.iocoder.yudao.module.report.framework.ureport.core;
2 2
3 import com.bstek.ureport.definition.datasource.BuildinDatasource; 3 import com.bstek.ureport.definition.datasource.BuildinDatasource;
4 import lombok.extern.slf4j.Slf4j; 4 import lombok.extern.slf4j.Slf4j;
@@ -10,10 +10,11 @@ import java.sql.Connection; @@ -10,10 +10,11 @@ import java.sql.Connection;
10 import java.sql.SQLException; 10 import java.sql.SQLException;
11 11
12 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 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; 13 +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_DATABASE_NOT_EXISTS;
14 14
15 /** 15 /**
16 - * UReport 内置数据源 16 + * UReport2 内置数据源
  17 + *
17 * @author 赤焰 18 * @author 赤焰
18 */ 19 */
19 @Slf4j 20 @Slf4j
@@ -41,8 +42,8 @@ public class UReportDataSource implements BuildinDatasource { @@ -41,8 +42,8 @@ public class UReportDataSource implements BuildinDatasource {
41 try { 42 try {
42 return dataSource.getConnection(); 43 return dataSource.getConnection();
43 } catch (SQLException e) { 44 } catch (SQLException e) {
44 - log.error("UReportDataSource获取连接失败!");  
45 - throw exception(REPORT_DATABASE_NOT_EXISTS); 45 + log.error("[getConnection][获取连接失败!]", e);
  46 + throw exception(UREPORT_DATABASE_NOT_EXISTS);
46 } 47 }
47 } 48 }
48 49
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java
@@ -3,11 +3,10 @@ package cn.iocoder.yudao.module.report.framework.ureport.core; @@ -3,11 +3,10 @@ package cn.iocoder.yudao.module.report.framework.ureport.core;
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.util.StrUtil; 4 import cn.hutool.core.util.StrUtil;
5 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; 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; 6 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
8 import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO; 7 import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO;
9 import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; 8 import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
10 -import cn.iocoder.yudao.module.report.framework.security.config.UReportProperties; 9 +import cn.iocoder.yudao.module.report.framework.ureport.config.UReportProperties;
11 import cn.iocoder.yudao.module.report.service.ureport.UReportDataService; 10 import cn.iocoder.yudao.module.report.service.ureport.UReportDataService;
12 import com.bstek.ureport.provider.report.ReportFile; 11 import com.bstek.ureport.provider.report.ReportFile;
13 import com.bstek.ureport.provider.report.ReportProvider; 12 import com.bstek.ureport.provider.report.ReportProvider;
@@ -22,11 +21,14 @@ import java.io.InputStream; @@ -22,11 +21,14 @@ import java.io.InputStream;
22 import java.util.Collections; 21 import java.util.Collections;
23 import java.util.List; 22 import java.util.List;
24 23
  24 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
  25 +
25 /** 26 /**
26 * 基于数据库的 {@link ReportProvider} 实现类 27 * 基于数据库的 {@link ReportProvider} 实现类
27 * 28 *
28 * @author 赤焰 29 * @author 赤焰
29 */ 30 */
  31 +// TODO @赤焰:这个 bean 的注解,交给 UReportConfiguration 搞
30 @Component 32 @Component
31 @Slf4j 33 @Slf4j
32 @Setter 34 @Setter
@@ -53,15 +55,16 @@ public class UReportDatabaseProvider implements ReportProvider { @@ -53,15 +55,16 @@ public class UReportDatabaseProvider implements ReportProvider {
53 @Override 55 @Override
54 public List<ReportFile> getReportFiles() { 56 public List<ReportFile> getReportFiles() {
55 List<UReportDataDO> list = uReportDataService.getReportDataList(); 57 List<UReportDataDO> list = uReportDataService.getReportDataList();
  58 + // TODO @赤焰:这里,不用判空,CollectionUtils.convertList 已经处理了哈。
56 if(CollUtil.isEmpty(list)) { 59 if(CollUtil.isEmpty(list)) {
57 return Collections.emptyList(); 60 return Collections.emptyList();
58 } 61 }
59 - return CollectionUtils.convertList(list, report -> new ReportFile(report.getName(), DateUtils.of(report.getUpdateTime())));  
60 - 62 + return convertList(list, report -> new ReportFile(report.getName(), DateUtils.of(report.getUpdateTime())));
61 } 63 }
62 64
63 @Override 65 @Override
64 public void saveReport(String name, String content) { 66 public void saveReport(String name, String content) {
  67 + // TODO @赤焰:收到 uReportDataService 里面实现一个 saveUReportData 方法,然后这里调用即可。
65 name = getCorrectName(name); 68 name = getCorrectName(name);
66 UReportDataDO uReportDataDO = uReportDataService.selectOneByName(name); 69 UReportDataDO uReportDataDO = uReportDataService.selectOneByName(name);
67 UReportDataSaveReqVO saveReqVO = new UReportDataSaveReqVO(); 70 UReportDataSaveReqVO saveReqVO = new UReportDataSaveReqVO();
@@ -96,8 +99,9 @@ public class UReportDatabaseProvider implements ReportProvider { @@ -96,8 +99,9 @@ public class UReportDatabaseProvider implements ReportProvider {
96 99
97 /** 100 /**
98 * 去除存储媒介,获取报表名字 101 * 去除存储媒介,获取报表名字
  102 + *
99 * @param name 前端传入的报表带存储媒介的名字 103 * @param name 前端传入的报表带存储媒介的名字
100 - * @return 104 + * @return 表名字
101 */ 105 */
102 private String getCorrectName(String name) { 106 private String getCorrectName(String name) {
103 return StrUtil.removePrefix(name,getPrefix()); 107 return StrUtil.removePrefix(name,getPrefix());
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportFilter.java renamed to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportFilter.java
1 -package cn.iocoder.yudao.module.report.framework.security.config; 1 +package cn.iocoder.yudao.module.report.framework.ureport.core;
2 2
3 import cn.iocoder.yudao.framework.common.exception.ServiceException; 3 import cn.iocoder.yudao.framework.common.exception.ServiceException;
4 import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; 4 import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
@@ -8,7 +8,6 @@ import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; @@ -8,7 +8,6 @@ import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
8 import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; 8 import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
9 import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi; 9 import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
10 import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO; 10 import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
11 -import lombok.Data;  
12 import lombok.RequiredArgsConstructor; 11 import lombok.RequiredArgsConstructor;
13 import lombok.extern.slf4j.Slf4j; 12 import lombok.extern.slf4j.Slf4j;
14 import org.springframework.web.filter.OncePerRequestFilter; 13 import org.springframework.web.filter.OncePerRequestFilter;
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataService.java
@@ -9,14 +9,14 @@ import javax.validation.Valid; @@ -9,14 +9,14 @@ import javax.validation.Valid;
9 import java.util.List; 9 import java.util.List;
10 10
11 /** 11 /**
12 - * Ureport2报表 Service 接口 12 + * Ureport2 报表 Service 接口
13 * 13 *
14 * @author 芋道源码 14 * @author 芋道源码
15 */ 15 */
16 public interface UReportDataService { 16 public interface UReportDataService {
17 17
18 /** 18 /**
19 - * 创建Ureport2报表 19 + * 创建 Ureport2 报表
20 * 20 *
21 * @param createReqVO 创建信息 21 * @param createReqVO 创建信息
22 * @return 编号 22 * @return 编号
@@ -24,58 +24,65 @@ public interface UReportDataService { @@ -24,58 +24,65 @@ public interface UReportDataService {
24 Long createUReportData(@Valid UReportDataSaveReqVO createReqVO); 24 Long createUReportData(@Valid UReportDataSaveReqVO createReqVO);
25 25
26 /** 26 /**
27 - * 更新Ureport2报表 27 + * 更新 Ureport2 报表
28 * 28 *
29 * @param updateReqVO 更新信息 29 * @param updateReqVO 更新信息
30 */ 30 */
31 void updateUReportData(@Valid UReportDataSaveReqVO updateReqVO); 31 void updateUReportData(@Valid UReportDataSaveReqVO updateReqVO);
32 32
33 /** 33 /**
34 - * 删除Ureport2报表 34 + * 删除 Ureport2 报表
35 * 35 *
36 * @param id 编号 36 * @param id 编号
37 */ 37 */
38 void deleteUReportData(Long id); 38 void deleteUReportData(Long id);
39 39
40 /** 40 /**
41 - * 获得Ureport2报表 41 + * 获得 Ureport2 报表
42 * 42 *
43 * @param id 编号 43 * @param id 编号
44 - * @return Ureport2报表 44 + * @return Ureport2 报表
45 */ 45 */
46 UReportDataDO getUReportData(Long id); 46 UReportDataDO getUReportData(Long id);
47 47
48 /** 48 /**
49 - * 获得Ureport2报表分页 49 + * 获得 Ureport2 报表分页
50 * 50 *
51 * @param pageReqVO 分页查询 51 * @param pageReqVO 分页查询
52 - * @return Ureport2报表分页 52 + * @return Ureport2 报表分页
53 */ 53 */
54 PageResult<UReportDataDO> getUReportDataPage(UReportDataPageReqVO pageReqVO); 54 PageResult<UReportDataDO> getUReportDataPage(UReportDataPageReqVO pageReqVO);
55 55
  56 + // TODO @赤焰:可以不用返回 int。如果不需要哈。
56 /** 57 /**
57 * 根据名称删除报表 58 * 根据名称删除报表
58 - * @param name 59 + *
  60 + * @param name 报表名称
59 * @return 61 * @return
60 */ 62 */
61 int deleteByName(String name); 63 int deleteByName(String name);
62 64
  65 + // TODO @赤焰:这里直接返回 UReportDataDO 是不是更好?上层业务直接使用啦
63 /** 66 /**
64 * 根据名称校验报表是否存在 67 * 根据名称校验报表是否存在
65 - * @param name 68 + *
  69 + * @param name 报表名称
66 */ 70 */
67 void validateUReportDataExists(String name); 71 void validateUReportDataExists(String name);
68 72
  73 + // TODO @赤焰:这里方法名改成 getUReportDataByName。select 只用于 mapper;
69 /** 74 /**
70 * 根据名称查询报表 75 * 根据名称查询报表
71 - * @param name  
72 - * @return 76 + *
  77 + * @param name 报表名称
  78 + * @return Ureport2 报表
73 */ 79 */
74 UReportDataDO selectOneByName(String name); 80 UReportDataDO selectOneByName(String name);
75 81
76 /** 82 /**
77 * 获取全部报表 83 * 获取全部报表
78 - * @return 84 + *
  85 + * @return 全部报表
79 */ 86 */
80 List<UReportDataDO> getReportDataList(); 87 List<UReportDataDO> getReportDataList();
81 88
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java
1 package cn.iocoder.yudao.module.report.service.ureport; 1 package cn.iocoder.yudao.module.report.service.ureport;
2 2
3 -import org.springframework.stereotype.Service;  
4 -import javax.annotation.Resource;  
5 -import org.springframework.validation.annotation.Validated;  
6 -  
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; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
10 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
11 - 5 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO;
  6 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO;
  7 +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
12 import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper; 8 import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper;
  9 +import org.springframework.stereotype.Service;
  10 +import org.springframework.validation.annotation.Validated;
13 11
  12 +import javax.annotation.Resource;
14 import java.util.List; 13 import java.util.List;
15 14
16 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 15 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
17 -import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*; 16 +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_DATA_NOT_EXISTS;
18 17
19 /** 18 /**
20 * Ureport2报表 Service 实现类 19 * Ureport2报表 Service 实现类
@@ -30,10 +29,9 @@ public class UReportDataServiceImpl implements UReportDataService { @@ -30,10 +29,9 @@ public class UReportDataServiceImpl implements UReportDataService {
30 29
31 @Override 30 @Override
32 public Long createUReportData(UReportDataSaveReqVO createReqVO) { 31 public Long createUReportData(UReportDataSaveReqVO createReqVO) {
33 - // 插入 32 + // TODO @赤焰:名字不要重复的校验,要加下
34 UReportDataDO uReportData = BeanUtils.toBean(createReqVO, UReportDataDO.class); 33 UReportDataDO uReportData = BeanUtils.toBean(createReqVO, UReportDataDO.class);
35 uReportDataMapper.insert(uReportData); 34 uReportDataMapper.insert(uReportData);
36 - // 返回  
37 return uReportData.getId(); 35 return uReportData.getId();
38 } 36 }
39 37
@@ -41,6 +39,7 @@ public class UReportDataServiceImpl implements UReportDataService { @@ -41,6 +39,7 @@ public class UReportDataServiceImpl implements UReportDataService {
41 public void updateUReportData(UReportDataSaveReqVO updateReqVO) { 39 public void updateUReportData(UReportDataSaveReqVO updateReqVO) {
42 // 校验存在 40 // 校验存在
43 validateUReportDataExists(updateReqVO.getId()); 41 validateUReportDataExists(updateReqVO.getId());
  42 + // TODO @赤焰:名字不要重复的校验,要加下
44 // 更新 43 // 更新
45 UReportDataDO updateObj = BeanUtils.toBean(updateReqVO, UReportDataDO.class); 44 UReportDataDO updateObj = BeanUtils.toBean(updateReqVO, UReportDataDO.class);
46 uReportDataMapper.updateById(updateObj); 45 uReportDataMapper.updateById(updateObj);
@@ -56,14 +55,14 @@ public class UReportDataServiceImpl implements UReportDataService { @@ -56,14 +55,14 @@ public class UReportDataServiceImpl implements UReportDataService {
56 55
57 private void validateUReportDataExists(Long id) { 56 private void validateUReportDataExists(Long id) {
58 if (uReportDataMapper.selectById(id) == null) { 57 if (uReportDataMapper.selectById(id) == null) {
59 - throw exception(REPORT_DATA_NOT_EXISTS); 58 + throw exception(UREPORT_DATA_NOT_EXISTS);
60 } 59 }
61 } 60 }
62 61
63 @Override 62 @Override
64 public void validateUReportDataExists(String name) { 63 public void validateUReportDataExists(String name) {
65 - if (uReportDataMapper.selectByName(name) == null) {  
66 - throw exception(REPORT_DATA_NOT_EXISTS); 64 + if (uReportDataMapper.selectListByName(name) == null) {
  65 + throw exception(UREPORT_DATA_NOT_EXISTS);
67 } 66 }
68 } 67 }
69 68
@@ -84,11 +83,12 @@ public class UReportDataServiceImpl implements UReportDataService { @@ -84,11 +83,12 @@ public class UReportDataServiceImpl implements UReportDataService {
84 83
85 @Override 84 @Override
86 public UReportDataDO selectOneByName(String name) { 85 public UReportDataDO selectOneByName(String name) {
87 - return uReportDataMapper.selectOneByName(name); 86 + return uReportDataMapper.selectByName(name);
88 } 87 }
89 88
90 @Override 89 @Override
91 public List<UReportDataDO> getReportDataList() { 90 public List<UReportDataDO> getReportDataList() {
92 return uReportDataMapper.selectList(); 91 return uReportDataMapper.selectList();
93 } 92 }
  93 +
94 } 94 }
yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml deleted
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>  
13 \ No newline at end of file 0 \ No newline at end of file
yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java
1 package cn.iocoder.yudao.module.report.service.ureport; 1 package cn.iocoder.yudao.module.report.service.ureport;
2 2
3 -import org.junit.jupiter.api.Disabled;  
4 -import org.junit.jupiter.api.Test;  
5 -  
6 -import javax.annotation.Resource;  
7 - 3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
8 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; 4 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
9 -  
10 -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; 5 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO;
  6 +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO;
11 import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; 7 import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
12 import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper; 8 import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper;
13 -import cn.iocoder.yudao.framework.common.pojo.PageResult;  
14 - 9 +import org.junit.jupiter.api.Disabled;
  10 +import org.junit.jupiter.api.Test;
15 import org.springframework.context.annotation.Import; 11 import org.springframework.context.annotation.Import;
16 12
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.*; 13 +import javax.annotation.Resource;
  14 +
  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_DATA_NOT_EXISTS;
22 import static org.junit.jupiter.api.Assertions.*; 22 import static org.junit.jupiter.api.Assertions.*;
23 23
  24 +// TODO 芋艿:最后搞单测
24 /** 25 /**
25 * {@link UReportDataServiceImpl} 的单元测试类 26 * {@link UReportDataServiceImpl} 的单元测试类
26 * 27 *
@@ -72,7 +73,7 @@ public class UReportDataServiceImplTest extends BaseDbUnitTest { @@ -72,7 +73,7 @@ public class UReportDataServiceImplTest extends BaseDbUnitTest {
72 UReportDataSaveReqVO updateReqVO = randomPojo(UReportDataSaveReqVO.class); 73 UReportDataSaveReqVO updateReqVO = randomPojo(UReportDataSaveReqVO.class);
73 74
74 // 调用, 并断言异常 75 // 调用, 并断言异常
75 - assertServiceException(() -> uReportDataService.updateUReportData(updateReqVO), REPORT_DATA_NOT_EXISTS); 76 + assertServiceException(() -> uReportDataService.updateUReportData(updateReqVO), UREPORT_DATA_NOT_EXISTS);
76 } 77 }
77 78
78 @Test 79 @Test
@@ -95,7 +96,7 @@ public class UReportDataServiceImplTest extends BaseDbUnitTest { @@ -95,7 +96,7 @@ public class UReportDataServiceImplTest extends BaseDbUnitTest {
95 Long id = randomLongId(); 96 Long id = randomLongId();
96 97
97 // 调用, 并断言异常 98 // 调用, 并断言异常
98 - assertServiceException(() -> uReportDataService.deleteUReportData(id), REPORT_DATA_NOT_EXISTS); 99 + assertServiceException(() -> uReportDataService.deleteUReportData(id), UREPORT_DATA_NOT_EXISTS);
99 } 100 }
100 101
101 @Test 102 @Test
yudao-server/pom.xml
@@ -44,11 +44,11 @@ @@ -44,11 +44,11 @@
44 <!-- </dependency>--> 44 <!-- </dependency>-->
45 45
46 <!-- 数据报表。默认注释,保证编译速度 --> 46 <!-- 数据报表。默认注释,保证编译速度 -->
47 -<!-- <dependency>-->  
48 -<!-- <groupId>cn.iocoder.boot</groupId>-->  
49 -<!-- <artifactId>yudao-module-report-biz</artifactId>-->  
50 -<!-- <version>${revision}</version>-->  
51 -<!-- </dependency>--> 47 + <dependency>
  48 + <groupId>cn.iocoder.boot</groupId>
  49 + <artifactId>yudao-module-report-biz</artifactId>
  50 + <version>${revision}</version>
  51 + </dependency>
52 <!-- 工作流。默认注释,保证编译速度 --> 52 <!-- 工作流。默认注释,保证编译速度 -->
53 <!-- <dependency>--> 53 <!-- <dependency>-->
54 <!-- <groupId>cn.iocoder.boot</groupId>--> 54 <!-- <groupId>cn.iocoder.boot</groupId>-->