【修改】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对应的xml配置文件
* @author 赤焰
*/
@PropertySource(value = {"classpath:ureport.properties"})
@ImportResource("classpath:ureport-console-context.xml")
@Configuration
public class UreportConfig{
@ImportResource({"classpath:ureport-console-context.xml"})
@PropertySource(value = {"classpath:ureport.properties"})
public class UreportConfiguration {
/**
* ureport2报表Servlet配置
*/
@Bean
public ServletRegistrationBean<Servlet> ureport2Servlet(){
public ServletRegistrationBean<Servlet> registrationBean() {
return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*");
}

View File

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

View File

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

View File

@ -1,11 +1,12 @@
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;
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 接口
@ -52,4 +53,34 @@ public interface UreportFileService {
*/
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;
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.hutool.core.collection.CollectionUtil;
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.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 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.module.report.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS;
/**
* Ureport2报表 Service 实现类
@ -71,4 +71,34 @@ public class UreportFileServiceImpl implements UreportFileService {
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.disableFileProvider=false
ureport.fileStoreDir=D:\\ureport\\files
ureport.disableHttpSessionReportCache=true
ureport.disableFileProvider=true
ureport.fileStoreDir=/WEB-INF/ureportfiles
ureport.debug=true

View File

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