Commit 8507fa9172d84bb1bf41c6a340255e4adcc2073e
Committed by
YunaiV
1 parent
5bf7cd39
【新增】ureport2 集成
Showing
23 changed files
with
982 additions
and
4 deletions
sql/mysql/Ureport.sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + 'Ureport2报表管理', '', 2, 0, 1281, | |
| 8 | + 'ureport-file', '', 'report/ureport/index', 0, 'UreportFile' | |
| 9 | + ); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + 'Ureport2报表查询', 'report:ureport-file:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | + ); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + 'Ureport2报表创建', 'report:ureport-file:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | + ); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + 'Ureport2报表更新', 'report:ureport-file:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | + ); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + 'Ureport2报表删除', 'report:ureport-file:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | + ); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + 'Ureport2报表导出', 'report:ureport-file:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | + ); | ... | ... |
yudao-dependencies/pom.xml
| ... | ... | @@ -74,6 +74,7 @@ |
| 74 | 74 | <jimureport.version>1.6.1</jimureport.version> |
| 75 | 75 | <xercesImpl.version>2.12.2</xercesImpl.version> |
| 76 | 76 | <weixin-java.version>4.5.7.B</weixin-java.version> |
| 77 | + <ureport2.version>2.2.9</ureport2.version> | |
| 77 | 78 | </properties> |
| 78 | 79 | |
| 79 | 80 | <dependencyManagement> |
| ... | ... | @@ -647,12 +648,14 @@ |
| 647 | 648 | <artifactId>xercesImpl</artifactId> |
| 648 | 649 | <version>${xercesImpl.version}</version> |
| 649 | 650 | </dependency> |
| 650 | - <!-- SpringBoot Websocket --> | |
| 651 | + | |
| 652 | + <!-- UReport2 报表--> | |
| 651 | 653 | <dependency> |
| 652 | - <groupId>org.springframework.boot</groupId> | |
| 653 | - <artifactId>spring-boot-starter-websocket</artifactId> | |
| 654 | - <version>${spring.boot.version}</version> | |
| 654 | + <groupId>com.bstek.ureport</groupId> | |
| 655 | + <artifactId>ureport2-console</artifactId> | |
| 656 | + <version>${ureport2.version}</version> | |
| 655 | 657 | </dependency> |
| 658 | + | |
| 656 | 659 | </dependencies> |
| 657 | 660 | </dependencyManagement> |
| 658 | 661 | ... | ... |
yudao-module-report/yudao-module-report-api/src/main/java/cn/iocoder/yudao/module/report/enums/ErrorCodeConstants.java
| ... | ... | @@ -12,4 +12,6 @@ public interface ErrorCodeConstants { |
| 12 | 12 | // ========== AUTH 模块 1-003-000-000 ========== |
| 13 | 13 | ErrorCode GO_VIEW_PROJECT_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在"); |
| 14 | 14 | |
| 15 | + ErrorCode UREPORT_FILE_NOT_EXISTS = new ErrorCode(1_003_001_000, "打印文件不存在,请检查Ureport报表文件"); | |
| 16 | + ErrorCode UREPORT_FILE_EXISTS = new ErrorCode(1_003_001_001, "报表名字已存在,请修改后再保存"); | |
| 15 | 17 | } | ... | ... |
yudao-module-report/yudao-module-report-biz/pom.xml
| ... | ... | @@ -74,5 +74,15 @@ |
| 74 | 74 | <artifactId>xercesImpl</artifactId> |
| 75 | 75 | </dependency> |
| 76 | 76 | |
| 77 | + <dependency> | |
| 78 | + <groupId>com.bstek.ureport</groupId> | |
| 79 | + <artifactId>ureport2-console</artifactId> | |
| 80 | + </dependency> | |
| 81 | + | |
| 82 | + <dependency> | |
| 83 | + <groupId>cn.iocoder.boot</groupId> | |
| 84 | + <artifactId>yudao-spring-boot-starter-excel</artifactId> | |
| 85 | + </dependency> | |
| 86 | + | |
| 77 | 87 | </dependencies> |
| 78 | 88 | </project> | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/UreportFileController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.controller.admin.ureport; | |
| 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 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 18 | +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; | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | + | |
| 25 | +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.*; | |
| 29 | +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | |
| 30 | +import cn.iocoder.yudao.module.report.service.ureport.UreportFileService; | |
| 31 | + | |
| 32 | +@Tag(name = "管理后台 - Ureport2报表") | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/report/ureport-file") | |
| 35 | +@Validated | |
| 36 | +public class UreportFileController { | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private UreportFileService ureportFileService; | |
| 40 | + | |
| 41 | + @PostMapping("/create") | |
| 42 | + @Operation(summary = "创建Ureport2报表") | |
| 43 | + @PreAuthorize("@ss.hasPermission('report:ureport-file:create')") | |
| 44 | + public CommonResult<Long> createUreportFile(@Valid @RequestBody UreportFileSaveReqVO createReqVO) { | |
| 45 | + return success(ureportFileService.createUreportFile(createReqVO)); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @PutMapping("/update") | |
| 49 | + @Operation(summary = "更新Ureport2报表") | |
| 50 | + @PreAuthorize("@ss.hasPermission('report:ureport-file:update')") | |
| 51 | + public CommonResult<Boolean> updateUreportFile(@Valid @RequestBody UreportFileSaveReqVO updateReqVO) { | |
| 52 | + ureportFileService.updateUreportFile(updateReqVO); | |
| 53 | + return success(true); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @DeleteMapping("/delete") | |
| 57 | + @Operation(summary = "删除Ureport2报表") | |
| 58 | + @Parameter(name = "id", description = "编号", required = true) | |
| 59 | + @PreAuthorize("@ss.hasPermission('report:ureport-file:delete')") | |
| 60 | + public CommonResult<Boolean> deleteUreportFile(@RequestParam("id") Long id) { | |
| 61 | + ureportFileService.deleteUreportFile(id); | |
| 62 | + return success(true); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @GetMapping("/get") | |
| 66 | + @Operation(summary = "获得Ureport2报表") | |
| 67 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 68 | + @PreAuthorize("@ss.hasPermission('report:ureport-file:query')") | |
| 69 | + public CommonResult<UreportFileRespVO> getUreportFile(@RequestParam("id") Long id) { | |
| 70 | + UreportFileDO ureportFile = ureportFileService.getUreportFile(id); | |
| 71 | + return success(BeanUtils.toBean(ureportFile, UreportFileRespVO.class)); | |
| 72 | + } | |
| 73 | + | |
| 74 | + @GetMapping("/page") | |
| 75 | + @Operation(summary = "获得Ureport2报表分页") | |
| 76 | + @PreAuthorize("@ss.hasPermission('report:ureport-file:query')") | |
| 77 | + public CommonResult<PageResult<UreportFileRespVO>> getUreportFilePage(@Valid UreportFilePageReqVO pageReqVO) { | |
| 78 | + PageResult<UreportFileDO> pageResult = ureportFileService.getUreportFilePage(pageReqVO); | |
| 79 | + return success(BeanUtils.toBean(pageResult, UreportFileRespVO.class)); | |
| 80 | + } | |
| 81 | + | |
| 82 | + @GetMapping("/export-excel") | |
| 83 | + @Operation(summary = "导出Ureport2报表 Excel") | |
| 84 | + @PreAuthorize("@ss.hasPermission('report:ureport-file:export')") | |
| 85 | + @OperateLog(type = EXPORT) | |
| 86 | + public void exportUreportFileExcel(@Valid UreportFilePageReqVO pageReqVO, | |
| 87 | + HttpServletResponse response) throws IOException { | |
| 88 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 89 | + List<UreportFileDO> list = ureportFileService.getUreportFilePage(pageReqVO).getList(); | |
| 90 | + // 导出 Excel | |
| 91 | + ExcelUtils.write(response, "Ureport2报表.xls", "数据", UreportFileRespVO.class, | |
| 92 | + BeanUtils.toBean(list, UreportFileRespVO.class)); | |
| 93 | + } | |
| 94 | + | |
| 95 | +} | |
| 0 | 96 | \ No newline at end of file | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFilePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.controller.admin.ureport.vo; | |
| 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; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - Ureport2报表分页 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class UreportFilePageReqVO extends PageParam { | |
| 17 | + | |
| 18 | + @Schema(description = "文件名称", example = "赵六") | |
| 19 | + private String fileName; | |
| 20 | + | |
| 21 | + @Schema(description = "状态", example = "1") | |
| 22 | + private Integer status; | |
| 23 | + | |
| 24 | + @Schema(description = "备注", example = "随便") | |
| 25 | + private String remark; | |
| 26 | + | |
| 27 | + @Schema(description = "创建时间") | |
| 28 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 29 | + private LocalDateTime[] createTime; | |
| 30 | + | |
| 31 | +} | |
| 0 | 32 | \ No newline at end of file | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFileRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.controller.admin.ureport.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.util.*; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | +import com.alibaba.excel.annotation.*; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - Ureport2报表 Response VO") | |
| 12 | +@Data | |
| 13 | +@ExcelIgnoreUnannotated | |
| 14 | +public class UreportFileRespVO { | |
| 15 | + | |
| 16 | + @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9948") | |
| 17 | + @ExcelProperty("ID") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | |
| 21 | + @ExcelProperty("文件名称") | |
| 22 | + private String fileName; | |
| 23 | + | |
| 24 | + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 25 | + @ExcelProperty("状态") | |
| 26 | + private Integer status; | |
| 27 | + | |
| 28 | + @Schema(description = "备注", example = "随便") | |
| 29 | + @ExcelProperty("备注") | |
| 30 | + private String remark; | |
| 31 | + | |
| 32 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 33 | + @ExcelProperty("创建时间") | |
| 34 | + private LocalDateTime createTime; | |
| 35 | + | |
| 36 | +} | |
| 0 | 37 | \ No newline at end of file | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/controller/admin/ureport/vo/UreportFileSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.controller.admin.ureport.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.util.*; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - Ureport2报表新增/修改 Request VO") | |
| 10 | +@Data | |
| 11 | +public class UreportFileSaveReqVO { | |
| 12 | + | |
| 13 | + @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9948") | |
| 14 | + private Long id; | |
| 15 | + | |
| 16 | + @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | |
| 17 | + @NotEmpty(message = "文件名称不能为空") | |
| 18 | + private String fileName; | |
| 19 | + | |
| 20 | + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 21 | + @NotNull(message = "状态不能为空") | |
| 22 | + private Integer status; | |
| 23 | + | |
| 24 | + @Schema(description = "文件内容") | |
| 25 | + private String fileContent; | |
| 26 | + | |
| 27 | + @Schema(description = "备注", example = "随便") | |
| 28 | + private String remark; | |
| 29 | + | |
| 30 | +} | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/dataobject/ureport/UreportFileDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.dal.dataobject.ureport; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Ureport2报表 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("ureport_file") | |
| 16 | +@KeySequence("ureport_file_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class UreportFileDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * ID | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 文件名称 | |
| 32 | + */ | |
| 33 | + private String fileName; | |
| 34 | + /** | |
| 35 | + * 状态 | |
| 36 | + */ | |
| 37 | + private Integer status; | |
| 38 | + /** | |
| 39 | + * 文件内容 | |
| 40 | + */ | |
| 41 | + private byte[] fileContent; | |
| 42 | + /** | |
| 43 | + * 备注 | |
| 44 | + */ | |
| 45 | + private String remark; | |
| 46 | + | |
| 47 | +} | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/dal/mysql/ureport/UreportFileMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.dal.mysql.ureport; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Ureport2报表 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface UreportFileMapper extends BaseMapperX<UreportFileDO> { | |
| 19 | + | |
| 20 | + default PageResult<UreportFileDO> selectPage(UreportFilePageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<UreportFileDO>() | |
| 22 | + .likeIfPresent(UreportFileDO::getFileName, reqVO.getFileName()) | |
| 23 | + .eqIfPresent(UreportFileDO::getStatus, reqVO.getStatus()) | |
| 24 | + .eqIfPresent(UreportFileDO::getRemark, reqVO.getRemark()) | |
| 25 | + .betweenIfPresent(UreportFileDO::getCreateTime, reqVO.getCreateTime()) | |
| 26 | + .orderByDesc(UreportFileDO::getId)); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | |
| 0 | 30 | \ No newline at end of file | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java
| ... | ... | @@ -20,6 +20,7 @@ public class SecurityConfiguration { |
| 20 | 20 | public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) { |
| 21 | 21 | //积木报表 |
| 22 | 22 | registry.antMatchers("/jmreport/**").permitAll(); |
| 23 | + registry.antMatchers("/ureport/**").permitAll(); | |
| 23 | 24 | } |
| 24 | 25 | |
| 25 | 26 | }; | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfig.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.framework.ureport.config; | |
| 2 | + | |
| 3 | +import com.bstek.ureport.console.UReportServlet; | |
| 4 | +import org.springframework.boot.web.servlet.ServletRegistrationBean; | |
| 5 | +import org.springframework.context.annotation.Bean; | |
| 6 | +import org.springframework.context.annotation.Configuration; | |
| 7 | +import org.springframework.context.annotation.ImportResource; | |
| 8 | +import org.springframework.context.annotation.PropertySource; | |
| 9 | + | |
| 10 | +import javax.servlet.Servlet; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Ureport 配置类 | |
| 14 | + * 加载ureport对应的xml配置文件 | |
| 15 | + */ | |
| 16 | +@PropertySource(value = {"classpath:ureport.properties"}) | |
| 17 | +@ImportResource("classpath:ureport-console-context.xml") | |
| 18 | +@Configuration | |
| 19 | +public class UreportConfig{ | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * ureport2报表Servlet配置 | |
| 23 | + */ | |
| 24 | + @Bean | |
| 25 | + public ServletRegistrationBean<Servlet> ureport2Servlet(){ | |
| 26 | + return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*"); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportDataSource.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.framework.ureport.config; | |
| 2 | + | |
| 3 | +import com.bstek.ureport.definition.datasource.BuildinDatasource; | |
| 4 | +import lombok.extern.slf4j.Slf4j; | |
| 5 | +import org.springframework.stereotype.Component; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | +import javax.sql.DataSource; | |
| 9 | +import java.sql.Connection; | |
| 10 | +import java.sql.SQLException; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * ureport内置数据源 | |
| 14 | + */ | |
| 15 | +@Slf4j | |
| 16 | +@Component | |
| 17 | +public class UreportDataSource implements BuildinDatasource { | |
| 18 | + | |
| 19 | + private static final String NAME = "本机数据源"; | |
| 20 | + | |
| 21 | + @Resource | |
| 22 | + private DataSource dataSource; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 数据源名称 | |
| 26 | + * | |
| 27 | + **/ | |
| 28 | + @Override | |
| 29 | + public String name() { | |
| 30 | + return NAME; | |
| 31 | + } | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * * 获取连接 | |
| 35 | + * | |
| 36 | + **/ | |
| 37 | + @Override | |
| 38 | + public Connection getConnection() { | |
| 39 | + try { | |
| 40 | + return dataSource.getConnection(); | |
| 41 | + } catch (SQLException e) { | |
| 42 | + log.error("Ureport 数据源 获取连接失败!"); | |
| 43 | + e.printStackTrace(); | |
| 44 | + } | |
| 45 | + return null; | |
| 46 | + } | |
| 47 | + | |
| 48 | +} | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/provider/UreportDatabaseProvider.java
0 → 100644
| 1 | +/* | |
| 2 | +package cn.iocoder.yudao.module.report.framework.ureport.provider; | |
| 3 | + | |
| 4 | +import cn.hutool.core.collection.CollUtil; | |
| 5 | +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | |
| 6 | +import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper; | |
| 7 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
| 8 | +import com.bstek.ureport.provider.report.ReportFile; | |
| 9 | +import com.bstek.ureport.provider.report.ReportProvider; | |
| 10 | +import lombok.Setter; | |
| 11 | +import lombok.extern.slf4j.Slf4j; | |
| 12 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
| 13 | +import org.springframework.stereotype.Component; | |
| 14 | + | |
| 15 | +import javax.annotation.Resource; | |
| 16 | +import java.io.ByteArrayInputStream; | |
| 17 | +import java.io.InputStream; | |
| 18 | +import java.time.LocalDateTime; | |
| 19 | +import java.time.ZoneId; | |
| 20 | +import java.time.ZonedDateTime; | |
| 21 | +import java.util.ArrayList; | |
| 22 | +import java.util.Date; | |
| 23 | +import java.util.List; | |
| 24 | + | |
| 25 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 26 | +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_EXISTS; | |
| 27 | +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS; | |
| 28 | + | |
| 29 | +*/ | |
| 30 | +/** | |
| 31 | + * 提供数据库的存储方式 | |
| 32 | + * @author 赤焰 | |
| 33 | + *//* | |
| 34 | + | |
| 35 | +@Slf4j | |
| 36 | +@Component | |
| 37 | +@ConfigurationProperties(prefix = "ureport.provider.database") | |
| 38 | +public class UreportDatabaseProvider implements ReportProvider{ | |
| 39 | + | |
| 40 | + private static final String NAME = "数据库存储系统"; | |
| 41 | + | |
| 42 | + private String prefix = "db:"; | |
| 43 | + | |
| 44 | + private boolean disabled; | |
| 45 | + | |
| 46 | + @Resource | |
| 47 | + private UreportFileMapper ureportFileMapper; | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + public InputStream loadReport(String file) { | |
| 51 | + LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); | |
| 52 | + queryWrapper.eq(UreportFileDO::getFileName, getCorrectName(file)); | |
| 53 | + UreportFileDO reportDo = ureportFileMapper.selectOne(queryWrapper); | |
| 54 | + if (reportDo == null) { | |
| 55 | + throw exception(UREPORT_FILE_NOT_EXISTS); | |
| 56 | + } | |
| 57 | + byte[] content = reportDo.getFileContent(); | |
| 58 | + return new ByteArrayInputStream(content); | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Override | |
| 62 | + public void deleteReport(String file) { | |
| 63 | + LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); | |
| 64 | + queryWrapper.eq(UreportFileDO::getFileName, getCorrectName(file)); | |
| 65 | + ureportFileMapper.delete(queryWrapper); | |
| 66 | + } | |
| 67 | + | |
| 68 | + @Override | |
| 69 | + public List<ReportFile> getReportFiles() { | |
| 70 | + LambdaQueryWrapper<UreportFileDO> reportFileQueryWrapper = new LambdaQueryWrapper<>(); | |
| 71 | + List<UreportFileDO> list = ureportFileMapper.selectList(reportFileQueryWrapper); | |
| 72 | + List<ReportFile> reportList = new ArrayList<>(); | |
| 73 | + if(CollUtil.isEmpty(list)){ | |
| 74 | + return reportList; | |
| 75 | + } | |
| 76 | + for (UreportFileDO reportFile : list) { | |
| 77 | + LocalDateTime updateTime = reportFile.getUpdateTime(); | |
| 78 | + ZonedDateTime zdt = updateTime.atZone(ZoneId.systemDefault()); | |
| 79 | + Date date = Date.from(zdt.toInstant()); | |
| 80 | + reportList.add(new ReportFile(reportFile.getFileName(),date)); | |
| 81 | + } | |
| 82 | + return reportList; | |
| 83 | + | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Override | |
| 87 | + public void saveReport(String file, String content) { | |
| 88 | + file = getCorrectName(file); | |
| 89 | + LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); | |
| 90 | + queryWrapper.eq(UreportFileDO::getFileName, file); | |
| 91 | + Long count = ureportFileMapper.selectCount(queryWrapper); | |
| 92 | + if(count>1){ | |
| 93 | + throw exception(UREPORT_FILE_EXISTS); | |
| 94 | + } | |
| 95 | + UreportFileDO ureportFileDO = ureportFileMapper.selectOne(queryWrapper); | |
| 96 | + if (ureportFileDO == null) { | |
| 97 | + ureportFileDO = new UreportFileDO(); | |
| 98 | + ureportFileDO.setFileName(file); | |
| 99 | + ureportFileDO.setFileContent(content.getBytes()); | |
| 100 | + ureportFileMapper.insert(ureportFileDO); | |
| 101 | + } else { | |
| 102 | + ureportFileDO.setFileContent(content.getBytes()); | |
| 103 | + ureportFileMapper.update(ureportFileDO, queryWrapper); | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + public String getName() { | |
| 109 | + return NAME; | |
| 110 | + } | |
| 111 | + | |
| 112 | + @Override | |
| 113 | + public boolean disabled() { | |
| 114 | + return disabled; | |
| 115 | + } | |
| 116 | + | |
| 117 | + @Override | |
| 118 | + public String getPrefix() { | |
| 119 | + return prefix; | |
| 120 | + } | |
| 121 | + | |
| 122 | + private String getCorrectName(String name) { | |
| 123 | + if (name.startsWith(prefix)) { | |
| 124 | + name = name.substring(prefix.length(), name.length()); | |
| 125 | + } | |
| 126 | + return name; | |
| 127 | + } | |
| 128 | +} | |
| 129 | +*/ | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/provider/UreportFileReportProvider.java
0 → 100644
| 1 | +/* | |
| 2 | +package cn.iocoder.yudao.module.report.framework.ureport.provider; | |
| 3 | + | |
| 4 | +import com.bstek.ureport.exception.ReportException; | |
| 5 | +import com.bstek.ureport.provider.report.ReportFile; | |
| 6 | +import com.bstek.ureport.provider.report.ReportProvider; | |
| 7 | +import lombok.extern.slf4j.Slf4j; | |
| 8 | +import org.apache.commons.io.IOUtils; | |
| 9 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import java.io.*; | |
| 13 | +import java.util.ArrayList; | |
| 14 | +import java.util.Calendar; | |
| 15 | +import java.util.List; | |
| 16 | +import java.util.Objects; | |
| 17 | + | |
| 18 | +*/ | |
| 19 | +/** | |
| 20 | + * 自定义文件存储,可接入oss等 | |
| 21 | + * @author 赤焰 | |
| 22 | + *//* | |
| 23 | + | |
| 24 | +@Slf4j | |
| 25 | +@Component | |
| 26 | +@ConfigurationProperties(prefix = "ureport.provider.file") | |
| 27 | +public class UreportFileReportProvider implements ReportProvider{ | |
| 28 | + | |
| 29 | + private String prefix="reportFile:"; | |
| 30 | + private String fileStoreDir; | |
| 31 | + private boolean disabled; | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public InputStream loadReport(String file) { | |
| 35 | + if(file.startsWith(prefix)){ | |
| 36 | + file=file.substring(prefix.length(),file.length()); | |
| 37 | + } | |
| 38 | + String fullPath=fileStoreDir+"/"+file; | |
| 39 | + try { | |
| 40 | + return new FileInputStream(fullPath); | |
| 41 | + } catch (FileNotFoundException e) { | |
| 42 | + throw new ReportException(e); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public void deleteReport(String file) { | |
| 48 | + if(file.startsWith(prefix)){ | |
| 49 | + file=file.substring(prefix.length(),file.length()); | |
| 50 | + } | |
| 51 | + String fullPath=fileStoreDir+"/"+file; | |
| 52 | + File f=new File(fullPath); | |
| 53 | + if(f.exists()){ | |
| 54 | + f.delete(); | |
| 55 | + } | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + public List<ReportFile> getReportFiles() { | |
| 60 | + File file=new File(fileStoreDir); | |
| 61 | + List<ReportFile> list= new ArrayList<>(); | |
| 62 | + for(File f: Objects.requireNonNull(file.listFiles())){ | |
| 63 | + Calendar calendar=Calendar.getInstance(); | |
| 64 | + calendar.setTimeInMillis(f.lastModified()); | |
| 65 | + list.add(new ReportFile(f.getName(),calendar.getTime())); | |
| 66 | + } | |
| 67 | + list.sort((f1, f2) -> f2.getUpdateDate().compareTo(f1.getUpdateDate())); | |
| 68 | + return list; | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public String getName() { | |
| 73 | + return "文件存储系统"; | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public void saveReport(String file,String content) { | |
| 78 | + if(file.startsWith(prefix)){ | |
| 79 | + file=file.substring(prefix.length(),file.length()); | |
| 80 | + } | |
| 81 | + String fullPath=fileStoreDir+"/"+file; | |
| 82 | + FileOutputStream outStream=null; | |
| 83 | + try{ | |
| 84 | + outStream=new FileOutputStream(new File(fullPath)); | |
| 85 | + IOUtils.write(content, outStream,"utf-8"); | |
| 86 | + }catch(Exception ex){ | |
| 87 | + throw new ReportException(ex); | |
| 88 | + }finally{ | |
| 89 | + if(outStream!=null){ | |
| 90 | + try { | |
| 91 | + outStream.close(); | |
| 92 | + } catch (IOException e) { | |
| 93 | + e.printStackTrace(); | |
| 94 | + } | |
| 95 | + } | |
| 96 | + } | |
| 97 | + | |
| 98 | + } | |
| 99 | + | |
| 100 | + @Override | |
| 101 | + public boolean disabled() { | |
| 102 | + return disabled; | |
| 103 | + } | |
| 104 | + | |
| 105 | + public void setDisabled(boolean disabled) { | |
| 106 | + this.disabled = disabled; | |
| 107 | + } | |
| 108 | + | |
| 109 | + public void setFileStoreDir(String fileStoreDir) { | |
| 110 | + this.fileStoreDir = fileStoreDir; | |
| 111 | + } | |
| 112 | + | |
| 113 | + @Override | |
| 114 | + public String getPrefix() { | |
| 115 | + return prefix; | |
| 116 | + } | |
| 117 | + | |
| 118 | +} | |
| 119 | +*/ | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.service.ureport; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Ureport2报表 Service 接口 | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +public interface UreportFileService { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 创建Ureport2报表 | |
| 19 | + * | |
| 20 | + * @param createReqVO 创建信息 | |
| 21 | + * @return 编号 | |
| 22 | + */ | |
| 23 | + Long createUreportFile(@Valid UreportFileSaveReqVO createReqVO); | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 更新Ureport2报表 | |
| 27 | + * | |
| 28 | + * @param updateReqVO 更新信息 | |
| 29 | + */ | |
| 30 | + void updateUreportFile(@Valid UreportFileSaveReqVO updateReqVO); | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 删除Ureport2报表 | |
| 34 | + * | |
| 35 | + * @param id 编号 | |
| 36 | + */ | |
| 37 | + void deleteUreportFile(Long id); | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 获得Ureport2报表 | |
| 41 | + * | |
| 42 | + * @param id 编号 | |
| 43 | + * @return Ureport2报表 | |
| 44 | + */ | |
| 45 | + UreportFileDO getUreportFile(Long id); | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * 获得Ureport2报表分页 | |
| 49 | + * | |
| 50 | + * @param pageReqVO 分页查询 | |
| 51 | + * @return Ureport2报表分页 | |
| 52 | + */ | |
| 53 | + PageResult<UreportFileDO> getUreportFilePage(UreportFilePageReqVO pageReqVO); | |
| 54 | + | |
| 55 | +} | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.service.ureport; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | |
| 11 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 12 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 13 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 14 | + | |
| 15 | +import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper; | |
| 16 | + | |
| 17 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 18 | +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * Ureport2报表 Service 实现类 | |
| 22 | + * | |
| 23 | + * @author 芋道源码 | |
| 24 | + */ | |
| 25 | +@Service | |
| 26 | +@Validated | |
| 27 | +public class UreportFileServiceImpl implements UreportFileService { | |
| 28 | + | |
| 29 | + @Resource | |
| 30 | + private UreportFileMapper ureportFileMapper; | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public Long createUreportFile(UreportFileSaveReqVO createReqVO) { | |
| 34 | + // 插入 | |
| 35 | + UreportFileDO ureportFile = BeanUtils.toBean(createReqVO, UreportFileDO.class); | |
| 36 | + ureportFileMapper.insert(ureportFile); | |
| 37 | + // 返回 | |
| 38 | + return ureportFile.getId(); | |
| 39 | + } | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public void updateUreportFile(UreportFileSaveReqVO updateReqVO) { | |
| 43 | + // 校验存在 | |
| 44 | + validateUreportFileExists(updateReqVO.getId()); | |
| 45 | + // 更新 | |
| 46 | + UreportFileDO updateObj = BeanUtils.toBean(updateReqVO, UreportFileDO.class); | |
| 47 | + ureportFileMapper.updateById(updateObj); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @Override | |
| 51 | + public void deleteUreportFile(Long id) { | |
| 52 | + // 校验存在 | |
| 53 | + validateUreportFileExists(id); | |
| 54 | + // 删除 | |
| 55 | + ureportFileMapper.deleteById(id); | |
| 56 | + } | |
| 57 | + | |
| 58 | + private void validateUreportFileExists(Long id) { | |
| 59 | + if (ureportFileMapper.selectById(id) == null) { | |
| 60 | + throw exception(UREPORT_FILE_NOT_EXISTS); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + @Override | |
| 65 | + public UreportFileDO getUreportFile(Long id) { | |
| 66 | + return ureportFileMapper.selectById(id); | |
| 67 | + } | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + public PageResult<UreportFileDO> getUreportFilePage(UreportFilePageReqVO pageReqVO) { | |
| 71 | + return ureportFileMapper.selectPage(pageReqVO); | |
| 72 | + } | |
| 73 | + | |
| 74 | +} | |
| 0 | 75 | \ No newline at end of file | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/resources/mapper/ureport/UreportFileMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-report/yudao-module-report-biz/src/main/resources/ureport.properties
0 → 100644
yudao-module-report/yudao-module-report-biz/src/test/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.report.service.ureport; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | |
| 13 | +import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link UreportFileServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(UreportFileServiceImpl.class) | |
| 37 | +public class UreportFileServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private UreportFileServiceImpl ureportFileService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private UreportFileMapper ureportFileMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateUreportFile_success() { | |
| 47 | + // 准备参数 | |
| 48 | + UreportFileSaveReqVO createReqVO = randomPojo(UreportFileSaveReqVO.class).setId(null); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long ureportFileId = ureportFileService.createUreportFile(createReqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(ureportFileId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + UreportFileDO ureportFile = ureportFileMapper.selectById(ureportFileId); | |
| 56 | + assertPojoEquals(createReqVO, ureportFile, "id"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateUreportFile_success() { | |
| 61 | + // mock 数据 | |
| 62 | + UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class); | |
| 63 | + ureportFileMapper.insert(dbUreportFile);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + UreportFileSaveReqVO updateReqVO = randomPojo(UreportFileSaveReqVO.class, o -> { | |
| 66 | + o.setId(dbUreportFile.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + ureportFileService.updateUreportFile(updateReqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + UreportFileDO ureportFile = ureportFileMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(updateReqVO, ureportFile); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateUreportFile_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + UreportFileSaveReqVO updateReqVO = randomPojo(UreportFileSaveReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> ureportFileService.updateUreportFile(updateReqVO), UREPORT_FILE_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteUreportFile_success() { | |
| 87 | + // mock 数据 | |
| 88 | + UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class); | |
| 89 | + ureportFileMapper.insert(dbUreportFile);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbUreportFile.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + ureportFileService.deleteUreportFile(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(ureportFileMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteUreportFile_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> ureportFileService.deleteUreportFile(id), UREPORT_FILE_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetUreportFilePage() { | |
| 111 | + // mock 数据 | |
| 112 | + UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class, o -> { // 等会查询到 | |
| 113 | + o.setFileName(null); | |
| 114 | + o.setStatus(null); | |
| 115 | + o.setRemark(null); | |
| 116 | + o.setCreateTime(null); | |
| 117 | + }); | |
| 118 | + ureportFileMapper.insert(dbUreportFile); | |
| 119 | + // 测试 fileName 不匹配 | |
| 120 | + ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setFileName(null))); | |
| 121 | + // 测试 status 不匹配 | |
| 122 | + ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setStatus(null))); | |
| 123 | + // 测试 remark 不匹配 | |
| 124 | + ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setRemark(null))); | |
| 125 | + // 测试 createTime 不匹配 | |
| 126 | + ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setCreateTime(null))); | |
| 127 | + // 准备参数 | |
| 128 | + UreportFilePageReqVO reqVO = new UreportFilePageReqVO(); | |
| 129 | + reqVO.setFileName(null); | |
| 130 | + reqVO.setStatus(null); | |
| 131 | + reqVO.setRemark(null); | |
| 132 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 133 | + | |
| 134 | + // 调用 | |
| 135 | + PageResult<UreportFileDO> pageResult = ureportFileService.getUreportFilePage(reqVO); | |
| 136 | + // 断言 | |
| 137 | + assertEquals(1, pageResult.getTotal()); | |
| 138 | + assertEquals(1, pageResult.getList().size()); | |
| 139 | + assertPojoEquals(dbUreportFile, pageResult.getList().get(0)); | |
| 140 | + } | |
| 141 | + | |
| 142 | +} | |
| 0 | 143 | \ No newline at end of file | ... | ... |
yudao-module-report/yudao-module-report-biz/src/test/resources/sql/clean.sql
yudao-module-report/yudao-module-report-biz/src/test/resources/sql/create_tables.sql
| ... | ... | @@ -12,3 +12,16 @@ CREATE TABLE IF NOT EXISTS "report_go_view_project" ( |
| 12 | 12 | "deleted" bit NOT NULL DEFAULT FALSE, |
| 13 | 13 | PRIMARY KEY ("id") |
| 14 | 14 | ) COMMENT 'GoView 项目表'; |
| 15 | +CREATE TABLE IF NOT EXISTS "ureport_file" ( | |
| 16 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 17 | + "file_name" varchar NOT NULL, | |
| 18 | + "status" int NOT NULL, | |
| 19 | + "file_content" varchar, | |
| 20 | + "remark" varchar, | |
| 21 | + "creator" varchar DEFAULT '', | |
| 22 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 23 | + "updater" varchar DEFAULT '', | |
| 24 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 25 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 26 | + PRIMARY KEY ("id") | |
| 27 | +) COMMENT 'Ureport2报表'; | ... | ... |
yudao-server/src/main/resources/application-local.yaml
| ... | ... | @@ -264,3 +264,16 @@ justauth: |
| 264 | 264 | prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE:: |
| 265 | 265 | timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟 |
| 266 | 266 | |
| 267 | +#ureport配置 | |
| 268 | +#ureport: | |
| 269 | +# disableHttpSessionReportCache: true #是否禁用 | |
| 270 | +# disableFileProvider: true #是否禁用 | |
| 271 | +# debug: true | |
| 272 | +# fileStoreDir: D://ureport//files | |
| 273 | +# provider: | |
| 274 | +# database: | |
| 275 | +# disabled: true | |
| 276 | +# file: | |
| 277 | +# disabled: true | |
| 278 | + | |
| 279 | + | ... | ... |