Commit 5894d2be01511fef94d15046604ff5cd861b5fdb
Committed by
YunaiV
1 parent
7c43c3a2
【修改】ureport2 集成的SQL语句,并适配数据库存储方式
Showing
7 changed files
with
126 additions
and
61 deletions
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/config/UreportConfig.java renamed to 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; | @@ -12,17 +12,15 @@ import javax.servlet.Servlet; | ||
| 12 | /** | 12 | /** |
| 13 | * Ureport 配置类 | 13 | * Ureport 配置类 |
| 14 | * 加载ureport对应的xml配置文件 | 14 | * 加载ureport对应的xml配置文件 |
| 15 | + * @author 赤焰 | ||
| 15 | */ | 16 | */ |
| 16 | -@PropertySource(value = {"classpath:ureport.properties"}) | ||
| 17 | -@ImportResource("classpath:ureport-console-context.xml") | ||
| 18 | @Configuration | 17 | @Configuration |
| 19 | -public class UreportConfig{ | 18 | +@ImportResource({"classpath:ureport-console-context.xml"}) |
| 19 | +@PropertySource(value = {"classpath:ureport.properties"}) | ||
| 20 | +public class UreportConfiguration { | ||
| 20 | 21 | ||
| 21 | - /** | ||
| 22 | - * ureport2报表Servlet配置 | ||
| 23 | - */ | ||
| 24 | @Bean | 22 | @Bean |
| 25 | - public ServletRegistrationBean<Servlet> ureport2Servlet(){ | 23 | + public ServletRegistrationBean<Servlet> registrationBean() { |
| 26 | return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*"); | 24 | return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*"); |
| 27 | } | 25 | } |
| 28 | 26 |
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; | @@ -16,7 +16,7 @@ import java.sql.SQLException; | ||
| 16 | @Component | 16 | @Component |
| 17 | public class UreportDataSource implements BuildinDatasource { | 17 | public class UreportDataSource implements BuildinDatasource { |
| 18 | 18 | ||
| 19 | - private static final String NAME = "本机数据源"; | 19 | + private static final String NAME = "UreportDataSource"; |
| 20 | 20 | ||
| 21 | @Resource | 21 | @Resource |
| 22 | private DataSource dataSource; | 22 | private DataSource dataSource; |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/ureport/provider/UreportDatabaseProvider.java
| 1 | -/* | ||
| 2 | package cn.iocoder.yudao.module.report.framework.ureport.provider; | 1 | package cn.iocoder.yudao.module.report.framework.ureport.provider; |
| 3 | 2 | ||
| 3 | +import cn.hutool.core.bean.BeanUtil; | ||
| 4 | import cn.hutool.core.collection.CollUtil; | 4 | import cn.hutool.core.collection.CollUtil; |
| 5 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 6 | +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO; | ||
| 5 | import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | 7 | import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; |
| 6 | -import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper; | 8 | +import cn.iocoder.yudao.module.report.service.ureport.UreportFileService; |
| 7 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 9 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 8 | import com.bstek.ureport.provider.report.ReportFile; | 10 | import com.bstek.ureport.provider.report.ReportFile; |
| 9 | import com.bstek.ureport.provider.report.ReportProvider; | 11 | import com.bstek.ureport.provider.report.ReportProvider; |
| @@ -26,49 +28,43 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU | @@ -26,49 +28,43 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU | ||
| 26 | import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_EXISTS; | 28 | import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_EXISTS; |
| 27 | import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS; | 29 | import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS; |
| 28 | 30 | ||
| 29 | -*/ | ||
| 30 | /** | 31 | /** |
| 31 | * 提供数据库的存储方式 | 32 | * 提供数据库的存储方式 |
| 32 | * @author 赤焰 | 33 | * @author 赤焰 |
| 33 | - *//* | ||
| 34 | - | 34 | + */ |
| 35 | @Slf4j | 35 | @Slf4j |
| 36 | +@Setter | ||
| 36 | @Component | 37 | @Component |
| 37 | @ConfigurationProperties(prefix = "ureport.provider.database") | 38 | @ConfigurationProperties(prefix = "ureport.provider.database") |
| 38 | public class UreportDatabaseProvider implements ReportProvider{ | 39 | public class UreportDatabaseProvider implements ReportProvider{ |
| 39 | 40 | ||
| 40 | - private static final String NAME = "数据库存储系统"; | ||
| 41 | - | ||
| 42 | - private String prefix = "db:"; | 41 | + private static final String NAME = "mysql-provider"; |
| 43 | 42 | ||
| 44 | - private boolean disabled; | 43 | + private String prefix = "mysql:"; |
| 45 | 44 | ||
| 45 | + private boolean disabled = false; | ||
| 46 | @Resource | 46 | @Resource |
| 47 | - private UreportFileMapper ureportFileMapper; | 47 | + private UreportFileService ureportFileService; |
| 48 | 48 | ||
| 49 | @Override | 49 | @Override |
| 50 | public InputStream loadReport(String file) { | 50 | public InputStream loadReport(String file) { |
| 51 | - LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 52 | - queryWrapper.eq(UreportFileDO::getFileName, getCorrectName(file)); | ||
| 53 | - UreportFileDO reportDo = ureportFileMapper.selectOne(queryWrapper); | ||
| 54 | - if (reportDo == null) { | 51 | + Long reportDo = ureportFileService.checkExistByName(getCorrectName(file)); |
| 52 | + if (reportDo <=0) { | ||
| 55 | throw exception(UREPORT_FILE_NOT_EXISTS); | 53 | throw exception(UREPORT_FILE_NOT_EXISTS); |
| 56 | } | 54 | } |
| 57 | - byte[] content = reportDo.getFileContent(); | 55 | + UreportFileDO ureportFileDO = ureportFileService.queryUreportFileDoByName(getCorrectName(file)); |
| 56 | + byte[] content = ureportFileDO.getFileContent(); | ||
| 58 | return new ByteArrayInputStream(content); | 57 | return new ByteArrayInputStream(content); |
| 59 | } | 58 | } |
| 60 | 59 | ||
| 61 | @Override | 60 | @Override |
| 62 | public void deleteReport(String file) { | 61 | public void deleteReport(String file) { |
| 63 | - LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 64 | - queryWrapper.eq(UreportFileDO::getFileName, getCorrectName(file)); | ||
| 65 | - ureportFileMapper.delete(queryWrapper); | 62 | + ureportFileService.deleteReportFileByName(getCorrectName(file)); |
| 66 | } | 63 | } |
| 67 | 64 | ||
| 68 | @Override | 65 | @Override |
| 69 | public List<ReportFile> getReportFiles() { | 66 | public List<ReportFile> getReportFiles() { |
| 70 | - LambdaQueryWrapper<UreportFileDO> reportFileQueryWrapper = new LambdaQueryWrapper<>(); | ||
| 71 | - List<UreportFileDO> list = ureportFileMapper.selectList(reportFileQueryWrapper); | 67 | + List<UreportFileDO> list = ureportFileService.queryReportFileList(); |
| 72 | List<ReportFile> reportList = new ArrayList<>(); | 68 | List<ReportFile> reportList = new ArrayList<>(); |
| 73 | if(CollUtil.isEmpty(list)){ | 69 | if(CollUtil.isEmpty(list)){ |
| 74 | return reportList; | 70 | return reportList; |
| @@ -88,19 +84,23 @@ public class UreportDatabaseProvider implements ReportProvider{ | @@ -88,19 +84,23 @@ public class UreportDatabaseProvider implements ReportProvider{ | ||
| 88 | file = getCorrectName(file); | 84 | file = getCorrectName(file); |
| 89 | LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); | 85 | LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); |
| 90 | queryWrapper.eq(UreportFileDO::getFileName, file); | 86 | queryWrapper.eq(UreportFileDO::getFileName, file); |
| 91 | - Long count = ureportFileMapper.selectCount(queryWrapper); | 87 | + Long count = ureportFileService.checkExistByName(file); |
| 92 | if(count>1){ | 88 | if(count>1){ |
| 93 | throw exception(UREPORT_FILE_EXISTS); | 89 | throw exception(UREPORT_FILE_EXISTS); |
| 94 | } | 90 | } |
| 95 | - UreportFileDO ureportFileDO = ureportFileMapper.selectOne(queryWrapper); | 91 | + UreportFileDO ureportFileDO = ureportFileService.queryUreportFileDoByName(file); |
| 92 | + UreportFileSaveReqVO saveReqVO = new UreportFileSaveReqVO(); | ||
| 96 | if (ureportFileDO == null) { | 93 | if (ureportFileDO == null) { |
| 97 | - ureportFileDO = new UreportFileDO(); | ||
| 98 | - ureportFileDO.setFileName(file); | ||
| 99 | - ureportFileDO.setFileContent(content.getBytes()); | ||
| 100 | - ureportFileMapper.insert(ureportFileDO); | 94 | + saveReqVO.setFileName(file); |
| 95 | + saveReqVO.setFileContent(content); | ||
| 96 | + saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 97 | + ureportFileService.createUreportFile(saveReqVO); | ||
| 101 | } else { | 98 | } else { |
| 102 | - ureportFileDO.setFileContent(content.getBytes()); | ||
| 103 | - ureportFileMapper.update(ureportFileDO, queryWrapper); | 99 | + saveReqVO.setId(ureportFileDO.getId()); |
| 100 | + saveReqVO.setFileName(file); | ||
| 101 | + saveReqVO.setFileContent(content); | ||
| 102 | + saveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 103 | + ureportFileService.updateUreportFile(saveReqVO); | ||
| 104 | } | 104 | } |
| 105 | } | 105 | } |
| 106 | 106 | ||
| @@ -120,10 +120,9 @@ public class UreportDatabaseProvider implements ReportProvider{ | @@ -120,10 +120,9 @@ public class UreportDatabaseProvider implements ReportProvider{ | ||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | private String getCorrectName(String name) { | 122 | private String getCorrectName(String name) { |
| 123 | - if (name.startsWith(prefix)) { | ||
| 124 | - name = name.substring(prefix.length(), name.length()); | 123 | + if (name.startsWith(getPrefix())) { |
| 124 | + name = name.substring(getPrefix().length()); | ||
| 125 | } | 125 | } |
| 126 | return name; | 126 | return name; |
| 127 | } | 127 | } |
| 128 | } | 128 | } |
| 129 | -*/ |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileService.java
| 1 | package cn.iocoder.yudao.module.report.service.ureport; | 1 | package cn.iocoder.yudao.module.report.service.ureport; |
| 2 | 2 | ||
| 3 | -import java.util.*; | ||
| 4 | -import javax.validation.*; | ||
| 5 | -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; | ||
| 6 | -import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | ||
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | 4 | +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO; |
| 5 | +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | ||
| 7 | + | ||
| 8 | +import javax.validation.Valid; | ||
| 9 | +import java.util.List; | ||
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| 11 | * Ureport2报表 Service 接口 | 12 | * Ureport2报表 Service 接口 |
| 12 | * | 13 | * |
| 13 | * @author 芋道源码 | 14 | * @author 芋道源码 |
| 14 | */ | 15 | */ |
| 15 | -public interface UreportFileService { | 16 | +public interface UreportFileService { |
| 16 | 17 | ||
| 17 | /** | 18 | /** |
| 18 | * 创建Ureport2报表 | 19 | * 创建Ureport2报表 |
| @@ -52,4 +53,34 @@ public interface UreportFileService { | @@ -52,4 +53,34 @@ public interface UreportFileService { | ||
| 52 | */ | 53 | */ |
| 53 | PageResult<UreportFileDO> getUreportFilePage(UreportFilePageReqVO pageReqVO); | 54 | PageResult<UreportFileDO> getUreportFilePage(UreportFilePageReqVO pageReqVO); |
| 54 | 55 | ||
| 55 | -} | ||
| 56 | \ No newline at end of file | 56 | \ No newline at end of file |
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * 根据报表名称检查报表是否存在 | ||
| 60 | + * @param name 报表名称 | ||
| 61 | + * @return | ||
| 62 | + */ | ||
| 63 | + Long checkExistByName(String name); | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 根据报表名称查询报表 | ||
| 67 | + * @param name 报表名称 | ||
| 68 | + * @return | ||
| 69 | + */ | ||
| 70 | + UreportFileDO queryUreportFileDoByName(String name); | ||
| 71 | + | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * 查询全部报表 | ||
| 75 | + * @return | ||
| 76 | + */ | ||
| 77 | + List<UreportFileDO> queryReportFileList(); | ||
| 78 | + | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * 根据报表名称删除报表 | ||
| 82 | + * @param name | ||
| 83 | + * @return | ||
| 84 | + */ | ||
| 85 | + int deleteReportFileByName(String name); | ||
| 86 | + | ||
| 87 | +} |
yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/service/ureport/UreportFileServiceImpl.java
| 1 | package cn.iocoder.yudao.module.report.service.ureport; | 1 | package cn.iocoder.yudao.module.report.service.ureport; |
| 2 | 2 | ||
| 3 | -import org.springframework.stereotype.Service; | ||
| 4 | -import javax.annotation.Resource; | ||
| 5 | -import org.springframework.validation.annotation.Validated; | ||
| 6 | -import org.springframework.transaction.annotation.Transactional; | ||
| 7 | - | ||
| 8 | -import java.util.*; | ||
| 9 | -import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.*; | ||
| 10 | -import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | 3 | +import cn.hutool.core.collection.CollectionUtil; |
| 11 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 12 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 13 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 14 | - | 6 | +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFilePageReqVO; |
| 7 | +import cn.iocoder.yudao.module.report.controller.admin.ureport.vo.UreportFileSaveReqVO; | ||
| 8 | +import cn.iocoder.yudao.module.report.dal.dataobject.ureport.UreportFileDO; | ||
| 15 | import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper; | 9 | import cn.iocoder.yudao.module.report.dal.mysql.ureport.UreportFileMapper; |
| 10 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
| 11 | +import org.springframework.stereotype.Service; | ||
| 12 | +import org.springframework.validation.annotation.Validated; | ||
| 13 | + | ||
| 14 | +import javax.annotation.Resource; | ||
| 15 | +import java.util.List; | ||
| 16 | 16 | ||
| 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 18 | -import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.*; | 18 | +import static cn.iocoder.yudao.module.report.enums.ErrorCodeConstants.UREPORT_FILE_NOT_EXISTS; |
| 19 | 19 | ||
| 20 | /** | 20 | /** |
| 21 | * Ureport2报表 Service 实现类 | 21 | * Ureport2报表 Service 实现类 |
| @@ -71,4 +71,34 @@ public class UreportFileServiceImpl implements UreportFileService { | @@ -71,4 +71,34 @@ public class UreportFileServiceImpl implements UreportFileService { | ||
| 71 | return ureportFileMapper.selectPage(pageReqVO); | 71 | return ureportFileMapper.selectPage(pageReqVO); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | -} | ||
| 75 | \ No newline at end of file | 74 | \ No newline at end of file |
| 75 | + @Override | ||
| 76 | + public Long checkExistByName(String name) { | ||
| 77 | + LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 78 | + queryWrapper.eq(UreportFileDO::getFileName,name); | ||
| 79 | + return ureportFileMapper.selectCount(queryWrapper); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Override | ||
| 83 | + public UreportFileDO queryUreportFileDoByName(String name) { | ||
| 84 | + LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 85 | + queryWrapper.eq(UreportFileDO::getFileName,name); | ||
| 86 | + List<UreportFileDO> list = ureportFileMapper.selectList(queryWrapper); | ||
| 87 | + if(CollectionUtil.isNotEmpty(list)){ | ||
| 88 | + return list.get(0); | ||
| 89 | + } | ||
| 90 | + return null; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 94 | + public List<UreportFileDO> queryReportFileList() { | ||
| 95 | + LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 96 | + return ureportFileMapper.selectList(queryWrapper); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + @Override | ||
| 100 | + public int deleteReportFileByName(String name) { | ||
| 101 | + LambdaQueryWrapper<UreportFileDO> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 102 | + queryWrapper.eq(UreportFileDO::getFileName,name); | ||
| 103 | + return ureportFileMapper.delete(queryWrapper); | ||
| 104 | + } | ||
| 105 | +} |
yudao-module-report/yudao-module-report-biz/src/main/resources/ureport.properties
yudao-server/src/main/resources/application.yaml
| @@ -190,6 +190,7 @@ yudao: | @@ -190,6 +190,7 @@ yudao: | ||
| 190 | - /admin-api/system/sms/callback/* # 短信回调接口,无法带上租户编号 | 190 | - /admin-api/system/sms/callback/* # 短信回调接口,无法带上租户编号 |
| 191 | - /admin-api/pay/notify/** # 支付回调通知,不携带租户编号 | 191 | - /admin-api/pay/notify/** # 支付回调通知,不携带租户编号 |
| 192 | - /jmreport/* # 积木报表,无法携带租户编号 | 192 | - /jmreport/* # 积木报表,无法携带租户编号 |
| 193 | + - /ureport/* # ureport报表,无法携带租户编号 | ||
| 193 | - /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,无法携带租户编号 | 194 | - /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,无法携带租户编号 |
| 194 | ignore-tables: | 195 | ignore-tables: |
| 195 | - system_tenant | 196 | - system_tenant |
| @@ -228,6 +229,7 @@ yudao: | @@ -228,6 +229,7 @@ yudao: | ||
| 228 | - jimu_report_link | 229 | - jimu_report_link |
| 229 | - jimu_report_map | 230 | - jimu_report_map |
| 230 | - jimu_report_share | 231 | - jimu_report_share |
| 232 | + - ureport_file | ||
| 231 | - rep_demo_dxtj | 233 | - rep_demo_dxtj |
| 232 | - rep_demo_employee | 234 | - rep_demo_employee |
| 233 | - rep_demo_gongsi | 235 | - rep_demo_gongsi |
| @@ -261,3 +263,8 @@ debug: false | @@ -261,3 +263,8 @@ debug: false | ||
| 261 | minidao : | 263 | minidao : |
| 262 | base-package: org.jeecg.modules.jmreport.desreport.dao* | 264 | base-package: org.jeecg.modules.jmreport.desreport.dao* |
| 263 | db-type: mysql | 265 | db-type: mysql |
| 266 | +#ureport配置 | ||
| 267 | +ureport: | ||
| 268 | + provider: | ||
| 269 | + database: | ||
| 270 | + disabled: false |