当前位置:   article > 正文

1.若依微服务版本集成积木报表_若依 积木报表

若依 积木报表

一、项目结构

新建报表微服务模块,这是我的项目结构图。

二、执行初始化数据脚本

运行积木报表的初始化脚本,创建相关表结构,github速度太慢,推荐使用 gitee地址。选择你要建表的数据库,我是跟业务库放到了一起,执行完后会新增以下这几张表。

三、pom中引入积木报表依赖

在顶级父pom中声明积木报表的版本号:

  1. <properties>
  2. <jeccg.jimureport.version>1.5.6</jeccg.jimureport.version>
  3. </properties>

在报表微服务模块添加积木报表的依赖:

  1. <!-- JimuReport -->
  2. <dependency>
  3. <groupId>org.jeecgframework.jimureport</groupId>
  4. <artifactId>jimureport-spring-boot-starter</artifactId>
  5. <version>${jeccg.jimureport.version}</version>
  6. </dependency>

四、启动类添加积木扫描目录

在报表微服务启动类上添加积木报表扫描注解,@SpringBootApplication(exclude = {MongoAutoConfiguration.class},
scanBasePackages = {"org.jeecg.modules.jmreport", "com.iotings.report"}),下面是完整的启动类代码块:

  1. package com.iotings.report;
  2. import com.iotings.common.security.annotation.EnableCustomConfig;
  3. import com.iotings.common.security.annotation.EnableRyFeignClients;
  4. import com.iotings.common.swagger.annotation.EnableCustomSwagger2;
  5. import org.springframework.boot.SpringApplication;
  6. import org.springframework.boot.autoconfigure.SpringBootApplication;
  7. import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
  8. /**
  9. * @description: 报表中心模块
  10. * @author: wzlUp
  11. * @date: 2023/06/16 17:05
  12. * @motto: Done is better than perfect.
  13. */
  14. @EnableCustomConfig
  15. @EnableCustomSwagger2
  16. @EnableRyFeignClients
  17. @SpringBootApplication(exclude = {MongoAutoConfiguration.class},
  18. scanBasePackages = {"org.jeecg.modules.jmreport", "com.iotings.report"})
  19. public class IotingsReportApplication {
  20. public static void main(String[] args) {
  21. SpringApplication.run(IotingsReportApplication.class, args);
  22. System.out.println(
  23. " .------------------------------------. \n" +
  24. " : __ :\n" +
  25. " : =='_)) __-:!:- :\n" +
  26. " : ,.' .' ))-:!:- :\n" +
  27. " : ((_,' .'-:!:- - Report Started - :\n" +
  28. " : ~^~~~^~~^~~~^~ :\n" +
  29. " `------------------------------------' ");
  30. }
  31. }

五、配置积木报表数据源

使用代码方式进行数据源的配置:

  1. package com.iotings.report.config;
  2. import org.springframework.boot.context.properties.ConfigurationProperties;
  3. import org.springframework.boot.jdbc.DataSourceBuilder;
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.context.annotation.Configuration;
  6. import javax.sql.DataSource;
  7. /**
  8. * @description: 数据源配置类
  9. * @author: wzlUp
  10. * @date: 2023/06/25 16:17
  11. * @motto: Done is better than perfect.
  12. */
  13. @Configuration
  14. public class DataSourceConfig{
  15. /**
  16. * 1、bean的名称必须为minidaoDataSource,否则不生效
  17. * 2、jeecg.minidao-datasource对应的是yml中的jeecg下的minidao-datasource,可自定义
  18. */
  19. @Bean(name="minidaoDataSource")
  20. @ConfigurationProperties(prefix = "jeecg.minidao-datasource")
  21. public DataSource dataSource(){
  22. return DataSourceBuilder.create().build();
  23. }
  24. }

六、报表微服务配置

在 nacos 中新建 iotings-report-dev.yml 配置文件

以下是我的完整配置数据项:

  1. # spring配置
  2. spring:
  3. redis:
  4. host: 127.0.0.1
  5. port: 6379
  6. password: 123456
  7. #Minidao配置
  8. minidao :
  9. base-package: org.jeecg.modules.jmreport.*
  10. jeecg:
  11. minidao-datasource:
  12. jdbc-url: jdbc:mysql://127.0.0.1:3306/ry-cloud?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2b8
  13. username: root
  14. password: 123456
  15. driver-class-name: com.mysql.cj.jdbc.Driver
  16. hikari:
  17. # 连接池最大连接数
  18. maximum-pool-size: 400
  19. # 空闲时保持最小连接数
  20. minimum-idle: 20
  21. # 空闲连接存活时间
  22. idle-timeout: 30000
  23. # 连接超时时间
  24. connection-timeout: 1800000
  25. #池中连接最长生命周期
  26. max-lifetime: 1800000
  27. jmreport:
  28. #数据字典是否进行saas数据隔离(限制只能看自己的字典)
  29. saas: false
  30. #是否 禁用导出PDF和图片的按钮 默认为false
  31. exportDisabled: false
  32. #是否自动保存
  33. autoSave: false
  34. #自动保存间隔时间毫秒
  35. interval: 20000
  36. # 列索引
  37. col: 300
  38. #自定义项目前缀
  39. customPrePath: /report
  40. # 自定义API接口的前缀 #{api_base_path}的值
  41. # apiBasePath: http://10.10.0.138:83/
  42. #预览分页自定义
  43. pageSize:
  44. - 10
  45. - 20
  46. - 50
  47. - 100
  48. #打印纸张自定义
  49. printPaper:
  50. - title: 标签打印
  51. size:
  52. - 140
  53. - 100
  54. #接口超时设置(毫秒)
  55. connect-timeout: 1800000
  56. #Excel导出模式(fast/快、primary/精致模式,默认fast)
  57. export-excel-pattern: fast
  58. #Excel导出数据每个sheet的行数,每个sheet最大1048576
  59. page-size-number: 1048576
  60. #excel样式超过多少行显示默认样式(只在fast模式下有效)
  61. excel-style-row: 1048576
  62. #预览页面的工具条 是否显示 默认true
  63. viewToolbar: true
  64. #设计页面表格的线是否显示 默认true
  65. line: true
  66. #sql数据源不写字典下拉框显示条数 版本1.4.2之后被放弃
  67. select-show-total: 10
  68. # mybatis配置
  69. mybatis:
  70. # 搜索指定包别名
  71. typeAliasesPackage: com.iotings.report
  72. # 配置mapper的扫描,找到所有的mapper.xml映射文件
  73. mapperLocations: classpath:mapper/**/*.xml
  74. # knife4j配置
  75. knife4j:
  76. enable: true
  77. # basic:
  78. # enable: true
  79. # username: iotings
  80. # password: iotings2023
  81. # swagger配置
  82. swagger:
  83. version: 1.0.0
  84. title: 报表中心接口文档
  85. basePackage: com.iotings.report
  86. termsOfServiceUrl: iotings-center
  87. description: 报表中心系统接口的说明文档
  88. contact:
  89. name: xxx

注意事项:

  • customPrePath路径配置:需要跟网关的断言【predicates】报表关键字保持一致,否则无法进行正确的路由

七、网关微服务配置

在 iotings-gateway-dev.yml 配置文件中添加报表微服务的路由:

  1. routes:
  2. # 报表中心服务
  3. - id: iotings-report
  4. uri: lb://iotings-report
  5. predicates:
  6. - Path=/report/**
  7. filters:
  8. - StripPrefix=1

在 iotings-gateway-dev.yml 配置文件中添加积木报表的安全配置和不校验白名单:

  1. # 安全配置
  2. security:
  3. # 验证码
  4. captcha:
  5. enabled: true
  6. type: math
  7. # 防止XSS攻击
  8. xss:
  9. enabled: true
  10. excludeUrls:
  11. - /system/notice
  12. - /report/jmreport/**
  13. # 不校验白名单
  14. ignore:
  15. whites:
  16. - /auth/logout
  17. - /auth/login
  18. - /auth/register
  19. - /*/v2/api-docs
  20. - /csrf
  21. - /message/websocket/**
  22. - /report/**

八、扩展:Token权限控制

  1. package com.iotings.report.service.impl;
  2. import com.iotings.common.core.utils.DateUtils;
  3. import com.iotings.common.core.utils.StringUtils;
  4. import com.iotings.common.security.service.TokenService;
  5. import com.iotings.common.security.utils.SecurityUtils;
  6. import com.iotings.system.api.model.LoginUser;
  7. import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.http.HttpHeaders;
  10. import org.springframework.stereotype.Component;
  11. import javax.servlet.http.HttpServletRequest;
  12. import java.util.HashMap;
  13. import java.util.Map;
  14. /**
  15. * @description: 自定义报表鉴权(如果不进行自定义, 则所有请求不做权限控制)
  16. * @author: wzlUp
  17. * @date: 2023/06/25 16:37
  18. * @motto: Done is better than perfect.
  19. */
  20. @Component
  21. public class JimuReportTokenServiceImpl implements JmReportTokenServiceI {
  22. @Autowired
  23. private TokenService tokenService;
  24. /**
  25. * 通过请求获取Token
  26. */
  27. @Override
  28. public String getToken(HttpServletRequest request) {
  29. String token = request.getParameter("token");
  30. String jmToken = request.getHeader("token");
  31. if (token == null || token.length() == 0) {
  32. token = jmToken;
  33. }
  34. LoginUser loginUser = tokenService.getLoginUser(token);
  35. if (loginUser != null) {
  36. return token;
  37. }
  38. return "";
  39. }
  40. /**
  41. * 获取登录人用户名
  42. */
  43. @Override
  44. public String getUsername(String s) {
  45. LoginUser loginUser = tokenService.getLoginUser(s);
  46. return loginUser.getUsername();
  47. }
  48. /**
  49. * Token校验
  50. */
  51. @Override
  52. public Boolean verifyToken(String s) {
  53. if (s != null && s.length() > 0) {
  54. LoginUser loginUser = tokenService.getLoginUser(s);
  55. return loginUser != null;
  56. }
  57. return false;
  58. }
  59. /**
  60. * 自定义请求头
  61. */
  62. @Override
  63. public HttpHeaders customApiHeader() {
  64. HttpHeaders header = new HttpHeaders();
  65. header.add("X-Access-Token", SecurityUtils.getToken());
  66. return header;
  67. }
  68. /**
  69. * 获取多租户id
  70. * @return tenantId
  71. */
  72. public String getTenantId() {
  73. String token = SecurityUtils.getCurrentRequestInfo().getParameter("token");
  74. String header = SecurityUtils.getCurrentRequestInfo().getHeader("X-Access-Token");
  75. LoginUser loginUser = null;
  76. if (StringUtils.isNotBlank(token)) {
  77. loginUser = tokenService.getLoginUser(token);
  78. } else if (StringUtils.isNotBlank(header)) {
  79. loginUser = tokenService.getLoginUser(header);
  80. } else {
  81. //都不具备则不能访问
  82. return "NO";
  83. }
  84. //具备admin或者管理员权限才可访问所有报表
  85. if (SecurityUtils.isAdmin(loginUser.getUserid())
  86. || loginUser.getRoles().contains("it")
  87. || loginUser.getRoles().contains("manger")) {
  88. return "";
  89. }
  90. return loginUser.getUsername();
  91. }
  92. @Override
  93. public Map<String, Object> getUserInfo(String token) {
  94. // 将所有信息存放至map 解析sql会根据map的键值解析,可自定义其他值
  95. Map<String, Object> map = new HashMap<>(20);
  96. LoginUser loginUser = tokenService.getLoginUser(token);
  97. map.put("sysUserCode", loginUser.getUsername());
  98. //设置当前日期(年月日)
  99. map.put("sysData", DateUtils.getDate());
  100. //设置昨天日期(年月日)
  101. map.put("sysYesterDay", DateUtils.getYesterday());
  102. //设置当前登录用户昵称
  103. map.put("sysUserName", loginUser.getSysUser().getNickName());
  104. //设置当前登录用户部门ID
  105. map.put("deptId", loginUser.getSysUser().getDeptId());
  106. //设置当前登录用户描述
  107. // map.put("describe", loginUser.getSysUser().getDept().getDescribes());
  108. map.put("describe", loginUser.getSysUser().getDept().getRemark());
  109. return map;
  110. }
  111. }

九、前端页面配置

在前端页面中新建 jimureport 文件夹,新建以下vue文件

1、jimu.vue
  1. <template>
  2. <i-frame :src="openUrl" id="jimuReportFrame"></i-frame>
  3. </template>
  4. <script>
  5. import { getToken } from '@/utils/auth'
  6. import iFrame from '@/components/iFrame/index'
  7. export default {
  8. name: "Jimu",
  9. components: {iFrame},
  10. data() {
  11. return {
  12. // 这里写暴露的统一的网关地址
  13. openUrl: "http://127.0.0.1:8080/report/jmreport/list?token=" + getToken(),
  14. };
  15. },
  16. mounted: function() {
  17. }
  18. };
  19. </script>
2、view.vue
  1. <template>
  2. <i-frame :src="openUrl"/>
  3. </template>
  4. <script>
  5. import {getToken} from '@/utils/auth'
  6. import iFrame from "@/components/iFrame/index";
  7. export default {
  8. name: 'jimuview',
  9. components: {iFrame},
  10. props: {
  11. reportID: {
  12. type: [String],
  13. required: false,
  14. default: ''
  15. },
  16. },
  17. data() {
  18. return {
  19. serverUrl: 'http://127.0.0.1:8080',
  20. openUrl: '',
  21. }
  22. },
  23. created() {
  24. if (this.reportID.length != 0) {
  25. this.openUrl = this.serverUrl + '/report/jmreport/view/' + this.reportID + '?token=' + getToken()
  26. } else {
  27. this.openUrl = this.serverUrl + '/report/jmreport/view/' + this.$route.path.substring(this.$route.path.lastIndexOf("/") + 1) + '?token=' + getToken()
  28. }
  29. console.log(this.openUrl)
  30. }
  31. }
  32. </script>
  33. <style scoped>
  34. </style>

十、配置报表菜单

先新建一个主类目,我是建立了一个二级菜单,这个可以自定义,随意配置

添加二级目录

十一、集成效果展示

集成后的页面

模板案例页面

报表的设计页面

预览页面

十二、参考资料

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/735117
推荐阅读
相关标签
  

闽ICP备14008679号