From 5894d2be01511fef94d15046604ff5cd861b5fdb Mon Sep 17 00:00:00 2001 From: liuhongfeng <291117974@qq.com> Date: Wed, 22 Nov 2023 22:13:05 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91ureport2=20?= =?UTF-8?q?=E9=9B=86=E6=88=90=E7=9A=84SQL=E8=AF=AD=E5=8F=A5=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E9=80=82=E9=85=8D=E6=95=B0=E6=8D=AE=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tConfig.java => UreportConfiguration.java} | 12 ++-- .../ureport/config/UreportDataSource.java | 2 +- .../provider/UreportDatabaseProvider.java | 61 +++++++++---------- .../service/ureport/UreportFileService.java | 45 +++++++++++--- .../ureport/UreportFileServiceImpl.java | 54 ++++++++++++---- .../src/main/resources/ureport.properties | 6 +- .../src/main/resources/application.yaml | 7 +++ 7 files changed, 126 insertions(+), 61 deletions(-) rename yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/{UreportConfig.java => UreportConfiguration.java} (77%) diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfig.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfiguration.java similarity index 77% rename from yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfig.java rename to yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfiguration.java index 47841e101..6e3093f9e 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfig.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfiguration.java @@ -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 ureport2Servlet(){ + public ServletRegistrationBean registrationBean() { return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*"); } diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportDataSource.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportDataSource.java index 30c0be2df..9aeddfc72 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportDataSource.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportDataSource.java @@ -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; diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/provider/UreportDatabaseProvider.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/provider/UreportDatabaseProvider.java index f0949e7e7..ddaf7c7b0 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/provider/UreportDatabaseProvider.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/provider/UreportDatabaseProvider.java @@ -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 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 queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(UreportFileDO::getFileName, getCorrectName(file)); - ureportFileMapper.delete(queryWrapper); + ureportFileService.deleteReportFileByName(getCorrectName(file)); } @Override public List getReportFiles() { - LambdaQueryWrapper reportFileQueryWrapper = new LambdaQueryWrapper<>(); - List list = ureportFileMapper.selectList(reportFileQueryWrapper); + List list = ureportFileService.queryReportFileList(); List reportList = new ArrayList<>(); if(CollUtil.isEmpty(list)){ return reportList; @@ -88,19 +84,23 @@ public class UreportDatabaseProvider implements ReportProvider{ file = getCorrectName(file); LambdaQueryWrapper 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; } } -*/ diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileService.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileService.java index a7be5c1c6..ed26f187e 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileService.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileService.java @@ -1,18 +1,19 @@ 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 接口 * * @author 芋道源码 */ -public interface UreportFileService { +public interface UreportFileService { /** * 创建Ureport2报表 @@ -52,4 +53,34 @@ public interface UreportFileService { */ PageResult getUreportFilePage(UreportFilePageReqVO pageReqVO); -} \ No newline at end of file + + /** + * 根据报表名称检查报表是否存在 + * @param name 报表名称 + * @return + */ + Long checkExistByName(String name); + + /** + * 根据报表名称查询报表 + * @param name 报表名称 + * @return + */ + UreportFileDO queryUreportFileDoByName(String name); + + + /** + * 查询全部报表 + * @return + */ + List queryReportFileList(); + + + /** + * 根据报表名称删除报表 + * @param name + * @return + */ + int deleteReportFileByName(String name); + +} diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java index 3a6608f83..ccb47efd1 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java @@ -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); } -} \ No newline at end of file + @Override + public Long checkExistByName(String name) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(UreportFileDO::getFileName,name); + return ureportFileMapper.selectCount(queryWrapper); + } + + @Override + public UreportFileDO queryUreportFileDoByName(String name) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(UreportFileDO::getFileName,name); + List list = ureportFileMapper.selectList(queryWrapper); + if(CollectionUtil.isNotEmpty(list)){ + return list.get(0); + } + return null; + } + + @Override + public List queryReportFileList() { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + return ureportFileMapper.selectList(queryWrapper); + } + + @Override + public int deleteReportFileByName(String name) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(UreportFileDO::getFileName,name); + return ureportFileMapper.delete(queryWrapper); + } +} diff --git a/yudao-module-report/yudao-module-report-biz/src/main/resources/ureport.properties b/yudao-module-report/yudao-module-report-biz/src/main/resources/ureport.properties index c84e00dc1..a4f9313db 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/resources/ureport.properties +++ b/yudao-module-report/yudao-module-report-biz/src/main/resources/ureport.properties @@ -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 diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 954411022..c70e44b2f 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -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