mirror of
https://gitee.com/y_project/RuoYi-Vue.git
synced 2025-12-08 15:02:29 +08:00
Compare commits
431 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a811d9824 | |||
| 1c9c076280 | |||
| 918f94d8da | |||
| 5db610d16f | |||
| cc6f983ee3 | |||
| afe2852bbb | |||
| 9c7d302b94 | |||
| 9e66ada9c1 | |||
| a63eec3be4 | |||
| 51990695f5 | |||
| a7b8f2ee90 | |||
| 67ba621db6 | |||
| 05feef34c7 | |||
| be0b36f6b9 | |||
| 69bbccbd76 | |||
| 1eb7b3a03f | |||
| 4661edf7f0 | |||
| 8485605145 | |||
| a4fe88ca61 | |||
| af15a3b274 | |||
| 571393c32c | |||
| eff06c110f | |||
| 6a18e06339 | |||
| f04ca57f7a | |||
| b4f2a4f7dd | |||
| de0a43285f | |||
| 4952ac0a3d | |||
| 6ad345331d | |||
| 5a634a4ecd | |||
| f5b865a2e1 | |||
| f7595e4998 | |||
| 64e71302e4 | |||
| 2e99c68ed0 | |||
| af0e0a110e | |||
| bef86e041f | |||
| 1067567f1c | |||
| 0a670fdfd7 | |||
| a33090c90e | |||
| 5061558e94 | |||
| e7f088552f | |||
| 5c4682e060 | |||
| 5d5ebbec1a | |||
| 23544bab5e | |||
| c5ef0336a4 | |||
| a907f8485c | |||
| 66200c4203 | |||
| 5a25212509 | |||
| 95742bf5bd | |||
| 4eea8cdbb0 | |||
| cfce89be7d | |||
| ce7e12ec1d | |||
| 4f02f3c6f7 | |||
| 5ca9bd6876 | |||
| 020a2d4670 | |||
| 635d621b7b | |||
| 4cbd56cbd7 | |||
| dcb9cb3d13 | |||
| 628bc94a9a | |||
| 38ddefe2e6 | |||
| 7a090bda1e | |||
| 4e8dd706d5 | |||
| 641e550d7f | |||
| 81a01a1d9d | |||
| 6523fe59a2 | |||
| 90970eb9fe | |||
| 3402b69556 | |||
| 2c5e3e429f | |||
| 96ba768f50 | |||
| 1268637e58 | |||
| 61caa7966b | |||
| a5f95eddab | |||
| ade70583e9 | |||
| 5676cf9ad4 | |||
| c3d0cd5f8c | |||
| eb96afee64 | |||
| 5873da87ae | |||
| 4f1933e2e4 | |||
| 9926f73cd0 | |||
| 492919d4af | |||
| a7ff50e695 | |||
| 71e7e1d6dd | |||
| 5073f95ccd | |||
| c3a727b2fd | |||
| 19eaad0129 | |||
| 565cbb8c7a | |||
| b2cf949956 | |||
| 3fec133c69 | |||
| c9de6fcd82 | |||
| 22ee2c2e94 | |||
| f11db02ff8 | |||
| d5f5c5d066 | |||
| 4536906b21 | |||
| 9748e10339 | |||
| b08a6ce3f6 | |||
| 3039b745a9 | |||
| 39298d803c | |||
| 09bb3e15c6 | |||
| 3b8a68c4cf | |||
| 9aae863ce3 | |||
| 963247df43 | |||
| 7d874e31cf | |||
| 1bb6342bcb | |||
| 27acbe5b73 | |||
| 6474a17100 | |||
| 142f6ad6a0 | |||
| b4bdd4f306 | |||
| 74ba681fee | |||
| 8f2b3ac465 | |||
| 7eee3b9f02 | |||
| 27e34c2f0a | |||
| 836180fe0e | |||
| 06fbda5324 | |||
| bf313b17da | |||
| a8b9485a29 | |||
| 101e15d83f | |||
| ebb9f15a75 | |||
| cd137bd9fc | |||
| 07bde5f88a | |||
| 6fffa02acf | |||
| dc48f9858b | |||
| a6b2ac5dcd | |||
| c0685b7f7f | |||
| fb2d616c57 | |||
| 6ff6853082 | |||
| f8014ae969 | |||
| 1de2b7a57e | |||
| f01aa37394 | |||
| 4517dea98d | |||
| e21396870f | |||
| b67f6a0fec | |||
| 42d8104505 | |||
| f40a0eab23 | |||
| b6153d1aef | |||
| a2c585daa4 | |||
| 5a60bf0b0a | |||
| 9dcddc7876 | |||
| b970185536 | |||
| a64a029323 | |||
| 78f4d1c85b | |||
| bf83fe568b | |||
| 6505432bf4 | |||
| a32a931d24 | |||
| 4d72fb4289 | |||
| 186c04d90a | |||
| c542b7ac32 | |||
| 3607e008a3 | |||
| 5b8edbf381 | |||
| 03f7bc0f3f | |||
| e95a1245c5 | |||
| d7441edae7 | |||
| 5053361a7f | |||
| acbdd6365a | |||
| e781f88eca | |||
| 86d16d070d | |||
| 854b405d89 | |||
| c3faa1a925 | |||
| 37d6cc8146 | |||
| 2293822dc2 | |||
| f5bec70911 | |||
| 87c53a049b | |||
| 5bcd2825b6 | |||
| 036144b9ea | |||
| 42d602b7a8 | |||
| d4b800036c | |||
| 2f380f0c41 | |||
| 39efed1710 | |||
| 9a895763d5 | |||
| 7347cbaedf | |||
| a78b5b7b2a | |||
| 99d1760b98 | |||
| 4d71cfa90a | |||
| e02f692359 | |||
| 77ec8d1c9a | |||
| 66ce21ec29 | |||
| 27e0937235 | |||
| aadb7a41cb | |||
| 9b3767a954 | |||
| 851dc54b49 | |||
| cf2c4e02c6 | |||
| 88b5715eae | |||
| 5b05d4a123 | |||
| 893ef39401 | |||
| 890ad682d7 | |||
| b9f45057b8 | |||
| 89008c28df | |||
| af7d0a3409 | |||
| 1cd2eef899 | |||
| 8c7b93ec4f | |||
| 3f7bf545b5 | |||
| cbedec7ca6 | |||
| fb1bac2114 | |||
| d0f399a66a | |||
| e73dbd470a | |||
| e0cd5381e2 | |||
| aee5d417ed | |||
| 250c5ba226 | |||
| b91c848962 | |||
| d4475d0e8d | |||
| aff54ab5fe | |||
| 06177addf5 | |||
| 9f3b91fe57 | |||
| 80d25863db | |||
| cf8a7f8678 | |||
| 86fc709b03 | |||
| b8b58cb202 | |||
| 96970ff951 | |||
| 7cc9d17424 | |||
| bc8b5f1079 | |||
| 5ec5e1a65d | |||
| 1f0e742710 | |||
| 28b9fbb4d2 | |||
| 2c79dc906e | |||
| 1852017ecc | |||
| 424d11896a | |||
| edefee46b2 | |||
| c7c3da2038 | |||
| eb9f3d3772 | |||
| 1a61790407 | |||
| fe98fba5b5 | |||
| 4eb8809a8a | |||
| 0a893d196e | |||
| ec45cf04af | |||
| 6f48fc3c58 | |||
| 8558954da7 | |||
| 2ae41df23b | |||
| 47b8daf69c | |||
| ef31a0de42 | |||
| 8c956d681b | |||
| 89eb44afbc | |||
| 9d7e32fb07 | |||
| abb88d622a | |||
| 1ccdd75019 | |||
| aaedafff52 | |||
| 3ccf5c0e50 | |||
| db5fea922f | |||
| 0214d93299 | |||
| 1124a203cc | |||
| e8fbf5fdbd | |||
| 8fd4ae1282 | |||
| eab1b450d5 | |||
| 98fc30786e | |||
| a46c4bf04e | |||
| b97a662f2e | |||
| 9639c096ba | |||
| e4af41e89a | |||
| 52e1717014 | |||
| 8a2e3d13f2 | |||
| a29a0648ad | |||
| 63d471ec94 | |||
| 9fa3eac3aa | |||
| e320c50e49 | |||
| 524ad4e6dd | |||
| 77fffda10e | |||
| da0309eb09 | |||
| 6805a96e53 | |||
| a92667c000 | |||
| 4a0619cadb | |||
| a7e16d582d | |||
| b5b8d941f3 | |||
| 9c3b53b701 | |||
| 5693bbe1f5 | |||
| 0055f479cb | |||
| 1c41b701dd | |||
| 9476f7f616 | |||
| cbe405f6ea | |||
| 7414bc492e | |||
| 6f14087a16 | |||
| 328d4b916d | |||
| b42a8176ca | |||
| 2a9beec31d | |||
| 910fe6261b | |||
| 0c820b96d8 | |||
| c3c49a05c2 | |||
| 68a616d7c7 | |||
| a0447de061 | |||
| 46db06a22b | |||
| de5ae4a05e | |||
| c0d430f4e5 | |||
| d910888181 | |||
| db2dfee6ae | |||
| d311d56bbf | |||
| 3bc5ef38d3 | |||
| bac3b3a0dc | |||
| 07fded4da9 | |||
| a854e0ca8e | |||
| de1766abde | |||
| 01a566c794 | |||
| 5362a633e6 | |||
| b2c3f45141 | |||
| d5f9b5b74a | |||
| 2043d1f439 | |||
| 61034d4dde | |||
| 6605bf35a8 | |||
| b2b93e5060 | |||
| 098286fcaf | |||
| eaa12de740 | |||
| 857054179c | |||
| 0a3fcfd9f4 | |||
| 0271aa5414 | |||
| a0364f0758 | |||
| ed693e89c9 | |||
| 526957e0ac | |||
| 420a43cdd5 | |||
| 5e8ccda522 | |||
| 62fc38078c | |||
| bc4f844cd8 | |||
| f15f8e3295 | |||
| 6130bebbb3 | |||
| 9f944c043f | |||
| 092b3214c5 | |||
| 07dfef48be | |||
| e9571fc2e2 | |||
| 22f7ccc11d | |||
| 4bd5009ec1 | |||
| cb8f5de5af | |||
| ac030b7275 | |||
| 9370747479 | |||
| 45efd9290e | |||
| 96edba7eec | |||
| 927b05713a | |||
| 8f23ff7274 | |||
| 158e883e47 | |||
| e62e8e372c | |||
| bb65cd1976 | |||
| 1086c00929 | |||
| 9aaa9ce8aa | |||
| cb5a6d29e2 | |||
| 4d8bd8805b | |||
| c8c57b545a | |||
| d0f7a317e4 | |||
| aa9ed2e863 | |||
| 54c6c4e547 | |||
| 986b48cf36 | |||
| 3bb9b03add | |||
| f05aa674ab | |||
| 965bdc9986 | |||
| e793138031 | |||
| d734bfc34f | |||
| 84fe0737de | |||
| 81630a096f | |||
| 21780d8106 | |||
| b7b4364db2 | |||
| d9859de756 | |||
| 5e6fd0d1e1 | |||
| a91d7cdd72 | |||
| d00dc3b03a | |||
| f5c69bae30 | |||
| 89fe17f419 | |||
| c491257359 | |||
| dd5e514d92 | |||
| 2532e40f9c | |||
| 50236ae4e5 | |||
| c99eb98001 | |||
| a29201a248 | |||
| 6f0c59d7be | |||
| a6ed5667ab | |||
| 612c4293d1 | |||
| 8007b22b85 | |||
| 35664d818d | |||
| 1fe08f49c7 | |||
| 48b007543a | |||
| dccb3ac6c6 | |||
| 89cd2106ed | |||
| 74f991b8c5 | |||
| a966b95a5b | |||
| 15f05b602f | |||
| 9e51d3f250 | |||
| d7ca248bc8 | |||
| 3980b2f2ff | |||
| bed9fcea46 | |||
| b1b82857ba | |||
| 869dcf73f8 | |||
| 96a34d1ad7 | |||
| 766361ac83 | |||
| 9bd7509e87 | |||
| 9f7acd4cf9 | |||
| eb11337f7d | |||
| d2872539e3 | |||
| 1a5b024df6 | |||
| 578d65dfb4 | |||
| db4c2d3dd5 | |||
| 47842a1611 | |||
| f4f4cd9b1f | |||
| b7452cc281 | |||
| 8ba91fc9dd | |||
| c8d9b3f8fc | |||
| c9d19cbe56 | |||
| 10ae0bce65 | |||
| 7bc15245aa | |||
| cb6228800b | |||
| 6ef899d000 | |||
| 6353f4ff09 | |||
| bb1af390a7 | |||
| f65cd6245d | |||
| 530b2a51d5 | |||
| d51e7cbb51 | |||
| f244fe1855 | |||
| 1294f68265 | |||
| 0e771a6c1b | |||
| e4df0c6da1 | |||
| 7b23b6db6f | |||
| be412faf6c | |||
| fd3a699ad8 | |||
| c28aa299bd | |||
| a028b566ed | |||
| ca2405c104 | |||
| e5647793ce | |||
| 903b5aebca | |||
| 7492dcc9e6 | |||
| 8978012f9d | |||
| 7cf4a5da87 | |||
| 47b67331d4 | |||
| 6e14601c7c | |||
| fef7ead0d5 | |||
| 06aef0587a | |||
| bf7c259cdd | |||
| 43d76e5990 | |||
| d365a52cd6 | |||
| e1c7115d8c | |||
| bb4d75aff0 | |||
| 2743785aaf | |||
| 2a235917dc | |||
| 44ce6774dc | |||
| b911d7f78f | |||
| 4644176e26 | |||
| 850b98337b | |||
| 7f2921f26b | |||
| 836017f2b9 | |||
| 4de4763baf | |||
| 965ebd0f03 | |||
| 2c3f1c28e5 |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
custom: http://doc.ruoyi.vip/ruoyi-vue/other/donate.html
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -25,6 +25,9 @@ target/
|
|||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
|
|
||||||
|
### JRebel ###
|
||||||
|
rebel.xml
|
||||||
|
|
||||||
### NetBeans ###
|
### NetBeans ###
|
||||||
nbproject/private/
|
nbproject/private/
|
||||||
build/*
|
build/*
|
||||||
|
|||||||
14
README.md
14
README.md
@ -1,3 +1,14 @@
|
|||||||
|
<p align="center">
|
||||||
|
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
|
||||||
|
</p>
|
||||||
|
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi v3.8.6</h1>
|
||||||
|
<h4 align="center">基于SpringBoot+Vue前后端分离的Java快速开发框架</h4>
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://gitee.com/y_project/RuoYi-Vue/stargazers"><img src="https://gitee.com/y_project/RuoYi-Vue/badge/star.svg?theme=dark"></a>
|
||||||
|
<a href="https://gitee.com/y_project/RuoYi-Vue"><img src="https://img.shields.io/badge/RuoYi-v3.8.6-brightgreen.svg"></a>
|
||||||
|
<a href="https://gitee.com/y_project/RuoYi-Vue/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
## 平台简介
|
## 平台简介
|
||||||
|
|
||||||
若依是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。
|
若依是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。
|
||||||
@ -10,7 +21,6 @@
|
|||||||
* 提供了技术栈([Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev))版本[RuoYi-Vue3](https://github.com/yangzongzhuan/RuoYi-Vue3),保持同步更新。
|
* 提供了技术栈([Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev))版本[RuoYi-Vue3](https://github.com/yangzongzhuan/RuoYi-Vue3),保持同步更新。
|
||||||
* 提供了单应用版本[RuoYi-Vue-fast](https://github.com/yangzongzhuan/RuoYi-Vue-fast),Oracle版本[RuoYi-Vue-Oracle](https://github.com/yangzongzhuan/RuoYi-Vue-Oracle),保持同步更新。
|
* 提供了单应用版本[RuoYi-Vue-fast](https://github.com/yangzongzhuan/RuoYi-Vue-fast),Oracle版本[RuoYi-Vue-Oracle](https://github.com/yangzongzhuan/RuoYi-Vue-Oracle),保持同步更新。
|
||||||
* 不分离版本,请移步[RuoYi](https://gitee.com/y_project/RuoYi),微服务版本,请移步[RuoYi-Cloud](https://gitee.com/y_project/RuoYi-Cloud)
|
* 不分离版本,请移步[RuoYi](https://gitee.com/y_project/RuoYi),微服务版本,请移步[RuoYi-Cloud](https://gitee.com/y_project/RuoYi-Cloud)
|
||||||
* 特别鸣谢:[element](https://github.com/ElemeFE/element),[vue-element-admin](https://github.com/PanJiaChen/vue-element-admin),[eladmin-web](https://github.com/elunez/eladmin-web)。
|
|
||||||
* 阿里云折扣场:[点我进入](http://aly.ruoyi.vip),腾讯云秒杀场:[点我进入](http://txy.ruoyi.vip)
|
* 阿里云折扣场:[点我进入](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)
|
* 阿里云优惠券:[点我领取](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)
|
||||||
|
|
||||||
@ -83,4 +93,4 @@
|
|||||||
|
|
||||||
## 若依前后端分离交流群
|
## 若依前后端分离交流群
|
||||||
|
|
||||||
QQ群: [](https://jq.qq.com/?_wv=1027&k=5bVB1og) [](https://jq.qq.com/?_wv=1027&k=5eiA4DH) [](https://jq.qq.com/?_wv=1027&k=5AxMKlC) [](https://jq.qq.com/?_wv=1027&k=51G72yr) [](https://jq.qq.com/?_wv=1027&k=VvjN2nvu) [](https://jq.qq.com/?_wv=1027&k=5vYAqA05) [](https://jq.qq.com/?_wv=1027&k=kOIINEb5) [](https://jq.qq.com/?_wv=1027&k=UKtX5jhs) 点击按钮入群。
|
QQ群: [](https://jq.qq.com/?_wv=1027&k=5bVB1og) [](https://jq.qq.com/?_wv=1027&k=5eiA4DH) [](https://jq.qq.com/?_wv=1027&k=5AxMKlC) [](https://jq.qq.com/?_wv=1027&k=51G72yr) [](https://jq.qq.com/?_wv=1027&k=VvjN2nvu) [](https://jq.qq.com/?_wv=1027&k=5vYAqA05) [](https://jq.qq.com/?_wv=1027&k=kOIINEb5) [](https://jq.qq.com/?_wv=1027&k=UKtX5jhs) [](https://jq.qq.com/?_wv=1027&k=EI9an8lJ) [](https://jq.qq.com/?_wv=1027&k=SWCtLnMz) [](https://jq.qq.com/?_wv=1027&k=96Dkdq0k) [](https://jq.qq.com/?_wv=1027&k=0fsNiYZt) [](https://jq.qq.com/?_wv=1027&k=7xw4xUG1) [](https://jq.qq.com/?_wv=1027&k=eCx8eyoJ) [](https://jq.qq.com/?_wv=1027&k=SpyH2875) [](https://jq.qq.com/?_wv=1027&k=tKEt51dz) 点击按钮入群。
|
||||||
56
pom.xml
56
pom.xml
@ -6,29 +6,26 @@
|
|||||||
|
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi</artifactId>
|
<artifactId>ruoyi</artifactId>
|
||||||
<version>3.8.0</version>
|
<version>3.8.6</version>
|
||||||
|
|
||||||
<name>ruoyi</name>
|
<name>ruoyi</name>
|
||||||
<url>http://www.ruoyi.vip</url>
|
<url>http://www.ruoyi.vip</url>
|
||||||
<description>若依管理系统</description>
|
<description>若依管理系统</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<ruoyi.version>3.8.0</ruoyi.version>
|
<ruoyi.version>3.8.6</ruoyi.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||||
<druid.version>1.2.8</druid.version>
|
<druid.version>1.2.16</druid.version>
|
||||||
<bitwalker.version>1.21</bitwalker.version>
|
<bitwalker.version>1.21</bitwalker.version>
|
||||||
<swagger.version>3.0.0</swagger.version>
|
<swagger.version>3.0.0</swagger.version>
|
||||||
<kaptcha.version>2.3.2</kaptcha.version>
|
<kaptcha.version>2.3.3</kaptcha.version>
|
||||||
<mybatis-spring-boot.version>2.2.0</mybatis-spring-boot.version>
|
<pagehelper.boot.version>1.4.6</pagehelper.boot.version>
|
||||||
<pagehelper.boot.version>1.4.0</pagehelper.boot.version>
|
<fastjson.version>2.0.34</fastjson.version>
|
||||||
<fastjson.version>1.2.78</fastjson.version>
|
<oshi.version>6.4.3</oshi.version>
|
||||||
<oshi.version>5.8.2</oshi.version>
|
|
||||||
<jna.version>5.9.0</jna.version>
|
|
||||||
<commons.io.version>2.11.0</commons.io.version>
|
<commons.io.version>2.11.0</commons.io.version>
|
||||||
<commons.fileupload.version>1.4</commons.fileupload.version>
|
|
||||||
<commons.collections.version>3.2.2</commons.collections.version>
|
<commons.collections.version>3.2.2</commons.collections.version>
|
||||||
<poi.version>4.1.2</poi.version>
|
<poi.version>4.1.2</poi.version>
|
||||||
<velocity.version>2.3</velocity.version>
|
<velocity.version>2.3</velocity.version>
|
||||||
@ -43,7 +40,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
<version>2.5.6</version>
|
<version>2.5.15</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -62,13 +59,6 @@
|
|||||||
<version>${bitwalker.version}</version>
|
<version>${bitwalker.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringBoot集成mybatis框架 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mybatis.spring.boot</groupId>
|
|
||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
|
||||||
<version>${mybatis-spring-boot.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- pagehelper 分页插件 -->
|
<!-- pagehelper 分页插件 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.pagehelper</groupId>
|
<groupId>com.github.pagehelper</groupId>
|
||||||
@ -83,18 +73,6 @@
|
|||||||
<version>${oshi.version}</version>
|
<version>${oshi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.java.dev.jna</groupId>
|
|
||||||
<artifactId>jna</artifactId>
|
|
||||||
<version>${jna.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.java.dev.jna</groupId>
|
|
||||||
<artifactId>jna-platform</artifactId>
|
|
||||||
<version>${jna.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Swagger3依赖 -->
|
<!-- Swagger3依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>io.springfox</groupId>
|
||||||
@ -115,13 +93,6 @@
|
|||||||
<version>${commons.io.version}</version>
|
<version>${commons.io.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 文件上传工具类 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-fileupload</groupId>
|
|
||||||
<artifactId>commons-fileupload</artifactId>
|
|
||||||
<version>${commons.fileupload.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- excel工具 -->
|
<!-- excel工具 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
@ -145,8 +116,8 @@
|
|||||||
|
|
||||||
<!-- 阿里JSON解析器 -->
|
<!-- 阿里JSON解析器 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson2</artifactId>
|
||||||
<version>${fastjson.version}</version>
|
<version>${fastjson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -159,7 +130,7 @@
|
|||||||
|
|
||||||
<!-- 验证码 -->
|
<!-- 验证码 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.penggle</groupId>
|
<groupId>pro.fessional</groupId>
|
||||||
<artifactId>kaptcha</artifactId>
|
<artifactId>kaptcha</artifactId>
|
||||||
<version>${kaptcha.version}</version>
|
<version>${kaptcha.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -212,11 +183,6 @@
|
|||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>ruoyi</artifactId>
|
<artifactId>ruoyi</artifactId>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<version>3.8.0</version>
|
<version>3.8.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|||||||
@ -6,12 +6,13 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import com.ruoyi.common.config.RuoYiConfig;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.util.FastByteArrayOutputStream;
|
import org.springframework.util.FastByteArrayOutputStream;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.google.code.kaptcha.Producer;
|
import com.google.code.kaptcha.Producer;
|
||||||
|
import com.ruoyi.common.config.RuoYiConfig;
|
||||||
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.redis.RedisCache;
|
import com.ruoyi.common.core.redis.RedisCache;
|
||||||
@ -45,16 +46,16 @@ public class CaptchaController
|
|||||||
public AjaxResult getCode(HttpServletResponse response) throws IOException
|
public AjaxResult getCode(HttpServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
boolean captchaOnOff = configService.selectCaptchaOnOff();
|
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
||||||
ajax.put("captchaOnOff", captchaOnOff);
|
ajax.put("captchaEnabled", captchaEnabled);
|
||||||
if (!captchaOnOff)
|
if (!captchaEnabled)
|
||||||
{
|
{
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存验证码信息
|
// 保存验证码信息
|
||||||
String uuid = IdUtils.simpleUUID();
|
String uuid = IdUtils.simpleUUID();
|
||||||
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
|
||||||
|
|
||||||
String capStr = null, code = null;
|
String capStr = null, code = null;
|
||||||
BufferedImage image = null;
|
BufferedImage image = null;
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package com.ruoyi.web.controller.common;
|
package com.ruoyi.web.controller.common;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -8,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.ruoyi.common.config.RuoYiConfig;
|
import com.ruoyi.common.config.RuoYiConfig;
|
||||||
@ -24,6 +27,7 @@ import com.ruoyi.framework.config.ServerConfig;
|
|||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
|
@RequestMapping("/common")
|
||||||
public class CommonController
|
public class CommonController
|
||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
|
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
|
||||||
@ -31,13 +35,15 @@ public class CommonController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ServerConfig serverConfig;
|
private ServerConfig serverConfig;
|
||||||
|
|
||||||
|
private static final String FILE_DELIMETER = ",";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用下载请求
|
* 通用下载请求
|
||||||
*
|
*
|
||||||
* @param fileName 文件名称
|
* @param fileName 文件名称
|
||||||
* @param delete 是否删除
|
* @param delete 是否删除
|
||||||
*/
|
*/
|
||||||
@GetMapping("common/download")
|
@GetMapping("/download")
|
||||||
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
|
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -64,9 +70,9 @@ public class CommonController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用上传请求
|
* 通用上传请求(单个)
|
||||||
*/
|
*/
|
||||||
@PostMapping("/common/upload")
|
@PostMapping("/upload")
|
||||||
public AjaxResult uploadFile(MultipartFile file) throws Exception
|
public AjaxResult uploadFile(MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -77,8 +83,47 @@ public class CommonController
|
|||||||
String fileName = FileUploadUtils.upload(filePath, file);
|
String fileName = FileUploadUtils.upload(filePath, file);
|
||||||
String url = serverConfig.getUrl() + fileName;
|
String url = serverConfig.getUrl() + fileName;
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
ajax.put("fileName", fileName);
|
|
||||||
ajax.put("url", url);
|
ajax.put("url", url);
|
||||||
|
ajax.put("fileName", fileName);
|
||||||
|
ajax.put("newFileName", FileUtils.getName(fileName));
|
||||||
|
ajax.put("originalFilename", file.getOriginalFilename());
|
||||||
|
return ajax;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return AjaxResult.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用上传请求(多个)
|
||||||
|
*/
|
||||||
|
@PostMapping("/uploads")
|
||||||
|
public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 上传文件路径
|
||||||
|
String filePath = RuoYiConfig.getUploadPath();
|
||||||
|
List<String> urls = new ArrayList<String>();
|
||||||
|
List<String> fileNames = new ArrayList<String>();
|
||||||
|
List<String> newFileNames = new ArrayList<String>();
|
||||||
|
List<String> originalFilenames = new ArrayList<String>();
|
||||||
|
for (MultipartFile file : files)
|
||||||
|
{
|
||||||
|
// 上传并返回新文件名称
|
||||||
|
String fileName = FileUploadUtils.upload(filePath, file);
|
||||||
|
String url = serverConfig.getUrl() + fileName;
|
||||||
|
urls.add(url);
|
||||||
|
fileNames.add(fileName);
|
||||||
|
newFileNames.add(FileUtils.getName(fileName));
|
||||||
|
originalFilenames.add(file.getOriginalFilename());
|
||||||
|
}
|
||||||
|
AjaxResult ajax = AjaxResult.success();
|
||||||
|
ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
|
||||||
|
ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
|
||||||
|
ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
|
||||||
|
ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -90,7 +135,7 @@ public class CommonController
|
|||||||
/**
|
/**
|
||||||
* 本地资源通用下载
|
* 本地资源通用下载
|
||||||
*/
|
*/
|
||||||
@GetMapping("/common/download/resource")
|
@GetMapping("/download/resource")
|
||||||
public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
|
public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,19 +1,25 @@
|
|||||||
package com.ruoyi.web.controller.monitor;
|
package com.ruoyi.web.controller.monitor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisCallback;
|
import org.springframework.data.redis.core.RedisCallback;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.system.domain.SysCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存监控
|
* 缓存监控
|
||||||
@ -27,6 +33,17 @@ public class CacheController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<String, String> redisTemplate;
|
private RedisTemplate<String, String> redisTemplate;
|
||||||
|
|
||||||
|
private final static List<SysCache> caches = new ArrayList<SysCache>();
|
||||||
|
{
|
||||||
|
caches.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "用户信息"));
|
||||||
|
caches.add(new SysCache(CacheConstants.SYS_CONFIG_KEY, "配置信息"));
|
||||||
|
caches.add(new SysCache(CacheConstants.SYS_DICT_KEY, "数据字典"));
|
||||||
|
caches.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "验证码"));
|
||||||
|
caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交"));
|
||||||
|
caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理"));
|
||||||
|
caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数"));
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("@ss.hasPermi('monitor:cache:list')")
|
@PreAuthorize("@ss.hasPermi('monitor:cache:list')")
|
||||||
@GetMapping()
|
@GetMapping()
|
||||||
public AjaxResult getInfo() throws Exception
|
public AjaxResult getInfo() throws Exception
|
||||||
@ -50,4 +67,54 @@ public class CacheController
|
|||||||
result.put("commandStats", pieList);
|
result.put("commandStats", pieList);
|
||||||
return AjaxResult.success(result);
|
return AjaxResult.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("@ss.hasPermi('monitor:cache:list')")
|
||||||
|
@GetMapping("/getNames")
|
||||||
|
public AjaxResult cache()
|
||||||
|
{
|
||||||
|
return AjaxResult.success(caches);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("@ss.hasPermi('monitor:cache:list')")
|
||||||
|
@GetMapping("/getKeys/{cacheName}")
|
||||||
|
public AjaxResult getCacheKeys(@PathVariable String cacheName)
|
||||||
|
{
|
||||||
|
Set<String> cacheKeys = redisTemplate.keys(cacheName + "*");
|
||||||
|
return AjaxResult.success(cacheKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("@ss.hasPermi('monitor:cache:list')")
|
||||||
|
@GetMapping("/getValue/{cacheName}/{cacheKey}")
|
||||||
|
public AjaxResult getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey)
|
||||||
|
{
|
||||||
|
String cacheValue = redisTemplate.opsForValue().get(cacheKey);
|
||||||
|
SysCache sysCache = new SysCache(cacheName, cacheKey, cacheValue);
|
||||||
|
return AjaxResult.success(sysCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("@ss.hasPermi('monitor:cache:list')")
|
||||||
|
@DeleteMapping("/clearCacheName/{cacheName}")
|
||||||
|
public AjaxResult clearCacheName(@PathVariable String cacheName)
|
||||||
|
{
|
||||||
|
Collection<String> cacheKeys = redisTemplate.keys(cacheName + "*");
|
||||||
|
redisTemplate.delete(cacheKeys);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("@ss.hasPermi('monitor:cache:list')")
|
||||||
|
@DeleteMapping("/clearCacheKey/{cacheKey}")
|
||||||
|
public AjaxResult clearCacheKey(@PathVariable String cacheKey)
|
||||||
|
{
|
||||||
|
redisTemplate.delete(cacheKey);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("@ss.hasPermi('monitor:cache:list')")
|
||||||
|
@DeleteMapping("/clearCacheAll")
|
||||||
|
public AjaxResult clearCacheAll()
|
||||||
|
{
|
||||||
|
Collection<String> cacheKeys = redisTemplate.keys("*");
|
||||||
|
redisTemplate.delete(cacheKeys);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
|||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.framework.web.service.SysPasswordService;
|
||||||
import com.ruoyi.system.domain.SysLogininfor;
|
import com.ruoyi.system.domain.SysLogininfor;
|
||||||
import com.ruoyi.system.service.ISysLogininforService;
|
import com.ruoyi.system.service.ISysLogininforService;
|
||||||
|
|
||||||
@ -31,6 +32,9 @@ public class SysLogininforController extends BaseController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ISysLogininforService logininforService;
|
private ISysLogininforService logininforService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysPasswordService passwordService;
|
||||||
|
|
||||||
@PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
|
@PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo list(SysLogininfor logininfor)
|
public TableDataInfo list(SysLogininfor logininfor)
|
||||||
@ -64,6 +68,15 @@ public class SysLogininforController extends BaseController
|
|||||||
public AjaxResult clean()
|
public AjaxResult clean()
|
||||||
{
|
{
|
||||||
logininforService.cleanLogininfor();
|
logininforService.cleanLogininfor();
|
||||||
return AjaxResult.success();
|
return success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("@ss.hasPermi('monitor:logininfor:unlock')")
|
||||||
|
@Log(title = "账户解锁", businessType = BusinessType.OTHER)
|
||||||
|
@GetMapping("/unlock/{userName}")
|
||||||
|
public AjaxResult unlock(@PathVariable("userName") String userName)
|
||||||
|
{
|
||||||
|
passwordService.clearLoginRecordCache(userName);
|
||||||
|
return success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,6 +64,6 @@ public class SysOperlogController extends BaseController
|
|||||||
public AjaxResult clean()
|
public AjaxResult clean()
|
||||||
{
|
{
|
||||||
operLogService.cleanOperLog();
|
operLogService.cleanOperLog();
|
||||||
return AjaxResult.success();
|
return success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
@ -42,31 +42,22 @@ public class SysUserOnlineController extends BaseController
|
|||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo list(String ipaddr, String userName)
|
public TableDataInfo list(String ipaddr, String userName)
|
||||||
{
|
{
|
||||||
Collection<String> keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*");
|
Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
|
||||||
List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
|
List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
|
||||||
for (String key : keys)
|
for (String key : keys)
|
||||||
{
|
{
|
||||||
LoginUser user = redisCache.getCacheObject(key);
|
LoginUser user = redisCache.getCacheObject(key);
|
||||||
if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName))
|
if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName))
|
||||||
{
|
{
|
||||||
if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername()))
|
userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
|
||||||
{
|
|
||||||
userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(ipaddr))
|
else if (StringUtils.isNotEmpty(ipaddr))
|
||||||
{
|
{
|
||||||
if (StringUtils.equals(ipaddr, user.getIpaddr()))
|
userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
|
||||||
{
|
|
||||||
userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser()))
|
else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser()))
|
||||||
{
|
{
|
||||||
if (StringUtils.equals(userName, user.getUsername()))
|
userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
|
||||||
{
|
|
||||||
userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -86,7 +77,7 @@ public class SysUserOnlineController extends BaseController
|
|||||||
@DeleteMapping("/{tokenId}")
|
@DeleteMapping("/{tokenId}")
|
||||||
public AjaxResult forceLogout(@PathVariable String tokenId)
|
public AjaxResult forceLogout(@PathVariable String tokenId)
|
||||||
{
|
{
|
||||||
redisCache.deleteObject(Constants.LOGIN_TOKEN_KEY + tokenId);
|
redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
|
||||||
return AjaxResult.success();
|
return success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
@ -64,7 +63,7 @@ public class SysConfigController extends BaseController
|
|||||||
@GetMapping(value = "/{configId}")
|
@GetMapping(value = "/{configId}")
|
||||||
public AjaxResult getInfo(@PathVariable Long configId)
|
public AjaxResult getInfo(@PathVariable Long configId)
|
||||||
{
|
{
|
||||||
return AjaxResult.success(configService.selectConfigById(configId));
|
return success(configService.selectConfigById(configId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +72,7 @@ public class SysConfigController extends BaseController
|
|||||||
@GetMapping(value = "/configKey/{configKey}")
|
@GetMapping(value = "/configKey/{configKey}")
|
||||||
public AjaxResult getConfigKey(@PathVariable String configKey)
|
public AjaxResult getConfigKey(@PathVariable String configKey)
|
||||||
{
|
{
|
||||||
return AjaxResult.success(configService.selectConfigByKey(configKey));
|
return success(configService.selectConfigByKey(configKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,9 +83,9 @@ public class SysConfigController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Validated @RequestBody SysConfig config)
|
public AjaxResult add(@Validated @RequestBody SysConfig config)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
|
if (!configService.checkConfigKeyUnique(config))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
||||||
}
|
}
|
||||||
config.setCreateBy(getUsername());
|
config.setCreateBy(getUsername());
|
||||||
return toAjax(configService.insertConfig(config));
|
return toAjax(configService.insertConfig(config));
|
||||||
@ -100,9 +99,9 @@ public class SysConfigController extends BaseController
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@Validated @RequestBody SysConfig config)
|
public AjaxResult edit(@Validated @RequestBody SysConfig config)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
|
if (!configService.checkConfigKeyUnique(config))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
||||||
}
|
}
|
||||||
config.setUpdateBy(getUsername());
|
config.setUpdateBy(getUsername());
|
||||||
return toAjax(configService.updateConfig(config));
|
return toAjax(configService.updateConfig(config));
|
||||||
@ -129,6 +128,6 @@ public class SysConfigController extends BaseController
|
|||||||
public AjaxResult refreshCache()
|
public AjaxResult refreshCache()
|
||||||
{
|
{
|
||||||
configService.resetConfigCache();
|
configService.resetConfigCache();
|
||||||
return AjaxResult.success();
|
return success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package com.ruoyi.web.controller.system;
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -43,7 +42,7 @@ public class SysDeptController extends BaseController
|
|||||||
public AjaxResult list(SysDept dept)
|
public AjaxResult list(SysDept dept)
|
||||||
{
|
{
|
||||||
List<SysDept> depts = deptService.selectDeptList(dept);
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
||||||
return AjaxResult.success(depts);
|
return success(depts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,17 +53,8 @@ public class SysDeptController extends BaseController
|
|||||||
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
|
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
|
||||||
{
|
{
|
||||||
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
||||||
Iterator<SysDept> it = depts.iterator();
|
depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
|
||||||
while (it.hasNext())
|
return success(depts);
|
||||||
{
|
|
||||||
SysDept d = (SysDept) it.next();
|
|
||||||
if (d.getDeptId().intValue() == deptId
|
|
||||||
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))
|
|
||||||
{
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return AjaxResult.success(depts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,30 +65,7 @@ public class SysDeptController extends BaseController
|
|||||||
public AjaxResult getInfo(@PathVariable Long deptId)
|
public AjaxResult getInfo(@PathVariable Long deptId)
|
||||||
{
|
{
|
||||||
deptService.checkDeptDataScope(deptId);
|
deptService.checkDeptDataScope(deptId);
|
||||||
return AjaxResult.success(deptService.selectDeptById(deptId));
|
return success(deptService.selectDeptById(deptId));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取部门下拉树列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/treeselect")
|
|
||||||
public AjaxResult treeselect(SysDept dept)
|
|
||||||
{
|
|
||||||
List<SysDept> depts = deptService.selectDeptList(dept);
|
|
||||||
return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载对应角色部门列表树
|
|
||||||
*/
|
|
||||||
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
|
|
||||||
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)
|
|
||||||
{
|
|
||||||
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
|
||||||
AjaxResult ajax = AjaxResult.success();
|
|
||||||
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
|
|
||||||
ajax.put("depts", deptService.buildDeptTreeSelect(depts));
|
|
||||||
return ajax;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,9 +76,9 @@ public class SysDeptController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Validated @RequestBody SysDept dept)
|
public AjaxResult add(@Validated @RequestBody SysDept dept)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
|
if (!deptService.checkDeptNameUnique(dept))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
||||||
}
|
}
|
||||||
dept.setCreateBy(getUsername());
|
dept.setCreateBy(getUsername());
|
||||||
return toAjax(deptService.insertDept(dept));
|
return toAjax(deptService.insertDept(dept));
|
||||||
@ -125,18 +92,19 @@ public class SysDeptController extends BaseController
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@Validated @RequestBody SysDept dept)
|
public AjaxResult edit(@Validated @RequestBody SysDept dept)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
|
Long deptId = dept.getDeptId();
|
||||||
|
deptService.checkDeptDataScope(deptId);
|
||||||
|
if (!deptService.checkDeptNameUnique(dept))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
||||||
}
|
}
|
||||||
else if (dept.getParentId().equals(dept.getDeptId()))
|
else if (dept.getParentId().equals(deptId))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
||||||
}
|
}
|
||||||
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
|
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0)
|
||||||
&& deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
|
|
||||||
{
|
{
|
||||||
return AjaxResult.error("该部门包含未停用的子部门!");
|
return error("该部门包含未停用的子部门!");
|
||||||
}
|
}
|
||||||
dept.setUpdateBy(getUsername());
|
dept.setUpdateBy(getUsername());
|
||||||
return toAjax(deptService.updateDept(dept));
|
return toAjax(deptService.updateDept(dept));
|
||||||
@ -152,12 +120,13 @@ public class SysDeptController extends BaseController
|
|||||||
{
|
{
|
||||||
if (deptService.hasChildByDeptId(deptId))
|
if (deptService.hasChildByDeptId(deptId))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("存在下级部门,不允许删除");
|
return warn("存在下级部门,不允许删除");
|
||||||
}
|
}
|
||||||
if (deptService.checkDeptExistUser(deptId))
|
if (deptService.checkDeptExistUser(deptId))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("部门存在用户,不允许删除");
|
return warn("部门存在用户,不允许删除");
|
||||||
}
|
}
|
||||||
|
deptService.checkDeptDataScope(deptId);
|
||||||
return toAjax(deptService.deleteDeptById(deptId));
|
return toAjax(deptService.deleteDeptById(deptId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,7 +66,7 @@ public class SysDictDataController extends BaseController
|
|||||||
@GetMapping(value = "/{dictCode}")
|
@GetMapping(value = "/{dictCode}")
|
||||||
public AjaxResult getInfo(@PathVariable Long dictCode)
|
public AjaxResult getInfo(@PathVariable Long dictCode)
|
||||||
{
|
{
|
||||||
return AjaxResult.success(dictDataService.selectDictDataById(dictCode));
|
return success(dictDataService.selectDictDataById(dictCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,7 +80,7 @@ public class SysDictDataController extends BaseController
|
|||||||
{
|
{
|
||||||
data = new ArrayList<SysDictData>();
|
data = new ArrayList<SysDictData>();
|
||||||
}
|
}
|
||||||
return AjaxResult.success(data);
|
return success(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.domain.entity.SysDictType;
|
import com.ruoyi.common.core.domain.entity.SysDictType;
|
||||||
@ -61,7 +60,7 @@ public class SysDictTypeController extends BaseController
|
|||||||
@GetMapping(value = "/{dictId}")
|
@GetMapping(value = "/{dictId}")
|
||||||
public AjaxResult getInfo(@PathVariable Long dictId)
|
public AjaxResult getInfo(@PathVariable Long dictId)
|
||||||
{
|
{
|
||||||
return AjaxResult.success(dictTypeService.selectDictTypeById(dictId));
|
return success(dictTypeService.selectDictTypeById(dictId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,9 +71,9 @@ public class SysDictTypeController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Validated @RequestBody SysDictType dict)
|
public AjaxResult add(@Validated @RequestBody SysDictType dict)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
|
if (!dictTypeService.checkDictTypeUnique(dict))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增字典'" + dict.getDictName() + "'失败,字典类型已存在");
|
return error("新增字典'" + dict.getDictName() + "'失败,字典类型已存在");
|
||||||
}
|
}
|
||||||
dict.setCreateBy(getUsername());
|
dict.setCreateBy(getUsername());
|
||||||
return toAjax(dictTypeService.insertDictType(dict));
|
return toAjax(dictTypeService.insertDictType(dict));
|
||||||
@ -88,9 +87,9 @@ public class SysDictTypeController extends BaseController
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@Validated @RequestBody SysDictType dict)
|
public AjaxResult edit(@Validated @RequestBody SysDictType dict)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
|
if (!dictTypeService.checkDictTypeUnique(dict))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
|
return error("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
|
||||||
}
|
}
|
||||||
dict.setUpdateBy(getUsername());
|
dict.setUpdateBy(getUsername());
|
||||||
return toAjax(dictTypeService.updateDictType(dict));
|
return toAjax(dictTypeService.updateDictType(dict));
|
||||||
@ -117,7 +116,7 @@ public class SysDictTypeController extends BaseController
|
|||||||
public AjaxResult refreshCache()
|
public AjaxResult refreshCache()
|
||||||
{
|
{
|
||||||
dictTypeService.resetDictCache();
|
dictTypeService.resetDictCache();
|
||||||
return AjaxResult.success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,6 +126,6 @@ public class SysDictTypeController extends BaseController
|
|||||||
public AjaxResult optionselect()
|
public AjaxResult optionselect()
|
||||||
{
|
{
|
||||||
List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll();
|
List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll();
|
||||||
return AjaxResult.success(dictTypes);
|
return success(dictTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ public class SysMenuController extends BaseController
|
|||||||
public AjaxResult list(SysMenu menu)
|
public AjaxResult list(SysMenu menu)
|
||||||
{
|
{
|
||||||
List<SysMenu> menus = menuService.selectMenuList(menu, getUserId());
|
List<SysMenu> menus = menuService.selectMenuList(menu, getUserId());
|
||||||
return AjaxResult.success(menus);
|
return success(menus);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +51,7 @@ public class SysMenuController extends BaseController
|
|||||||
@GetMapping(value = "/{menuId}")
|
@GetMapping(value = "/{menuId}")
|
||||||
public AjaxResult getInfo(@PathVariable Long menuId)
|
public AjaxResult getInfo(@PathVariable Long menuId)
|
||||||
{
|
{
|
||||||
return AjaxResult.success(menuService.selectMenuById(menuId));
|
return success(menuService.selectMenuById(menuId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,7 +61,7 @@ public class SysMenuController extends BaseController
|
|||||||
public AjaxResult treeselect(SysMenu menu)
|
public AjaxResult treeselect(SysMenu menu)
|
||||||
{
|
{
|
||||||
List<SysMenu> menus = menuService.selectMenuList(menu, getUserId());
|
List<SysMenu> menus = menuService.selectMenuList(menu, getUserId());
|
||||||
return AjaxResult.success(menuService.buildMenuTreeSelect(menus));
|
return success(menuService.buildMenuTreeSelect(menus));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,13 +85,13 @@ public class SysMenuController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Validated @RequestBody SysMenu menu)
|
public AjaxResult add(@Validated @RequestBody SysMenu menu)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
|
if (!menuService.checkMenuNameUnique(menu))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
return error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
||||||
}
|
}
|
||||||
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath()))
|
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath()))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
return error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
||||||
}
|
}
|
||||||
menu.setCreateBy(getUsername());
|
menu.setCreateBy(getUsername());
|
||||||
return toAjax(menuService.insertMenu(menu));
|
return toAjax(menuService.insertMenu(menu));
|
||||||
@ -105,17 +105,17 @@ public class SysMenuController extends BaseController
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@Validated @RequestBody SysMenu menu)
|
public AjaxResult edit(@Validated @RequestBody SysMenu menu)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
|
if (!menuService.checkMenuNameUnique(menu))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
return error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
||||||
}
|
}
|
||||||
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath()))
|
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath()))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
return error("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
||||||
}
|
}
|
||||||
else if (menu.getMenuId().equals(menu.getParentId()))
|
else if (menu.getMenuId().equals(menu.getParentId()))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
|
return error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
|
||||||
}
|
}
|
||||||
menu.setUpdateBy(getUsername());
|
menu.setUpdateBy(getUsername());
|
||||||
return toAjax(menuService.updateMenu(menu));
|
return toAjax(menuService.updateMenu(menu));
|
||||||
@ -131,11 +131,11 @@ public class SysMenuController extends BaseController
|
|||||||
{
|
{
|
||||||
if (menuService.hasChildByMenuId(menuId))
|
if (menuService.hasChildByMenuId(menuId))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("存在子菜单,不允许删除");
|
return warn("存在子菜单,不允许删除");
|
||||||
}
|
}
|
||||||
if (menuService.checkMenuExistRole(menuId))
|
if (menuService.checkMenuExistRole(menuId))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("菜单已分配,不允许删除");
|
return warn("菜单已分配,不允许删除");
|
||||||
}
|
}
|
||||||
return toAjax(menuService.deleteMenuById(menuId));
|
return toAjax(menuService.deleteMenuById(menuId));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,7 +51,7 @@ public class SysNoticeController extends BaseController
|
|||||||
@GetMapping(value = "/{noticeId}")
|
@GetMapping(value = "/{noticeId}")
|
||||||
public AjaxResult getInfo(@PathVariable Long noticeId)
|
public AjaxResult getInfo(@PathVariable Long noticeId)
|
||||||
{
|
{
|
||||||
return AjaxResult.success(noticeService.selectNoticeById(noticeId));
|
return success(noticeService.selectNoticeById(noticeId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
@ -64,7 +63,7 @@ public class SysPostController extends BaseController
|
|||||||
@GetMapping(value = "/{postId}")
|
@GetMapping(value = "/{postId}")
|
||||||
public AjaxResult getInfo(@PathVariable Long postId)
|
public AjaxResult getInfo(@PathVariable Long postId)
|
||||||
{
|
{
|
||||||
return AjaxResult.success(postService.selectPostById(postId));
|
return success(postService.selectPostById(postId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,13 +74,13 @@ public class SysPostController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Validated @RequestBody SysPost post)
|
public AjaxResult add(@Validated @RequestBody SysPost post)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
|
if (!postService.checkPostNameUnique(post))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
|
return error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
|
||||||
}
|
}
|
||||||
else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
|
else if (!postService.checkPostCodeUnique(post))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
|
return error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
|
||||||
}
|
}
|
||||||
post.setCreateBy(getUsername());
|
post.setCreateBy(getUsername());
|
||||||
return toAjax(postService.insertPost(post));
|
return toAjax(postService.insertPost(post));
|
||||||
@ -95,13 +94,13 @@ public class SysPostController extends BaseController
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@Validated @RequestBody SysPost post)
|
public AjaxResult edit(@Validated @RequestBody SysPost post)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
|
if (!postService.checkPostNameUnique(post))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
|
return error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
|
||||||
}
|
}
|
||||||
else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
|
else if (!postService.checkPostCodeUnique(post))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
|
return error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
|
||||||
}
|
}
|
||||||
post.setUpdateBy(getUsername());
|
post.setUpdateBy(getUsername());
|
||||||
return toAjax(postService.updatePost(post));
|
return toAjax(postService.updatePost(post));
|
||||||
@ -125,6 +124,6 @@ public class SysPostController extends BaseController
|
|||||||
public AjaxResult optionselect()
|
public AjaxResult optionselect()
|
||||||
{
|
{
|
||||||
List<SysPost> posts = postService.selectPostAll();
|
List<SysPost> posts = postService.selectPostAll();
|
||||||
return AjaxResult.success(posts);
|
return success(posts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package com.ruoyi.web.controller.system;
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@ -12,7 +11,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.config.RuoYiConfig;
|
import com.ruoyi.common.config.RuoYiConfig;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
@ -21,6 +19,7 @@ import com.ruoyi.common.enums.BusinessType;
|
|||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.file.FileUploadUtils;
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
||||||
|
import com.ruoyi.common.utils.file.MimeTypeUtils;
|
||||||
import com.ruoyi.framework.web.service.TokenService;
|
import com.ruoyi.framework.web.service.TokenService;
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
|
|
||||||
@ -63,18 +62,18 @@ public class SysProfileController extends BaseController
|
|||||||
LoginUser loginUser = getLoginUser();
|
LoginUser loginUser = getLoginUser();
|
||||||
SysUser sysUser = loginUser.getUser();
|
SysUser sysUser = loginUser.getUser();
|
||||||
user.setUserName(sysUser.getUserName());
|
user.setUserName(sysUser.getUserName());
|
||||||
if (StringUtils.isNotEmpty(user.getPhonenumber())
|
if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
||||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(user.getEmail())
|
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
||||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||||
}
|
}
|
||||||
user.setUserId(sysUser.getUserId());
|
user.setUserId(sysUser.getUserId());
|
||||||
user.setPassword(null);
|
user.setPassword(null);
|
||||||
|
user.setAvatar(null);
|
||||||
|
user.setDeptId(null);
|
||||||
if (userService.updateUserProfile(user) > 0)
|
if (userService.updateUserProfile(user) > 0)
|
||||||
{
|
{
|
||||||
// 更新缓存用户信息
|
// 更新缓存用户信息
|
||||||
@ -83,9 +82,9 @@ public class SysProfileController extends BaseController
|
|||||||
sysUser.setEmail(user.getEmail());
|
sysUser.setEmail(user.getEmail());
|
||||||
sysUser.setSex(user.getSex());
|
sysUser.setSex(user.getSex());
|
||||||
tokenService.setLoginUser(loginUser);
|
tokenService.setLoginUser(loginUser);
|
||||||
return AjaxResult.success();
|
return success();
|
||||||
}
|
}
|
||||||
return AjaxResult.error("修改个人信息异常,请联系管理员");
|
return error("修改个人信息异常,请联系管理员");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,20 +99,20 @@ public class SysProfileController extends BaseController
|
|||||||
String password = loginUser.getPassword();
|
String password = loginUser.getPassword();
|
||||||
if (!SecurityUtils.matchesPassword(oldPassword, password))
|
if (!SecurityUtils.matchesPassword(oldPassword, password))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改密码失败,旧密码错误");
|
return error("修改密码失败,旧密码错误");
|
||||||
}
|
}
|
||||||
if (SecurityUtils.matchesPassword(newPassword, password))
|
if (SecurityUtils.matchesPassword(newPassword, password))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新密码不能与旧密码相同");
|
return error("新密码不能与旧密码相同");
|
||||||
}
|
}
|
||||||
if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0)
|
if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0)
|
||||||
{
|
{
|
||||||
// 更新缓存用户密码
|
// 更新缓存用户密码
|
||||||
loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
|
loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
|
||||||
tokenService.setLoginUser(loginUser);
|
tokenService.setLoginUser(loginUser);
|
||||||
return AjaxResult.success();
|
return success();
|
||||||
}
|
}
|
||||||
return AjaxResult.error("修改密码异常,请联系管理员");
|
return error("修改密码异常,请联系管理员");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,12 +120,12 @@ public class SysProfileController extends BaseController
|
|||||||
*/
|
*/
|
||||||
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
||||||
@PostMapping("/avatar")
|
@PostMapping("/avatar")
|
||||||
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException
|
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
if (!file.isEmpty())
|
if (!file.isEmpty())
|
||||||
{
|
{
|
||||||
LoginUser loginUser = getLoginUser();
|
LoginUser loginUser = getLoginUser();
|
||||||
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
|
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
|
||||||
if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
|
if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
|
||||||
{
|
{
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
@ -137,6 +136,6 @@ public class SysProfileController extends BaseController
|
|||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return AjaxResult.error("上传图片异常,请联系管理员");
|
return error("上传图片异常,请联系管理员");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,9 +14,9 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
@ -27,6 +27,7 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
|
|||||||
import com.ruoyi.framework.web.service.SysPermissionService;
|
import com.ruoyi.framework.web.service.SysPermissionService;
|
||||||
import com.ruoyi.framework.web.service.TokenService;
|
import com.ruoyi.framework.web.service.TokenService;
|
||||||
import com.ruoyi.system.domain.SysUserRole;
|
import com.ruoyi.system.domain.SysUserRole;
|
||||||
|
import com.ruoyi.system.service.ISysDeptService;
|
||||||
import com.ruoyi.system.service.ISysRoleService;
|
import com.ruoyi.system.service.ISysRoleService;
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
|
|
||||||
@ -44,13 +45,16 @@ public class SysRoleController extends BaseController
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenService tokenService;
|
private TokenService tokenService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysPermissionService permissionService;
|
private SysPermissionService permissionService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysUserService userService;
|
private ISysUserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysDeptService deptService;
|
||||||
|
|
||||||
@PreAuthorize("@ss.hasPermi('system:role:list')")
|
@PreAuthorize("@ss.hasPermi('system:role:list')")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo list(SysRole role)
|
public TableDataInfo list(SysRole role)
|
||||||
@ -78,7 +82,7 @@ public class SysRoleController extends BaseController
|
|||||||
public AjaxResult getInfo(@PathVariable Long roleId)
|
public AjaxResult getInfo(@PathVariable Long roleId)
|
||||||
{
|
{
|
||||||
roleService.checkRoleDataScope(roleId);
|
roleService.checkRoleDataScope(roleId);
|
||||||
return AjaxResult.success(roleService.selectRoleById(roleId));
|
return success(roleService.selectRoleById(roleId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,13 +93,13 @@ public class SysRoleController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Validated @RequestBody SysRole role)
|
public AjaxResult add(@Validated @RequestBody SysRole role)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
|
if (!roleService.checkRoleNameUnique(role))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||||
}
|
}
|
||||||
else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
|
else if (!roleService.checkRoleKeyUnique(role))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||||
}
|
}
|
||||||
role.setCreateBy(getUsername());
|
role.setCreateBy(getUsername());
|
||||||
return toAjax(roleService.insertRole(role));
|
return toAjax(roleService.insertRole(role));
|
||||||
@ -111,13 +115,14 @@ public class SysRoleController extends BaseController
|
|||||||
public AjaxResult edit(@Validated @RequestBody SysRole role)
|
public AjaxResult edit(@Validated @RequestBody SysRole role)
|
||||||
{
|
{
|
||||||
roleService.checkRoleAllowed(role);
|
roleService.checkRoleAllowed(role);
|
||||||
if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
|
roleService.checkRoleDataScope(role.getRoleId());
|
||||||
|
if (!roleService.checkRoleNameUnique(role))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||||
}
|
}
|
||||||
else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
|
else if (!roleService.checkRoleKeyUnique(role))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||||
}
|
}
|
||||||
role.setUpdateBy(getUsername());
|
role.setUpdateBy(getUsername());
|
||||||
|
|
||||||
@ -131,9 +136,9 @@ public class SysRoleController extends BaseController
|
|||||||
loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
|
loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
|
||||||
tokenService.setLoginUser(loginUser);
|
tokenService.setLoginUser(loginUser);
|
||||||
}
|
}
|
||||||
return AjaxResult.success();
|
return success();
|
||||||
}
|
}
|
||||||
return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
|
return error("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,6 +150,7 @@ public class SysRoleController extends BaseController
|
|||||||
public AjaxResult dataScope(@RequestBody SysRole role)
|
public AjaxResult dataScope(@RequestBody SysRole role)
|
||||||
{
|
{
|
||||||
roleService.checkRoleAllowed(role);
|
roleService.checkRoleAllowed(role);
|
||||||
|
roleService.checkRoleDataScope(role.getRoleId());
|
||||||
return toAjax(roleService.authDataScope(role));
|
return toAjax(roleService.authDataScope(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,6 +163,7 @@ public class SysRoleController extends BaseController
|
|||||||
public AjaxResult changeStatus(@RequestBody SysRole role)
|
public AjaxResult changeStatus(@RequestBody SysRole role)
|
||||||
{
|
{
|
||||||
roleService.checkRoleAllowed(role);
|
roleService.checkRoleAllowed(role);
|
||||||
|
roleService.checkRoleDataScope(role.getRoleId());
|
||||||
role.setUpdateBy(getUsername());
|
role.setUpdateBy(getUsername());
|
||||||
return toAjax(roleService.updateRoleStatus(role));
|
return toAjax(roleService.updateRoleStatus(role));
|
||||||
}
|
}
|
||||||
@ -179,7 +186,7 @@ public class SysRoleController extends BaseController
|
|||||||
@GetMapping("/optionselect")
|
@GetMapping("/optionselect")
|
||||||
public AjaxResult optionselect()
|
public AjaxResult optionselect()
|
||||||
{
|
{
|
||||||
return AjaxResult.success(roleService.selectRoleAll());
|
return success(roleService.selectRoleAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -236,6 +243,20 @@ public class SysRoleController extends BaseController
|
|||||||
@PutMapping("/authUser/selectAll")
|
@PutMapping("/authUser/selectAll")
|
||||||
public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
|
public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
|
||||||
{
|
{
|
||||||
|
roleService.checkRoleDataScope(roleId);
|
||||||
return toAjax(roleService.insertAuthUsers(roleId, userIds));
|
return toAjax(roleService.insertAuthUsers(roleId, userIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取对应角色部门树列表
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:role:query')")
|
||||||
|
@GetMapping(value = "/deptTree/{roleId}")
|
||||||
|
public AjaxResult deptTree(@PathVariable("roleId") Long roleId)
|
||||||
|
{
|
||||||
|
AjaxResult ajax = AjaxResult.success();
|
||||||
|
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
|
||||||
|
ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));
|
||||||
|
return ajax;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,9 +17,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
@ -27,6 +27,7 @@ import com.ruoyi.common.enums.BusinessType;
|
|||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.system.service.ISysDeptService;
|
||||||
import com.ruoyi.system.service.ISysPostService;
|
import com.ruoyi.system.service.ISysPostService;
|
||||||
import com.ruoyi.system.service.ISysRoleService;
|
import com.ruoyi.system.service.ISysRoleService;
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
@ -46,6 +47,9 @@ public class SysUserController extends BaseController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ISysRoleService roleService;
|
private ISysRoleService roleService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysDeptService deptService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysPostService postService;
|
private ISysPostService postService;
|
||||||
|
|
||||||
@ -80,7 +84,7 @@ public class SysUserController extends BaseController
|
|||||||
List<SysUser> userList = util.importExcel(file.getInputStream());
|
List<SysUser> userList = util.importExcel(file.getInputStream());
|
||||||
String operName = getUsername();
|
String operName = getUsername();
|
||||||
String message = userService.importUser(userList, updateSupport, operName);
|
String message = userService.importUser(userList, updateSupport, operName);
|
||||||
return AjaxResult.success(message);
|
return success(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/importTemplate")
|
@PostMapping("/importTemplate")
|
||||||
@ -104,9 +108,10 @@ public class SysUserController extends BaseController
|
|||||||
ajax.put("posts", postService.selectPostAll());
|
ajax.put("posts", postService.selectPostAll());
|
||||||
if (StringUtils.isNotNull(userId))
|
if (StringUtils.isNotNull(userId))
|
||||||
{
|
{
|
||||||
ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId));
|
SysUser sysUser = userService.selectUserById(userId);
|
||||||
|
ajax.put(AjaxResult.DATA_TAG, sysUser);
|
||||||
ajax.put("postIds", postService.selectPostListByUserId(userId));
|
ajax.put("postIds", postService.selectPostListByUserId(userId));
|
||||||
ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
|
ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
@ -119,19 +124,17 @@ public class SysUserController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@Validated @RequestBody SysUser user)
|
public AjaxResult add(@Validated @RequestBody SysUser user)
|
||||||
{
|
{
|
||||||
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName())))
|
if (!userService.checkUserNameUnique(user))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
||||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(user.getEmail())
|
else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
||||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
|
||||||
{
|
{
|
||||||
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||||
}
|
}
|
||||||
user.setCreateBy(getUsername());
|
user.setCreateBy(getUsername());
|
||||||
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
||||||
@ -147,15 +150,18 @@ public class SysUserController extends BaseController
|
|||||||
public AjaxResult edit(@Validated @RequestBody SysUser user)
|
public AjaxResult edit(@Validated @RequestBody SysUser user)
|
||||||
{
|
{
|
||||||
userService.checkUserAllowed(user);
|
userService.checkUserAllowed(user);
|
||||||
if (StringUtils.isNotEmpty(user.getPhonenumber())
|
userService.checkUserDataScope(user.getUserId());
|
||||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
if (!userService.checkUserNameUnique(user))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(user.getEmail())
|
else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
||||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
|
||||||
{
|
{
|
||||||
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||||
|
}
|
||||||
|
else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
||||||
|
{
|
||||||
|
return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||||
}
|
}
|
||||||
user.setUpdateBy(getUsername());
|
user.setUpdateBy(getUsername());
|
||||||
return toAjax(userService.updateUser(user));
|
return toAjax(userService.updateUser(user));
|
||||||
@ -185,6 +191,7 @@ public class SysUserController extends BaseController
|
|||||||
public AjaxResult resetPwd(@RequestBody SysUser user)
|
public AjaxResult resetPwd(@RequestBody SysUser user)
|
||||||
{
|
{
|
||||||
userService.checkUserAllowed(user);
|
userService.checkUserAllowed(user);
|
||||||
|
userService.checkUserDataScope(user.getUserId());
|
||||||
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
||||||
user.setUpdateBy(getUsername());
|
user.setUpdateBy(getUsername());
|
||||||
return toAjax(userService.resetPwd(user));
|
return toAjax(userService.resetPwd(user));
|
||||||
@ -199,6 +206,7 @@ public class SysUserController extends BaseController
|
|||||||
public AjaxResult changeStatus(@RequestBody SysUser user)
|
public AjaxResult changeStatus(@RequestBody SysUser user)
|
||||||
{
|
{
|
||||||
userService.checkUserAllowed(user);
|
userService.checkUserAllowed(user);
|
||||||
|
userService.checkUserDataScope(user.getUserId());
|
||||||
user.setUpdateBy(getUsername());
|
user.setUpdateBy(getUsername());
|
||||||
return toAjax(userService.updateUserStatus(user));
|
return toAjax(userService.updateUserStatus(user));
|
||||||
}
|
}
|
||||||
@ -226,7 +234,18 @@ public class SysUserController extends BaseController
|
|||||||
@PutMapping("/authRole")
|
@PutMapping("/authRole")
|
||||||
public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
|
public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
|
||||||
{
|
{
|
||||||
|
userService.checkUserDataScope(userId);
|
||||||
userService.insertUserAuth(userId, roleIds);
|
userService.insertUserAuth(userId, roleIds);
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门树列表
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:user:list')")
|
||||||
|
@GetMapping("/deptTree")
|
||||||
|
public AjaxResult deptTree(SysDept dept)
|
||||||
|
{
|
||||||
|
return success(deptService.selectDeptTreeList(dept));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
package com.ruoyi.web.controller.tool;
|
|
||||||
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* swagger 接口
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/tool/swagger")
|
|
||||||
public class SwaggerController extends BaseController
|
|
||||||
{
|
|
||||||
@PreAuthorize("@ss.hasPermi('tool:swagger:view')")
|
|
||||||
@GetMapping()
|
|
||||||
public String index()
|
|
||||||
{
|
|
||||||
return redirect("/swagger-ui.html");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
@ -40,24 +40,24 @@ public class TestController extends BaseController
|
|||||||
|
|
||||||
@ApiOperation("获取用户列表")
|
@ApiOperation("获取用户列表")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public AjaxResult userList()
|
public R<List<UserEntity>> userList()
|
||||||
{
|
{
|
||||||
List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
|
List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
|
||||||
return AjaxResult.success(userList);
|
return R.ok(userList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("获取用户详细")
|
@ApiOperation("获取用户详细")
|
||||||
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
|
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
|
||||||
@GetMapping("/{userId}")
|
@GetMapping("/{userId}")
|
||||||
public AjaxResult getUser(@PathVariable Integer userId)
|
public R<UserEntity> getUser(@PathVariable Integer userId)
|
||||||
{
|
{
|
||||||
if (!users.isEmpty() && users.containsKey(userId))
|
if (!users.isEmpty() && users.containsKey(userId))
|
||||||
{
|
{
|
||||||
return AjaxResult.success(users.get(userId));
|
return R.ok(users.get(userId));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return error("用户不存在");
|
return R.fail("用户不存在");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,44 +69,46 @@ public class TestController extends BaseController
|
|||||||
@ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String", dataTypeClass = String.class)
|
@ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String", dataTypeClass = String.class)
|
||||||
})
|
})
|
||||||
@PostMapping("/save")
|
@PostMapping("/save")
|
||||||
public AjaxResult save(UserEntity user)
|
public R<String> save(UserEntity user)
|
||||||
{
|
{
|
||||||
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
|
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
|
||||||
{
|
{
|
||||||
return error("用户ID不能为空");
|
return R.fail("用户ID不能为空");
|
||||||
}
|
}
|
||||||
return AjaxResult.success(users.put(user.getUserId(), user));
|
users.put(user.getUserId(), user);
|
||||||
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("更新用户")
|
@ApiOperation("更新用户")
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
public AjaxResult update(@RequestBody UserEntity user)
|
public R<String> update(@RequestBody UserEntity user)
|
||||||
{
|
{
|
||||||
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
|
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
|
||||||
{
|
{
|
||||||
return error("用户ID不能为空");
|
return R.fail("用户ID不能为空");
|
||||||
}
|
}
|
||||||
if (users.isEmpty() || !users.containsKey(user.getUserId()))
|
if (users.isEmpty() || !users.containsKey(user.getUserId()))
|
||||||
{
|
{
|
||||||
return error("用户不存在");
|
return R.fail("用户不存在");
|
||||||
}
|
}
|
||||||
users.remove(user.getUserId());
|
users.remove(user.getUserId());
|
||||||
return AjaxResult.success(users.put(user.getUserId(), user));
|
users.put(user.getUserId(), user);
|
||||||
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("删除用户信息")
|
@ApiOperation("删除用户信息")
|
||||||
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
|
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
|
||||||
@DeleteMapping("/{userId}")
|
@DeleteMapping("/{userId}")
|
||||||
public AjaxResult delete(@PathVariable Integer userId)
|
public R<String> delete(@PathVariable Integer userId)
|
||||||
{
|
{
|
||||||
if (!users.isEmpty() && users.containsKey(userId))
|
if (!users.isEmpty() && users.containsKey(userId))
|
||||||
{
|
{
|
||||||
users.remove(userId);
|
users.remove(userId);
|
||||||
return success();
|
return R.ok();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return error("用户不存在");
|
return R.fail("用户不存在");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,10 @@ spring:
|
|||||||
maxActive: 20
|
maxActive: 20
|
||||||
# 配置获取连接等待超时的时间
|
# 配置获取连接等待超时的时间
|
||||||
maxWait: 60000
|
maxWait: 60000
|
||||||
|
# 配置连接超时时间
|
||||||
|
connectTimeout: 30000
|
||||||
|
# 配置网络超时时间
|
||||||
|
socketTimeout: 60000
|
||||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||||
timeBetweenEvictionRunsMillis: 60000
|
timeBetweenEvictionRunsMillis: 60000
|
||||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||||
|
|||||||
@ -3,16 +3,16 @@ ruoyi:
|
|||||||
# 名称
|
# 名称
|
||||||
name: RuoYi
|
name: RuoYi
|
||||||
# 版本
|
# 版本
|
||||||
version: 3.8.0
|
version: 3.8.6
|
||||||
# 版权年份
|
# 版权年份
|
||||||
copyrightYear: 2021
|
copyrightYear: 2023
|
||||||
# 实例演示开关
|
# 实例演示开关
|
||||||
demoEnabled: true
|
demoEnabled: true
|
||||||
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
|
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
|
||||||
profile: D:/ruoyi/uploadPath
|
profile: D:/ruoyi/uploadPath
|
||||||
# 获取ip地址开关
|
# 获取ip地址开关
|
||||||
addressEnabled: false
|
addressEnabled: false
|
||||||
# 验证码类型 math 数组计算 char 字符验证
|
# 验证码类型 math 数字计算 char 字符验证
|
||||||
captchaType: math
|
captchaType: math
|
||||||
|
|
||||||
# 开发环境配置
|
# 开发环境配置
|
||||||
@ -25,10 +25,13 @@ server:
|
|||||||
tomcat:
|
tomcat:
|
||||||
# tomcat的URI编码
|
# tomcat的URI编码
|
||||||
uri-encoding: UTF-8
|
uri-encoding: UTF-8
|
||||||
# tomcat最大线程数,默认为200
|
# 连接数满后的排队数,默认为100
|
||||||
max-threads: 800
|
accept-count: 1000
|
||||||
# Tomcat启动初始化的线程数,默认值25
|
threads:
|
||||||
min-spare-threads: 30
|
# tomcat最大线程数,默认为200
|
||||||
|
max: 800
|
||||||
|
# Tomcat启动初始化的线程数,默认值10
|
||||||
|
min-spare: 100
|
||||||
|
|
||||||
# 日志配置
|
# 日志配置
|
||||||
logging:
|
logging:
|
||||||
@ -36,21 +39,29 @@ logging:
|
|||||||
com.ruoyi: debug
|
com.ruoyi: debug
|
||||||
org.springframework: warn
|
org.springframework: warn
|
||||||
|
|
||||||
|
# 用户配置
|
||||||
|
user:
|
||||||
|
password:
|
||||||
|
# 密码最大错误次数
|
||||||
|
maxRetryCount: 5
|
||||||
|
# 密码锁定时间(默认10分钟)
|
||||||
|
lockTime: 10
|
||||||
|
|
||||||
# Spring配置
|
# Spring配置
|
||||||
spring:
|
spring:
|
||||||
# 资源信息
|
# 资源信息
|
||||||
messages:
|
messages:
|
||||||
# 国际化资源文件路径
|
# 国际化资源文件路径
|
||||||
basename: i18n/messages
|
basename: i18n/messages
|
||||||
profiles:
|
profiles:
|
||||||
active: druid
|
active: druid
|
||||||
# 文件上传
|
# 文件上传
|
||||||
servlet:
|
servlet:
|
||||||
multipart:
|
multipart:
|
||||||
# 单个文件大小
|
# 单个文件大小
|
||||||
max-file-size: 10MB
|
max-file-size: 10MB
|
||||||
# 设置总上传的文件大小
|
# 设置总上传的文件大小
|
||||||
max-request-size: 20MB
|
max-request-size: 20MB
|
||||||
# 服务模块
|
# 服务模块
|
||||||
devtools:
|
devtools:
|
||||||
restart:
|
restart:
|
||||||
@ -65,7 +76,7 @@ spring:
|
|||||||
# 数据库索引
|
# 数据库索引
|
||||||
database: 0
|
database: 0
|
||||||
# 密码
|
# 密码
|
||||||
password:
|
password:
|
||||||
# 连接超时时间
|
# 连接超时时间
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
lettuce:
|
lettuce:
|
||||||
@ -81,27 +92,27 @@ spring:
|
|||||||
|
|
||||||
# token配置
|
# token配置
|
||||||
token:
|
token:
|
||||||
# 令牌自定义标识
|
# 令牌自定义标识
|
||||||
header: Authorization
|
header: Authorization
|
||||||
# 令牌密钥
|
# 令牌密钥
|
||||||
secret: abcdefghijklmnopqrstuvwxyz
|
secret: abcdefghijklmnopqrstuvwxyz
|
||||||
# 令牌有效期(默认30分钟)
|
# 令牌有效期(默认30分钟)
|
||||||
expireTime: 30
|
expireTime: 30
|
||||||
|
|
||||||
# MyBatis配置
|
# MyBatis配置
|
||||||
mybatis:
|
mybatis:
|
||||||
# 搜索指定包别名
|
# 搜索指定包别名
|
||||||
typeAliasesPackage: com.ruoyi.**.domain
|
typeAliasesPackage: com.ruoyi.**.domain
|
||||||
# 配置mapper的扫描,找到所有的mapper.xml映射文件
|
# 配置mapper的扫描,找到所有的mapper.xml映射文件
|
||||||
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||||
# 加载全局的配置文件
|
# 加载全局的配置文件
|
||||||
configLocation: classpath:mybatis/mybatis-config.xml
|
configLocation: classpath:mybatis/mybatis-config.xml
|
||||||
|
|
||||||
# PageHelper分页插件
|
# PageHelper分页插件
|
||||||
pagehelper:
|
pagehelper:
|
||||||
helperDialect: mysql
|
helperDialect: mysql
|
||||||
supportMethodsArguments: true
|
supportMethodsArguments: true
|
||||||
params: count=countSql
|
params: count=countSql
|
||||||
|
|
||||||
# Swagger配置
|
# Swagger配置
|
||||||
swagger:
|
swagger:
|
||||||
@ -111,7 +122,7 @@ swagger:
|
|||||||
pathMapping: /dev-api
|
pathMapping: /dev-api
|
||||||
|
|
||||||
# 防止XSS攻击
|
# 防止XSS攻击
|
||||||
xss:
|
xss:
|
||||||
# 过滤开关
|
# 过滤开关
|
||||||
enabled: true
|
enabled: true
|
||||||
# 排除链接(多个用逗号分隔)
|
# 排除链接(多个用逗号分隔)
|
||||||
|
|||||||
@ -5,10 +5,11 @@ user.jcaptcha.expire=验证码已失效
|
|||||||
user.not.exists=用户不存在/密码错误
|
user.not.exists=用户不存在/密码错误
|
||||||
user.password.not.match=用户不存在/密码错误
|
user.password.not.match=用户不存在/密码错误
|
||||||
user.password.retry.limit.count=密码输入错误{0}次
|
user.password.retry.limit.count=密码输入错误{0}次
|
||||||
user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定10分钟
|
user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定{1}分钟
|
||||||
user.password.delete=对不起,您的账号已被删除
|
user.password.delete=对不起,您的账号已被删除
|
||||||
user.blocked=用户已封禁,请联系管理员
|
user.blocked=用户已封禁,请联系管理员
|
||||||
role.blocked=角色已封禁,请联系管理员
|
role.blocked=角色已封禁,请联系管理员
|
||||||
|
login.blocked=很遗憾,访问IP已被列入系统黑名单
|
||||||
user.logout.success=退出成功
|
user.logout.success=退出成功
|
||||||
|
|
||||||
length.not.valid=长度必须在{min}到{max}个字符之间
|
length.not.valid=长度必须在{min}到{max}个字符之间
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>ruoyi</artifactId>
|
<artifactId>ruoyi</artifactId>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<version>3.8.0</version>
|
<version>3.8.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -58,11 +58,18 @@
|
|||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 动态数据源 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||||
|
<version>3.5.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 阿里JSON解析器 -->
|
<!-- 阿里JSON解析器 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson2</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- io常用工具类 -->
|
<!-- io常用工具类 -->
|
||||||
@ -71,12 +78,6 @@
|
|||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 文件上传工具类 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-fileupload</groupId>
|
|
||||||
<artifactId>commons-fileupload</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- excel工具 -->
|
<!-- excel工具 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 匿名访问不鉴权注解
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface Anonymous
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -25,4 +25,9 @@ public @interface DataScope
|
|||||||
* 用户表的别名
|
* 用户表的别名
|
||||||
*/
|
*/
|
||||||
public String userAlias() default "";
|
public String userAlias() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限字符(用于多个角色匹配符合要求的权限)默认根据权限注解@ss获取,多个权限用逗号分隔开来
|
||||||
|
*/
|
||||||
|
public String permission() default "";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,8 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||||
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
import com.ruoyi.common.utils.poi.ExcelHandlerAdapter;
|
import com.ruoyi.common.utils.poi.ExcelHandlerAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,17 +59,12 @@ public @interface Excel
|
|||||||
public int roundingMode() default BigDecimal.ROUND_HALF_EVEN;
|
public int roundingMode() default BigDecimal.ROUND_HALF_EVEN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出类型(0数字 1字符串)
|
* 导出时在excel中每个列的高度
|
||||||
*/
|
|
||||||
public ColumnType cellType() default ColumnType.STRING;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导出时在excel中每个列的高度 单位为字符
|
|
||||||
*/
|
*/
|
||||||
public double height() default 14;
|
public double height() default 14;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出时在excel中每个列的宽 单位为字符
|
* 导出时在excel中每个列的宽度
|
||||||
*/
|
*/
|
||||||
public double width() default 16;
|
public double width() default 16;
|
||||||
|
|
||||||
@ -91,6 +88,11 @@ public @interface Excel
|
|||||||
*/
|
*/
|
||||||
public String[] combo() default {};
|
public String[] combo() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否需要纵向合并单元格,应对需求:含有list集合单元格)
|
||||||
|
*/
|
||||||
|
public boolean needMerge() default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
|
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
|
||||||
*/
|
*/
|
||||||
@ -107,9 +109,34 @@ public @interface Excel
|
|||||||
public boolean isStatistics() default false;
|
public boolean isStatistics() default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出字段对齐方式(0:默认;1:靠左;2:居中;3:靠右)
|
* 导出类型(0数字 1字符串 2图片)
|
||||||
*/
|
*/
|
||||||
public Align align() default Align.AUTO;
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出字段对齐方式
|
||||||
|
*/
|
||||||
|
public HorizontalAlignment align() default HorizontalAlignment.CENTER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义数据处理器
|
* 自定义数据处理器
|
||||||
@ -121,22 +148,6 @@ public @interface Excel
|
|||||||
*/
|
*/
|
||||||
public String[] args() default {};
|
public String[] args() default {};
|
||||||
|
|
||||||
public enum Align
|
|
||||||
{
|
|
||||||
AUTO(0), LEFT(1), CENTER(2), RIGHT(3);
|
|
||||||
private final int value;
|
|
||||||
|
|
||||||
Align(int value)
|
|
||||||
{
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int value()
|
|
||||||
{
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
|
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import com.ruoyi.common.enums.OperatorType;
|
|||||||
public @interface Log
|
public @interface Log
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 模块
|
* 模块
|
||||||
*/
|
*/
|
||||||
public String title() default "";
|
public String title() default "";
|
||||||
|
|
||||||
@ -43,4 +43,9 @@ public @interface Log
|
|||||||
* 是否保存响应的参数
|
* 是否保存响应的参数
|
||||||
*/
|
*/
|
||||||
public boolean isSaveResponseData() default true;
|
public boolean isSaveResponseData() default true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排除指定的请求参数
|
||||||
|
*/
|
||||||
|
public String[] excludeParamNames() default {};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import java.lang.annotation.ElementType;
|
|||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
import com.ruoyi.common.enums.LimitType;
|
import com.ruoyi.common.enums.LimitType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,7 +21,7 @@ public @interface RateLimiter
|
|||||||
/**
|
/**
|
||||||
* 限流key
|
* 限流key
|
||||||
*/
|
*/
|
||||||
public String key() default Constants.RATE_LIMIT_KEY;
|
public String key() default CacheConstants.RATE_LIMIT_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 限流时间,单位秒
|
* 限流时间,单位秒
|
||||||
|
|||||||
@ -0,0 +1,44 @@
|
|||||||
|
package com.ruoyi.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存的key 常量
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class CacheConstants
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 登录用户 redis key
|
||||||
|
*/
|
||||||
|
public static final 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 REPEAT_SUBMIT_KEY = "repeat_submit:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限流 redis key
|
||||||
|
*/
|
||||||
|
public static final String RATE_LIMIT_KEY = "rate_limit:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录账户密码错误次数 redis key
|
||||||
|
*/
|
||||||
|
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
|
||||||
|
}
|
||||||
@ -19,6 +19,11 @@ public class Constants
|
|||||||
*/
|
*/
|
||||||
public static final String GBK = "GBK";
|
public static final String GBK = "GBK";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* www主域
|
||||||
|
*/
|
||||||
|
public static final String WWW = "www.";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http请求
|
* http请求
|
||||||
*/
|
*/
|
||||||
@ -58,27 +63,7 @@ public class Constants
|
|||||||
* 登录失败
|
* 登录失败
|
||||||
*/
|
*/
|
||||||
public static final String LOGIN_FAIL = "Error";
|
public static final String LOGIN_FAIL = "Error";
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码 redis key
|
|
||||||
*/
|
|
||||||
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录用户 redis key
|
|
||||||
*/
|
|
||||||
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 防重提交 redis key
|
|
||||||
*/
|
|
||||||
public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 限流 redis key
|
|
||||||
*/
|
|
||||||
public static final String RATE_LIMIT_KEY = "rate_limit:";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码有效期(分钟)
|
* 验证码有效期(分钟)
|
||||||
*/
|
*/
|
||||||
@ -124,16 +109,6 @@ public class Constants
|
|||||||
*/
|
*/
|
||||||
public static final String JWT_AUTHORITIES = "authorities";
|
public static final String JWT_AUTHORITIES = "authorities";
|
||||||
|
|
||||||
/**
|
|
||||||
* 参数管理 cache key
|
|
||||||
*/
|
|
||||||
public static final String SYS_CONFIG_KEY = "sys_config:";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字典管理 cache key
|
|
||||||
*/
|
|
||||||
public static final String SYS_DICT_KEY = "sys_dict:";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 资源映射路径 前缀
|
* 资源映射路径 前缀
|
||||||
*/
|
*/
|
||||||
@ -142,16 +117,26 @@ public class Constants
|
|||||||
/**
|
/**
|
||||||
* RMI 远程方法调用
|
* RMI 远程方法调用
|
||||||
*/
|
*/
|
||||||
public static final String LOOKUP_RMI = "rmi://";
|
public static final String LOOKUP_RMI = "rmi:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LDAP 远程方法调用
|
* LDAP 远程方法调用
|
||||||
*/
|
*/
|
||||||
public static final String LOOKUP_LDAP = "ldap://";
|
public static final String LOOKUP_LDAP = "ldap:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LDAPS 远程方法调用
|
||||||
|
*/
|
||||||
|
public static final String LOOKUP_LDAPS = "ldaps:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
|
||||||
|
*/
|
||||||
|
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时任务违规的字符
|
* 定时任务违规的字符
|
||||||
*/
|
*/
|
||||||
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
|
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
|
||||||
"org.springframework.jndi" };
|
"org.springframework", "org.apache", "com.ruoyi.common.utils.file", "com.ruoyi.common.config" };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,6 +109,9 @@ public class GenConstants
|
|||||||
/** 模糊查询 */
|
/** 模糊查询 */
|
||||||
public static final String QUERY_LIKE = "LIKE";
|
public static final String QUERY_LIKE = "LIKE";
|
||||||
|
|
||||||
|
/** 相等查询 */
|
||||||
|
public static final String QUERY_EQ = "EQ";
|
||||||
|
|
||||||
/** 需要 */
|
/** 需要 */
|
||||||
public static final String REQUIRE = "1";
|
public static final String REQUIRE = "1";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,4 +86,9 @@ public class HttpStatus
|
|||||||
* 接口未实现
|
* 接口未实现
|
||||||
*/
|
*/
|
||||||
public static final int NOT_IMPLEMENTED = 501;
|
public static final int NOT_IMPLEMENTED = 501;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统警告消息
|
||||||
|
*/
|
||||||
|
public static final int WARN = 601;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,9 +60,9 @@ public class UserConstants
|
|||||||
/** InnerLink组件标识 */
|
/** InnerLink组件标识 */
|
||||||
public final static String INNER_LINK = "InnerLink";
|
public final static String INNER_LINK = "InnerLink";
|
||||||
|
|
||||||
/** 校验返回结果码 */
|
/** 校验是否唯一的返回标识 */
|
||||||
public final static String UNIQUE = "0";
|
public final static boolean UNIQUE = true;
|
||||||
public final static String NOT_UNIQUE = "1";
|
public final static boolean NOT_UNIQUE = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名长度限制
|
* 用户名长度限制
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import com.ruoyi.common.core.page.PageDomain;
|
|||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.core.page.TableSupport;
|
import com.ruoyi.common.core.page.TableSupport;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
import com.ruoyi.common.utils.PageUtils;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.sql.SqlUtil;
|
import com.ruoyi.common.utils.sql.SqlUtil;
|
||||||
@ -51,15 +52,7 @@ public class BaseController
|
|||||||
*/
|
*/
|
||||||
protected void startPage()
|
protected void startPage()
|
||||||
{
|
{
|
||||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
PageUtils.startPage();
|
||||||
Integer pageNum = pageDomain.getPageNum();
|
|
||||||
Integer pageSize = pageDomain.getPageSize();
|
|
||||||
if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize))
|
|
||||||
{
|
|
||||||
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
|
|
||||||
Boolean reasonable = pageDomain.getReasonable();
|
|
||||||
PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,6 +68,14 @@ public class BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理分页的线程变量
|
||||||
|
*/
|
||||||
|
protected void clearPage()
|
||||||
|
{
|
||||||
|
PageUtils.clearPage();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 响应请求分页数据
|
* 响应请求分页数据
|
||||||
*/
|
*/
|
||||||
@ -112,6 +113,14 @@ public class BaseController
|
|||||||
{
|
{
|
||||||
return AjaxResult.success(message);
|
return AjaxResult.success(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回成功消息
|
||||||
|
*/
|
||||||
|
public AjaxResult success(Object data)
|
||||||
|
{
|
||||||
|
return AjaxResult.success(data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回失败消息
|
* 返回失败消息
|
||||||
@ -121,6 +130,14 @@ public class BaseController
|
|||||||
return AjaxResult.error(message);
|
return AjaxResult.error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回警告消息
|
||||||
|
*/
|
||||||
|
public AjaxResult warn(String message)
|
||||||
|
{
|
||||||
|
return AjaxResult.warn(message);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 响应返回结果
|
* 响应返回结果
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.common.core.domain;
|
package com.ruoyi.common.core.domain;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Objects;
|
||||||
import com.ruoyi.common.constant.HttpStatus;
|
import com.ruoyi.common.constant.HttpStatus;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
|
||||||
@ -101,10 +102,33 @@ public class AjaxResult extends HashMap<String, Object>
|
|||||||
return new AjaxResult(HttpStatus.SUCCESS, msg, data);
|
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()
|
public static AjaxResult error()
|
||||||
{
|
{
|
||||||
@ -115,7 +139,7 @@ public class AjaxResult extends HashMap<String, Object>
|
|||||||
* 返回错误消息
|
* 返回错误消息
|
||||||
*
|
*
|
||||||
* @param msg 返回内容
|
* @param msg 返回内容
|
||||||
* @return 警告消息
|
* @return 错误消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult error(String msg)
|
public static AjaxResult error(String msg)
|
||||||
{
|
{
|
||||||
@ -127,7 +151,7 @@ public class AjaxResult extends HashMap<String, Object>
|
|||||||
*
|
*
|
||||||
* @param msg 返回内容
|
* @param msg 返回内容
|
||||||
* @param data 数据对象
|
* @param data 数据对象
|
||||||
* @return 警告消息
|
* @return 错误消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult error(String msg, Object data)
|
public static AjaxResult error(String msg, Object data)
|
||||||
{
|
{
|
||||||
@ -139,13 +163,43 @@ public class AjaxResult extends HashMap<String, Object>
|
|||||||
*
|
*
|
||||||
* @param code 状态码
|
* @param code 状态码
|
||||||
* @param msg 返回内容
|
* @param msg 返回内容
|
||||||
* @return 警告消息
|
* @return 错误消息
|
||||||
*/
|
*/
|
||||||
public static AjaxResult error(int code, String msg)
|
public static AjaxResult error(int code, String msg)
|
||||||
{
|
{
|
||||||
return new AjaxResult(code, msg, null);
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 方便链式调用
|
* 方便链式调用
|
||||||
*
|
*
|
||||||
|
|||||||
@ -5,6 +5,8 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity基类
|
* Entity基类
|
||||||
@ -16,6 +18,7 @@ public class BaseEntity implements Serializable
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/** 搜索值 */
|
/** 搜索值 */
|
||||||
|
@JsonIgnore
|
||||||
private String searchValue;
|
private String searchValue;
|
||||||
|
|
||||||
/** 创建者 */
|
/** 创建者 */
|
||||||
@ -36,6 +39,7 @@ public class BaseEntity implements Serializable
|
|||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
/** 请求参数 */
|
/** 请求参数 */
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
private Map<String, Object> params;
|
private Map<String, Object> params;
|
||||||
|
|
||||||
public String getSearchValue()
|
public String getSearchValue()
|
||||||
|
|||||||
115
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java
Normal file
115
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/R.java
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
package com.ruoyi.common.core.domain;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import com.ruoyi.common.constant.HttpStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应信息主体
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class R<T> implements Serializable
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 成功 */
|
||||||
|
public static final int SUCCESS = HttpStatus.SUCCESS;
|
||||||
|
|
||||||
|
/** 失败 */
|
||||||
|
public static final int FAIL = HttpStatus.ERROR;
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public static <T> R<T> ok()
|
||||||
|
{
|
||||||
|
return restResult(null, SUCCESS, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> ok(T data)
|
||||||
|
{
|
||||||
|
return restResult(data, SUCCESS, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> ok(T data, String msg)
|
||||||
|
{
|
||||||
|
return restResult(data, SUCCESS, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> fail()
|
||||||
|
{
|
||||||
|
return restResult(null, FAIL, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> fail(String msg)
|
||||||
|
{
|
||||||
|
return restResult(null, FAIL, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> fail(T data)
|
||||||
|
{
|
||||||
|
return restResult(data, FAIL, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> fail(T data, String msg)
|
||||||
|
{
|
||||||
|
return restResult(data, FAIL, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> fail(int code, String msg)
|
||||||
|
{
|
||||||
|
return restResult(null, code, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> R<T> restResult(T data, int code, String msg)
|
||||||
|
{
|
||||||
|
R<T> apiResult = new R<>();
|
||||||
|
apiResult.setCode(code);
|
||||||
|
apiResult.setData(data);
|
||||||
|
apiResult.setMsg(msg);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode()
|
||||||
|
{
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(int code)
|
||||||
|
{
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg()
|
||||||
|
{
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg)
|
||||||
|
{
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getData()
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(T data)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.validation.constraints.Email;
|
import javax.validation.constraints.Email;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
@ -31,7 +32,7 @@ public class SysDept extends BaseEntity
|
|||||||
private String deptName;
|
private String deptName;
|
||||||
|
|
||||||
/** 显示顺序 */
|
/** 显示顺序 */
|
||||||
private String orderNum;
|
private Integer orderNum;
|
||||||
|
|
||||||
/** 负责人 */
|
/** 负责人 */
|
||||||
private String leader;
|
private String leader;
|
||||||
@ -96,13 +97,13 @@ public class SysDept extends BaseEntity
|
|||||||
this.deptName = deptName;
|
this.deptName = deptName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotBlank(message = "显示顺序不能为空")
|
@NotNull(message = "显示顺序不能为空")
|
||||||
public String getOrderNum()
|
public Integer getOrderNum()
|
||||||
{
|
{
|
||||||
return orderNum;
|
return orderNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrderNum(String orderNum)
|
public void setOrderNum(Integer orderNum)
|
||||||
{
|
{
|
||||||
this.orderNum = orderNum;
|
this.orderNum = orderNum;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -131,7 +131,7 @@ public class SysDictData extends BaseEntity
|
|||||||
|
|
||||||
public boolean getDefault()
|
public boolean getDefault()
|
||||||
{
|
{
|
||||||
return UserConstants.YES.equals(this.isDefault) ? true : false;
|
return UserConstants.YES.equals(this.isDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIsDefault()
|
public String getIsDefault()
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.common.core.domain.entity;
|
package com.ruoyi.common.core.domain.entity;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
@ -57,6 +58,7 @@ public class SysDictType extends BaseEntity
|
|||||||
|
|
||||||
@NotBlank(message = "字典类型不能为空")
|
@NotBlank(message = "字典类型不能为空")
|
||||||
@Size(min = 0, max = 100, message = "字典类型类型长度不能超过100个字符")
|
@Size(min = 0, max = 100, message = "字典类型类型长度不能超过100个字符")
|
||||||
|
@Pattern(regexp = "^[a-z][a-z0-9_]*$", message = "字典类型必须以字母开头,且只能为(小写字母,数字,下滑线)")
|
||||||
public String getDictType()
|
public String getDictType()
|
||||||
{
|
{
|
||||||
return dictType;
|
return dictType;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.ruoyi.common.core.domain.entity;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
@ -30,7 +31,7 @@ public class SysMenu extends BaseEntity
|
|||||||
private Long parentId;
|
private Long parentId;
|
||||||
|
|
||||||
/** 显示顺序 */
|
/** 显示顺序 */
|
||||||
private String orderNum;
|
private Integer orderNum;
|
||||||
|
|
||||||
/** 路由地址 */
|
/** 路由地址 */
|
||||||
private String path;
|
private String path;
|
||||||
@ -53,7 +54,7 @@ public class SysMenu extends BaseEntity
|
|||||||
/** 显示状态(0显示 1隐藏) */
|
/** 显示状态(0显示 1隐藏) */
|
||||||
private String visible;
|
private String visible;
|
||||||
|
|
||||||
/** 菜单状态(0显示 1隐藏) */
|
/** 菜单状态(0正常 1停用) */
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
/** 权限字符串 */
|
/** 权限字符串 */
|
||||||
@ -107,13 +108,13 @@ public class SysMenu extends BaseEntity
|
|||||||
this.parentId = parentId;
|
this.parentId = parentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotBlank(message = "显示顺序不能为空")
|
@NotNull(message = "显示顺序不能为空")
|
||||||
public String getOrderNum()
|
public Integer getOrderNum()
|
||||||
{
|
{
|
||||||
return orderNum;
|
return orderNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrderNum(String orderNum)
|
public void setOrderNum(Integer orderNum)
|
||||||
{
|
{
|
||||||
this.orderNum = orderNum;
|
this.orderNum = orderNum;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package com.ruoyi.common.core.domain.entity;
|
package com.ruoyi.common.core.domain.entity;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
@ -31,7 +33,7 @@ public class SysRole extends BaseEntity
|
|||||||
|
|
||||||
/** 角色排序 */
|
/** 角色排序 */
|
||||||
@Excel(name = "角色排序")
|
@Excel(name = "角色排序")
|
||||||
private String roleSort;
|
private Integer roleSort;
|
||||||
|
|
||||||
/** 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) */
|
/** 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) */
|
||||||
@Excel(name = "数据范围", readConverterExp = "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 Long[] deptIds;
|
||||||
|
|
||||||
|
/** 角色菜单权限 */
|
||||||
|
private Set<String> permissions;
|
||||||
|
|
||||||
public SysRole()
|
public SysRole()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -113,13 +118,13 @@ public class SysRole extends BaseEntity
|
|||||||
this.roleKey = roleKey;
|
this.roleKey = roleKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotBlank(message = "显示顺序不能为空")
|
@NotNull(message = "显示顺序不能为空")
|
||||||
public String getRoleSort()
|
public Integer getRoleSort()
|
||||||
{
|
{
|
||||||
return roleSort;
|
return roleSort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoleSort(String roleSort)
|
public void setRoleSort(Integer roleSort)
|
||||||
{
|
{
|
||||||
this.roleSort = roleSort;
|
this.roleSort = roleSort;
|
||||||
}
|
}
|
||||||
@ -203,7 +208,17 @@ public class SysRole extends BaseEntity
|
|||||||
{
|
{
|
||||||
this.deptIds = deptIds;
|
this.deptIds = deptIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<String> getPermissions()
|
||||||
|
{
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissions(Set<String> permissions)
|
||||||
|
{
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
|||||||
@ -2,18 +2,15 @@ package com.ruoyi.common.core.domain.entity;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.validation.constraints.Email;
|
import javax.validation.constraints.*;
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.Size;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.ruoyi.common.annotation.Excel;
|
import com.ruoyi.common.annotation.Excel;
|
||||||
import com.ruoyi.common.annotation.Excel.ColumnType;
|
import com.ruoyi.common.annotation.Excel.ColumnType;
|
||||||
import com.ruoyi.common.annotation.Excel.Type;
|
import com.ruoyi.common.annotation.Excel.Type;
|
||||||
import com.ruoyi.common.annotation.Excels;
|
import com.ruoyi.common.annotation.Excels;
|
||||||
import com.ruoyi.common.core.domain.BaseEntity;
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
import com.ruoyi.common.xss.Xss;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户对象 sys_user
|
* 用户对象 sys_user
|
||||||
@ -58,9 +55,6 @@ public class SysUser extends BaseEntity
|
|||||||
/** 密码 */
|
/** 密码 */
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
/** 盐加密 */
|
|
||||||
private String salt;
|
|
||||||
|
|
||||||
/** 帐号状态(0正常 1停用) */
|
/** 帐号状态(0正常 1停用) */
|
||||||
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
||||||
private String status;
|
private String status;
|
||||||
@ -135,6 +129,7 @@ public class SysUser extends BaseEntity
|
|||||||
this.deptId = deptId;
|
this.deptId = deptId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Xss(message = "用户昵称不能包含脚本字符")
|
||||||
@Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
|
@Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
|
||||||
public String getNickName()
|
public String getNickName()
|
||||||
{
|
{
|
||||||
@ -146,6 +141,7 @@ public class SysUser extends BaseEntity
|
|||||||
this.nickName = nickName;
|
this.nickName = nickName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Xss(message = "用户账号不能包含脚本字符")
|
||||||
@NotBlank(message = "用户账号不能为空")
|
@NotBlank(message = "用户账号不能为空")
|
||||||
@Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
|
@Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
|
||||||
public String getUserName()
|
public String getUserName()
|
||||||
@ -201,8 +197,6 @@ public class SysUser extends BaseEntity
|
|||||||
this.avatar = avatar;
|
this.avatar = avatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
@JsonProperty
|
|
||||||
public String getPassword()
|
public String getPassword()
|
||||||
{
|
{
|
||||||
return password;
|
return password;
|
||||||
@ -213,16 +207,6 @@ public class SysUser extends BaseEntity
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSalt()
|
|
||||||
{
|
|
||||||
return salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSalt(String salt)
|
|
||||||
{
|
|
||||||
this.salt = salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatus()
|
public String getStatus()
|
||||||
{
|
{
|
||||||
return status;
|
return status;
|
||||||
@ -325,7 +309,6 @@ public class SysUser extends BaseEntity
|
|||||||
.append("sex", getSex())
|
.append("sex", getSex())
|
||||||
.append("avatar", getAvatar())
|
.append("avatar", getAvatar())
|
||||||
.append("password", getPassword())
|
.append("password", getPassword())
|
||||||
.append("salt", getSalt())
|
|
||||||
.append("status", getStatus())
|
.append("status", getStatus())
|
||||||
.append("delFlag", getDelFlag())
|
.append("delFlag", getDelFlag())
|
||||||
.append("loginIp", getLoginIp())
|
.append("loginIp", getLoginIp())
|
||||||
|
|||||||
@ -25,7 +25,7 @@ public class LoginBody
|
|||||||
/**
|
/**
|
||||||
* 唯一标识
|
* 唯一标识
|
||||||
*/
|
*/
|
||||||
private String uuid = "";
|
private String uuid;
|
||||||
|
|
||||||
public String getUsername()
|
public String getUsername()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
package com.ruoyi.common.core.domain.model;
|
package com.ruoyi.common.core.domain.model;
|
||||||
|
|
||||||
import java.util.Collection;
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
import java.util.Set;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import java.util.Collection;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录用户身份权限
|
* 登录用户身份权限
|
||||||
@ -71,6 +71,24 @@ public class LoginUser implements UserDetails
|
|||||||
*/
|
*/
|
||||||
private SysUser user;
|
private SysUser user;
|
||||||
|
|
||||||
|
public LoginUser()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoginUser(SysUser user, Set<String> permissions)
|
||||||
|
{
|
||||||
|
this.user = user;
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoginUser(Long userId, Long deptId, SysUser user, Set<String> permissions)
|
||||||
|
{
|
||||||
|
this.userId = userId;
|
||||||
|
this.deptId = deptId;
|
||||||
|
this.user = user;
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getUserId()
|
public Long getUserId()
|
||||||
{
|
{
|
||||||
return userId;
|
return userId;
|
||||||
@ -101,24 +119,6 @@ public class LoginUser implements UserDetails
|
|||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoginUser()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoginUser(SysUser user, Set<String> permissions)
|
|
||||||
{
|
|
||||||
this.user = user;
|
|
||||||
this.permissions = permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoginUser(Long userId, Long deptId, SysUser user, Set<String> permissions)
|
|
||||||
{
|
|
||||||
this.userId = userId;
|
|
||||||
this.deptId = deptId;
|
|
||||||
this.user = user;
|
|
||||||
this.permissions = permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
@Override
|
@Override
|
||||||
public String getPassword()
|
public String getPassword()
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.common.core.page;
|
package com.ruoyi.common.core.page;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.text.Convert;
|
||||||
import com.ruoyi.common.utils.ServletUtils;
|
import com.ruoyi.common.utils.ServletUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,8 +41,8 @@ public class TableSupport
|
|||||||
public static PageDomain getPageDomain()
|
public static PageDomain getPageDomain()
|
||||||
{
|
{
|
||||||
PageDomain pageDomain = new PageDomain();
|
PageDomain pageDomain = new PageDomain();
|
||||||
pageDomain.setPageNum(ServletUtils.getParameterToInt(PAGE_NUM));
|
pageDomain.setPageNum(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1));
|
||||||
pageDomain.setPageSize(ServletUtils.getParameterToInt(PAGE_SIZE));
|
pageDomain.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10));
|
||||||
pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN));
|
pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN));
|
||||||
pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC));
|
pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC));
|
||||||
pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE));
|
pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE));
|
||||||
|
|||||||
@ -74,6 +74,28 @@ public class RedisCache
|
|||||||
return redisTemplate.expire(key, timeout, unit);
|
return redisTemplate.expire(key, timeout, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取有效时间
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @return 有效时间
|
||||||
|
*/
|
||||||
|
public long getExpire(final String key)
|
||||||
|
{
|
||||||
|
return redisTemplate.getExpire(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断 key是否存在
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
* @return true 存在 false不存在
|
||||||
|
*/
|
||||||
|
public Boolean hasKey(String key)
|
||||||
|
{
|
||||||
|
return redisTemplate.hasKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得缓存的基本对象。
|
* 获得缓存的基本对象。
|
||||||
*
|
*
|
||||||
@ -102,9 +124,9 @@ public class RedisCache
|
|||||||
* @param collection 多个对象
|
* @param collection 多个对象
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public long deleteObject(final Collection collection)
|
public boolean deleteObject(final Collection collection)
|
||||||
{
|
{
|
||||||
return redisTemplate.delete(collection);
|
return redisTemplate.delete(collection) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -209,18 +231,6 @@ public class RedisCache
|
|||||||
return opsForHash.get(key, hKey);
|
return opsForHash.get(key, hKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除Hash中的数据
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* @param mapkey
|
|
||||||
*/
|
|
||||||
public void delCacheMapValue(final String key, final String hkey)
|
|
||||||
{
|
|
||||||
HashOperations hashOperations = redisTemplate.opsForHash();
|
|
||||||
hashOperations.delete(key, hkey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取多个Hash中的数据
|
* 获取多个Hash中的数据
|
||||||
*
|
*
|
||||||
@ -233,6 +243,18 @@ public class RedisCache
|
|||||||
return redisTemplate.opsForHash().multiGet(key, hKeys);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得缓存的基本对象列表
|
* 获得缓存的基本对象列表
|
||||||
*
|
*
|
||||||
|
|||||||
@ -562,17 +562,12 @@ public class Convert
|
|||||||
switch (valueStr)
|
switch (valueStr)
|
||||||
{
|
{
|
||||||
case "true":
|
case "true":
|
||||||
return true;
|
|
||||||
case "false":
|
|
||||||
return false;
|
|
||||||
case "yes":
|
case "yes":
|
||||||
return true;
|
|
||||||
case "ok":
|
case "ok":
|
||||||
return true;
|
|
||||||
case "no":
|
|
||||||
return false;
|
|
||||||
case "1":
|
case "1":
|
||||||
return true;
|
return true;
|
||||||
|
case "false":
|
||||||
|
case "no":
|
||||||
case "0":
|
case "0":
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
@ -718,7 +713,7 @@ public class Convert
|
|||||||
}
|
}
|
||||||
if (value instanceof Double)
|
if (value instanceof Double)
|
||||||
{
|
{
|
||||||
return new BigDecimal((Double) value);
|
return BigDecimal.valueOf((Double) value);
|
||||||
}
|
}
|
||||||
if (value instanceof Integer)
|
if (value instanceof Integer)
|
||||||
{
|
{
|
||||||
@ -899,7 +894,7 @@ public class Convert
|
|||||||
*/
|
*/
|
||||||
public static String toSBC(String input, Set<Character> notConvertSet)
|
public static String toSBC(String input, Set<Character> notConvertSet)
|
||||||
{
|
{
|
||||||
char c[] = input.toCharArray();
|
char[] c = input.toCharArray();
|
||||||
for (int i = 0; i < c.length; i++)
|
for (int i = 0; i < c.length; i++)
|
||||||
{
|
{
|
||||||
if (null != notConvertSet && notConvertSet.contains(c[i]))
|
if (null != notConvertSet && notConvertSet.contains(c[i]))
|
||||||
@ -941,7 +936,7 @@ public class Convert
|
|||||||
*/
|
*/
|
||||||
public static String toDBC(String text, Set<Character> notConvertSet)
|
public static String toDBC(String text, Set<Character> notConvertSet)
|
||||||
{
|
{
|
||||||
char c[] = text.toCharArray();
|
char[] c = text.toCharArray();
|
||||||
for (int i = 0; i < c.length; i++)
|
for (int i = 0; i < c.length; i++)
|
||||||
{
|
{
|
||||||
if (null != notConvertSet && notConvertSet.contains(c[i]))
|
if (null != notConvertSet && notConvertSet.contains(c[i]))
|
||||||
|
|||||||
@ -7,7 +7,6 @@ package com.ruoyi.common.exception;
|
|||||||
*/
|
*/
|
||||||
public class GlobalException extends RuntimeException
|
public class GlobalException extends RuntimeException
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,6 +44,7 @@ public class GlobalException extends RuntimeException
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getMessage()
|
public String getMessage()
|
||||||
{
|
{
|
||||||
return message;
|
return message;
|
||||||
|
|||||||
@ -49,6 +49,7 @@ public final class ServiceException extends RuntimeException
|
|||||||
return detailMessage;
|
return detailMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getMessage()
|
public String getMessage()
|
||||||
{
|
{
|
||||||
return message;
|
return message;
|
||||||
|
|||||||
@ -0,0 +1,61 @@
|
|||||||
|
package com.ruoyi.common.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.exception.file;
|
package com.ruoyi.common.exception.file;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import org.apache.commons.fileupload.FileUploadException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传 误异常类
|
* 文件上传 误异常类
|
||||||
@ -18,7 +17,7 @@ public class InvalidExtensionException extends FileUploadException
|
|||||||
|
|
||||||
public InvalidExtensionException(String[] allowedExtension, String extension, String filename)
|
public InvalidExtensionException(String[] allowedExtension, String extension, String filename)
|
||||||
{
|
{
|
||||||
super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]");
|
super("文件[" + filename + "]后缀[" + extension + "]不正确,请上传" + Arrays.toString(allowedExtension) + "格式");
|
||||||
this.allowedExtension = allowedExtension;
|
this.allowedExtension = allowedExtension;
|
||||||
this.extension = extension;
|
this.extension = extension;
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.common.exception.user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 黑名单IP异常类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class BlackListException extends UserException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public BlackListException()
|
||||||
|
{
|
||||||
|
super("login.blocked", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.common.exception.user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户不存在异常类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class UserNotExistsException extends UserException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public UserNotExistsException()
|
||||||
|
{
|
||||||
|
super("user.not.exists", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.ruoyi.common.exception.user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户错误最大次数异常类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class UserPasswordRetryLimitExceedException extends UserException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public UserPasswordRetryLimitExceedException(int retryLimitCount, int lockTime)
|
||||||
|
{
|
||||||
|
super("user.password.retry.limit.exceed", new Object[] { retryLimitCount, lockTime });
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package com.ruoyi.common.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,6 +10,7 @@ import javax.servlet.ServletResponse;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequestWrapper;
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
import com.ruoyi.common.utils.http.HttpHelper;
|
import com.ruoyi.common.utils.http.HttpHelper;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建可重复读取inputStream的request
|
* 构建可重复读取inputStream的request
|
||||||
@ -23,10 +24,10 @@ public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper
|
|||||||
public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException
|
public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
super(request);
|
super(request);
|
||||||
request.setCharacterEncoding("UTF-8");
|
request.setCharacterEncoding(Constants.UTF8);
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding(Constants.UTF8);
|
||||||
|
|
||||||
body = HttpHelper.getBodyString(request).getBytes("UTF-8");
|
body = HttpHelper.getBodyString(request).getBytes(Constants.UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import javax.servlet.ServletResponse;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.enums.HttpMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 防止XSS攻击的过滤器
|
* 防止XSS攻击的过滤器
|
||||||
@ -59,7 +60,7 @@ public class XssFilter implements Filter
|
|||||||
String url = request.getServletPath();
|
String url = request.getServletPath();
|
||||||
String method = request.getMethod();
|
String method = request.getMethod();
|
||||||
// GET DELETE 不过滤
|
// GET DELETE 不过滤
|
||||||
if (method == null || method.matches("GET") || method.matches("DELETE"))
|
if (method == null || HttpMethod.GET.matches(method) || HttpMethod.DELETE.matches(method))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,13 +34,13 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper
|
|||||||
if (values != null)
|
if (values != null)
|
||||||
{
|
{
|
||||||
int length = values.length;
|
int length = values.length;
|
||||||
String[] escapseValues = new String[length];
|
String[] escapesValues = new String[length];
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
// 防xss攻击和过滤前后空格
|
// 防xss攻击和过滤前后空格
|
||||||
escapseValues[i] = EscapeUtil.clean(values[i]).trim();
|
escapesValues[i] = EscapeUtil.clean(values[i]).trim();
|
||||||
}
|
}
|
||||||
return escapseValues;
|
return escapesValues;
|
||||||
}
|
}
|
||||||
return super.getParameterValues(name);
|
return super.getParameterValues(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,11 @@ package com.ruoyi.common.utils;
|
|||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
|
|
||||||
@ -22,7 +27,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
|||||||
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
||||||
|
|
||||||
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
|
||||||
private static String[] parsePatterns = {
|
private static String[] parsePatterns = {
|
||||||
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
||||||
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
||||||
@ -121,7 +126,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取服务器启动时间
|
* 获取服务器启动时间
|
||||||
*/
|
*/
|
||||||
@ -132,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 endTime 最后时间
|
||||||
|
* @param startTime 开始时间
|
||||||
|
* @return 时间差(天/小时/分钟)
|
||||||
|
*/
|
||||||
|
public static String timeDistance(Date endDate, Date startTime)
|
||||||
{
|
{
|
||||||
long nd = 1000 * 24 * 60 * 60;
|
long nd = 1000 * 24 * 60 * 60;
|
||||||
long nh = 1000 * 60 * 60;
|
long nh = 1000 * 60 * 60;
|
||||||
long nm = 1000 * 60;
|
long nm = 1000 * 60;
|
||||||
// long ns = 1000;
|
// long ns = 1000;
|
||||||
// 获得两个时间的毫秒时间差异
|
// 获得两个时间的毫秒时间差异
|
||||||
long diff = endDate.getTime() - nowDate.getTime();
|
long diff = endDate.getTime() - startTime.getTime();
|
||||||
// 计算差多少天
|
// 计算差多少天
|
||||||
long day = diff / nd;
|
long day = diff / nd;
|
||||||
// 计算差多少小时
|
// 计算差多少小时
|
||||||
@ -152,4 +169,23 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
|||||||
// long sec = diff % nd % nh % nm / ns;
|
// long sec = diff % nd % nh % nm / ns;
|
||||||
return day + "天" + hour + "小时" + min + "分钟";
|
return day + "天" + hour + "小时" + min + "分钟";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加 LocalDateTime ==> Date
|
||||||
|
*/
|
||||||
|
public static Date toDate(LocalDateTime temporalAccessor)
|
||||||
|
{
|
||||||
|
ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault());
|
||||||
|
return Date.from(zdt.toInstant());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加 LocalDate ==> Date
|
||||||
|
*/
|
||||||
|
public static Date toDate(LocalDate temporalAccessor)
|
||||||
|
{
|
||||||
|
LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0));
|
||||||
|
ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
|
||||||
|
return Date.from(zdt.toInstant());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,8 @@ package com.ruoyi.common.utils;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
import com.ruoyi.common.core.domain.entity.SysDictData;
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||||||
import com.ruoyi.common.core.redis.RedisCache;
|
import com.ruoyi.common.core.redis.RedisCache;
|
||||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
@ -38,11 +39,10 @@ public class DictUtils
|
|||||||
*/
|
*/
|
||||||
public static List<SysDictData> getDictCache(String key)
|
public static List<SysDictData> getDictCache(String key)
|
||||||
{
|
{
|
||||||
Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
|
JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
|
||||||
if (StringUtils.isNotNull(cacheObj))
|
if (StringUtils.isNotNull(arrayCache))
|
||||||
{
|
{
|
||||||
List<SysDictData> dictDatas = StringUtils.cast(cacheObj);
|
return arrayCache.toList(SysDictData.class);
|
||||||
return dictDatas;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -84,27 +84,30 @@ public class DictUtils
|
|||||||
StringBuilder propertyString = new StringBuilder();
|
StringBuilder propertyString = new StringBuilder();
|
||||||
List<SysDictData> datas = getDictCache(dictType);
|
List<SysDictData> datas = getDictCache(dictType);
|
||||||
|
|
||||||
if (StringUtils.containsAny(separator, dictValue) && StringUtils.isNotEmpty(datas))
|
if (StringUtils.isNotNull(datas))
|
||||||
{
|
{
|
||||||
for (SysDictData dict : datas)
|
if (StringUtils.containsAny(separator, dictValue))
|
||||||
{
|
{
|
||||||
for (String value : dictValue.split(separator))
|
for (SysDictData dict : datas)
|
||||||
{
|
{
|
||||||
if (value.equals(dict.getDictValue()))
|
for (String value : dictValue.split(separator))
|
||||||
{
|
{
|
||||||
propertyString.append(dict.getDictLabel() + separator);
|
if (value.equals(dict.getDictValue()))
|
||||||
break;
|
{
|
||||||
|
propertyString.append(dict.getDictLabel()).append(separator);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
|
||||||
{
|
|
||||||
for (SysDictData dict : datas)
|
|
||||||
{
|
{
|
||||||
if (dictValue.equals(dict.getDictValue()))
|
for (SysDictData dict : datas)
|
||||||
{
|
{
|
||||||
return dict.getDictLabel();
|
if (dictValue.equals(dict.getDictValue()))
|
||||||
|
{
|
||||||
|
return dict.getDictLabel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,7 +135,7 @@ public class DictUtils
|
|||||||
{
|
{
|
||||||
if (label.equals(dict.getDictLabel()))
|
if (label.equals(dict.getDictLabel()))
|
||||||
{
|
{
|
||||||
propertyString.append(dict.getDictValue() + separator);
|
propertyString.append(dict.getDictValue()).append(separator);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,7 +169,7 @@ public class DictUtils
|
|||||||
*/
|
*/
|
||||||
public static void clearDictCache()
|
public static void clearDictCache()
|
||||||
{
|
{
|
||||||
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(Constants.SYS_DICT_KEY + "*");
|
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*");
|
||||||
SpringUtils.getBean(RedisCache.class).deleteObject(keys);
|
SpringUtils.getBean(RedisCache.class).deleteObject(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,6 +181,6 @@ public class DictUtils
|
|||||||
*/
|
*/
|
||||||
public static String getCacheKey(String configKey)
|
public static String getCacheKey(String configKey)
|
||||||
{
|
{
|
||||||
return Constants.SYS_DICT_KEY + configKey;
|
return CacheConstants.SYS_DICT_KEY + configKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,8 +18,7 @@ public class ExceptionUtil
|
|||||||
{
|
{
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
e.printStackTrace(new PrintWriter(sw, true));
|
e.printStackTrace(new PrintWriter(sw, true));
|
||||||
String str = sw.toString();
|
return sw.toString();
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRootErrorMessage(Exception e)
|
public static String getRootErrorMessage(Exception e)
|
||||||
|
|||||||
@ -0,0 +1,35 @@
|
|||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.ruoyi.common.core.page.PageDomain;
|
||||||
|
import com.ruoyi.common.core.page.TableSupport;
|
||||||
|
import com.ruoyi.common.utils.sql.SqlUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class PageUtils extends PageHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 设置请求分页数据
|
||||||
|
*/
|
||||||
|
public static void startPage()
|
||||||
|
{
|
||||||
|
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||||
|
Integer pageNum = pageDomain.getPageNum();
|
||||||
|
Integer pageSize = pageDomain.getPageSize();
|
||||||
|
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
|
||||||
|
Boolean reasonable = pageDomain.getReasonable();
|
||||||
|
PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理分页的线程变量
|
||||||
|
*/
|
||||||
|
public static void clearPage()
|
||||||
|
{
|
||||||
|
PageHelper.clearPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,12 +1,20 @@
|
|||||||
package com.ruoyi.common.utils;
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import org.springframework.web.context.request.RequestAttributes;
|
import org.springframework.web.context.request.RequestAttributes;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,6 +72,34 @@ public class ServletUtils
|
|||||||
return Convert.toBool(getRequest().getParameter(name), defaultValue);
|
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
|
* 获取request
|
||||||
*/
|
*/
|
||||||
@ -99,9 +135,8 @@ public class ServletUtils
|
|||||||
*
|
*
|
||||||
* @param response 渲染对象
|
* @param response 渲染对象
|
||||||
* @param string 待渲染的字符串
|
* @param string 待渲染的字符串
|
||||||
* @return null
|
|
||||||
*/
|
*/
|
||||||
public static String renderString(HttpServletResponse response, String string)
|
public static void renderString(HttpServletResponse response, String string)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -114,7 +149,6 @@ public class ServletUtils
|
|||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,13 +159,13 @@ public class ServletUtils
|
|||||||
public static boolean isAjaxRequest(HttpServletRequest request)
|
public static boolean isAjaxRequest(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
String accept = request.getHeader("accept");
|
String accept = request.getHeader("accept");
|
||||||
if (accept != null && accept.indexOf("application/json") != -1)
|
if (accept != null && accept.contains("application/json"))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String xRequestedWith = request.getHeader("X-Requested-With");
|
String xRequestedWith = request.getHeader("X-Requested-With");
|
||||||
if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1)
|
if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -143,10 +177,42 @@ public class ServletUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
String ajax = request.getParameter("__ajax");
|
String ajax = request.getParameter("__ajax");
|
||||||
if (StringUtils.inStringIgnoreCase(ajax, "json", "xml"))
|
return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容编码
|
||||||
|
*
|
||||||
|
* @param str 内容
|
||||||
|
* @return 编码后的内容
|
||||||
|
*/
|
||||||
|
public static String urlEncode(String str)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return true;
|
return URLEncoder.encode(str, Constants.UTF8);
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException e)
|
||||||
|
{
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容解码
|
||||||
|
*
|
||||||
|
* @param str 内容
|
||||||
|
* @return 解码后的内容
|
||||||
|
*/
|
||||||
|
public static String urlDecode(String str)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return URLDecoder.decode(str, Constants.UTF8);
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException e)
|
||||||
|
{
|
||||||
|
return StringUtils.EMPTY;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -324,6 +324,32 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断给定的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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写
|
* 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写
|
||||||
*
|
*
|
||||||
@ -455,7 +481,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 驼峰式命名法 例如:user_name->userName
|
* 驼峰式命名法
|
||||||
|
* 例如:user_name->userName
|
||||||
*/
|
*/
|
||||||
public static String toCamelCase(String s)
|
public static String toCamelCase(String s)
|
||||||
{
|
{
|
||||||
@ -463,6 +490,10 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (s.indexOf(SEPARATOR) == -1)
|
||||||
|
{
|
||||||
|
return s;
|
||||||
|
}
|
||||||
s = s.toLowerCase();
|
s = s.toLowerCase();
|
||||||
StringBuilder sb = new StringBuilder(s.length());
|
StringBuilder sb = new StringBuilder(s.length());
|
||||||
boolean upperCase = false;
|
boolean upperCase = false;
|
||||||
@ -531,4 +562,53 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||||||
{
|
{
|
||||||
return (T) obj;
|
return (T) obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数字左边补齐0,使之达到指定长度。注意,如果数字转换为字符串后,长度大于size,则只保留 最后size个字符。
|
||||||
|
*
|
||||||
|
* @param num 数字对象
|
||||||
|
* @param size 字符串指定长度
|
||||||
|
* @return 返回数字的字符串格式,该字符串为指定长度。
|
||||||
|
*/
|
||||||
|
public static final String padl(final Number num, final int size)
|
||||||
|
{
|
||||||
|
return padl(num.toString(), size, '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串左补齐。如果原始字符串s长度大于size,则只保留最后size个字符。
|
||||||
|
*
|
||||||
|
* @param s 原始字符串
|
||||||
|
* @param size 字符串指定长度
|
||||||
|
* @param c 用于补齐的字符
|
||||||
|
* @return 返回指定长度的字符串,由原字符串左补齐或截取得到。
|
||||||
|
*/
|
||||||
|
public static final String padl(final String s, final int size, final char c)
|
||||||
|
{
|
||||||
|
final StringBuilder sb = new StringBuilder(size);
|
||||||
|
if (s != null)
|
||||||
|
{
|
||||||
|
final int len = s.length();
|
||||||
|
if (s.length() <= size)
|
||||||
|
{
|
||||||
|
for (int i = size - len; i > 0; i--)
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
sb.append(s);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return s.substring(len - size, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = size; i > 0; i--)
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,228 +0,0 @@
|
|||||||
package com.ruoyi.common.utils;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.RenderingHints;
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Random;
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码工具类
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
public class VerifyCodeUtils
|
|
||||||
{
|
|
||||||
// 使用到Algerian字体,系统里没有的话需要安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字符
|
|
||||||
public static final String VERIFY_CODES = "123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
||||||
|
|
||||||
private static Random random = new SecureRandom();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用系统默认字符源生成验证码
|
|
||||||
*
|
|
||||||
* @param verifySize 验证码长度
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String generateVerifyCode(int verifySize)
|
|
||||||
{
|
|
||||||
return generateVerifyCode(verifySize, VERIFY_CODES);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用指定源生成验证码
|
|
||||||
*
|
|
||||||
* @param verifySize 验证码长度
|
|
||||||
* @param sources 验证码字符源
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String generateVerifyCode(int verifySize, String sources)
|
|
||||||
{
|
|
||||||
if (sources == null || sources.length() == 0)
|
|
||||||
{
|
|
||||||
sources = VERIFY_CODES;
|
|
||||||
}
|
|
||||||
int codesLen = sources.length();
|
|
||||||
Random rand = new Random(System.currentTimeMillis());
|
|
||||||
StringBuilder verifyCode = new StringBuilder(verifySize);
|
|
||||||
for (int i = 0; i < verifySize; i++)
|
|
||||||
{
|
|
||||||
verifyCode.append(sources.charAt(rand.nextInt(codesLen - 1)));
|
|
||||||
}
|
|
||||||
return verifyCode.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 输出指定验证码图片流
|
|
||||||
*
|
|
||||||
* @param w
|
|
||||||
* @param h
|
|
||||||
* @param os
|
|
||||||
* @param code
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static void outputImage(int w, int h, OutputStream os, String code) throws IOException
|
|
||||||
{
|
|
||||||
int verifySize = code.length();
|
|
||||||
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
|
|
||||||
Random rand = new Random();
|
|
||||||
Graphics2D g2 = image.createGraphics();
|
|
||||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
||||||
Color[] colors = new Color[5];
|
|
||||||
Color[] colorSpaces = new Color[] { Color.WHITE, Color.CYAN, Color.GRAY, Color.LIGHT_GRAY, Color.MAGENTA,
|
|
||||||
Color.ORANGE, Color.PINK, Color.YELLOW };
|
|
||||||
float[] fractions = new float[colors.length];
|
|
||||||
for (int i = 0; i < colors.length; i++)
|
|
||||||
{
|
|
||||||
colors[i] = colorSpaces[rand.nextInt(colorSpaces.length)];
|
|
||||||
fractions[i] = rand.nextFloat();
|
|
||||||
}
|
|
||||||
Arrays.sort(fractions);
|
|
||||||
|
|
||||||
g2.setColor(Color.GRAY);// 设置边框色
|
|
||||||
g2.fillRect(0, 0, w, h);
|
|
||||||
|
|
||||||
Color c = getRandColor(200, 250);
|
|
||||||
g2.setColor(c);// 设置背景色
|
|
||||||
g2.fillRect(0, 2, w, h - 4);
|
|
||||||
|
|
||||||
// 绘制干扰线
|
|
||||||
Random random = new Random();
|
|
||||||
g2.setColor(getRandColor(160, 200));// 设置线条的颜色
|
|
||||||
for (int i = 0; i < 20; i++)
|
|
||||||
{
|
|
||||||
int x = random.nextInt(w - 1);
|
|
||||||
int y = random.nextInt(h - 1);
|
|
||||||
int xl = random.nextInt(6) + 1;
|
|
||||||
int yl = random.nextInt(12) + 1;
|
|
||||||
g2.drawLine(x, y, x + xl + 40, y + yl + 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加噪点
|
|
||||||
float yawpRate = 0.05f;// 噪声率
|
|
||||||
int area = (int) (yawpRate * w * h);
|
|
||||||
for (int i = 0; i < area; i++)
|
|
||||||
{
|
|
||||||
int x = random.nextInt(w);
|
|
||||||
int y = random.nextInt(h);
|
|
||||||
int rgb = getRandomIntColor();
|
|
||||||
image.setRGB(x, y, rgb);
|
|
||||||
}
|
|
||||||
|
|
||||||
shear(g2, w, h, c);// 使图片扭曲
|
|
||||||
|
|
||||||
g2.setColor(getRandColor(100, 160));
|
|
||||||
int fontSize = h - 4;
|
|
||||||
Font font = new Font("Algerian", Font.ITALIC, fontSize);
|
|
||||||
g2.setFont(font);
|
|
||||||
char[] chars = code.toCharArray();
|
|
||||||
for (int i = 0; i < verifySize; i++)
|
|
||||||
{
|
|
||||||
AffineTransform affine = new AffineTransform();
|
|
||||||
affine.setToRotation(Math.PI / 4 * rand.nextDouble() * (rand.nextBoolean() ? 1 : -1),
|
|
||||||
(w / verifySize) * i + fontSize / 2, h / 2);
|
|
||||||
g2.setTransform(affine);
|
|
||||||
g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + fontSize / 2 - 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
g2.dispose();
|
|
||||||
ImageIO.write(image, "jpg", os);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Color getRandColor(int fc, int bc)
|
|
||||||
{
|
|
||||||
if (fc > 255) {
|
|
||||||
fc = 255;
|
|
||||||
}
|
|
||||||
if (bc > 255) {
|
|
||||||
bc = 255;
|
|
||||||
}
|
|
||||||
int r = fc + random.nextInt(bc - fc);
|
|
||||||
int g = fc + random.nextInt(bc - fc);
|
|
||||||
int b = fc + random.nextInt(bc - fc);
|
|
||||||
return new Color(r, g, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getRandomIntColor()
|
|
||||||
{
|
|
||||||
int[] rgb = getRandomRgb();
|
|
||||||
int color = 0;
|
|
||||||
for (int c : rgb)
|
|
||||||
{
|
|
||||||
color = color << 8;
|
|
||||||
color = color | c;
|
|
||||||
}
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int[] getRandomRgb()
|
|
||||||
{
|
|
||||||
int[] rgb = new int[3];
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
rgb[i] = random.nextInt(255);
|
|
||||||
}
|
|
||||||
return rgb;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void shear(Graphics g, int w1, int h1, Color color)
|
|
||||||
{
|
|
||||||
shearX(g, w1, h1, color);
|
|
||||||
shearY(g, w1, h1, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void shearX(Graphics g, int w1, int h1, Color color)
|
|
||||||
{
|
|
||||||
|
|
||||||
int period = random.nextInt(2);
|
|
||||||
|
|
||||||
boolean borderGap = true;
|
|
||||||
int frames = 1;
|
|
||||||
int phase = random.nextInt(2);
|
|
||||||
|
|
||||||
for (int i = 0; i < h1; i++)
|
|
||||||
{
|
|
||||||
double d = (double) (period >> 1)
|
|
||||||
* Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
|
|
||||||
g.copyArea(0, i, w1, 1, (int) d, 0);
|
|
||||||
if (borderGap)
|
|
||||||
{
|
|
||||||
g.setColor(color);
|
|
||||||
g.drawLine((int) d, i, 0, i);
|
|
||||||
g.drawLine((int) d + w1, i, w1, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void shearY(Graphics g, int w1, int h1, Color color)
|
|
||||||
{
|
|
||||||
|
|
||||||
int period = random.nextInt(40) + 10; // 50;
|
|
||||||
|
|
||||||
boolean borderGap = true;
|
|
||||||
int frames = 20;
|
|
||||||
int phase = 7;
|
|
||||||
for (int i = 0; i < w1; i++)
|
|
||||||
{
|
|
||||||
double d = (double) (period >> 1)
|
|
||||||
* Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
|
|
||||||
g.copyArea(i, 0, 1, h1, 0, (int) d);
|
|
||||||
if (borderGap)
|
|
||||||
{
|
|
||||||
g.setColor(color);
|
|
||||||
g.drawLine(i, (int) d, i, 0);
|
|
||||||
g.drawLine(i, (int) d + h1, i, h1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package com.ruoyi.common.utils.bean;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
import javax.validation.Validator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bean对象属性验证
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class BeanValidators
|
||||||
|
{
|
||||||
|
public static void validateWithException(Validator validator, Object object, Class<?>... groups)
|
||||||
|
throws ConstraintViolationException
|
||||||
|
{
|
||||||
|
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
|
||||||
|
if (!constraintViolations.isEmpty())
|
||||||
|
{
|
||||||
|
throw new ConstraintViolationException(constraintViolations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,8 @@ package com.ruoyi.common.utils.file;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Objects;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.ruoyi.common.config.RuoYiConfig;
|
import com.ruoyi.common.config.RuoYiConfig;
|
||||||
@ -11,7 +13,7 @@ import com.ruoyi.common.exception.file.FileSizeLimitExceededException;
|
|||||||
import com.ruoyi.common.exception.file.InvalidExtensionException;
|
import com.ruoyi.common.exception.file.InvalidExtensionException;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.uuid.IdUtils;
|
import com.ruoyi.common.utils.uuid.Seq;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传工具类
|
* 文件上传工具类
|
||||||
@ -100,7 +102,7 @@ public class FileUploadUtils
|
|||||||
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
|
||||||
InvalidExtensionException
|
InvalidExtensionException
|
||||||
{
|
{
|
||||||
int fileNamelength = file.getOriginalFilename().length();
|
int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
|
||||||
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
|
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
|
||||||
{
|
{
|
||||||
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
||||||
@ -110,10 +112,9 @@ public class FileUploadUtils
|
|||||||
|
|
||||||
String fileName = extractFilename(file);
|
String fileName = extractFilename(file);
|
||||||
|
|
||||||
File desc = getAbsoluteFile(baseDir, fileName);
|
String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
|
||||||
file.transferTo(desc);
|
file.transferTo(Paths.get(absPath));
|
||||||
String pathFileName = getPathFileName(baseDir, fileName);
|
return getPathFileName(baseDir, fileName);
|
||||||
return pathFileName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,10 +122,8 @@ public class FileUploadUtils
|
|||||||
*/
|
*/
|
||||||
public static final String extractFilename(MultipartFile file)
|
public static final String extractFilename(MultipartFile file)
|
||||||
{
|
{
|
||||||
String fileName = file.getOriginalFilename();
|
return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(),
|
||||||
String extension = getExtension(file);
|
FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file));
|
||||||
fileName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension;
|
|
||||||
return fileName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
|
public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
|
||||||
@ -145,8 +144,7 @@ public class FileUploadUtils
|
|||||||
{
|
{
|
||||||
int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
|
int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
|
||||||
String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
|
String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
|
||||||
String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
|
return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
|
||||||
return pathFileName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,7 +159,7 @@ public class FileUploadUtils
|
|||||||
throws FileSizeLimitExceededException, InvalidExtensionException
|
throws FileSizeLimitExceededException, InvalidExtensionException
|
||||||
{
|
{
|
||||||
long size = file.getSize();
|
long size = file.getSize();
|
||||||
if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE)
|
if (size > DEFAULT_MAX_SIZE)
|
||||||
{
|
{
|
||||||
throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
|
throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
|
||||||
}
|
}
|
||||||
@ -195,7 +193,6 @@ public class FileUploadUtils
|
|||||||
throw new InvalidExtensionException(allowedExtension, extension, fileName);
|
throw new InvalidExtensionException(allowedExtension, extension, fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -228,7 +225,7 @@ public class FileUploadUtils
|
|||||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||||
if (StringUtils.isEmpty(extension))
|
if (StringUtils.isEmpty(extension))
|
||||||
{
|
{
|
||||||
extension = MimeTypeUtils.getExtension(file.getContentType());
|
extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType()));
|
||||||
}
|
}
|
||||||
return extension;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import com.ruoyi.common.config.RuoYiConfig;
|
|||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.uuid.IdUtils;
|
import com.ruoyi.common.utils.uuid.IdUtils;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件处理工具类
|
* 文件处理工具类
|
||||||
@ -115,8 +116,7 @@ public class FileUtils
|
|||||||
// 路径为文件且不为空则进行删除
|
// 路径为文件且不为空则进行删除
|
||||||
if (file.isFile() && file.exists())
|
if (file.isFile() && file.exists())
|
||||||
{
|
{
|
||||||
file.delete();
|
flag = file.delete();
|
||||||
flag = true;
|
|
||||||
}
|
}
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
@ -196,7 +196,6 @@ public class FileUtils
|
|||||||
*
|
*
|
||||||
* @param response 响应对象
|
* @param response 响应对象
|
||||||
* @param realFileName 真实文件名
|
* @param realFileName 真实文件名
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException
|
public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) throws UnsupportedEncodingException
|
||||||
{
|
{
|
||||||
@ -210,7 +209,6 @@ public class FileUtils
|
|||||||
.append("utf-8''")
|
.append("utf-8''")
|
||||||
.append(percentEncodedFileName);
|
.append(percentEncodedFileName);
|
||||||
|
|
||||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
|
||||||
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
|
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
|
||||||
response.setHeader("Content-disposition", contentDispositionValue.toString());
|
response.setHeader("Content-disposition", contentDispositionValue.toString());
|
||||||
response.setHeader("download-filename", percentEncodedFileName);
|
response.setHeader("download-filename", percentEncodedFileName);
|
||||||
@ -256,4 +254,38 @@ public class FileUtils
|
|||||||
}
|
}
|
||||||
return strFileExtendName;
|
return strFileExtendName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件名称 /profile/upload/2022/04/16/ruoyi.png -- ruoyi.png
|
||||||
|
*
|
||||||
|
* @param fileName 路径名称
|
||||||
|
* @return 没有文件路径的名称
|
||||||
|
*/
|
||||||
|
public static String getName(String fileName)
|
||||||
|
{
|
||||||
|
if (fileName == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int lastUnixPos = fileName.lastIndexOf('/');
|
||||||
|
int lastWindowsPos = fileName.lastIndexOf('\\');
|
||||||
|
int index = Math.max(lastUnixPos, lastWindowsPos);
|
||||||
|
return fileName.substring(index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取不带后缀文件名称 /profile/upload/2022/04/16/ruoyi.png -- ruoyi
|
||||||
|
*
|
||||||
|
* @param fileName 路径名称
|
||||||
|
* @return 没有文件路径和后缀的名称
|
||||||
|
*/
|
||||||
|
public static String getNameNotSuffix(String fileName)
|
||||||
|
{
|
||||||
|
if (fileName == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String baseName = FilenameUtils.getBaseName(fileName);
|
||||||
|
return baseName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package com.ruoyi.common.utils.file;
|
package com.ruoyi.common.utils.file;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -59,13 +58,12 @@ public class ImageUtils
|
|||||||
/**
|
/**
|
||||||
* 读取文件为字节数据
|
* 读取文件为字节数据
|
||||||
*
|
*
|
||||||
* @param key 地址
|
* @param url 地址
|
||||||
* @return 字节数据
|
* @return 字节数据
|
||||||
*/
|
*/
|
||||||
public static byte[] readFile(String url)
|
public static byte[] readFile(String url)
|
||||||
{
|
{
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
ByteArrayOutputStream baos = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (url.startsWith("http"))
|
if (url.startsWith("http"))
|
||||||
@ -95,7 +93,6 @@ public class ImageUtils
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
IOUtils.closeQuietly(in);
|
IOUtils.closeQuietly(in);
|
||||||
IOUtils.closeQuietly(baos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -387,7 +387,7 @@ public final class HTMLFilter
|
|||||||
{
|
{
|
||||||
paramValue = processParamProtocol(paramValue);
|
paramValue = processParamProtocol(paramValue);
|
||||||
}
|
}
|
||||||
params.append(' ').append(paramName).append("=\\\"").append(paramValue).append("\"");
|
params.append(' ').append(paramName).append("=\\\"").append(paramValue).append("\\\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import java.io.BufferedReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -25,7 +25,7 @@ public class HttpHelper
|
|||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
try (InputStream inputStream = request.getInputStream())
|
try (InputStream inputStream = request.getInputStream())
|
||||||
{
|
{
|
||||||
reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
|
reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||||
String line = "";
|
String line = "";
|
||||||
while ((line = reader.readLine()) != null)
|
while ((line = reader.readLine()) != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import java.net.ConnectException;
|
|||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
@ -130,9 +131,8 @@ public class HttpUtils
|
|||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String urlNameString = url;
|
log.info("sendPost - {}", url);
|
||||||
log.info("sendPost - {}", urlNameString);
|
URL realUrl = new URL(url);
|
||||||
URL realUrl = new URL(urlNameString);
|
|
||||||
URLConnection conn = realUrl.openConnection();
|
URLConnection conn = realUrl.openConnection();
|
||||||
conn.setRequestProperty("accept", "*/*");
|
conn.setRequestProperty("accept", "*/*");
|
||||||
conn.setRequestProperty("connection", "Keep-Alive");
|
conn.setRequestProperty("connection", "Keep-Alive");
|
||||||
@ -144,7 +144,7 @@ public class HttpUtils
|
|||||||
out = new PrintWriter(conn.getOutputStream());
|
out = new PrintWriter(conn.getOutputStream());
|
||||||
out.print(param);
|
out.print(param);
|
||||||
out.flush();
|
out.flush();
|
||||||
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
|
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
|
||||||
String line;
|
String line;
|
||||||
while ((line = in.readLine()) != null)
|
while ((line = in.readLine()) != null)
|
||||||
{
|
{
|
||||||
@ -218,7 +218,7 @@ public class HttpUtils
|
|||||||
{
|
{
|
||||||
if (ret != null && !"".equals(ret.trim()))
|
if (ret != null && !"".equals(ret.trim()))
|
||||||
{
|
{
|
||||||
result.append(new String(ret.getBytes("ISO-8859-1"), "utf-8"));
|
result.append(new String(ret.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("recv - {}", result);
|
log.info("recv - {}", result);
|
||||||
|
|||||||
@ -2,7 +2,8 @@ package com.ruoyi.common.utils.ip;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.ruoyi.common.config.RuoYiConfig;
|
import com.ruoyi.common.config.RuoYiConfig;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
@ -25,7 +26,6 @@ public class AddressUtils
|
|||||||
|
|
||||||
public static String getRealAddressByIP(String ip)
|
public static String getRealAddressByIP(String ip)
|
||||||
{
|
{
|
||||||
String address = UNKNOWN;
|
|
||||||
// 内网不查询
|
// 内网不查询
|
||||||
if (IpUtils.internalIp(ip))
|
if (IpUtils.internalIp(ip))
|
||||||
{
|
{
|
||||||
@ -41,7 +41,7 @@ public class AddressUtils
|
|||||||
log.error("获取地理位置异常 {}", ip);
|
log.error("获取地理位置异常 {}", ip);
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
JSONObject obj = JSONObject.parseObject(rspStr);
|
JSONObject obj = JSON.parseObject(rspStr);
|
||||||
String region = obj.getString("pro");
|
String region = obj.getString("pro");
|
||||||
String city = obj.getString("city");
|
String city = obj.getString("city");
|
||||||
return String.format("%s %s", region, city);
|
return String.format("%s %s", region, city);
|
||||||
@ -51,6 +51,6 @@ public class AddressUtils
|
|||||||
log.error("获取地理位置异常 {}", ip);
|
log.error("获取地理位置异常 {}", ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return address;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,8 @@ package com.ruoyi.common.utils.ip;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import com.ruoyi.common.utils.ServletUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.html.EscapeUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取IP方法
|
* 获取IP方法
|
||||||
@ -13,6 +13,29 @@ import com.ruoyi.common.utils.html.EscapeUtil;
|
|||||||
*/
|
*/
|
||||||
public class IpUtils
|
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
|
||||||
|
*
|
||||||
|
* @param request 请求对象
|
||||||
|
* @return IP地址
|
||||||
|
*/
|
||||||
public static String getIpAddr(HttpServletRequest request)
|
public static String getIpAddr(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
if (request == null)
|
if (request == null)
|
||||||
@ -41,15 +64,28 @@ public class IpUtils
|
|||||||
{
|
{
|
||||||
ip = request.getRemoteAddr();
|
ip = request.getRemoteAddr();
|
||||||
}
|
}
|
||||||
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : EscapeUtil.clean(ip);
|
|
||||||
|
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : getMultistageReverseProxyIp(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否为内部IP地址
|
||||||
|
*
|
||||||
|
* @param ip IP地址
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
public static boolean internalIp(String ip)
|
public static boolean internalIp(String ip)
|
||||||
{
|
{
|
||||||
byte[] addr = textToNumericFormatV4(ip);
|
byte[] addr = textToNumericFormatV4(ip);
|
||||||
return internalIp(addr) || "127.0.0.1".equals(ip);
|
return internalIp(addr) || "127.0.0.1".equals(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否为内部IP地址
|
||||||
|
*
|
||||||
|
* @param addr byte地址
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
private static boolean internalIp(byte[] addr)
|
private static boolean internalIp(byte[] addr)
|
||||||
{
|
{
|
||||||
if (StringUtils.isNull(addr) || addr.length < 2)
|
if (StringUtils.isNull(addr) || addr.length < 2)
|
||||||
@ -110,7 +146,8 @@ public class IpUtils
|
|||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
l = Long.parseLong(elements[0]);
|
l = Long.parseLong(elements[0]);
|
||||||
if ((l < 0L) || (l > 4294967295L)) {
|
if ((l < 0L) || (l > 4294967295L))
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bytes[0] = (byte) (int) (l >> 24 & 0xFF);
|
bytes[0] = (byte) (int) (l >> 24 & 0xFF);
|
||||||
@ -120,12 +157,14 @@ public class IpUtils
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
l = Integer.parseInt(elements[0]);
|
l = Integer.parseInt(elements[0]);
|
||||||
if ((l < 0L) || (l > 255L)) {
|
if ((l < 0L) || (l > 255L))
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bytes[0] = (byte) (int) (l & 0xFF);
|
bytes[0] = (byte) (int) (l & 0xFF);
|
||||||
l = Integer.parseInt(elements[1]);
|
l = Integer.parseInt(elements[1]);
|
||||||
if ((l < 0L) || (l > 16777215L)) {
|
if ((l < 0L) || (l > 16777215L))
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bytes[1] = (byte) (int) (l >> 16 & 0xFF);
|
bytes[1] = (byte) (int) (l >> 16 & 0xFF);
|
||||||
@ -136,13 +175,15 @@ public class IpUtils
|
|||||||
for (i = 0; i < 2; ++i)
|
for (i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
l = Integer.parseInt(elements[i]);
|
l = Integer.parseInt(elements[i]);
|
||||||
if ((l < 0L) || (l > 255L)) {
|
if ((l < 0L) || (l > 255L))
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bytes[i] = (byte) (int) (l & 0xFF);
|
bytes[i] = (byte) (int) (l & 0xFF);
|
||||||
}
|
}
|
||||||
l = Integer.parseInt(elements[2]);
|
l = Integer.parseInt(elements[2]);
|
||||||
if ((l < 0L) || (l > 65535L)) {
|
if ((l < 0L) || (l > 65535L))
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bytes[2] = (byte) (int) (l >> 8 & 0xFF);
|
bytes[2] = (byte) (int) (l >> 8 & 0xFF);
|
||||||
@ -152,7 +193,8 @@ public class IpUtils
|
|||||||
for (i = 0; i < 4; ++i)
|
for (i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
l = Integer.parseInt(elements[i]);
|
l = Integer.parseInt(elements[i]);
|
||||||
if ((l < 0L) || (l > 255L)) {
|
if ((l < 0L) || (l > 255L))
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
bytes[i] = (byte) (int) (l & 0xFF);
|
bytes[i] = (byte) (int) (l & 0xFF);
|
||||||
@ -169,6 +211,11 @@ public class IpUtils
|
|||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取IP地址
|
||||||
|
*
|
||||||
|
* @return 本地IP地址
|
||||||
|
*/
|
||||||
public static String getHostIp()
|
public static String getHostIp()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -181,6 +228,11 @@ public class IpUtils
|
|||||||
return "127.0.0.1";
|
return "127.0.0.1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取主机名
|
||||||
|
*
|
||||||
|
* @return 本地主机名
|
||||||
|
*/
|
||||||
public static String getHostName()
|
public static String getHostName()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -192,4 +244,139 @@ public class IpUtils
|
|||||||
}
|
}
|
||||||
return "未知";
|
return "未知";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从多级反向代理中获得第一个非unknown IP地址
|
||||||
|
*
|
||||||
|
* @param ip 获得的IP地址
|
||||||
|
* @return 第一个非unknown IP地址
|
||||||
|
*/
|
||||||
|
public static String getMultistageReverseProxyIp(String ip)
|
||||||
|
{
|
||||||
|
// 多级反向代理检测
|
||||||
|
if (ip != null && ip.indexOf(",") > 0)
|
||||||
|
{
|
||||||
|
final String[] ips = ip.trim().split(",");
|
||||||
|
for (String subIp : ips)
|
||||||
|
{
|
||||||
|
if (false == isUnknown(subIp))
|
||||||
|
{
|
||||||
|
ip = subIp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return StringUtils.substring(ip, 0, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测给定字符串是否为未知,多用于检测HTTP请求相关
|
||||||
|
*
|
||||||
|
* @param checkString 被检测的字符串
|
||||||
|
* @return 是否未知
|
||||||
|
*/
|
||||||
|
public static boolean isUnknown(String checkString)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -7,10 +7,14 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -20,6 +24,9 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
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.hssf.usermodel.HSSFClientAnchor;
|
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFPicture;
|
import org.apache.poi.hssf.usermodel.HSSFPicture;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFPictureData;
|
import org.apache.poi.hssf.usermodel.HSSFPictureData;
|
||||||
@ -41,6 +48,7 @@ import org.apache.poi.ss.usermodel.FillPatternType;
|
|||||||
import org.apache.poi.ss.usermodel.Font;
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
|
import org.apache.poi.ss.usermodel.Name;
|
||||||
import org.apache.poi.ss.usermodel.PictureData;
|
import org.apache.poi.ss.usermodel.PictureData;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
@ -86,6 +94,15 @@ public class ExcelUtil<T>
|
|||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
|
private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
|
||||||
|
|
||||||
|
public static final String FORMULA_REGEX_STR = "=|-|\\+|@";
|
||||||
|
|
||||||
|
public static final String[] FORMULA_STR = { "=", "-", "+", "@" };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于dictType属性数据存储,避免重复查缓存
|
||||||
|
*/
|
||||||
|
public Map<String, String> sysDictMap = new HashMap<String, String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Excel sheet最大行数,默认65536
|
* Excel sheet最大行数,默认65536
|
||||||
*/
|
*/
|
||||||
@ -130,7 +147,7 @@ public class ExcelUtil<T>
|
|||||||
* 当前行号
|
* 当前行号
|
||||||
*/
|
*/
|
||||||
private int rownum;
|
private int rownum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标题
|
* 标题
|
||||||
*/
|
*/
|
||||||
@ -141,6 +158,26 @@ public class ExcelUtil<T>
|
|||||||
*/
|
*/
|
||||||
private short maxHeight;
|
private short maxHeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并后最后行数
|
||||||
|
*/
|
||||||
|
private int subMergedLastRowNum = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并后开始行数
|
||||||
|
*/
|
||||||
|
private int subMergedFirstRowNum = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象的子列表方法
|
||||||
|
*/
|
||||||
|
private Method subMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象的子列表属性
|
||||||
|
*/
|
||||||
|
private List<Field> subFields;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计列表
|
* 统计列表
|
||||||
*/
|
*/
|
||||||
@ -156,11 +193,27 @@ public class ExcelUtil<T>
|
|||||||
*/
|
*/
|
||||||
public Class<T> clazz;
|
public Class<T> clazz;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 需要排除列属性
|
||||||
|
*/
|
||||||
|
public String[] excludeFields;
|
||||||
|
|
||||||
public ExcelUtil(Class<T> clazz)
|
public ExcelUtil(Class<T> clazz)
|
||||||
{
|
{
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 隐藏Excel中列属性
|
||||||
|
*
|
||||||
|
* @param fields 列属性名 示例[单个"name"/多个"id","name"]
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void hideColumn(String... fields)
|
||||||
|
{
|
||||||
|
this.excludeFields = fields;
|
||||||
|
}
|
||||||
|
|
||||||
public void init(List<T> list, String sheetName, String title, Type type)
|
public void init(List<T> list, String sheetName, String title, Type type)
|
||||||
{
|
{
|
||||||
if (list == null)
|
if (list == null)
|
||||||
@ -174,6 +227,7 @@ public class ExcelUtil<T>
|
|||||||
createExcelField();
|
createExcelField();
|
||||||
createWorkbook();
|
createWorkbook();
|
||||||
createTitle();
|
createTitle();
|
||||||
|
createSubHead();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,13 +237,48 @@ public class ExcelUtil<T>
|
|||||||
{
|
{
|
||||||
if (StringUtils.isNotEmpty(title))
|
if (StringUtils.isNotEmpty(title))
|
||||||
{
|
{
|
||||||
|
subMergedFirstRowNum++;
|
||||||
|
subMergedLastRowNum++;
|
||||||
|
int titleLastCol = this.fields.size() - 1;
|
||||||
|
if (isSubList())
|
||||||
|
{
|
||||||
|
titleLastCol = titleLastCol + subFields.size() - 1;
|
||||||
|
}
|
||||||
Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0);
|
Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0);
|
||||||
titleRow.setHeightInPoints(30);
|
titleRow.setHeightInPoints(30);
|
||||||
Cell titleCell = titleRow.createCell(0);
|
Cell titleCell = titleRow.createCell(0);
|
||||||
titleCell.setCellStyle(styles.get("title"));
|
titleCell.setCellStyle(styles.get("title"));
|
||||||
titleCell.setCellValue(title);
|
titleCell.setCellValue(title);
|
||||||
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(),
|
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), titleLastCol));
|
||||||
this.fields.size() - 1));
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建对象的子列表名称
|
||||||
|
*/
|
||||||
|
public void createSubHead()
|
||||||
|
{
|
||||||
|
if (isSubList())
|
||||||
|
{
|
||||||
|
subMergedFirstRowNum++;
|
||||||
|
subMergedLastRowNum++;
|
||||||
|
Row subRow = sheet.createRow(rownum);
|
||||||
|
int excelNum = 0;
|
||||||
|
for (Object[] objects : fields)
|
||||||
|
{
|
||||||
|
Excel attr = (Excel) objects[1];
|
||||||
|
Cell headCell1 = subRow.createCell(excelNum);
|
||||||
|
headCell1.setCellValue(attr.name());
|
||||||
|
headCell1.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor())));
|
||||||
|
excelNum++;
|
||||||
|
}
|
||||||
|
int headFirstRow = excelNum - 1;
|
||||||
|
int headLastRow = headFirstRow + subFields.size() - 1;
|
||||||
|
if (headLastRow > headFirstRow)
|
||||||
|
{
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, headFirstRow, headLastRow));
|
||||||
|
}
|
||||||
|
rownum++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +401,7 @@ public class ExcelUtil<T>
|
|||||||
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
|
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
|
||||||
if (StringUtils.isNotEmpty(dateFormat))
|
if (StringUtils.isNotEmpty(dateFormat))
|
||||||
{
|
{
|
||||||
val = DateUtils.parseDateToStr(dateFormat, (Date) val);
|
val = parseDateToStr(dateFormat, val);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -324,7 +413,7 @@ public class ExcelUtil<T>
|
|||||||
{
|
{
|
||||||
val = Convert.toInt(val);
|
val = Convert.toInt(val);
|
||||||
}
|
}
|
||||||
else if (Long.TYPE == fieldType || Long.class == fieldType)
|
else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val)))
|
||||||
{
|
{
|
||||||
val = Convert.toLong(val);
|
val = Convert.toLong(val);
|
||||||
}
|
}
|
||||||
@ -407,7 +496,7 @@ public class ExcelUtil<T>
|
|||||||
{
|
{
|
||||||
return exportExcel(list, sheetName, StringUtils.EMPTY);
|
return exportExcel(list, sheetName, StringUtils.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对list数据源将其里面的数据导入到excel表单
|
* 对list数据源将其里面的数据导入到excel表单
|
||||||
*
|
*
|
||||||
@ -429,7 +518,6 @@ public class ExcelUtil<T>
|
|||||||
* @param list 导出数据集合
|
* @param list 导出数据集合
|
||||||
* @param sheetName 工作表的名称
|
* @param sheetName 工作表的名称
|
||||||
* @return 结果
|
* @return 结果
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName)
|
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName)
|
||||||
{
|
{
|
||||||
@ -444,7 +532,6 @@ public class ExcelUtil<T>
|
|||||||
* @param sheetName 工作表的名称
|
* @param sheetName 工作表的名称
|
||||||
* @param title 标题
|
* @param title 标题
|
||||||
* @return 结果
|
* @return 结果
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title)
|
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title)
|
||||||
{
|
{
|
||||||
@ -571,8 +658,20 @@ public class ExcelUtil<T>
|
|||||||
// 写入各个字段的列头名称
|
// 写入各个字段的列头名称
|
||||||
for (Object[] os : fields)
|
for (Object[] os : fields)
|
||||||
{
|
{
|
||||||
|
Field field = (Field) os[0];
|
||||||
Excel excel = (Excel) os[1];
|
Excel excel = (Excel) os[1];
|
||||||
this.createCell(excel, row, column++);
|
if (Collection.class.isAssignableFrom(field.getType()))
|
||||||
|
{
|
||||||
|
for (Field subField : subFields)
|
||||||
|
{
|
||||||
|
Excel subExcel = subField.getAnnotation(Excel.class);
|
||||||
|
this.createHeadCell(subExcel, row, column++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.createHeadCell(excel, row, column++);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Type.EXPORT.equals(type))
|
if (Type.EXPORT.equals(type))
|
||||||
{
|
{
|
||||||
@ -588,21 +687,67 @@ public class ExcelUtil<T>
|
|||||||
* @param index 序号
|
* @param index 序号
|
||||||
* @param row 单元格行
|
* @param row 单元格行
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void fillExcelData(int index, Row row)
|
public void fillExcelData(int index, Row row)
|
||||||
{
|
{
|
||||||
int startNo = index * sheetSize;
|
int startNo = index * sheetSize;
|
||||||
int endNo = Math.min(startNo + sheetSize, list.size());
|
int endNo = Math.min(startNo + sheetSize, list.size());
|
||||||
|
int rowNo = (1 + rownum) - startNo;
|
||||||
for (int i = startNo; i < endNo; i++)
|
for (int i = startNo; i < endNo; i++)
|
||||||
{
|
{
|
||||||
row = sheet.createRow(i + 1 + rownum - startNo);
|
rowNo = isSubList() ? (i > 1 ? rowNo + 1 : rowNo + i) : i + 1 + rownum - startNo;
|
||||||
|
row = sheet.createRow(rowNo);
|
||||||
// 得到导出对象.
|
// 得到导出对象.
|
||||||
T vo = (T) list.get(i);
|
T vo = (T) list.get(i);
|
||||||
|
Collection<?> subList = null;
|
||||||
|
if (isSubList())
|
||||||
|
{
|
||||||
|
if (isSubListValue(vo))
|
||||||
|
{
|
||||||
|
subList = getListCellValue(vo);
|
||||||
|
subMergedLastRowNum = subMergedLastRowNum + subList.size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
subMergedFirstRowNum++;
|
||||||
|
subMergedLastRowNum++;
|
||||||
|
}
|
||||||
|
}
|
||||||
int column = 0;
|
int column = 0;
|
||||||
for (Object[] os : fields)
|
for (Object[] os : fields)
|
||||||
{
|
{
|
||||||
Field field = (Field) os[0];
|
Field field = (Field) os[0];
|
||||||
Excel excel = (Excel) os[1];
|
Excel excel = (Excel) os[1];
|
||||||
this.addCell(excel, row, vo, field, column++);
|
if (Collection.class.isAssignableFrom(field.getType()) && StringUtils.isNotNull(subList))
|
||||||
|
{
|
||||||
|
boolean subFirst = false;
|
||||||
|
for (Object obj : subList)
|
||||||
|
{
|
||||||
|
if (subFirst)
|
||||||
|
{
|
||||||
|
rowNo++;
|
||||||
|
row = sheet.createRow(rowNo);
|
||||||
|
}
|
||||||
|
List<Field> subFields = FieldUtils.getFieldsListWithAnnotation(obj.getClass(), Excel.class);
|
||||||
|
int subIndex = 0;
|
||||||
|
for (Field subField : subFields)
|
||||||
|
{
|
||||||
|
if (subField.isAnnotationPresent(Excel.class))
|
||||||
|
{
|
||||||
|
subField.setAccessible(true);
|
||||||
|
Excel attr = subField.getAnnotation(Excel.class);
|
||||||
|
this.addCell(attr, row, (T) obj, subField, column + subIndex);
|
||||||
|
}
|
||||||
|
subIndex++;
|
||||||
|
}
|
||||||
|
subFirst = true;
|
||||||
|
}
|
||||||
|
this.subMergedFirstRowNum = this.subMergedFirstRowNum + subList.size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.addCell(excel, row, vo, field, column++);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -644,20 +789,6 @@ public class ExcelUtil<T>
|
|||||||
style.setFont(dataFont);
|
style.setFont(dataFont);
|
||||||
styles.put("data", style);
|
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 = wb.createCellStyle();
|
||||||
style.setAlignment(HorizontalAlignment.CENTER);
|
style.setAlignment(HorizontalAlignment.CENTER);
|
||||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
@ -667,35 +798,105 @@ public class ExcelUtil<T>
|
|||||||
style.setFont(totalFont);
|
style.setFont(totalFont);
|
||||||
styles.put("total", style);
|
styles.put("total", style);
|
||||||
|
|
||||||
style = wb.createCellStyle();
|
styles.putAll(annotationHeaderStyles(wb, styles));
|
||||||
style.cloneStyleFrom(styles.get("data"));
|
|
||||||
style.setAlignment(HorizontalAlignment.LEFT);
|
|
||||||
styles.put("data1", style);
|
|
||||||
|
|
||||||
style = wb.createCellStyle();
|
styles.putAll(annotationDataStyles(wb));
|
||||||
style.cloneStyleFrom(styles.get("data"));
|
|
||||||
style.setAlignment(HorizontalAlignment.CENTER);
|
|
||||||
styles.put("data2", style);
|
|
||||||
|
|
||||||
style = wb.createCellStyle();
|
return styles;
|
||||||
style.cloneStyleFrom(styles.get("data"));
|
}
|
||||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
|
||||||
styles.put("data3", style);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据Excel注解创建表格头样式
|
||||||
|
*
|
||||||
|
* @param wb 工作薄对象
|
||||||
|
* @return 自定义样式列表
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
Excel excel = (Excel) os[1];
|
||||||
|
String key = StringUtils.format("data_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor());
|
||||||
|
if (!styles.containsKey(key))
|
||||||
|
{
|
||||||
|
CellStyle style = wb.createCellStyle();
|
||||||
|
style.setAlignment(excel.align());
|
||||||
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
style.setBorderRight(BorderStyle.THIN);
|
||||||
|
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
||||||
|
style.setBorderLeft(BorderStyle.THIN);
|
||||||
|
style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
||||||
|
style.setBorderTop(BorderStyle.THIN);
|
||||||
|
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());
|
||||||
|
Font dataFont = wb.createFont();
|
||||||
|
dataFont.setFontName("Arial");
|
||||||
|
dataFont.setFontHeightInPoints((short) 10);
|
||||||
|
dataFont.setColor(excel.color().index);
|
||||||
|
style.setFont(dataFont);
|
||||||
|
styles.put(key, style);
|
||||||
|
}
|
||||||
|
}
|
||||||
return styles;
|
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 cell = row.createCell(column);
|
||||||
// 写入列信息
|
// 写入列信息
|
||||||
cell.setCellValue(attr.name());
|
cell.setCellValue(attr.name());
|
||||||
setDataValidation(attr, row, column);
|
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())));
|
||||||
|
if (attr.needMerge())
|
||||||
|
{
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column));
|
||||||
|
}
|
||||||
|
}
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -710,7 +911,17 @@ public class ExcelUtil<T>
|
|||||||
{
|
{
|
||||||
if (ColumnType.STRING == attr.cellType())
|
if (ColumnType.STRING == attr.cellType())
|
||||||
{
|
{
|
||||||
cell.setCellValue(StringUtils.isNull(value) ? attr.defaultValue() : value + attr.suffix());
|
String cellValue = Convert.toStr(value);
|
||||||
|
// 对于任何以表达式触发字符 =-+@开头的单元格,直接使用tab字符作为前缀,防止CSV注入。
|
||||||
|
if (StringUtils.startsWithAny(cellValue, FORMULA_STR))
|
||||||
|
{
|
||||||
|
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())
|
else if (ColumnType.NUMERIC == attr.cellType())
|
||||||
{
|
{
|
||||||
@ -775,17 +986,18 @@ public class ExcelUtil<T>
|
|||||||
// 设置列宽
|
// 设置列宽
|
||||||
sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
|
sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
|
||||||
}
|
}
|
||||||
// 如果设置了提示信息则鼠标放上去提示.
|
if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0)
|
||||||
if (StringUtils.isNotEmpty(attr.prompt()))
|
|
||||||
{
|
{
|
||||||
// 这里默认设了2-101列提示.
|
if (attr.combo().length > 15 || StringUtils.join(attr.combo()).length() > 255)
|
||||||
setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
|
{
|
||||||
}
|
// 如果下拉数大于15或字符串长度大于255,则使用一个新sheet存储,避免生成的模板下拉值获取不到
|
||||||
// 如果设置了combo属性则本列只能选择不能输入
|
setXSSFValidationWithHidden(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
||||||
if (attr.combo().length > 0)
|
}
|
||||||
{
|
else
|
||||||
// 这里默认设了2-101列只能选择不能输入.
|
{
|
||||||
setXSSFValidation(sheet, attr.combo(), 1, 100, column, column);
|
// 提示信息或只能选择不能输入的列内容.
|
||||||
|
setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -804,8 +1016,12 @@ public class ExcelUtil<T>
|
|||||||
{
|
{
|
||||||
// 创建cell
|
// 创建cell
|
||||||
cell = row.createCell(column);
|
cell = row.createCell(column);
|
||||||
int align = attr.align().value();
|
if (isSubListValue(vo) && getListCellValue(vo).size() > 1 && attr.needMerge())
|
||||||
cell.setCellStyle(styles.get("data" + (align >= 1 && align <= 3 ? align : "")));
|
{
|
||||||
|
CellRangeAddress cellAddress = new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column);
|
||||||
|
sheet.addMergedRegion(cellAddress);
|
||||||
|
}
|
||||||
|
cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor())));
|
||||||
|
|
||||||
// 用于读取对象中的属性
|
// 用于读取对象中的属性
|
||||||
Object value = getTargetValue(vo, field, attr);
|
Object value = getTargetValue(vo, field, attr);
|
||||||
@ -815,7 +1031,7 @@ public class ExcelUtil<T>
|
|||||||
String dictType = attr.dictType();
|
String dictType = attr.dictType();
|
||||||
if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
||||||
{
|
{
|
||||||
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
|
cell.setCellValue(parseDateToStr(dateFormat, value));
|
||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
|
else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
|
||||||
{
|
{
|
||||||
@ -823,11 +1039,16 @@ public class ExcelUtil<T>
|
|||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value))
|
else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value))
|
||||||
{
|
{
|
||||||
cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
|
if (!sysDictMap.containsKey(dictType + value))
|
||||||
|
{
|
||||||
|
String lable = convertDictByExp(Convert.toStr(value), dictType, separator);
|
||||||
|
sysDictMap.put(dictType + value, lable);
|
||||||
|
}
|
||||||
|
cell.setCellValue(sysDictMap.get(dictType + value));
|
||||||
}
|
}
|
||||||
else if (value instanceof BigDecimal && -1 != attr.scale())
|
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))
|
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||||
{
|
{
|
||||||
@ -849,48 +1070,78 @@ public class ExcelUtil<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置 POI XSSFSheet 单元格提示
|
* 设置 POI XSSFSheet 单元格提示或选择框
|
||||||
*
|
*
|
||||||
* @param sheet 表单
|
* @param sheet 表单
|
||||||
* @param promptTitle 提示标题
|
* @param textlist 下拉框显示的内容
|
||||||
* @param promptContent 提示内容
|
* @param promptContent 提示内容
|
||||||
* @param firstRow 开始行
|
* @param firstRow 开始行
|
||||||
* @param endRow 结束行
|
* @param endRow 结束行
|
||||||
* @param firstCol 开始列
|
* @param firstCol 开始列
|
||||||
* @param endCol 结束列
|
* @param endCol 结束列
|
||||||
*/
|
*/
|
||||||
public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
|
public void setPromptOrValidation(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow,
|
||||||
int firstCol, int endCol)
|
int firstCol, int endCol)
|
||||||
{
|
{
|
||||||
DataValidationHelper helper = sheet.getDataValidationHelper();
|
DataValidationHelper helper = sheet.getDataValidationHelper();
|
||||||
DataValidationConstraint constraint = helper.createCustomConstraint("DD1");
|
DataValidationConstraint constraint = textlist.length > 0 ? helper.createExplicitListConstraint(textlist) : helper.createCustomConstraint("DD1");
|
||||||
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
|
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
|
||||||
DataValidation dataValidation = helper.createValidation(constraint, regions);
|
DataValidation dataValidation = helper.createValidation(constraint, regions);
|
||||||
dataValidation.createPromptBox(promptTitle, promptContent);
|
if (StringUtils.isNotEmpty(promptContent))
|
||||||
dataValidation.setShowPromptBox(true);
|
{
|
||||||
|
// 如果设置了提示信息则鼠标放上去提示
|
||||||
|
dataValidation.createPromptBox("", promptContent);
|
||||||
|
dataValidation.setShowPromptBox(true);
|
||||||
|
}
|
||||||
|
// 处理Excel兼容性问题
|
||||||
|
if (dataValidation instanceof XSSFDataValidation)
|
||||||
|
{
|
||||||
|
dataValidation.setSuppressDropDownArrow(true);
|
||||||
|
dataValidation.setShowErrorBox(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dataValidation.setSuppressDropDownArrow(false);
|
||||||
|
}
|
||||||
sheet.addValidationData(dataValidation);
|
sheet.addValidationData(dataValidation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置某些列的值只能输入预制的数据,显示下拉框.
|
* 设置某些列的值只能输入预制的数据,显示下拉框(兼容超出一定数量的下拉框).
|
||||||
*
|
*
|
||||||
* @param sheet 要设置的sheet.
|
* @param sheet 要设置的sheet.
|
||||||
* @param textlist 下拉框显示的内容
|
* @param textlist 下拉框显示的内容
|
||||||
|
* @param promptContent 提示内容
|
||||||
* @param firstRow 开始行
|
* @param firstRow 开始行
|
||||||
* @param endRow 结束行
|
* @param endRow 结束行
|
||||||
* @param firstCol 开始列
|
* @param firstCol 开始列
|
||||||
* @param endCol 结束列
|
* @param endCol 结束列
|
||||||
* @return 设置好的sheet.
|
|
||||||
*/
|
*/
|
||||||
public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int 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 = wb.createSheet(hideSheetName); // 用于存储 下拉菜单数据
|
||||||
|
for (int i = 0; i < textlist.length; i++)
|
||||||
|
{
|
||||||
|
hideSheet.createRow(i).createCell(0).setCellValue(textlist[i]);
|
||||||
|
}
|
||||||
|
// 创建名称,可被其他单元格引用
|
||||||
|
Name name = wb.createName();
|
||||||
|
name.setNameName(hideSheetName + "_data");
|
||||||
|
name.setRefersToFormula(hideSheetName + "!$A$1:$A$" + textlist.length);
|
||||||
DataValidationHelper helper = sheet.getDataValidationHelper();
|
DataValidationHelper helper = sheet.getDataValidationHelper();
|
||||||
// 加载下拉列表内容
|
// 加载下拉列表内容
|
||||||
DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist);
|
DataValidationConstraint constraint = helper.createFormulaListConstraint(hideSheetName + "_data");
|
||||||
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
|
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
|
||||||
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
|
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
|
||||||
// 数据有效性对象
|
// 数据有效性对象
|
||||||
DataValidation dataValidation = helper.createValidation(constraint, regions);
|
DataValidation dataValidation = helper.createValidation(constraint, regions);
|
||||||
|
if (StringUtils.isNotEmpty(promptContent))
|
||||||
|
{
|
||||||
|
// 如果设置了提示信息则鼠标放上去提示
|
||||||
|
dataValidation.createPromptBox("", promptContent);
|
||||||
|
dataValidation.setShowPromptBox(true);
|
||||||
|
}
|
||||||
// 处理Excel兼容性问题
|
// 处理Excel兼容性问题
|
||||||
if (dataValidation instanceof XSSFDataValidation)
|
if (dataValidation instanceof XSSFDataValidation)
|
||||||
{
|
{
|
||||||
@ -903,6 +1154,8 @@ public class ExcelUtil<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
sheet.addValidationData(dataValidation);
|
sheet.addValidationData(dataValidation);
|
||||||
|
// 设置hiddenSheet隐藏
|
||||||
|
wb.setSheetHidden(wb.getSheetIndex(hideSheet), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -920,7 +1173,7 @@ public class ExcelUtil<T>
|
|||||||
for (String item : convertSource)
|
for (String item : convertSource)
|
||||||
{
|
{
|
||||||
String[] itemArray = item.split("=");
|
String[] itemArray = item.split("=");
|
||||||
if (StringUtils.containsAny(separator, propertyValue))
|
if (StringUtils.containsAny(propertyValue, separator))
|
||||||
{
|
{
|
||||||
for (String value : propertyValue.split(separator))
|
for (String value : propertyValue.split(separator))
|
||||||
{
|
{
|
||||||
@ -957,7 +1210,7 @@ public class ExcelUtil<T>
|
|||||||
for (String item : convertSource)
|
for (String item : convertSource)
|
||||||
{
|
{
|
||||||
String[] itemArray = item.split("=");
|
String[] itemArray = item.split("=");
|
||||||
if (StringUtils.containsAny(separator, propertyValue))
|
if (StringUtils.containsAny(propertyValue, separator))
|
||||||
{
|
{
|
||||||
for (String value : propertyValue.split(separator))
|
for (String value : propertyValue.split(separator))
|
||||||
{
|
{
|
||||||
@ -1078,7 +1331,7 @@ public class ExcelUtil<T>
|
|||||||
*/
|
*/
|
||||||
public String encodingFilename(String filename)
|
public String encodingFilename(String filename)
|
||||||
{
|
{
|
||||||
filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx";
|
filename = UUID.randomUUID() + "_" + filename + ".xlsx";
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1113,7 +1366,7 @@ public class ExcelUtil<T>
|
|||||||
if (StringUtils.isNotEmpty(excel.targetAttr()))
|
if (StringUtils.isNotEmpty(excel.targetAttr()))
|
||||||
{
|
{
|
||||||
String target = excel.targetAttr();
|
String target = excel.targetAttr();
|
||||||
if (target.indexOf(".") > -1)
|
if (target.contains("."))
|
||||||
{
|
{
|
||||||
String[] targets = target.split("[.]");
|
String[] targets = target.split("[.]");
|
||||||
for (String name : targets)
|
for (String name : targets)
|
||||||
@ -1170,29 +1423,40 @@ public class ExcelUtil<T>
|
|||||||
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
||||||
for (Field field : tempFields)
|
for (Field field : tempFields)
|
||||||
{
|
{
|
||||||
// 单注解
|
if (!ArrayUtils.contains(this.excludeFields, field.getName()))
|
||||||
if (field.isAnnotationPresent(Excel.class))
|
|
||||||
{
|
{
|
||||||
Excel attr = field.getAnnotation(Excel.class);
|
// 单注解
|
||||||
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
if (field.isAnnotationPresent(Excel.class))
|
||||||
{
|
|
||||||
field.setAccessible(true);
|
|
||||||
fields.add(new Object[] { field, attr });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 多注解
|
|
||||||
if (field.isAnnotationPresent(Excels.class))
|
|
||||||
{
|
|
||||||
Excels attrs = field.getAnnotation(Excels.class);
|
|
||||||
Excel[] excels = attrs.value();
|
|
||||||
for (Excel attr : excels)
|
|
||||||
{
|
{
|
||||||
|
Excel attr = field.getAnnotation(Excel.class);
|
||||||
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
||||||
{
|
{
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
fields.add(new Object[] { field, attr });
|
fields.add(new Object[] { field, attr });
|
||||||
}
|
}
|
||||||
|
if (Collection.class.isAssignableFrom(field.getType()))
|
||||||
|
{
|
||||||
|
subMethod = getSubMethod(field.getName(), clazz);
|
||||||
|
ParameterizedType pt = (ParameterizedType) field.getGenericType();
|
||||||
|
Class<?> subClass = (Class<?>) pt.getActualTypeArguments()[0];
|
||||||
|
this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 多注解
|
||||||
|
if (field.isAnnotationPresent(Excels.class))
|
||||||
|
{
|
||||||
|
Excels attrs = field.getAnnotation(Excels.class);
|
||||||
|
Excel[] excels = attrs.value();
|
||||||
|
for (Excel attr : excels)
|
||||||
|
{
|
||||||
|
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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1208,7 +1472,7 @@ public class ExcelUtil<T>
|
|||||||
for (Object[] os : this.fields)
|
for (Object[] os : this.fields)
|
||||||
{
|
{
|
||||||
Excel excel = (Excel) os[1];
|
Excel excel = (Excel) os[1];
|
||||||
maxHeight = maxHeight > excel.height() ? maxHeight : excel.height();
|
maxHeight = Math.max(maxHeight, excel.height());
|
||||||
}
|
}
|
||||||
return (short) (maxHeight * 20);
|
return (short) (maxHeight * 20);
|
||||||
}
|
}
|
||||||
@ -1345,7 +1609,7 @@ public class ExcelUtil<T>
|
|||||||
HSSFPicture pic = (HSSFPicture) shape;
|
HSSFPicture pic = (HSSFPicture) shape;
|
||||||
int pictureIndex = pic.getPictureIndex() - 1;
|
int pictureIndex = pic.getPictureIndex() - 1;
|
||||||
HSSFPictureData picData = pictures.get(pictureIndex);
|
HSSFPictureData picData = pictures.get(pictureIndex);
|
||||||
String picIndex = String.valueOf(anchor.getRow1()) + "_" + String.valueOf(anchor.getCol1());
|
String picIndex = anchor.getRow1() + "_" + anchor.getCol1();
|
||||||
sheetIndexPicMap.put(picIndex, picData);
|
sheetIndexPicMap.put(picIndex, picData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1388,4 +1652,94 @@ public class ExcelUtil<T>
|
|||||||
}
|
}
|
||||||
return sheetIndexPicMap;
|
return sheetIndexPicMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化不同类型的日期对象
|
||||||
|
*
|
||||||
|
* @param dateFormat 日期格式
|
||||||
|
* @param val 被格式化的日期对象
|
||||||
|
* @return 格式化后的日期字符
|
||||||
|
*/
|
||||||
|
public String parseDateToStr(String dateFormat, Object val)
|
||||||
|
{
|
||||||
|
if (val == null)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String str;
|
||||||
|
if (val instanceof Date)
|
||||||
|
{
|
||||||
|
str = DateUtils.parseDateToStr(dateFormat, (Date) val);
|
||||||
|
}
|
||||||
|
else if (val instanceof LocalDateTime)
|
||||||
|
{
|
||||||
|
str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDateTime) val));
|
||||||
|
}
|
||||||
|
else if (val instanceof LocalDate)
|
||||||
|
{
|
||||||
|
str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDate) val));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str = val.toString();
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否有对象的子列表
|
||||||
|
*/
|
||||||
|
public boolean isSubList()
|
||||||
|
{
|
||||||
|
return StringUtils.isNotNull(subFields) && subFields.size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否有对象的子列表,集合不为空
|
||||||
|
*/
|
||||||
|
public boolean isSubListValue(T vo)
|
||||||
|
{
|
||||||
|
return StringUtils.isNotNull(subFields) && subFields.size() > 0 && StringUtils.isNotNull(getListCellValue(vo)) && getListCellValue(vo).size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取集合的值
|
||||||
|
*/
|
||||||
|
public Collection<?> getListCellValue(Object obj)
|
||||||
|
{
|
||||||
|
Object value;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
value = subMethod.invoke(obj, new Object[] {});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new ArrayList<Object>();
|
||||||
|
}
|
||||||
|
return (Collection<?>) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取对象的子列表方法
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.common.utils.sign;
|
package com.ruoyi.common.utils.sign;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -55,7 +56,7 @@ public class Md5Utils
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new String(toHex(md5(s)).getBytes("UTF-8"), "UTF-8");
|
return new String(toHex(md5(s)).getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -143,4 +143,16 @@ public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationC
|
|||||||
final String[] activeProfiles = getActiveProfiles();
|
final String[] activeProfiles = getActiveProfiles();
|
||||||
return StringUtils.isNotEmpty(activeProfiles) ? activeProfiles[0] : null;
|
return StringUtils.isNotEmpty(activeProfiles) ? activeProfiles[0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置文件中的值
|
||||||
|
*
|
||||||
|
* @param key 配置文件的key
|
||||||
|
* @return 当前的配置文件的值
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static String getRequiredProperty(String key)
|
||||||
|
{
|
||||||
|
return applicationContext.getEnvironment().getRequiredProperty(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,11 @@ import com.ruoyi.common.utils.StringUtils;
|
|||||||
*/
|
*/
|
||||||
public class SqlUtil
|
public class SqlUtil
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 定义常用的 sql关键字
|
||||||
|
*/
|
||||||
|
public static String SQL_REGEX = "and |extractvalue|updatexml|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |+|user()";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
||||||
*/
|
*/
|
||||||
@ -34,4 +39,23 @@ public class SqlUtil
|
|||||||
{
|
{
|
||||||
return value.matches(SQL_PATTERN);
|
return value.matches(SQL_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL关键字检查
|
||||||
|
*/
|
||||||
|
public static void filterKeyword(String value)
|
||||||
|
{
|
||||||
|
if (StringUtils.isEmpty(value))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|");
|
||||||
|
for (String sqlKeyword : sqlKeywords)
|
||||||
|
{
|
||||||
|
if (StringUtils.indexOfIgnoreCase(value, sqlKeyword) > -1)
|
||||||
|
{
|
||||||
|
throw new UtilException("参数存在SQL注入风险");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,86 @@
|
|||||||
|
package com.ruoyi.common.utils.uuid;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ruoyi 序列生成类
|
||||||
|
*/
|
||||||
|
public class Seq
|
||||||
|
{
|
||||||
|
// 通用序列类型
|
||||||
|
public static final String commSeqType = "COMMON";
|
||||||
|
|
||||||
|
// 上传序列类型
|
||||||
|
public static final String uploadSeqType = "UPLOAD";
|
||||||
|
|
||||||
|
// 通用接口序列数
|
||||||
|
private static AtomicInteger commSeq = new AtomicInteger(1);
|
||||||
|
|
||||||
|
// 上传接口序列数
|
||||||
|
private static AtomicInteger uploadSeq = new AtomicInteger(1);
|
||||||
|
|
||||||
|
// 机器标识
|
||||||
|
private static final String machineCode = "A";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取通用序列号
|
||||||
|
*
|
||||||
|
* @return 序列值
|
||||||
|
*/
|
||||||
|
public static String getId()
|
||||||
|
{
|
||||||
|
return getId(commSeqType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认16位序列号 yyMMddHHmmss + 一位机器标识 + 3长度循环递增字符串
|
||||||
|
*
|
||||||
|
* @return 序列值
|
||||||
|
*/
|
||||||
|
public static String getId(String type)
|
||||||
|
{
|
||||||
|
AtomicInteger atomicInt = commSeq;
|
||||||
|
if (uploadSeqType.equals(type))
|
||||||
|
{
|
||||||
|
atomicInt = uploadSeq;
|
||||||
|
}
|
||||||
|
return getId(atomicInt, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用接口序列号 yyMMddHHmmss + 一位机器标识 + length长度循环递增字符串
|
||||||
|
*
|
||||||
|
* @param atomicInt 序列数
|
||||||
|
* @param length 数值长度
|
||||||
|
* @return 序列值
|
||||||
|
*/
|
||||||
|
public static String getId(AtomicInteger atomicInt, int length)
|
||||||
|
{
|
||||||
|
String result = DateUtils.dateTimeNow();
|
||||||
|
result += machineCode;
|
||||||
|
result += getSeq(atomicInt, length);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 序列循环递增字符串[1, 10 的 (length)幂次方), 用0左补齐length位数
|
||||||
|
*
|
||||||
|
* @return 序列值
|
||||||
|
*/
|
||||||
|
private synchronized static String getSeq(AtomicInteger atomicInt, int length)
|
||||||
|
{
|
||||||
|
// 先取值再+1
|
||||||
|
int value = atomicInt.getAndIncrement();
|
||||||
|
|
||||||
|
// 如果更新后值>=10 的 (length)幂次方则重置为1
|
||||||
|
int maxSeq = (int) Math.pow(10, length);
|
||||||
|
if (atomicInt.get() >= maxSeq)
|
||||||
|
{
|
||||||
|
atomicInt.set(1);
|
||||||
|
}
|
||||||
|
// 转字符串,用0左补齐
|
||||||
|
return StringUtils.padl(value, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -66,7 +66,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的本地线程伪随机数生成器生成该 UUID。
|
* 获取类型 4(伪随机生成的)UUID 的静态工厂。
|
||||||
*
|
*
|
||||||
* @return 随机生成的 {@code UUID}
|
* @return 随机生成的 {@code UUID}
|
||||||
*/
|
*/
|
||||||
|
|||||||
27
ruoyi-common/src/main/java/com/ruoyi/common/xss/Xss.java
Normal file
27
ruoyi-common/src/main/java/com/ruoyi/common/xss/Xss.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package com.ruoyi.common.xss;
|
||||||
|
|
||||||
|
import javax.validation.Constraint;
|
||||||
|
import javax.validation.Payload;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义xss校验注解
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(value = { ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER })
|
||||||
|
@Constraint(validatedBy = { XssValidator.class })
|
||||||
|
public @interface Xss
|
||||||
|
{
|
||||||
|
String message()
|
||||||
|
|
||||||
|
default "不允许任何脚本运行";
|
||||||
|
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package com.ruoyi.common.xss;
|
||||||
|
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import javax.validation.ConstraintValidator;
|
||||||
|
import javax.validation.ConstraintValidatorContext;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义xss校验注解实现
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class XssValidator implements ConstraintValidator<Xss, String>
|
||||||
|
{
|
||||||
|
private static final String HTML_PATTERN = "<(\\S*?)[^>]*>.*?|<.*? />";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext)
|
||||||
|
{
|
||||||
|
if (StringUtils.isBlank(value))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return !containsHtml(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean containsHtml(String value)
|
||||||
|
{
|
||||||
|
Pattern pattern = Pattern.compile(HTML_PATTERN);
|
||||||
|
Matcher matcher = pattern.matcher(value);
|
||||||
|
return matcher.matches();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>ruoyi</artifactId>
|
<artifactId>ruoyi</artifactId>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<version>3.8.0</version>
|
<version>3.8.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -37,11 +37,11 @@
|
|||||||
|
|
||||||
<!-- 验证码 -->
|
<!-- 验证码 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.penggle</groupId>
|
<groupId>pro.fessional</groupId>
|
||||||
<artifactId>kaptcha</artifactId>
|
<artifactId>kaptcha</artifactId>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>servlet-api</artifactId>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package com.ruoyi.framework.aspectj;
|
package com.ruoyi.framework.aspectj;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
@ -9,8 +11,10 @@ import com.ruoyi.common.core.domain.BaseEntity;
|
|||||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.framework.security.context.PermissionContextHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据过滤处理
|
* 数据过滤处理
|
||||||
@ -68,8 +72,9 @@ public class DataScopeAspect
|
|||||||
// 如果是超级管理员,则不过滤数据
|
// 如果是超级管理员,则不过滤数据
|
||||||
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
|
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
|
||||||
{
|
{
|
||||||
|
String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext());
|
||||||
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
|
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
|
||||||
controllerDataScope.userAlias());
|
controllerDataScope.userAlias(), permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,18 +84,31 @@ public class DataScopeAspect
|
|||||||
*
|
*
|
||||||
* @param joinPoint 切点
|
* @param joinPoint 切点
|
||||||
* @param user 用户
|
* @param user 用户
|
||||||
* @param userAlias 别名
|
* @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();
|
StringBuilder sqlString = new StringBuilder();
|
||||||
|
List<String> conditions = new ArrayList<String>();
|
||||||
|
|
||||||
for (SysRole role : user.getRoles())
|
for (SysRole role : user.getRoles())
|
||||||
{
|
{
|
||||||
String dataScope = role.getDataScope();
|
String dataScope = role.getDataScope();
|
||||||
|
if (!DATA_SCOPE_CUSTOM.equals(dataScope) && conditions.contains(dataScope))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(permission) && StringUtils.isNotEmpty(role.getPermissions())
|
||||||
|
&& !StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission)))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (DATA_SCOPE_ALL.equals(dataScope))
|
if (DATA_SCOPE_ALL.equals(dataScope))
|
||||||
{
|
{
|
||||||
sqlString = new StringBuilder();
|
sqlString = new StringBuilder();
|
||||||
|
conditions.add(dataScope);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (DATA_SCOPE_CUSTOM.equals(dataScope))
|
else if (DATA_SCOPE_CUSTOM.equals(dataScope))
|
||||||
@ -118,9 +136,16 @@ public class DataScopeAspect
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 数据权限为仅本人且没有userAlias别名不查询任何数据
|
// 数据权限为仅本人且没有userAlias别名不查询任何数据
|
||||||
sqlString.append(" OR 1=0 ");
|
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()))
|
if (StringUtils.isNotBlank(sqlString.toString()))
|
||||||
|
|||||||
@ -4,25 +4,28 @@ import java.util.Collection;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.AfterReturning;
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
import org.aspectj.lang.annotation.AfterThrowing;
|
import org.aspectj.lang.annotation.AfterThrowing;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.core.NamedThreadLocal;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.servlet.HandlerMapping;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
import com.ruoyi.common.enums.BusinessStatus;
|
import com.ruoyi.common.enums.BusinessStatus;
|
||||||
import com.ruoyi.common.enums.HttpMethod;
|
import com.ruoyi.common.enums.HttpMethod;
|
||||||
|
import com.ruoyi.common.filter.PropertyPreExcludeFilter;
|
||||||
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.ServletUtils;
|
import com.ruoyi.common.utils.ServletUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.ip.IpUtils;
|
import com.ruoyi.common.utils.ip.IpUtils;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
|
||||||
import com.ruoyi.framework.manager.AsyncManager;
|
import com.ruoyi.framework.manager.AsyncManager;
|
||||||
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
||||||
import com.ruoyi.system.domain.SysOperLog;
|
import com.ruoyi.system.domain.SysOperLog;
|
||||||
@ -38,6 +41,21 @@ public class LogAspect
|
|||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
|
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");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理请求前执行
|
||||||
|
*/
|
||||||
|
@Before(value = "@annotation(controllerLog)")
|
||||||
|
public void boBefore(JoinPoint joinPoint, Log controllerLog)
|
||||||
|
{
|
||||||
|
TIME_THREADLOCAL.set(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理完请求后执行
|
* 处理完请求后执行
|
||||||
*
|
*
|
||||||
@ -65,7 +83,6 @@ public class LogAspect
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
// 获取当前的用户
|
// 获取当前的用户
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
|
|
||||||
@ -73,9 +90,9 @@ public class LogAspect
|
|||||||
SysOperLog operLog = new SysOperLog();
|
SysOperLog operLog = new SysOperLog();
|
||||||
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
||||||
// 请求的地址
|
// 请求的地址
|
||||||
String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
|
String ip = IpUtils.getIpAddr();
|
||||||
operLog.setOperIp(ip);
|
operLog.setOperIp(ip);
|
||||||
operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
|
operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
|
||||||
if (loginUser != null)
|
if (loginUser != null)
|
||||||
{
|
{
|
||||||
operLog.setOperName(loginUser.getUsername());
|
operLog.setOperName(loginUser.getUsername());
|
||||||
@ -94,16 +111,21 @@ public class LogAspect
|
|||||||
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
||||||
// 处理设置注解上的参数
|
// 处理设置注解上的参数
|
||||||
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
||||||
|
// 设置消耗时间
|
||||||
|
operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
|
||||||
// 保存数据库
|
// 保存数据库
|
||||||
AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
|
AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
|
||||||
}
|
}
|
||||||
catch (Exception exp)
|
catch (Exception exp)
|
||||||
{
|
{
|
||||||
// 记录本地异常日志
|
// 记录本地异常日志
|
||||||
log.error("==前置通知异常==");
|
|
||||||
log.error("异常信息:{}", exp.getMessage());
|
log.error("异常信息:{}", exp.getMessage());
|
||||||
exp.printStackTrace();
|
exp.printStackTrace();
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
TIME_THREADLOCAL.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,7 +147,7 @@ public class LogAspect
|
|||||||
if (log.isSaveRequestData())
|
if (log.isSaveRequestData())
|
||||||
{
|
{
|
||||||
// 获取参数的信息,传入到数据库中。
|
// 获取参数的信息,传入到数据库中。
|
||||||
setRequestValue(joinPoint, operLog);
|
setRequestValue(joinPoint, operLog, log.excludeParamNames());
|
||||||
}
|
}
|
||||||
// 是否需要保存response,参数和值
|
// 是否需要保存response,参数和值
|
||||||
if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult))
|
if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult))
|
||||||
@ -140,25 +162,26 @@ public class LogAspect
|
|||||||
* @param operLog 操作日志
|
* @param operLog 操作日志
|
||||||
* @throws Exception 异常
|
* @throws Exception 异常
|
||||||
*/
|
*/
|
||||||
private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception
|
private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog, String[] excludeParamNames) throws Exception
|
||||||
{
|
{
|
||||||
|
Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
||||||
String requestMethod = operLog.getRequestMethod();
|
String requestMethod = operLog.getRequestMethod();
|
||||||
if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))
|
if (StringUtils.isEmpty(paramsMap)
|
||||||
|
&& (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)))
|
||||||
{
|
{
|
||||||
String params = argsArrayToString(joinPoint.getArgs());
|
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
|
||||||
operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
|
operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter(excludeParamNames)), 0, 2000));
|
||||||
operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数拼装
|
* 参数拼装
|
||||||
*/
|
*/
|
||||||
private String argsArrayToString(Object[] paramsArray)
|
private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames)
|
||||||
{
|
{
|
||||||
String params = "";
|
String params = "";
|
||||||
if (paramsArray != null && paramsArray.length > 0)
|
if (paramsArray != null && paramsArray.length > 0)
|
||||||
@ -169,7 +192,7 @@ public class LogAspect
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object jsonObj = JSON.toJSON(o);
|
String jsonObj = JSON.toJSONString(o, excludePropertyPreFilter(excludeParamNames));
|
||||||
params += jsonObj.toString() + " ";
|
params += jsonObj.toString() + " ";
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -181,6 +204,14 @@ public class LogAspect
|
|||||||
return params.trim();
|
return params.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 忽略敏感属性
|
||||||
|
*/
|
||||||
|
public PropertyPreExcludeFilter excludePropertyPreFilter(String[] excludeParamNames)
|
||||||
|
{
|
||||||
|
return new PropertyPreExcludeFilter().addExcludes(ArrayUtils.addAll(EXCLUDE_PROPERTIES, excludeParamNames));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否需要过滤的对象。
|
* 判断是否需要过滤的对象。
|
||||||
*
|
*
|
||||||
|
|||||||
@ -16,7 +16,6 @@ import org.springframework.stereotype.Component;
|
|||||||
import com.ruoyi.common.annotation.RateLimiter;
|
import com.ruoyi.common.annotation.RateLimiter;
|
||||||
import com.ruoyi.common.enums.LimitType;
|
import com.ruoyi.common.enums.LimitType;
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.ServletUtils;
|
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.ip.IpUtils;
|
import com.ruoyi.common.utils.ip.IpUtils;
|
||||||
|
|
||||||
@ -50,7 +49,6 @@ public class RateLimiterAspect
|
|||||||
@Before("@annotation(rateLimiter)")
|
@Before("@annotation(rateLimiter)")
|
||||||
public void doBefore(JoinPoint point, RateLimiter rateLimiter) throws Throwable
|
public void doBefore(JoinPoint point, RateLimiter rateLimiter) throws Throwable
|
||||||
{
|
{
|
||||||
String key = rateLimiter.key();
|
|
||||||
int time = rateLimiter.time();
|
int time = rateLimiter.time();
|
||||||
int count = rateLimiter.count();
|
int count = rateLimiter.count();
|
||||||
|
|
||||||
@ -63,7 +61,7 @@ public class RateLimiterAspect
|
|||||||
{
|
{
|
||||||
throw new ServiceException("访问过于频繁,请稍候再试");
|
throw new ServiceException("访问过于频繁,请稍候再试");
|
||||||
}
|
}
|
||||||
log.info("限制请求'{}',当前请求'{}',缓存key'{}'", count, number.intValue(), key);
|
log.info("限制请求'{}',当前请求'{}',缓存key'{}'", count, number.intValue(), combineKey);
|
||||||
}
|
}
|
||||||
catch (ServiceException e)
|
catch (ServiceException e)
|
||||||
{
|
{
|
||||||
@ -80,7 +78,7 @@ public class RateLimiterAspect
|
|||||||
StringBuffer stringBuffer = new StringBuffer(rateLimiter.key());
|
StringBuffer stringBuffer = new StringBuffer(rateLimiter.key());
|
||||||
if (rateLimiter.limitType() == LimitType.IP)
|
if (rateLimiter.limitType() == LimitType.IP)
|
||||||
{
|
{
|
||||||
stringBuffer.append(IpUtils.getIpAddr(ServletUtils.getRequest())).append("-");
|
stringBuffer.append(IpUtils.getIpAddr()).append("-");
|
||||||
}
|
}
|
||||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||||
Method method = signature.getMethod();
|
Method method = signature.getMethod();
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
package com.ruoyi.framework.config;
|
package com.ruoyi.framework.config;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import java.nio.charset.Charset;
|
||||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
||||||
import com.fasterxml.jackson.databind.JavaType;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
||||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
import org.springframework.data.redis.serializer.SerializationException;
|
import org.springframework.data.redis.serializer.SerializationException;
|
||||||
import com.alibaba.fastjson.parser.ParserConfig;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import org.springframework.util.Assert;
|
import com.alibaba.fastjson2.JSONReader;
|
||||||
import java.nio.charset.Charset;
|
import com.alibaba.fastjson2.JSONWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redis使用FastJson序列化
|
* Redis使用FastJson序列化
|
||||||
@ -18,18 +14,10 @@ import java.nio.charset.Charset;
|
|||||||
*/
|
*/
|
||||||
public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
||||||
{
|
{
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||||
|
|
||||||
private Class<T> clazz;
|
private Class<T> clazz;
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FastJson2JsonRedisSerializer(Class<T> clazz)
|
public FastJson2JsonRedisSerializer(Class<T> clazz)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
@ -43,7 +31,7 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
|||||||
{
|
{
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);
|
return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,17 +43,6 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
|
|||||||
}
|
}
|
||||||
String str = new String(bytes, DEFAULT_CHARSET);
|
String str = new String(bytes, DEFAULT_CHARSET);
|
||||||
|
|
||||||
return JSON.parseObject(str, clazz);
|
return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType);
|
||||||
}
|
|
||||||
|
|
||||||
public void setObjectMapper(ObjectMapper objectMapper)
|
|
||||||
{
|
|
||||||
Assert.notNull(objectMapper, "'objectMapper' must not be null");
|
|
||||||
this.objectMapper = objectMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JavaType getJavaType(Class<?> clazz)
|
|
||||||
{
|
|
||||||
return TypeFactory.defaultInstance().constructType(clazz);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.google.code.kaptcha.text.impl.DefaultTextCreator;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码文本生成器
|
* 验证码文本生成器
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class KaptchaTextCreator extends DefaultTextCreator
|
public class KaptchaTextCreator extends DefaultTextCreator
|
||||||
@ -20,7 +20,7 @@ public class KaptchaTextCreator extends DefaultTextCreator
|
|||||||
int x = random.nextInt(10);
|
int x = random.nextInt(10);
|
||||||
int y = random.nextInt(10);
|
int y = random.nextInt(10);
|
||||||
StringBuilder suChinese = new StringBuilder();
|
StringBuilder suChinese = new StringBuilder();
|
||||||
int randomoperands = (int) Math.round(Math.random() * 2);
|
int randomoperands = random.nextInt(3);
|
||||||
if (randomoperands == 0)
|
if (randomoperands == 0)
|
||||||
{
|
{
|
||||||
result = x * y;
|
result = x * y;
|
||||||
@ -30,7 +30,7 @@ public class KaptchaTextCreator extends DefaultTextCreator
|
|||||||
}
|
}
|
||||||
else if (randomoperands == 1)
|
else if (randomoperands == 1)
|
||||||
{
|
{
|
||||||
if (!(x == 0) && y % x == 0)
|
if ((x != 0) && y % x == 0)
|
||||||
{
|
{
|
||||||
result = y / x;
|
result = y / x;
|
||||||
suChinese.append(CNUMBERS[y]);
|
suChinese.append(CNUMBERS[y]);
|
||||||
@ -45,7 +45,7 @@ public class KaptchaTextCreator extends DefaultTextCreator
|
|||||||
suChinese.append(CNUMBERS[y]);
|
suChinese.append(CNUMBERS[y]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (randomoperands == 2)
|
else
|
||||||
{
|
{
|
||||||
if (x >= y)
|
if (x >= y)
|
||||||
{
|
{
|
||||||
@ -62,13 +62,6 @@ public class KaptchaTextCreator extends DefaultTextCreator
|
|||||||
suChinese.append(CNUMBERS[x]);
|
suChinese.append(CNUMBERS[x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
result = x + y;
|
|
||||||
suChinese.append(CNUMBERS[x]);
|
|
||||||
suChinese.append("+");
|
|
||||||
suChinese.append(CNUMBERS[y]);
|
|
||||||
}
|
|
||||||
suChinese.append("=?@" + result);
|
suChinese.append("=?@" + result);
|
||||||
return suChinese.toString();
|
return suChinese.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,11 +8,6 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
||||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* redis配置
|
* redis配置
|
||||||
@ -32,11 +27,6 @@ public class RedisConfig extends CachingConfigurerSupport
|
|||||||
|
|
||||||
FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
|
FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
|
||||||
mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
|
||||||
serializer.setObjectMapper(mapper);
|
|
||||||
|
|
||||||
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||||
template.setKeySerializer(new StringRedisSerializer());
|
template.setKeySerializer(new StringRedisSerializer());
|
||||||
template.setValueSerializer(serializer);
|
template.setValueSerializer(serializer);
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
package com.ruoyi.framework.config;
|
package com.ruoyi.framework.config;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.CacheControl;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
import org.springframework.web.filter.CorsFilter;
|
import org.springframework.web.filter.CorsFilter;
|
||||||
@ -33,7 +35,8 @@ public class ResourcesConfig implements WebMvcConfigurer
|
|||||||
|
|
||||||
/** swagger配置 */
|
/** swagger配置 */
|
||||||
registry.addResourceHandler("/swagger-ui/**")
|
registry.addResourceHandler("/swagger-ui/**")
|
||||||
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
|
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
|
||||||
|
.setCacheControl(CacheControl.maxAge(5, TimeUnit.HOURS).cachePublic());;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -8,12 +8,14 @@ import org.springframework.security.config.annotation.authentication.builders.Au
|
|||||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
|
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
||||||
import org.springframework.web.filter.CorsFilter;
|
import org.springframework.web.filter.CorsFilter;
|
||||||
|
import com.ruoyi.framework.config.properties.PermitAllUrlProperties;
|
||||||
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
|
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
|
||||||
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
|
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
|
||||||
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
|
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
|
||||||
@ -55,7 +57,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private CorsFilter corsFilter;
|
private CorsFilter corsFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许匿名访问的地址
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private PermitAllUrlProperties permitAllUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解决 无法直接注入 AuthenticationManager
|
* 解决 无法直接注入 AuthenticationManager
|
||||||
*
|
*
|
||||||
@ -87,9 +95,15 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity httpSecurity) throws Exception
|
protected void configure(HttpSecurity httpSecurity) throws Exception
|
||||||
{
|
{
|
||||||
|
// 注解标记允许匿名访问的url
|
||||||
|
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = httpSecurity.authorizeRequests();
|
||||||
|
permitAllUrl.getUrls().forEach(url -> registry.antMatchers(url).permitAll());
|
||||||
|
|
||||||
httpSecurity
|
httpSecurity
|
||||||
// CSRF禁用,因为不使用session
|
// CSRF禁用,因为不使用session
|
||||||
.csrf().disable()
|
.csrf().disable()
|
||||||
|
// 禁用HTTP响应标头
|
||||||
|
.headers().cacheControl().disable().and()
|
||||||
// 认证失败处理类
|
// 认证失败处理类
|
||||||
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
|
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
|
||||||
// 基于token,所以不需要session
|
// 基于token,所以不需要session
|
||||||
@ -97,25 +111,15 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|||||||
// 过滤请求
|
// 过滤请求
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
|
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
|
||||||
.antMatchers("/login", "/register", "/captchaImage").anonymous()
|
.antMatchers("/login", "/register", "/captchaImage").permitAll()
|
||||||
.antMatchers(
|
// 静态资源,可匿名访问
|
||||||
HttpMethod.GET,
|
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
|
||||||
"/",
|
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
|
||||||
"/*.html",
|
|
||||||
"/**/*.html",
|
|
||||||
"/**/*.css",
|
|
||||||
"/**/*.js",
|
|
||||||
"/profile/**"
|
|
||||||
).permitAll()
|
|
||||||
.antMatchers("/swagger-ui.html").anonymous()
|
|
||||||
.antMatchers("/swagger-resources/**").anonymous()
|
|
||||||
.antMatchers("/webjars/**").anonymous()
|
|
||||||
.antMatchers("/*/api-docs").anonymous()
|
|
||||||
.antMatchers("/druid/**").anonymous()
|
|
||||||
// 除上面外的所有请求全部需要鉴权认证
|
// 除上面外的所有请求全部需要鉴权认证
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
.headers().frameOptions().disable();
|
.headers().frameOptions().disable();
|
||||||
|
// 添加Logout filter
|
||||||
httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);
|
httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);
|
||||||
// 添加JWT filter
|
// 添加JWT filter
|
||||||
httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
|
httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
package com.ruoyi.framework.config;
|
package com.ruoyi.framework.config;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import com.ruoyi.common.utils.Threads;
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import com.ruoyi.common.utils.Threads;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 线程池配置
|
* 线程池配置
|
||||||
@ -49,7 +49,8 @@ public class ThreadPoolConfig
|
|||||||
protected ScheduledExecutorService scheduledExecutorService()
|
protected ScheduledExecutorService scheduledExecutorService()
|
||||||
{
|
{
|
||||||
return new ScheduledThreadPoolExecutor(corePoolSize,
|
return new ScheduledThreadPoolExecutor(corePoolSize,
|
||||||
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build())
|
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build(),
|
||||||
|
new ThreadPoolExecutor.CallerRunsPolicy())
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected void afterExecute(Runnable r, Throwable t)
|
protected void afterExecute(Runnable r, Throwable t)
|
||||||
|
|||||||
@ -24,6 +24,12 @@ public class DruidProperties
|
|||||||
@Value("${spring.datasource.druid.maxWait}")
|
@Value("${spring.datasource.druid.maxWait}")
|
||||||
private int maxWait;
|
private int maxWait;
|
||||||
|
|
||||||
|
@Value("${spring.datasource.druid.connectTimeout}")
|
||||||
|
private int connectTimeout;
|
||||||
|
|
||||||
|
@Value("${spring.datasource.druid.socketTimeout}")
|
||||||
|
private int socketTimeout;
|
||||||
|
|
||||||
@Value("${spring.datasource.druid.timeBetweenEvictionRunsMillis}")
|
@Value("${spring.datasource.druid.timeBetweenEvictionRunsMillis}")
|
||||||
private int timeBetweenEvictionRunsMillis;
|
private int timeBetweenEvictionRunsMillis;
|
||||||
|
|
||||||
@ -54,6 +60,12 @@ public class DruidProperties
|
|||||||
|
|
||||||
/** 配置获取连接等待超时的时间 */
|
/** 配置获取连接等待超时的时间 */
|
||||||
datasource.setMaxWait(maxWait);
|
datasource.setMaxWait(maxWait);
|
||||||
|
|
||||||
|
/** 配置驱动连接超时时间,检测数据库建立连接的超时时间,单位是毫秒 */
|
||||||
|
datasource.setConnectTimeout(connectTimeout);
|
||||||
|
|
||||||
|
/** 配置网络超时时间,等待数据库操作完成的网络超时时间,单位是毫秒 */
|
||||||
|
datasource.setSocketTimeout(socketTimeout);
|
||||||
|
|
||||||
/** 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 */
|
/** 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 */
|
||||||
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
|
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
|
||||||
|
|||||||
@ -0,0 +1,73 @@
|
|||||||
|
package com.ruoyi.framework.config.properties;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import org.apache.commons.lang3.RegExUtils;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||||
|
import com.ruoyi.common.annotation.Anonymous;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置Anonymous注解允许匿名访问的url
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class PermitAllUrlProperties implements InitializingBean, ApplicationContextAware
|
||||||
|
{
|
||||||
|
private static final Pattern PATTERN = Pattern.compile("\\{(.*?)\\}");
|
||||||
|
|
||||||
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
private List<String> urls = new ArrayList<>();
|
||||||
|
|
||||||
|
public String ASTERISK = "*";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet()
|
||||||
|
{
|
||||||
|
RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
|
||||||
|
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
|
||||||
|
|
||||||
|
map.keySet().forEach(info -> {
|
||||||
|
HandlerMethod handlerMethod = map.get(info);
|
||||||
|
|
||||||
|
// 获取方法上边的注解 替代path variable 为 *
|
||||||
|
Anonymous method = AnnotationUtils.findAnnotation(handlerMethod.getMethod(), Anonymous.class);
|
||||||
|
Optional.ofNullable(method).ifPresent(anonymous -> Objects.requireNonNull(info.getPatternsCondition().getPatterns())
|
||||||
|
.forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK))));
|
||||||
|
|
||||||
|
// 获取类上边的注解, 替代path variable 为 *
|
||||||
|
Anonymous controller = AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), Anonymous.class);
|
||||||
|
Optional.ofNullable(controller).ifPresent(anonymous -> Objects.requireNonNull(info.getPatternsCondition().getPatterns())
|
||||||
|
.forEach(url -> urls.add(RegExUtils.replaceAll(url, PATTERN, ASTERISK))));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext context) throws BeansException
|
||||||
|
{
|
||||||
|
this.applicationContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getUrls()
|
||||||
|
{
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrls(List<String> urls)
|
||||||
|
{
|
||||||
|
this.urls = urls;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -14,7 +14,7 @@ public class DynamicDataSourceContextHolder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用ThreadLocal维护变量,ThreadLocal为每个使用该变量的线程提供独立的变量副本,
|
* 使用ThreadLocal维护变量,ThreadLocal为每个使用该变量的线程提供独立的变量副本,
|
||||||
* 所以每一个线程都可以独立地改变自己的副本,而不会影响其它线程所对应的副本。
|
* 所以每一个线程都可以独立地改变自己的副本,而不会影响其它线程所对应的副本。
|
||||||
*/
|
*/
|
||||||
private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();
|
private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user