Browse Source

📈 REPORT:code review ureport2 实现

YunaiV 1 year ago
parent
commit
9d10c74599
18 changed files with 134 additions and 142 deletions
  1. 1 1
      pom.xml
  2. 2 2
      yudao-module-report/yudao-module-report-api/src/main/java/cn/iocoder/yudao/module/report/enums/ErrorCodeConstants.java
  3. 25 27
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UReportDataController.java
  4. 6 4
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataPageReqVO.java
  5. 1 1
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataRespVO.java
  6. 8 5
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UReportDataSaveReqVO.java
  7. 3 2
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UReportDataDO.java
  8. 7 23
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UReportDataMapper.java
  9. 1 2
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportConfiguration.java
  10. 8 3
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportProperties.java
  11. 6 5
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDataSource.java
  12. 9 5
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportDatabaseProvider.java
  13. 1 2
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/core/UReportFilter.java
  14. 20 13
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataService.java
  15. 14 14
      yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImpl.java
  16. 0 12
      yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml
  17. 17 16
      yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UReportDataServiceImplTest.java
  18. 5 5
      yudao-server/pom.xml

+ 1 - 1
pom.xml

@@ -17,7 +17,7 @@
         <module>yudao-module-infra</module>
 <!--        <module>yudao-module-member</module>-->
 <!--        <module>yudao-module-bpm</module>-->
-<!--        <module>yudao-module-report</module>-->
+        <module>yudao-module-report</module>
 <!--        <module>yudao-module-mp</module>-->
 <!--        <module>yudao-module-pay</module>-->
 <!--        <module>yudao-module-mall</module>-->

+ 2 - 2
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报表数据源不存在");
 }

+ 25 - 27
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.*;
+
+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报表")
+@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<Long> 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<Boolean> 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<Boolean> 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<UReportDataDO> 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));
     }
 

+ 6 - 4
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)

+ 1 - 1
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 {

+ 8 - 5
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 = "文件内容")

+ 3 - 2
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;
     /**

+ 7 - 23
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<UReportDataDO> {
                 .orderByDesc(UReportDataDO::getId));
     }
 
-    /**
-     * 根据名字查询报表
-     * @param name 报表名字
-     * @return
-     */
-    default List<UReportDataDO> selectByName(String name){
+    default List<UReportDataDO> selectListByName(String name) {
         return selectList(new LambdaQueryWrapperX<UReportDataDO>()
                 .eqIfPresent(UReportDataDO::getName,name));
     }
 
-    /**
-     * 根据名字查询报表
-     * @param name 报表名字
-     * @return
-     */
-    default UReportDataDO selectOneByName(String name){
+    default UReportDataDO selectByName(String name){
         return selectOne(new LambdaQueryWrapperX<UReportDataDO>()
                 .eqIfPresent(UReportDataDO::getName,name));
     }
 
-
-    /**
-     * 根据名字删除报表
-     * @param name 报表名字
-     * @return
-     */
-    default int deleteByName(String name){
+    default int deleteByName(String name) {
         return delete(new LambdaQueryWrapperX<UReportDataDO>()
                 .eqIfPresent(UReportDataDO::getName,name));
     }

+ 1 - 2
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 {
 

+ 8 - 3
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportProperties.java → 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;
+
 }

+ 6 - 5
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UReportDataSource.java → 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);
 		}
 	}
 

+ 9 - 5
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<ReportFile> getReportFiles() {
         List<UReportDataDO> 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());

+ 1 - 2
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/UReportFilter.java → 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;

+ 20 - 13
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<UReportDataDO> 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<UReportDataDO> getReportDataList();
 

+ 14 - 14
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<UReportDataDO> getReportDataList() {
         return uReportDataMapper.selectList();
     }
+
 }

+ 0 - 12
yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UReportDataMapper.xml

@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper">
-
-    <!--
-        一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
-        无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
-        代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
-        文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-     -->
-
-</mapper>

+ 17 - 16
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 org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-
-import javax.annotation.Resource;
-
+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.*;
+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 cn.iocoder.yudao.framework.common.pojo.PageResult;
-
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 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 javax.annotation.Resource;
+
+import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
+import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
+import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
+import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
+import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
+import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
+import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_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

+ 5 - 5
yudao-server/pom.xml

@@ -44,11 +44,11 @@
 <!--        </dependency>-->
 
         <!-- 数据报表。默认注释,保证编译速度 -->
-<!--        <dependency>-->
-<!--            <groupId>cn.iocoder.boot</groupId>-->
-<!--            <artifactId>yudao-module-report-biz</artifactId>-->
-<!--            <version>${revision}</version>-->
-<!--        </dependency>-->
+        <dependency>
+            <groupId>cn.iocoder.boot</groupId>
+            <artifactId>yudao-module-report-biz</artifactId>
+            <version>${revision}</version>
+        </dependency>
         <!-- 工作流。默认注释,保证编译速度 -->
 <!--        <dependency>-->
 <!--            <groupId>cn.iocoder.boot</groupId>-->