Compare commits
399 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
d488b79c2d | |
|
|
f53b783049 | |
|
|
97f30a5415 | |
|
|
ad1d009165 | |
|
|
90cbabb7a7 | |
|
|
1c4dbb1e46 | |
|
|
a3eefb6bad | |
|
|
09e8e9995a | |
|
|
381151bc50 | |
|
|
66e502727a | |
|
|
4265f8ecb7 | |
|
|
2c82079d04 | |
|
|
6aecd35a4f | |
|
|
ac92ae3ae6 | |
|
|
1d2c8378f7 | |
|
|
50a9337ee8 | |
|
|
e6a3415a71 | |
|
|
7919af54da | |
|
|
3503005f9d | |
|
|
b304a41194 | |
|
|
a39ae33c82 | |
|
|
b9a27657c5 | |
|
|
2e009841ca | |
|
|
2cbe4a8234 | |
|
|
4b37049713 | |
|
|
e549210ad6 | |
|
|
ad988d54bb | |
|
|
51a6fce0a5 | |
|
|
c86bfa9243 | |
|
|
8aca11c2a2 | |
|
|
725033e361 | |
|
|
d29e49e23b | |
|
|
706c3bb69b | |
|
|
cd0ee95b9c | |
|
|
3293e2fb56 | |
|
|
924ec0eb6e | |
|
|
135b1204a9 | |
|
|
cb566a704b | |
|
|
aadba0382e | |
|
|
a0ce1cf33b | |
|
|
3915c77391 | |
|
|
b80932ceb4 | |
|
|
056cf94082 | |
|
|
0dcd3e6183 | |
|
|
07be5ceb26 | |
|
|
cc59502d7c | |
|
|
98738f23ad | |
|
|
57fe1c663e | |
|
|
7b6fdb3a89 | |
|
|
79c885decb | |
|
|
1a0f37a2dc | |
|
|
02de344d8c | |
|
|
189100f74e | |
|
|
e29284e687 | |
|
|
d4af286f41 | |
|
|
60e2d55a23 | |
|
|
bbd112d5a3 | |
|
|
90922844ea | |
|
|
3a9f56f04b | |
|
|
a1ec1d57d4 | |
|
|
060959a7c5 | |
|
|
43e1d8d573 | |
|
|
67cf51ba77 | |
|
|
a256618d5d | |
|
|
a6bcebb62b | |
|
|
1cb262daa3 | |
|
|
8c096cba8d | |
|
|
088cec8adf | |
|
|
85ff6a9910 | |
|
|
cab5beaca7 | |
|
|
fc8069a250 | |
|
|
924e705dca | |
|
|
049ba453d1 | |
|
|
4aa261e8f7 | |
|
|
914a6620f5 | |
|
|
3dcee7057d | |
|
|
0467631319 | |
|
|
a11df90255 | |
|
|
596e4fe756 | |
|
|
37219e4ae6 | |
|
|
adaa3e1db8 | |
|
|
88ad5a2c19 | |
|
|
b45dc2ec25 | |
|
|
67b17da06f | |
|
|
b25a280ebb | |
|
|
cc026e75a3 | |
|
|
7216b56a56 | |
|
|
a326e880a1 | |
|
|
92c6d21855 | |
|
|
2335157f6e | |
|
|
6c3b01c3c5 | |
|
|
8faea60191 | |
|
|
28a16d9878 | |
|
|
dd3cf18e27 | |
|
|
65d03dc014 | |
|
|
7912fd81bd | |
|
|
e2175e5b9d | |
|
|
c0e119f8e0 | |
|
|
fa77b2a08c | |
|
|
a222c24796 | |
|
|
08f4b877ce | |
|
|
aa607d135c | |
|
|
6d34cdb8a3 | |
|
|
d47352253e | |
|
|
61cbd470e1 | |
|
|
b3ef4adfed | |
|
|
856c471472 | |
|
|
bec5600f16 | |
|
|
5b485e7934 | |
|
|
73a752d3ab | |
|
|
1899a832b9 | |
|
|
e6796c0954 | |
|
|
4987289a98 | |
|
|
18409922a5 | |
|
|
3dca02b306 | |
|
|
75f3275e15 | |
|
|
b2e4a7046b | |
|
|
60618c1da9 | |
|
|
3b499b1344 | |
|
|
8984ecba86 | |
|
|
0953a9c0b2 | |
|
|
fcff9dfdea | |
|
|
d1cb4e1f71 | |
|
|
68ef1297cb | |
|
|
b79f01e051 | |
|
|
095f3a126f | |
|
|
ce94a9d620 | |
|
|
2a73de34f0 | |
|
|
8694501a7e | |
|
|
4dfc3d766e | |
|
|
0680d1ed1f | |
|
|
493dee03c8 | |
|
|
3992b1e666 | |
|
|
c855884ebd | |
|
|
19c457ae5f | |
|
|
1a3751ab71 | |
|
|
af8d62e5e2 | |
|
|
cf03781bd7 | |
|
|
fa2a28e877 | |
|
|
e2f1b31735 | |
|
|
488aafb683 | |
|
|
735273d69f | |
|
|
f2a587c2f9 | |
|
|
4f7bcef44c | |
|
|
393a9326c8 | |
|
|
33a52c8166 | |
|
|
b44e0e4de6 | |
|
|
3fa4901d57 | |
|
|
2dca6f0a12 | |
|
|
78e61d89ba | |
|
|
4908b6230b | |
|
|
f6d4f5c6e3 | |
|
|
1580c1e672 | |
|
|
6ff45b2644 | |
|
|
ae77c82304 | |
|
|
41c2d6fc2a | |
|
|
d0e9e07e9c | |
|
|
210626b21f | |
|
|
85ab6236e7 | |
|
|
0037e65ca0 | |
|
|
adec3f0608 | |
|
|
e7adf59b88 | |
|
|
21a17945fa | |
|
|
b7abcd8374 | |
|
|
2eeb642f07 | |
|
|
4512af436d | |
|
|
6a8964f086 | |
|
|
75b2eb067d | |
|
|
2eaabefeac | |
|
|
c3ab80967c | |
|
|
892e3ac822 | |
|
|
e2b4bb0420 | |
|
|
d6b4806e43 | |
|
|
7df1b02476 | |
|
|
6d9cbe218c | |
|
|
302299bbb0 | |
|
|
437301d5d9 | |
|
|
dc121ff4aa | |
|
|
c4cda3f4ad | |
|
|
e067c04464 | |
|
|
af03fefc83 | |
|
|
2d49f2a56e | |
|
|
2af351f898 | |
|
|
a709c8f06e | |
|
|
b00775f988 | |
|
|
48711178ec | |
|
|
07bb636109 | |
|
|
24e0fa863e | |
|
|
fb6d93fbab | |
|
|
db18477786 | |
|
|
91575613a8 | |
|
|
a5354083b9 | |
|
|
1665fa2793 | |
|
|
df8d6bcd33 | |
|
|
2fecc6273b | |
|
|
8b252709a4 | |
|
|
b2cb085f21 | |
|
|
1b1bc96bd5 | |
|
|
a416d55780 | |
|
|
1994aff544 | |
|
|
b18eced03d | |
|
|
ee2fef02f8 | |
|
|
ad954dacb7 | |
|
|
10de4eb96d | |
|
|
a5b612c8e4 | |
|
|
ebc848b5b5 | |
|
|
f31c207551 | |
|
|
dd338b56da | |
|
|
7c3d7b384c | |
|
|
0647ca8b66 | |
|
|
f3477f75e6 | |
|
|
22fa7ac6f6 | |
|
|
924aafae86 | |
|
|
5280fb5a0d | |
|
|
d3c6ba2598 | |
|
|
08308d61c7 | |
|
|
356b451b2a | |
|
|
a606973cbe | |
|
|
19fb27502b | |
|
|
d7b309afd9 | |
|
|
d9bfc3e322 | |
|
|
74045776d6 | |
|
|
5fcec99e6c | |
|
|
102a5ac575 | |
|
|
3786f3671d | |
|
|
49e6fbf2ff | |
|
|
81a8192de7 | |
|
|
a366d09659 | |
|
|
2fe7341fa7 | |
|
|
a3615e5c6c | |
|
|
68eac98acf | |
|
|
d4bae9745c | |
|
|
23ae0eb43b | |
|
|
308d497d74 | |
|
|
7af254ee51 | |
|
|
2ad13c9f72 | |
|
|
56d50d10e9 | |
|
|
0b21d15f26 | |
|
|
7421d7ccce | |
|
|
84ba2dbd93 | |
|
|
55447c72e9 | |
|
|
26c63520f2 | |
|
|
8b52b90670 | |
|
|
05ca78e82f | |
|
|
b155059d66 | |
|
|
f8ad7ea3ce | |
|
|
feff419641 | |
|
|
33a0806cbe | |
|
|
230e2bb3f4 | |
|
|
24d9ccba40 | |
|
|
dc24ed81b8 | |
|
|
504a4e8e66 | |
|
|
775234dabe | |
|
|
7fdd20c054 | |
|
|
1eeed86b65 | |
|
|
7c9903e057 | |
|
|
20dd6d37ea | |
|
|
89a04423cd | |
|
|
c42b4cad02 | |
|
|
4b21a3bc48 | |
|
|
1ef82d75b1 | |
|
|
c10a3b6dbb | |
|
|
b93c9bfc5d | |
|
|
cd5556d188 | |
|
|
1126e2234f | |
|
|
dce91a03ef | |
|
|
8dff14a6cc | |
|
|
3462c58ce4 | |
|
|
6c3e88ee6d | |
|
|
da2e5a2d93 | |
|
|
12c51fc8e3 | |
|
|
736b6348bc | |
|
|
6317e902e3 | |
|
|
94590a008d | |
|
|
8b5acaf341 | |
|
|
8eb22e86e0 | |
|
|
853040cd42 | |
|
|
17364e2699 | |
|
|
9f48ff40d2 | |
|
|
f93fc98b4f | |
|
|
c03a671de8 | |
|
|
6d6d5140fe | |
|
|
f016006224 | |
|
|
abcc045cad | |
|
|
d76fab1d0c | |
|
|
a0d2b383ef | |
|
|
af33456ca8 | |
|
|
3d2f9aa9c6 | |
|
|
a8be0ccb35 | |
|
|
f646bfc0f5 | |
|
|
6efd427f79 | |
|
|
04a042c585 | |
|
|
ee3f03f1f1 | |
|
|
b1a67a113e | |
|
|
bc1c1dbfa7 | |
|
|
7a112c7317 | |
|
|
d2bd73b4dc | |
|
|
a211d93092 | |
|
|
a9938302f0 | |
|
|
6e5d7a6dab | |
|
|
7a3892a77a | |
|
|
e0a5e704b0 | |
|
|
d936ce76b1 | |
|
|
f2320d356d | |
|
|
b50e79bbde | |
|
|
295b5d5cfd | |
|
|
8f4ac612c8 | |
|
|
b3f9e1f2de | |
|
|
bcbc9d7adc | |
|
|
6421f68964 | |
|
|
652f4372c0 | |
|
|
cff5fe93a5 | |
|
|
c759728269 | |
|
|
58e07ba142 | |
|
|
43b336d26b | |
|
|
8eeb73eabb | |
|
|
98c3e4b48a | |
|
|
839366f2b0 | |
|
|
65cf05fddb | |
|
|
a9a8f94ae2 | |
|
|
1617c74d4d | |
|
|
01c1505340 | |
|
|
c2708f2ba4 | |
|
|
48a0d5bc9d | |
|
|
a057b7a4b9 | |
|
|
0e4a1c872c | |
|
|
5faa1af464 | |
|
|
0dfbb5fbf3 | |
|
|
3b4f1d7937 | |
|
|
07c2e08e4a | |
|
|
e03cebac57 | |
|
|
0c36921587 | |
|
|
53b84261f8 | |
|
|
11de8aa17b | |
|
|
f250c6ee93 | |
|
|
fd89356ed7 | |
|
|
ad54d36385 | |
|
|
3cf088a0d8 | |
|
|
22fac34b82 | |
|
|
7f0f842651 | |
|
|
1124c27f06 | |
|
|
adbba02cb8 | |
|
|
5b6dc85b62 | |
|
|
62eec4df51 | |
|
|
11d8274462 | |
|
|
732071ef58 | |
|
|
afa23c2111 | |
|
|
4bf9f3cff5 | |
|
|
8c7986acdb | |
|
|
52d50e4e47 | |
|
|
f0bfff1ff3 | |
|
|
a37315d513 | |
|
|
479755650c | |
|
|
73256dfeaf | |
|
|
767f7c8621 | |
|
|
12d335b9ac | |
|
|
bc7a743998 | |
|
|
ca36f9fc6e | |
|
|
8345eed709 | |
|
|
2af8e817bd | |
|
|
fcb58876e7 | |
|
|
d4c61daf9b | |
|
|
31523867e7 | |
|
|
a8daa1f044 | |
|
|
858f576fa3 | |
|
|
c960108b12 | |
|
|
59b867dcca | |
|
|
b9fdc4de87 | |
|
|
d504a7df2f | |
|
|
2a675aa304 | |
|
|
d6df1fe7b3 | |
|
|
428255ddcf | |
|
|
a92ca233aa | |
|
|
537105b2a9 | |
|
|
d56ef651e3 | |
|
|
9d21b1627b | |
|
|
467557fef3 | |
|
|
c8a108b93a | |
|
|
5408af9d1f | |
|
|
e7b9e12d15 | |
|
|
a4b714b95a | |
|
|
4ae26c2f86 | |
|
|
b51c127eb7 | |
|
|
c5eb7458c8 | |
|
|
347a717d5c | |
|
|
0484c63d9b | |
|
|
4d21c11acd | |
|
|
8fdb3c4d14 | |
|
|
0ef63207f4 | |
|
|
1295177393 | |
|
|
67a6841043 | |
|
|
d4930f6a88 | |
|
|
c98f452431 | |
|
|
fb35360f81 | |
|
|
5e20f99a99 | |
|
|
9f90b4eba7 | |
|
|
ce82095f04 | |
|
|
9ebd484f46 | |
|
|
cc0e184314 |
15
README.md
15
README.md
|
|
@ -1,11 +1,11 @@
|
|||
<p align="center">
|
||||
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-b99b286755aef70355a7084753f89cdb7c9.png">
|
||||
</p>
|
||||
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi v3.6.0</h1>
|
||||
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi v3.6.6</h1>
|
||||
<h4 align="center">基于 Vue/Element UI 和 Spring Boot/Spring Cloud & Alibaba 前后端分离的分布式微服务架构</h4>
|
||||
<p align="center">
|
||||
<a href="https://gitee.com/y_project/RuoYi-Cloud/stargazers"><img src="https://gitee.com/y_project/RuoYi-Cloud/badge/star.svg?theme=dark"></a>
|
||||
<a href="https://gitee.com/y_project/RuoYi-Cloud"><img src="https://img.shields.io/badge/RuoYi-v3.6.0-brightgreen.svg"></a>
|
||||
<a href="https://gitee.com/y_project/RuoYi-Cloud"><img src="https://img.shields.io/badge/RuoYi-v3.6.6-brightgreen.svg"></a>
|
||||
<a href="https://gitee.com/y_project/RuoYi-Cloud/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
|
||||
</p>
|
||||
|
||||
|
|
@ -17,12 +17,9 @@
|
|||
* 后端采用Spring Boot、Spring Cloud & Alibaba。
|
||||
* 注册中心、配置中心选型Nacos,权限认证使用Redis。
|
||||
* 流量控制框架选型Sentinel,分布式事务选型Seata。
|
||||
* 提供了技术栈([Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev))版本[RuoYi-Cloud-Vue3](https://github.com/yangzongzhuan/RuoYi-Cloud-Vue3),保持同步更新。
|
||||
* 提供了技术栈([Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev))版本[RuoYi-Cloud-Vue3](https://gitcode.com/yangzongzhuan/RuoYi-Cloud-Vue3),保持同步更新。
|
||||
* 如需不分离应用,请移步 [RuoYi](https://gitee.com/y_project/RuoYi),如需分离应用,请移步 [RuoYi-Vue](https://gitee.com/y_project/RuoYi-Vue)
|
||||
* 阿里云折扣场:[点我进入](http://aly.ruoyi.vip),腾讯云秒杀场:[点我进入](http://txy.ruoyi.vip)
|
||||
* 阿里云优惠券:[点我领取](https://www.aliyun.com/minisite/goods?userCode=brki8iof&share_source=copy_link),腾讯云优惠券:[点我领取](https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=198c8df2ed259157187173bc7f4f32fd&from=console)
|
||||
|
||||
#### 友情链接 [若依/RuoYi-Cloud](https://gitee.com/zhangmrit/ruoyi-cloud) Ant Design版本。
|
||||
* 阿里云优惠券:[点我进入](http://aly.ruoyi.vip),腾讯云优惠券:[点我进入](http://txy.ruoyi.vip)
|
||||
|
||||
## 系统模块
|
||||
|
||||
|
|
@ -39,7 +36,9 @@ com.ruoyi
|
|||
│ └── ruoyi-common-datasource // 多数据源
|
||||
│ └── ruoyi-common-log // 日志记录
|
||||
│ └── ruoyi-common-redis // 缓存服务
|
||||
│ └── ruoyi-common-seata // 分布式事务
|
||||
│ └── ruoyi-common-security // 安全模块
|
||||
│ └── ruoyi-common-sensitive // 数据脱敏
|
||||
│ └── ruoyi-common-swagger // 系统接口
|
||||
├── ruoyi-modules // 业务模块
|
||||
│ └── ruoyi-system // 系统模块 [9201]
|
||||
|
|
@ -127,4 +126,4 @@ com.ruoyi
|
|||
|
||||
## 若依微服务交流群
|
||||
|
||||
QQ群: [](https://jq.qq.com/?_wv=1027&k=yqInfq0S) [](https://jq.qq.com/?_wv=1027&k=Oy1mb3p8) [](https://jq.qq.com/?_wv=1027&k=rvxkJtXK) [](https://jq.qq.com/?_wv=1027&k=0Ck3PvTe) [](https://jq.qq.com/?_wv=1027&k=FnHHP4TT) [](https://jq.qq.com/?_wv=1027&k=qdT1Ojpz) [](https://jq.qq.com/?_wv=1027&k=nw3OiyXs) [](https://jq.qq.com/?_wv=1027&k=kiU5WDls) 点击按钮入群。
|
||||
QQ群: [](https://jq.qq.com/?_wv=1027&k=yqInfq0S) [](https://jq.qq.com/?_wv=1027&k=Oy1mb3p8) [](https://jq.qq.com/?_wv=1027&k=rvxkJtXK) [](https://jq.qq.com/?_wv=1027&k=0Ck3PvTe) [](https://jq.qq.com/?_wv=1027&k=FnHHP4TT) [](https://jq.qq.com/?_wv=1027&k=qdT1Ojpz) [](https://jq.qq.com/?_wv=1027&k=nw3OiyXs) [](https://jq.qq.com/?_wv=1027&k=kiU5WDls) [](https://jq.qq.com/?_wv=1027&k=MtBy6YfT) [](https://jq.qq.com/?_wv=1027&k=FqImHgH2) [](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=G4jZ4EtdT50PhnMBudTnEwgonxkXOscJ&authKey=FkGHYfoTKlGE6wHdKdjH9bVoOgQjtLP9WM%2Fj7pqGY1msoqw9uxDiBo39E2mLgzYg&noverify=0&group_code=128355254) [](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=irnwcXhbLOQEv1g-TwGifjNTA_f4wZiA&authKey=4bpzEwhcUY%2FvsPDHvzYn6xfoS%2FtOArvZ%2BGXzfr7O0%2FEqLfkKA%2BuCDXlzHIFg8t93&noverify=0&group_code=179219821) [](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=lx1uEdEDuxeM7rUvF3qmlFdqKqdJ5Z-R&authKey=rgyPW9yhhh4IIURKVFa6NgP3qiqH04WAzrJ0trsgkr3pjzm6sKIOGyA58oOjoj%2FJ&noverify=0&group_code=158753145) [](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=Kuaw0Xdlw2Nlgn6s8h9elzuquHGxGObD&authKey=cSrQcWQ%2BzQZAFFrwxaR%2BbzcumX4WRduZnd1O6JO1dlclQMiu%2BKwxAy8t2JfNp67V&noverify=0&group_code=112869560) 点击按钮入群。
|
||||
|
|
@ -9,8 +9,8 @@ usage() {
|
|||
|
||||
# copy sql
|
||||
echo "begin copy sql "
|
||||
cp ../sql/ry_20210908.sql ./mysql/db
|
||||
cp ../sql/ry_config_20220114.sql ./mysql/db
|
||||
cp ../sql/ry_20250523.sql ./mysql/db
|
||||
cp ../sql/ry_config_20250224.sql ./mysql/db
|
||||
|
||||
# copy html
|
||||
echo "begin copy html "
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ management.metrics.export.influx.enabled=false
|
|||
server.tomcat.accesslog.enabled=true
|
||||
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
|
||||
|
||||
server.tomcat.basedir=
|
||||
server.tomcat.basedir=/home/ruoyi/nacos/tomcat/logs
|
||||
|
||||
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
|
||||
|
||||
|
|
|
|||
|
|
@ -28,9 +28,14 @@ http {
|
|||
proxy_pass http://ruoyi-gateway:8080/;
|
||||
}
|
||||
|
||||
# 避免actuator暴露
|
||||
if ($uri ~ "/actuator") {
|
||||
return 403;
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root html;
|
||||
}
|
||||
}
|
||||
}# requirepass 123456
|
||||
}
|
||||
159
pom.xml
159
pom.xml
|
|
@ -6,46 +6,53 @@
|
|||
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
|
||||
<name>ruoyi</name>
|
||||
<url>http://www.ruoyi.vip</url>
|
||||
<description>若依微服务系统</description>
|
||||
|
||||
<properties>
|
||||
<ruoyi.version>3.6.0</ruoyi.version>
|
||||
<ruoyi.version>3.6.6</ruoyi.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-boot.version>2.7.1</spring-boot.version>
|
||||
<spring-cloud.version>2021.0.3</spring-cloud.version>
|
||||
<spring-cloud-alibaba.version>2021.0.1.0</spring-cloud-alibaba.version>
|
||||
<alibaba.nacos.version>2.0.4</alibaba.nacos.version>
|
||||
<alibaba.seata.version>1.5.1</alibaba.seata.version>
|
||||
<spring-boot-admin.version>2.7.2</spring-boot-admin.version>
|
||||
<spring-boot.mybatis>2.2.2</spring-boot.mybatis>
|
||||
<swagger.fox.version>3.0.0</swagger.fox.version>
|
||||
<swagger.core.version>1.6.2</swagger.core.version>
|
||||
<spring-boot.version>2.7.18</spring-boot.version>
|
||||
<spring-cloud.version>2021.0.9</spring-cloud.version>
|
||||
<spring-cloud-alibaba.version>2021.0.6.1</spring-cloud-alibaba.version>
|
||||
<spring-boot-admin.version>2.7.16</spring-boot-admin.version>
|
||||
<tobato.version>1.27.2</tobato.version>
|
||||
<kaptcha.version>2.3.2</kaptcha.version>
|
||||
<pagehelper.boot.version>1.4.3</pagehelper.boot.version>
|
||||
<druid.version>1.2.11</druid.version>
|
||||
<dynamic-ds.version>3.5.1</dynamic-ds.version>
|
||||
<commons.io.version>2.11.0</commons.io.version>
|
||||
<commons.fileupload.version>1.4</commons.fileupload.version>
|
||||
<kaptcha.version>2.3.3</kaptcha.version>
|
||||
<pagehelper.boot.version>2.0.0</pagehelper.boot.version>
|
||||
<druid.version>1.2.23</druid.version>
|
||||
<dynamic-ds.version>4.3.1</dynamic-ds.version>
|
||||
<commons.io.version>2.19.0</commons.io.version>
|
||||
<velocity.version>2.3</velocity.version>
|
||||
<fastjson.version>2.0.9</fastjson.version>
|
||||
<fastjson.version>2.0.57</fastjson.version>
|
||||
<jjwt.version>0.9.1</jjwt.version>
|
||||
<minio.version>8.2.2</minio.version>
|
||||
<poi.version>4.1.2</poi.version>
|
||||
<commons-collections.version>3.2.2</commons-collections.version>
|
||||
<transmittable-thread-local.version>2.13.2</transmittable-thread-local.version>
|
||||
<springdoc.version>1.6.9</springdoc.version>
|
||||
<transmittable-thread-local.version>2.14.4</transmittable-thread-local.version>
|
||||
<!-- override dependency version -->
|
||||
<tomcat.version>9.0.112</tomcat.version>
|
||||
<logback.version>1.2.13</logback.version>
|
||||
<spring-framework.version>5.3.39</spring-framework.version>
|
||||
</properties>
|
||||
|
||||
<!-- 依赖声明 -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
<!-- 覆盖SpringFramework的依赖配置-->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>${spring-framework.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud 微服务 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
|
|
@ -64,20 +71,6 @@
|
|||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Alibaba Nacos 配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${alibaba.nacos.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Alibaba Seata 配置 -->
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-spring-boot-starter</artifactId>
|
||||
<version>${alibaba.seata.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot 依赖配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
@ -87,6 +80,38 @@
|
|||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 覆盖logback的依赖配置-->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 覆盖tomcat的依赖配置-->
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-el</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-websocket</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- FastDFS 分布式文件系统 -->
|
||||
<dependency>
|
||||
<groupId>com.github.tobato</groupId>
|
||||
|
|
@ -94,28 +119,16 @@
|
|||
<version>${tobato.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Mybatis 依赖配置 -->
|
||||
<!-- Springdoc webmvc 依赖配置 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${spring-boot.mybatis}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger 依赖配置 -->
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-models</artifactId>
|
||||
<version>${swagger.core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger.core.version}</version>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
<version>${springdoc.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 验证码 -->
|
||||
<dependency>
|
||||
<groupId>com.github.penggle</groupId>
|
||||
<groupId>pro.fessional</groupId>
|
||||
<artifactId>kaptcha</artifactId>
|
||||
<version>${kaptcha.version}</version>
|
||||
</dependency>
|
||||
|
|
@ -141,13 +154,6 @@
|
|||
<version>${poi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 文件上传工具类 -->
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>${commons.fileupload.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 代码生成使用模板 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
|
|
@ -155,13 +161,6 @@
|
|||
<version>${velocity.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Collection 增强Java集合框架 -->
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>${commons-collections.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JSON 解析器和生成器 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
|
|
@ -204,6 +203,13 @@
|
|||
<version>${ruoyi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 数据脱敏 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-sensitive</artifactId>
|
||||
<version>${ruoyi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 权限范围 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
|
|
@ -218,6 +224,13 @@
|
|||
<version>${ruoyi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 分布式事务 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-seata</artifactId>
|
||||
<version>${ruoyi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 日志记录 -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
|
|
@ -272,6 +285,22 @@
|
|||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-api</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package com.ruoyi.system.api;
|
|||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
|
|
@ -26,4 +28,13 @@ public interface RemoteFileService
|
|||
*/
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R<SysFile> upload(@RequestPart(value = "file") MultipartFile file);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param fileUrl 文件地址
|
||||
* @return 结果
|
||||
*/
|
||||
@DeleteMapping(value = "/delete", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
public R<Boolean> delete(@RequestParam("fileUrl") String fileUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public interface RemoteLogService
|
|||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/operlog")
|
||||
public R<Boolean> saveLog(@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
public R<Boolean> saveLog(@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source) throws Exception;
|
||||
|
||||
/**
|
||||
* 保存访问记录
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import org.springframework.cloud.openfeign.FeignClient;
|
|||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
|
|
@ -40,4 +41,14 @@ public interface RemoteUserService
|
|||
*/
|
||||
@PostMapping("/user/register")
|
||||
public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 记录用户登录IP地址和登录时间
|
||||
*
|
||||
* @param sysUser 用户信息
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
*/
|
||||
@PutMapping("/user/recordlogin")
|
||||
public R<Boolean> recordUserLogin(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ public class SysDictData extends BaseEntity
|
|||
|
||||
public boolean getDefault()
|
||||
{
|
||||
return UserConstants.YES.equals(this.isDefault) ? true : false;
|
||||
return UserConstants.YES.equals(this.isDefault);
|
||||
}
|
||||
|
||||
public String getIsDefault()
|
||||
|
|
|
|||
|
|
@ -79,6 +79,10 @@ public class SysOperLog extends BaseEntity
|
|||
@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date operTime;
|
||||
|
||||
/** 消耗时间 */
|
||||
@Excel(name = "消耗时间", suffix = "毫秒")
|
||||
private Long costTime;
|
||||
|
||||
public Long getOperId()
|
||||
{
|
||||
return operId;
|
||||
|
|
@ -238,4 +242,14 @@ public class SysOperLog extends BaseEntity
|
|||
{
|
||||
this.operTime = operTime;
|
||||
}
|
||||
|
||||
public Long getCostTime()
|
||||
{
|
||||
return costTime;
|
||||
}
|
||||
|
||||
public void setCostTime(Long costTime)
|
||||
{
|
||||
this.costTime = costTime;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import java.util.Set;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
|
@ -31,7 +33,7 @@ public class SysRole extends BaseEntity
|
|||
|
||||
/** 角色排序 */
|
||||
@Excel(name = "角色排序")
|
||||
private String roleSort;
|
||||
private Integer roleSort;
|
||||
|
||||
/** 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) */
|
||||
@Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限,5=仅本人数据权限")
|
||||
|
|
@ -59,6 +61,9 @@ public class SysRole extends BaseEntity
|
|||
/** 部门组(数据权限) */
|
||||
private Long[] deptIds;
|
||||
|
||||
/** 角色菜单权限 */
|
||||
private Set<String> permissions;
|
||||
|
||||
public SysRole()
|
||||
{
|
||||
|
||||
|
|
@ -113,13 +118,13 @@ public class SysRole extends BaseEntity
|
|||
this.roleKey = roleKey;
|
||||
}
|
||||
|
||||
@NotBlank(message = "显示顺序不能为空")
|
||||
public String getRoleSort()
|
||||
@NotNull(message = "显示顺序不能为空")
|
||||
public Integer getRoleSort()
|
||||
{
|
||||
return roleSort;
|
||||
}
|
||||
|
||||
public void setRoleSort(String roleSort)
|
||||
public void setRoleSort(Integer roleSort)
|
||||
{
|
||||
this.roleSort = roleSort;
|
||||
}
|
||||
|
|
@ -204,6 +209,16 @@ public class SysRole extends BaseEntity
|
|||
this.deptIds = deptIds;
|
||||
}
|
||||
|
||||
public Set<String> getPermissions()
|
||||
{
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(Set<String> permissions)
|
||||
{
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ import java.util.List;
|
|||
import javax.validation.constraints.*;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
||||
import com.ruoyi.common.core.annotation.Excel.Type;
|
||||
import com.ruoyi.common.core.annotation.Excels;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import com.ruoyi.common.core.xss.Xss;
|
||||
|
||||
|
|
@ -22,7 +24,7 @@ public class SysUser extends BaseEntity
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 用户ID */
|
||||
@Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
|
||||
@Excel(name = "用户序号", type = Type.EXPORT, cellType = ColumnType.NUMERIC, prompt = "用户编号")
|
||||
private Long userId;
|
||||
|
||||
/** 部门ID */
|
||||
|
|
@ -42,7 +44,7 @@ public class SysUser extends BaseEntity
|
|||
private String email;
|
||||
|
||||
/** 手机号码 */
|
||||
@Excel(name = "手机号码")
|
||||
@Excel(name = "手机号码", cellType = ColumnType.TEXT)
|
||||
private String phonenumber;
|
||||
|
||||
/** 用户性别 */
|
||||
|
|
@ -55,8 +57,8 @@ public class SysUser extends BaseEntity
|
|||
/** 密码 */
|
||||
private String password;
|
||||
|
||||
/** 帐号状态(0正常 1停用) */
|
||||
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
||||
/** 账号状态(0正常 1停用) */
|
||||
@Excel(name = "账号状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
|
|
@ -70,6 +72,9 @@ public class SysUser extends BaseEntity
|
|||
@Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
|
||||
private Date loginDate;
|
||||
|
||||
/** 密码最后更新时间 */
|
||||
private Date pwdUpdateDate;
|
||||
|
||||
/** 部门对象 */
|
||||
@Excels({
|
||||
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
|
||||
|
|
@ -116,7 +121,7 @@ public class SysUser extends BaseEntity
|
|||
|
||||
public static boolean isAdmin(Long userId)
|
||||
{
|
||||
return userId != null && 1L == userId;
|
||||
return UserConstants.isAdmin(userId);
|
||||
}
|
||||
|
||||
public Long getDeptId()
|
||||
|
|
@ -197,6 +202,7 @@ public class SysUser extends BaseEntity
|
|||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
|
|
@ -247,6 +253,16 @@ public class SysUser extends BaseEntity
|
|||
this.loginDate = loginDate;
|
||||
}
|
||||
|
||||
public Date getPwdUpdateDate()
|
||||
{
|
||||
return pwdUpdateDate;
|
||||
}
|
||||
|
||||
public void setPwdUpdateDate(Date pwdUpdateDate)
|
||||
{
|
||||
this.pwdUpdateDate = pwdUpdateDate;
|
||||
}
|
||||
|
||||
public SysDept getDept()
|
||||
{
|
||||
return dept;
|
||||
|
|
@ -296,6 +312,7 @@ public class SysUser extends BaseEntity
|
|||
{
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
|
@ -312,6 +329,7 @@ public class SysUser extends BaseEntity
|
|||
.append("delFlag", getDelFlag())
|
||||
.append("loginIp", getLoginIp())
|
||||
.append("loginDate", getLoginDate())
|
||||
.append("pwdUpdateDate", getPwdUpdateDate())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileServ
|
|||
{
|
||||
return R.fail("上传文件失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Boolean> delete(String fileUrl)
|
||||
{
|
||||
return R.fail("删除文件失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogServic
|
|||
@Override
|
||||
public R<Boolean> saveLog(SysOperLog sysOperLog, String source)
|
||||
{
|
||||
return null;
|
||||
return R.fail("保存操作日志失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Boolean> saveLogininfor(SysLogininfor sysLogininfor, String source)
|
||||
{
|
||||
return null;
|
||||
return R.fail("保存登录日志失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,12 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
{
|
||||
return R.fail("注册用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Boolean> recordUserLogin(SysUser sysUser, String source)
|
||||
{
|
||||
return R.fail("记录用户登录信息失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,20 @@ package com.ruoyi.auth.service;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.core.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.enums.UserStatus;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.ServletUtils;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.ip.IpUtils;
|
||||
import com.ruoyi.common.redis.service.RedisService;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.system.api.RemoteLogService;
|
||||
import com.ruoyi.system.api.RemoteUserService;
|
||||
import com.ruoyi.system.api.domain.SysLogininfor;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
|
||||
|
|
@ -27,10 +28,16 @@ import com.ruoyi.system.api.model.LoginUser;
|
|||
public class SysLoginService
|
||||
{
|
||||
@Autowired
|
||||
private RemoteLogService remoteLogService;
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
private SysPasswordService passwordService;
|
||||
|
||||
@Autowired
|
||||
private SysRecordLogService recordLogService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 登录
|
||||
|
|
@ -40,23 +47,30 @@ public class SysLoginService
|
|||
// 用户名或密码为空 错误
|
||||
if (StringUtils.isAnyBlank(username, password))
|
||||
{
|
||||
recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
||||
throw new ServiceException("用户/密码必须填写");
|
||||
}
|
||||
// 密码如果不在指定范围内 错误
|
||||
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
||||
{
|
||||
recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
||||
throw new ServiceException("用户密码不在指定范围");
|
||||
}
|
||||
// 用户名不在指定范围内 错误
|
||||
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
||||
{
|
||||
recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
||||
throw new ServiceException("用户名不在指定范围");
|
||||
}
|
||||
// IP黑名单校验
|
||||
String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
|
||||
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
|
||||
{
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
|
||||
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
|
||||
}
|
||||
// 查询用户信息
|
||||
R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||
|
||||
|
|
@ -65,35 +79,43 @@ public class SysLoginService
|
|||
throw new ServiceException(userResult.getMsg());
|
||||
}
|
||||
|
||||
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData()))
|
||||
{
|
||||
recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
||||
throw new ServiceException("登录用户:" + username + " 不存在");
|
||||
}
|
||||
LoginUser userInfo = userResult.getData();
|
||||
SysUser user = userResult.getData().getSysUser();
|
||||
if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
||||
{
|
||||
recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
||||
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
||||
}
|
||||
if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
||||
{
|
||||
recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
||||
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
|
||||
}
|
||||
if (!SecurityUtils.matchesPassword(password, user.getPassword()))
|
||||
{
|
||||
recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码错误");
|
||||
throw new ServiceException("用户不存在/密码错误");
|
||||
}
|
||||
recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
||||
passwordService.validate(user, password);
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
||||
recordLoginInfo(user.getUserId());
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登录信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
public void recordLoginInfo(Long userId)
|
||||
{
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserId(userId);
|
||||
// 更新用户登录IP
|
||||
sysUser.setLoginIp(IpUtils.getIpAddr());
|
||||
// 更新用户登录时间
|
||||
sysUser.setLoginDate(DateUtils.getNowDate());
|
||||
remoteUserService.recordUserLogin(sysUser, SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
public void logout(String loginName)
|
||||
{
|
||||
recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
|
||||
recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -121,6 +143,7 @@ public class SysLoginService
|
|||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserName(username);
|
||||
sysUser.setNickName(username);
|
||||
sysUser.setPwdUpdateDate(DateUtils.getNowDate());
|
||||
sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
||||
R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
|
||||
|
||||
|
|
@ -128,32 +151,6 @@ public class SysLoginService
|
|||
{
|
||||
throw new ServiceException(registerResult.getMsg());
|
||||
}
|
||||
recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登录信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param status 状态
|
||||
* @param message 消息内容
|
||||
* @return
|
||||
*/
|
||||
public void recordLogininfor(String username, String status, String message)
|
||||
{
|
||||
SysLogininfor logininfor = new SysLogininfor();
|
||||
logininfor.setUserName(username);
|
||||
logininfor.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
||||
logininfor.setMsg(message);
|
||||
// 日志状态
|
||||
if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER))
|
||||
{
|
||||
logininfor.setStatus(Constants.LOGIN_SUCCESS_STATUS);
|
||||
}
|
||||
else if (Constants.LOGIN_FAIL.equals(status))
|
||||
{
|
||||
logininfor.setStatus(Constants.LOGIN_FAIL_STATUS);
|
||||
}
|
||||
remoteLogService.saveLogininfor(logininfor, SecurityConstants.INNER);
|
||||
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package com.ruoyi.auth.service;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.core.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.redis.service.RedisService;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
|
||||
/**
|
||||
* 登录密码方法
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class SysPasswordService
|
||||
{
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
private int maxRetryCount = CacheConstants.PASSWORD_MAX_RETRY_COUNT;
|
||||
|
||||
private Long lockTime = CacheConstants.PASSWORD_LOCK_TIME;
|
||||
|
||||
@Autowired
|
||||
private SysRecordLogService recordLogService;
|
||||
|
||||
/**
|
||||
* 登录账户密码错误次数缓存键名
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 缓存键key
|
||||
*/
|
||||
private String getCacheKey(String username)
|
||||
{
|
||||
return CacheConstants.PWD_ERR_CNT_KEY + username;
|
||||
}
|
||||
|
||||
public void validate(SysUser user, String password)
|
||||
{
|
||||
String username = user.getUserName();
|
||||
|
||||
Integer retryCount = redisService.getCacheObject(getCacheKey(username));
|
||||
|
||||
if (retryCount == null)
|
||||
{
|
||||
retryCount = 0;
|
||||
}
|
||||
|
||||
if (retryCount >= Integer.valueOf(maxRetryCount).intValue())
|
||||
{
|
||||
String errMsg = String.format("密码输入错误%s次,帐户锁定%s分钟", maxRetryCount, lockTime);
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL,errMsg);
|
||||
throw new ServiceException(errMsg);
|
||||
}
|
||||
|
||||
if (!matches(user, password))
|
||||
{
|
||||
retryCount = retryCount + 1;
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, String.format("密码输入错误%s次", retryCount));
|
||||
redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
|
||||
throw new ServiceException("用户不存在/密码错误");
|
||||
}
|
||||
else
|
||||
{
|
||||
clearLoginRecordCache(username);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matches(SysUser user, String rawPassword)
|
||||
{
|
||||
return SecurityUtils.matchesPassword(rawPassword, user.getPassword());
|
||||
}
|
||||
|
||||
public void clearLoginRecordCache(String loginName)
|
||||
{
|
||||
if (redisService.hasKey(getCacheKey(loginName)))
|
||||
{
|
||||
redisService.deleteObject(getCacheKey(loginName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.ruoyi.auth.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.ip.IpUtils;
|
||||
import com.ruoyi.system.api.RemoteLogService;
|
||||
import com.ruoyi.system.api.domain.SysLogininfor;
|
||||
|
||||
/**
|
||||
* 记录日志方法
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class SysRecordLogService
|
||||
{
|
||||
@Autowired
|
||||
private RemoteLogService remoteLogService;
|
||||
|
||||
/**
|
||||
* 记录登录信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param status 状态
|
||||
* @param message 消息内容
|
||||
* @return
|
||||
*/
|
||||
public void recordLogininfor(String username, String status, String message)
|
||||
{
|
||||
SysLogininfor logininfor = new SysLogininfor();
|
||||
logininfor.setUserName(username);
|
||||
logininfor.setIpaddr(IpUtils.getIpAddr());
|
||||
logininfor.setMsg(message);
|
||||
// 日志状态
|
||||
if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER))
|
||||
{
|
||||
logininfor.setStatus(Constants.LOGIN_SUCCESS_STATUS);
|
||||
}
|
||||
else if (Constants.LOGIN_FAIL.equals(status))
|
||||
{
|
||||
logininfor.setStatus(Constants.LOGIN_FAIL_STATUS);
|
||||
}
|
||||
remoteLogService.saveLogininfor(logininfor, SecurityConstants.INNER);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
@ -12,8 +12,10 @@
|
|||
<module>ruoyi-common-log</module>
|
||||
<module>ruoyi-common-core</module>
|
||||
<module>ruoyi-common-redis</module>
|
||||
<module>ruoyi-common-seata</module>
|
||||
<module>ruoyi-common-swagger</module>
|
||||
<module>ruoyi-common-security</module>
|
||||
<module>ruoyi-common-sensitive</module>
|
||||
<module>ruoyi-common-datascope</module>
|
||||
<module>ruoyi-common-datasource</module>
|
||||
</modules>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
@ -95,12 +95,6 @@
|
|||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Commons Fileupload -->
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- excel工具 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
|
|
@ -113,12 +107,6 @@
|
|||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger -->
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -54,12 +54,12 @@ public @interface Excel
|
|||
public int roundingMode() default BigDecimal.ROUND_HALF_EVEN;
|
||||
|
||||
/**
|
||||
* 导出时在excel中每个列的高度 单位为字符
|
||||
* 导出时在excel中每个列的高度
|
||||
*/
|
||||
public double height() default 14;
|
||||
|
||||
/**
|
||||
* 导出时在excel中每个列的宽 单位为字符
|
||||
* 导出时在excel中每个列的宽度
|
||||
*/
|
||||
public double width() default 16;
|
||||
|
||||
|
|
@ -78,11 +78,21 @@ public @interface Excel
|
|||
*/
|
||||
public String prompt() default "";
|
||||
|
||||
/**
|
||||
* 是否允许内容换行
|
||||
*/
|
||||
public boolean wrapText() default false;
|
||||
|
||||
/**
|
||||
* 设置只能选择不能输入的列内容.
|
||||
*/
|
||||
public String[] combo() default {};
|
||||
|
||||
/**
|
||||
* 是否需要纵向合并单元格,应对需求:含有list集合单元格)
|
||||
*/
|
||||
public boolean needMerge() default false;
|
||||
|
||||
/**
|
||||
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
|
||||
*/
|
||||
|
|
@ -104,7 +114,22 @@ public @interface Excel
|
|||
public ColumnType cellType() default ColumnType.STRING;
|
||||
|
||||
/**
|
||||
* 导出字体颜色
|
||||
* 导出列头背景颜色
|
||||
*/
|
||||
public IndexedColors headerBackgroundColor() default IndexedColors.GREY_50_PERCENT;
|
||||
|
||||
/**
|
||||
* 导出列头字体颜色
|
||||
*/
|
||||
public IndexedColors headerColor() default IndexedColors.WHITE;
|
||||
|
||||
/**
|
||||
* 导出单元格背景颜色
|
||||
*/
|
||||
public IndexedColors backgroundColor() default IndexedColors.WHITE;
|
||||
|
||||
/**
|
||||
* 导出单元格字体颜色
|
||||
*/
|
||||
public IndexedColors color() default IndexedColors.BLACK;
|
||||
|
||||
|
|
@ -146,7 +171,7 @@ public @interface Excel
|
|||
|
||||
public enum ColumnType
|
||||
{
|
||||
NUMERIC(0), STRING(1), IMAGE(2);
|
||||
NUMERIC(0), STRING(1), IMAGE(2), TEXT(3);
|
||||
private final int value;
|
||||
|
||||
ColumnType(int value)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.ruoyi.common.core.constant;
|
||||
|
||||
/**
|
||||
* 缓存的key 常量
|
||||
* 缓存常量信息
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
|
|
@ -17,8 +17,43 @@ public class CacheConstants
|
|||
*/
|
||||
public final static long REFRESH_TIME = 120;
|
||||
|
||||
/**
|
||||
* 密码最大错误次数
|
||||
*/
|
||||
public final static int PASSWORD_MAX_RETRY_COUNT = 5;
|
||||
|
||||
/**
|
||||
* 密码锁定时间,默认10(分钟)
|
||||
*/
|
||||
public final static long PASSWORD_LOCK_TIME = 10;
|
||||
|
||||
/**
|
||||
* 权限缓存前缀
|
||||
*/
|
||||
public final static String LOGIN_TOKEN_KEY = "login_tokens:";
|
||||
|
||||
/**
|
||||
* 验证码 redis key
|
||||
*/
|
||||
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
|
||||
|
||||
/**
|
||||
* 参数管理 cache key
|
||||
*/
|
||||
public static final String SYS_CONFIG_KEY = "sys_config:";
|
||||
|
||||
/**
|
||||
* 字典管理 cache key
|
||||
*/
|
||||
public static final String SYS_DICT_KEY = "sys_dict:";
|
||||
|
||||
/**
|
||||
* 登录账户密码错误次数 redis key
|
||||
*/
|
||||
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
|
||||
|
||||
/**
|
||||
* 登录IP黑名单 cache key
|
||||
*/
|
||||
public static final String SYS_LOGIN_BLACKIPLIST = SYS_CONFIG_KEY + "sys.login.blackIPList";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,11 @@ public class Constants
|
|||
*/
|
||||
public static final String GBK = "GBK";
|
||||
|
||||
/**
|
||||
* www主域
|
||||
*/
|
||||
public static final String WWW = "www.";
|
||||
|
||||
/**
|
||||
* RMI 远程方法调用
|
||||
*/
|
||||
|
|
@ -82,6 +87,16 @@ public class Constants
|
|||
*/
|
||||
public static final String LOGIN_FAIL = "Error";
|
||||
|
||||
/**
|
||||
* 所有权限标识
|
||||
*/
|
||||
public static final String ALL_PERMISSION = "*:*:*";
|
||||
|
||||
/**
|
||||
* 管理员角色权限标识
|
||||
*/
|
||||
public static final String SUPER_ADMIN = "admin";
|
||||
|
||||
/**
|
||||
* 当前记录起始索引
|
||||
*/
|
||||
|
|
@ -102,36 +117,25 @@ public class Constants
|
|||
*/
|
||||
public static final String IS_ASC = "isAsc";
|
||||
|
||||
/**
|
||||
* 验证码 redis key
|
||||
*/
|
||||
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
|
||||
|
||||
/**
|
||||
* 验证码有效期(分钟)
|
||||
*/
|
||||
public static final long CAPTCHA_EXPIRATION = 2;
|
||||
|
||||
|
||||
/**
|
||||
* 参数管理 cache key
|
||||
*/
|
||||
public static final String SYS_CONFIG_KEY = "sys_config:";
|
||||
|
||||
/**
|
||||
* 字典管理 cache key
|
||||
*/
|
||||
public static final String SYS_DICT_KEY = "sys_dict:";
|
||||
|
||||
/**
|
||||
* 资源映射路径 前缀
|
||||
*/
|
||||
public static final String RESOURCE_PREFIX = "/profile";
|
||||
|
||||
/**
|
||||
* 自动识别json对象白名单配置(仅允许解析的包名,范围越小越安全)
|
||||
*/
|
||||
public static final String[] JSON_WHITELIST_STR = { "com.ruoyi" };
|
||||
|
||||
/**
|
||||
* 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
|
||||
*/
|
||||
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" };
|
||||
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi.job.task" };
|
||||
|
||||
/**
|
||||
* 定时任务违规的字符
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class GenConstants
|
|||
|
||||
/** 数据库数字类型 */
|
||||
public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
|
||||
"bigint", "float", "double", "decimal" };
|
||||
"bit", "bigint", "float", "double", "decimal" };
|
||||
|
||||
/** 页面不需要编辑字段 */
|
||||
public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" };
|
||||
|
|
|
|||
|
|
@ -86,4 +86,9 @@ public class HttpStatus
|
|||
* 接口未实现
|
||||
*/
|
||||
public static final int NOT_IMPLEMENTED = 501;
|
||||
|
||||
/**
|
||||
* 系统警告消息
|
||||
*/
|
||||
public static final int WARN = 601;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class SecurityConstants
|
|||
/**
|
||||
* 授权信息字段
|
||||
*/
|
||||
public static final String AUTHORIZATION_HEADER = "authorization";
|
||||
public static final String AUTHORIZATION_HEADER = "Authorization";
|
||||
|
||||
/**
|
||||
* 请求来源
|
||||
|
|
@ -41,4 +41,9 @@ public class SecurityConstants
|
|||
* 登录用户
|
||||
*/
|
||||
public static final String LOGIN_USER = "login_user";
|
||||
|
||||
/**
|
||||
* 角色权限
|
||||
*/
|
||||
public static final String ROLE_PERMISSION = "role_permission";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,6 @@ package com.ruoyi.common.core.constant;
|
|||
*/
|
||||
public class TokenConstants
|
||||
{
|
||||
/**
|
||||
* 令牌自定义标识
|
||||
*/
|
||||
public static final String AUTHENTICATION = "Authorization";
|
||||
|
||||
/**
|
||||
* 令牌前缀
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ public class UserConstants
|
|||
/** 用户封禁状态 */
|
||||
public static final String USER_DISABLE = "1";
|
||||
|
||||
/** 角色正常状态 */
|
||||
public static final String ROLE_NORMAL = "0";
|
||||
|
||||
/** 角色封禁状态 */
|
||||
public static final String ROLE_DISABLE = "1";
|
||||
|
||||
|
|
@ -60,10 +63,9 @@ public class UserConstants
|
|||
/** InnerLink组件标识 */
|
||||
public final static String INNER_LINK = "InnerLink";
|
||||
|
||||
/** 校验返回结果码 */
|
||||
public final static String UNIQUE = "0";
|
||||
|
||||
public final static String NOT_UNIQUE = "1";
|
||||
/** 校验是否唯一的返回标识 */
|
||||
public final static boolean UNIQUE = true;
|
||||
public final static boolean NOT_UNIQUE = false;
|
||||
|
||||
/**
|
||||
* 用户名长度限制
|
||||
|
|
@ -78,4 +80,9 @@ public class UserConstants
|
|||
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||
|
||||
public static final int PASSWORD_MAX_LENGTH = 20;
|
||||
|
||||
public static boolean isAdmin(Long userId)
|
||||
{
|
||||
return userId != null && 1L == userId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,16 @@ public class SecurityContextHolder
|
|||
set(SecurityConstants.USER_KEY, userKey);
|
||||
}
|
||||
|
||||
public static String getPermission()
|
||||
{
|
||||
return get(SecurityConstants.ROLE_PERMISSION);
|
||||
}
|
||||
|
||||
public static void setPermission(String permissions)
|
||||
{
|
||||
set(SecurityConstants.ROLE_PERMISSION, permissions);
|
||||
}
|
||||
|
||||
public static void remove()
|
||||
{
|
||||
THREAD_LOCAL.remove();
|
||||
|
|
|
|||
|
|
@ -102,4 +102,14 @@ public class R<T> implements Serializable
|
|||
{
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static <T> Boolean isError(R<T> ret)
|
||||
{
|
||||
return !isSuccess(ret);
|
||||
}
|
||||
|
||||
public static <T> Boolean isSuccess(R<T> ret)
|
||||
{
|
||||
return R.SUCCESS == ret.getCode();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package com.ruoyi.common.core.exception;
|
|||
*/
|
||||
public class GlobalException extends RuntimeException
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
|
@ -45,6 +44,7 @@ public class GlobalException extends RuntimeException
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ public final class ServiceException extends RuntimeException
|
|||
return detailMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ public class FileException extends BaseException
|
|||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FileException(String code, Object[] args)
|
||||
public FileException(String code, Object[] args, String msg)
|
||||
{
|
||||
super("file", code, args, null);
|
||||
super("file", code, args, msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@ public class FileNameLengthLimitExceededException extends FileException
|
|||
|
||||
public FileNameLengthLimitExceededException(int defaultFileNameLength)
|
||||
{
|
||||
super("upload.filename.exceed.length", new Object[] { defaultFileNameLength });
|
||||
super("upload.filename.exceed.length", new Object[] { defaultFileNameLength }, "the filename is too long");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@ public class FileSizeLimitExceededException extends FileException
|
|||
|
||||
public FileSizeLimitExceededException(long defaultMaxSize)
|
||||
{
|
||||
super("upload.exceed.maxSize", new Object[] { defaultMaxSize });
|
||||
super("upload.exceed.maxSize", new Object[] { defaultMaxSize }, "the filesize is too large");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
package com.ruoyi.common.core.exception.file;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* 文件上传异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class FileUploadException extends Exception
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Throwable cause;
|
||||
|
||||
public FileUploadException()
|
||||
{
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public FileUploadException(final String msg)
|
||||
{
|
||||
this(msg, null);
|
||||
}
|
||||
|
||||
public FileUploadException(String msg, Throwable cause)
|
||||
{
|
||||
super(msg);
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStackTrace(PrintStream stream)
|
||||
{
|
||||
super.printStackTrace(stream);
|
||||
if (cause != null)
|
||||
{
|
||||
stream.println("Caused by:");
|
||||
cause.printStackTrace(stream);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStackTrace(PrintWriter writer)
|
||||
{
|
||||
super.printStackTrace(writer);
|
||||
if (cause != null)
|
||||
{
|
||||
writer.println("Caused by:");
|
||||
cause.printStackTrace(writer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable getCause()
|
||||
{
|
||||
return cause;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package com.ruoyi.common.core.exception.file;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
|
||||
/**
|
||||
* 文件上传 误异常类
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.ruoyi.common.core.text;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.NumberFormat;
|
||||
|
|
@ -313,7 +314,7 @@ public class Convert
|
|||
* 转换为Integer数组<br>
|
||||
*
|
||||
* @param split 分隔符
|
||||
* @param split 被转换的值
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer[] toIntArray(String split, String str)
|
||||
|
|
@ -363,6 +364,10 @@ public class Convert
|
|||
*/
|
||||
public static String[] toStrArray(String str)
|
||||
{
|
||||
if (StringUtils.isEmpty(str))
|
||||
{
|
||||
return new String[] {};
|
||||
}
|
||||
return toStrArray(",", str);
|
||||
}
|
||||
|
||||
|
|
@ -370,7 +375,7 @@ public class Convert
|
|||
* 转换为String数组<br>
|
||||
*
|
||||
* @param split 分隔符
|
||||
* @param split 被转换的值
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String[] toStrArray(String split, String str)
|
||||
|
|
@ -535,7 +540,7 @@ public class Convert
|
|||
|
||||
/**
|
||||
* 转换为boolean<br>
|
||||
* String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* String支持的值为:true、false、yes、ok、no、1、0、是、否, 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
|
|
@ -564,10 +569,12 @@ public class Convert
|
|||
case "yes":
|
||||
case "ok":
|
||||
case "1":
|
||||
case "是":
|
||||
return true;
|
||||
case "false":
|
||||
case "no":
|
||||
case "0":
|
||||
case "否":
|
||||
return false;
|
||||
default:
|
||||
return defaultValue;
|
||||
|
|
@ -712,7 +719,7 @@ public class Convert
|
|||
}
|
||||
if (value instanceof Double)
|
||||
{
|
||||
return new BigDecimal((Double) value);
|
||||
return BigDecimal.valueOf((Double) value);
|
||||
}
|
||||
if (value instanceof Integer)
|
||||
{
|
||||
|
|
@ -962,9 +969,7 @@ public class Convert
|
|||
c[i] = (char) (c[i] - 65248);
|
||||
}
|
||||
}
|
||||
String returnString = new String(c);
|
||||
|
||||
return returnString;
|
||||
return new String(c);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -985,7 +990,12 @@ public class Convert
|
|||
String s = "";
|
||||
for (int i = 0; i < fraction.length; i++)
|
||||
{
|
||||
s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
|
||||
// 优化double计算精度丢失问题
|
||||
BigDecimal nNum = new BigDecimal(n);
|
||||
BigDecimal decimal = new BigDecimal(10);
|
||||
BigDecimal scale = nNum.multiply(decimal).setScale(2, RoundingMode.HALF_EVEN);
|
||||
double d = scale.doubleValue();
|
||||
s += (digit[(int) (Math.floor(d * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
|
||||
}
|
||||
if (s.length() < 1)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -137,16 +137,28 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
|||
}
|
||||
|
||||
/**
|
||||
* 计算两个时间差
|
||||
* 计算相差天数
|
||||
*/
|
||||
public static String getDatePoor(Date endDate, Date nowDate)
|
||||
public static int differentDaysByMillisecond(Date date1, Date date2)
|
||||
{
|
||||
return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算时间差
|
||||
*
|
||||
* @param endDate 最后时间
|
||||
* @param startTime 开始时间
|
||||
* @return 时间差(天/小时/分钟)
|
||||
*/
|
||||
public static String timeDistance(Date endDate, Date startTime)
|
||||
{
|
||||
long nd = 1000 * 24 * 60 * 60;
|
||||
long nh = 1000 * 60 * 60;
|
||||
long nm = 1000 * 60;
|
||||
// long ns = 1000;
|
||||
// 获得两个时间的毫秒时间差异
|
||||
long diff = endDate.getTime() - nowDate.getTime();
|
||||
long diff = endDate.getTime() - startTime.getTime();
|
||||
// 计算差多少天
|
||||
long day = diff / nd;
|
||||
// 计算差多少小时
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@ import java.io.IOException;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
|
@ -79,6 +82,34 @@ public class ServletUtils
|
|||
return Convert.toBool(getRequest().getParameter(name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得所有请求参数
|
||||
*
|
||||
* @param request 请求对象{@link ServletRequest}
|
||||
* @return Map
|
||||
*/
|
||||
public static Map<String, String[]> getParams(ServletRequest request)
|
||||
{
|
||||
final Map<String, String[]> map = request.getParameterMap();
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得所有请求参数
|
||||
*
|
||||
* @param request 请求对象{@link ServletRequest}
|
||||
* @return Map
|
||||
*/
|
||||
public static Map<String, String> getParamMap(ServletRequest request)
|
||||
{
|
||||
Map<String, String> params = new HashMap<>();
|
||||
for (Map.Entry<String, String[]> entry : getParams(request).entrySet())
|
||||
{
|
||||
params.put(entry.getKey(), StringUtils.join(entry.getValue(), ","));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取request
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||
/** 下划线 */
|
||||
private static final char SEPARATOR = '_';
|
||||
|
||||
/** 星号 */
|
||||
private static final char ASTERISK = '*';
|
||||
|
||||
/**
|
||||
* 获取参数不为空值
|
||||
*
|
||||
|
|
@ -160,6 +163,49 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||
return (str == null ? "" : str.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换指定字符串的指定区间内字符为"*"
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param startInclude 开始位置(包含)
|
||||
* @param endExclude 结束位置(不包含)
|
||||
* @return 替换后的字符串
|
||||
*/
|
||||
public static String hide(CharSequence str, int startInclude, int endExclude)
|
||||
{
|
||||
if (isEmpty(str))
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
final int strLength = str.length();
|
||||
if (startInclude > strLength)
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
if (endExclude > strLength)
|
||||
{
|
||||
endExclude = strLength;
|
||||
}
|
||||
if (startInclude > endExclude)
|
||||
{
|
||||
// 如果起始位置大于结束位置,不替换
|
||||
return NULLSTR;
|
||||
}
|
||||
final char[] chars = new char[strLength];
|
||||
for (int i = 0; i < strLength; i++)
|
||||
{
|
||||
if (i >= startInclude && i < endExclude)
|
||||
{
|
||||
chars[i] = ASTERISK;
|
||||
}
|
||||
else
|
||||
{
|
||||
chars[i] = str.charAt(i);
|
||||
}
|
||||
}
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取字符串
|
||||
*
|
||||
|
|
@ -237,6 +283,32 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||
return str.substring(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在字符串中查找第一个出现的 `open` 和最后一个出现的 `close` 之间的子字符串
|
||||
*
|
||||
* @param str 要截取的字符串
|
||||
* @param open 起始字符串
|
||||
* @param close 结束字符串
|
||||
* @return 截取结果
|
||||
*/
|
||||
public static String substringBetweenLast(final String str, final String open, final String close)
|
||||
{
|
||||
if (isEmpty(str) || isEmpty(open) || isEmpty(close))
|
||||
{
|
||||
return NULLSTR;
|
||||
}
|
||||
final int start = str.indexOf(open);
|
||||
if (start != INDEX_NOT_FOUND)
|
||||
{
|
||||
final int end = str.lastIndexOf(close);
|
||||
if (end != INDEX_NOT_FOUND)
|
||||
{
|
||||
return str.substring(start + open.length(), end);
|
||||
}
|
||||
}
|
||||
return NULLSTR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为空,并且不是空白字符
|
||||
*
|
||||
|
|
@ -294,6 +366,32 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||
return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断给定的collection列表中是否包含数组array 判断给定的数组array中是否包含给定的元素value
|
||||
*
|
||||
* @param collection 给定的集合
|
||||
* @param array 给定的数组
|
||||
* @return boolean 结果
|
||||
*/
|
||||
public static boolean containsAny(Collection<String> collection, String... array)
|
||||
{
|
||||
if (isEmpty(collection) || isEmpty(array))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String str : array)
|
||||
{
|
||||
if (collection.contains(str))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 驼峰转下划线命名
|
||||
*/
|
||||
|
|
@ -402,7 +500,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||
}
|
||||
|
||||
/**
|
||||
* 驼峰式命名法 例如:user_name->userName
|
||||
* 驼峰式命名法
|
||||
* 例如:user_name->userName
|
||||
*/
|
||||
public static String toCamelCase(String s)
|
||||
{
|
||||
|
|
@ -410,6 +509,10 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||
{
|
||||
return null;
|
||||
}
|
||||
if (s.indexOf(SEPARATOR) == -1)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
s = s.toLowerCase();
|
||||
StringBuilder sb = new StringBuilder(s.length());
|
||||
boolean upperCase = false;
|
||||
|
|
|
|||
|
|
@ -97,8 +97,7 @@ public class FileUtils
|
|||
// 路径为文件且不为空则进行删除
|
||||
if (file.isFile() && file.exists())
|
||||
{
|
||||
file.delete();
|
||||
flag = true;
|
||||
flag = file.delete();
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
|
@ -115,27 +114,20 @@ public class FileUtils
|
|||
}
|
||||
|
||||
/**
|
||||
* 检查文件是否可下载
|
||||
* 校验文件路径合法性(安全性与扩展名)
|
||||
*
|
||||
* @param resource 需要下载的文件
|
||||
* @param fileUrl 待校验的文件地址
|
||||
* @return true 正常 false 非法
|
||||
*/
|
||||
public static boolean checkAllowDownload(String resource)
|
||||
public static boolean validateFilePath(String fileUrl)
|
||||
{
|
||||
// 禁止目录上跳级别
|
||||
if (StringUtils.contains(resource, ".."))
|
||||
if (StringUtils.contains(fileUrl, ".."))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查允许下载的文件规则
|
||||
if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 不在允许下载的文件规则
|
||||
return false;
|
||||
// 判断是否在允许下载的文件规则内
|
||||
return ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(fileUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ public final class HTMLFilter
|
|||
final String name = m.group(1).toLowerCase();
|
||||
if (allowed(name))
|
||||
{
|
||||
if (false == inArray(name, vSelfClosingTags))
|
||||
if (!inArray(name, vSelfClosingTags))
|
||||
{
|
||||
if (vTagCounts.containsKey(name))
|
||||
{
|
||||
|
|
@ -387,7 +387,7 @@ public final class HTMLFilter
|
|||
{
|
||||
paramValue = processParamProtocol(paramValue);
|
||||
}
|
||||
params.append(' ').append(paramName).append("=\\\"").append(paramValue).append("\"");
|
||||
params.append(' ').append(paramName).append("=\\\"").append(paramValue).append("\\\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.ruoyi.common.core.utils.ip;
|
|||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.ruoyi.common.core.utils.ServletUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -12,6 +13,23 @@ import com.ruoyi.common.core.utils.StringUtils;
|
|||
*/
|
||||
public class IpUtils
|
||||
{
|
||||
public final static String REGX_0_255 = "(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)";
|
||||
// 匹配 ip
|
||||
public final static String REGX_IP = "((" + REGX_0_255 + "\\.){3}" + REGX_0_255 + ")";
|
||||
public final static String REGX_IP_WILDCARD = "(((\\*\\.){3}\\*)|(" + REGX_0_255 + "(\\.\\*){3})|(" + REGX_0_255 + "\\." + REGX_0_255 + ")(\\.\\*){2}" + "|((" + REGX_0_255 + "\\.){3}\\*))";
|
||||
// 匹配网段
|
||||
public final static String REGX_IP_SEG = "(" + REGX_IP + "\\-" + REGX_IP + ")";
|
||||
|
||||
/**
|
||||
* 获取客户端IP
|
||||
*
|
||||
* @return IP地址
|
||||
*/
|
||||
public static String getIpAddr()
|
||||
{
|
||||
return getIpAddr(ServletUtils.getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户端IP
|
||||
*
|
||||
|
|
@ -248,7 +266,7 @@ public class IpUtils
|
|||
}
|
||||
}
|
||||
}
|
||||
return ip;
|
||||
return StringUtils.substring(ip, 0, 255);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -261,4 +279,104 @@ public class IpUtils
|
|||
{
|
||||
return StringUtils.isBlank(checkString) || "unknown".equalsIgnoreCase(checkString);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为IP
|
||||
*/
|
||||
public static boolean isIP(String ip)
|
||||
{
|
||||
return StringUtils.isNotBlank(ip) && ip.matches(REGX_IP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为IP,或 *为间隔的通配符地址
|
||||
*/
|
||||
public static boolean isIpWildCard(String ip)
|
||||
{
|
||||
return StringUtils.isNotBlank(ip) && ip.matches(REGX_IP_WILDCARD);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测参数是否在ip通配符里
|
||||
*/
|
||||
public static boolean ipIsInWildCardNoCheck(String ipWildCard, String ip)
|
||||
{
|
||||
String[] s1 = ipWildCard.split("\\.");
|
||||
String[] s2 = ip.split("\\.");
|
||||
boolean isMatchedSeg = true;
|
||||
for (int i = 0; i < s1.length && !s1[i].equals("*"); i++)
|
||||
{
|
||||
if (!s1[i].equals(s2[i]))
|
||||
{
|
||||
isMatchedSeg = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isMatchedSeg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为特定格式如:“10.10.10.1-10.10.10.99”的ip段字符串
|
||||
*/
|
||||
public static boolean isIPSegment(String ipSeg)
|
||||
{
|
||||
return StringUtils.isNotBlank(ipSeg) && ipSeg.matches(REGX_IP_SEG);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断ip是否在指定网段中
|
||||
*/
|
||||
public static boolean ipIsInNetNoCheck(String iparea, String ip)
|
||||
{
|
||||
int idx = iparea.indexOf('-');
|
||||
String[] sips = iparea.substring(0, idx).split("\\.");
|
||||
String[] sipe = iparea.substring(idx + 1).split("\\.");
|
||||
String[] sipt = ip.split("\\.");
|
||||
long ips = 0L, ipe = 0L, ipt = 0L;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
ips = ips << 8 | Integer.parseInt(sips[i]);
|
||||
ipe = ipe << 8 | Integer.parseInt(sipe[i]);
|
||||
ipt = ipt << 8 | Integer.parseInt(sipt[i]);
|
||||
}
|
||||
if (ips > ipe)
|
||||
{
|
||||
long t = ips;
|
||||
ips = ipe;
|
||||
ipe = t;
|
||||
}
|
||||
return ips <= ipt && ipt <= ipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验ip是否符合过滤串规则
|
||||
*
|
||||
* @param filter 过滤IP列表,支持后缀'*'通配,支持网段如:`10.10.10.1-10.10.10.99`
|
||||
* @param ip 校验IP地址
|
||||
* @return boolean 结果
|
||||
*/
|
||||
public static boolean isMatchedIp(String filter, String ip)
|
||||
{
|
||||
if (StringUtils.isEmpty(filter) || StringUtils.isEmpty(ip))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
String[] ips = filter.split(";");
|
||||
for (String iStr : ips)
|
||||
{
|
||||
if (isIP(iStr) && iStr.equals(ip))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (isIpWildCard(iStr) && ipIsInWildCardNoCheck(iStr, ip))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (isIPSegment(iStr) && ipIsInNetNoCheck(iStr, ip))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
package com.ruoyi.common.core.utils.poi;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
/**
|
||||
* Excel数据格式处理适配器
|
||||
*
|
||||
|
|
@ -12,8 +15,10 @@ public interface ExcelHandlerAdapter
|
|||
*
|
||||
* @param value 单元格数据值
|
||||
* @param args excel注解args参数组
|
||||
* @param cell 单元格对象
|
||||
* @param wb 工作簿对象
|
||||
*
|
||||
* @return 处理后的值
|
||||
*/
|
||||
Object format(Object value, String[] args);
|
||||
Object format(Object value, String[] args, Cell cell, Workbook wb);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -18,12 +20,15 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.RegExUtils;
|
||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||
import org.apache.poi.ss.usermodel.BorderStyle;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||
import org.apache.poi.ss.usermodel.DataFormat;
|
||||
import org.apache.poi.ss.usermodel.DataValidation;
|
||||
import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
||||
import org.apache.poi.ss.usermodel.DataValidationHelper;
|
||||
|
|
@ -33,6 +38,7 @@ import org.apache.poi.ss.usermodel.FillPatternType;
|
|||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.Name;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
|
|
@ -50,6 +56,7 @@ import com.ruoyi.common.core.annotation.Excel;
|
|||
import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
||||
import com.ruoyi.common.core.annotation.Excel.Type;
|
||||
import com.ruoyi.common.core.annotation.Excels;
|
||||
import com.ruoyi.common.core.exception.UtilException;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
|
|
@ -66,6 +73,8 @@ public class ExcelUtil<T>
|
|||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
|
||||
|
||||
public static final String SEPARATOR = ",";
|
||||
|
||||
public static final String FORMULA_REGEX_STR = "=|-|\\+|@";
|
||||
|
||||
public static final String[] FORMULA_STR = { "=", "-", "+", "@" };
|
||||
|
|
@ -125,26 +134,71 @@ public class ExcelUtil<T>
|
|||
*/
|
||||
private short maxHeight;
|
||||
|
||||
/**
|
||||
* 合并后最后行数
|
||||
*/
|
||||
private int subMergedLastRowNum = 0;
|
||||
|
||||
/**
|
||||
* 合并后开始行数
|
||||
*/
|
||||
private int subMergedFirstRowNum = 1;
|
||||
|
||||
/**
|
||||
* 对象的子列表方法
|
||||
*/
|
||||
private Map<String, Method> subMethods;
|
||||
|
||||
/**
|
||||
* 对象的子列表属性
|
||||
*/
|
||||
private Map<String, List<Field>> subFieldsMap;
|
||||
|
||||
/**
|
||||
* 统计列表
|
||||
*/
|
||||
private Map<Integer, Double> statistics = new HashMap<Integer, Double>();
|
||||
|
||||
/**
|
||||
* 数字格式
|
||||
*/
|
||||
private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00");
|
||||
|
||||
/**
|
||||
* 实体对象
|
||||
*/
|
||||
public Class<T> clazz;
|
||||
|
||||
/**
|
||||
* 需要显示列属性
|
||||
*/
|
||||
public String[] includeFields;
|
||||
|
||||
/**
|
||||
* 需要排除列属性
|
||||
*/
|
||||
public String[] excludeFields;
|
||||
|
||||
public ExcelUtil(Class<T> clazz)
|
||||
{
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅在Excel中显示列属性
|
||||
*
|
||||
* @param fields 列属性名 示例[单个"name"/多个"id","name"]
|
||||
*/
|
||||
public void showColumn(String... fields)
|
||||
{
|
||||
this.includeFields = fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏Excel中列属性
|
||||
*
|
||||
* @param fields 列属性名 示例[单个"name"/多个"id","name"]
|
||||
*/
|
||||
public void hideColumn(String... fields)
|
||||
{
|
||||
this.excludeFields = fields;
|
||||
}
|
||||
|
||||
public void init(List<T> list, String sheetName, String title, Type type)
|
||||
{
|
||||
if (list == null)
|
||||
|
|
@ -158,6 +212,7 @@ public class ExcelUtil<T>
|
|||
createExcelField();
|
||||
createWorkbook();
|
||||
createTitle();
|
||||
createSubHead();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -167,13 +222,58 @@ public class ExcelUtil<T>
|
|||
{
|
||||
if (StringUtils.isNotEmpty(title))
|
||||
{
|
||||
int titleLastCol = this.fields.size() - 1;
|
||||
if (isSubList())
|
||||
{
|
||||
for (List<Field> currentSubFields : subFieldsMap.values())
|
||||
{
|
||||
titleLastCol = titleLastCol + currentSubFields.size() - 1;
|
||||
}
|
||||
}
|
||||
Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0);
|
||||
titleRow.setHeightInPoints(30);
|
||||
Cell titleCell = titleRow.createCell(0);
|
||||
titleCell.setCellStyle(styles.get("title"));
|
||||
titleCell.setCellValue(title);
|
||||
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(),
|
||||
this.fields.size() - 1));
|
||||
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), 0, titleLastCol));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建对象的子列表名称
|
||||
*/
|
||||
public void createSubHead()
|
||||
{
|
||||
if (isSubList())
|
||||
{
|
||||
Row subRow = sheet.createRow(rownum);
|
||||
int column = 0;
|
||||
for (Object[] objects : fields)
|
||||
{
|
||||
Field field = (Field) objects[0];
|
||||
Excel attr = (Excel) objects[1];
|
||||
CellStyle cellStyle = styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor()));
|
||||
if (Collection.class.isAssignableFrom(field.getType()))
|
||||
{
|
||||
Cell cell = subRow.createCell(column);
|
||||
cell.setCellValue(attr.name());
|
||||
cell.setCellStyle(cellStyle);
|
||||
int subFieldSize = subFieldsMap != null ? subFieldsMap.get(field.getName()).size() : 0;
|
||||
if (subFieldSize > 1)
|
||||
{
|
||||
CellRangeAddress cellAddress = new CellRangeAddress(rownum, rownum, column, column + subFieldSize - 1);
|
||||
sheet.addMergedRegion(cellAddress);
|
||||
}
|
||||
column += subFieldSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cell cell = subRow.createCell(column++);
|
||||
cell.setCellValue(attr.name());
|
||||
cell.setCellStyle(cellStyle);
|
||||
}
|
||||
}
|
||||
rownum++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +283,7 @@ public class ExcelUtil<T>
|
|||
* @param is 输入流
|
||||
* @return 转换后集合
|
||||
*/
|
||||
public List<T> importExcel(InputStream is) throws Exception
|
||||
public List<T> importExcel(InputStream is)
|
||||
{
|
||||
return importExcel(is, 0);
|
||||
}
|
||||
|
|
@ -195,9 +295,23 @@ public class ExcelUtil<T>
|
|||
* @param titleNum 标题占用行数
|
||||
* @return 转换后集合
|
||||
*/
|
||||
public List<T> importExcel(InputStream is, int titleNum) throws Exception
|
||||
public List<T> importExcel(InputStream is, int titleNum)
|
||||
{
|
||||
return importExcel(StringUtils.EMPTY, is, titleNum);
|
||||
List<T> list = null;
|
||||
try
|
||||
{
|
||||
list = importExcel(StringUtils.EMPTY, is, titleNum);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("导入Excel异常{}", e.getMessage());
|
||||
throw new UtilException(e.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -222,14 +336,17 @@ public class ExcelUtil<T>
|
|||
|
||||
// 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
|
||||
int rows = sheet.getLastRowNum();
|
||||
|
||||
if (rows > 0)
|
||||
{
|
||||
// 定义一个map用于存放excel列的序号和field.
|
||||
Map<String, Integer> cellMap = new HashMap<String, Integer>();
|
||||
// 获取表头
|
||||
Row heard = sheet.getRow(titleNum);
|
||||
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++)
|
||||
if (heard == null)
|
||||
{
|
||||
throw new UtilException("文件标题行为空,请检查Excel文件格式");
|
||||
}
|
||||
for (int i = 0; i < heard.getLastCellNum(); i++)
|
||||
{
|
||||
Cell cell = heard.getCell(i);
|
||||
if (StringUtils.isNotNull(cell))
|
||||
|
|
@ -237,10 +354,6 @@ public class ExcelUtil<T>
|
|||
String value = this.getCellValue(heard, i).toString();
|
||||
cellMap.put(value, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
cellMap.put(null, i);
|
||||
}
|
||||
}
|
||||
// 有数据时才处理 得到类的所有field.
|
||||
List<Object[]> fields = this.getFields();
|
||||
|
|
@ -278,7 +391,7 @@ public class ExcelUtil<T>
|
|||
if (String.class == fieldType)
|
||||
{
|
||||
String s = Convert.toStr(val);
|
||||
if (StringUtils.endsWith(s, ".0"))
|
||||
if (s.matches("^\\d+\\.0$"))
|
||||
{
|
||||
val = StringUtils.substringBefore(s, ".0");
|
||||
}
|
||||
|
|
@ -337,13 +450,13 @@ public class ExcelUtil<T>
|
|||
{
|
||||
propertyName = field.getName() + "." + attr.targetAttr();
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
||||
if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
||||
{
|
||||
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
||||
}
|
||||
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||
{
|
||||
val = dataFormatHandlerAdapter(val, attr);
|
||||
val = dataFormatHandlerAdapter(val, attr, null);
|
||||
}
|
||||
ReflectUtils.invokeSetter(entity, propertyName, val);
|
||||
}
|
||||
|
|
@ -361,7 +474,6 @@ public class ExcelUtil<T>
|
|||
* @param list 导出数据集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @return 结果
|
||||
* @throws IOException
|
||||
*/
|
||||
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName)
|
||||
{
|
||||
|
|
@ -376,7 +488,6 @@ public class ExcelUtil<T>
|
|||
* @param sheetName 工作表的名称
|
||||
* @param title 标题
|
||||
* @return 结果
|
||||
* @throws IOException
|
||||
*/
|
||||
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title)
|
||||
{
|
||||
|
|
@ -451,12 +562,25 @@ public class ExcelUtil<T>
|
|||
// 写入各个字段的列头名称
|
||||
for (Object[] os : fields)
|
||||
{
|
||||
Field field = (Field) os[0];
|
||||
Excel excel = (Excel) os[1];
|
||||
this.createCell(excel, row, column++);
|
||||
if (Collection.class.isAssignableFrom(field.getType()))
|
||||
{
|
||||
List<Field> currentSubFields = subFieldsMap.get(field.getName());
|
||||
for (Field subField : currentSubFields)
|
||||
{
|
||||
Excel subExcel = subField.getAnnotation(Excel.class);
|
||||
this.createHeadCell(subExcel, row, column++);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.createHeadCell(excel, row, column++);
|
||||
}
|
||||
}
|
||||
if (Type.EXPORT.equals(type))
|
||||
{
|
||||
fillExcelData(index, row);
|
||||
fillExcelData(index);
|
||||
addStatisticsRow();
|
||||
}
|
||||
}
|
||||
|
|
@ -466,25 +590,98 @@ public class ExcelUtil<T>
|
|||
* 填充excel数据
|
||||
*
|
||||
* @param index 序号
|
||||
* @param row 单元格行
|
||||
*/
|
||||
public void fillExcelData(int index, Row row)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void fillExcelData(int index)
|
||||
{
|
||||
int startNo = index * sheetSize;
|
||||
int endNo = Math.min(startNo + sheetSize, list.size());
|
||||
int currentRowNum = rownum + 1; // 从标题行后开始
|
||||
|
||||
for (int i = startNo; i < endNo; i++)
|
||||
{
|
||||
row = sheet.createRow(i + 1 + rownum - startNo);
|
||||
// 得到导出对象.
|
||||
Row row = sheet.createRow(currentRowNum);
|
||||
T vo = (T) list.get(i);
|
||||
int column = 0;
|
||||
int maxSubListSize = getCurrentMaxSubListSize(vo);
|
||||
for (Object[] os : fields)
|
||||
{
|
||||
Field field = (Field) os[0];
|
||||
Excel excel = (Excel) os[1];
|
||||
this.addCell(excel, row, vo, field, column++);
|
||||
if (Collection.class.isAssignableFrom(field.getType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
Collection<?> subList = (Collection<?>) getTargetValue(vo, field, excel);
|
||||
List<Field> currentSubFields = subFieldsMap.get(field.getName());
|
||||
if (subList != null && !subList.isEmpty())
|
||||
{
|
||||
int subIndex = 0;
|
||||
for (Object subVo : subList)
|
||||
{
|
||||
Row subRow = sheet.getRow(currentRowNum + subIndex);
|
||||
if (subRow == null)
|
||||
{
|
||||
subRow = sheet.createRow(currentRowNum + subIndex);
|
||||
}
|
||||
|
||||
int subColumn = column;
|
||||
for (Field subField : currentSubFields)
|
||||
{
|
||||
Excel subExcel = subField.getAnnotation(Excel.class);
|
||||
addCell(subExcel, subRow, (T) subVo, subField, subColumn++);
|
||||
}
|
||||
subIndex++;
|
||||
}
|
||||
}
|
||||
column += currentSubFields.size();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("填充集合数据失败", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 创建单元格并设置值
|
||||
addCell(excel, row, vo, field, column);
|
||||
if (maxSubListSize > 1 && excel.needMerge())
|
||||
{
|
||||
sheet.addMergedRegion(new CellRangeAddress(currentRowNum, currentRowNum + maxSubListSize - 1, column, column));
|
||||
}
|
||||
column++;
|
||||
}
|
||||
}
|
||||
currentRowNum += maxSubListSize;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子列表最大数
|
||||
*/
|
||||
private int getCurrentMaxSubListSize(T vo)
|
||||
{
|
||||
int maxSubListSize = 1;
|
||||
for (Object[] os : fields)
|
||||
{
|
||||
Field field = (Field) os[0];
|
||||
if (Collection.class.isAssignableFrom(field.getType()))
|
||||
{
|
||||
try
|
||||
{
|
||||
Collection<?> subList = (Collection<?>) getTargetValue(vo, field, (Excel) os[1]);
|
||||
if (subList != null && !subList.isEmpty())
|
||||
{
|
||||
maxSubListSize = Math.max(maxSubListSize, subList.size());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("获取集合大小失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxSubListSize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -505,6 +702,8 @@ public class ExcelUtil<T>
|
|||
titleFont.setFontHeightInPoints((short) 16);
|
||||
titleFont.setBold(true);
|
||||
style.setFont(titleFont);
|
||||
DataFormat dataFormat = wb.createDataFormat();
|
||||
style.setDataFormat(dataFormat.getFormat("@"));
|
||||
styles.put("title", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
|
|
@ -524,51 +723,104 @@ public class ExcelUtil<T>
|
|||
style.setFont(dataFont);
|
||||
styles.put("data", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.cloneStyleFrom(styles.get("data"));
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
Font headerFont = wb.createFont();
|
||||
headerFont.setFontName("Arial");
|
||||
headerFont.setFontHeightInPoints((short) 10);
|
||||
headerFont.setBold(true);
|
||||
headerFont.setColor(IndexedColors.WHITE.getIndex());
|
||||
style.setFont(headerFont);
|
||||
styles.put("header", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setDataFormat(dataFormat.getFormat("######0.00"));
|
||||
Font totalFont = wb.createFont();
|
||||
totalFont.setFontName("Arial");
|
||||
totalFont.setFontHeightInPoints((short) 10);
|
||||
style.setFont(totalFont);
|
||||
styles.put("total", style);
|
||||
|
||||
styles.putAll(annotationStyles(wb));
|
||||
styles.putAll(annotationHeaderStyles(wb, styles));
|
||||
|
||||
styles.putAll(annotationDataStyles(wb));
|
||||
|
||||
return styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Excel注解创建表格样式
|
||||
* 根据Excel注解创建表格头样式
|
||||
*
|
||||
* @param wb 工作薄对象
|
||||
* @return 自定义样式列表
|
||||
*/
|
||||
private Map<String, CellStyle> annotationStyles(Workbook wb)
|
||||
private Map<String, CellStyle> annotationHeaderStyles(Workbook wb, Map<String, CellStyle> styles)
|
||||
{
|
||||
Map<String, CellStyle> headerStyles = new HashMap<String, CellStyle>();
|
||||
for (Object[] os : fields)
|
||||
{
|
||||
Excel excel = (Excel) os[1];
|
||||
String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor());
|
||||
if (!headerStyles.containsKey(key))
|
||||
{
|
||||
CellStyle style = wb.createCellStyle();
|
||||
style.cloneStyleFrom(styles.get("data"));
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setFillForegroundColor(excel.headerBackgroundColor().index);
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
Font headerFont = wb.createFont();
|
||||
headerFont.setFontName("Arial");
|
||||
headerFont.setFontHeightInPoints((short) 10);
|
||||
headerFont.setBold(true);
|
||||
headerFont.setColor(excel.headerColor().index);
|
||||
style.setFont(headerFont);
|
||||
// 设置表格头单元格文本形式
|
||||
DataFormat dataFormat = wb.createDataFormat();
|
||||
style.setDataFormat(dataFormat.getFormat("@"));
|
||||
headerStyles.put(key, style);
|
||||
}
|
||||
}
|
||||
return headerStyles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Excel注解创建表格列样式
|
||||
*
|
||||
* @param wb 工作薄对象
|
||||
* @return 自定义样式列表
|
||||
*/
|
||||
private Map<String, CellStyle> annotationDataStyles(Workbook wb)
|
||||
{
|
||||
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
|
||||
for (Object[] os : fields)
|
||||
{
|
||||
Field field = (Field) os[0];
|
||||
Excel excel = (Excel) os[1];
|
||||
String key = "data_" + excel.align() + "_" + excel.color();
|
||||
if (Collection.class.isAssignableFrom(field.getType()))
|
||||
{
|
||||
ParameterizedType pt = (ParameterizedType) field.getGenericType();
|
||||
Class<?> subClass = (Class<?>) pt.getActualTypeArguments()[0];
|
||||
List<Field> subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
|
||||
for (Field subField : subFields)
|
||||
{
|
||||
Excel subExcel = subField.getAnnotation(Excel.class);
|
||||
annotationDataStyles(styles, subField, subExcel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
annotationDataStyles(styles, field, excel);
|
||||
}
|
||||
}
|
||||
return styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Excel注解创建表格列样式
|
||||
*
|
||||
* @param styles 自定义样式列表
|
||||
* @param field 属性列信息
|
||||
* @param excel 注解信息
|
||||
*/
|
||||
public void annotationDataStyles(Map<String, CellStyle> styles, Field field, Excel excel)
|
||||
{
|
||||
String key = StringUtils.format("data_{}_{}_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor(), excel.cellType(), excel.wrapText());
|
||||
if (!styles.containsKey(key))
|
||||
{
|
||||
CellStyle style = wb.createCellStyle();
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(excel.align());
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
|
|
@ -579,28 +831,43 @@ public class ExcelUtil<T>
|
|||
style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setFillForegroundColor(excel.backgroundColor().getIndex());
|
||||
style.setWrapText(excel.wrapText());
|
||||
Font dataFont = wb.createFont();
|
||||
dataFont.setFontName("Arial");
|
||||
dataFont.setFontHeightInPoints((short) 10);
|
||||
dataFont.setColor(excel.color().index);
|
||||
style.setFont(dataFont);
|
||||
if (ColumnType.TEXT == excel.cellType())
|
||||
{
|
||||
DataFormat dataFormat = wb.createDataFormat();
|
||||
style.setDataFormat(dataFormat.getFormat("@"));
|
||||
}
|
||||
styles.put(key, style);
|
||||
}
|
||||
}
|
||||
return styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建单元格
|
||||
*/
|
||||
public Cell createCell(Excel attr, Row row, int column)
|
||||
public Cell createHeadCell(Excel attr, Row row, int column)
|
||||
{
|
||||
// 创建列
|
||||
Cell cell = row.createCell(column);
|
||||
// 写入列信息
|
||||
cell.setCellValue(attr.name());
|
||||
setDataValidation(attr, row, column);
|
||||
cell.setCellStyle(styles.get("header"));
|
||||
cell.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor())));
|
||||
if (isSubList())
|
||||
{
|
||||
// 填充默认样式,防止合并单元格样式失效
|
||||
sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText())));
|
||||
if (attr.needMerge())
|
||||
{
|
||||
sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column));
|
||||
}
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
|
@ -613,7 +880,7 @@ public class ExcelUtil<T>
|
|||
*/
|
||||
public void setCellVo(Object value, Excel attr, Cell cell)
|
||||
{
|
||||
if (ColumnType.STRING == attr.cellType())
|
||||
if (ColumnType.STRING == attr.cellType() || ColumnType.TEXT == attr.cellType())
|
||||
{
|
||||
String cellValue = Convert.toStr(value);
|
||||
// 对于任何以表达式触发字符 =-+@开头的单元格,直接使用tab字符作为前缀,防止CSV注入。
|
||||
|
|
@ -621,6 +888,10 @@ public class ExcelUtil<T>
|
|||
{
|
||||
cellValue = RegExUtils.replaceFirst(cellValue, FORMULA_REGEX_STR, "\t$0");
|
||||
}
|
||||
if (value instanceof Collection && StringUtils.equals("[]", cellValue))
|
||||
{
|
||||
cellValue = StringUtils.EMPTY;
|
||||
}
|
||||
cell.setCellValue(StringUtils.isNull(cellValue) ? attr.defaultValue() : cellValue + attr.suffix());
|
||||
}
|
||||
else if (ColumnType.NUMERIC == attr.cellType())
|
||||
|
|
@ -687,11 +958,19 @@ public class ExcelUtil<T>
|
|||
sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0)
|
||||
{
|
||||
if (attr.combo().length > 15 || StringUtils.join(attr.combo()).length() > 255)
|
||||
{
|
||||
// 如果下拉数大于15或字符串长度大于255,则使用一个新sheet存储,避免生成的模板下拉值获取不到
|
||||
setXSSFValidationWithHidden(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 提示信息或只能选择不能输入的列内容.
|
||||
setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加单元格
|
||||
|
|
@ -708,7 +987,14 @@ public class ExcelUtil<T>
|
|||
{
|
||||
// 创建cell
|
||||
cell = row.createCell(column);
|
||||
cell.setCellStyle(styles.get("data_" + attr.align() + "_" + attr.color()));
|
||||
if (isSubListValue(vo) && getListCellValue(vo) > 1 && attr.needMerge())
|
||||
{
|
||||
if (subMergedLastRowNum >= subMergedFirstRowNum)
|
||||
{
|
||||
sheet.addMergedRegion(new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column));
|
||||
}
|
||||
}
|
||||
cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor(), attr.cellType(), attr.wrapText())));
|
||||
|
||||
// 用于读取对象中的属性
|
||||
Object value = getTargetValue(vo, field, attr);
|
||||
|
|
@ -717,6 +1003,7 @@ public class ExcelUtil<T>
|
|||
String separator = attr.separator();
|
||||
if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
||||
{
|
||||
cell.getCellStyle().setDataFormat(this.wb.getCreationHelper().createDataFormat().getFormat(dateFormat));
|
||||
cell.setCellValue(parseDateToStr(dateFormat, value));
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
|
||||
|
|
@ -725,11 +1012,11 @@ public class ExcelUtil<T>
|
|||
}
|
||||
else if (value instanceof BigDecimal && -1 != attr.scale())
|
||||
{
|
||||
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).toString());
|
||||
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).doubleValue());
|
||||
}
|
||||
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||
{
|
||||
cell.setCellValue(dataFormatHandlerAdapter(value, attr));
|
||||
cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -783,6 +1070,76 @@ public class ExcelUtil<T>
|
|||
sheet.addValidationData(dataValidation);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置某些列的值只能输入预制的数据,显示下拉框(兼容超出一定数量的下拉框).
|
||||
*
|
||||
* @param sheet 要设置的sheet.
|
||||
* @param textlist 下拉框显示的内容
|
||||
* @param promptContent 提示内容
|
||||
* @param firstRow 开始行
|
||||
* @param endRow 结束行
|
||||
* @param firstCol 开始列
|
||||
* @param endCol 结束列
|
||||
*/
|
||||
public void setXSSFValidationWithHidden(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, int firstCol, int endCol)
|
||||
{
|
||||
String hideSheetName = "combo_" + firstCol + "_" + endCol;
|
||||
Sheet hideSheet = null;
|
||||
String hideSheetDataName = hideSheetName + "_data";
|
||||
Name name = wb.getName(hideSheetDataName);
|
||||
if (name != null)
|
||||
{
|
||||
// 名称已存在,尝试从名称的引用中找到sheet名称
|
||||
String refersToFormula = name.getRefersToFormula();
|
||||
if (StringUtils.isNotEmpty(refersToFormula) && refersToFormula.contains("!"))
|
||||
{
|
||||
String sheetNameFromFormula = refersToFormula.substring(0, refersToFormula.indexOf("!"));
|
||||
hideSheet = wb.getSheet(sheetNameFromFormula);
|
||||
}
|
||||
}
|
||||
|
||||
if (hideSheet == null)
|
||||
{
|
||||
hideSheet = wb.createSheet(hideSheetName); // 用于存储 下拉菜单数据
|
||||
for (int i = 0; i < textlist.length; i++)
|
||||
{
|
||||
hideSheet.createRow(i).createCell(0).setCellValue(textlist[i]);
|
||||
}
|
||||
// 创建名称,可被其他单元格引用
|
||||
name = wb.createName();
|
||||
name.setNameName(hideSheetDataName);
|
||||
name.setRefersToFormula(hideSheetName + "!$A$1:$A$" + textlist.length);
|
||||
}
|
||||
|
||||
DataValidationHelper helper = sheet.getDataValidationHelper();
|
||||
// 加载下拉列表内容
|
||||
DataValidationConstraint constraint = helper.createFormulaListConstraint(hideSheetDataName);
|
||||
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
|
||||
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
|
||||
// 数据有效性对象
|
||||
DataValidation dataValidation = helper.createValidation(constraint, regions);
|
||||
if (StringUtils.isNotEmpty(promptContent))
|
||||
{
|
||||
// 如果设置了提示信息则鼠标放上去提示
|
||||
dataValidation.createPromptBox("", promptContent);
|
||||
dataValidation.setShowPromptBox(true);
|
||||
}
|
||||
// 处理Excel兼容性问题
|
||||
if (dataValidation instanceof XSSFDataValidation)
|
||||
{
|
||||
dataValidation.setSuppressDropDownArrow(true);
|
||||
dataValidation.setShowErrorBox(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataValidation.setSuppressDropDownArrow(false);
|
||||
}
|
||||
|
||||
sheet.addValidationData(dataValidation);
|
||||
// 设置hiddenSheet隐藏
|
||||
wb.setSheetHidden(wb.getSheetIndex(hideSheet), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析导出值 0=男,1=女,2=未知
|
||||
*
|
||||
|
|
@ -794,11 +1151,11 @@ public class ExcelUtil<T>
|
|||
public static String convertByExp(String propertyValue, String converterExp, String separator)
|
||||
{
|
||||
StringBuilder propertyString = new StringBuilder();
|
||||
String[] convertSource = converterExp.split(",");
|
||||
String[] convertSource = converterExp.split(SEPARATOR);
|
||||
for (String item : convertSource)
|
||||
{
|
||||
String[] itemArray = item.split("=");
|
||||
if (StringUtils.containsAny(separator, propertyValue))
|
||||
if (StringUtils.containsAny(propertyValue, separator))
|
||||
{
|
||||
for (String value : propertyValue.split(separator))
|
||||
{
|
||||
|
|
@ -831,11 +1188,11 @@ public class ExcelUtil<T>
|
|||
public static String reverseByExp(String propertyValue, String converterExp, String separator)
|
||||
{
|
||||
StringBuilder propertyString = new StringBuilder();
|
||||
String[] convertSource = converterExp.split(",");
|
||||
String[] convertSource = converterExp.split(SEPARATOR);
|
||||
for (String item : convertSource)
|
||||
{
|
||||
String[] itemArray = item.split("=");
|
||||
if (StringUtils.containsAny(separator, propertyValue))
|
||||
if (StringUtils.containsAny(propertyValue, separator))
|
||||
{
|
||||
for (String value : propertyValue.split(separator))
|
||||
{
|
||||
|
|
@ -864,13 +1221,13 @@ public class ExcelUtil<T>
|
|||
* @param excel 数据注解
|
||||
* @return
|
||||
*/
|
||||
public String dataFormatHandlerAdapter(Object value, Excel excel)
|
||||
public String dataFormatHandlerAdapter(Object value, Excel excel, Cell cell)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object instance = excel.handler().newInstance();
|
||||
Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class });
|
||||
value = formatMethod.invoke(instance, value, excel.args());
|
||||
Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class, Cell.class, Workbook.class });
|
||||
value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
@ -919,7 +1276,7 @@ public class ExcelUtil<T>
|
|||
{
|
||||
cell = row.createCell(key);
|
||||
cell.setCellStyle(styles.get("total"));
|
||||
cell.setCellValue(DOUBLE_FORMAT.format(statistics.get(key)));
|
||||
cell.setCellValue(statistics.get(key));
|
||||
}
|
||||
statistics.clear();
|
||||
}
|
||||
|
|
@ -936,6 +1293,7 @@ public class ExcelUtil<T>
|
|||
*/
|
||||
private Object getTargetValue(T vo, Field field, Excel excel) throws Exception
|
||||
{
|
||||
field.setAccessible(true);
|
||||
Object o = field.get(vo);
|
||||
if (StringUtils.isNotEmpty(excel.targetAttr()))
|
||||
{
|
||||
|
|
@ -993,9 +1351,44 @@ public class ExcelUtil<T>
|
|||
{
|
||||
List<Object[]> fields = new ArrayList<Object[]>();
|
||||
List<Field> tempFields = new ArrayList<>();
|
||||
subFieldsMap = new HashMap<>();
|
||||
subMethods = new HashMap<>();
|
||||
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
|
||||
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
||||
if (StringUtils.isNotEmpty(includeFields))
|
||||
{
|
||||
for (Field field : tempFields)
|
||||
{
|
||||
if (ArrayUtils.contains(this.includeFields, field.getName()) || field.isAnnotationPresent(Excels.class))
|
||||
{
|
||||
addField(fields, field);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(excludeFields))
|
||||
{
|
||||
for (Field field : tempFields)
|
||||
{
|
||||
if (!ArrayUtils.contains(this.excludeFields, field.getName()))
|
||||
{
|
||||
addField(fields, field);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Field field : tempFields)
|
||||
{
|
||||
addField(fields, field);
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加字段信息
|
||||
*/
|
||||
public void addField(List<Object[]> fields, Field field)
|
||||
{
|
||||
// 单注解
|
||||
if (field.isAnnotationPresent(Excel.class))
|
||||
|
|
@ -1003,9 +1396,16 @@ public class ExcelUtil<T>
|
|||
Excel attr = field.getAnnotation(Excel.class);
|
||||
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
||||
{
|
||||
field.setAccessible(true);
|
||||
fields.add(new Object[] { field, attr });
|
||||
}
|
||||
if (Collection.class.isAssignableFrom(field.getType()))
|
||||
{
|
||||
String fieldName = field.getName();
|
||||
subMethods.put(fieldName, getSubMethod(fieldName, clazz));
|
||||
ParameterizedType pt = (ParameterizedType) field.getGenericType();
|
||||
Class<?> subClass = (Class<?>) pt.getActualTypeArguments()[0];
|
||||
subFieldsMap.put(fieldName, FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class));
|
||||
}
|
||||
}
|
||||
|
||||
// 多注解
|
||||
|
|
@ -1015,15 +1415,24 @@ public class ExcelUtil<T>
|
|||
Excel[] excels = attrs.value();
|
||||
for (Excel attr : excels)
|
||||
{
|
||||
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
||||
if (StringUtils.isNotEmpty(includeFields))
|
||||
{
|
||||
if (ArrayUtils.contains(this.includeFields, field.getName() + "." + attr.targetAttr())
|
||||
&& (attr != null && (attr.type() == Type.ALL || attr.type() == type)))
|
||||
{
|
||||
fields.add(new Object[] { field, attr });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr())
|
||||
&& (attr != null && (attr.type() == Type.ALL || attr.type() == type)))
|
||||
{
|
||||
field.setAccessible(true);
|
||||
fields.add(new Object[] { field, attr });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1064,7 +1473,8 @@ public class ExcelUtil<T>
|
|||
{
|
||||
this.sheet = wb.createSheet();
|
||||
this.createTitle();
|
||||
wb.setSheetName(index, sheetName + index);
|
||||
int actualIndex = wb.getSheetIndex(this.sheet);
|
||||
wb.setSheetName(actualIndex, sheetName + index);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1183,4 +1593,69 @@ public class ExcelUtil<T>
|
|||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有对象的子列表
|
||||
*/
|
||||
public boolean isSubList()
|
||||
{
|
||||
return !StringUtils.isEmpty(subFieldsMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有对象的子列表,集合不为空
|
||||
*/
|
||||
public boolean isSubListValue(T vo)
|
||||
{
|
||||
return !StringUtils.isEmpty(subFieldsMap) && getListCellValue(vo) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取集合的值
|
||||
*/
|
||||
public int getListCellValue(Object obj)
|
||||
{
|
||||
Collection<?> value;
|
||||
int max = 0;
|
||||
try
|
||||
{
|
||||
for (String s : subMethods.keySet())
|
||||
{
|
||||
value = (Collection<?>) subMethods.get(s).invoke(obj);
|
||||
if (value.size() > max)
|
||||
{
|
||||
max = value.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象的子列表方法
|
||||
*
|
||||
* @param name 名称
|
||||
* @param pojoClass 类对象
|
||||
* @return 子列表方法
|
||||
*/
|
||||
public Method getSubMethod(String name, Class<?> pojoClass)
|
||||
{
|
||||
StringBuffer getMethodName = new StringBuffer("get");
|
||||
getMethodName.append(name.substring(0, 1).toUpperCase());
|
||||
getMethodName.append(name.substring(1));
|
||||
Method method = null;
|
||||
try
|
||||
{
|
||||
method = pojoClass.getMethod(getMethodName.toString(), new Class[] {});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("获取对象异常{}", e.getMessage());
|
||||
}
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,18 @@ public class SqlUtil
|
|||
/**
|
||||
* 定义常用的 sql关键字
|
||||
*/
|
||||
public static String SQL_REGEX = "select |insert |delete |update |drop |count |exec |chr |mid |master |truncate |char |and |declare ";
|
||||
public static String SQL_REGEX = "\u000B|and |extractvalue|updatexml|sleep|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |union |like |+|/*|user()";
|
||||
|
||||
/**
|
||||
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
||||
*/
|
||||
public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+";
|
||||
|
||||
/**
|
||||
* 限制orderBy最大长度
|
||||
*/
|
||||
private static final int ORDER_BY_MAX_LENGTH = 500;
|
||||
|
||||
/**
|
||||
* 检查字符,防止注入绕过
|
||||
*/
|
||||
|
|
@ -29,6 +34,10 @@ public class SqlUtil
|
|||
{
|
||||
throw new UtilException("参数不符合规范,不能进行查询");
|
||||
}
|
||||
if (StringUtils.length(value) > ORDER_BY_MAX_LENGTH)
|
||||
{
|
||||
throw new UtilException("参数已超过最大限制,不能进行查询");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class Seq
|
|||
private static AtomicInteger uploadSeq = new AtomicInteger(1);
|
||||
|
||||
// 机器标识
|
||||
private static String machineCode = "A";
|
||||
private static final String machineCode = "A";
|
||||
|
||||
/**
|
||||
* 获取通用序列号
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的本地线程伪随机数生成器生成该 UUID。
|
||||
* 获取类型 4(伪随机生成的)UUID 的静态工厂。
|
||||
*
|
||||
* @return 随机生成的 {@code UUID}
|
||||
*/
|
||||
|
|
@ -343,25 +343,25 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
|||
final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36);
|
||||
// time_low
|
||||
builder.append(digits(mostSigBits >> 32, 8));
|
||||
if (false == isSimple)
|
||||
if (!isSimple)
|
||||
{
|
||||
builder.append('-');
|
||||
}
|
||||
// time_mid
|
||||
builder.append(digits(mostSigBits >> 16, 4));
|
||||
if (false == isSimple)
|
||||
if (!isSimple)
|
||||
{
|
||||
builder.append('-');
|
||||
}
|
||||
// time_high_and_version
|
||||
builder.append(digits(mostSigBits, 4));
|
||||
if (false == isSimple)
|
||||
if (!isSimple)
|
||||
{
|
||||
builder.append('-');
|
||||
}
|
||||
// variant_and_sequence
|
||||
builder.append(digits(leastSigBits >> 48, 4));
|
||||
if (false == isSimple)
|
||||
if (!isSimple)
|
||||
{
|
||||
builder.append('-');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,17 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ruoyi.common.core.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.PageUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.sql.SqlUtil;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.core.web.page.TableSupport;
|
||||
|
||||
/**
|
||||
* web层通用数据处理
|
||||
|
|
@ -48,6 +53,19 @@ public class BaseController
|
|||
PageUtils.startPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求排序数据
|
||||
*/
|
||||
protected void startOrderBy()
|
||||
{
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
if (StringUtils.isNotEmpty(pageDomain.getOrderBy()))
|
||||
{
|
||||
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
|
||||
PageHelper.orderBy(orderBy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理分页的线程变量
|
||||
*/
|
||||
|
|
@ -70,6 +88,54 @@ public class BaseController
|
|||
return rspData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功
|
||||
*/
|
||||
public AjaxResult success()
|
||||
{
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*/
|
||||
public AjaxResult success(String message)
|
||||
{
|
||||
return AjaxResult.success(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*/
|
||||
public AjaxResult success(Object data)
|
||||
{
|
||||
return AjaxResult.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败消息
|
||||
*/
|
||||
public AjaxResult error()
|
||||
{
|
||||
return AjaxResult.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败消息
|
||||
*/
|
||||
public AjaxResult error(String message)
|
||||
{
|
||||
return AjaxResult.error(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回警告消息
|
||||
*/
|
||||
public AjaxResult warn(String message)
|
||||
{
|
||||
return AjaxResult.warn(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应返回结果
|
||||
*
|
||||
|
|
@ -91,36 +157,4 @@ public class BaseController
|
|||
{
|
||||
return result ? success() : error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功
|
||||
*/
|
||||
public AjaxResult success()
|
||||
{
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败消息
|
||||
*/
|
||||
public AjaxResult error()
|
||||
{
|
||||
return AjaxResult.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*/
|
||||
public AjaxResult success(String message)
|
||||
{
|
||||
return AjaxResult.success(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败消息
|
||||
*/
|
||||
public AjaxResult error(String message)
|
||||
{
|
||||
return AjaxResult.error(message);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.ruoyi.common.core.web.domain;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import com.ruoyi.common.core.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
|
||||
|
|
@ -58,20 +59,6 @@ public class AjaxResult extends HashMap<String, Object>
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 方便链式调用
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult put(String key, Object value)
|
||||
{
|
||||
super.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
|
|
@ -115,10 +102,33 @@ public class AjaxResult extends HashMap<String, Object>
|
|||
return new AjaxResult(HttpStatus.SUCCESS, msg, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回警告消息
|
||||
*
|
||||
* @param msg 返回内容
|
||||
* @return 警告消息
|
||||
*/
|
||||
public static AjaxResult warn(String msg)
|
||||
{
|
||||
return AjaxResult.warn(msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回警告消息
|
||||
*
|
||||
* @param msg 返回内容
|
||||
* @param data 数据对象
|
||||
* @return 警告消息
|
||||
*/
|
||||
public static AjaxResult warn(String msg, Object data)
|
||||
{
|
||||
return new AjaxResult(HttpStatus.WARN, msg, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回错误消息
|
||||
*
|
||||
* @return
|
||||
* @return 错误消息
|
||||
*/
|
||||
public static AjaxResult error()
|
||||
{
|
||||
|
|
@ -129,7 +139,7 @@ public class AjaxResult extends HashMap<String, Object>
|
|||
* 返回错误消息
|
||||
*
|
||||
* @param msg 返回内容
|
||||
* @return 警告消息
|
||||
* @return 错误消息
|
||||
*/
|
||||
public static AjaxResult error(String msg)
|
||||
{
|
||||
|
|
@ -141,7 +151,7 @@ public class AjaxResult extends HashMap<String, Object>
|
|||
*
|
||||
* @param msg 返回内容
|
||||
* @param data 数据对象
|
||||
* @return 警告消息
|
||||
* @return 错误消息
|
||||
*/
|
||||
public static AjaxResult error(String msg, Object data)
|
||||
{
|
||||
|
|
@ -153,10 +163,54 @@ public class AjaxResult extends HashMap<String, Object>
|
|||
*
|
||||
* @param code 状态码
|
||||
* @param msg 返回内容
|
||||
* @return 警告消息
|
||||
* @return 错误消息
|
||||
*/
|
||||
public static AjaxResult error(int code, String msg)
|
||||
{
|
||||
return new AjaxResult(code, msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为成功消息
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean isSuccess()
|
||||
{
|
||||
return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG));
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为警告消息
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean isWarn()
|
||||
{
|
||||
return Objects.equals(HttpStatus.WARN, this.get(CODE_TAG));
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为错误消息
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean isError()
|
||||
{
|
||||
return Objects.equals(HttpStatus.ERROR, this.get(CODE_TAG));
|
||||
}
|
||||
|
||||
/**
|
||||
* 方便链式调用
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult put(String key, Object value)
|
||||
{
|
||||
super.put(key, value);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
/**
|
||||
* Entity基类
|
||||
|
|
@ -16,6 +18,7 @@ public class BaseEntity implements Serializable
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 搜索值 */
|
||||
@JsonIgnore
|
||||
private String searchValue;
|
||||
|
||||
/** 创建者 */
|
||||
|
|
@ -36,6 +39,7 @@ public class BaseEntity implements Serializable
|
|||
private String remark;
|
||||
|
||||
/** 请求参数 */
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private Map<String, Object> params;
|
||||
|
||||
public String getSearchValue()
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class TableDataInfo implements Serializable
|
|||
* @param list 列表数据
|
||||
* @param total 总记录数
|
||||
*/
|
||||
public TableDataInfo(List<?> list, int total)
|
||||
public TableDataInfo(List<?> list, long total)
|
||||
{
|
||||
this.rows = list;
|
||||
this.total = total;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,13 @@ public class XssValidator implements ConstraintValidator<Xss, String>
|
|||
|
||||
public static boolean containsHtml(String value)
|
||||
{
|
||||
StringBuilder sHtml = new StringBuilder();
|
||||
Pattern pattern = Pattern.compile(HTML_PATTERN);
|
||||
Matcher matcher = pattern.matcher(value);
|
||||
return matcher.matches();
|
||||
while (matcher.find())
|
||||
{
|
||||
sHtml.append(matcher.group());
|
||||
}
|
||||
return pattern.matcher(sHtml).matches();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -25,4 +25,9 @@ public @interface DataScope
|
|||
* 用户表的别名
|
||||
*/
|
||||
public String userAlias() default "";
|
||||
|
||||
/**
|
||||
* 权限字符(用于多个角色匹配符合要求的权限)默认根据权限注解@RequiresPermissions获取,多个权限用逗号分隔开来
|
||||
*/
|
||||
public String permission() default "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
package com.ruoyi.common.datascope.aspect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.context.SecurityContextHolder;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import com.ruoyi.common.datascope.annotation.DataScope;
|
||||
|
|
@ -68,8 +73,8 @@ public class DataScopeAspect
|
|||
// 如果是超级管理员,则不过滤数据
|
||||
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
|
||||
{
|
||||
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
|
||||
controllerDataScope.userAlias());
|
||||
String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), SecurityContextHolder.getPermission());
|
||||
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), controllerDataScope.userAlias(), permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -81,24 +86,48 @@ public class DataScopeAspect
|
|||
* @param user 用户
|
||||
* @param deptAlias 部门别名
|
||||
* @param userAlias 用户别名
|
||||
* @param permission 权限字符
|
||||
*/
|
||||
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias)
|
||||
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String permission)
|
||||
{
|
||||
StringBuilder sqlString = new StringBuilder();
|
||||
List<String> conditions = new ArrayList<String>();
|
||||
List<String> scopeCustomIds = new ArrayList<String>();
|
||||
user.getRoles().forEach(role -> {
|
||||
if (DATA_SCOPE_CUSTOM.equals(role.getDataScope()) && StringUtils.equals(role.getStatus(), UserConstants.ROLE_NORMAL) && (StringUtils.isEmpty(permission) || StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission))))
|
||||
{
|
||||
scopeCustomIds.add(Convert.toStr(role.getRoleId()));
|
||||
}
|
||||
});
|
||||
|
||||
for (SysRole role : user.getRoles())
|
||||
{
|
||||
String dataScope = role.getDataScope();
|
||||
if (conditions.contains(dataScope) || StringUtils.equals(role.getStatus(), UserConstants.ROLE_DISABLE))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(permission) && !StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (DATA_SCOPE_ALL.equals(dataScope))
|
||||
{
|
||||
sqlString = new StringBuilder();
|
||||
conditions.add(dataScope);
|
||||
break;
|
||||
}
|
||||
else if (DATA_SCOPE_CUSTOM.equals(dataScope))
|
||||
{
|
||||
sqlString.append(StringUtils.format(
|
||||
" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,
|
||||
role.getRoleId()));
|
||||
if (scopeCustomIds.size() > 1)
|
||||
{
|
||||
// 多个自定数据权限使用in查询,避免多次拼接。
|
||||
sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id in ({}) ) ", deptAlias, String.join(",", scopeCustomIds)));
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, role.getRoleId()));
|
||||
}
|
||||
}
|
||||
else if (DATA_SCOPE_DEPT.equals(dataScope))
|
||||
{
|
||||
|
|
@ -106,9 +135,7 @@ public class DataScopeAspect
|
|||
}
|
||||
else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
|
||||
{
|
||||
sqlString.append(StringUtils.format(
|
||||
" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
|
||||
deptAlias, user.getDeptId(), user.getDeptId()));
|
||||
sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", deptAlias, user.getDeptId(), user.getDeptId()));
|
||||
}
|
||||
else if (DATA_SCOPE_SELF.equals(dataScope))
|
||||
{
|
||||
|
|
@ -122,6 +149,13 @@ public class DataScopeAspect
|
|||
sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
|
||||
}
|
||||
}
|
||||
conditions.add(dataScope);
|
||||
}
|
||||
|
||||
// 角色都不包含传递过来的权限字符,这个时候sqlString也会为空,所以要限制一下,不查询任何数据
|
||||
if (StringUtils.isEmpty(conditions))
|
||||
{
|
||||
sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(sqlString.toString()))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
@ -31,11 +31,5 @@
|
|||
<version>${dynamic-ds.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Seata -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -43,4 +43,9 @@ public @interface Log
|
|||
* 是否保存响应的参数
|
||||
*/
|
||||
public boolean isSaveResponseData() default true;
|
||||
|
||||
/**
|
||||
* 排除指定的请求参数
|
||||
*/
|
||||
public String[] excludeParamNames() default {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,23 +4,29 @@ import java.util.Collection;
|
|||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.NamedThreadLocal;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.core.utils.ExceptionUtil;
|
||||
import com.ruoyi.common.core.utils.ServletUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.ip.IpUtils;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessStatus;
|
||||
import com.ruoyi.common.log.filter.PropertyPreExcludeFilter;
|
||||
import com.ruoyi.common.log.service.AsyncLogService;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.system.api.domain.SysOperLog;
|
||||
|
|
@ -36,9 +42,27 @@ public class LogAspect
|
|||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
|
||||
|
||||
/** 排除敏感属性字段 */
|
||||
public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
||||
|
||||
/** 计算操作消耗时间 */
|
||||
private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
|
||||
|
||||
/** 参数最大长度限制 */
|
||||
private static final int PARAM_MAX_LENGTH = 2000;
|
||||
|
||||
@Autowired
|
||||
private AsyncLogService asyncLogService;
|
||||
|
||||
/**
|
||||
* 处理请求前执行
|
||||
*/
|
||||
@Before(value = "@annotation(controllerLog)")
|
||||
public void doBefore(JoinPoint joinPoint, Log controllerLog)
|
||||
{
|
||||
TIME_THREADLOCAL.set(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理完请求后执行
|
||||
*
|
||||
|
|
@ -70,9 +94,9 @@ public class LogAspect
|
|||
SysOperLog operLog = new SysOperLog();
|
||||
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
||||
// 请求的地址
|
||||
String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
|
||||
String ip = IpUtils.getIpAddr();
|
||||
operLog.setOperIp(ip);
|
||||
operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
|
||||
operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
|
||||
String username = SecurityUtils.getUsername();
|
||||
if (StringUtils.isNotBlank(username))
|
||||
{
|
||||
|
|
@ -82,7 +106,7 @@ public class LogAspect
|
|||
if (e != null)
|
||||
{
|
||||
operLog.setStatus(BusinessStatus.FAIL.ordinal());
|
||||
operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
|
||||
operLog.setErrorMsg(StringUtils.substring(Convert.toStr(e.getMessage(), ExceptionUtil.getExceptionMessage(e)), 0, 2000));
|
||||
}
|
||||
// 设置方法名称
|
||||
String className = joinPoint.getTarget().getClass().getName();
|
||||
|
|
@ -92,16 +116,21 @@ public class LogAspect
|
|||
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
||||
// 处理设置注解上的参数
|
||||
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
||||
// 设置消耗时间
|
||||
operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
|
||||
// 保存数据库
|
||||
asyncLogService.saveSysLog(operLog);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
// 记录本地异常日志
|
||||
log.error("==前置通知异常==");
|
||||
log.error("异常信息:{}", exp.getMessage());
|
||||
exp.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
TIME_THREADLOCAL.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -123,7 +152,7 @@ public class LogAspect
|
|||
if (log.isSaveRequestData())
|
||||
{
|
||||
// 获取参数的信息,传入到数据库中。
|
||||
setRequestValue(joinPoint, operLog);
|
||||
setRequestValue(joinPoint, operLog, log.excludeParamNames());
|
||||
}
|
||||
// 是否需要保存response,参数和值
|
||||
if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult))
|
||||
|
|
@ -138,22 +167,27 @@ public class LogAspect
|
|||
* @param operLog 操作日志
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception
|
||||
private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog, String[] excludeParamNames) throws Exception
|
||||
{
|
||||
String requestMethod = operLog.getRequestMethod();
|
||||
if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))
|
||||
Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
||||
if (StringUtils.isEmpty(paramsMap) && StringUtils.equalsAny(requestMethod, HttpMethod.PUT.name(), HttpMethod.POST.name(), HttpMethod.DELETE.name()))
|
||||
{
|
||||
String params = argsArrayToString(joinPoint.getArgs());
|
||||
operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
||||
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
|
||||
operLog.setOperParam(params);
|
||||
}
|
||||
else
|
||||
{
|
||||
operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter(excludeParamNames)), 0, PARAM_MAX_LENGTH));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数拼装
|
||||
*/
|
||||
private String argsArrayToString(Object[] paramsArray)
|
||||
private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames)
|
||||
{
|
||||
String params = "";
|
||||
StringBuilder params = new StringBuilder();
|
||||
if (paramsArray != null && paramsArray.length > 0)
|
||||
{
|
||||
for (Object o : paramsArray)
|
||||
|
|
@ -162,16 +196,29 @@ public class LogAspect
|
|||
{
|
||||
try
|
||||
{
|
||||
Object jsonObj = JSON.toJSON(o);
|
||||
params += jsonObj.toString() + " ";
|
||||
String jsonObj = JSON.toJSONString(o, excludePropertyPreFilter(excludeParamNames));
|
||||
params.append(jsonObj).append(" ");
|
||||
if (params.length() >= PARAM_MAX_LENGTH)
|
||||
{
|
||||
return StringUtils.substring(params.toString(), 0, PARAM_MAX_LENGTH);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("请求参数拼装异常 msg:{}, 参数:{}", e.getMessage(), paramsArray, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return params.trim();
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 忽略敏感属性
|
||||
*/
|
||||
public PropertyPreExcludeFilter excludePropertyPreFilter(String[] excludeParamNames)
|
||||
{
|
||||
return new PropertyPreExcludeFilter().addExcludes(ArrayUtils.addAll(EXCLUDE_PROPERTIES, excludeParamNames));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.ruoyi.common.log.filter;
|
||||
|
||||
import com.alibaba.fastjson2.filter.SimplePropertyPreFilter;
|
||||
|
||||
/**
|
||||
* 排除JSON敏感属性
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class PropertyPreExcludeFilter extends SimplePropertyPreFilter
|
||||
{
|
||||
public PropertyPreExcludeFilter()
|
||||
{
|
||||
}
|
||||
|
||||
public PropertyPreExcludeFilter addExcludes(String... filters)
|
||||
{
|
||||
for (int i = 0; i < filters.length; i++)
|
||||
{
|
||||
this.getExcludes().add(filters[i]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ public class AsyncLogService
|
|||
* 保存系统日志记录
|
||||
*/
|
||||
@Async
|
||||
public void saveSysLog(SysOperLog sysOperLog)
|
||||
public void saveSysLog(SysOperLog sysOperLog) throws Exception
|
||||
{
|
||||
remoteLogService.saveLog(sysOperLog, SecurityConstants.INNER);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import org.springframework.data.redis.serializer.SerializationException;
|
|||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.filter.Filter;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
|
||||
/**
|
||||
* Redis使用FastJson序列化
|
||||
|
|
@ -16,8 +18,9 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
|||
{
|
||||
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
|
||||
private Class<T> clazz;
|
||||
static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(Constants.JSON_WHITELIST_STR);
|
||||
|
||||
private Class<T> clazz;
|
||||
|
||||
public FastJson2JsonRedisSerializer(Class<T> clazz)
|
||||
{
|
||||
|
|
@ -44,6 +47,6 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
|||
}
|
||||
String str = new String(bytes, DEFAULT_CHARSET);
|
||||
|
||||
return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType);
|
||||
return JSON.parseObject(str, clazz, AUTO_TYPE_FILTER);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,9 +124,9 @@ public class RedisService
|
|||
* @param collection 多个对象
|
||||
* @return
|
||||
*/
|
||||
public long deleteObject(final Collection collection)
|
||||
public boolean deleteObject(final Collection collection)
|
||||
{
|
||||
return redisTemplate.delete(collection);
|
||||
return redisTemplate.delete(collection) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -243,6 +243,18 @@ public class RedisService
|
|||
return redisTemplate.opsForHash().multiGet(key, hKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除Hash中的某条数据
|
||||
*
|
||||
* @param key Redis键
|
||||
* @param hKey Hash键
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean deleteCacheMapValue(final String key, final String hKey)
|
||||
{
|
||||
return redisTemplate.opsForHash().delete(key, hKey) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得缓存的基本对象列表
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ruoyi-common-seata</artifactId>
|
||||
|
||||
<description>
|
||||
ruoyi-common-seata分布式事务
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringBoot Seata -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -56,16 +56,8 @@ public class PreAuthorizeAspect
|
|||
// 注解鉴权
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
checkMethodAnnotation(signature.getMethod());
|
||||
try
|
||||
{
|
||||
// 执行原有逻辑
|
||||
Object obj = joinPoint.proceed();
|
||||
return obj;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.util.Collection;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.springframework.util.PatternMatchUtils;
|
||||
import com.ruoyi.common.core.context.SecurityContextHolder;
|
||||
import com.ruoyi.common.core.exception.auth.NotLoginException;
|
||||
import com.ruoyi.common.core.exception.auth.NotPermissionException;
|
||||
import com.ruoyi.common.core.exception.auth.NotRoleException;
|
||||
|
|
@ -134,6 +135,7 @@ public class AuthLogic
|
|||
*/
|
||||
public void checkPermi(RequiresPermissions requiresPermissions)
|
||||
{
|
||||
SecurityContextHolder.setPermission(StringUtils.join(requiresPermissions.value(), ","));
|
||||
if (requiresPermissions.logical() == Logical.AND)
|
||||
{
|
||||
checkPermiAnd(requiresPermissions.value());
|
||||
|
|
@ -353,7 +355,7 @@ public class AuthLogic
|
|||
public boolean hasPermi(Collection<String> authorities, String permission)
|
||||
{
|
||||
return authorities.stream().filter(StringUtils::hasText)
|
||||
.anyMatch(x -> ALL_PERMISSION.contains(x) || PatternMatchUtils.simpleMatch(x, permission));
|
||||
.anyMatch(x -> ALL_PERMISSION.equals(x) || PatternMatchUtils.simpleMatch(x, permission));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -366,6 +368,6 @@ public class AuthLogic
|
|||
public boolean hasRole(Collection<String> roles, String role)
|
||||
{
|
||||
return roles.stream().filter(StringUtils::hasText)
|
||||
.anyMatch(x -> SUPER_ADMIN.contains(x) || PatternMatchUtils.simpleMatch(x, role));
|
||||
.anyMatch(x -> SUPER_ADMIN.equals(x) || PatternMatchUtils.simpleMatch(x, role));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class AuthUtil
|
|||
/**
|
||||
* 会话注销,根据指定Token
|
||||
*
|
||||
* @param tokenValue 指定token
|
||||
* @param token 指定token
|
||||
*/
|
||||
public static void logoutByToken(String token)
|
||||
{
|
||||
|
|
@ -44,6 +44,9 @@ public class AuthUtil
|
|||
|
||||
/**
|
||||
* 获取当前登录用户信息
|
||||
*
|
||||
* @param token 指定token
|
||||
* @return 用户信息
|
||||
*/
|
||||
public static LoginUser getLoginUser(String token)
|
||||
{
|
||||
|
|
@ -52,6 +55,8 @@ public class AuthUtil
|
|||
|
||||
/**
|
||||
* 验证当前用户有效期
|
||||
*
|
||||
* @param loginUser 用户信息
|
||||
*/
|
||||
public static void verifyLoginUserExpire(LoginUser loginUser)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@ public class FeignRequestInterceptor implements RequestInterceptor
|
|||
{
|
||||
requestTemplate.header(SecurityConstants.DETAILS_USER_ID, userId);
|
||||
}
|
||||
String userKey = headers.get(SecurityConstants.USER_KEY);
|
||||
if (StringUtils.isNotEmpty(userKey))
|
||||
{
|
||||
requestTemplate.header(SecurityConstants.USER_KEY, userKey);
|
||||
}
|
||||
String userName = headers.get(SecurityConstants.DETAILS_USERNAME);
|
||||
if (StringUtils.isNotEmpty(userName))
|
||||
{
|
||||
|
|
@ -43,7 +48,7 @@ public class FeignRequestInterceptor implements RequestInterceptor
|
|||
}
|
||||
|
||||
// 配置客户端IP
|
||||
requestTemplate.header("X-Forwarded-For", IpUtils.getIpAddr(ServletUtils.getRequest()));
|
||||
requestTemplate.header("X-Forwarded-For", IpUtils.getIpAddr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,15 +6,19 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.MissingPathVariableException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
import com.ruoyi.common.core.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.exception.DemoModeException;
|
||||
import com.ruoyi.common.core.exception.InnerAuthException;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.exception.auth.NotPermissionException;
|
||||
import com.ruoyi.common.core.exception.auth.NotRoleException;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.html.EscapeUtil;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
|
||||
/**
|
||||
|
|
@ -53,8 +57,7 @@ public class GlobalExceptionHandler
|
|||
* 请求方式不支持
|
||||
*/
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||
public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,
|
||||
HttpServletRequest request)
|
||||
public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request)
|
||||
{
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
|
||||
|
|
@ -72,6 +75,33 @@ public class GlobalExceptionHandler
|
|||
return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求路径中缺少必需的路径变量
|
||||
*/
|
||||
@ExceptionHandler(MissingPathVariableException.class)
|
||||
public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request)
|
||||
{
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
|
||||
return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求参数类型不匹配
|
||||
*/
|
||||
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
|
||||
public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request)
|
||||
{
|
||||
String requestURI = request.getRequestURI();
|
||||
String value = Convert.toStr(e.getValue());
|
||||
if (StringUtils.isNotEmpty(value))
|
||||
{
|
||||
value = EscapeUtil.clean(value);
|
||||
}
|
||||
log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
|
||||
return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截未知的运行时异常
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.core.constant.CacheConstants;
|
||||
|
|
@ -25,6 +27,8 @@ import com.ruoyi.system.api.model.LoginUser;
|
|||
@Component
|
||||
public class TokenService
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(TokenService.class);
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
|
@ -32,11 +36,11 @@ public class TokenService
|
|||
|
||||
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
|
||||
|
||||
private final static long expireTime = CacheConstants.EXPIRATION;
|
||||
private final static long TOKEN_EXPIRE_TIME = CacheConstants.EXPIRATION;
|
||||
|
||||
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
|
||||
|
||||
private final static Long MILLIS_MINUTE_TEN = CacheConstants.REFRESH_TIME * MILLIS_MINUTE;
|
||||
private final static Long TOKEN_REFRESH_THRESHOLD_MINUTES = CacheConstants.REFRESH_TIME * MILLIS_MINUTE;
|
||||
|
||||
/**
|
||||
* 创建令牌
|
||||
|
|
@ -49,7 +53,7 @@ public class TokenService
|
|||
loginUser.setToken(token);
|
||||
loginUser.setUserid(userId);
|
||||
loginUser.setUsername(userName);
|
||||
loginUser.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
||||
loginUser.setIpaddr(IpUtils.getIpAddr());
|
||||
refreshToken(loginUser);
|
||||
|
||||
// Jwt存储信息
|
||||
|
|
@ -61,7 +65,7 @@ public class TokenService
|
|||
// 接口返回信息
|
||||
Map<String, Object> rspMap = new HashMap<String, Object>();
|
||||
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
||||
rspMap.put("expires_in", expireTime);
|
||||
rspMap.put("expires_in", TOKEN_EXPIRE_TIME);
|
||||
return rspMap;
|
||||
}
|
||||
|
||||
|
|
@ -106,6 +110,7 @@ public class TokenService
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("获取用户信息异常'{}'", e.getMessage());
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
|
@ -142,7 +147,7 @@ public class TokenService
|
|||
{
|
||||
long expireTime = loginUser.getExpireTime();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (expireTime - currentTime <= MILLIS_MINUTE_TEN)
|
||||
if (expireTime - currentTime <= TOKEN_REFRESH_THRESHOLD_MINUTES)
|
||||
{
|
||||
refreshToken(loginUser);
|
||||
}
|
||||
|
|
@ -156,10 +161,10 @@ public class TokenService
|
|||
public void refreshToken(LoginUser loginUser)
|
||||
{
|
||||
loginUser.setLoginTime(System.currentTimeMillis());
|
||||
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
|
||||
loginUser.setExpireTime(loginUser.getLoginTime() + TOKEN_EXPIRE_TIME * MILLIS_MINUTE);
|
||||
// 根据uuid将loginUser缓存
|
||||
String userKey = getTokenKey(loginUser.getToken());
|
||||
redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
|
||||
redisService.setCacheObject(userKey, loginUser, TOKEN_EXPIRE_TIME, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
private String getTokenKey(String token)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package com.ruoyi.common.security.utils;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.redis.service.RedisService;
|
||||
|
|
@ -58,7 +58,7 @@ public class DictUtils
|
|||
*/
|
||||
public static void clearDictCache()
|
||||
{
|
||||
Collection<String> keys = SpringUtils.getBean(RedisService.class).keys(Constants.SYS_DICT_KEY + "*");
|
||||
Collection<String> keys = SpringUtils.getBean(RedisService.class).keys(CacheConstants.SYS_DICT_KEY + "*");
|
||||
SpringUtils.getBean(RedisService.class).deleteObject(keys);
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +70,6 @@ public class DictUtils
|
|||
*/
|
||||
public static String getCacheKey(String configKey)
|
||||
{
|
||||
return Constants.SYS_DICT_KEY + configKey;
|
||||
return CacheConstants.SYS_DICT_KEY + configKey;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class SecurityUtils
|
|||
public static String getToken(HttpServletRequest request)
|
||||
{
|
||||
// 从header获取token标识
|
||||
String token = request.getHeader(TokenConstants.AUTHENTICATION);
|
||||
String token = request.getHeader(SecurityConstants.AUTHORIZATION_HEADER);
|
||||
return replaceTokenPrefix(token);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ruoyi-common-sensitive</artifactId>
|
||||
|
||||
<description>
|
||||
ruoyi-common-sensitive数据脱敏
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- RuoYi Common Core -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.ruoyi.common.sensitive.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.ruoyi.common.sensitive.config.SensitiveJsonSerializer;
|
||||
import com.ruoyi.common.sensitive.enums.DesensitizedType;
|
||||
|
||||
/**
|
||||
* 数据脱敏注解
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@JacksonAnnotationsInside
|
||||
@JsonSerialize(using = SensitiveJsonSerializer.class)
|
||||
public @interface Sensitive
|
||||
{
|
||||
DesensitizedType desensitizedType();
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package com.ruoyi.common.sensitive.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.BeanProperty;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.context.SecurityContextHolder;
|
||||
import com.ruoyi.common.sensitive.annotation.Sensitive;
|
||||
import com.ruoyi.common.sensitive.enums.DesensitizedType;
|
||||
|
||||
/**
|
||||
* 数据脱敏序列化过滤
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class SensitiveJsonSerializer extends JsonSerializer<String> implements ContextualSerializer
|
||||
{
|
||||
private DesensitizedType desensitizedType;
|
||||
|
||||
@Override
|
||||
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException
|
||||
{
|
||||
if (desensitization())
|
||||
{
|
||||
gen.writeString(desensitizedType.desensitizer().apply(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
gen.writeString(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property)
|
||||
throws JsonMappingException
|
||||
{
|
||||
Sensitive annotation = property.getAnnotation(Sensitive.class);
|
||||
if (Objects.nonNull(annotation) && Objects.equals(String.class, property.getType().getRawClass()))
|
||||
{
|
||||
this.desensitizedType = annotation.desensitizedType();
|
||||
return this;
|
||||
}
|
||||
return prov.findValueSerializer(property.getType(), property);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要脱敏处理
|
||||
*/
|
||||
private boolean desensitization()
|
||||
{
|
||||
try
|
||||
{
|
||||
Long userId = SecurityContextHolder.getUserId();
|
||||
// 管理员不脱敏
|
||||
return !UserConstants.isAdmin(userId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.ruoyi.common.sensitive.enums;
|
||||
|
||||
import java.util.function.Function;
|
||||
import com.ruoyi.common.sensitive.utils.DesensitizedUtil;
|
||||
|
||||
/**
|
||||
* 脱敏类型
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public enum DesensitizedType
|
||||
{
|
||||
/**
|
||||
* 姓名,第2位星号替换
|
||||
*/
|
||||
USERNAME(s -> s.replaceAll("(\\S)\\S(\\S*)", "$1*$2")),
|
||||
|
||||
/**
|
||||
* 密码,全部字符都用*代替
|
||||
*/
|
||||
PASSWORD(DesensitizedUtil::password),
|
||||
|
||||
/**
|
||||
* 身份证,中间10位星号替换
|
||||
*/
|
||||
ID_CARD(s -> s.replaceAll("(\\d{4})\\d{10}(\\d{3}[Xx]|\\d{4})", "$1** **** ****$2")),
|
||||
|
||||
/**
|
||||
* 手机号,中间4位星号替换
|
||||
*/
|
||||
PHONE(s -> s.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")),
|
||||
|
||||
/**
|
||||
* 电子邮箱,仅显示第一个字母和@后面的地址显示,其他星号替换
|
||||
*/
|
||||
EMAIL(s -> s.replaceAll("(^.)[^@]*(@.*$)", "$1****$2")),
|
||||
|
||||
/**
|
||||
* 银行卡号,保留最后4位,其他星号替换
|
||||
*/
|
||||
BANK_CARD(s -> s.replaceAll("\\d{15}(\\d{3})", "**** **** **** **** $1")),
|
||||
|
||||
/**
|
||||
* 车牌号码,包含普通车辆、新能源车辆
|
||||
*/
|
||||
CAR_LICENSE(DesensitizedUtil::carLicense);
|
||||
|
||||
private final Function<String, String> desensitizer;
|
||||
|
||||
DesensitizedType(Function<String, String> desensitizer)
|
||||
{
|
||||
this.desensitizer = desensitizer;
|
||||
}
|
||||
|
||||
public Function<String, String> desensitizer()
|
||||
{
|
||||
return desensitizer;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.ruoyi.common.sensitive.utils;
|
||||
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* 脱敏工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class DesensitizedUtil
|
||||
{
|
||||
/**
|
||||
* 密码的全部字符都用*代替,比如:******
|
||||
*
|
||||
* @param password 密码
|
||||
* @return 脱敏后的密码
|
||||
*/
|
||||
public static String password(String password)
|
||||
{
|
||||
if (StringUtils.isBlank(password))
|
||||
{
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
return StringUtils.repeat('*', password.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* 车牌中间用*代替,如果是错误的车牌,不处理
|
||||
*
|
||||
* @param carLicense 完整的车牌号
|
||||
* @return 脱敏后的车牌
|
||||
*/
|
||||
public static String carLicense(String carLicense)
|
||||
{
|
||||
if (StringUtils.isBlank(carLicense))
|
||||
{
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
// 普通车牌
|
||||
if (carLicense.length() == 7)
|
||||
{
|
||||
carLicense = StringUtils.hide(carLicense, 3, 6);
|
||||
}
|
||||
else if (carLicense.length() == 8)
|
||||
{
|
||||
// 新能源车牌
|
||||
carLicense = StringUtils.hide(carLicense, 3, 7);
|
||||
}
|
||||
return carLicense;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
@ -23,11 +23,10 @@
|
|||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger -->
|
||||
<!-- SpringDoc webmvc -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
package com.ruoyi.common.swagger.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import com.ruoyi.common.swagger.config.SwaggerAutoConfiguration;
|
||||
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import({ SwaggerAutoConfiguration.class })
|
||||
public @interface EnableCustomSwagger2
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.ruoyi.common.swagger.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import com.ruoyi.common.swagger.config.properties.SpringDocProperties;
|
||||
import io.swagger.v3.oas.models.Components;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
|
||||
/**
|
||||
* Swagger 文档配置
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@EnableConfigurationProperties(SpringDocProperties.class)
|
||||
@ConditionalOnProperty(name = "springdoc.api-docs.enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class SpringDocAutoConfiguration
|
||||
{
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(OpenAPI.class)
|
||||
public OpenAPI openApi(SpringDocProperties properties)
|
||||
{
|
||||
return new OpenAPI().components(new Components()
|
||||
// 设置认证的请求头
|
||||
.addSecuritySchemes("apikey", securityScheme()))
|
||||
.addSecurityItem(new SecurityRequirement().addList("apikey"))
|
||||
.info(convertInfo(properties.getInfo()))
|
||||
.servers(servers(properties.getGatewayUrl()));
|
||||
}
|
||||
|
||||
public SecurityScheme securityScheme()
|
||||
{
|
||||
return new SecurityScheme().type(SecurityScheme.Type.APIKEY)
|
||||
.name("Authorization")
|
||||
.in(SecurityScheme.In.HEADER)
|
||||
.scheme("Bearer");
|
||||
}
|
||||
|
||||
private Info convertInfo(SpringDocProperties.InfoProperties infoProperties)
|
||||
{
|
||||
Info info = new Info();
|
||||
info.setTitle(infoProperties.getTitle());
|
||||
info.setDescription(infoProperties.getDescription());
|
||||
info.setContact(infoProperties.getContact());
|
||||
info.setLicense(infoProperties.getLicense());
|
||||
info.setVersion(infoProperties.getVersion());
|
||||
return info;
|
||||
}
|
||||
|
||||
public List<Server> servers(String gatewayUrl)
|
||||
{
|
||||
List<Server> serverList = new ArrayList<>();
|
||||
serverList.add(new Server().url(gatewayUrl));
|
||||
return serverList;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,129 +0,0 @@
|
|||
package com.ruoyi.common.swagger.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.ApiKey;
|
||||
import springfox.documentation.service.AuthorizationScope;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.service.SecurityReference;
|
||||
import springfox.documentation.service.SecurityScheme;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
@EnableAutoConfiguration
|
||||
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
|
||||
public class SwaggerAutoConfiguration
|
||||
{
|
||||
/**
|
||||
* 默认的排除路径,排除Spring Boot默认的错误处理路径和端点
|
||||
*/
|
||||
private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error", "/actuator/**");
|
||||
|
||||
private static final String BASE_PATH = "/**";
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SwaggerProperties swaggerProperties()
|
||||
{
|
||||
return new SwaggerProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket api(SwaggerProperties swaggerProperties)
|
||||
{
|
||||
// base-path处理
|
||||
if (swaggerProperties.getBasePath().isEmpty())
|
||||
{
|
||||
swaggerProperties.getBasePath().add(BASE_PATH);
|
||||
}
|
||||
// noinspection unchecked
|
||||
List<Predicate<String>> basePath = new ArrayList<Predicate<String>>();
|
||||
swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path)));
|
||||
|
||||
// exclude-path处理
|
||||
if (swaggerProperties.getExcludePath().isEmpty())
|
||||
{
|
||||
swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH);
|
||||
}
|
||||
|
||||
List<Predicate<String>> excludePath = new ArrayList<>();
|
||||
swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path)));
|
||||
|
||||
ApiSelectorBuilder builder = new Docket(DocumentationType.SWAGGER_2).host(swaggerProperties.getHost())
|
||||
.apiInfo(apiInfo(swaggerProperties)).select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()));
|
||||
|
||||
swaggerProperties.getBasePath().forEach(p -> builder.paths(PathSelectors.ant(p)));
|
||||
swaggerProperties.getExcludePath().forEach(p -> builder.paths(PathSelectors.ant(p).negate()));
|
||||
|
||||
return builder.build().securitySchemes(securitySchemes()).securityContexts(securityContexts()).pathMapping("/");
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全模式,这里指定token通过Authorization头请求头传递
|
||||
*/
|
||||
private List<SecurityScheme> securitySchemes()
|
||||
{
|
||||
List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
|
||||
apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
|
||||
return apiKeyList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全上下文
|
||||
*/
|
||||
private List<SecurityContext> securityContexts()
|
||||
{
|
||||
List<SecurityContext> securityContexts = new ArrayList<>();
|
||||
securityContexts.add(
|
||||
SecurityContext.builder()
|
||||
.securityReferences(defaultAuth())
|
||||
.operationSelector(o -> o.requestMappingPattern().matches("/.*"))
|
||||
.build());
|
||||
return securityContexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认的全局鉴权策略
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private List<SecurityReference> defaultAuth()
|
||||
{
|
||||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
||||
authorizationScopes[0] = authorizationScope;
|
||||
List<SecurityReference> securityReferences = new ArrayList<>();
|
||||
securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
|
||||
return securityReferences;
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo(SwaggerProperties swaggerProperties)
|
||||
{
|
||||
return new ApiInfoBuilder()
|
||||
.title(swaggerProperties.getTitle())
|
||||
.description(swaggerProperties.getDescription())
|
||||
.license(swaggerProperties.getLicense())
|
||||
.licenseUrl(swaggerProperties.getLicenseUrl())
|
||||
.termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl())
|
||||
.contact(new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail()))
|
||||
.version(swaggerProperties.getVersion())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
package com.ruoyi.common.swagger.config;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
|
||||
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
|
||||
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* swagger 在 springboot 2.6.x 不兼容问题的处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class SwaggerBeanPostProcessor implements BeanPostProcessor
|
||||
{
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
|
||||
{
|
||||
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider)
|
||||
{
|
||||
customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings)
|
||||
{
|
||||
List<T> copy = mappings.stream().filter(mapping -> mapping.getPatternParser() == null)
|
||||
.collect(Collectors.toList());
|
||||
mappings.clear();
|
||||
mappings.addAll(copy);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
|
||||
field.setAccessible(true);
|
||||
return (List<RequestMappingInfoHandlerMapping>) field.get(bean);
|
||||
}
|
||||
catch (IllegalArgumentException | IllegalAccessException e)
|
||||
{
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,345 +0,0 @@
|
|||
package com.ruoyi.common.swagger.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties("swagger")
|
||||
public class SwaggerProperties
|
||||
{
|
||||
/**
|
||||
* 是否开启swagger
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* swagger会解析的包路径
|
||||
**/
|
||||
private String basePackage = "";
|
||||
|
||||
/**
|
||||
* swagger会解析的url规则
|
||||
**/
|
||||
private List<String> basePath = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 在basePath基础上需要排除的url规则
|
||||
**/
|
||||
private List<String> excludePath = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 标题
|
||||
**/
|
||||
private String title = "";
|
||||
|
||||
/**
|
||||
* 描述
|
||||
**/
|
||||
private String description = "";
|
||||
|
||||
/**
|
||||
* 版本
|
||||
**/
|
||||
private String version = "";
|
||||
|
||||
/**
|
||||
* 许可证
|
||||
**/
|
||||
private String license = "";
|
||||
|
||||
/**
|
||||
* 许可证URL
|
||||
**/
|
||||
private String licenseUrl = "";
|
||||
|
||||
/**
|
||||
* 服务条款URL
|
||||
**/
|
||||
private String termsOfServiceUrl = "";
|
||||
|
||||
/**
|
||||
* host信息
|
||||
**/
|
||||
private String host = "";
|
||||
|
||||
/**
|
||||
* 联系人信息
|
||||
*/
|
||||
private Contact contact = new Contact();
|
||||
|
||||
/**
|
||||
* 全局统一鉴权配置
|
||||
**/
|
||||
private Authorization authorization = new Authorization();
|
||||
|
||||
public Boolean getEnabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled)
|
||||
{
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getBasePackage()
|
||||
{
|
||||
return basePackage;
|
||||
}
|
||||
|
||||
public void setBasePackage(String basePackage)
|
||||
{
|
||||
this.basePackage = basePackage;
|
||||
}
|
||||
|
||||
public List<String> getBasePath()
|
||||
{
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public void setBasePath(List<String> basePath)
|
||||
{
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public List<String> getExcludePath()
|
||||
{
|
||||
return excludePath;
|
||||
}
|
||||
|
||||
public void setExcludePath(List<String> excludePath)
|
||||
{
|
||||
this.excludePath = excludePath;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version)
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getLicense()
|
||||
{
|
||||
return license;
|
||||
}
|
||||
|
||||
public void setLicense(String license)
|
||||
{
|
||||
this.license = license;
|
||||
}
|
||||
|
||||
public String getLicenseUrl()
|
||||
{
|
||||
return licenseUrl;
|
||||
}
|
||||
|
||||
public void setLicenseUrl(String licenseUrl)
|
||||
{
|
||||
this.licenseUrl = licenseUrl;
|
||||
}
|
||||
|
||||
public String getTermsOfServiceUrl()
|
||||
{
|
||||
return termsOfServiceUrl;
|
||||
}
|
||||
|
||||
public void setTermsOfServiceUrl(String termsOfServiceUrl)
|
||||
{
|
||||
this.termsOfServiceUrl = termsOfServiceUrl;
|
||||
}
|
||||
|
||||
public String getHost()
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host)
|
||||
{
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public Contact getContact()
|
||||
{
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setContact(Contact contact)
|
||||
{
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public Authorization getAuthorization()
|
||||
{
|
||||
return authorization;
|
||||
}
|
||||
|
||||
public void setAuthorization(Authorization authorization)
|
||||
{
|
||||
this.authorization = authorization;
|
||||
}
|
||||
|
||||
public static class Contact
|
||||
{
|
||||
/**
|
||||
* 联系人
|
||||
**/
|
||||
private String name = "";
|
||||
/**
|
||||
* 联系人url
|
||||
**/
|
||||
private String url = "";
|
||||
/**
|
||||
* 联系人email
|
||||
**/
|
||||
private String email = "";
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url)
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getEmail()
|
||||
{
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email)
|
||||
{
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Authorization
|
||||
{
|
||||
/**
|
||||
* 鉴权策略ID,需要和SecurityReferences ID保持一致
|
||||
*/
|
||||
private String name = "";
|
||||
|
||||
/**
|
||||
* 需要开启鉴权URL的正则
|
||||
*/
|
||||
private String authRegex = "^.*$";
|
||||
|
||||
/**
|
||||
* 鉴权作用域列表
|
||||
*/
|
||||
private List<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
||||
|
||||
private List<String> tokenUrlList = new ArrayList<>();
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAuthRegex()
|
||||
{
|
||||
return authRegex;
|
||||
}
|
||||
|
||||
public void setAuthRegex(String authRegex)
|
||||
{
|
||||
this.authRegex = authRegex;
|
||||
}
|
||||
|
||||
public List<AuthorizationScope> getAuthorizationScopeList()
|
||||
{
|
||||
return authorizationScopeList;
|
||||
}
|
||||
|
||||
public void setAuthorizationScopeList(List<AuthorizationScope> authorizationScopeList)
|
||||
{
|
||||
this.authorizationScopeList = authorizationScopeList;
|
||||
}
|
||||
|
||||
public List<String> getTokenUrlList()
|
||||
{
|
||||
return tokenUrlList;
|
||||
}
|
||||
|
||||
public void setTokenUrlList(List<String> tokenUrlList)
|
||||
{
|
||||
this.tokenUrlList = tokenUrlList;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AuthorizationScope
|
||||
{
|
||||
/**
|
||||
* 作用域名称
|
||||
*/
|
||||
private String scope = "";
|
||||
|
||||
/**
|
||||
* 作用域描述
|
||||
*/
|
||||
private String description = "";
|
||||
|
||||
public String getScope()
|
||||
{
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(String scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
package com.ruoyi.common.swagger.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* swagger 资源映射路径
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
public class SwaggerWebConfiguration implements WebMvcConfigurer
|
||||
{
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry)
|
||||
{
|
||||
/** swagger-ui 地址 */
|
||||
registry.addResourceHandler("/swagger-ui/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
package com.ruoyi.common.swagger.config.properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
|
||||
/**
|
||||
* Swagger 配置属性
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "springdoc")
|
||||
public class SpringDocProperties
|
||||
{
|
||||
/**
|
||||
* 网关
|
||||
*/
|
||||
private String gatewayUrl;
|
||||
|
||||
/**
|
||||
* 文档基本信息
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private InfoProperties info = new InfoProperties();
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 文档的基础属性信息
|
||||
* </p>
|
||||
*
|
||||
* @see io.swagger.v3.oas.models.info.Info
|
||||
*
|
||||
* 为了 springboot 自动生产配置提示信息,所以这里复制一个类出来
|
||||
*/
|
||||
public static class InfoProperties
|
||||
{
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title = null;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description = null;
|
||||
|
||||
/**
|
||||
* 联系人信息
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private Contact contact = null;
|
||||
|
||||
/**
|
||||
* 许可证
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private License license = null;
|
||||
|
||||
/**
|
||||
* 版本
|
||||
*/
|
||||
private String version = null;
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Contact getContact()
|
||||
{
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setContact(Contact contact)
|
||||
{
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public License getLicense()
|
||||
{
|
||||
return license;
|
||||
}
|
||||
|
||||
public void setLicense(License license)
|
||||
{
|
||||
this.license = license;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version)
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
public String getGatewayUrl()
|
||||
{
|
||||
return gatewayUrl;
|
||||
}
|
||||
|
||||
public void setGatewayUrl(String gatewayUrl)
|
||||
{
|
||||
this.gatewayUrl = gatewayUrl;
|
||||
}
|
||||
|
||||
public InfoProperties getInfo()
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
public void setInfo(InfoProperties info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1 @@
|
|||
com.ruoyi.common.swagger.config.SwaggerAutoConfiguration
|
||||
com.ruoyi.common.swagger.config.SwaggerWebConfiguration
|
||||
com.ruoyi.common.swagger.config.SwaggerBeanPostProcessor
|
||||
com.ruoyi.common.swagger.config.SpringDocAutoConfiguration
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
@ -66,7 +66,7 @@
|
|||
|
||||
<!--验证码 -->
|
||||
<dependency>
|
||||
<groupId>com.github.penggle</groupId>
|
||||
<groupId>pro.fessional</groupId>
|
||||
<artifactId>kaptcha</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
|
@ -76,16 +76,11 @@
|
|||
<artifactId>ruoyi-common-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger -->
|
||||
<!-- Springdoc -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-webflux-ui</artifactId>
|
||||
<version>${springdoc.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
package com.ruoyi.gateway.config;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springdoc.core.AbstractSwaggerUiConfigProperties;
|
||||
import org.springdoc.core.SwaggerUiConfigProperties;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import com.alibaba.nacos.client.naming.event.InstancesChangeEvent;
|
||||
import com.alibaba.nacos.common.notify.Event;
|
||||
import com.alibaba.nacos.common.notify.NotifyCenter;
|
||||
import com.alibaba.nacos.common.notify.listener.Subscriber;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* SpringDoc配置类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(value = "springdoc.api-docs.enabled", matchIfMissing = true)
|
||||
public class SpringDocConfig implements InitializingBean
|
||||
{
|
||||
@Autowired
|
||||
private SwaggerUiConfigProperties swaggerUiConfigProperties;
|
||||
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
|
||||
/**
|
||||
* 在初始化后调用的方法
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet()
|
||||
{
|
||||
NotifyCenter.registerSubscriber(new SwaggerDocRegister(swaggerUiConfigProperties, discoveryClient));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Swagger文档注册器
|
||||
*/
|
||||
class SwaggerDocRegister extends Subscriber<InstancesChangeEvent>
|
||||
{
|
||||
@Autowired
|
||||
private SwaggerUiConfigProperties swaggerUiConfigProperties;
|
||||
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
|
||||
private final static String[] EXCLUDE_ROUTES = new String[] { "ruoyi-gateway", "ruoyi-auth", "ruoyi-file", "ruoyi-monitor" };
|
||||
|
||||
public SwaggerDocRegister(SwaggerUiConfigProperties swaggerUiConfigProperties, DiscoveryClient discoveryClient)
|
||||
{
|
||||
this.swaggerUiConfigProperties = swaggerUiConfigProperties;
|
||||
this.discoveryClient = discoveryClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* 事件回调方法,处理InstancesChangeEvent事件
|
||||
* @param event 事件对象
|
||||
*/
|
||||
@Override
|
||||
public void onEvent(InstancesChangeEvent event)
|
||||
{
|
||||
Set<AbstractSwaggerUiConfigProperties.SwaggerUrl> swaggerUrlSet = discoveryClient.getServices()
|
||||
.stream()
|
||||
.flatMap(serviceId -> discoveryClient.getInstances(serviceId).stream())
|
||||
.filter(instance -> !StringUtils.equalsAnyIgnoreCase(instance.getServiceId(), EXCLUDE_ROUTES))
|
||||
.map(instance -> {
|
||||
AbstractSwaggerUiConfigProperties.SwaggerUrl swaggerUrl = new AbstractSwaggerUiConfigProperties.SwaggerUrl();
|
||||
swaggerUrl.setName(instance.getServiceId());
|
||||
swaggerUrl.setUrl(String.format("/%s/v3/api-docs", instance.getServiceId()));
|
||||
return swaggerUrl;
|
||||
})
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
swaggerUiConfigProperties.setUrls(swaggerUrlSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅类型方法,返回订阅的事件类型
|
||||
* @return 订阅的事件类型
|
||||
*/
|
||||
@Override
|
||||
public Class<? extends Event> subscribeType()
|
||||
{
|
||||
return InstancesChangeEvent.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
package com.ruoyi.gateway.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.gateway.config.GatewayProperties;
|
||||
import org.springframework.cloud.gateway.route.RouteLocator;
|
||||
import org.springframework.cloud.gateway.support.NameUtils;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||
import springfox.documentation.swagger.web.SwaggerResource;
|
||||
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
|
||||
|
||||
/**
|
||||
* 聚合系统接口
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class SwaggerProvider implements SwaggerResourcesProvider, WebFluxConfigurer
|
||||
{
|
||||
/**
|
||||
* Swagger2默认的url后缀
|
||||
*/
|
||||
public static final String SWAGGER2URL = "/v2/api-docs";
|
||||
|
||||
/**
|
||||
* 网关路由
|
||||
*/
|
||||
@Lazy
|
||||
@Autowired
|
||||
private RouteLocator routeLocator;
|
||||
|
||||
@Autowired
|
||||
private GatewayProperties gatewayProperties;
|
||||
|
||||
/**
|
||||
* 聚合其他服务接口
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SwaggerResource> get()
|
||||
{
|
||||
List<SwaggerResource> resourceList = new ArrayList<>();
|
||||
List<String> routes = new ArrayList<>();
|
||||
// 获取网关中配置的route
|
||||
routeLocator.getRoutes().subscribe(route -> routes.add(route.getId()));
|
||||
gatewayProperties.getRoutes().stream()
|
||||
.filter(routeDefinition -> routes
|
||||
.contains(routeDefinition.getId()))
|
||||
.forEach(routeDefinition -> routeDefinition.getPredicates().stream()
|
||||
.filter(predicateDefinition -> "Path".equalsIgnoreCase(predicateDefinition.getName()))
|
||||
.filter(predicateDefinition -> !"ruoyi-auth".equalsIgnoreCase(routeDefinition.getId()))
|
||||
.forEach(predicateDefinition -> resourceList
|
||||
.add(swaggerResource(routeDefinition.getId(), predicateDefinition.getArgs()
|
||||
.get(NameUtils.GENERATED_NAME_PREFIX + "0").replace("/**", SWAGGER2URL)))));
|
||||
return resourceList;
|
||||
}
|
||||
|
||||
private SwaggerResource swaggerResource(String name, String location)
|
||||
{
|
||||
SwaggerResource swaggerResource = new SwaggerResource();
|
||||
swaggerResource.setName(name);
|
||||
swaggerResource.setLocation(location);
|
||||
swaggerResource.setSwaggerVersion("2.0");
|
||||
return swaggerResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry)
|
||||
{
|
||||
/** swagger-ui 地址 */
|
||||
registry.addResourceHandler("/swagger-ui/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
|
||||
}
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ public class AuthFilter implements GlobalFilter, Ordered
|
|||
|
||||
private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg)
|
||||
{
|
||||
log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());
|
||||
log.error("[鉴权异常处理]请求路径:{},错误信息:{}", exchange.getRequest().getPath(), msg);
|
||||
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ public class AuthFilter implements GlobalFilter, Ordered
|
|||
*/
|
||||
private String getToken(ServerHttpRequest request)
|
||||
{
|
||||
String token = request.getHeaders().getFirst(TokenConstants.AUTHENTICATION);
|
||||
String token = request.getHeaders().getFirst(SecurityConstants.AUTHORIZATION_HEADER);
|
||||
// 如果前端设置了令牌前缀,则裁剪掉前缀
|
||||
if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,87 +0,0 @@
|
|||
package com.ruoyi.gateway.filter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.OrderedGatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
||||
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 获取body请求数据(解决流不能重复读取问题)
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class CacheRequestFilter extends AbstractGatewayFilterFactory<CacheRequestFilter.Config>
|
||||
{
|
||||
public CacheRequestFilter()
|
||||
{
|
||||
super(Config.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name()
|
||||
{
|
||||
return "CacheRequestFilter";
|
||||
}
|
||||
|
||||
@Override
|
||||
public GatewayFilter apply(Config config)
|
||||
{
|
||||
CacheRequestGatewayFilter cacheRequestGatewayFilter = new CacheRequestGatewayFilter();
|
||||
Integer order = config.getOrder();
|
||||
if (order == null)
|
||||
{
|
||||
return cacheRequestGatewayFilter;
|
||||
}
|
||||
return new OrderedGatewayFilter(cacheRequestGatewayFilter, order);
|
||||
}
|
||||
|
||||
public static class CacheRequestGatewayFilter implements GatewayFilter
|
||||
{
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain)
|
||||
{
|
||||
// GET DELETE 不过滤
|
||||
HttpMethod method = exchange.getRequest().getMethod();
|
||||
if (method == null || method == HttpMethod.GET || method == HttpMethod.DELETE)
|
||||
{
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
return ServerWebExchangeUtils.cacheRequestBodyAndRequest(exchange, (serverHttpRequest) -> {
|
||||
if (serverHttpRequest == exchange.getRequest())
|
||||
{
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
return chain.filter(exchange.mutate().request(serverHttpRequest).build());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> shortcutFieldOrder()
|
||||
{
|
||||
return Collections.singletonList("order");
|
||||
}
|
||||
|
||||
static class Config
|
||||
{
|
||||
private Integer order;
|
||||
|
||||
public Integer getOrder()
|
||||
{
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Integer order)
|
||||
{
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object>
|
|||
ServerHttpRequest request = exchange.getRequest();
|
||||
|
||||
// 非登录/注册请求或验证码关闭,不处理
|
||||
if (!StringUtils.containsAnyIgnoreCase(request.getURI().getPath(), VALIDATE_URL) || !captchaProperties.getEnabled())
|
||||
if (!StringUtils.equalsAnyIgnoreCase(request.getURI().getPath(), VALIDATE_URL) || !captchaProperties.getEnabled())
|
||||
{
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,11 @@ public class XssFilter implements GlobalFilter, Ordered
|
|||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain)
|
||||
{
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
// xss开关未开启 或 通过nacos关闭,不过滤
|
||||
if (!xss.getEnabled())
|
||||
{
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
// GET DELETE 不过滤
|
||||
HttpMethod method = request.getMethod();
|
||||
if (method == null || method == HttpMethod.GET || method == HttpMethod.DELETE)
|
||||
|
|
@ -82,7 +87,7 @@ public class XssFilter implements GlobalFilter, Ordered
|
|||
// 防xss攻击过滤
|
||||
bodyStr = EscapeUtil.clean(bodyStr);
|
||||
// 转成字节
|
||||
byte[] bytes = bodyStr.getBytes();
|
||||
byte[] bytes = bodyStr.getBytes(StandardCharsets.UTF_8);
|
||||
NettyDataBufferFactory nettyDataBufferFactory = new NettyDataBufferFactory(ByteBufAllocator.DEFAULT);
|
||||
DataBuffer buffer = nettyDataBufferFactory.allocateBuffer(bytes.length);
|
||||
buffer.write(bytes);
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue