mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-25 00:15:06 +08:00
BPM:【移除】Ureport 的实现,因为和 Spring Boot 兼容性较差
This commit is contained in:
@ -12,8 +12,4 @@ public interface ErrorCodeConstants {
|
||||
// ========== GoView 模块 1-003-000-000 ==========
|
||||
ErrorCode GO_VIEW_PROJECT_NOT_EXISTS = new ErrorCode(1_003_000_000, "GoView 项目不存在");
|
||||
|
||||
// ========== UREPORT 模块 1-003-001-000 ==========
|
||||
ErrorCode UREPORT_DATA_NOT_EXISTS = new ErrorCode(1_003_001_001, "Ureport2 报表不存在");
|
||||
ErrorCode UREPORT_DATABASE_NOT_EXISTS = new ErrorCode(1_003_001_002, "Ureport2 报表数据源不存在");
|
||||
|
||||
}
|
||||
|
@ -74,11 +74,6 @@
|
||||
<artifactId>xercesImpl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.bstek.ureport</groupId>
|
||||
<artifactId>ureport2-console</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-excel</artifactId>
|
||||
|
@ -1,93 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.controller.admin.ureport;
|
||||
|
||||
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.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
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 jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - Ureport2 报表")
|
||||
@RestController
|
||||
@RequestMapping("/report/ureport-data")
|
||||
@Validated
|
||||
public class UReportDataController {
|
||||
|
||||
@Resource
|
||||
private UReportDataService uReportDataService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@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 报表")
|
||||
@PreAuthorize("@ss.hasPermission('report:ureport-data:update')")
|
||||
public CommonResult<Boolean> updateUReportData(@Valid @RequestBody UReportDataSaveReqVO updateReqVO) {
|
||||
uReportDataService.updateUReportData(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除 Ureport2 报表")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('report:ureport-data:delete')")
|
||||
public CommonResult<Boolean> deleteUReportData(@RequestParam("id") Long id) {
|
||||
uReportDataService.deleteUReportData(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得Ureport2报表")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('report:ureport-data:query')")
|
||||
public CommonResult<UReportDataRespVO> getUReportData(@RequestParam("id") Long id) {
|
||||
UReportDataDO uReportData = uReportDataService.getUReportData(id);
|
||||
return success(BeanUtils.toBean(uReportData, UReportDataRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得Ureport2报表分页")
|
||||
@PreAuthorize("@ss.hasPermission('report:ureport-data:query')")
|
||||
public CommonResult<PageResult<UReportDataRespVO>> getUReportDataPage(@Valid UReportDataPageReqVO pageReqVO) {
|
||||
PageResult<UReportDataDO> pageResult = uReportDataService.getUReportDataPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, UReportDataRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出 Ureport2 报表 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('report:ureport-data:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportUReportDataExcel(@Valid UReportDataPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<UReportDataDO> list = uReportDataService.getUReportDataPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "Ureport2 报表.xls", "数据", UReportDataRespVO.class,
|
||||
BeanUtils.toBean(list, UReportDataRespVO.class));
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.controller.admin.ureport.vo;
|
||||
|
||||
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")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class UReportDataPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "文件名称", example = "李四")
|
||||
private String name;
|
||||
|
||||
@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;
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.controller.admin.ureport.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - Ureport2 报表 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class UReportDataRespVO {
|
||||
|
||||
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26175")
|
||||
@ExcelProperty("ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
@ExcelProperty("文件名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "状态", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.COMMON_STATUS)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "文件内容")
|
||||
@ExcelProperty("文件内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
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.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - Ureport2 报表新增/修改 Request VO")
|
||||
@Data
|
||||
public class UReportDataSaveReqVO {
|
||||
|
||||
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26175")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
@NotEmpty(message = "文件名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(CommonStatusEnum.class)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "文件内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
private String remark;
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.dal.dataobject.ureport;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
// TODO @赤焰:这个是不是可以支持多租户?
|
||||
/**
|
||||
* Ureport2 报表 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("report_ureport_data")
|
||||
@KeySequence("report_ureport_data_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UReportDataDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 文件名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link CommonStatusEnum#getStatus()}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 文件内容
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.dal.mysql.ureport;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
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 java.util.List;
|
||||
|
||||
/**
|
||||
* Ureport2报表 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface UReportDataMapper extends BaseMapperX<UReportDataDO> {
|
||||
|
||||
default PageResult<UReportDataDO> selectPage(UReportDataPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<UReportDataDO>()
|
||||
.likeIfPresent(UReportDataDO::getName, reqVO.getName())
|
||||
.eqIfPresent(UReportDataDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(UReportDataDO::getRemark, reqVO.getRemark())
|
||||
.betweenIfPresent(UReportDataDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(UReportDataDO::getId));
|
||||
}
|
||||
|
||||
default List<UReportDataDO> selectListByName(String name) {
|
||||
return selectList(new LambdaQueryWrapperX<UReportDataDO>()
|
||||
.eqIfPresent(UReportDataDO::getName,name));
|
||||
}
|
||||
|
||||
default UReportDataDO selectByName(String name){
|
||||
return selectOne(new LambdaQueryWrapperX<UReportDataDO>()
|
||||
.eqIfPresent(UReportDataDO::getName,name));
|
||||
}
|
||||
|
||||
default int deleteByName(String name) {
|
||||
return delete(new LambdaQueryWrapperX<UReportDataDO>()
|
||||
.eqIfPresent(UReportDataDO::getName,name));
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +1,12 @@
|
||||
package cn.iocoder.yudao.module.report.framework.security.config;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
|
||||
import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer;
|
||||
import cn.iocoder.yudao.framework.security.config.SecurityProperties;
|
||||
import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;
|
||||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Report 模块的 Security 配置
|
||||
@ -29,20 +23,8 @@ public class SecurityConfiguration {
|
||||
@Override
|
||||
public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) {
|
||||
registry.requestMatchers("/jmreport/**").permitAll(); // 积木报表
|
||||
registry.requestMatchers("/ureport/**").permitAll(); // UReport 报表
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 UReportFilter 过滤器,响应 header 设置 token
|
||||
*/
|
||||
/*@Bean
|
||||
public FilterRegistrationBean<UReportFilter> uReportFilterFilterRegistrationBean() {
|
||||
FilterRegistrationBean<UReportFilter> registrationBean = new FilterRegistrationBean<>();
|
||||
registrationBean.setFilter(new UReportFilter(oauth2TokenApi));
|
||||
registrationBean.setOrder(WebFilterOrderEnum.TRACE_FILTER);
|
||||
return registrationBean;
|
||||
}*/
|
||||
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.framework.ureport.config;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
/**
|
||||
* UReport2 配置类
|
||||
*
|
||||
* @author 赤焰
|
||||
*/
|
||||
// @Configuration TODO 芋艿:JDK21 暂时不支持 UReport2,原因是 Spring Boot 3 的 javax 替换成 jakarta 了
|
||||
@ImportResource({"classpath:ureport-console-context.xml"})
|
||||
@PropertySource(value = {"classpath:ureport.properties"}) // TODO @赤焰:这个可以搞到 application.yaml 里么?
|
||||
@EnableConfigurationProperties({UReportProperties.class})
|
||||
public class UReportConfiguration {
|
||||
|
||||
// TODO 芋艿:JDK21 暂时不支持 UReport2,原因是 Spring Boot 3 的 javax 替换成 jakarta 了
|
||||
// @Bean
|
||||
// public ServletRegistrationBean<Servlet> uReportRegistrationBean() {
|
||||
// return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*");
|
||||
// }
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.framework.ureport.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* UReport2 配置类
|
||||
*
|
||||
* @author 赤焰
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "ureport.provider.database")
|
||||
public class UReportProperties {
|
||||
|
||||
// TODO @赤焰:每个字段的注释写下哈;
|
||||
private String name = "数据库文件系统";
|
||||
|
||||
private String prefix = "db-";
|
||||
|
||||
private boolean disabled = false;
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.framework.ureport.core;
|
||||
|
||||
import com.bstek.ureport.definition.datasource.BuildinDatasource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
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.UREPORT_DATABASE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* UReport2 内置数据源
|
||||
*
|
||||
* @author 赤焰
|
||||
*/
|
||||
@Slf4j
|
||||
//@Component
|
||||
public class UReportDataSource implements BuildinDatasource {
|
||||
|
||||
private static final String NAME = "UReportDataSource";
|
||||
|
||||
@Resource
|
||||
private DataSource dataSource;
|
||||
|
||||
/**
|
||||
* @return 数据源名称
|
||||
*/
|
||||
@Override
|
||||
public String name() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 获取连接
|
||||
*/
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
log.error("[getConnection][获取连接失败!]", e);
|
||||
throw exception(UREPORT_DATABASE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
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.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.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;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
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
|
||||
public class UReportDatabaseProvider implements ReportProvider {
|
||||
|
||||
@Autowired
|
||||
private UReportProperties uReportProperties;
|
||||
@Resource
|
||||
private UReportDataService uReportDataService;
|
||||
|
||||
@Override
|
||||
public InputStream loadReport(String name) {
|
||||
uReportDataService.validateUReportDataExists(getCorrectName(name));
|
||||
UReportDataDO uReportDataDO = uReportDataService.selectOneByName(getCorrectName(name));
|
||||
String content = uReportDataDO.getContent();
|
||||
return new ByteArrayInputStream(content.getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteReport(String name) {
|
||||
uReportDataService.deleteByName(getCorrectName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReportFile> getReportFiles() {
|
||||
List<UReportDataDO> list = uReportDataService.getReportDataList();
|
||||
// TODO @赤焰:这里,不用判空,CollectionUtils.convertList 已经处理了哈。
|
||||
if(CollUtil.isEmpty(list)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
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();
|
||||
if (uReportDataDO == null) {
|
||||
saveReqVO.setName(name);
|
||||
saveReqVO.setContent(content);
|
||||
saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
uReportDataService.createUReportData(saveReqVO);
|
||||
} else {
|
||||
saveReqVO.setId(uReportDataDO.getId());
|
||||
saveReqVO.setName(name);
|
||||
saveReqVO.setContent(content);
|
||||
saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
uReportDataService.updateUReportData(saveReqVO);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return uReportProperties.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disabled() {
|
||||
return uReportProperties.isDisabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return uReportProperties.getPrefix();
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除存储媒介,获取报表名字
|
||||
*
|
||||
* @param name 前端传入的报表带存储媒介的名字
|
||||
* @return 表名字
|
||||
*/
|
||||
private String getCorrectName(String name) {
|
||||
return StrUtil.removePrefix(name,getPrefix());
|
||||
}
|
||||
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
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;
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
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.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* UReport 认证过滤器
|
||||
* @author 赤焰
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class UReportFilter extends OncePerRequestFilter {
|
||||
|
||||
private final static String TOKEN = "token";
|
||||
|
||||
private final OAuth2TokenApi oauth2TokenApi;
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
||||
throws ServletException, IOException {
|
||||
|
||||
if(log.isDebugEnabled()){
|
||||
log.debug("UReportFilter自定义过滤器");
|
||||
}
|
||||
|
||||
Map<String, String> paramMap = ServletUtils.getParamMap(request);
|
||||
String requestURI = request.getRequestURI();
|
||||
boolean contains = requestURI.contains("/ureport");
|
||||
if (paramMap.containsKey(TOKEN)&&contains) {
|
||||
String token = request.getParameter(TOKEN);
|
||||
if(log.isDebugEnabled()){
|
||||
log.debug("UReportFilter自定义过滤器 token="+token);
|
||||
}
|
||||
|
||||
response.addHeader(TOKEN,token);
|
||||
|
||||
TenantContextHolder.setIgnore(true); // 忽略租户,保证可查询到 token 信息
|
||||
LoginUser user = null;
|
||||
try {
|
||||
OAuth2AccessTokenCheckRespDTO accessToken = oauth2TokenApi.checkAccessToken(token);
|
||||
if (accessToken != null) {
|
||||
user = new LoginUser().setId(accessToken.getUserId()).setUserType(accessToken.getUserType())
|
||||
.setTenantId(accessToken.getTenantId()).setScopes(accessToken.getScopes());
|
||||
if (user != null) {
|
||||
SecurityFrameworkUtils.setLoginUser(user, WebFrameworkUtils.getRequest());
|
||||
|
||||
// ② 参考 TenantContextWebFilter 实现(Tenant 的上下文清理,交给 TenantContextWebFilter 完成)
|
||||
// 目的:基于 LoginUser 获得到的租户编号,设置到 Tenant 上下文,避免查询数据库时的报错
|
||||
TenantContextHolder.setIgnore(false);
|
||||
TenantContextHolder.setTenantId(user.getTenantId());
|
||||
}
|
||||
}
|
||||
} catch (ServiceException ignored) {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 继续过滤
|
||||
chain.doFilter(request, response);
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
/**
|
||||
* ureport2:https://github.com/youseries/ureport
|
||||
*
|
||||
* ureport2 和 jimurepot 是相同类型的产品,不过停更了,最好发布时间是 2018 年。
|
||||
* 它们之间的功能对比,可见 https://juejin.cn/post/6939836480269320200 地址
|
||||
*/
|
||||
package cn.iocoder.yudao.module.report.framework.ureport;
|
@ -1,89 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.service.ureport;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
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 jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Ureport2 报表 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface UReportDataService {
|
||||
|
||||
/**
|
||||
* 创建 Ureport2 报表
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createUReportData(@Valid UReportDataSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新 Ureport2 报表
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateUReportData(@Valid UReportDataSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除 Ureport2 报表
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteUReportData(Long id);
|
||||
|
||||
/**
|
||||
* 获得 Ureport2 报表
|
||||
*
|
||||
* @param id 编号
|
||||
* @return Ureport2 报表
|
||||
*/
|
||||
UReportDataDO getUReportData(Long id);
|
||||
|
||||
/**
|
||||
* 获得 Ureport2 报表分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return Ureport2 报表分页
|
||||
*/
|
||||
PageResult<UReportDataDO> getUReportDataPage(UReportDataPageReqVO pageReqVO);
|
||||
|
||||
// TODO @赤焰:可以不用返回 int。如果不需要哈。
|
||||
/**
|
||||
* 根据名称删除报表
|
||||
*
|
||||
* @param name 报表名称
|
||||
* @return
|
||||
*/
|
||||
int deleteByName(String name);
|
||||
|
||||
// TODO @赤焰:这里直接返回 UReportDataDO 是不是更好?上层业务直接使用啦
|
||||
/**
|
||||
* 根据名称校验报表是否存在
|
||||
*
|
||||
* @param name 报表名称
|
||||
*/
|
||||
void validateUReportDataExists(String name);
|
||||
|
||||
// TODO @赤焰:这里方法名改成 getUReportDataByName。select 只用于 mapper;
|
||||
/**
|
||||
* 根据名称查询报表
|
||||
*
|
||||
* @param name 报表名称
|
||||
* @return Ureport2 报表
|
||||
*/
|
||||
UReportDataDO selectOneByName(String name);
|
||||
|
||||
/**
|
||||
* 获取全部报表
|
||||
*
|
||||
* @return 全部报表
|
||||
*/
|
||||
List<UReportDataDO> getReportDataList();
|
||||
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.service.ureport;
|
||||
|
||||
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 jakarta.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.UREPORT_DATA_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* Ureport2报表 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class UReportDataServiceImpl implements UReportDataService {
|
||||
|
||||
@Resource
|
||||
private UReportDataMapper uReportDataMapper;
|
||||
|
||||
@Override
|
||||
public Long createUReportData(UReportDataSaveReqVO createReqVO) {
|
||||
// TODO @赤焰:名字不要重复的校验,要加下
|
||||
UReportDataDO uReportData = BeanUtils.toBean(createReqVO, UReportDataDO.class);
|
||||
uReportDataMapper.insert(uReportData);
|
||||
return uReportData.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUReportData(UReportDataSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateUReportDataExists(updateReqVO.getId());
|
||||
// TODO @赤焰:名字不要重复的校验,要加下
|
||||
// 更新
|
||||
UReportDataDO updateObj = BeanUtils.toBean(updateReqVO, UReportDataDO.class);
|
||||
uReportDataMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUReportData(Long id) {
|
||||
// 校验存在
|
||||
validateUReportDataExists(id);
|
||||
// 删除
|
||||
uReportDataMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateUReportDataExists(Long id) {
|
||||
if (uReportDataMapper.selectById(id) == null) {
|
||||
throw exception(UREPORT_DATA_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateUReportDataExists(String name) {
|
||||
if (uReportDataMapper.selectListByName(name) == null) {
|
||||
throw exception(UREPORT_DATA_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UReportDataDO getUReportData(Long id) {
|
||||
return uReportDataMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<UReportDataDO> getUReportDataPage(UReportDataPageReqVO pageReqVO) {
|
||||
return uReportDataMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByName(String name) {
|
||||
return uReportDataMapper.deleteByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UReportDataDO selectOneByName(String name) {
|
||||
return uReportDataMapper.selectByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UReportDataDO> getReportDataList() {
|
||||
return uReportDataMapper.selectList();
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
## TODO ????????? application.yaml ?????
|
||||
ureport.disableHttpSessionReportCache=true
|
||||
ureport.disableFileProvider=true
|
||||
ureport.fileStoreDir=/WEB-INF/ureportfiles
|
||||
ureport.debug=true
|
@ -1,136 +0,0 @@
|
||||
package cn.iocoder.yudao.module.report.service.ureport;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataPageReqVO;
|
||||
import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UReportDataSaveReqVO;
|
||||
import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UReportDataDO;
|
||||
import cn.iocoder.yudao.module.report.dal.mysql.ureport.UReportDataMapper;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import jakarta.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.*;
|
||||
|
||||
/**
|
||||
* {@link UReportDataServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Disabled // TODO 芋艿:临时禁用,暂时不修复,等重构后解决
|
||||
@Import(UReportDataServiceImpl.class)
|
||||
public class UReportDataServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private UReportDataServiceImpl uReportDataService;
|
||||
|
||||
@Resource
|
||||
private UReportDataMapper uReportDataMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateUReportData_success() {
|
||||
// 准备参数
|
||||
UReportDataSaveReqVO createReqVO = randomPojo(UReportDataSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long uReportDataId = uReportDataService.createUReportData(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(uReportDataId);
|
||||
// 校验记录的属性是否正确
|
||||
UReportDataDO uReportData = uReportDataMapper.selectById(uReportDataId);
|
||||
assertPojoEquals(createReqVO, uReportData, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUReportData_success() {
|
||||
// mock 数据
|
||||
UReportDataDO dbUReportData = randomPojo(UReportDataDO.class);
|
||||
uReportDataMapper.insert(dbUReportData);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
UReportDataSaveReqVO updateReqVO = randomPojo(UReportDataSaveReqVO.class, o -> {
|
||||
o.setId(dbUReportData.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
uReportDataService.updateUReportData(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
UReportDataDO uReportData = uReportDataMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, uReportData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUReportData_notExists() {
|
||||
// 准备参数
|
||||
UReportDataSaveReqVO updateReqVO = randomPojo(UReportDataSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> uReportDataService.updateUReportData(updateReqVO), UREPORT_DATA_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteUReportData_success() {
|
||||
// mock 数据
|
||||
UReportDataDO dbUReportData = randomPojo(UReportDataDO.class);
|
||||
uReportDataMapper.insert(dbUReportData);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbUReportData.getId();
|
||||
|
||||
// 调用
|
||||
uReportDataService.deleteUReportData(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(uReportDataMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteUReportData_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> uReportDataService.deleteUReportData(id), UREPORT_DATA_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetUReportDataPage() {
|
||||
// mock 数据
|
||||
UReportDataDO dbUReportData = randomPojo(UReportDataDO.class, o -> { // 等会查询到
|
||||
o.setName(null);
|
||||
o.setStatus(null);
|
||||
o.setRemark(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
uReportDataMapper.insert(dbUReportData);
|
||||
// 测试 name 不匹配
|
||||
uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setName(null)));
|
||||
// 测试 status 不匹配
|
||||
uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setStatus(null)));
|
||||
// 测试 remark 不匹配
|
||||
uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setRemark(null)));
|
||||
// 测试 createTime 不匹配
|
||||
uReportDataMapper.insert(cloneIgnoreId(dbUReportData, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
UReportDataPageReqVO reqVO = new UReportDataPageReqVO();
|
||||
reqVO.setName(null);
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setRemark(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<UReportDataDO> pageResult = uReportDataService.getUReportDataPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbUReportData, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
@ -1,2 +1 @@
|
||||
DELETE FROM "report_go_view_project";
|
||||
DELETE FROM "report_ureport_data";
|
||||
DELETE FROM "report_go_view_project";
|
@ -12,16 +12,3 @@ CREATE TABLE IF NOT EXISTS "report_go_view_project" (
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT 'GoView 项目表';
|
||||
CREATE TABLE IF NOT EXISTS "report_ureport_data" (
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"name" varchar NOT NULL,
|
||||
"status" int NOT NULL,
|
||||
"content" varchar,
|
||||
"remark" varchar,
|
||||
"creator" varchar DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT 'Ureport2报表';
|
||||
|
Reference in New Issue
Block a user