【修改】ureport2 集成的SQL语句,并适配数据库存储方式

This commit is contained in:
liuhongfeng 2023-11-22 22:13:05 +08:00 committed by YunaiV
parent 7c43c3a2b1
commit 5894d2be01
7 changed files with 126 additions and 61 deletions

View File

@ -12,17 +12,15 @@ import javax.servlet.Servlet;
/** /**
* Ureport 配置类 * Ureport 配置类
* 加载ureport对应的xml配置文件 * 加载ureport对应的xml配置文件
* @author 赤焰
*/ */
@PropertySource(value = {"classpath:ureport.properties"})
@ImportResource("classpath:ureport-console-context.xml")
@Configuration @Configuration
public class UreportConfig{ @ImportResource({"classpath:ureport-console-context.xml"})
@PropertySource(value = {"classpath:ureport.properties"})
public class UreportConfiguration {
/**
* ureport2报表Servlet配置
*/
@Bean @Bean
public ServletRegistrationBean<Servlet> ureport2Servlet(){ public ServletRegistrationBean<Servlet> registrationBean() {
return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*"); return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*");
} }

View File

@ -16,7 +16,7 @@ import java.sql.SQLException;
@Component @Component
public class UreportDataSource implements BuildinDatasource { public class UreportDataSource implements BuildinDatasource {
private static final String NAME = "本机数据源"; private static final String NAME = "UreportDataSource";
@Resource @Resource
private DataSource dataSource; private DataSource dataSource;

View File

@ -1,9 +1,11 @@
/*
package cn.iocoder.yudao.module.report.framework.ureport.provider; package cn.iocoder.yudao.module.report.framework.ureport.provider;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper; import cn.iocoder.yudao.module.report.service.ureport.UreportFileService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bstek.ureport.provider.report.ReportFile; import com.bstek.ureport.provider.report.ReportFile;
import com.bstek.ureport.provider.report.ReportProvider; import com.bstek.ureport.provider.report.ReportProvider;
@ -26,49 +28,43 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_EXISTS; 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; import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS;
*/
/** /**
* 提供数据库的存储方式 * 提供数据库的存储方式
* @author 赤焰 * @author 赤焰
*//* */
@Slf4j @Slf4j
@Setter
@Component @Component
@ConfigurationProperties(prefix = "ureport.provider.database") @ConfigurationProperties(prefix = "ureport.provider.database")
public class UreportDatabaseProvider implements ReportProvider{ public class UreportDatabaseProvider implements ReportProvider{
private static final String NAME = "数据库存储系统"; private static final String NAME = "mysql-provider";
private String prefix = "db:"; private String prefix = "mysql:";
private boolean disabled;
private boolean disabled = false;
@Resource @Resource
private UreportFileMapper ureportFileMapper; private UreportFileService ureportFileService;
@Override @Override
public InputStream loadReport(String file) { public InputStream loadReport(String file) {
LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); Long reportDo = ureportFileService.checkExistByName(getCorrectName(file));
queryWrapper.eq(UreportFileDO::getFileName, getCorrectName(file)); if (reportDo <=0) {
UreportFileDO reportDo = ureportFileMapper.selectOne(queryWrapper);
if (reportDo == null) {
throw exception(UREPORT_FILE_NOT_EXISTS); throw exception(UREPORT_FILE_NOT_EXISTS);
} }
byte[] content = reportDo.getFileContent(); UreportFileDO ureportFileDO = ureportFileService.queryUreportFileDoByName(getCorrectName(file));
byte[] content = ureportFileDO.getFileContent();
return new ByteArrayInputStream(content); return new ByteArrayInputStream(content);
} }
@Override @Override
public void deleteReport(String file) { public void deleteReport(String file) {
LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); ureportFileService.deleteReportFileByName(getCorrectName(file));
queryWrapper.eq(UreportFileDO::getFileName, getCorrectName(file));
ureportFileMapper.delete(queryWrapper);
} }
@Override @Override
public List<ReportFile> getReportFiles() { public List<ReportFile> getReportFiles() {
LambdaQueryWrapper<UreportFileDO> reportFileQueryWrapper = new LambdaQueryWrapper<>(); List<UreportFileDO> list = ureportFileService.queryReportFileList();
List<UreportFileDO> list = ureportFileMapper.selectList(reportFileQueryWrapper);
List<ReportFile> reportList = new ArrayList<>(); List<ReportFile> reportList = new ArrayList<>();
if(CollUtil.isEmpty(list)){ if(CollUtil.isEmpty(list)){
return reportList; return reportList;
@ -88,19 +84,23 @@ public class UreportDatabaseProvider implements ReportProvider{
file = getCorrectName(file); file = getCorrectName(file);
LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(UreportFileDO::getFileName, file); queryWrapper.eq(UreportFileDO::getFileName, file);
Long count = ureportFileMapper.selectCount(queryWrapper); Long count = ureportFileService.checkExistByName(file);
if(count>1){ if(count>1){
throw exception(UREPORT_FILE_EXISTS); throw exception(UREPORT_FILE_EXISTS);
} }
UreportFileDO ureportFileDO = ureportFileMapper.selectOne(queryWrapper); UreportFileDO ureportFileDO = ureportFileService.queryUreportFileDoByName(file);
UreportFileSaveReqVO saveReqVO = new UreportFileSaveReqVO();
if (ureportFileDO == null) { if (ureportFileDO == null) {
ureportFileDO = new UreportFileDO(); saveReqVO.setFileName(file);
ureportFileDO.setFileName(file); saveReqVO.setFileContent(content);
ureportFileDO.setFileContent(content.getBytes()); saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
ureportFileMapper.insert(ureportFileDO); ureportFileService.createUreportFile(saveReqVO);
} else { } else {
ureportFileDO.setFileContent(content.getBytes()); saveReqVO.setId(ureportFileDO.getId());
ureportFileMapper.update(ureportFileDO, queryWrapper); saveReqVO.setFileName(file);
saveReqVO.setFileContent(content);
saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
ureportFileService.updateUreportFile(saveReqVO);
} }
} }
@ -120,10 +120,9 @@ public class UreportDatabaseProvider implements ReportProvider{
} }
private String getCorrectName(String name) { private String getCorrectName(String name) {
if (name.startsWith(prefix)) { if (name.startsWith(getPrefix())) {
name = name.substring(prefix.length(), name.length()); name = name.substring(getPrefix().length());
} }
return name; return name;
} }
} }
*/

View File

@ -1,11 +1,12 @@
package cn.iocoder.yudao.module.report.service.ureport; 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.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO;
import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
import javax.validation.Valid;
import java.util.List;
/** /**
* Ureport2报表 Service 接口 * Ureport2报表 Service 接口
@ -52,4 +53,34 @@ public interface UreportFileService {
*/ */
PageResult<UreportFileDO> getUreportFilePage(UreportFilePageReqVO pageReqVO); PageResult<UreportFileDO> getUreportFilePage(UreportFilePageReqVO pageReqVO);
/**
* 根据报表名称检查报表是否存在
* @param name 报表名称
* @return
*/
Long checkExistByName(String name);
/**
* 根据报表名称查询报表
* @param name 报表名称
* @return
*/
UreportFileDO queryUreportFileDoByName(String name);
/**
* 查询全部报表
* @return
*/
List<UreportFileDO> queryReportFileList();
/**
* 根据报表名称删除报表
* @param name
* @return
*/
int deleteReportFileByName(String name);
} }

View File

@ -1,21 +1,21 @@
package cn.iocoder.yudao.module.report.service.ureport; package cn.iocoder.yudao.module.report.service.ureport;
import org.springframework.stereotype.Service; import cn.hutool.core.collection.CollectionUtil;
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.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO;
import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO;
import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO;
import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper; import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS;
/** /**
* Ureport2报表 Service 实现类 * Ureport2报表 Service 实现类
@ -71,4 +71,34 @@ public class UreportFileServiceImpl implements UreportFileService {
return ureportFileMapper.selectPage(pageReqVO); return ureportFileMapper.selectPage(pageReqVO);
} }
@Override
public Long checkExistByName(String name) {
LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(UreportFileDO::getFileName,name);
return ureportFileMapper.selectCount(queryWrapper);
}
@Override
public UreportFileDO queryUreportFileDoByName(String name) {
LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(UreportFileDO::getFileName,name);
List<UreportFileDO> list = ureportFileMapper.selectList(queryWrapper);
if(CollectionUtil.isNotEmpty(list)){
return list.get(0);
}
return null;
}
@Override
public List<UreportFileDO> queryReportFileList() {
LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
return ureportFileMapper.selectList(queryWrapper);
}
@Override
public int deleteReportFileByName(String name) {
LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(UreportFileDO::getFileName,name);
return ureportFileMapper.delete(queryWrapper);
}
} }

View File

@ -1,4 +1,4 @@
ureport.disableHttpSessionReportCache=false ureport.disableHttpSessionReportCache=true
ureport.disableFileProvider=false ureport.disableFileProvider=true
ureport.fileStoreDir=D:\\ureport\\files ureport.fileStoreDir=/WEB-INF/ureportfiles
ureport.debug=true ureport.debug=true

View File

@ -190,6 +190,7 @@ yudao:
- /admin-api/system/sms/callback/* # 短信回调接口,无法带上租户编号 - /admin-api/system/sms/callback/* # 短信回调接口,无法带上租户编号
- /admin-api/pay/notify/** # 支付回调通知,不携带租户编号 - /admin-api/pay/notify/** # 支付回调通知,不携带租户编号
- /jmreport/* # 积木报表,无法携带租户编号 - /jmreport/* # 积木报表,无法携带租户编号
- /ureport/* # ureport报表无法携带租户编号
- /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,无法携带租户编号 - /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,无法携带租户编号
ignore-tables: ignore-tables:
- system_tenant - system_tenant
@ -228,6 +229,7 @@ yudao:
- jimu_report_link - jimu_report_link
- jimu_report_map - jimu_report_map
- jimu_report_share - jimu_report_share
- ureport_file
- rep_demo_dxtj - rep_demo_dxtj
- rep_demo_employee - rep_demo_employee
- rep_demo_gongsi - rep_demo_gongsi
@ -261,3 +263,8 @@ debug: false
minidao : minidao :
base-package: org.jeecg.modules.jmreport.desreport.dao* base-package: org.jeecg.modules.jmreport.desreport.dao*
db-type: mysql db-type: mysql
#ureport配置
ureport:
provider:
database:
disabled: false