一、項(xiàng)目結(jié)構(gòu)
新建報(bào)表微服務(wù)模塊,這是我的項(xiàng)目結(jié)構(gòu)圖。
二、執(zhí)行初始化數(shù)據(jù)腳本
運(yùn)行積木報(bào)表的初始化腳本,創(chuàng)建相關(guān)表結(jié)構(gòu),github速度太慢,推薦使用 gitee地址。選擇你要建表的數(shù)據(jù)庫,我是跟業(yè)務(wù)庫放到了一起,執(zhí)行完后會新增以下這幾張表。
三、pom中引入積木報(bào)表依賴
在頂級父pom中聲明積木報(bào)表的版本號:
<properties>
<jeccg.jimureport.version>1.5.6</jeccg.jimureport.version>
</properties>
在報(bào)表微服務(wù)模塊添加積木報(bào)表的依賴:
<!-- JimuReport -->
<dependency>
<groupId>org.jeecgframework.jimureport</groupId>
<artifactId>jimureport-spring-boot-starter</artifactId>
<version>${jeccg.jimureport.version}</version>
</dependency>
四、啟動類添加積木掃描目錄
在報(bào)表微服務(wù)啟動類上添加積木報(bào)表掃描注解,@SpringBootApplication(exclude = {MongoAutoConfiguration.class},
scanBasePackages = {"org.jeecg.modules.jmreport", "com.iotings.report"}),下面是完整的啟動類代碼塊:
package com.iotings.report;
import com.iotings.common.security.annotation.EnableCustomConfig;
import com.iotings.common.security.annotation.EnableRyFeignClients;
import com.iotings.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
/**
* @description: 報(bào)表中心模塊
* @author: wzlUp
* @date: 2023/06/16 17:05
* @motto: Done is better than perfect.
*/
@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
@SpringBootApplication(exclude = {MongoAutoConfiguration.class},
scanBasePackages = {"org.jeecg.modules.jmreport", "com.iotings.report"})
public class IotingsReportApplication {
public static void main(String[] args) {
SpringApplication.run(IotingsReportApplication.class, args);
System.out.println(
" .------------------------------------. \n" +
" : __ :\n" +
" : =='_)) __-:!:- :\n" +
" : ,.' .' ))-:!:- :\n" +
" : ((_,' .'-:!:- - Report Started - :\n" +
" : ~^~~~^~~^~~~^~ :\n" +
" `------------------------------------' ");
}
}
五、配置積木報(bào)表數(shù)據(jù)源
使用代碼方式進(jìn)行數(shù)據(jù)源的配置:
package com.iotings.report.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
/**
* @description: 數(shù)據(jù)源配置類
* @author: wzlUp
* @date: 2023/06/25 16:17
* @motto: Done is better than perfect.
*/
@Configuration
public class DataSourceConfig{
/**
* 1、bean的名稱必須為minidaoDataSource,否則不生效
* 2、jeecg.minidao-datasource對應(yīng)的是yml中的jeecg下的minidao-datasource,可自定義
*/
@Bean(name="minidaoDataSource")
@ConfigurationProperties(prefix = "jeecg.minidao-datasource")
public DataSource dataSource(){
return DataSourceBuilder.create().build();
}
}
六、報(bào)表微服務(wù)配置
在 nacos 中新建 iotings-report-dev.yml 配置文件
以下是我的完整配置數(shù)據(jù)項(xiàng):
# spring配置
spring:
redis:
host: 127.0.0.1
port: 6379
password: 123456
#Minidao配置
minidao :
base-package: org.jeecg.modules.jmreport.*
jeecg:
minidao-datasource:
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
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
hikari:
# 連接池最大連接數(shù)
maximum-pool-size: 400
# 空閑時(shí)保持最小連接數(shù)
minimum-idle: 20
# 空閑連接存活時(shí)間
idle-timeout: 30000
# 連接超時(shí)時(shí)間
connection-timeout: 1800000
#池中連接最長生命周期
max-lifetime: 1800000
jmreport:
#數(shù)據(jù)字典是否進(jìn)行saas數(shù)據(jù)隔離(限制只能看自己的字典)
saas: false
#是否 禁用導(dǎo)出PDF和圖片的按鈕 默認(rèn)為false
exportDisabled: false
#是否自動保存
autoSave: false
#自動保存間隔時(shí)間毫秒
interval: 20000
# 列索引
col: 300
#自定義項(xiàng)目前綴
customPrePath: /report
# 自定義API接口的前綴 #{api_base_path}的值
# apiBasePath: http://10.10.0.138:83/
#預(yù)覽分頁自定義
pageSize:
- 10
- 20
- 50
- 100
#打印紙張自定義
printPaper:
- title: 標(biāo)簽打印
size:
- 140
- 100
#接口超時(shí)設(shè)置(毫秒)
connect-timeout: 1800000
#Excel導(dǎo)出模式(fast/快、primary/精致模式,默認(rèn)fast)
export-excel-pattern: fast
#Excel導(dǎo)出數(shù)據(jù)每個(gè)sheet的行數(shù),每個(gè)sheet最大1048576行
page-size-number: 1048576
#excel樣式超過多少行顯示默認(rèn)樣式(只在fast模式下有效)
excel-style-row: 1048576
#預(yù)覽頁面的工具條 是否顯示 默認(rèn)true
viewToolbar: true
#設(shè)計(jì)頁面表格的線是否顯示 默認(rèn)true
line: true
#sql數(shù)據(jù)源不寫字典下拉框顯示條數(shù) 版本1.4.2之后被放棄
select-show-total: 10
# mybatis配置
mybatis:
# 搜索指定包別名
typeAliasesPackage: com.iotings.report
# 配置mapper的掃描,找到所有的mapper.xml映射文件
mapperLocations: classpath:mapper/**/*.xml
# knife4j配置
knife4j:
enable: true
# basic:
# enable: true
# username: iotings
# password: iotings2023
# swagger配置
swagger:
version: 1.0.0
title: 報(bào)表中心接口文檔
basePackage: com.iotings.report
termsOfServiceUrl: iotings-center
description: 報(bào)表中心系統(tǒng)接口的說明文檔
contact:
name: xxx
注意事項(xiàng):
- customPrePath路徑配置:需要跟網(wǎng)關(guān)的斷言【predicates】報(bào)表關(guān)鍵字保持一致,否則無法進(jìn)行正確的路由
七、網(wǎng)關(guān)微服務(wù)配置
在 iotings-gateway-dev.yml 配置文件中添加報(bào)表微服務(wù)的路由:
routes:
# 報(bào)表中心服務(wù)
- id: iotings-report
uri: lb://iotings-report
predicates:
- Path=/report/**
filters:
- StripPrefix=1
在 iotings-gateway-dev.yml 配置文件中添加積木報(bào)表的安全配置和不校驗(yàn)白名單:
# 安全配置
security:
# 驗(yàn)證碼
captcha:
enabled: true
type: math
# 防止XSS攻擊
xss:
enabled: true
excludeUrls:
- /system/notice
- /report/jmreport/**
# 不校驗(yàn)白名單
ignore:
whites:
- /auth/logout
- /auth/login
- /auth/register
- /*/v2/api-docs
- /csrf
- /message/websocket/**
- /report/**
八、擴(kuò)展:Token權(quán)限控制
package com.iotings.report.service.impl;
import com.iotings.common.core.utils.DateUtils;
import com.iotings.common.core.utils.StringUtils;
import com.iotings.common.security.service.TokenService;
import com.iotings.common.security.utils.SecurityUtils;
import com.iotings.system.api.model.LoginUser;
import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* @description: 自定義報(bào)表鑒權(quán)(如果不進(jìn)行自定義, 則所有請求不做權(quán)限控制)
* @author: wzlUp
* @date: 2023/06/25 16:37
* @motto: Done is better than perfect.
*/
@Component
public class JimuReportTokenServiceImpl implements JmReportTokenServiceI {
@Autowired
private TokenService tokenService;
/**
* 通過請求獲取Token
*/
@Override
public String getToken(HttpServletRequest request) {
String token = request.getParameter("token");
String jmToken = request.getHeader("token");
if (token == null || token.length() == 0) {
token = jmToken;
}
LoginUser loginUser = tokenService.getLoginUser(token);
if (loginUser != null) {
return token;
}
return "";
}
/**
* 獲取登錄人用戶名
*/
@Override
public String getUsername(String s) {
LoginUser loginUser = tokenService.getLoginUser(s);
return loginUser.getUsername();
}
/**
* Token校驗(yàn)
*/
@Override
public Boolean verifyToken(String s) {
if (s != null && s.length() > 0) {
LoginUser loginUser = tokenService.getLoginUser(s);
return loginUser != null;
}
return false;
}
/**
* 自定義請求頭
*/
@Override
public HttpHeaders customApiHeader() {
HttpHeaders header = new HttpHeaders();
header.add("X-Access-Token", SecurityUtils.getToken());
return header;
}
/**
* 獲取多租戶id
* @return tenantId
*/
public String getTenantId() {
String token = SecurityUtils.getCurrentRequestInfo().getParameter("token");
String header = SecurityUtils.getCurrentRequestInfo().getHeader("X-Access-Token");
LoginUser loginUser = null;
if (StringUtils.isNotBlank(token)) {
loginUser = tokenService.getLoginUser(token);
} else if (StringUtils.isNotBlank(header)) {
loginUser = tokenService.getLoginUser(header);
} else {
//都不具備則不能訪問
return "NO";
}
//具備admin或者管理員權(quán)限才可訪問所有報(bào)表
if (SecurityUtils.isAdmin(loginUser.getUserid())
|| loginUser.getRoles().contains("it")
|| loginUser.getRoles().contains("manger")) {
return "";
}
return loginUser.getUsername();
}
@Override
public Map<String, Object> getUserInfo(String token) {
// 將所有信息存放至map 解析sql會根據(jù)map的鍵值解析,可自定義其他值
Map<String, Object> map = new HashMap<>(20);
LoginUser loginUser = tokenService.getLoginUser(token);
map.put("sysUserCode", loginUser.getUsername());
//設(shè)置當(dāng)前日期(年月日)
map.put("sysData", DateUtils.getDate());
//設(shè)置昨天日期(年月日)
map.put("sysYesterDay", DateUtils.getYesterday());
//設(shè)置當(dāng)前登錄用戶昵稱
map.put("sysUserName", loginUser.getSysUser().getNickName());
//設(shè)置當(dāng)前登錄用戶部門ID
map.put("deptId", loginUser.getSysUser().getDeptId());
//設(shè)置當(dāng)前登錄用戶描述
// map.put("describe", loginUser.getSysUser().getDept().getDescribes());
map.put("describe", loginUser.getSysUser().getDept().getRemark());
return map;
}
}
九、前端頁面配置
在前端頁面中新建 jimureport 文件夾,新建以下vue文件
1、jimu.vue
<template>
<i-frame :src="openUrl" id="jimuReportFrame"></i-frame>
</template>
<script>
import { getToken } from '@/utils/auth'
import iFrame from '@/components/iFrame/index'
export default {
name: "Jimu",
components: {iFrame},
data() {
return {
// 這里寫暴露的統(tǒng)一的網(wǎng)關(guān)地址
openUrl: "http://127.0.0.1:8080/report/jmreport/list?token=" + getToken(),
};
},
mounted: function() {
}
};
</script>
2、view.vue
<template>
<i-frame :src="openUrl"/>
</template>
<script>
import {getToken} from '@/utils/auth'
import iFrame from "@/components/iFrame/index";
export default {
name: 'jimuview',
components: {iFrame},
props: {
reportID: {
type: [String],
required: false,
default: ''
},
},
data() {
return {
serverUrl: 'http://127.0.0.1:8080',
openUrl: '',
}
},
created() {
if (this.reportID.length != 0) {
this.openUrl = this.serverUrl + '/report/jmreport/view/' + this.reportID + '?token=' + getToken()
} else {
this.openUrl = this.serverUrl + '/report/jmreport/view/' + this.$route.path.substring(this.$route.path.lastIndexOf("/") + 1) + '?token=' + getToken()
}
console.log(this.openUrl)
}
}
</script>
<style scoped>
</style>
十、配置報(bào)表菜單
先新建一個(gè)主類目,我是建立了一個(gè)二級菜單,這個(gè)可以自定義,隨意配置
添加二級目錄
十一、集成效果展示
集成后的頁面
模板案例頁面
報(bào)表的設(shè)計(jì)頁面文章來源:http://www.zghlxwxcb.cn/news/detail-500889.html
預(yù)覽頁面文章來源地址http://www.zghlxwxcb.cn/news/detail-500889.html
十二、參考資料
- 若依微服務(wù)版本
- 若依cloud集成積木報(bào)表
- 若依cloud微服務(wù)集成積木報(bào)表
- ruoyi vue版集成積木報(bào)表
- 關(guān)于報(bào)表訪問權(quán)限認(rèn)證方案
到了這里,關(guān)于若依微服務(wù)版本集成積木報(bào)表的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!