【新增】ureport2 集成
parent
5bf7cd396f
commit
8507fa9172
@ -0,0 +1,95 @@
|
|||||||
|
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.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.dal.dataobject.ureport.UreportFileDO;
|
||||||
|
import cn.iocoder.yudao.module.report.service.ureport.UreportFileService;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - Ureport2报表")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/report/ureport-file")
|
||||||
|
@Validated
|
||||||
|
public class UreportFileController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UreportFileService ureportFileService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建Ureport2报表")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:ureport-file:create')")
|
||||||
|
public CommonResult<Long> createUreportFile(@Valid @RequestBody UreportFileSaveReqVO createReqVO) {
|
||||||
|
return success(ureportFileService.createUreportFile(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新Ureport2报表")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:ureport-file:update')")
|
||||||
|
public CommonResult<Boolean> updateUreportFile(@Valid @RequestBody UreportFileSaveReqVO updateReqVO) {
|
||||||
|
ureportFileService.updateUreportFile(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除Ureport2报表")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:ureport-file:delete')")
|
||||||
|
public CommonResult<Boolean> deleteUreportFile(@RequestParam("id") Long id) {
|
||||||
|
ureportFileService.deleteUreportFile(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得Ureport2报表")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:ureport-file:query')")
|
||||||
|
public CommonResult<UreportFileRespVO> getUreportFile(@RequestParam("id") Long id) {
|
||||||
|
UreportFileDO ureportFile = ureportFileService.getUreportFile(id);
|
||||||
|
return success(BeanUtils.toBean(ureportFile, UreportFileRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得Ureport2报表分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:ureport-file:query')")
|
||||||
|
public CommonResult<PageResult<UreportFileRespVO>> getUreportFilePage(@Valid UreportFilePageReqVO pageReqVO) {
|
||||||
|
PageResult<UreportFileDO> pageResult = ureportFileService.getUreportFilePage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, UreportFileRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出Ureport2报表 Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('report:ureport-file:export')")
|
||||||
|
@OperateLog(type = EXPORT)
|
||||||
|
public void exportUreportFileExcel(@Valid UreportFilePageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<UreportFileDO> list = ureportFileService.getUreportFilePage(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "Ureport2报表.xls", "数据", UreportFileRespVO.class,
|
||||||
|
BeanUtils.toBean(list, UreportFileRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
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 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")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class UreportFilePageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "文件名称", example = "赵六")
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Schema(description = "状态", example = "1")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "随便")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private LocalDateTime[] createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
package cn.iocoder.yudao.module.report.controller.admin.ureport.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.*;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.alibaba.excel.annotation.*;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - Ureport2报表 Response VO")
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class UreportFileRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9948")
|
||||||
|
@ExcelProperty("ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||||
|
@ExcelProperty("文件名称")
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@ExcelProperty("状态")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "随便")
|
||||||
|
@ExcelProperty("备注")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package cn.iocoder.yudao.module.report.controller.admin.ureport.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - Ureport2报表新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
public class UreportFileSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "9948")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||||
|
@NotEmpty(message = "文件名称不能为空")
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotNull(message = "状态不能为空")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "文件内容")
|
||||||
|
private String fileContent;
|
||||||
|
|
||||||
|
@Schema(description = "备注", example = "随便")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
package cn.iocoder.yudao.module.report.dal.dataobject.ureport;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ureport2报表 DO
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@TableName("ureport_file")
|
||||||
|
@KeySequence("ureport_file_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class UreportFileDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 文件名称
|
||||||
|
*/
|
||||||
|
private String fileName;
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 文件内容
|
||||||
|
*/
|
||||||
|
private byte[] fileContent;
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
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.module.report.dal.dataobject.ureport.UreportFileDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ureport2报表 Mapper
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface UreportFileMapper extends BaseMapperX<UreportFileDO> {
|
||||||
|
|
||||||
|
default PageResult<UreportFileDO> selectPage(UreportFilePageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<UreportFileDO>()
|
||||||
|
.likeIfPresent(UreportFileDO::getFileName, reqVO.getFileName())
|
||||||
|
.eqIfPresent(UreportFileDO::getStatus, reqVO.getStatus())
|
||||||
|
.eqIfPresent(UreportFileDO::getRemark, reqVO.getRemark())
|
||||||
|
.betweenIfPresent(UreportFileDO::getCreateTime, reqVO.getCreateTime())
|
||||||
|
.orderByDesc(UreportFileDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package cn.iocoder.yudao.module.report.framework.ureport.config;
|
||||||
|
|
||||||
|
import com.bstek.ureport.console.UReportServlet;
|
||||||
|
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.ImportResource;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
|
import javax.servlet.Servlet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ureport 配置类
|
||||||
|
* 加载ureport对应的xml配置文件
|
||||||
|
*/
|
||||||
|
@PropertySource(value = {"classpath:ureport.properties"})
|
||||||
|
@ImportResource("classpath:ureport-console-context.xml")
|
||||||
|
@Configuration
|
||||||
|
public class UreportConfig{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ureport2报表Servlet配置
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public ServletRegistrationBean<Servlet> ureport2Servlet(){
|
||||||
|
return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package cn.iocoder.yudao.module.report.framework.ureport.config;
|
||||||
|
|
||||||
|
import com.bstek.ureport.definition.datasource.BuildinDatasource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ureport内置数据源
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class UreportDataSource implements BuildinDatasource {
|
||||||
|
|
||||||
|
private static final String NAME = "本机数据源";
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源名称
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 获取连接
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public Connection getConnection() {
|
||||||
|
try {
|
||||||
|
return dataSource.getConnection();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Ureport 数据源 获取连接失败!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
package cn.iocoder.yudao.module.report.framework.ureport.provider;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
|
||||||
|
import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.bstek.ureport.provider.report.ReportFile;
|
||||||
|
import com.bstek.ureport.provider.report.ReportProvider;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_EXISTS;
|
||||||
|
import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS;
|
||||||
|
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 提供数据库的存储方式
|
||||||
|
* @author 赤焰
|
||||||
|
*//*
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "ureport.provider.database")
|
||||||
|
public class UreportDatabaseProvider implements ReportProvider{
|
||||||
|
|
||||||
|
private static final String NAME = "数据库存储系统";
|
||||||
|
|
||||||
|
private String prefix = "db:";
|
||||||
|
|
||||||
|
private boolean disabled;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UreportFileMapper ureportFileMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream loadReport(String file) {
|
||||||
|
LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(UreportFileDO::getFileName, getCorrectName(file));
|
||||||
|
UreportFileDO reportDo = ureportFileMapper.selectOne(queryWrapper);
|
||||||
|
if (reportDo == null) {
|
||||||
|
throw exception(UREPORT_FILE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
byte[] content = reportDo.getFileContent();
|
||||||
|
return new ByteArrayInputStream(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteReport(String file) {
|
||||||
|
LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(UreportFileDO::getFileName, getCorrectName(file));
|
||||||
|
ureportFileMapper.delete(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ReportFile> getReportFiles() {
|
||||||
|
LambdaQueryWrapper<UreportFileDO> reportFileQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
List<UreportFileDO> list = ureportFileMapper.selectList(reportFileQueryWrapper);
|
||||||
|
List<ReportFile> reportList = new ArrayList<>();
|
||||||
|
if(CollUtil.isEmpty(list)){
|
||||||
|
return reportList;
|
||||||
|
}
|
||||||
|
for (UreportFileDO reportFile : list) {
|
||||||
|
LocalDateTime updateTime = reportFile.getUpdateTime();
|
||||||
|
ZonedDateTime zdt = updateTime.atZone(ZoneId.systemDefault());
|
||||||
|
Date date = Date.from(zdt.toInstant());
|
||||||
|
reportList.add(new ReportFile(reportFile.getFileName(),date));
|
||||||
|
}
|
||||||
|
return reportList;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveReport(String file, String content) {
|
||||||
|
file = getCorrectName(file);
|
||||||
|
LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(UreportFileDO::getFileName, file);
|
||||||
|
Long count = ureportFileMapper.selectCount(queryWrapper);
|
||||||
|
if(count>1){
|
||||||
|
throw exception(UREPORT_FILE_EXISTS);
|
||||||
|
}
|
||||||
|
UreportFileDO ureportFileDO = ureportFileMapper.selectOne(queryWrapper);
|
||||||
|
if (ureportFileDO == null) {
|
||||||
|
ureportFileDO = new UreportFileDO();
|
||||||
|
ureportFileDO.setFileName(file);
|
||||||
|
ureportFileDO.setFileContent(content.getBytes());
|
||||||
|
ureportFileMapper.insert(ureportFileDO);
|
||||||
|
} else {
|
||||||
|
ureportFileDO.setFileContent(content.getBytes());
|
||||||
|
ureportFileMapper.update(ureportFileDO, queryWrapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean disabled() {
|
||||||
|
return disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrefix() {
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCorrectName(String name) {
|
||||||
|
if (name.startsWith(prefix)) {
|
||||||
|
name = name.substring(prefix.length(), name.length());
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
package cn.iocoder.yudao.module.report.service.ureport;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import javax.validation.*;
|
||||||
|
import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ureport2报表 Service 接口
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public interface UreportFileService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建Ureport2报表
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createUreportFile(@Valid UreportFileSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新Ureport2报表
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateUreportFile(@Valid UreportFileSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除Ureport2报表
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteUreportFile(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得Ureport2报表
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return Ureport2报表
|
||||||
|
*/
|
||||||
|
UreportFileDO getUreportFile(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得Ureport2报表分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return Ureport2报表分页
|
||||||
|
*/
|
||||||
|
PageResult<UreportFileDO> getUreportFilePage(UreportFilePageReqVO pageReqVO);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
package cn.iocoder.yudao.module.report.service.ureport;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ureport2报表 Service 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class UreportFileServiceImpl implements UreportFileService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UreportFileMapper ureportFileMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createUreportFile(UreportFileSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
UreportFileDO ureportFile = BeanUtils.toBean(createReqVO, UreportFileDO.class);
|
||||||
|
ureportFileMapper.insert(ureportFile);
|
||||||
|
// 返回
|
||||||
|
return ureportFile.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateUreportFile(UreportFileSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateUreportFileExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
UreportFileDO updateObj = BeanUtils.toBean(updateReqVO, UreportFileDO.class);
|
||||||
|
ureportFileMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteUreportFile(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateUreportFileExists(id);
|
||||||
|
// 删除
|
||||||
|
ureportFileMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateUreportFileExists(Long id) {
|
||||||
|
if (ureportFileMapper.selectById(id) == null) {
|
||||||
|
throw exception(UREPORT_FILE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UreportFileDO getUreportFile(Long id) {
|
||||||
|
return ureportFileMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<UreportFileDO> getUreportFilePage(UreportFilePageReqVO pageReqVO) {
|
||||||
|
return ureportFileMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
ureport.disableHttpSessionReportCache=false
|
||||||
|
ureport.disableFileProvider=false
|
||||||
|
ureport.fileStoreDir=D:\\ureport\\files
|
||||||
|
ureport.debug=true
|
||||||
@ -0,0 +1,142 @@
|
|||||||
|
package cn.iocoder.yudao.module.report.service.ureport;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
|
||||||
|
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.UreportFileDO;
|
||||||
|
import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static cn.hutool.core.util.RandomUtil.*;
|
||||||
|
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.DateUtils.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link UreportFileServiceImpl} 的单元测试类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Import(UreportFileServiceImpl.class)
|
||||||
|
public class UreportFileServiceImplTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UreportFileServiceImpl ureportFileService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UreportFileMapper ureportFileMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateUreportFile_success() {
|
||||||
|
// 准备参数
|
||||||
|
UreportFileSaveReqVO createReqVO = randomPojo(UreportFileSaveReqVO.class).setId(null);
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Long ureportFileId = ureportFileService.createUreportFile(createReqVO);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(ureportFileId);
|
||||||
|
// 校验记录的属性是否正确
|
||||||
|
UreportFileDO ureportFile = ureportFileMapper.selectById(ureportFileId);
|
||||||
|
assertPojoEquals(createReqVO, ureportFile, "id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateUreportFile_success() {
|
||||||
|
// mock 数据
|
||||||
|
UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class);
|
||||||
|
ureportFileMapper.insert(dbUreportFile);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
UreportFileSaveReqVO updateReqVO = randomPojo(UreportFileSaveReqVO.class, o -> {
|
||||||
|
o.setId(dbUreportFile.getId()); // 设置更新的 ID
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
ureportFileService.updateUreportFile(updateReqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
UreportFileDO ureportFile = ureportFileMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||||
|
assertPojoEquals(updateReqVO, ureportFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateUreportFile_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
UreportFileSaveReqVO updateReqVO = randomPojo(UreportFileSaveReqVO.class);
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> ureportFileService.updateUreportFile(updateReqVO), UREPORT_FILE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteUreportFile_success() {
|
||||||
|
// mock 数据
|
||||||
|
UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class);
|
||||||
|
ureportFileMapper.insert(dbUreportFile);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
Long id = dbUreportFile.getId();
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
ureportFileService.deleteUreportFile(id);
|
||||||
|
// 校验数据不存在了
|
||||||
|
assertNull(ureportFileMapper.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteUreportFile_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
Long id = randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> ureportFileService.deleteUreportFile(id), UREPORT_FILE_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||||
|
public void testGetUreportFilePage() {
|
||||||
|
// mock 数据
|
||||||
|
UreportFileDO dbUreportFile = randomPojo(UreportFileDO.class, o -> { // 等会查询到
|
||||||
|
o.setFileName(null);
|
||||||
|
o.setStatus(null);
|
||||||
|
o.setRemark(null);
|
||||||
|
o.setCreateTime(null);
|
||||||
|
});
|
||||||
|
ureportFileMapper.insert(dbUreportFile);
|
||||||
|
// 测试 fileName 不匹配
|
||||||
|
ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setFileName(null)));
|
||||||
|
// 测试 status 不匹配
|
||||||
|
ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setStatus(null)));
|
||||||
|
// 测试 remark 不匹配
|
||||||
|
ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setRemark(null)));
|
||||||
|
// 测试 createTime 不匹配
|
||||||
|
ureportFileMapper.insert(cloneIgnoreId(dbUreportFile, o -> o.setCreateTime(null)));
|
||||||
|
// 准备参数
|
||||||
|
UreportFilePageReqVO reqVO = new UreportFilePageReqVO();
|
||||||
|
reqVO.setFileName(null);
|
||||||
|
reqVO.setStatus(null);
|
||||||
|
reqVO.setRemark(null);
|
||||||
|
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
PageResult<UreportFileDO> pageResult = ureportFileService.getUreportFilePage(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, pageResult.getTotal());
|
||||||
|
assertEquals(1, pageResult.getList().size());
|
||||||
|
assertPojoEquals(dbUreportFile, pageResult.getList().get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1 +1,2 @@
|
|||||||
DELETE FROM "report_go_view_project";
|
DELETE FROM "report_go_view_project";
|
||||||
|
DELETE FROM "ureport_file";
|
||||||
|
|||||||
Loading…
Reference in New Issue