From 076bf136876c004e99a2e0bb5aa3e0933786edf8 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 6 Dec 2023 21:00:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=88=20REPORT=EF=BC=9Acode=20review=20u?= =?UTF-8?q?report2=20=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../report/enums/ErrorCodeConstants.java | 4 +- .../admin/ureport/UReportDataController.java | 52 +++++++++---------- .../ureport/vo/UReportDataPageReqVO.java | 10 ++-- .../admin/ureport/vo/UReportDataRespVO.java | 2 +- .../ureport/vo/UReportDataSaveReqVO.java | 13 +++-- .../dal/dataobject/ureport/UReportDataDO.java | 5 +- .../dal/mysql/ureport/UReportDataMapper.java | 30 +++-------- .../ureport/config/UReportConfiguration.java | 3 +- .../config/UReportProperties.java | 11 ++-- .../{config => core}/UReportDataSource.java | 11 ++-- .../ureport/core/UReportDatabaseProvider.java | 14 +++-- .../core}/UReportFilter.java | 3 +- .../service/ureport/UReportDataService.java | 33 +++++++----- .../ureport/UReportDataServiceImpl.java | 28 +++++----- .../mapper/ureport/UReportDataMapper.xml | 12 ----- .../ureport/UReportDataServiceImplTest.java | 33 ++++++------ yudao-server/pom.xml | 10 ++-- 18 files changed, 134 insertions(+), 142 deletions(-) rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/{security => ureport}/config/UReportProperties.java (63%) rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/{config => core}/UReportDataSource.java (79%) rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/{security/config => ureport/core}/UReportFilter.java (97%) delete mode 100644 yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml diff --git a/pom.xml b/pom.xml index 8ce3a9144..81468c173 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ yudao-module-infra - + yudao-module-report diff --git a/yudao-module-report/yudao-module-report-api/src/main/java/cn/iocoder/yudao/module/report/enums/ErrorCodeConstants.java b/yudao-module-report/yudao-module-report-api/src/main/java/cn/iocoder/yudao/module/report/enums/ErrorCodeConstants.java index 206ceec63..c0992f44d 100644 --- a/yudao-module-report/yudao-module-report-api/src/main/java/cn/iocoder/yudao/module/report/enums/ErrorCodeConstants.java +++ b/yudao-module-report/yudao-module-report-api/src/main/java/cn/iocoder/yudao/module/report/enums/ErrorCodeConstants.java @@ -13,7 +13,7 @@ public interface ErrorCodeConstants { ErrorCode GO_VIEW_PROJECT_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在"); // ========== UREPORT 模块 1-003-001-000 ========== - ErrorCode REPORT_DATA_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2报表不存在"); + ErrorCode UREPORT_DATA_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2 报表不存在"); + ErrorCode UREPORT_DATABASE_NOT_EXISTS = new ErrorCode(1_003_001_002, "Ureport2 报表数据源不存在"); - ErrorCode REPORT_DATABASE_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2报表数据源不存在"); } diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UReportDataController.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UReportDataController.java index e6c0036f6..bc5d12579 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UReportDataController.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UReportDataController.java @@ -1,35 +1,33 @@ package cn.iocoder.yudao.module.report.controller.admin.ureport; -import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Operation; - -import javax.validation.constraints.*; -import javax.validation.*; -import javax.servlet.http.*; -import java.util.*; -import java.io.IOException; - +import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; - import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; - -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO; +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataRespVO; +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO; import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; import cn.iocoder.yudao.module.report.service.ureport.UReportDataService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; -@Tag(name = "管理后台 - Ureport2报表") +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; + +@Tag(name = "管理后台 - Ureport2 报表") @RestController @RequestMapping("/report/ureport-data") @Validated @@ -39,14 +37,14 @@ public class UReportDataController { private UReportDataService uReportDataService; @PostMapping("/create") - @Operation(summary = "创建Ureport2报表") + @Operation(summary = "创建 Ureport2 报表") @PreAuthorize("@ss.hasPermission('report:ureport-data:create')") public CommonResult createUReportData(@Valid @RequestBody UReportDataSaveReqVO createReqVO) { return success(uReportDataService.createUReportData(createReqVO)); } @PutMapping("/update") - @Operation(summary = "更新Ureport2报表") + @Operation(summary = "更新 Ureport2 报表") @PreAuthorize("@ss.hasPermission('report:ureport-data:update')") public CommonResult updateUReportData(@Valid @RequestBody UReportDataSaveReqVO updateReqVO) { uReportDataService.updateUReportData(updateReqVO); @@ -54,7 +52,7 @@ public class UReportDataController { } @DeleteMapping("/delete") - @Operation(summary = "删除Ureport2报表") + @Operation(summary = "删除 Ureport2 报表") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('report:ureport-data:delete')") public CommonResult deleteUReportData(@RequestParam("id") Long id) { @@ -80,7 +78,7 @@ public class UReportDataController { } @GetMapping("/export-excel") - @Operation(summary = "导出Ureport2报表 Excel") + @Operation(summary = "导出 Ureport2 报表 Excel") @PreAuthorize("@ss.hasPermission('report:ureport-data:export')") @OperateLog(type = EXPORT) public void exportUReportDataExcel(@Valid UReportDataPageReqVO pageReqVO, @@ -88,7 +86,7 @@ public class UReportDataController { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = uReportDataService.getUReportDataPage(pageReqVO).getList(); // 导出 Excel - ExcelUtils.write(response, "Ureport2报表.xls", "数据", UReportDataRespVO.class, + ExcelUtils.write(response, "Ureport2 报表.xls", "数据", UReportDataRespVO.class, BeanUtils.toBean(list, UReportDataRespVO.class)); } diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataPageReqVO.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataPageReqVO.java index a31b8c5b3..d3c1a5719 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataPageReqVO.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataPageReqVO.java @@ -1,15 +1,17 @@ package cn.iocoder.yudao.module.report.controller.admin.ureport.vo; -import lombok.*; -import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import org.springframework.format.annotation.DateTimeFormat; + import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; -@Schema(description = "管理后台 - Ureport2报表分页 Request VO") +@Schema(description = "管理后台 - Ureport2 报表分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataRespVO.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataRespVO.java index cea23829a..f0b3ab1d1 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataRespVO.java +++ b/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; import java.time.LocalDateTime; -@Schema(description = "管理后台 - Ureport2报表 Response VO") +@Schema(description = "管理后台 - Ureport2 报表 Response VO") @Data @ExcelIgnoreUnannotated public class UReportDataRespVO { diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataSaveReqVO.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataSaveReqVO.java index 206796871..d8af857c5 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataSaveReqVO.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataSaveReqVO.java @@ -1,12 +1,14 @@ package cn.iocoder.yudao.module.report.controller.admin.ureport.vo; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.util.*; -import javax.validation.constraints.*; -import java.util.*; +import lombok.Data; -@Schema(description = "管理后台 - Ureport2报表新增/修改 Request VO") +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - Ureport2 报表新增/修改 Request VO") @Data public class UReportDataSaveReqVO { @@ -19,6 +21,7 @@ public class UReportDataSaveReqVO { @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "状态不能为空") + @InEnum(CommonStatusEnum.class) private Integer status; @Schema(description = "文件内容") diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UReportDataDO.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UReportDataDO.java index 55bb2e2a7..6aab35a08 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UReportDataDO.java +++ b/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; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; +// TODO @赤焰:这个是不是可以支持多租户? /** - * Ureport2报表 DO + * Ureport2 报表 DO * * @author 芋道源码 */ @@ -34,7 +35,7 @@ public class UReportDataDO extends BaseDO { /** * 状态 * - * 枚举 {@link CommonStatusEnum#getStatus()} + * 枚举 {@link CommonStatusEnum#getStatus()} */ private Integer status; /** diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java index a91f8f141..c64b771fa 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java @@ -1,13 +1,13 @@ package cn.iocoder.yudao.module.report.dal.mysql.ureport; -import java.util.*; - import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO; import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; import org.apache.ibatis.annotations.Mapper; -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; + +import java.util.List; /** * Ureport2报表 Mapper @@ -26,33 +26,17 @@ public interface UReportDataMapper extends BaseMapperX { .orderByDesc(UReportDataDO::getId)); } - /** - * 根据名字查询报表 - * @param name 报表名字 - * @return - */ - default List selectByName(String name){ + default List selectListByName(String name) { return selectList(new LambdaQueryWrapperX() .eqIfPresent(UReportDataDO::getName,name)); } - /** - * 根据名字查询报表 - * @param name 报表名字 - * @return - */ - default UReportDataDO selectOneByName(String name){ + default UReportDataDO selectByName(String name){ return selectOne(new LambdaQueryWrapperX() .eqIfPresent(UReportDataDO::getName,name)); } - - /** - * 根据名字删除报表 - * @param name 报表名字 - * @return - */ - default int deleteByName(String name){ + default int deleteByName(String name) { return delete(new LambdaQueryWrapperX() .eqIfPresent(UReportDataDO::getName,name)); } diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportConfiguration.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportConfiguration.java index 25c4b3a00..915c45ecd 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportConfiguration.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportConfiguration.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.report.framework.ureport.config; -import cn.iocoder.yudao.module.report.framework.security.config.UReportProperties; import com.bstek.ureport.console.UReportServlet; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.ServletRegistrationBean; @@ -18,7 +17,7 @@ import javax.servlet.Servlet; */ @Configuration @ImportResource({"classpath:ureport-console-context.xml"}) -@PropertySource(value = {"classpath:ureport.properties"}) +@PropertySource(value = {"classpath:ureport.properties"}) // TODO @赤焰:这个可以搞到 application.yaml 里么? @EnableConfigurationProperties({UReportProperties.class}) public class UReportConfiguration { diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportProperties.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportProperties.java similarity index 63% rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportProperties.java rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportProperties.java index 5bf5e20e4..b3d41cd2f 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportProperties.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportProperties.java @@ -1,17 +1,22 @@ -package cn.iocoder.yudao.module.report.framework.security.config; +package cn.iocoder.yudao.module.report.framework.ureport.config; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; /** - * UReport配置类 + * UReport2 配置类 * * @author 赤焰 */ @Data @ConfigurationProperties(prefix = "ureport.provider.database") public class UReportProperties { + + // TODO @赤焰:每个字段的注释写下哈; private String name = "数据库文件系统"; - private String prefix = "db-"; + + private String prefix = "db-"; + private boolean disabled = false; + } diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportDataSource.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDataSource.java similarity index 79% rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportDataSource.java rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDataSource.java index 46e9e9e93..233ed12b9 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportDataSource.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDataSource.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.report.framework.ureport.config; +package cn.iocoder.yudao.module.report.framework.ureport.core; import com.bstek.ureport.definition.datasource.BuildinDatasource; import lombok.extern.slf4j.Slf4j; @@ -10,10 +10,11 @@ import java.sql.Connection; import java.sql.SQLException; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.REPORT_DATABASE_NOT_EXISTS; +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_DATABASE_NOT_EXISTS; /** - * UReport 内置数据源 + * UReport2 内置数据源 + * * @author 赤焰 */ @Slf4j @@ -41,8 +42,8 @@ public class UReportDataSource implements BuildinDatasource { try { return dataSource.getConnection(); } catch (SQLException e) { - log.error("UReportDataSource获取连接失败!"); - throw exception(REPORT_DATABASE_NOT_EXISTS); + log.error("[getConnection][获取连接失败!]", e); + throw exception(UREPORT_DATABASE_NOT_EXISTS); } } diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java index d06e9da54..056699036 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java @@ -3,11 +3,10 @@ package cn.iocoder.yudao.module.report.framework.ureport.core; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO; import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; -import cn.iocoder.yudao.module.report.framework.security.config.UReportProperties; +import cn.iocoder.yudao.module.report.framework.ureport.config.UReportProperties; import cn.iocoder.yudao.module.report.service.ureport.UReportDataService; import com.bstek.ureport.provider.report.ReportFile; import com.bstek.ureport.provider.report.ReportProvider; @@ -22,11 +21,14 @@ import java.io.InputStream; import java.util.Collections; import java.util.List; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; + /** * 基于数据库的 {@link ReportProvider} 实现类 * * @author 赤焰 */ +// TODO @赤焰:这个 bean 的注解,交给 UReportConfiguration 搞 @Component @Slf4j @Setter @@ -53,15 +55,16 @@ public class UReportDatabaseProvider implements ReportProvider { @Override public List getReportFiles() { List list = uReportDataService.getReportDataList(); + // TODO @赤焰:这里,不用判空,CollectionUtils.convertList 已经处理了哈。 if(CollUtil.isEmpty(list)) { return Collections.emptyList(); } - return CollectionUtils.convertList(list, report -> new ReportFile(report.getName(), DateUtils.of(report.getUpdateTime()))); - + return convertList(list, report -> new ReportFile(report.getName(), DateUtils.of(report.getUpdateTime()))); } @Override public void saveReport(String name, String content) { + // TODO @赤焰:收到 uReportDataService 里面实现一个 saveUReportData 方法,然后这里调用即可。 name = getCorrectName(name); UReportDataDO uReportDataDO = uReportDataService.selectOneByName(name); UReportDataSaveReqVO saveReqVO = new UReportDataSaveReqVO(); @@ -96,8 +99,9 @@ public class UReportDatabaseProvider implements ReportProvider { /** * 去除存储媒介,获取报表名字 + * * @param name 前端传入的报表带存储媒介的名字 - * @return + * @return 表名字 */ private String getCorrectName(String name) { return StrUtil.removePrefix(name,getPrefix()); diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportFilter.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportFilter.java similarity index 97% rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportFilter.java rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportFilter.java index 5ff22d6f4..39c757bfe 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportFilter.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportFilter.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.report.framework.security.config; +package cn.iocoder.yudao.module.report.framework.ureport.core; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; @@ -8,7 +8,6 @@ import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi; import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO; -import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.filter.OncePerRequestFilter; diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataService.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataService.java index fcefb583d..87a8dca73 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataService.java +++ b/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; import java.util.List; /** - * Ureport2报表 Service 接口 + * Ureport2 报表 Service 接口 * * @author 芋道源码 */ public interface UReportDataService { /** - * 创建Ureport2报表 + * 创建 Ureport2 报表 * * @param createReqVO 创建信息 * @return 编号 @@ -24,58 +24,65 @@ public interface UReportDataService { Long createUReportData(@Valid UReportDataSaveReqVO createReqVO); /** - * 更新Ureport2报表 + * 更新 Ureport2 报表 * * @param updateReqVO 更新信息 */ void updateUReportData(@Valid UReportDataSaveReqVO updateReqVO); /** - * 删除Ureport2报表 + * 删除 Ureport2 报表 * * @param id 编号 */ void deleteUReportData(Long id); /** - * 获得Ureport2报表 + * 获得 Ureport2 报表 * * @param id 编号 - * @return Ureport2报表 + * @return Ureport2 报表 */ UReportDataDO getUReportData(Long id); /** - * 获得Ureport2报表分页 + * 获得 Ureport2 报表分页 * * @param pageReqVO 分页查询 - * @return Ureport2报表分页 + * @return Ureport2 报表分页 */ PageResult getUReportDataPage(UReportDataPageReqVO pageReqVO); + // TODO @赤焰:可以不用返回 int。如果不需要哈。 /** * 根据名称删除报表 - * @param name + * + * @param name 报表名称 * @return */ int deleteByName(String name); + // TODO @赤焰:这里直接返回 UReportDataDO 是不是更好?上层业务直接使用啦 /** * 根据名称校验报表是否存在 - * @param name + * + * @param name 报表名称 */ void validateUReportDataExists(String name); + // TODO @赤焰:这里方法名改成 getUReportDataByName。select 只用于 mapper; /** * 根据名称查询报表 - * @param name - * @return + * + * @param name 报表名称 + * @return Ureport2 报表 */ UReportDataDO selectOneByName(String name); /** * 获取全部报表 - * @return + * + * @return 全部报表 */ List getReportDataList(); diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java index c99ce7cf3..a01551b40 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java @@ -1,20 +1,19 @@ package cn.iocoder.yudao.module.report.service.ureport; -import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; - -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; -import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; - +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO; +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO; +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import javax.annotation.Resource; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_DATA_NOT_EXISTS; /** * Ureport2报表 Service 实现类 @@ -30,10 +29,9 @@ public class UReportDataServiceImpl implements UReportDataService { @Override public Long createUReportData(UReportDataSaveReqVO createReqVO) { - // 插入 + // TODO @赤焰:名字不要重复的校验,要加下 UReportDataDO uReportData = BeanUtils.toBean(createReqVO, UReportDataDO.class); uReportDataMapper.insert(uReportData); - // 返回 return uReportData.getId(); } @@ -41,6 +39,7 @@ public class UReportDataServiceImpl implements UReportDataService { public void updateUReportData(UReportDataSaveReqVO updateReqVO) { // 校验存在 validateUReportDataExists(updateReqVO.getId()); + // TODO @赤焰:名字不要重复的校验,要加下 // 更新 UReportDataDO updateObj = BeanUtils.toBean(updateReqVO, UReportDataDO.class); uReportDataMapper.updateById(updateObj); @@ -56,14 +55,14 @@ public class UReportDataServiceImpl implements UReportDataService { private void validateUReportDataExists(Long id) { if (uReportDataMapper.selectById(id) == null) { - throw exception(REPORT_DATA_NOT_EXISTS); + throw exception(UREPORT_DATA_NOT_EXISTS); } } @Override public void validateUReportDataExists(String name) { - if (uReportDataMapper.selectByName(name) == null) { - throw exception(REPORT_DATA_NOT_EXISTS); + if (uReportDataMapper.selectListByName(name) == null) { + throw exception(UREPORT_DATA_NOT_EXISTS); } } @@ -84,11 +83,12 @@ public class UReportDataServiceImpl implements UReportDataService { @Override public UReportDataDO selectOneByName(String name) { - return uReportDataMapper.selectOneByName(name); + return uReportDataMapper.selectByName(name); } @Override public List getReportDataList() { return uReportDataMapper.selectList(); } + } diff --git a/yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml b/yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml deleted file mode 100644 index 8b545b3c5..000000000 --- a/yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java b/yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java index b6fc8a657..0d972d454 100644 --- a/yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java +++ b/yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java @@ -1,26 +1,27 @@ package cn.iocoder.yudao.module.report.service.ureport; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO; +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO; +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; +import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; - -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; -import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO; -import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import org.springframework.context.annotation.Import; - -import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_DATA_NOT_EXISTS; import static org.junit.jupiter.api.Assertions.*; +// TODO 芋艿:最后搞单测 /** * {@link UReportDataServiceImpl} 的单元测试类 * @@ -72,7 +73,7 @@ public class UReportDataServiceImplTest extends BaseDbUnitTest { UReportDataSaveReqVO updateReqVO = randomPojo(UReportDataSaveReqVO.class); // 调用, 并断言异常 - assertServiceException(() -> uReportDataService.updateUReportData(updateReqVO), REPORT_DATA_NOT_EXISTS); + assertServiceException(() -> uReportDataService.updateUReportData(updateReqVO), UREPORT_DATA_NOT_EXISTS); } @Test @@ -95,7 +96,7 @@ public class UReportDataServiceImplTest extends BaseDbUnitTest { Long id = randomLongId(); // 调用, 并断言异常 - assertServiceException(() -> uReportDataService.deleteUReportData(id), REPORT_DATA_NOT_EXISTS); + assertServiceException(() -> uReportDataService.deleteUReportData(id), UREPORT_DATA_NOT_EXISTS); } @Test diff --git a/yudao-server/pom.xml b/yudao-server/pom.xml index 20b67725b..3db2d4bfa 100644 --- a/yudao-server/pom.xml +++ b/yudao-server/pom.xml @@ -44,11 +44,11 @@ - - - - - + + cn.iocoder.boot + yudao-module-report-biz + ${revision} +