mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-25 05:50:19 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3fee1bf3e | ||
|
|
d1009704d8 | ||
|
|
4d00bb9d21 | ||
|
|
1dff8eb945 | ||
|
|
8eef4717cc | ||
|
|
1de437dc5a | ||
|
|
8f1885f56e | ||
|
|
eeac49157f | ||
|
|
ffc19c7fbf | ||
|
|
e03f0cc4b0 | ||
|
|
70044a88a0 | ||
|
|
4a279ffa29 | ||
|
|
979c9c193f | ||
|
|
f603ebb09f | ||
|
|
7d93bc7256 | ||
|
|
89fa2c1061 | ||
|
|
5a0aa6422f | ||
|
|
b59f068c7d | ||
|
|
ad6311d244 | ||
|
|
645d6799b2 | ||
|
|
758c1f8306 | ||
|
|
905297907a | ||
|
|
6fb241af4b | ||
|
|
0cf29d7488 | ||
|
|
615aa3ad23 | ||
|
|
c756d26592 | ||
|
|
0f45d3830a | ||
|
|
c37ea861eb | ||
|
|
aaa53d9a35 | ||
|
|
3d59181d2a | ||
|
|
ef11b6caa7 | ||
|
|
563a1fc1a4 | ||
|
|
5625444fbc | ||
|
|
169205f132 | ||
|
|
447d824da6 | ||
|
|
c3ad90dde5 | ||
|
|
f218695bef | ||
|
|
9b758084bf | ||
|
|
8159aa1a88 | ||
|
|
18cf39529e | ||
|
|
a54e7a5654 | ||
|
|
4392f0ffac | ||
|
|
732cd54578 | ||
|
|
0de1fe1132 | ||
|
|
3e85645e44 | ||
|
|
39fdc43ada | ||
|
|
acda4470bc | ||
|
|
0fb3d16c49 | ||
|
|
228882d8c4 | ||
|
|
186aa89476 | ||
|
|
f9296d90d4 | ||
|
|
258c2afa32 | ||
|
|
105adfe7e9 | ||
|
|
d2104fade2 | ||
|
|
739eed6a01 | ||
|
|
bffe222e1b | ||
|
|
ceb5b9e4d6 | ||
|
|
e49bd514f7 | ||
|
|
39fb8b7c5d | ||
|
|
2b0a565120 | ||
|
|
2399c97c51 | ||
|
|
eb1911232b | ||
|
|
0fe70c5e1c | ||
|
|
483da629e9 | ||
|
|
129f4e6281 | ||
|
|
683355d773 | ||
|
|
cb28f6f438 | ||
|
|
c9f2301335 | ||
|
|
751a10d91e | ||
|
|
7c821bf673 | ||
|
|
be2b584cee | ||
|
|
f39048fad0 | ||
|
|
4e9ce0de7e | ||
|
|
6e78abb34e | ||
|
|
ae5ec006ba | ||
|
|
c9d1e424e9 | ||
|
|
f48f39e024 | ||
|
|
3dde9cfdc6 | ||
|
|
85d6e954ae | ||
|
|
146b0b2925 | ||
|
|
4faa807c53 | ||
|
|
ea998db824 | ||
|
|
7334ad9f33 | ||
|
|
f32d725773 | ||
|
|
fb9bec8623 | ||
|
|
b7847e6198 | ||
|
|
4307abf274 | ||
|
|
8206e5cbad | ||
|
|
73cc49448e | ||
|
|
a2f4d58648 | ||
|
|
5b290ef0b1 | ||
|
|
b9a9c5d917 | ||
|
|
3112f0afe8 | ||
|
|
0a3696ee01 | ||
|
|
03431dee58 | ||
|
|
8f33b3de5e | ||
|
|
9e0f95ec48 | ||
|
|
7668e7fdde | ||
|
|
0df2b3ea1c | ||
|
|
4f726f1eb8 | ||
|
|
752e9f917e | ||
|
|
a4493021e2 | ||
|
|
13d823ec57 | ||
|
|
a6736e6e30 | ||
|
|
9b26947849 | ||
|
|
0af29cfcae | ||
|
|
c63904aedf | ||
|
|
076538a6b6 | ||
|
|
8deefff08a | ||
|
|
1cae92b119 | ||
|
|
b5dbde8ad1 | ||
|
|
45d552ac8c | ||
|
|
bdce16a582 | ||
|
|
7bf3294113 | ||
|
|
26dbd1446c | ||
|
|
74796f3546 | ||
|
|
48bb3b6452 | ||
|
|
c4ec7f562a | ||
|
|
733874316a | ||
|
|
b5efcd251a | ||
|
|
b74ea58172 | ||
|
|
707dbac2ca | ||
|
|
184b1a903f | ||
|
|
4a995a1c56 | ||
|
|
e6768d5e17 | ||
|
|
e3057c4bd9 | ||
|
|
87f101a7bf | ||
|
|
ab435d131c | ||
|
|
674ae4c4a0 | ||
|
|
f3a84e2ca8 | ||
|
|
835dd15c47 | ||
|
|
c983370162 | ||
|
|
00b5024f20 | ||
|
|
ae0af55d17 | ||
|
|
f19b398c93 | ||
|
|
8743b63869 | ||
|
|
4af1627116 | ||
|
|
5d4c4d53fc | ||
|
|
62bc8092e2 | ||
|
|
4cea6f9f5d | ||
|
|
decee13bf1 | ||
|
|
60bfe48307 | ||
|
|
bca54282c9 | ||
|
|
db933cecb6 | ||
|
|
3f06c8ba7d | ||
|
|
f7fb34ec16 | ||
|
|
b691d53523 | ||
|
|
5396aa40cb | ||
|
|
1a43b89674 | ||
|
|
fb570acf7c | ||
|
|
8c5d0ad64b | ||
|
|
74a92b08d8 | ||
|
|
3e6a3d97bb | ||
|
|
b3e4666108 | ||
|
|
a344f2bdb7 | ||
|
|
4b6eb80ddb | ||
|
|
5226a2a26f | ||
|
|
e8bb532cdc | ||
|
|
171be652eb | ||
|
|
c410125c8f | ||
|
|
0f6613c4a1 | ||
|
|
d278344dd4 | ||
|
|
c47b3eee2c | ||
|
|
162b8df569 | ||
|
|
55e2109091 | ||
|
|
11efbe7699 | ||
|
|
329d094e2a | ||
|
|
414766001b | ||
|
|
e05e16dce4 | ||
|
|
3549f4cf1f | ||
|
|
bedbd3c872 | ||
|
|
296110f969 | ||
|
|
f60b0f1750 | ||
|
|
6ad13c5930 | ||
|
|
6a1b53e3d4 | ||
|
|
21ef7bdcc0 | ||
|
|
718574cdf3 | ||
|
|
18571ca224 | ||
|
|
41c164a8ef | ||
|
|
f82acdb478 | ||
|
|
40b56b6bf5 | ||
|
|
f259d69910 | ||
|
|
3952d5ec14 | ||
|
|
c1745f6f40 | ||
|
|
0940a70d86 | ||
|
|
7abe6987a5 | ||
|
|
7baa2c84a3 | ||
|
|
6867eb2c05 | ||
|
|
3d01706fb6 | ||
|
|
7707d4c99d | ||
|
|
b66d7a4e7a | ||
|
|
8a67795faf | ||
|
|
64299e6912 | ||
|
|
fdd522e56a | ||
|
|
1c257fa830 | ||
|
|
3d9fbbac63 | ||
|
|
f83332b2c8 | ||
|
|
b8d187bb35 | ||
|
|
9567564bf4 | ||
|
|
d05bf07db8 | ||
|
|
5adb89694b | ||
|
|
e21146d048 | ||
|
|
4c7f04536d | ||
|
|
71d0883c3d | ||
|
|
ee9022f9e3 | ||
|
|
cc0a894162 | ||
|
|
d27f2ec966 | ||
|
|
83b7927c4b | ||
|
|
e1975682a9 | ||
|
|
f914f96b9a | ||
|
|
35a21d4e24 | ||
|
|
3e58190112 | ||
|
|
39150b2b2b | ||
|
|
f2b287f933 | ||
|
|
e458e583ee | ||
|
|
74c1fd5b7d | ||
|
|
2547ba88ae | ||
|
|
5c78ecc2d3 | ||
|
|
9c934917d0 | ||
|
|
1132723355 | ||
|
|
26261001f5 | ||
|
|
2e3a1582ab | ||
|
|
5d1bcb3575 | ||
|
|
6c7d49b323 | ||
|
|
843a585b7f | ||
|
|
8df6fa6a33 | ||
|
|
9ccb5439df | ||
|
|
928d816c68 | ||
|
|
27df9862ea | ||
|
|
d428ed6876 | ||
|
|
72fd7beec0 | ||
|
|
7613b85271 | ||
|
|
23eac98551 | ||
|
|
8bd245b1f1 | ||
|
|
b13bbfced1 | ||
|
|
645c788512 | ||
|
|
9f6c8f5e22 | ||
|
|
9a4667fa46 | ||
|
|
338d81e101 | ||
|
|
336d7473f7 | ||
|
|
265cd4d885 | ||
|
|
cab8de721f | ||
|
|
4030cd325c | ||
|
|
d796a39aa7 | ||
|
|
04d8303f28 | ||
|
|
5eec28a964 | ||
|
|
a5e5c588ba | ||
|
|
34e6ccc6e2 | ||
|
|
6a028e13cb | ||
|
|
176e9d09b6 | ||
|
|
7ddcf97efd | ||
|
|
e19bda949b | ||
|
|
b09d142091 | ||
|
|
e102f820c1 | ||
|
|
36627e4ca5 | ||
|
|
9c6e6ca1b2 | ||
|
|
f32fdbf543 | ||
|
|
7342788339 | ||
|
|
15d6ff0144 | ||
|
|
9718b16e39 | ||
|
|
e80842207f | ||
|
|
58585afdf6 | ||
|
|
a3eee91cef | ||
|
|
9098eaf22e | ||
|
|
2d3b039f71 | ||
|
|
864c468440 | ||
|
|
cc295fad32 | ||
|
|
b4e0dc800d | ||
|
|
5e7078e3a6 | ||
|
|
2829d7b653 | ||
|
|
ba834592a7 | ||
|
|
1607e6a0a9 | ||
|
|
f936029d59 | ||
|
|
9f1552f508 | ||
|
|
c00d465709 | ||
|
|
c2a55931bb | ||
|
|
e957e5ebc9 | ||
|
|
1357e22330 | ||
|
|
8a282cd743 | ||
|
|
6ca7f62ce6 | ||
|
|
6ee7ad8069 | ||
|
|
307b1bf496 | ||
|
|
61f50980e1 | ||
|
|
5293222ac0 | ||
|
|
411a21d0f7 | ||
|
|
8a5d788e73 | ||
|
|
3e48fa55c7 | ||
|
|
cd735e727e | ||
|
|
1eb69c696a | ||
|
|
8208ccf5a3 | ||
|
|
1591944756 | ||
|
|
8e87ae55a9 | ||
|
|
85fce8f01e | ||
|
|
7475bc56c9 | ||
|
|
7af2dffb7a | ||
|
|
15f2d149df | ||
|
|
c09924dbdc | ||
|
|
1ddd6dac4f | ||
|
|
b45afe9669 | ||
|
|
1e85e03713 | ||
|
|
43eef673bc | ||
|
|
41ce276dbd | ||
|
|
d6e078f3d6 | ||
|
|
a487266f5b | ||
|
|
0286d56e9c | ||
|
|
4c2f43b4cf | ||
|
|
9bbcb62505 | ||
|
|
5bb840c1ce | ||
|
|
8f221b6b0b | ||
|
|
ac4398873b | ||
|
|
2fad9035d3 | ||
|
|
ef03c95f40 | ||
|
|
eb7a6411d1 | ||
|
|
e02e70ff26 | ||
|
|
b6843e04d5 | ||
|
|
5e4c82b94a | ||
|
|
1f411ec6e0 | ||
|
|
a890bd2d38 | ||
|
|
7a47f59945 | ||
|
|
830c2cf29b | ||
|
|
86593943d3 | ||
|
|
7c188fa7ce | ||
|
|
a9432b5d9c | ||
|
|
0bebb7f65b | ||
|
|
6536caed75 | ||
|
|
4863b2c5be | ||
|
|
86afc0ddf4 | ||
|
|
bf6f469dad | ||
|
|
68677e1b5b | ||
|
|
f4709f00ab | ||
|
|
8392398b1c | ||
|
|
b4355b4399 | ||
|
|
b12bbc74ff | ||
|
|
d3dbca0e00 | ||
|
|
81e0e4dde7 | ||
|
|
fba9ab0ae6 | ||
|
|
e18518b4d3 | ||
|
|
074a7145d2 | ||
|
|
46372f0e6c | ||
|
|
1acd2e3238 | ||
|
|
a2e7827aa8 | ||
|
|
ac71aafe83 | ||
|
|
0b1cc913d9 | ||
|
|
84b967ae82 | ||
|
|
cf9002a377 | ||
|
|
829fa4dac5 | ||
|
|
5529d5f46d | ||
|
|
08e9c6b38a | ||
|
|
5c94c73004 | ||
|
|
8ebb1fda77 | ||
|
|
96380bd031 | ||
|
|
c342e63e63 | ||
|
|
4fa43c232d | ||
|
|
d07cbc8783 | ||
|
|
f7667ad3e1 | ||
|
|
5fe66b7abc | ||
|
|
856c09c38d | ||
|
|
b947f043ee | ||
|
|
ebd515f057 | ||
|
|
636faaf93b | ||
|
|
ed1c6c7a47 | ||
|
|
e4340641ad | ||
|
|
35738cfda8 | ||
|
|
e749adaa10 | ||
|
|
26a1a89d60 | ||
|
|
2daa65f00d | ||
|
|
d2579d390c | ||
|
|
261e34a5c2 | ||
|
|
b4bad21e35 | ||
|
|
699f53e8b2 | ||
|
|
820c9f733f | ||
|
|
99bd217080 | ||
|
|
c86c05f380 | ||
|
|
544901bf45 | ||
|
|
8db0e2fb06 | ||
|
|
c5ed47192e | ||
|
|
3d56cb7eb2 | ||
|
|
ada8818960 | ||
|
|
2f97f4b979 | ||
|
|
0a4e81138a | ||
|
|
c61350643a | ||
|
|
9f59275652 | ||
|
|
1da644b96a | ||
|
|
1de825ee43 | ||
|
|
2e18f3f5e1 | ||
|
|
653f73b989 | ||
|
|
9c5b9729d8 | ||
|
|
6950e493f2 | ||
|
|
286f0b74da | ||
|
|
a1191abc43 | ||
|
|
75799b81e8 | ||
|
|
511a187f49 | ||
|
|
01ecfcdf8d | ||
|
|
14a55fcb83 | ||
|
|
49c146b3dc | ||
|
|
e2c5988bea | ||
|
|
4828dc3dae | ||
|
|
8413f0e8d3 | ||
|
|
3d2e9ef063 | ||
|
|
28c7d178c4 | ||
|
|
5bfc5563b3 | ||
|
|
d6bc0572c2 | ||
|
|
32abd69c16 | ||
|
|
024f461e94 | ||
|
|
a25823f5b5 | ||
|
|
4d4d8e4955 | ||
|
|
7488db81c1 | ||
|
|
e8c6d388f2 | ||
|
|
02f155f497 | ||
|
|
c570c095b9 | ||
|
|
10d8d7f28a | ||
|
|
0e1a820c3a | ||
|
|
bf21fec50e | ||
|
|
4e514dc83e | ||
|
|
3f52783b30 | ||
|
|
16bab848e1 | ||
|
|
986406a880 | ||
|
|
2946c8ce34 | ||
|
|
fef12cb747 | ||
|
|
b710f6a5df | ||
|
|
840723c592 | ||
|
|
6f63290e74 | ||
|
|
4d8d4b77c1 | ||
|
|
10b009bb7e | ||
|
|
7cb172d60a | ||
|
|
8350dfe2c9 | ||
|
|
970b2d21a9 | ||
|
|
e9c5ac6ec0 | ||
|
|
f7804b627e | ||
|
|
247487529b | ||
|
|
5ef5af4723 | ||
|
|
2188f79e77 | ||
|
|
a7bb4a7ac4 | ||
|
|
06c67c1024 | ||
|
|
03024f192a | ||
|
|
b1baccf0a5 | ||
|
|
ad047f4c06 | ||
|
|
dc1cc2ec10 | ||
|
|
6f589d7af9 | ||
|
|
eeaaa40259 | ||
|
|
e394a3afdf | ||
|
|
45cc0aec93 | ||
|
|
0bd80ad900 | ||
|
|
1214241dab | ||
|
|
28dbad6c1f | ||
|
|
84e35753cf | ||
|
|
6a03008ac9 | ||
|
|
cc215d6ad0 | ||
|
|
e28217e5ec | ||
|
|
cebb9b3002 | ||
|
|
0d8edbbb64 | ||
|
|
4abcbeb420 | ||
|
|
77aea09d5f | ||
|
|
2baf392129 | ||
|
|
c56e0416f2 | ||
|
|
d478246edc | ||
|
|
ea375a026d | ||
|
|
9101d5bdb8 | ||
|
|
811df12524 | ||
|
|
3ee469aef3 | ||
|
|
7b503337b1 | ||
|
|
dd65a4a716 | ||
|
|
9865d53ea7 | ||
|
|
213d1a700f | ||
|
|
e18f0cae1a | ||
|
|
973da4df7e | ||
|
|
b9f7783878 |
@@ -10,6 +10,8 @@ cat>"${filename}"<<EOF
|
||||
# jwt configuration
|
||||
jwt:
|
||||
signing-key: 'qmPlus'
|
||||
expires-time: 604800
|
||||
buffer-time: 86400
|
||||
|
||||
# zap logger configuration
|
||||
zap:
|
||||
@@ -49,8 +51,6 @@ system:
|
||||
addr: 8888
|
||||
db-type: 'mysql'
|
||||
oss-type: 'local'
|
||||
config-env: 'GVA_CONFIG'
|
||||
need-init-data: true
|
||||
use-multipoint: false
|
||||
|
||||
# captcha configuration
|
||||
@@ -61,44 +61,15 @@ captcha:
|
||||
|
||||
# mysql connect configuration
|
||||
mysql:
|
||||
path: '177.7.0.13:3306'
|
||||
config: 'charset=utf8mb4&parseTime=True&loc=Local'
|
||||
db-name: 'qmPlus'
|
||||
username: 'root'
|
||||
password: 'Aa@6447985'
|
||||
path: ''
|
||||
config: ''
|
||||
db-name: ''
|
||||
username: ''
|
||||
password: ''
|
||||
max-idle-conns: 10
|
||||
max-open-conns: 10
|
||||
max-open-conns: 100
|
||||
log-mode: false
|
||||
|
||||
# sqlite connect configuration (sqlite需要gcc支持 windows用户需要自行安装gcc)
|
||||
sqlite:
|
||||
path: 'db.db'
|
||||
max-idle-conns: 10
|
||||
max-open-conns: 10
|
||||
logger: true
|
||||
|
||||
# Sqlserver connect configuration
|
||||
sqlserver:
|
||||
path: 'localhost:9930'
|
||||
db-name: 'gorm'
|
||||
username: 'gorm'
|
||||
password: 'LoremIpsum86'
|
||||
max-idle-conns: 10
|
||||
max-open-conns: 10
|
||||
logger: true
|
||||
|
||||
# Postgresql connect configuration
|
||||
postgresql:
|
||||
host: '127.0.0.1'
|
||||
port: '9920'
|
||||
config: 'sslmode=disable TimeZone=Asia/Shanghai'
|
||||
db-name: 'gorm'
|
||||
username: 'gorm'
|
||||
password: 'gorm'
|
||||
max-idle-conns: 10
|
||||
max-open-conns: 10
|
||||
prefer-simple-protocol: true
|
||||
logger: false
|
||||
log-zap: ""
|
||||
|
||||
# local configuration
|
||||
local:
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
open_collective: gin-vue-admin
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
|
||||
@@ -24,6 +24,7 @@ yarn-error.log*
|
||||
|
||||
go.sum
|
||||
/server/log/
|
||||
/server/gva
|
||||
/server/latest_log
|
||||
|
||||
*.iml
|
||||
|
||||
@@ -12,9 +12,19 @@
|
||||
|
||||
[English](./README-en.md) | 简体中文
|
||||
|
||||
[gitee地址:https://gitee.com/pixelmax/gin-vue-admin](https://gitee.com/pixelmax/gin-vue-admin)
|
||||
|
||||
[github地址:https://github.com/flipped-aurora/gin-vue-admin](https://github.com/flipped-aurora/gin-vue-admin)
|
||||
|
||||
[vue3版本分支地址:https://github.com/flipped-aurora/gin-vue-admin/tree/vue3Develop](https://github.com/flipped-aurora/gin-vue-admin/tree/vue3Develop)
|
||||
|
||||
[审批流分支:https://github.com/flipped-aurora/gin-vue-admin/tree/gva_workflow](https://github.com/flipped-aurora/gin-vue-admin/tree/gva_workflow)
|
||||
|
||||
# 项目文档
|
||||
[在线文档](https://www.gin-vue-admin.com/) : https://www.gin-vue-admin.com/
|
||||
|
||||
[从环境到部署教学视频](https://www.bilibili.com/video/BV1fV411y7dT)
|
||||
|
||||
[开发教学](https://www.gin-vue-admin.com/docs/help) (贡献者: <a href="https://github.com/LLemonGreen">LLemonGreen</a> And <a href="https://github.com/fkk0509">Fann</a>)
|
||||
- 前端UI框架:[element-ui](https://github.com/ElemeFE/element)
|
||||
- 后台框架:[gin](https://github.com/gin-gonic/gin)
|
||||
@@ -67,7 +77,7 @@ Gin-vue-admin 的成长离不开大家的支持,如果你愿意为 gin-vue-adm
|
||||
- node版本 > v8.6.0
|
||||
- golang版本 >= v1.14
|
||||
- IDE推荐:Goland
|
||||
- gormv2版本初始化数据库可以利用批量创建功能,这里已经写好初始化代码,需要在main.go内打开 initialize.Data() 的注释即可
|
||||
- 初始化项目: 不同版本数据库初始化不通 参见https://www.gin-vue-admin.com/docs/server#1-%E5%88%9D%E5%A7%8B%E5%8C%96server%E9%A1%B9%E7%9B%AE
|
||||
- 替换掉项目中的七牛云公钥,私钥,仓名和默认url地址,以免发生测试文件数据错乱
|
||||
```
|
||||
|
||||
@@ -131,6 +141,7 @@ Gin-vue-admin 的成长离不开大家的支持,如果你愿意为 gin-vue-adm
|
||||
|
||||
> <font color=red>**使用docker-compose进行部署本项目需注意的问题**</font>
|
||||
|
||||
- dockerfile_server使用了多阶段构建,这是docker 17.05后引入的,因此安装的docker版本需要高于17.05
|
||||
- mysql数据库请使用装在服务器磁盘的本地数据库.
|
||||
- 避免使用docker容器内的mysql,可能会出现写入的问题, io比宿主机低 docker的持久化机制问题
|
||||
- [init.sql](.docker-compose/docker-entrypoint-initdb.d/init.sql)是给docker-compose进行<font color=red>体验本项目</font>的, 禁止[init.sql](.docker-compose/docker-entrypoint-initdb.d/init.sql)使用进行项目数据的初始化, 数据库初始化[请使用此方法](https://www.gin-vue-admin.com/docs/help#step1%EF%BC%9A%E6%95%B0%E6%8D%AE%E5%BA%93%E5%88%9D%E5%A7%8B%E5%8C%96)
|
||||
@@ -155,6 +166,8 @@ npm run serve
|
||||
|
||||
### 2.2 server端
|
||||
|
||||
使用 goland等编辑工具,打开server目录,不可以打开 gin-vue-admin 根目录
|
||||
|
||||
```bash
|
||||
# 使用 go.mod
|
||||
|
||||
@@ -210,12 +223,12 @@ zap:
|
||||
|
||||
#### 2.3.1 安装 swagger
|
||||
|
||||
##### (1)可以翻墙
|
||||
##### (1)可以访问外国网站
|
||||
````
|
||||
go get -u github.com/swaggo/swag/cmd/swag
|
||||
````
|
||||
|
||||
##### (2)无法翻墙
|
||||
##### (2)无法访问外国网站
|
||||
|
||||
由于国内没法安装 go.org/x 包下面的东西,推荐使用 [goproxy.io](https://goproxy.io/zh/)
|
||||
|
||||
@@ -236,7 +249,7 @@ go get -u github.com/swaggo/swag/cmd/swag
|
||||
cd server
|
||||
swag init
|
||||
````
|
||||
执行上面的命令后,server目录下会出现docs文件夹,登录http://localhost:8888/swagger/index.html,即可查看swagger文档
|
||||
执行上面的命令后,server目录下会出现docs文件夹,登录 http://localhost:8888/swagger/index.html ,即可查看swagger文档
|
||||
|
||||
|
||||
## 3. 技术选型
|
||||
@@ -315,7 +328,6 @@ swag init
|
||||
|
||||
- [ ] 导入,导出Excel
|
||||
- [ ] Echart图表支持
|
||||
- [ ] 工作流,任务交接功能开发
|
||||
- [ ] 单独前端使用模式以及数据模拟
|
||||
|
||||
## 7. 知识库
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
version: "3.8"
|
||||
version: "3"
|
||||
|
||||
networks:
|
||||
network:
|
||||
|
||||
+1
-16
@@ -12,8 +12,7 @@ RUN sh ./server-handle.sh
|
||||
RUN rm -f server-handle.sh
|
||||
RUN cat ./config.yaml
|
||||
|
||||
RUN go env && go build -o server .
|
||||
|
||||
RUN go env && go mod tidy && go build -o server .
|
||||
|
||||
FROM alpine:latest
|
||||
LABEL MAINTAINER="SliverHorn@sliver_horn@qq.com"
|
||||
@@ -27,17 +26,3 @@ COPY --from=0 /go/src/gin-vue-admin/resource ./resource
|
||||
EXPOSE 8888
|
||||
|
||||
ENTRYPOINT ./server
|
||||
|
||||
# 根据Dockerfile生成Docker镜像
|
||||
|
||||
# docker build -t gva-server:1.0 .
|
||||
|
||||
#- 根据Docker镜像启动Docker容器
|
||||
# - 后台运行
|
||||
# - ```
|
||||
# docker run -d -p 8888:8888 --name gva-server-v1 gva-server:1.0
|
||||
# ```
|
||||
# - 以可交互模式运行, Ctrl + p + q
|
||||
# - ```
|
||||
# docker run -it -p 8888:8888 --name gva-server-v1 gva-server:1.0
|
||||
# ```
|
||||
+15
-14
@@ -1,19 +1,20 @@
|
||||
FROM golang:alpine as builder
|
||||
FROM golang:alpine
|
||||
|
||||
# 设置go mod proxy 国内代理
|
||||
# 设置golang path
|
||||
ENV GOPROXY=https://goproxy.cn,https://goproxy.io,direct \
|
||||
GO111MODULE=on \
|
||||
CGO_ENABLED=1
|
||||
WORKDIR /ginvue
|
||||
RUN go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct
|
||||
ENV GO111MODULE=on
|
||||
ENV GOPROXY=https://goproxy.io,direct
|
||||
|
||||
WORKDIR /go/src/gin-vue-admin
|
||||
COPY . .
|
||||
RUN go env && go list && go build -o app main.go
|
||||
RUN go env && go build -o server .
|
||||
|
||||
FROM alpine:latest
|
||||
LABEL MAINTAINER="SliverHorn@sliver_horn@qq.com"
|
||||
|
||||
WORKDIR /go/src/gin-vue-admin
|
||||
COPY --from=0 /go/src/gin-vue-admin/server ./
|
||||
COPY --from=0 /go/src/gin-vue-admin/config.yaml ./
|
||||
COPY --from=0 /go/src/gin-vue-admin/resource ./resource
|
||||
|
||||
EXPOSE 8888
|
||||
ENTRYPOINT /ginvue/app
|
||||
|
||||
# 根据Dockerfile生成Docker镜像
|
||||
# docker build -t ginvue .
|
||||
# 根据Docker镜像启动Docker容器
|
||||
# docker run -itd -p 8888:8888 --name ginvue ginvue
|
||||
ENTRYPOINT ./server
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
整理代码结构
|
||||
``` lua
|
||||
web
|
||||
├── api/v1 -- 主要API
|
||||
| ├── sys_initdb.go -- ico
|
||||
| └── sys_user.go --
|
||||
├── config -- 配置文件 设定操作的结构体
|
||||
| ├── auto_code.go -- ico captcha.go
|
||||
| ├── ... -- ico captcha.go
|
||||
| └── zap.go -- core
|
||||
├── core -- 主要结构代码
|
||||
| ├── server_other.go -- ico captcha.go
|
||||
| ├── ... -- ico captcha.go
|
||||
| └── zap.go --
|
||||
├── docs -- 文档系统
|
||||
| ├── docs.go -- ico captcha.go
|
||||
| ├── swagger.json -- json
|
||||
| └── swagger.yaml -- yaml
|
||||
├── global -- global
|
||||
├── initialize -- initialize
|
||||
├── middleware -- 中间键
|
||||
├── model -- global
|
||||
│ ├── request -- 所有请求model结构体
|
||||
| | ├── common.go
|
||||
| | ├── ...
|
||||
| | └── sys_user.go -- yaml
|
||||
| ├── response -- 返回数据
|
||||
| | ├── common.go
|
||||
| | ├── ...
|
||||
| | └── sys_user.go -- yaml
|
||||
├── packfile -- 文件写入
|
||||
├── resource -- 资源文件
|
||||
├── router -- 路由
|
||||
├── service -- service层
|
||||
├── source -- 文件目录操作
|
||||
├── utils
|
||||
├── config.yaml --
|
||||
├── Dockerfile -- docker配置
|
||||
├── go.mod -- mod 配置
|
||||
├── go.sum -- sum
|
||||
├── latest_log -- vue-cli 配置
|
||||
└── main.go -- package.json
|
||||
```
|
||||
@@ -1,12 +1,12 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
)
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param file formData file true "an example for breakpoint resume, 断点续传示例"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"切片创建成功"}"
|
||||
// @Router /fileUploadAndDownload/breakpointContinue [post]
|
||||
func BreakpointContinue(c *gin.Context) {
|
||||
fileMd5 := c.Request.FormValue("fileMd5")
|
||||
@@ -27,32 +27,39 @@ func BreakpointContinue(c *gin.Context) {
|
||||
chunkTotal, _ := strconv.Atoi(c.Request.FormValue("chunkTotal"))
|
||||
_, FileHeader, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("接收文件失败", c)
|
||||
return
|
||||
}
|
||||
f, err := FileHeader.Open()
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
global.GVA_LOG.Error("文件读取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("文件读取失败", c)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
cen, _ := ioutil.ReadAll(f)
|
||||
if flag := utils.CheckMd5(cen, chunkMd5); !flag {
|
||||
if !utils.CheckMd5(cen, chunkMd5) {
|
||||
global.GVA_LOG.Error("检查md5失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("检查md5失败", c)
|
||||
return
|
||||
}
|
||||
err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
global.GVA_LOG.Error("查找或创建记录失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("查找或创建记录失败", c)
|
||||
return
|
||||
}
|
||||
err, pathc := utils.BreakPointContinue(cen, fileName, chunkNumber, chunkTotal, fileMd5)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
global.GVA_LOG.Error("断点续传失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("断点续传失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
if err = service.CreateFileChunk(file.ID, pathc, chunkNumber); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
global.GVA_LOG.Error("创建文件记录失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("创建文件记录失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("切片创建成功", c)
|
||||
@@ -72,14 +79,15 @@ func FindFile(c *gin.Context) {
|
||||
chunkTotal, _ := strconv.Atoi(c.Query("chunkTotal"))
|
||||
err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查找失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("查找失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.FileResponse{File: file}, c)
|
||||
response.OkWithDetailed(response.FileResponse{File: file}, "查找成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags ExaFileUploadAndDownload
|
||||
// @Summary 查找文件
|
||||
// @Summary 创建文件
|
||||
// @Security ApiKeyAuth
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
@@ -91,9 +99,10 @@ func BreakpointContinueFinish(c *gin.Context) {
|
||||
fileName := c.Query("fileName")
|
||||
err, filePath := utils.MakeFile(fileName, fileMd5)
|
||||
if err != nil {
|
||||
response.FailWithDetailed(response.ERROR, resp.FilePathResponse{FilePath: filePath}, fmt.Sprintf("文件创建失败:%v", err), c)
|
||||
global.GVA_LOG.Error("文件创建失败!", zap.Any("err", err))
|
||||
response.FailWithDetailed(response.FilePathResponse{FilePath: filePath}, "文件创建失败", c)
|
||||
} else {
|
||||
response.OkDetailed(resp.FilePathResponse{FilePath: filePath}, "文件创建成功", c)
|
||||
response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "文件创建成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +112,7 @@ func BreakpointContinueFinish(c *gin.Context) {
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param file formData file true "删除缓存切片"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查找成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"缓存切片删除成功"}"
|
||||
// @Router /fileUploadAndDownload/removeChunk [post]
|
||||
func RemoveChunk(c *gin.Context) {
|
||||
fileMd5 := c.Query("fileMd5")
|
||||
@@ -112,8 +121,9 @@ func RemoveChunk(c *gin.Context) {
|
||||
err := utils.RemoveChunk(fileMd5)
|
||||
err = service.DeleteFileChunk(fileMd5, fileName, filePath)
|
||||
if err != nil {
|
||||
response.FailWithDetailed(response.ERROR, resp.FilePathResponse{FilePath: filePath}, fmt.Sprintf("缓存切片删除失败:%v", err), c)
|
||||
global.GVA_LOG.Error("缓存切片删除失败!", zap.Any("err", err))
|
||||
response.FailWithDetailed(response.FilePathResponse{FilePath: filePath}, "缓存切片删除失败", c)
|
||||
} else {
|
||||
response.OkDetailed(resp.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c)
|
||||
response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,164 +2,140 @@ package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags SysApi
|
||||
// @Tags ExaCustomer
|
||||
// @Summary 创建客户
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.ExaCustomer true "创建客户"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body model.ExaCustomer true "客户用户名, 客户手机号码"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||
// @Router /customer/customer [post]
|
||||
func CreateExaCustomer(c *gin.Context) {
|
||||
var cu model.ExaCustomer
|
||||
_ = c.ShouldBindJSON(&cu)
|
||||
CustomerVerify := utils.Rules{
|
||||
"CustomerName": {utils.NotEmpty()},
|
||||
"CustomerPhoneData": {utils.NotEmpty()},
|
||||
}
|
||||
CustomerVerifyErr := utils.Verify(cu, CustomerVerify)
|
||||
if CustomerVerifyErr != nil {
|
||||
response.FailWithMessage(CustomerVerifyErr.Error(), c)
|
||||
var customer model.ExaCustomer
|
||||
_ = c.ShouldBindJSON(&customer)
|
||||
if err := utils.Verify(customer, utils.CustomerVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
claims, _ := c.Get("claims")
|
||||
waitUse := claims.(*request.CustomClaims)
|
||||
cu.SysUserID = waitUse.ID
|
||||
cu.SysUserAuthorityID = waitUse.AuthorityId
|
||||
err := service.CreateExaCustomer(cu)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
|
||||
customer.SysUserID = getUserID(c)
|
||||
customer.SysUserAuthorityID = getUserAuthorityId(c)
|
||||
if err := service.CreateExaCustomer(customer); err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysApi
|
||||
// @Tags ExaCustomer
|
||||
// @Summary 删除客户
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.ExaCustomer true "删除客户"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body model.ExaCustomer true "客户ID"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /customer/customer [delete]
|
||||
func DeleteExaCustomer(c *gin.Context) {
|
||||
var cu model.ExaCustomer
|
||||
_ = c.ShouldBindJSON(&cu)
|
||||
CustomerVerify := utils.Rules{
|
||||
"ID": {utils.NotEmpty()},
|
||||
}
|
||||
CustomerVerifyErr := utils.Verify(cu.Model, CustomerVerify)
|
||||
if CustomerVerifyErr != nil {
|
||||
response.FailWithMessage(CustomerVerifyErr.Error(), c)
|
||||
var customer model.ExaCustomer
|
||||
_ = c.ShouldBindJSON(&customer)
|
||||
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.DeleteExaCustomer(cu)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
|
||||
if err := service.DeleteExaCustomer(customer); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysApi
|
||||
// @Tags ExaCustomer
|
||||
// @Summary 更新客户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.ExaCustomer true "创建客户"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body model.ExaCustomer true "客户ID, 客户信息"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /customer/customer [put]
|
||||
func UpdateExaCustomer(c *gin.Context) {
|
||||
var cu model.ExaCustomer
|
||||
_ = c.ShouldBindJSON(&cu)
|
||||
IdCustomerVerify := utils.Rules{
|
||||
"ID": {utils.NotEmpty()},
|
||||
}
|
||||
IdCustomerVerifyErr := utils.Verify(cu.Model, IdCustomerVerify)
|
||||
if IdCustomerVerifyErr != nil {
|
||||
response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
|
||||
var customer model.ExaCustomer
|
||||
_ = c.ShouldBindJSON(&customer)
|
||||
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
CustomerVerify := utils.Rules{
|
||||
"CustomerName": {utils.NotEmpty()},
|
||||
"CustomerPhoneData": {utils.NotEmpty()},
|
||||
}
|
||||
CustomerVerifyErr := utils.Verify(cu, CustomerVerify)
|
||||
if CustomerVerifyErr != nil {
|
||||
response.FailWithMessage(CustomerVerifyErr.Error(), c)
|
||||
if err := utils.Verify(customer, utils.CustomerVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.UpdateExaCustomer(&cu)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("更新失败:%v", err), c)
|
||||
if err := service.UpdateExaCustomer(&customer); err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("更新失败!", c)
|
||||
} else {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysApi
|
||||
// @Tags ExaCustomer
|
||||
// @Summary 获取单一客户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.ExaCustomer true "获取单一客户信息"
|
||||
// @Param data body model.ExaCustomer true "客户ID"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /customer/customer [get]
|
||||
func GetExaCustomer(c *gin.Context) {
|
||||
var cu model.ExaCustomer
|
||||
_ = c.ShouldBindQuery(&cu)
|
||||
IdCustomerVerify := utils.Rules{
|
||||
"ID": {utils.NotEmpty()},
|
||||
}
|
||||
IdCustomerVerifyErr := utils.Verify(cu.Model, IdCustomerVerify)
|
||||
if IdCustomerVerifyErr != nil {
|
||||
response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
|
||||
var customer model.ExaCustomer
|
||||
_ = c.ShouldBindQuery(&customer)
|
||||
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, customer := service.GetExaCustomer(cu.ID)
|
||||
err, data := service.GetExaCustomer(customer.ID)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.ExaCustomerResponse{Customer: customer}, c)
|
||||
response.OkWithDetailed(response.ExaCustomerResponse{Customer: data}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysApi
|
||||
// @Summary 获取权限客户列表
|
||||
// @Tags ExaCustomer
|
||||
// @Summary 分页获取权限客户列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.PageInfo true "获取权限客户列表"
|
||||
// @Param data body request.PageInfo true "页码, 每页大小"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /customer/customerList [get]
|
||||
func GetExaCustomerList(c *gin.Context) {
|
||||
claims, _ := c.Get("claims")
|
||||
waitUse := claims.(*request.CustomClaims)
|
||||
var pageInfo request.PageInfo
|
||||
_ = c.ShouldBindQuery(&pageInfo)
|
||||
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
|
||||
if PageVerifyErr != nil {
|
||||
response.FailWithMessage(PageVerifyErr.Error(), c)
|
||||
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, customerList, total := service.GetCustomerInfoList(waitUse.AuthorityId, pageInfo)
|
||||
err, customerList, total := service.GetCustomerInfoList(getUserAuthorityId(c), pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
|
||||
} else {
|
||||
response.OkWithData(resp.PageResult{
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: customerList,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// /excel/importExcel 接口,与upload接口作用类似,只是把文件存到resource/excel目录下,用于导入Excel时存放Excel文件(ExcelImport.xlsx)
|
||||
// /excel/loadExcel接口,用于读取resource/excel目录下的文件((ExcelImport.xlsx)并加载为[]model.SysBaseMenu类型的示例数据
|
||||
// /excel/exportExcel 接口,用于读取前端传来的tableData,生成Excel文件并返回
|
||||
// /excel/downloadTemplate 接口,用于下载resource/excel目录下的 ExcelTemplate.xlsx 文件,作为导入的模板
|
||||
|
||||
// @Tags excel
|
||||
// @Summary 导出Excel
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/octet-stream
|
||||
// @Param data body model.ExcelInfo true "导出Excel文件信息"
|
||||
// @Success 200
|
||||
// @Router /excel/exportExcel [post]
|
||||
func ExportExcel(c *gin.Context) {
|
||||
var excelInfo model.ExcelInfo
|
||||
_ = c.ShouldBindJSON(&excelInfo)
|
||||
filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
|
||||
err := service.ParseInfoList2Excel(excelInfo.InfoList, filePath)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("转换Excel失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("转换Excel失败", c)
|
||||
return
|
||||
}
|
||||
c.Writer.Header().Add("success", "true")
|
||||
c.File(filePath)
|
||||
}
|
||||
|
||||
// @Tags excel
|
||||
// @Summary 导入Excel文件
|
||||
// @Security ApiKeyAuth
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param file formData file true "导入Excel文件"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"导入成功"}"
|
||||
// @Router /excel/importExcel [post]
|
||||
func ImportExcel(c *gin.Context) {
|
||||
_, header, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("接收文件失败", c)
|
||||
return
|
||||
}
|
||||
_ = c.SaveUploadedFile(header, global.GVA_CONFIG.Excel.Dir+"ExcelImport.xlsx")
|
||||
response.OkWithMessage("导入成功", c)
|
||||
}
|
||||
|
||||
// @Tags excel
|
||||
// @Summary 加载Excel数据
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"加载数据成功"}"
|
||||
// @Router /excel/loadExcel [get]
|
||||
func LoadExcel(c *gin.Context) {
|
||||
menus, err := service.ParseExcel2InfoList()
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("加载数据失败", zap.Any("err", err))
|
||||
response.FailWithMessage("加载数据失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: menus,
|
||||
Total: int64(len(menus)),
|
||||
Page: 1,
|
||||
PageSize: 999,
|
||||
}, "加载数据成功", c)
|
||||
}
|
||||
|
||||
// @Tags excel
|
||||
// @Summary 下载模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param fileName query string true "模板名称"
|
||||
// @Success 200
|
||||
// @Router /excel/downloadTemplate [get]
|
||||
func DownloadTemplate(c *gin.Context) {
|
||||
fileName := c.Query("fileName")
|
||||
filePath := global.GVA_CONFIG.Excel.Dir + fileName
|
||||
ok, err := utils.PathExists(filePath)
|
||||
if !ok || err != nil {
|
||||
global.GVA_LOG.Error("文件不存在", zap.Any("err", err))
|
||||
response.FailWithMessage("文件不存在", c)
|
||||
return
|
||||
}
|
||||
c.Writer.Header().Add("success", "true")
|
||||
c.File(filePath)
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags ExaFileUploadAndDownload
|
||||
@@ -23,15 +23,17 @@ func UploadFile(c *gin.Context) {
|
||||
noSave := c.DefaultQuery("noSave", "0")
|
||||
_, header, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("上传文件失败,%v", err), c)
|
||||
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("接收文件失败", c)
|
||||
return
|
||||
}
|
||||
err, file = service.UploadFile(header, noSave) // 文件上传后拿到文件路径
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("修改数据库链接失败,%v", err), c)
|
||||
global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("修改数据库链接失败", c)
|
||||
return
|
||||
}
|
||||
response.OkDetailed(resp.ExaFileResponse{File: file}, "上传成功", c)
|
||||
response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c)
|
||||
}
|
||||
|
||||
// @Tags ExaFileUploadAndDownload
|
||||
@@ -39,13 +41,14 @@ func UploadFile(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body model.ExaFileUploadAndDownload true "传入文件里面id即可"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /fileUploadAndDownload/deleteFile [post]
|
||||
func DeleteFile(c *gin.Context) {
|
||||
var file model.ExaFileUploadAndDownload
|
||||
_ = c.ShouldBindJSON(&file)
|
||||
if err := service.DeleteFile(file); err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
@@ -56,7 +59,7 @@ func DeleteFile(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.PageInfo true "分页获取文件户列表"
|
||||
// @Param data body request.PageInfo true "页码, 每页大小"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /fileUploadAndDownload/getFileList [post]
|
||||
func GetFileList(c *gin.Context) {
|
||||
@@ -64,13 +67,14 @@ func GetFileList(c *gin.Context) {
|
||||
_ = c.ShouldBindJSON(&pageInfo)
|
||||
err, list, total := service.GetFileRecordInfoList(pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.PageResult{
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags SimpleUploader
|
||||
@@ -15,7 +16,7 @@ import (
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param file formData file true "断点续传插件版示例"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"切片创建成功"}"
|
||||
// @Router /simpleUploader/upload [post]
|
||||
func SimpleUploaderUpload(c *gin.Context) {
|
||||
var chunk model.ExaSimpleUploader
|
||||
@@ -29,42 +30,46 @@ func SimpleUploaderUpload(c *gin.Context) {
|
||||
var chunkDir = "./chunk/" + chunk.Identifier + "/"
|
||||
hasDir, _ := utils.PathExists(chunkDir)
|
||||
if !hasDir {
|
||||
utils.CreateDir(chunkDir)
|
||||
if err := utils.CreateDir(chunkDir); err != nil {
|
||||
global.GVA_LOG.Error("创建目录失败!", zap.Any("err", err))
|
||||
}
|
||||
}
|
||||
chunkPath := chunkDir + chunk.Filename + chunk.ChunkNumber
|
||||
err = c.SaveUploadedFile(header, chunkPath)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("切片创建失败,%v", err), c)
|
||||
global.GVA_LOG.Error("切片创建失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("切片创建失败", c)
|
||||
return
|
||||
}
|
||||
chunk.CurrentChunkPath = chunkPath
|
||||
err = service.SaveChunk(chunk)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("切片创建失败,%v", err), c)
|
||||
global.GVA_LOG.Error("切片创建失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("切片创建失败", c)
|
||||
return
|
||||
} else {
|
||||
response.Ok(c)
|
||||
response.OkWithMessage("切片创建成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SimpleUploader
|
||||
// @Summary 断点续传插件版示例
|
||||
// @Security ApiKeyAuth
|
||||
|
||||
// @Produce application/json
|
||||
// @Param md5 query string true "测试文件是否已经存在和判断已经上传过的切片"
|
||||
// @Param md5 query string true "md5"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /simpleUploader/checkFileMd5 [get]
|
||||
func CheckFileMd5(c *gin.Context) {
|
||||
md5 := c.Query("md5")
|
||||
err, chunks, isDone := service.CheckFileMd5(md5)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("md5读取失败,%v", err), c)
|
||||
global.GVA_LOG.Error("md5读取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("md5读取失败", c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{
|
||||
response.OkWithDetailed(gin.H{
|
||||
"chunks": chunks,
|
||||
"isDone": isDone,
|
||||
}, c)
|
||||
}, "查询成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +77,7 @@ func CheckFileMd5(c *gin.Context) {
|
||||
// @Summary 合并文件
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param md5 query string true "合并文件"
|
||||
// @Param md5 query string true "md5"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"合并成功"}"
|
||||
// @Router /simpleUploader/mergeFileMd5 [get]
|
||||
func MergeFileMd5(c *gin.Context) {
|
||||
@@ -80,8 +85,9 @@ func MergeFileMd5(c *gin.Context) {
|
||||
fileName := c.Query("fileName")
|
||||
err := service.MergeFileMd5(md5, fileName)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("md5读取失败,%v", err), c)
|
||||
global.GVA_LOG.Error("md5读取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("md5读取失败", c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{}, c)
|
||||
response.OkWithMessage("合并成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
+69
-71
@@ -1,14 +1,15 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags SysApi
|
||||
@@ -16,60 +17,47 @@ import (
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysApi true "创建api"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body model.SysApi true "api路径, api中文描述, api组, 方法"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||
// @Router /api/createApi [post]
|
||||
func CreateApi(c *gin.Context) {
|
||||
var api model.SysApi
|
||||
_ = c.ShouldBindJSON(&api)
|
||||
ApiVerify := utils.Rules{
|
||||
"Path": {utils.NotEmpty()},
|
||||
"Description": {utils.NotEmpty()},
|
||||
"ApiGroup": {utils.NotEmpty()},
|
||||
"Method": {utils.NotEmpty()},
|
||||
}
|
||||
ApiVerifyErr := utils.Verify(api, ApiVerify)
|
||||
if ApiVerifyErr != nil {
|
||||
response.FailWithMessage(ApiVerifyErr.Error(), c)
|
||||
if err := utils.Verify(api, utils.ApiVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.CreateApi(api)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
|
||||
if err := service.CreateApi(api); err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysApi
|
||||
// @Summary 删除指定api
|
||||
// @Summary 删除api
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysApi true "删除api"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body model.SysApi true "ID"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /api/deleteApi [post]
|
||||
func DeleteApi(c *gin.Context) {
|
||||
var a model.SysApi
|
||||
_ = c.ShouldBindJSON(&a)
|
||||
ApiVerify := utils.Rules{
|
||||
"ID": {utils.NotEmpty()},
|
||||
}
|
||||
ApiVerifyErr := utils.Verify(a.Model, ApiVerify)
|
||||
if ApiVerifyErr != nil {
|
||||
response.FailWithMessage(ApiVerifyErr.Error(), c)
|
||||
var api model.SysApi
|
||||
_ = c.ShouldBindJSON(&api)
|
||||
if err := utils.Verify(api.GVA_MODEL, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.DeleteApi(a)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
if err := service.DeleteApi(api); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// 条件搜索后端看此api
|
||||
|
||||
// @Tags SysApi
|
||||
// @Summary 分页获取API列表
|
||||
// @Security ApiKeyAuth
|
||||
@@ -79,24 +67,22 @@ func DeleteApi(c *gin.Context) {
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /api/getApiList [post]
|
||||
func GetApiList(c *gin.Context) {
|
||||
// 此结构体仅本方法使用
|
||||
var sp request.SearchApiParams
|
||||
_ = c.ShouldBindJSON(&sp)
|
||||
PageVerifyErr := utils.Verify(sp.PageInfo, utils.CustomizeMap["PageVerify"])
|
||||
if PageVerifyErr != nil {
|
||||
response.FailWithMessage(PageVerifyErr.Error(), c)
|
||||
var pageInfo request.SearchApiParams
|
||||
_ = c.ShouldBindJSON(&pageInfo)
|
||||
if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, list, total := service.GetAPIInfoList(sp.SysApi, sp.PageInfo, sp.OrderKey, sp.Desc)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
if err, list, total := service.GetAPIInfoList(pageInfo.SysApi, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.PageResult{
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: sp.PageInfo.Page,
|
||||
PageSize: sp.PageInfo.PageSize,
|
||||
}, c)
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,16 +97,16 @@ func GetApiList(c *gin.Context) {
|
||||
func GetApiById(c *gin.Context) {
|
||||
var idInfo request.GetById
|
||||
_ = c.ShouldBindJSON(&idInfo)
|
||||
IdVerifyErr := utils.Verify(idInfo, utils.CustomizeMap["IdVerify"])
|
||||
if IdVerifyErr != nil {
|
||||
response.FailWithMessage(IdVerifyErr.Error(), c)
|
||||
if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, api := service.GetApiById(idInfo.Id)
|
||||
err, api := service.GetApiById(idInfo.ID)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.SysAPIResponse{Api: api}, c)
|
||||
response.OkWithData(response.SysAPIResponse{Api: api}, c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,28 +115,21 @@ func GetApiById(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysApi true "创建api"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body model.SysApi true "api路径, api中文描述, api组, 方法"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
|
||||
// @Router /api/updateApi [post]
|
||||
func UpdateApi(c *gin.Context) {
|
||||
var api model.SysApi
|
||||
_ = c.ShouldBindJSON(&api)
|
||||
ApiVerify := utils.Rules{
|
||||
"Path": {utils.NotEmpty()},
|
||||
"Description": {utils.NotEmpty()},
|
||||
"ApiGroup": {utils.NotEmpty()},
|
||||
"Method": {utils.NotEmpty()},
|
||||
}
|
||||
ApiVerifyErr := utils.Verify(api, ApiVerify)
|
||||
if ApiVerifyErr != nil {
|
||||
response.FailWithMessage(ApiVerifyErr.Error(), c)
|
||||
if err := utils.Verify(api, utils.ApiVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.UpdateApi(api)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("修改数据失败,%v", err), c)
|
||||
if err := service.UpdateApi(api); err != nil {
|
||||
global.GVA_LOG.Error("修改失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("修改失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("修改数据成功", c)
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,10 +141,29 @@ func UpdateApi(c *gin.Context) {
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /api/getAllApis [post]
|
||||
func GetAllApis(c *gin.Context) {
|
||||
err, apis := service.GetAllApis()
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
if err, apis := service.GetAllApis(); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.SysAPIListResponse{Apis: apis}, c)
|
||||
response.OkWithDetailed(response.SysAPIListResponse{Apis: apis}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysApi
|
||||
// @Summary 删除选中Api
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "ID"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /api/deleteApisByIds [delete]
|
||||
func DeleteApisByIds(c *gin.Context) {
|
||||
var ids request.IdsReq
|
||||
_ = c.ShouldBindJSON(&ids)
|
||||
if err := service.DeleteApisByIds(ids); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,166 +1,141 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags authority
|
||||
// @Tags Authority
|
||||
// @Summary 创建角色
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysAuthority true "创建角色"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body model.SysAuthority true "权限id, 权限名, 父角色id"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||
// @Router /authority/createAuthority [post]
|
||||
func CreateAuthority(c *gin.Context) {
|
||||
var auth model.SysAuthority
|
||||
_ = c.ShouldBindJSON(&auth)
|
||||
AuthorityVerify := utils.Rules{
|
||||
"AuthorityId": {utils.NotEmpty()},
|
||||
"AuthorityName": {utils.NotEmpty()},
|
||||
"ParentId": {utils.NotEmpty()},
|
||||
}
|
||||
AuthorityVerifyErr := utils.Verify(auth, AuthorityVerify)
|
||||
if AuthorityVerifyErr != nil {
|
||||
response.FailWithMessage(AuthorityVerifyErr.Error(), c)
|
||||
var authority model.SysAuthority
|
||||
_ = c.ShouldBindJSON(&authority)
|
||||
if err := utils.Verify(authority, utils.AuthorityVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, authBack := service.CreateAuthority(auth)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
|
||||
if err, authBack := service.CreateAuthority(authority); err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("创建失败"+err.Error(), c)
|
||||
} else {
|
||||
response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c)
|
||||
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "创建成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags authority
|
||||
// @Tags Authority
|
||||
// @Summary 拷贝角色
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body response.SysAuthorityCopyResponse true "拷贝角色"
|
||||
// @Param data body response.SysAuthorityCopyResponse true "旧角色id, 新权限id, 新权限名, 新父角色id"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"拷贝成功"}"
|
||||
// @Router /authority/copyAuthority [post]
|
||||
func CopyAuthority(c *gin.Context) {
|
||||
var copyInfo resp.SysAuthorityCopyResponse
|
||||
var copyInfo response.SysAuthorityCopyResponse
|
||||
_ = c.ShouldBindJSON(©Info)
|
||||
OldAuthorityVerify := utils.Rules{
|
||||
"OldAuthorityId": {utils.NotEmpty()},
|
||||
}
|
||||
OldAuthorityVerifyErr := utils.Verify(copyInfo, OldAuthorityVerify)
|
||||
if OldAuthorityVerifyErr != nil {
|
||||
response.FailWithMessage(OldAuthorityVerifyErr.Error(), c)
|
||||
if err := utils.Verify(copyInfo, utils.OldAuthorityVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
AuthorityVerify := utils.Rules{
|
||||
"AuthorityId": {utils.NotEmpty()},
|
||||
"AuthorityName": {utils.NotEmpty()},
|
||||
"ParentId": {utils.NotEmpty()},
|
||||
}
|
||||
AuthorityVerifyErr := utils.Verify(copyInfo.Authority, AuthorityVerify)
|
||||
if AuthorityVerifyErr != nil {
|
||||
response.FailWithMessage(AuthorityVerifyErr.Error(), c)
|
||||
if err := utils.Verify(copyInfo.Authority, utils.AuthorityVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, authBack := service.CopyAuthority(copyInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("拷贝失败,%v", err), c)
|
||||
if err, authBack := service.CopyAuthority(copyInfo); err != nil {
|
||||
global.GVA_LOG.Error("拷贝失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("拷贝失败"+err.Error(), c)
|
||||
} else {
|
||||
response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c)
|
||||
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "拷贝成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags authority
|
||||
// @Tags Authority
|
||||
// @Summary 删除角色
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysAuthority true "删除角色"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /authority/deleteAuthority [post]
|
||||
func DeleteAuthority(c *gin.Context) {
|
||||
var a model.SysAuthority
|
||||
_ = c.ShouldBindJSON(&a)
|
||||
AuthorityIdVerifyErr := utils.Verify(a, utils.CustomizeMap["AuthorityIdVerify"])
|
||||
if AuthorityIdVerifyErr != nil {
|
||||
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
|
||||
var authority model.SysAuthority
|
||||
_ = c.ShouldBindJSON(&authority)
|
||||
if err := utils.Verify(authority, utils.AuthorityIdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
// 删除角色之前需要判断是否有用户正在使用此角色
|
||||
err := service.DeleteAuthority(&a)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
if err := service.DeleteAuthority(&authority); err != nil { // 删除角色之前需要判断是否有用户正在使用此角色
|
||||
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("删除失败"+err.Error(), c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags authority
|
||||
// @Summary 设置角色资源权限
|
||||
// @Tags Authority
|
||||
// @Summary 更新角色信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysAuthority true "设置角色资源权限"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
|
||||
// @Param data body model.SysAuthority true "权限id, 权限名, 父角色id"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /authority/updateAuthority [post]
|
||||
func UpdateAuthority(c *gin.Context) {
|
||||
var auth model.SysAuthority
|
||||
_ = c.ShouldBindJSON(&auth)
|
||||
AuthorityVerify := utils.Rules{
|
||||
"AuthorityId": {utils.NotEmpty()},
|
||||
"AuthorityName": {utils.NotEmpty()},
|
||||
"ParentId": {utils.NotEmpty()},
|
||||
}
|
||||
AuthorityVerifyErr := utils.Verify(auth, AuthorityVerify)
|
||||
if AuthorityVerifyErr != nil {
|
||||
response.FailWithMessage(AuthorityVerifyErr.Error(), c)
|
||||
if err := utils.Verify(auth, utils.AuthorityVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, authority := service.UpdateAuthority(auth)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
|
||||
if err, authority := service.UpdateAuthority(auth); err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("更新失败"+err.Error(), c)
|
||||
} else {
|
||||
response.OkWithData(resp.SysAuthorityResponse{Authority: authority}, c)
|
||||
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authority}, "更新成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags authority
|
||||
// @Tags Authority
|
||||
// @Summary 分页获取角色列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.PageInfo true "分页获取用户列表"
|
||||
// @Param data body request.PageInfo true "页码, 每页大小"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /authority/getAuthorityList [post]
|
||||
func GetAuthorityList(c *gin.Context) {
|
||||
var pageInfo request.PageInfo
|
||||
_ = c.ShouldBindJSON(&pageInfo)
|
||||
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
|
||||
if PageVerifyErr != nil {
|
||||
response.FailWithMessage(PageVerifyErr.Error(), c)
|
||||
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, list, total := service.GetAuthorityInfoList(pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
if err, list, total := service.GetAuthorityInfoList(pageInfo); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败"+err.Error(), c)
|
||||
} else {
|
||||
response.OkWithData(resp.PageResult{
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags authority
|
||||
// @Tags Authority
|
||||
// @Summary 设置角色资源权限
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
@@ -171,15 +146,14 @@ func GetAuthorityList(c *gin.Context) {
|
||||
func SetDataAuthority(c *gin.Context) {
|
||||
var auth model.SysAuthority
|
||||
_ = c.ShouldBindJSON(&auth)
|
||||
AuthorityIdVerifyErr := utils.Verify(auth, utils.CustomizeMap["AuthorityIdVerify"])
|
||||
if AuthorityIdVerifyErr != nil {
|
||||
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
|
||||
if err := utils.Verify(auth, utils.AuthorityIdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.SetDataAuthority(auth)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("设置关联失败,%v", err), c)
|
||||
if err := service.SetDataAuthority(auth); err != nil {
|
||||
global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("设置失败"+err.Error(), c)
|
||||
} else {
|
||||
response.Ok(c)
|
||||
response.OkWithMessage("设置成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,45 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags SysApi
|
||||
// @Tags AutoCode
|
||||
// @Summary 预览创建后的代码
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.AutoCodeStruct true "预览创建代码"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||
// @Router /autoCode/preview [post]
|
||||
func PreviewTemp(c *gin.Context) {
|
||||
var a model.AutoCodeStruct
|
||||
_ = c.ShouldBindJSON(&a)
|
||||
if err := utils.Verify(a, utils.AutoCodeVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
autoCode, err := service.PreviewTemp(a)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("预览失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("预览失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(gin.H{"autoCode": autoCode}, "预览成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags AutoCode
|
||||
// @Summary 自动代码模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
@@ -23,132 +50,87 @@ import (
|
||||
func CreateTemp(c *gin.Context) {
|
||||
var a model.AutoCodeStruct
|
||||
_ = c.ShouldBindJSON(&a)
|
||||
AutoCodeVerify := utils.Rules{
|
||||
"Abbreviation": {utils.NotEmpty()},
|
||||
"StructName": {utils.NotEmpty()},
|
||||
"PackageName": {utils.NotEmpty()},
|
||||
"Fields": {utils.NotEmpty()},
|
||||
}
|
||||
WKVerifyErr := utils.Verify(a, AutoCodeVerify)
|
||||
if WKVerifyErr != nil {
|
||||
response.FailWithMessage(WKVerifyErr.Error(), c)
|
||||
if err := utils.Verify(a, utils.AutoCodeVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if a.AutoCreateApiToSql {
|
||||
apiList := [6]model.SysApi{
|
||||
{
|
||||
Path: "/" + a.Abbreviation + "/" + "create" + a.StructName,
|
||||
Description: "新增" + a.Description,
|
||||
ApiGroup: a.Abbreviation,
|
||||
Method: "POST",
|
||||
},
|
||||
{
|
||||
Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName,
|
||||
Description: "删除" + a.Description,
|
||||
ApiGroup: a.Abbreviation,
|
||||
Method: "DELETE",
|
||||
},
|
||||
{
|
||||
Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName+"ByIds",
|
||||
Description: "批量删除" + a.Description,
|
||||
ApiGroup: a.Abbreviation,
|
||||
Method: "DELETE",
|
||||
},
|
||||
{
|
||||
Path: "/" + a.Abbreviation + "/" + "update" + a.StructName,
|
||||
Description: "更新" + a.Description,
|
||||
ApiGroup: a.Abbreviation,
|
||||
Method: "PUT",
|
||||
},
|
||||
{
|
||||
Path: "/" + a.Abbreviation + "/" + "find" + a.StructName,
|
||||
Description: "根据ID获取" + a.Description,
|
||||
ApiGroup: a.Abbreviation,
|
||||
Method: "GET",
|
||||
},
|
||||
{
|
||||
Path: "/" + a.Abbreviation + "/" + "get" + a.StructName + "List",
|
||||
Description: "获取" + a.Description + "列表",
|
||||
ApiGroup: a.Abbreviation,
|
||||
Method: "GET",
|
||||
},
|
||||
}
|
||||
for _, v := range apiList {
|
||||
errC := service.CreateApi(v)
|
||||
if errC != nil {
|
||||
c.Writer.Header().Add("success", "false")
|
||||
c.Writer.Header().Add("msg", url.QueryEscape(fmt.Sprintf("自动化创建失败,%v,请自行清空垃圾数据", errC)))
|
||||
return
|
||||
}
|
||||
if err := service.AutoCreateApi(&a); err != nil {
|
||||
global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Any("err", err))
|
||||
c.Writer.Header().Add("success", "false")
|
||||
c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!"))
|
||||
return
|
||||
}
|
||||
}
|
||||
err := service.CreateTemp(a)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
|
||||
os.Remove("./ginvueadmin.zip")
|
||||
if errors.Is(err, model.AutoMoveErr) {
|
||||
c.Writer.Header().Add("success", "false")
|
||||
c.Writer.Header().Add("msgtype", "success")
|
||||
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
|
||||
} else {
|
||||
c.Writer.Header().Add("success", "false")
|
||||
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
|
||||
_ = os.Remove("./ginvueadmin.zip")
|
||||
}
|
||||
|
||||
} else {
|
||||
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "ginvueadmin.zip")) // fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
|
||||
c.Writer.Header().Add("Content-Type", "application/json")
|
||||
c.Writer.Header().Add("success", "true")
|
||||
c.File("./ginvueadmin.zip")
|
||||
os.Remove("./ginvueadmin.zip")
|
||||
_ = os.Remove("./ginvueadmin.zip")
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysApi
|
||||
// @Tags AutoCode
|
||||
// @Summary 获取当前数据库所有表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /autoCode/getTables [get]
|
||||
|
||||
func GetTables(c *gin.Context) {
|
||||
dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname)
|
||||
err, tables := service.GetTables(dbName)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("查询table失败,%v", err), c)
|
||||
global.GVA_LOG.Error("查询table失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("查询table失败", c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{
|
||||
"tables": tables,
|
||||
}, c)
|
||||
response.OkWithDetailed(gin.H{"tables": tables}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysApi
|
||||
// @Tags AutoCode
|
||||
// @Summary 获取当前所有数据库
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /autoCode/getDatabase [get]
|
||||
func GetDB(c *gin.Context) {
|
||||
err, dbs := service.GetDB()
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("查询table失败,%v", err), c)
|
||||
if err, dbs := service.GetDB(); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{
|
||||
"dbs": dbs,
|
||||
}, c)
|
||||
response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysApi
|
||||
// @Tags AutoCode
|
||||
// @Summary 获取当前表所有字段
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||
// @Router /autoCode/getDatabase [get]
|
||||
func GetColume(c *gin.Context) {
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /autoCode/getColumn [get]
|
||||
func GetColumn(c *gin.Context) {
|
||||
dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname)
|
||||
tableName := c.Query("tableName")
|
||||
err, columes := service.GetColume(tableName, dbName)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("查询table失败,%v", err), c)
|
||||
if err, columns := service.GetColumn(tableName, dbName); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{
|
||||
"columes": columes,
|
||||
}, c)
|
||||
response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,32 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/global/response"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var store = base64Captcha.DefaultMemStore
|
||||
|
||||
// @Tags base
|
||||
// @Tags Base
|
||||
// @Summary 生成验证码
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"验证码获取成功"}"
|
||||
// @Router /base/captcha [post]
|
||||
func Captcha(c *gin.Context) {
|
||||
//字符,公式,验证码配置
|
||||
// 生成默认数字的driver
|
||||
driver := base64Captcha.NewDriverDigit(global.GVA_CONFIG.Captcha.ImgHeight, global.GVA_CONFIG.Captcha.ImgWidth, global.GVA_CONFIG.Captcha.KeyLong, 0.7, 80)
|
||||
cp := base64Captcha.NewCaptcha(driver, store)
|
||||
id, b64s, err := cp.Generate()
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
if id, b64s, err := cp.Generate(); err != nil {
|
||||
global.GVA_LOG.Error("验证码获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("验证码获取失败", c)
|
||||
} else {
|
||||
response.OkDetailed(resp.SysCaptchaResponse{
|
||||
response.OkWithDetailed(response.SysCaptchaResponse{
|
||||
CaptchaId: id,
|
||||
PicPath: b64s,
|
||||
}, "验证码获取成功", c)
|
||||
|
||||
+21
-24
@@ -1,56 +1,53 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags casbin
|
||||
// @Summary 更改角色api权限
|
||||
// @Tags Casbin
|
||||
// @Summary 更新角色api权限
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.CasbinInReceive true "更改角色api权限"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /casbin/UpdateCasbin [post]
|
||||
func UpdateCasbin(c *gin.Context) {
|
||||
var cmr request.CasbinInReceive
|
||||
_ = c.ShouldBindJSON(&cmr)
|
||||
AuthorityIdVerifyErr := utils.Verify(cmr, utils.CustomizeMap["AuthorityIdVerify"])
|
||||
if AuthorityIdVerifyErr != nil {
|
||||
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
|
||||
if err := utils.Verify(cmr, utils.AuthorityIdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("添加规则失败,%v", err), c)
|
||||
if err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos); err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("添加规则成功", c)
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags casbin
|
||||
// @Tags Casbin
|
||||
// @Summary 获取权限列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.CasbinInReceive true "获取权限列表"
|
||||
// @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /casbin/getPolicyPathByAuthorityId [post]
|
||||
func GetPolicyPathByAuthorityId(c *gin.Context) {
|
||||
var cmr request.CasbinInReceive
|
||||
_ = c.ShouldBindJSON(&cmr)
|
||||
AuthorityIdVerifyErr := utils.Verify(cmr, utils.CustomizeMap["AuthorityIdVerify"])
|
||||
if AuthorityIdVerifyErr != nil {
|
||||
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
|
||||
var casbin request.CasbinInReceive
|
||||
_ = c.ShouldBindJSON(&casbin)
|
||||
if err := utils.Verify(casbin, utils.AuthorityIdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
paths := service.GetPolicyPathByAuthorityId(cmr.AuthorityId)
|
||||
response.OkWithData(resp.PolicyPathResponse{Paths: paths}, c)
|
||||
paths := service.GetPolicyPathByAuthorityId(casbin.AuthorityId)
|
||||
response.OkWithDetailed(response.PolicyPathResponse{Paths: paths}, "获取成功", c)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags SysDictionary
|
||||
@@ -15,15 +16,15 @@ import (
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysDictionary true "创建SysDictionary"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body model.SysDictionary true "SysDictionary模型"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||
// @Router /sysDictionary/createSysDictionary [post]
|
||||
func CreateSysDictionary(c *gin.Context) {
|
||||
var sysDictionary model.SysDictionary
|
||||
_ = c.ShouldBindJSON(&sysDictionary)
|
||||
err := service.CreateSysDictionary(sysDictionary)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
|
||||
var dictionary model.SysDictionary
|
||||
_ = c.ShouldBindJSON(&dictionary)
|
||||
if err := service.CreateSysDictionary(dictionary); err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
@@ -34,15 +35,15 @@ func CreateSysDictionary(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysDictionary true "删除SysDictionary"
|
||||
// @Param data body model.SysDictionary true "SysDictionary模型"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /sysDictionary/deleteSysDictionary [delete]
|
||||
func DeleteSysDictionary(c *gin.Context) {
|
||||
var sysDictionary model.SysDictionary
|
||||
_ = c.ShouldBindJSON(&sysDictionary)
|
||||
err := service.DeleteSysDictionary(sysDictionary)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
var dictionary model.SysDictionary
|
||||
_ = c.ShouldBindJSON(&dictionary)
|
||||
if err := service.DeleteSysDictionary(dictionary); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
@@ -53,15 +54,15 @@ func DeleteSysDictionary(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysDictionary true "更新SysDictionary"
|
||||
// @Param data body model.SysDictionary true "SysDictionary模型"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /sysDictionary/updateSysDictionary [put]
|
||||
func UpdateSysDictionary(c *gin.Context) {
|
||||
var sysDictionary model.SysDictionary
|
||||
_ = c.ShouldBindJSON(&sysDictionary)
|
||||
err := service.UpdateSysDictionary(&sysDictionary)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
|
||||
var dictionary model.SysDictionary
|
||||
_ = c.ShouldBindJSON(&dictionary)
|
||||
if err := service.UpdateSysDictionary(&dictionary); err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
@@ -72,17 +73,17 @@ func UpdateSysDictionary(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysDictionary true "用id查询SysDictionary"
|
||||
// @Param data body model.SysDictionary true "ID或字典英名"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /sysDictionary/findSysDictionary [get]
|
||||
func FindSysDictionary(c *gin.Context) {
|
||||
var sysDictionary model.SysDictionary
|
||||
_ = c.ShouldBindQuery(&sysDictionary)
|
||||
err, resysDictionary := service.GetSysDictionary(sysDictionary.Type, sysDictionary.ID)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
|
||||
var dictionary model.SysDictionary
|
||||
_ = c.ShouldBindQuery(&dictionary)
|
||||
if err, sysDictionary := service.GetSysDictionary(dictionary.Type, dictionary.ID); err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{"resysDictionary": resysDictionary}, c)
|
||||
response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,21 +92,25 @@ func FindSysDictionary(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.SysDictionarySearch true "分页获取SysDictionary列表"
|
||||
// @Param data body request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /sysDictionary/getSysDictionaryList [get]
|
||||
func GetSysDictionaryList(c *gin.Context) {
|
||||
var pageInfo request.SysDictionarySearch
|
||||
_ = c.ShouldBindQuery(&pageInfo)
|
||||
err, list, total := service.GetSysDictionaryInfoList(pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err, list, total := service.GetSysDictionaryInfoList(pageInfo); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.PageResult{
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags SysDictionaryDetail
|
||||
@@ -15,15 +16,15 @@ import (
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysDictionaryDetail true "创建SysDictionaryDetail"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||
// @Router /sysDictionaryDetail/createSysDictionaryDetail [post]
|
||||
func CreateSysDictionaryDetail(c *gin.Context) {
|
||||
var sysDictionaryDetail model.SysDictionaryDetail
|
||||
_ = c.ShouldBindJSON(&sysDictionaryDetail)
|
||||
err := service.CreateSysDictionaryDetail(sysDictionaryDetail)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
|
||||
var detail model.SysDictionaryDetail
|
||||
_ = c.ShouldBindJSON(&detail)
|
||||
if err := service.CreateSysDictionaryDetail(detail); err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
@@ -34,15 +35,15 @@ func CreateSysDictionaryDetail(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysDictionaryDetail true "删除SysDictionaryDetail"
|
||||
// @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete]
|
||||
func DeleteSysDictionaryDetail(c *gin.Context) {
|
||||
var sysDictionaryDetail model.SysDictionaryDetail
|
||||
_ = c.ShouldBindJSON(&sysDictionaryDetail)
|
||||
err := service.DeleteSysDictionaryDetail(sysDictionaryDetail)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
var detail model.SysDictionaryDetail
|
||||
_ = c.ShouldBindJSON(&detail)
|
||||
if err := service.DeleteSysDictionaryDetail(detail); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
@@ -57,11 +58,11 @@ func DeleteSysDictionaryDetail(c *gin.Context) {
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /sysDictionaryDetail/updateSysDictionaryDetail [put]
|
||||
func UpdateSysDictionaryDetail(c *gin.Context) {
|
||||
var sysDictionaryDetail model.SysDictionaryDetail
|
||||
_ = c.ShouldBindJSON(&sysDictionaryDetail)
|
||||
err := service.UpdateSysDictionaryDetail(&sysDictionaryDetail)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
|
||||
var detail model.SysDictionaryDetail
|
||||
_ = c.ShouldBindJSON(&detail)
|
||||
if err := service.UpdateSysDictionaryDetail(&detail); err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
@@ -76,13 +77,17 @@ func UpdateSysDictionaryDetail(c *gin.Context) {
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /sysDictionaryDetail/findSysDictionaryDetail [get]
|
||||
func FindSysDictionaryDetail(c *gin.Context) {
|
||||
var sysDictionaryDetail model.SysDictionaryDetail
|
||||
_ = c.ShouldBindQuery(&sysDictionaryDetail)
|
||||
err, resysDictionaryDetail := service.GetSysDictionaryDetail(sysDictionaryDetail.ID)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
|
||||
var detail model.SysDictionaryDetail
|
||||
_ = c.ShouldBindQuery(&detail)
|
||||
if err := utils.Verify(detail, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err, resysDictionaryDetail := service.GetSysDictionaryDetail(detail.ID); err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{"resysDictionaryDetail": resysDictionaryDetail}, c)
|
||||
response.OkWithDetailed(gin.H{"resysDictionaryDetail": resysDictionaryDetail}, "查询成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,21 +96,21 @@ func FindSysDictionaryDetail(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.SysDictionaryDetailSearch true "分页获取SysDictionaryDetail列表"
|
||||
// @Param data body request.SysDictionaryDetailSearch true "页码, 每页大小, 搜索条件"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /sysDictionaryDetail/getSysDictionaryDetailList [get]
|
||||
func GetSysDictionaryDetailList(c *gin.Context) {
|
||||
var pageInfo request.SysDictionaryDetailSearch
|
||||
_ = c.ShouldBindQuery(&pageInfo)
|
||||
err, list, total := service.GetSysDictionaryDetailInfoList(pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
if err, list, total := service.GetSysDictionaryDetailInfoList(pageInfo); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.PageResult{
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags system
|
||||
// @Tags System
|
||||
// @Summary 发送测试邮件
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
|
||||
// @Router /email/emailTest [post]
|
||||
func EmailTest(c *gin.Context) {
|
||||
err := service.EmailTest()
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("发送失败,%v", err), c)
|
||||
if err := service.EmailTest(); err != nil {
|
||||
global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("发送失败", c)
|
||||
} else {
|
||||
response.OkWithData("发送成功", c)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/request"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Tags InitDB
|
||||
// @Summary 初始化用户数据库
|
||||
// @Produce application/json
|
||||
// @Param data body request.InitDB true "初始化数据库参数"
|
||||
// @Success 200 {string} string "{"code":0,"data":{},"msg":"自动创建数据库成功"}"
|
||||
// @Router /init/initdb [post]
|
||||
func InitDB(c *gin.Context) {
|
||||
if global.GVA_DB != nil {
|
||||
global.GVA_LOG.Error("非法访问")
|
||||
response.FailWithMessage("非法访问", c)
|
||||
return
|
||||
}
|
||||
var dbInfo request.InitDB
|
||||
if err := c.ShouldBindJSON(&dbInfo); err != nil {
|
||||
global.GVA_LOG.Error("参数校验不通过", zap.Any("err", err))
|
||||
response.FailWithMessage("参数校验不通过", c)
|
||||
return
|
||||
}
|
||||
if err := service.InitDB(dbInfo); err != nil {
|
||||
global.GVA_LOG.Error("自动创建数据库失败", zap.Any("err", err))
|
||||
response.FailWithMessage("自动创建数据库失败,请查看后台日志", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData("自动创建数据库成功", c)
|
||||
}
|
||||
|
||||
// @Tags CheckDB
|
||||
// @Summary 初始化用户数据库
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"code":0,"data":{},"msg":"探测完成"}"
|
||||
// @Router /init/checkdb [post]
|
||||
func CheckDB(c *gin.Context) {
|
||||
if global.GVA_DB != nil {
|
||||
global.GVA_LOG.Info("数据库无需初始化")
|
||||
response.OkWithDetailed(gin.H{
|
||||
"needInit": false,
|
||||
}, "数据库无需初始化", c)
|
||||
return
|
||||
} else {
|
||||
global.GVA_LOG.Info("前往初始化数据库")
|
||||
response.OkWithDetailed(gin.H{
|
||||
"needInit": true,
|
||||
}, "前往初始化数据库", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags jwt
|
||||
// @Tags Jwt
|
||||
// @Summary jwt加入黑名单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
@@ -17,12 +18,10 @@ import (
|
||||
// @Router /jwt/jsonInBlacklist [post]
|
||||
func JsonInBlacklist(c *gin.Context) {
|
||||
token := c.Request.Header.Get("x-token")
|
||||
modelJwt := model.JwtBlacklist{
|
||||
Jwt: token,
|
||||
}
|
||||
err := service.JsonInBlacklist(modelJwt)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("jwt作废失败,%v", err), c)
|
||||
jwt := model.JwtBlacklist{Jwt: token}
|
||||
if err := service.JsonInBlacklist(jwt); err != nil {
|
||||
global.GVA_LOG.Error("jwt作废失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("jwt作废失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("jwt作废成功", c)
|
||||
}
|
||||
|
||||
+123
-162
@@ -1,259 +1,220 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags authorityAndMenu
|
||||
// @Tags AuthorityMenu
|
||||
// @Summary 获取用户动态路由
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body request.RegisterAndLoginStruct true "可以什么都不填"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
|
||||
// @Param data body request.Empty true "空"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /menu/getMenu [post]
|
||||
func GetMenu(c *gin.Context) {
|
||||
claims, _ := c.Get("claims")
|
||||
waitUse := claims.(*request.CustomClaims)
|
||||
err, menus := service.GetMenuTree(waitUse.AuthorityId)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
|
||||
if err, menus := service.GetMenuTree(getUserAuthorityId(c)); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.SysMenusResponse{Menus: menus}, c)
|
||||
response.OkWithDetailed(response.SysMenusResponse{Menus: menus}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags menu
|
||||
// @Summary 分页获取基础menu列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.PageInfo true "分页获取基础menu列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /menu/getMenuList [post]
|
||||
func GetMenuList(c *gin.Context) {
|
||||
var pageInfo request.PageInfo
|
||||
_ = c.ShouldBindJSON(&pageInfo)
|
||||
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
|
||||
if PageVerifyErr != nil {
|
||||
response.FailWithMessage(PageVerifyErr.Error(), c)
|
||||
return
|
||||
}
|
||||
err, menuList, total := service.GetInfoList()
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
} else {
|
||||
response.OkWithData(resp.PageResult{
|
||||
List: menuList,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags menu
|
||||
// @Summary 新增菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysBaseMenu true "新增菜单"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /menu/addBaseMenu [post]
|
||||
func AddBaseMenu(c *gin.Context) {
|
||||
var menu model.SysBaseMenu
|
||||
_ = c.ShouldBindJSON(&menu)
|
||||
MenuVerify := utils.Rules{
|
||||
"Path": {utils.NotEmpty()},
|
||||
"ParentId": {utils.NotEmpty()},
|
||||
"Name": {utils.NotEmpty()},
|
||||
"Component": {utils.NotEmpty()},
|
||||
"Sort": {utils.Ge("0")},
|
||||
}
|
||||
MenuVerifyErr := utils.Verify(menu, MenuVerify)
|
||||
if MenuVerifyErr != nil {
|
||||
response.FailWithMessage(MenuVerifyErr.Error(), c)
|
||||
return
|
||||
}
|
||||
MetaVerify := utils.Rules{
|
||||
"Title": {utils.NotEmpty()},
|
||||
}
|
||||
MetaVerifyErr := utils.Verify(menu.Meta, MetaVerify)
|
||||
if MetaVerifyErr != nil {
|
||||
response.FailWithMessage(MetaVerifyErr.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.AddBaseMenu(menu)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("添加失败,%v", err), c)
|
||||
} else {
|
||||
response.OkWithMessage("添加成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags authorityAndMenu
|
||||
// @Tags AuthorityMenu
|
||||
// @Summary 获取用户动态路由
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body request.RegisterAndLoginStruct true "可以什么都不填"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
|
||||
// @Param data body request.Empty true "空"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /menu/getBaseMenuTree [post]
|
||||
func GetBaseMenuTree(c *gin.Context) {
|
||||
err, menus := service.GetBaseMenuTree()
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
|
||||
if err, menus := service.GetBaseMenuTree(); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.SysBaseMenusResponse{Menus: menus}, c)
|
||||
response.OkWithDetailed(response.SysBaseMenusResponse{Menus: menus}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags authorityAndMenu
|
||||
// @Tags AuthorityMenu
|
||||
// @Summary 增加menu和角色关联关系
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.AddMenuAuthorityInfo true "增加menu和角色关联关系"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body request.AddMenuAuthorityInfo true "角色ID"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}"
|
||||
// @Router /menu/addMenuAuthority [post]
|
||||
func AddMenuAuthority(c *gin.Context) {
|
||||
var addMenuAuthorityInfo request.AddMenuAuthorityInfo
|
||||
_ = c.ShouldBindJSON(&addMenuAuthorityInfo)
|
||||
MenuVerify := utils.Rules{
|
||||
"AuthorityId": {"notEmpty"},
|
||||
}
|
||||
MenuVerifyErr := utils.Verify(addMenuAuthorityInfo, MenuVerify)
|
||||
if MenuVerifyErr != nil {
|
||||
response.FailWithMessage(MenuVerifyErr.Error(), c)
|
||||
var authorityMenu request.AddMenuAuthorityInfo
|
||||
_ = c.ShouldBindJSON(&authorityMenu)
|
||||
if err := utils.Verify(authorityMenu, utils.AuthorityIdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.AddMenuAuthority(addMenuAuthorityInfo.Menus, addMenuAuthorityInfo.AuthorityId)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("添加失败,%v", err), c)
|
||||
if err := service.AddMenuAuthority(authorityMenu.Menus, authorityMenu.AuthorityId); err != nil {
|
||||
global.GVA_LOG.Error("添加失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("添加失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("添加成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags authorityAndMenu
|
||||
// @Tags AuthorityMenu
|
||||
// @Summary 获取指定角色menu
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.AuthorityIdInfo true "增加menu和角色关联关系"
|
||||
// @Param data body request.GetAuthorityId true "角色ID"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /menu/GetMenuAuthority [post]
|
||||
func GetMenuAuthority(c *gin.Context) {
|
||||
var authorityIdInfo request.AuthorityIdInfo
|
||||
_ = c.ShouldBindJSON(&authorityIdInfo)
|
||||
MenuVerify := utils.Rules{
|
||||
"AuthorityId": {"notEmpty"},
|
||||
}
|
||||
MenuVerifyErr := utils.Verify(authorityIdInfo, MenuVerify)
|
||||
if MenuVerifyErr != nil {
|
||||
response.FailWithMessage(MenuVerifyErr.Error(), c)
|
||||
var param request.GetAuthorityId
|
||||
_ = c.ShouldBindJSON(¶m)
|
||||
if err := utils.Verify(param, utils.AuthorityIdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, menus := service.GetMenuAuthority(authorityIdInfo.AuthorityId)
|
||||
if err != nil {
|
||||
response.FailWithDetailed(response.ERROR, resp.SysMenusResponse{Menus: menus}, fmt.Sprintf("添加失败,%v", err), c)
|
||||
if err, menus := service.GetMenuAuthority(¶m); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithDetailed(response.SysMenusResponse{Menus: menus}, "获取失败", c)
|
||||
} else {
|
||||
response.Result(response.SUCCESS, gin.H{"menus": menus}, "获取成功", c)
|
||||
response.OkWithDetailed(gin.H{"menus": menus}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags menu
|
||||
// @Tags Menu
|
||||
// @Summary 新增菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}"
|
||||
// @Router /menu/addBaseMenu [post]
|
||||
func AddBaseMenu(c *gin.Context) {
|
||||
var menu model.SysBaseMenu
|
||||
_ = c.ShouldBindJSON(&menu)
|
||||
if err := utils.Verify(menu, utils.MenuVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err := utils.Verify(menu.Meta, utils.MenuMetaVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err := service.AddBaseMenu(menu); err != nil {
|
||||
global.GVA_LOG.Error("添加失败!", zap.Any("err", err))
|
||||
|
||||
response.FailWithMessage("添加失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("添加成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags Menu
|
||||
// @Summary 删除菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetById true "删除菜单"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body request.GetById true "菜单id"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /menu/deleteBaseMenu [post]
|
||||
func DeleteBaseMenu(c *gin.Context) {
|
||||
var idInfo request.GetById
|
||||
_ = c.ShouldBindJSON(&idInfo)
|
||||
IdVerifyErr := utils.Verify(idInfo, utils.CustomizeMap["IdVerify"])
|
||||
if IdVerifyErr != nil {
|
||||
response.FailWithMessage(IdVerifyErr.Error(), c)
|
||||
var menu request.GetById
|
||||
_ = c.ShouldBindJSON(&menu)
|
||||
if err := utils.Verify(menu, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.DeleteBaseMenu(idInfo.Id)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
|
||||
if err := service.DeleteBaseMenu(menu.ID); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags menu
|
||||
// @Tags Menu
|
||||
// @Summary 更新菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysBaseMenu true "更新菜单"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /menu/updateBaseMenu [post]
|
||||
func UpdateBaseMenu(c *gin.Context) {
|
||||
var menu model.SysBaseMenu
|
||||
_ = c.ShouldBindJSON(&menu)
|
||||
MenuVerify := utils.Rules{
|
||||
"Path": {"notEmpty"},
|
||||
"ParentId": {utils.NotEmpty()},
|
||||
"Name": {utils.NotEmpty()},
|
||||
"Component": {utils.NotEmpty()},
|
||||
"Sort": {utils.Ge("0")},
|
||||
}
|
||||
MenuVerifyErr := utils.Verify(menu, MenuVerify)
|
||||
if MenuVerifyErr != nil {
|
||||
response.FailWithMessage(MenuVerifyErr.Error(), c)
|
||||
if err := utils.Verify(menu, utils.MenuVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
MetaVerify := utils.Rules{
|
||||
"Title": {utils.NotEmpty()},
|
||||
}
|
||||
MetaVerifyErr := utils.Verify(menu.Meta, MetaVerify)
|
||||
if MetaVerifyErr != nil {
|
||||
response.FailWithMessage(MetaVerifyErr.Error(), c)
|
||||
if err := utils.Verify(menu.Meta, utils.MenuMetaVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.UpdateBaseMenu(menu)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("修改失败:%v", err), c)
|
||||
if err := service.UpdateBaseMenu(menu); err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("修改成功", c)
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags menu
|
||||
// @Tags Menu
|
||||
// @Summary 根据id获取菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetById true "根据id获取菜单"
|
||||
// @Param data body request.GetById true "菜单id"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /menu/getBaseMenuById [post]
|
||||
func GetBaseMenuById(c *gin.Context) {
|
||||
var idInfo request.GetById
|
||||
_ = c.ShouldBindJSON(&idInfo)
|
||||
MenuVerify := utils.Rules{
|
||||
"Id": {"notEmpty"},
|
||||
}
|
||||
MenuVerifyErr := utils.Verify(idInfo, MenuVerify)
|
||||
if MenuVerifyErr != nil {
|
||||
response.FailWithMessage(MenuVerifyErr.Error(), c)
|
||||
if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, menu := service.GetBaseMenuById(idInfo.Id)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("查询失败:%v", err), c)
|
||||
if err, menu := service.GetBaseMenuById(idInfo.ID); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.SysBaseMenuResponse{Menu: menu}, c)
|
||||
response.OkWithDetailed(response.SysBaseMenuResponse{Menu: menu}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags Menu
|
||||
// @Summary 分页获取基础menu列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.PageInfo true "页码, 每页大小"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /menu/getMenuList [post]
|
||||
func GetMenuList(c *gin.Context) {
|
||||
var pageInfo request.PageInfo
|
||||
_ = c.ShouldBindJSON(&pageInfo)
|
||||
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err, menuList, total := service.GetInfoList(); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: menuList,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags SysOperationRecord
|
||||
@@ -21,9 +22,9 @@ import (
|
||||
func CreateSysOperationRecord(c *gin.Context) {
|
||||
var sysOperationRecord model.SysOperationRecord
|
||||
_ = c.ShouldBindJSON(&sysOperationRecord)
|
||||
err := service.CreateSysOperationRecord(sysOperationRecord)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
|
||||
if err := service.CreateSysOperationRecord(sysOperationRecord); err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
@@ -34,15 +35,15 @@ func CreateSysOperationRecord(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysOperationRecord true "删除SysOperationRecord"
|
||||
// @Param data body model.SysOperationRecord true "SysOperationRecord模型"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
|
||||
func DeleteSysOperationRecord(c *gin.Context) {
|
||||
var sysOperationRecord model.SysOperationRecord
|
||||
_ = c.ShouldBindJSON(&sysOperationRecord)
|
||||
err := service.DeleteSysOperationRecord(sysOperationRecord)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
if err := service.DeleteSysOperationRecord(sysOperationRecord); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
@@ -54,16 +55,16 @@ func DeleteSysOperationRecord(c *gin.Context) {
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除SysOperationRecord"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
|
||||
// @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete]
|
||||
func DeleteSysOperationRecordByIds(c *gin.Context) {
|
||||
var IDS request.IdsReq
|
||||
_ = c.ShouldBindJSON(&IDS)
|
||||
err := service.DeleteSysOperationRecordByIds(IDS)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
if err := service.DeleteSysOperationRecordByIds(IDS); err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,17 +73,21 @@ func DeleteSysOperationRecordByIds(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysOperationRecord true "用id查询SysOperationRecord"
|
||||
// @Param data body model.SysOperationRecord true "Id"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /sysOperationRecord/findSysOperationRecord [get]
|
||||
func FindSysOperationRecord(c *gin.Context) {
|
||||
var sysOperationRecord model.SysOperationRecord
|
||||
_ = c.ShouldBindQuery(&sysOperationRecord)
|
||||
err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.ID)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
|
||||
if err := utils.Verify(sysOperationRecord, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.ID); err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{"resysOperationRecord": resysOperationRecord}, c)
|
||||
response.OkWithDetailed(gin.H{"resysOperationRecord": resysOperationRecord}, "查询成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,21 +96,21 @@ func FindSysOperationRecord(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.SysOperationRecordSearch true "分页获取SysOperationRecord列表"
|
||||
// @Param data body request.SysOperationRecordSearch true "页码, 每页大小, 搜索条件"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /sysOperationRecord/getSysOperationRecordList [get]
|
||||
func GetSysOperationRecordList(c *gin.Context) {
|
||||
var pageInfo request.SysOperationRecordSearch
|
||||
_ = c.ShouldBindQuery(&pageInfo)
|
||||
err, list, total := service.GetSysOperationRecordInfoList(pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
if err, list, total := service.GetSysOperationRecordInfoList(pageInfo); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.PageResult{
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
+33
-32
@@ -1,78 +1,79 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags system
|
||||
// @Tags System
|
||||
// @Summary 获取配置文件内容
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /system/getSystemConfig [post]
|
||||
func GetSystemConfig(c *gin.Context) {
|
||||
err, config := service.GetSystemConfig()
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
|
||||
if err, config := service.GetSystemConfig(); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.SysConfigResponse{Config: config}, c)
|
||||
response.OkWithDetailed(response.SysConfigResponse{Config: config}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags system
|
||||
// @Tags System
|
||||
// @Summary 设置配置文件内容
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body model.System true "设置配置文件内容"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
|
||||
// @Router /system/setSystemConfig [post]
|
||||
func SetSystemConfig(c *gin.Context) {
|
||||
var sys model.System
|
||||
_ = c.ShouldBindJSON(&sys)
|
||||
err := service.SetSystemConfig(sys)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("设置失败,%v", err), c)
|
||||
if err := service.SetSystemConfig(sys); err != nil {
|
||||
global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("设置失败", c)
|
||||
} else {
|
||||
response.OkWithData("设置成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// 本方法开发中 开发者windows系统 缺少linux系统所需的包 因此搁置
|
||||
// @Tags system
|
||||
// @Summary 设置配置文件内容
|
||||
// @Tags System
|
||||
// @Summary 重启系统
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body model.System true "设置配置文件内容"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
|
||||
// @Router /system/ReloadSystem [post]
|
||||
// @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}"
|
||||
// @Router /system/reloadSystem [post]
|
||||
func ReloadSystem(c *gin.Context) {
|
||||
var sys model.System
|
||||
_ = c.ShouldBindJSON(&sys)
|
||||
err := service.SetSystemConfig(sys)
|
||||
err := utils.Reload()
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("设置失败,%v", err), c)
|
||||
} else {
|
||||
response.OkWithMessage("设置成功", c)
|
||||
global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("重启系统失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("重启系统成功", c)
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags system
|
||||
// @Tags System
|
||||
// @Summary 获取服务器信息
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /system/getServerInfo [post]
|
||||
func GetServerInfo(c *gin.Context) {
|
||||
server, err := service.GetServerInfo()
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
|
||||
if server, err := service.GetServerInfo(); err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
} else {
|
||||
response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
|
||||
}
|
||||
response.OkDetailed(gin.H{"server":server}, "获取成功",c)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+133
-123
@@ -1,128 +1,91 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/middleware"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-redis/redis"
|
||||
"mime/multipart"
|
||||
"time"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// @Tags Base
|
||||
// @Summary 用户注册账号
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysUser true "用户注册接口"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}"
|
||||
// @Router /user/register [post]
|
||||
func Register(c *gin.Context) {
|
||||
var R request.RegisterStruct
|
||||
_ = c.ShouldBindJSON(&R)
|
||||
UserVerify := utils.Rules{
|
||||
"Username": {utils.NotEmpty()},
|
||||
"NickName": {utils.NotEmpty()},
|
||||
"Password": {utils.NotEmpty()},
|
||||
"AuthorityId": {utils.NotEmpty()},
|
||||
}
|
||||
UserVerifyErr := utils.Verify(R, UserVerify)
|
||||
if UserVerifyErr != nil {
|
||||
response.FailWithMessage(UserVerifyErr.Error(), c)
|
||||
return
|
||||
}
|
||||
user := &model.SysUser{Username: R.Username, NickName: R.NickName, Password: R.Password, HeaderImg: R.HeaderImg, AuthorityId: R.AuthorityId}
|
||||
err, userReturn := service.Register(*user)
|
||||
if err != nil {
|
||||
response.FailWithDetailed(response.ERROR, resp.SysUserResponse{User: userReturn}, fmt.Sprintf("%v", err), c)
|
||||
} else {
|
||||
response.OkDetailed(resp.SysUserResponse{User: userReturn}, "注册成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags Base
|
||||
// @Summary 用户登录
|
||||
// @Produce application/json
|
||||
// @Param data body request.RegisterAndLoginStruct true "用户登录接口"
|
||||
// @Param data body request.Login true "用户名, 密码, 验证码"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"登陆成功"}"
|
||||
// @Router /base/login [post]
|
||||
func Login(c *gin.Context) {
|
||||
var L request.RegisterAndLoginStruct
|
||||
var L request.Login
|
||||
_ = c.ShouldBindJSON(&L)
|
||||
UserVerify := utils.Rules{
|
||||
"CaptchaId": {utils.NotEmpty()},
|
||||
"Captcha": {utils.NotEmpty()},
|
||||
"Username": {utils.NotEmpty()},
|
||||
"Password": {utils.NotEmpty()},
|
||||
}
|
||||
UserVerifyErr := utils.Verify(L, UserVerify)
|
||||
if UserVerifyErr != nil {
|
||||
response.FailWithMessage(UserVerifyErr.Error(), c)
|
||||
if err := utils.Verify(L, utils.LoginVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if store.Verify(L.CaptchaId, L.Captcha, true) {
|
||||
U := &model.SysUser{Username: L.Username, Password: L.Password}
|
||||
if err, user := service.Login(U); err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("用户名密码错误或%v", err), c)
|
||||
global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误", zap.Any("err", err))
|
||||
response.FailWithMessage("用户名不存在或者密码错误", c)
|
||||
} else {
|
||||
tokenNext(c, *user)
|
||||
}
|
||||
} else {
|
||||
response.FailWithMessage("验证码错误", c)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 登录以后签发jwt
|
||||
func tokenNext(c *gin.Context, user model.SysUser) {
|
||||
j := &middleware.JWT{
|
||||
SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey), // 唯一签名
|
||||
}
|
||||
clams := request.CustomClaims{
|
||||
j := &middleware.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
|
||||
claims := request.CustomClaims{
|
||||
UUID: user.UUID,
|
||||
ID: user.ID,
|
||||
NickName: user.NickName,
|
||||
Username: user.Username,
|
||||
AuthorityId: user.AuthorityId,
|
||||
BufferTime: 60 * 60 * 24, // 缓冲时间1天 缓冲时间内会获得新的token刷新令牌 此时一个用户会存在两个有效令牌 但是前端只留一个 另一个会丢失
|
||||
BufferTime: global.GVA_CONFIG.JWT.BufferTime, // 缓冲时间1天 缓冲时间内会获得新的token刷新令牌 此时一个用户会存在两个有效令牌 但是前端只留一个 另一个会丢失
|
||||
StandardClaims: jwt.StandardClaims{
|
||||
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
|
||||
ExpiresAt: time.Now().Unix() + 60*60*24*7, // 过期时间 7天
|
||||
Issuer: "qmPlus", // 签名的发行者
|
||||
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
|
||||
ExpiresAt: time.Now().Unix() + global.GVA_CONFIG.JWT.ExpiresTime, // 过期时间 7天 配置文件
|
||||
Issuer: "qmPlus", // 签名的发行者
|
||||
},
|
||||
}
|
||||
token, err := j.CreateToken(clams)
|
||||
token, err := j.CreateToken(claims)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取token失败", zap.Any("err", err))
|
||||
response.FailWithMessage("获取token失败", c)
|
||||
return
|
||||
}
|
||||
if !global.GVA_CONFIG.System.UseMultipoint {
|
||||
response.OkWithData(resp.LoginResponse{
|
||||
response.OkWithDetailed(response.LoginResponse{
|
||||
User: user,
|
||||
Token: token,
|
||||
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
|
||||
}, c)
|
||||
ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
|
||||
}, "登录成功", c)
|
||||
return
|
||||
}
|
||||
err, jwtStr := service.GetRedisJWT(user.Username)
|
||||
if err == redis.Nil {
|
||||
if err, jwtStr := service.GetRedisJWT(user.Username); err == redis.Nil {
|
||||
if err := service.SetRedisJWT(token, user.Username); err != nil {
|
||||
global.GVA_LOG.Error("设置登录状态失败", zap.Any("err", err))
|
||||
response.FailWithMessage("设置登录状态失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(resp.LoginResponse{
|
||||
response.OkWithDetailed(response.LoginResponse{
|
||||
User: user,
|
||||
Token: token,
|
||||
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
|
||||
}, c)
|
||||
ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
|
||||
}, "登录成功", c)
|
||||
} else if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("%v", err), c)
|
||||
global.GVA_LOG.Error("设置登录状态失败", zap.Any("err", err))
|
||||
response.FailWithMessage("设置登录状态失败", c)
|
||||
} else {
|
||||
var blackJWT model.JwtBlacklist
|
||||
blackJWT.Jwt = jwtStr
|
||||
@@ -134,11 +97,34 @@ func tokenNext(c *gin.Context, user model.SysUser) {
|
||||
response.FailWithMessage("设置登录状态失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(resp.LoginResponse{
|
||||
response.OkWithDetailed(response.LoginResponse{
|
||||
User: user,
|
||||
Token: token,
|
||||
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
|
||||
}, c)
|
||||
ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
|
||||
}, "登录成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 用户注册账号
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysUser true "用户名, 昵称, 密码, 角色ID"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}"
|
||||
// @Router /user/register [post]
|
||||
func Register(c *gin.Context) {
|
||||
var R request.Register
|
||||
_ = c.ShouldBindJSON(&R)
|
||||
if err := utils.Verify(R, utils.RegisterVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
user := &model.SysUser{Username: R.Username, NickName: R.NickName, Password: R.Password, HeaderImg: R.HeaderImg, AuthorityId: R.AuthorityId}
|
||||
err, userReturn := service.Register(*user)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("注册失败", zap.Any("err", err))
|
||||
response.FailWithDetailed(response.SysUserResponse{User: userReturn}, "注册失败", c)
|
||||
} else {
|
||||
response.OkWithDetailed(response.SysUserResponse{User: userReturn}, "注册成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,60 +132,50 @@ func tokenNext(c *gin.Context, user model.SysUser) {
|
||||
// @Summary 用户修改密码
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body request.ChangePasswordStruct true "用户修改密码"
|
||||
// @Param data body request.ChangePasswordStruct true "用户名, 原密码, 新密码"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
|
||||
// @Router /user/changePassword [put]
|
||||
func ChangePassword(c *gin.Context) {
|
||||
var params request.ChangePasswordStruct
|
||||
_ = c.ShouldBindJSON(¶ms)
|
||||
UserVerify := utils.Rules{
|
||||
"Username": {utils.NotEmpty()},
|
||||
"Password": {utils.NotEmpty()},
|
||||
"NewPassword": {utils.NotEmpty()},
|
||||
}
|
||||
UserVerifyErr := utils.Verify(params, UserVerify)
|
||||
if UserVerifyErr != nil {
|
||||
response.FailWithMessage(UserVerifyErr.Error(), c)
|
||||
var user request.ChangePasswordStruct
|
||||
_ = c.ShouldBindJSON(&user)
|
||||
if err := utils.Verify(user, utils.ChangePasswordVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
U := &model.SysUser{Username: params.Username, Password: params.Password}
|
||||
if err, _ := service.ChangePassword(U, params.NewPassword); err != nil {
|
||||
response.FailWithMessage("修改失败,请检查用户名密码", c)
|
||||
U := &model.SysUser{Username: user.Username, Password: user.Password}
|
||||
if err, _ := service.ChangePassword(U, user.NewPassword); err != nil {
|
||||
global.GVA_LOG.Error("修改失败", zap.Any("err", err))
|
||||
response.FailWithMessage("修改失败,原密码与当前账户不符", c)
|
||||
} else {
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
type UserHeaderImg struct {
|
||||
HeaderImg multipart.File `json:"headerImg"`
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 分页获取用户列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.PageInfo true "分页获取用户列表"
|
||||
// @Param data body request.PageInfo true "页码, 每页大小"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /user/getUserList [post]
|
||||
func GetUserList(c *gin.Context) {
|
||||
var pageInfo request.PageInfo
|
||||
_ = c.ShouldBindJSON(&pageInfo)
|
||||
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
|
||||
if PageVerifyErr != nil {
|
||||
response.FailWithMessage(PageVerifyErr.Error(), c)
|
||||
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err, list, total := service.GetUserInfoList(pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
if err, list, total := service.GetUserInfoList(pageInfo); err != nil {
|
||||
global.GVA_LOG.Error("获取失败", zap.Any("err", err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
} else {
|
||||
response.OkWithData(resp.PageResult{
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}, "获取成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,24 +184,19 @@ func GetUserList(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.SetUserAuth true "设置用户权限"
|
||||
// @Param data body request.SetUserAuth true "用户UUID, 角色ID"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
|
||||
// @Router /user/setUserAuthority [post]
|
||||
func SetUserAuthority(c *gin.Context) {
|
||||
var sua request.SetUserAuth
|
||||
_ = c.ShouldBindJSON(&sua)
|
||||
UserVerify := utils.Rules{
|
||||
"UUID": {utils.NotEmpty()},
|
||||
"AuthorityId": {utils.NotEmpty()},
|
||||
}
|
||||
UserVerifyErr := utils.Verify(sua, UserVerify)
|
||||
if UserVerifyErr != nil {
|
||||
if UserVerifyErr := utils.Verify(sua, utils.SetUserAuthorityVerify); UserVerifyErr != nil {
|
||||
response.FailWithMessage(UserVerifyErr.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.SetUserAuthority(sua.UUID, sua.AuthorityId)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("修改失败,%v", err), c)
|
||||
if err := service.SetUserAuthority(sua.UUID, sua.AuthorityId); err != nil {
|
||||
global.GVA_LOG.Error("修改失败", zap.Any("err", err))
|
||||
response.FailWithMessage("修改失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
@@ -236,42 +207,81 @@ func SetUserAuthority(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetById true "删除用户"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
|
||||
// @Param data body request.GetById true "用户ID"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /user/deleteUser [delete]
|
||||
func DeleteUser(c *gin.Context) {
|
||||
var reqId request.GetById
|
||||
_ = c.ShouldBindJSON(&reqId)
|
||||
IdVerifyErr := utils.Verify(reqId, utils.CustomizeMap["IdVerify"])
|
||||
if IdVerifyErr != nil {
|
||||
response.FailWithMessage(IdVerifyErr.Error(), c)
|
||||
if err := utils.Verify(reqId, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.DeleteUser(reqId.Id)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
jwtId := getUserID(c)
|
||||
if jwtId == uint(reqId.ID) {
|
||||
response.FailWithMessage("删除失败, 自杀失败", c)
|
||||
return
|
||||
}
|
||||
if err := service.DeleteUser(reqId.ID); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags SysUser
|
||||
// @Summary 删除用户
|
||||
// @Summary 设置用户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysUser true "删除用户"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
|
||||
// @Param data body model.SysUser true "ID, 用户名, 昵称, 头像链接"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
|
||||
// @Router /user/setUserInfo [put]
|
||||
func SetUserInfo(c *gin.Context) {
|
||||
var user model.SysUser
|
||||
c.ShouldBindJSON(&user)
|
||||
err, ReqUser := service.SetUserInfo(user)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
|
||||
_ = c.ShouldBindJSON(&user)
|
||||
if err := utils.Verify(user, utils.IdVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err, ReqUser := service.SetUserInfo(user); err != nil {
|
||||
global.GVA_LOG.Error("设置失败", zap.Any("err", err))
|
||||
response.FailWithMessage("设置失败", c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{
|
||||
"userInfo": ReqUser,
|
||||
}, c)
|
||||
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "设置成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// 从Gin的Context中获取从jwt解析出来的用户ID
|
||||
func getUserID(c *gin.Context) uint {
|
||||
if claims, exists := c.Get("claims"); !exists {
|
||||
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件")
|
||||
return 0
|
||||
} else {
|
||||
waitUse := claims.(*request.CustomClaims)
|
||||
return waitUse.ID
|
||||
}
|
||||
}
|
||||
|
||||
// 从Gin的Context中获取从jwt解析出来的用户UUID
|
||||
func getUserUuid(c *gin.Context) string {
|
||||
if claims, exists := c.Get("claims"); !exists {
|
||||
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件")
|
||||
return ""
|
||||
} else {
|
||||
waitUse := claims.(*request.CustomClaims)
|
||||
return waitUse.UUID.String()
|
||||
}
|
||||
}
|
||||
|
||||
// 从Gin的Context中获取从jwt解析出来的用户角色id
|
||||
func getUserAuthorityId(c *gin.Context) string {
|
||||
if claims, exists := c.Get("claims"); !exists {
|
||||
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件")
|
||||
return ""
|
||||
} else {
|
||||
waitUse := claims.(*request.CustomClaims)
|
||||
return waitUse.AuthorityId
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/service"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Tags workflow
|
||||
// @Summary 注册工作流
|
||||
// @Produce application/json
|
||||
// @Param data body model.SysWorkflow true "注册工作流接口"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}"
|
||||
// @Router /workflow/createWorkFlow [post]
|
||||
func CreateWorkFlow(c *gin.Context) {
|
||||
var wk model.SysWorkflow
|
||||
_ = c.ShouldBindJSON(&wk)
|
||||
WKVerify := utils.Rules{
|
||||
"WorkflowNickName": {utils.NotEmpty()},
|
||||
"WorkflowName": {utils.NotEmpty()},
|
||||
"WorkflowDescription": {utils.NotEmpty()},
|
||||
"WorkflowStepInfo": {utils.NotEmpty()},
|
||||
}
|
||||
WKVerifyErr := utils.Verify(wk, WKVerify)
|
||||
if WKVerifyErr != nil {
|
||||
response.FailWithMessage(WKVerifyErr.Error(), c)
|
||||
return
|
||||
}
|
||||
err := service.Create(wk)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
|
||||
} else {
|
||||
response.OkWithMessage("获取成功", c)
|
||||
}
|
||||
}
|
||||
+69
-44
@@ -3,6 +3,8 @@
|
||||
# jwt configuration
|
||||
jwt:
|
||||
signing-key: 'qmPlus'
|
||||
expires-time: 604800
|
||||
buffer-time: 86400
|
||||
|
||||
# zap logger configuration
|
||||
zap:
|
||||
@@ -41,8 +43,7 @@ system:
|
||||
env: 'public' # Change to "develop" to skip authentication for development mode
|
||||
addr: 8888
|
||||
db-type: 'mysql'
|
||||
oss-type: 'local'
|
||||
need-init-data: false
|
||||
oss-type: 'local' # 控制oss选择走本期还是 七牛等其他仓 自行增加其他oss仓可以在 server/utils/upload/upload.go 中 NewOss函数配置
|
||||
use-multipoint: false
|
||||
|
||||
# captcha configuration
|
||||
@@ -53,55 +54,79 @@ captcha:
|
||||
|
||||
# mysql connect configuration
|
||||
mysql:
|
||||
path: '127.0.0.1:3306'
|
||||
config: 'charset=utf8mb4&parseTime=True&loc=Local'
|
||||
db-name: 'qmPlus'
|
||||
username: 'root'
|
||||
password: 'Aa@6447985'
|
||||
path: ''
|
||||
config: ''
|
||||
db-name: ''
|
||||
username: ''
|
||||
password: ''
|
||||
max-idle-conns: 10
|
||||
max-open-conns: 10
|
||||
max-open-conns: 100
|
||||
log-mode: false
|
||||
|
||||
# sqlite connect configuration (sqlite需要gcc支持 windows用户需要自行安装gcc)
|
||||
sqlite:
|
||||
path: 'db.db'
|
||||
max-idle-conns: 10
|
||||
max-open-conns: 10
|
||||
logger: true
|
||||
|
||||
# Sqlserver connect configuration
|
||||
sqlserver:
|
||||
path: 'localhost:9930'
|
||||
db-name: 'gorm'
|
||||
username: 'gorm'
|
||||
password: 'LoremIpsum86'
|
||||
max-idle-conns: 10
|
||||
max-open-conns: 10
|
||||
logger: true
|
||||
|
||||
# Postgresql connect configuration
|
||||
postgresql:
|
||||
host: '127.0.0.1'
|
||||
port: '9920'
|
||||
config: 'sslmode=disable TimeZone=Asia/Shanghai'
|
||||
db-name: 'gorm'
|
||||
username: 'gorm'
|
||||
password: 'gorm'
|
||||
max-idle-conns: 10
|
||||
max-open-conns: 10
|
||||
prefer-simple-protocol: true
|
||||
logger: false
|
||||
log-zap: ""
|
||||
|
||||
# local configuration
|
||||
local:
|
||||
path: 'uploads/file'
|
||||
|
||||
# autocode configuration
|
||||
autocode:
|
||||
transfer-restart: true
|
||||
root: ""
|
||||
server: /server
|
||||
server-api: /api/v1
|
||||
server-initialize: /initialize
|
||||
server-model: /model
|
||||
server-request: /model/request/
|
||||
server-router: /router
|
||||
server-service: /service
|
||||
web: /web/src
|
||||
web-api: /api
|
||||
web-flow: /view
|
||||
web-form: /view
|
||||
web-table: /view
|
||||
|
||||
# qiniu configuration (请自行七牛申请对应的 公钥 私钥 bucket 和 域名地址)
|
||||
qiniu:
|
||||
zone: 'ZoneHuadong'
|
||||
bucket: 'qm-plus-img'
|
||||
img-path: 'http://qmplusimg.henrongyi.top'
|
||||
zone: 'ZoneHuaDong'
|
||||
bucket: ''
|
||||
img-path: ''
|
||||
use-https: false
|
||||
access-key: '25j8dYBZ2wuiy0yhwShytjZDTX662b8xiFguwxzZ'
|
||||
secret-key: 'pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY'
|
||||
use-cdn-domains: false
|
||||
access-key: ''
|
||||
secret-key: ''
|
||||
use-cdn-domains: false
|
||||
|
||||
|
||||
# aliyun oss configuration
|
||||
aliyun-oss:
|
||||
endpoint: 'yourEndpoint'
|
||||
access-key-id: 'yourAccessKeyId'
|
||||
access-key-secret: 'yourAccessKeySecret'
|
||||
bucket-name: 'yourBucketName'
|
||||
bucket-url: 'yourBucketUrl'
|
||||
|
||||
# tencent cos configuration
|
||||
tencent-cos:
|
||||
bucket: 'xxxxx-10005608'
|
||||
region: 'ap-shanghai'
|
||||
secret-id: 'xxxxxxxx'
|
||||
secret-key: 'xxxxxxxx'
|
||||
base-url: 'https://gin.vue.admin'
|
||||
path-prefix: 'gin-vue-admin'
|
||||
|
||||
# excel configuration
|
||||
excel:
|
||||
dir: './resource/excel/'
|
||||
|
||||
|
||||
# timer task db clear table
|
||||
Timer:
|
||||
start: true
|
||||
spec: "@daily" # 定时任务详细配置参考 https://pkg.go.dev/github.com/robfig/cron/v3
|
||||
detail: [
|
||||
# tableName: 需要清理的表名
|
||||
# compareField: 需要比较时间的字段
|
||||
# interval: 时间间隔, 具体配置详看 time.ParseDuration() 中字符串表示 且不能为负数
|
||||
# 2160h = 24 * 30 * 3 -> 三个月
|
||||
{ tableName: "sys_operation_records" , compareField: "created_at", interval: "2160h" },
|
||||
#{ tableName: "log2" , compareField: "created_at", interval: "2160h" }
|
||||
]
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package config
|
||||
|
||||
type Autocode struct {
|
||||
TransferRestart bool `mapstructure:"transfer-restart" json:"transferRestart" yaml:"transfer-restart"`
|
||||
Root string `mapstructure:"root" json:"root" yaml:"root"`
|
||||
Server string `mapstructure:"server" json:"server" yaml:"server"`
|
||||
SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"`
|
||||
SInitialize string `mapstructure:"server-initialize" json:"serverInitialize" yaml:"server-initialize"`
|
||||
SModel string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"`
|
||||
SRequest string `mapstructure:"server-request" json:"serverRequest" yaml:"server-request"`
|
||||
SRouter string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"`
|
||||
SService string `mapstructure:"server-service" json:"serverService" yaml:"server-service"`
|
||||
Web string `mapstructure:"web" json:"web" yaml:"web"`
|
||||
WApi string `mapstructure:"web-api" json:"webApi" yaml:"web-api"`
|
||||
WForm string `mapstructure:"web-form" json:"webForm" yaml:"web-form"`
|
||||
WTable string `mapstructure:"web-table" json:"webTable" yaml:"web-table"`
|
||||
WFlow string `mapstructure:"web-flow" json:"webFlow" yaml:"web-flow"`
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package config
|
||||
|
||||
type Captcha struct {
|
||||
KeyLong int `mapstructure:"key-long" json:"keyLong" yaml:"key-long"`
|
||||
ImgWidth int `mapstructure:"img-width" json:"imgWidth" yaml:"img-width"`
|
||||
ImgHeight int `mapstructure:"img-height" json:"imgHeight" yaml:"img-height"`
|
||||
KeyLong int `mapstructure:"key-long" json:"keyLong" yaml:"key-long"` // 验证码长度
|
||||
ImgWidth int `mapstructure:"img-width" json:"imgWidth" yaml:"img-width"` // 验证码宽度
|
||||
ImgHeight int `mapstructure:"img-height" json:"imgHeight" yaml:"img-height"` // 验证码高度
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package config
|
||||
|
||||
type Casbin struct {
|
||||
ModelPath string `mapstructure:"model-path" json:"modelPath" yaml:"model-path"`
|
||||
ModelPath string `mapstructure:"model-path" json:"modelPath" yaml:"model-path"` // 存放casbin模型的相对路径
|
||||
}
|
||||
|
||||
@@ -8,12 +8,15 @@ type Server struct {
|
||||
Casbin Casbin `mapstructure:"casbin" json:"casbin" yaml:"casbin"`
|
||||
System System `mapstructure:"system" json:"system" yaml:"system"`
|
||||
Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"`
|
||||
// auto
|
||||
AutoCode Autocode `mapstructure:"autoCode" json:"autoCode" yaml:"autoCode"`
|
||||
// gorm
|
||||
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
|
||||
Sqlite Sqlite `mapstructure:"sqlite" json:"sqlite" yaml:"sqlite"`
|
||||
Sqlserver Sqlserver `mapstructure:"sqlserver" json:"sqlserver" yaml:"sqlserver"`
|
||||
Postgresql Postgresql `mapstructure:"postgresql" json:"postgresql" yaml:"postgresql"`
|
||||
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
|
||||
// oss
|
||||
Local Local `mapstructure:"local" json:"local" yaml:"local"`
|
||||
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
|
||||
Local Local `mapstructure:"local" json:"local" yaml:"local"`
|
||||
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
|
||||
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
|
||||
TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"`
|
||||
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
|
||||
Timer Timer `mapstructure:"timer" json:"timer" yaml:"timer"`
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package config
|
||||
|
||||
type Email struct {
|
||||
To string `mapstructure:"to" json:"to" yaml:"to"`
|
||||
Port int `mapstructure:"port" json:"port" yaml:"port"`
|
||||
From string `mapstructure:"from" json:"from" yaml:"from"`
|
||||
Host string `mapstructure:"host" json:"host" yaml:"host"`
|
||||
IsSSL bool `mapstructure:"is-ssl" json:"isSSL" yaml:"is-ssl"`
|
||||
Secret string `mapstructure:"secret" json:"secret" yaml:"secret"`
|
||||
Nickname string `mapstructure:"nickname" json:"nickname" yaml:"nickname"`
|
||||
To string `mapstructure:"to" json:"to" yaml:"to"` // 收件人:多个以英文逗号分隔
|
||||
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口
|
||||
From string `mapstructure:"from" json:"from" yaml:"from"` // 收件人
|
||||
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址
|
||||
IsSSL bool `mapstructure:"is-ssl" json:"isSSL" yaml:"is-ssl"` // 是否SSL
|
||||
Secret string `mapstructure:"secret" json:"secret" yaml:"secret"` // 密钥
|
||||
Nickname string `mapstructure:"nickname" json:"nickname" yaml:"nickname"` // 昵称
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package config
|
||||
|
||||
type Excel struct {
|
||||
Dir string `mapstructure:"dir" json:"dir" yaml:"dir"`
|
||||
}
|
||||
+11
-37
@@ -1,43 +1,17 @@
|
||||
package config
|
||||
|
||||
type Mysql struct {
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"`
|
||||
Config string `mapstructure:"config" json:"config" yaml:"config"`
|
||||
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"`
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"`
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"`
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
|
||||
LogMode bool `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"`
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址:端口
|
||||
Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
|
||||
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"` // 数据库名
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` // 空闲中的最大连接数
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
|
||||
LogMode bool `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` // 是否开启Gorm全局日志
|
||||
LogZap string `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"`
|
||||
}
|
||||
|
||||
type Sqlite struct {
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"`
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
|
||||
Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"`
|
||||
func (m *Mysql) Dsn() string {
|
||||
return m.Username + ":" + m.Password + "@tcp(" + m.Path + ")/" + m.Dbname + "?" + m.Config
|
||||
}
|
||||
|
||||
type Sqlserver struct {
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"`
|
||||
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"`
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"`
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"`
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
|
||||
Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"`
|
||||
}
|
||||
|
||||
type Postgresql struct {
|
||||
Host string `mapstructure:"host" json:"host" yaml:"host"`
|
||||
Port string `mapstructure:"port" json:"port" yaml:"port"`
|
||||
Config string `mapstructure:"config" json:"config" yaml:"config"`
|
||||
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"`
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"`
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"`
|
||||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
|
||||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
|
||||
PreferSimpleProtocol bool `mapstructure:"prefer-simple-protocol" json:"preferSimpleProtocol" yaml:"prefer-simple-protocol"`
|
||||
Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"`
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package config
|
||||
|
||||
type JWT struct {
|
||||
SigningKey string `mapstructure:"signing-key" json:"signingKey" yaml:"signing-key"`
|
||||
SigningKey string `mapstructure:"signing-key" json:"signingKey" yaml:"signing-key"` // jwt签名
|
||||
ExpiresTime int64 `mapstructure:"expires-time" json:"expiresTime" yaml:"expires-time"` // 过期时间
|
||||
BufferTime int64 `mapstructure:"buffer-time" json:"bufferTime" yaml:"buffer-time"` // 缓冲时间
|
||||
}
|
||||
|
||||
+24
-8
@@ -1,15 +1,31 @@
|
||||
package config
|
||||
|
||||
type Local struct {
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path" `
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件路径
|
||||
}
|
||||
|
||||
type Qiniu struct {
|
||||
Zone string `mapstructure:"zone" json:"zone" yaml:"zone"`
|
||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
|
||||
ImgPath string `mapstructure:"img-path" json:"imgPath" yaml:"img-path"`
|
||||
UseHTTPS bool `mapstructure:"use-https" json:"useHttps" yaml:"use-https"`
|
||||
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"`
|
||||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
|
||||
UseCdnDomains bool `mapstructure:"use-cdn-domains" json:"useCdnDomains" yaml:"use-cdn-domains"`
|
||||
Zone string `mapstructure:"zone" json:"zone" yaml:"zone"` // 存储区域
|
||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` // 空间名称
|
||||
ImgPath string `mapstructure:"img-path" json:"imgPath" yaml:"img-path"` // CDN加速域名
|
||||
UseHTTPS bool `mapstructure:"use-https" json:"useHttps" yaml:"use-https"` // 是否使用https
|
||||
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"` // 秘钥AK
|
||||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"` // 秘钥SK
|
||||
UseCdnDomains bool `mapstructure:"use-cdn-domains" json:"useCdnDomains" yaml:"use-cdn-domains"` // 上传是否使用CDN上传加速
|
||||
}
|
||||
|
||||
type AliyunOSS struct {
|
||||
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"`
|
||||
AccessKeyId string `mapstructure:"access-key-id" json:"accessKeyId" yaml:"access-key-id"`
|
||||
AccessKeySecret string `mapstructure:"access-key-secret" json:"accessKeySecret" yaml:"access-key-secret"`
|
||||
BucketName string `mapstructure:"bucket-name" json:"bucketName" yaml:"bucket-name"`
|
||||
BucketUrl string `mapstructure:"bucket-url" json:"bucketUrl" yaml:"bucket-url"`
|
||||
}
|
||||
type TencentCOS struct {
|
||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
|
||||
Region string `mapstructure:"region" json:"region" yaml:"region"`
|
||||
SecretID string `mapstructure:"secret-id" json:"secretID" yaml:"secret-id"`
|
||||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"`
|
||||
BaseURL string `mapstructure:"base-url" json:"baseURL" yaml:"base-url"`
|
||||
PathPrefix string `mapstructure:"path-prefix" json:"pathPrefix" yaml:"path-prefix"`
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package config
|
||||
|
||||
type Redis struct {
|
||||
DB int `mapstructure:"db" json:"db" yaml:"db"`
|
||||
Addr string `mapstructure:"addr" json:"addr" yaml:"addr"`
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"`
|
||||
}
|
||||
DB int `mapstructure:"db" json:"db" yaml:"db"` // redis的哪个数据库
|
||||
Addr string `mapstructure:"addr" json:"addr" yaml:"addr"` // 服务器地址:端口
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 密码
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package config
|
||||
|
||||
type System struct {
|
||||
Env string `mapstructure:"env" json:"env" yaml:"env"`
|
||||
Addr int `mapstructure:"addr" json:"addr" yaml:"addr"`
|
||||
DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"`
|
||||
OssType string `mapstructure:"oss-type" json:"ossType" yaml:"oss-type"`
|
||||
NeedInitData bool `mapstructure:"need-init-data" json:"needInitData" yaml:"need-init-data"`
|
||||
UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint" yaml:"use-multipoint"`
|
||||
Env string `mapstructure:"env" json:"env" yaml:"env"` // 环境值
|
||||
Addr int `mapstructure:"addr" json:"addr" yaml:"addr"` // 端口值
|
||||
DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"` // 数据库类型:mysql(默认)|sqlite|sqlserver|postgresql
|
||||
OssType string `mapstructure:"oss-type" json:"ossType" yaml:"oss-type"` // Oss类型
|
||||
UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint" yaml:"use-multipoint"` // 多点登录拦截
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package config
|
||||
|
||||
type Timer struct {
|
||||
Start bool `mapstructure:"start" json:"start" yaml:"start"` // 是否启用
|
||||
Spec string `mapstructure:"spec" json:"spec" yaml:"spec"` // CRON表达式
|
||||
Detail []Detail `mapstructure:"detail" json:"detail" yaml:"detail"`
|
||||
}
|
||||
|
||||
type Detail struct {
|
||||
TableName string `mapstructure:"tableName" json:"tableName" yaml:"tableName"` // 需要清理的表名
|
||||
CompareField string `mapstructure:"compareField" json:"compareField" yaml:"compareField"` // 需要比较时间的字段
|
||||
Interval string `mapstructure:"interval" json:"interval" yaml:"interval"` // 时间间隔
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package config
|
||||
|
||||
type Zap struct {
|
||||
Level string `mapstructure:"level" json:"level" yaml:"level"`
|
||||
Format string `mapstructure:"format" json:"format" yaml:"format"`
|
||||
Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"`
|
||||
Director string `mapstructure:"director" json:"director" yaml:"director"`
|
||||
LinkName string `mapstructure:"link-name" json:"linkName" yaml:"link-name"`
|
||||
ShowLine bool `mapstructure:"show-line" json:"showLine" yaml:"showLine"`
|
||||
EncodeLevel string `mapstructure:"encode-level" json:"encodeLevel" yaml:"encode-level"`
|
||||
StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktraceKey" yaml:"stacktrace-key"`
|
||||
LogInConsole bool `mapstructure:"log-in-console" json:"logInConsole" yaml:"log-in-console"`
|
||||
Level string `mapstructure:"level" json:"level" yaml:"level"` // 级别
|
||||
Format string `mapstructure:"format" json:"format" yaml:"format"` // 输出
|
||||
Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"` // 日志前缀
|
||||
Director string `mapstructure:"director" json:"director" yaml:"director"` // 日志文件夹
|
||||
LinkName string `mapstructure:"link-name" json:"linkName" yaml:"link-name"` // 软链接名称
|
||||
ShowLine bool `mapstructure:"show-line" json:"showLine" yaml:"showLine"` // 显示行
|
||||
EncodeLevel string `mapstructure:"encode-level" json:"encodeLevel" yaml:"encode-level"` // 编码级
|
||||
StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktraceKey" yaml:"stacktrace-key"` // 栈名
|
||||
LogInConsole bool `mapstructure:"log-in-console" json:"logInConsole" yaml:"log-in-console"` // 输出控制台
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"gin-vue-admin/global"
|
||||
_ "gin-vue-admin/packfile"
|
||||
"gin-vue-admin/utils"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
)
|
||||
|
||||
var config string
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&config, "c", "", "choose config file.")
|
||||
flag.Parse()
|
||||
if config == "" { // 优先级: 命令行 > 环境变量 > 默认值
|
||||
if configEnv := os.Getenv(utils.ConfigEnv); configEnv == "" {
|
||||
config = utils.ConfigFile
|
||||
fmt.Printf("您正在使用config的默认值,config的路径为%v\n", utils.ConfigFile)
|
||||
} else {
|
||||
config = configEnv
|
||||
fmt.Printf("您正在使用GVA_CONFIG环境变量,config的路径为%v\n", config)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("您正在使用命令行的-c参数传递的值,config的路径为%v\n", config)
|
||||
}
|
||||
v := viper.New()
|
||||
v.SetConfigFile(config)
|
||||
err := v.ReadInConfig()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
||||
}
|
||||
v.WatchConfig()
|
||||
|
||||
v.OnConfigChange(func(e fsnotify.Event) {
|
||||
fmt.Println("config file changed:", e.Name)
|
||||
if err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
})
|
||||
if err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
global.GVA_VP = v
|
||||
}
|
||||
@@ -29,9 +29,11 @@ func RunWindowsServer() {
|
||||
|
||||
fmt.Printf(`
|
||||
欢迎使用 Gin-Vue-Admin
|
||||
当前版本:V2.3.3
|
||||
当前版本:V2.4.2
|
||||
加群方式:微信号:shouzi_1994 QQ群:622360840
|
||||
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
|
||||
默认前端文件运行地址:http://127.0.0.1:8080
|
||||
如果项目让您获得了收益,希望您能请团队喝杯可乐:https://www.gin-vue-admin.com/docs/coffee
|
||||
`, address)
|
||||
global.GVA_LOG.Error(s.ListenAndServe().Error())
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@ func initServer(address string, router *gin.Engine) server {
|
||||
s.WriteTimeout = 10 * time.Second
|
||||
s.MaxHeaderBytes = 1 << 20
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,4 @@ func initServer(address string, router *gin.Engine) server {
|
||||
WriteTimeout: 10 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"gin-vue-admin/global"
|
||||
_ "gin-vue-admin/packfile"
|
||||
"gin-vue-admin/utils"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func Viper(path ...string) *viper.Viper {
|
||||
var config string
|
||||
if len(path) == 0 {
|
||||
flag.StringVar(&config, "c", "", "choose config file.")
|
||||
flag.Parse()
|
||||
if config == "" { // 优先级: 命令行 > 环境变量 > 默认值
|
||||
if configEnv := os.Getenv(utils.ConfigEnv); configEnv == "" {
|
||||
config = utils.ConfigFile
|
||||
fmt.Printf("您正在使用config的默认值,config的路径为%v\n", utils.ConfigFile)
|
||||
} else {
|
||||
config = configEnv
|
||||
fmt.Printf("您正在使用GVA_CONFIG环境变量,config的路径为%v\n", config)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("您正在使用命令行的-c参数传递的值,config的路径为%v\n", config)
|
||||
}
|
||||
} else {
|
||||
config = path[0]
|
||||
fmt.Printf("您正在使用func Viper()传递的值,config的路径为%v\n", config)
|
||||
}
|
||||
|
||||
v := viper.New()
|
||||
v.SetConfigFile(config)
|
||||
v.SetConfigType("yaml")
|
||||
err := v.ReadInConfig()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
||||
}
|
||||
v.WatchConfig()
|
||||
|
||||
v.OnConfigChange(func(e fsnotify.Event) {
|
||||
fmt.Println("config file changed:", e.Name)
|
||||
if err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
})
|
||||
if err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..")
|
||||
return v
|
||||
}
|
||||
+14
-31
@@ -4,20 +4,15 @@ import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/utils"
|
||||
zaprotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
err error
|
||||
level zapcore.Level
|
||||
writer zapcore.WriteSyncer
|
||||
)
|
||||
var level zapcore.Level
|
||||
|
||||
func init() {
|
||||
func Zap() (logger *zap.Logger) {
|
||||
if ok, _ := utils.PathExists(global.GVA_CONFIG.Zap.Director); !ok { // 判断是否有Director文件夹
|
||||
fmt.Printf("create %v directory\n", global.GVA_CONFIG.Zap.Director)
|
||||
_ = os.Mkdir(global.GVA_CONFIG.Zap.Director, os.ModePerm)
|
||||
@@ -42,34 +37,15 @@ func init() {
|
||||
level = zap.InfoLevel
|
||||
}
|
||||
|
||||
writer, err = getWriteSyncer() // 使用file-rotatelogs进行日志分割
|
||||
if err != nil {
|
||||
fmt.Printf("Get Write Syncer Failed err:%v", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if level == zap.DebugLevel || level == zap.ErrorLevel {
|
||||
global.GVA_LOG = zap.New(getEncoderCore(), zap.AddStacktrace(level))
|
||||
logger = zap.New(getEncoderCore(), zap.AddStacktrace(level))
|
||||
} else {
|
||||
global.GVA_LOG = zap.New(getEncoderCore())
|
||||
logger = zap.New(getEncoderCore())
|
||||
}
|
||||
if global.GVA_CONFIG.Zap.ShowLine {
|
||||
global.GVA_LOG.WithOptions(zap.AddCaller())
|
||||
logger = logger.WithOptions(zap.AddCaller())
|
||||
}
|
||||
}
|
||||
|
||||
// getWriteSyncer zap logger中加入file-rotatelogs
|
||||
func getWriteSyncer() (zapcore.WriteSyncer, error) {
|
||||
fileWriter, err := zaprotatelogs.New(
|
||||
global.GVA_CONFIG.Zap.Director+string(os.PathSeparator)+"%Y-%m-%d.log",
|
||||
zaprotatelogs.WithLinkName(global.GVA_CONFIG.Zap.LinkName),
|
||||
zaprotatelogs.WithMaxAge(7*24*time.Hour),
|
||||
zaprotatelogs.WithRotationTime(24*time.Hour),
|
||||
)
|
||||
if global.GVA_CONFIG.Zap.LogInConsole {
|
||||
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
|
||||
}
|
||||
return zapcore.AddSync(fileWriter), err
|
||||
return logger
|
||||
}
|
||||
|
||||
// getEncoderConfig 获取zapcore.EncoderConfig
|
||||
@@ -87,7 +63,7 @@ func getEncoderConfig() (config zapcore.EncoderConfig) {
|
||||
EncodeDuration: zapcore.SecondsDurationEncoder,
|
||||
EncodeCaller: zapcore.FullCallerEncoder,
|
||||
}
|
||||
switch {
|
||||
switch {
|
||||
case global.GVA_CONFIG.Zap.EncodeLevel == "LowercaseLevelEncoder": // 小写编码器(默认)
|
||||
config.EncodeLevel = zapcore.LowercaseLevelEncoder
|
||||
case global.GVA_CONFIG.Zap.EncodeLevel == "LowercaseColorLevelEncoder": // 小写编码器带颜色
|
||||
@@ -96,6 +72,8 @@ func getEncoderConfig() (config zapcore.EncoderConfig) {
|
||||
config.EncodeLevel = zapcore.CapitalLevelEncoder
|
||||
case global.GVA_CONFIG.Zap.EncodeLevel == "CapitalColorLevelEncoder": // 大写编码器带颜色
|
||||
config.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||
default:
|
||||
config.EncodeLevel = zapcore.LowercaseLevelEncoder
|
||||
}
|
||||
return config
|
||||
}
|
||||
@@ -110,6 +88,11 @@ func getEncoder() zapcore.Encoder {
|
||||
|
||||
// getEncoderCore 获取Encoder的zapcore.Core
|
||||
func getEncoderCore() (core zapcore.Core) {
|
||||
writer, err := utils.GetWriteSyncer() // 使用file-rotatelogs进行日志分割
|
||||
if err != nil {
|
||||
fmt.Printf("Get Write Syncer Failed err:%v", err.Error())
|
||||
return
|
||||
}
|
||||
return zapcore.NewCore(getEncoder(), writer, level)
|
||||
}
|
||||
|
||||
|
||||
+1023
-371
File diff suppressed because it is too large
Load Diff
+1022
-370
File diff suppressed because it is too large
Load Diff
+786
-306
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,12 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"gin-vue-admin/utils/timer"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"gin-vue-admin/config"
|
||||
|
||||
"github.com/go-redis/redis"
|
||||
"github.com/spf13/viper"
|
||||
"gorm.io/gorm"
|
||||
@@ -15,5 +18,6 @@ var (
|
||||
GVA_CONFIG config.Server
|
||||
GVA_VP *viper.Viper
|
||||
//GVA_LOG *oplogging.Logger
|
||||
GVA_LOG *zap.Logger
|
||||
GVA_LOG *zap.Logger
|
||||
GVA_Timer timer.Timer = timer.NewTimerTask()
|
||||
)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type GVA_MODEL struct {
|
||||
ID uint `gorm:"primarykey"` // 主键ID
|
||||
CreatedAt time.Time // 创建时间
|
||||
UpdatedAt time.Time // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // 删除时间
|
||||
}
|
||||
+13
-10
@@ -1,11 +1,13 @@
|
||||
module gin-vue-admin
|
||||
|
||||
go 1.12
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.2
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
|
||||
github.com/casbin/casbin v1.9.1
|
||||
github.com/aliyun/aliyun-oss-go-sdk v2.1.6+incompatible
|
||||
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
|
||||
github.com/casbin/casbin/v2 v2.11.0
|
||||
github.com/casbin/gorm-adapter/v3 v3.0.2
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
@@ -20,6 +22,7 @@ require (
|
||||
github.com/go-redis/redis v6.15.7+incompatible
|
||||
github.com/go-sql-driver/mysql v1.5.0
|
||||
github.com/golang/protobuf v1.4.2 // indirect
|
||||
github.com/gookit/color v1.3.1
|
||||
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
|
||||
github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84
|
||||
github.com/json-iterator/go v1.1.10 // indirect
|
||||
@@ -33,25 +36,25 @@ require (
|
||||
github.com/pelletier/go-toml v1.6.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/qiniu/api.v7/v7 v7.4.1
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/shirou/gopsutil v2.20.8+incompatible
|
||||
github.com/shirou/gopsutil v3.21.1+incompatible
|
||||
github.com/spf13/afero v1.2.2 // indirect
|
||||
github.com/spf13/cast v1.3.1 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/viper v1.6.2
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/spf13/viper v1.7.0
|
||||
github.com/swaggo/gin-swagger v1.2.0
|
||||
github.com/swaggo/swag v1.6.7
|
||||
github.com/tebeka/strftime v0.1.3 // indirect
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.19
|
||||
github.com/unrolled/secure v1.0.7
|
||||
go.uber.org/zap v1.10.0
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
|
||||
golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
|
||||
golang.org/x/tools v0.0.0-20200324003944-a576cf524670 // indirect
|
||||
google.golang.org/protobuf v1.24.0 // indirect
|
||||
gopkg.in/ini.v1 v1.55.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
||||
gorm.io/driver/mysql v0.3.0
|
||||
gorm.io/driver/postgres v0.2.6
|
||||
gorm.io/driver/sqlserver v0.2.4
|
||||
gorm.io/gorm v1.20.1
|
||||
gorm.io/driver/mysql v1.0.1
|
||||
gorm.io/gorm v1.20.7
|
||||
)
|
||||
|
||||
@@ -1,497 +0,0 @@
|
||||
package init_data
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
gormadapter "github.com/casbin/gorm-adapter/v3"
|
||||
"github.com/satori/go.uuid"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SysAuthorityMenus struct {
|
||||
SysAuthorityAuthorityId string
|
||||
SysBaseMenuId uint
|
||||
}
|
||||
|
||||
type SysDataAuthorityId struct {
|
||||
SysAuthorityAuthorityId string
|
||||
DataAuthorityIdAuthorityId string
|
||||
}
|
||||
|
||||
func InitSysApi() (err error) {
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []model.SysApi{
|
||||
{gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/login", "用户登录", "base", "POST"},
|
||||
{gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/register", "用户注册", "user", "POST"},
|
||||
{gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/createApi", "创建api", "api", "POST"},
|
||||
{gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiList", "获取api列表", "api", "POST"},
|
||||
{gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiById", "获取api详细信息", "api", "POST"},
|
||||
{gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/deleteApi", "删除Api", "api", "POST"},
|
||||
{gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/updateApi", "更新Api", "api", "POST"},
|
||||
{gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getAllApis", "获取所有api", "api", "POST"},
|
||||
{gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/createAuthority", "创建角色", "authority", "POST"},
|
||||
{gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/deleteAuthority", "删除角色", "authority", "POST"},
|
||||
{gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/getAuthorityList", "获取角色列表", "authority", "POST"},
|
||||
{gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenu", "获取菜单树", "menu", "POST"},
|
||||
{gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuList", "分页获取基础menu列表", "menu", "POST"},
|
||||
{gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addBaseMenu", "新增菜单", "menu", "POST"},
|
||||
{gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuTree", "获取用户动态路由", "menu", "POST"},
|
||||
{gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addMenuAuthority", "增加menu和角色关联关系", "menu", "POST"},
|
||||
{gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuAuthority", "获取指定角色menu", "menu", "POST"},
|
||||
{gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/deleteBaseMenu", "删除菜单", "menu", "POST"},
|
||||
{gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/updateBaseMenu", "更新菜单", "menu", "POST"},
|
||||
{gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuById", "根据id获取菜单", "menu", "POST"},
|
||||
{gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/changePassword", "修改密码", "user", "POST"},
|
||||
{gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/getUserList", "获取用户列表", "user", "POST"},
|
||||
{gorm.Model{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserAuthority", "修改用户角色", "user", "POST"},
|
||||
{gorm.Model{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/upload", "文件上传示例", "fileUploadAndDownload", "POST"},
|
||||
{gorm.Model{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/getFileList", "获取上传文件列表", "fileUploadAndDownload", "POST"},
|
||||
{gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/updateCasbin", "更改角色api权限", "casbin", "POST"},
|
||||
{gorm.Model{ID: 28, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/getPolicyPathByAuthorityId", "获取权限列表", "casbin", "POST"},
|
||||
{gorm.Model{ID: 29, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/deleteFile", "删除文件", "fileUploadAndDownload", "POST"},
|
||||
{gorm.Model{ID: 30, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/jwt/jsonInBlacklist", "jwt加入黑名单", "jwt", "POST"},
|
||||
{gorm.Model{ID: 31, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/setDataAuthority", "设置角色资源权限", "authority", "POST"},
|
||||
{gorm.Model{ID: 32, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getSystemConfig", "获取配置文件内容", "system", "POST"},
|
||||
{gorm.Model{ID: 33, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/setSystemConfig", "设置配置文件内容", "system", "POST"},
|
||||
{gorm.Model{ID: 34, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "创建客户", "customer", "POST"},
|
||||
{gorm.Model{ID: 35, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "更新客户", "customer", "PUT"},
|
||||
{gorm.Model{ID: 36, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "删除客户", "customer", "DELETE"},
|
||||
{gorm.Model{ID: 37, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "获取单一客户", "customer", "GET"},
|
||||
{gorm.Model{ID: 38, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customerList", "获取客户列表", "customer", "GET"},
|
||||
{gorm.Model{ID: 39, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/casbinTest/:pathParam", "RESTFUL模式测试", "casbin", "GET"},
|
||||
{gorm.Model{ID: 40, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/createTemp", "自动化代码", "autoCode", "POST"},
|
||||
{gorm.Model{ID: 41, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/updateAuthority", "更新角色信息", "authority", "PUT"},
|
||||
{gorm.Model{ID: 42, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/copyAuthority", "拷贝角色", "authority", "POST"},
|
||||
{gorm.Model{ID: 43, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/deleteUser", "删除用户", "user", "DELETE"},
|
||||
{gorm.Model{ID: 44, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/createSysDictionaryDetail", "新增字典内容", "sysDictionaryDetail", "POST"},
|
||||
{gorm.Model{ID: 45, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/deleteSysDictionaryDetail", "删除字典内容", "sysDictionaryDetail", "DELETE"},
|
||||
{gorm.Model{ID: 46, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/updateSysDictionaryDetail", "更新字典内容", "sysDictionaryDetail", "PUT"},
|
||||
{gorm.Model{ID: 47, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/findSysDictionaryDetail", "根据ID获取字典内容", "sysDictionaryDetail", "GET"},
|
||||
{gorm.Model{ID: 48, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/getSysDictionaryDetailList", "获取字典内容列表", "sysDictionaryDetail", "GET"},
|
||||
{gorm.Model{ID: 49, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/createSysDictionary", "新增字典", "sysDictionary", "POST"},
|
||||
{gorm.Model{ID: 50, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/deleteSysDictionary", "删除字典", "sysDictionary", "DELETE"},
|
||||
{gorm.Model{ID: 51, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/updateSysDictionary", "更新字典", "sysDictionary", "PUT"},
|
||||
{gorm.Model{ID: 52, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/findSysDictionary", "根据ID获取字典", "sysDictionary", "GET"},
|
||||
{gorm.Model{ID: 53, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/getSysDictionaryList", "获取字典列表", "sysDictionary", "GET"},
|
||||
{gorm.Model{ID: 54, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/createSysOperationRecord", "新增操作记录", "sysOperationRecord", "POST"},
|
||||
{gorm.Model{ID: 55, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecord", "删除操作记录", "sysOperationRecord", "DELETE"},
|
||||
{gorm.Model{ID: 56, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/findSysOperationRecord", "根据ID获取操作记录", "sysOperationRecord", "GET"},
|
||||
{gorm.Model{ID: 57, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/getSysOperationRecordList", "获取操作记录列表", "sysOperationRecord", "GET"},
|
||||
{gorm.Model{ID: 58, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getTables", "获取数据库表", "autoCode", "GET"},
|
||||
{gorm.Model{ID: 59, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getDB", "获取所有数据库", "autoCode", "GET"},
|
||||
{gorm.Model{ID: 60, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getColume", "获取所选table的所有字段", "autoCode", "GET"},
|
||||
{gorm.Model{ID: 61, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecordByIds", "批量删除操作历史", "sysOperationRecord", "DELETE"},
|
||||
{gorm.Model{ID: 62, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/upload", "插件版分片上传", "simpleUploader", "POST"},
|
||||
{gorm.Model{ID: 63, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/checkFileMd5", "文件完整度验证", "simpleUploader", "GET"},
|
||||
{gorm.Model{ID: 64, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/mergeFileMd5", "上传完成合并文件", "simpleUploader", "GET"},
|
||||
{gorm.Model{ID: 65, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserInfo", "设置用户信息", "user", "PUT"},
|
||||
{gorm.Model{ID: 66, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getServerInfo", "获取服务器信息", "system", "POST"},
|
||||
{gorm.Model{ID: 67, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/email/emailTest", "发送测试邮件", "email", "POST"},
|
||||
}
|
||||
if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitSysUser() (err error) {
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []model.SysUser{
|
||||
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "admin", Password: "e10adc3949ba59abbe56e057f20f883e", NickName: "超级管理员", HeaderImg: "http://qmplusimg.henrongyi.top/1571627762timg.jpg", AuthorityId: "888"},
|
||||
{Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "a303176530", Password: "3ec063004a6f31642261936a379fde3d", NickName: "QMPlusUser", HeaderImg: "http://qmplusimg.henrongyi.top/1572075907logo.png", AuthorityId: "9528"},
|
||||
}
|
||||
if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitExaCustomer() (err error) {
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []model.ExaCustomer{
|
||||
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, CustomerName: "测试客户", CustomerPhoneData: "1761111111", SysUserID: 1, SysUserAuthorityID: "888"},
|
||||
}
|
||||
if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitCasbinModel() (err error) {
|
||||
if !global.GVA_DB.Migrator().HasTable("casbin_rule") {
|
||||
if err := global.GVA_DB.Migrator().CreateTable(&gormadapter.CasbinRule{}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []model.CasbinModel{
|
||||
{"p", "888", "/base/login", "POST"},
|
||||
{"p", "888", "/user/register", "POST"},
|
||||
{"p", "888", "/api/createApi", "POST"},
|
||||
{"p", "888", "/api/getApiList", "POST"},
|
||||
{"p", "888", "/api/getApiById", "POST"},
|
||||
{"p", "888", "/api/deleteApi", "POST"},
|
||||
{"p", "888", "/api/updateApi", "POST"},
|
||||
{"p", "888", "/api/getAllApis", "POST"},
|
||||
{"p", "888", "/authority/createAuthority", "POST"},
|
||||
{"p", "888", "/authority/deleteAuthority", "POST"},
|
||||
{"p", "888", "/authority/getAuthorityList", "POST"},
|
||||
{"p", "888", "/authority/setDataAuthority", "POST"},
|
||||
{"p", "888", "/authority/updateAuthority", "PUT"},
|
||||
{"p", "888", "/authority/copyAuthority", "POST"},
|
||||
{"p", "888", "/menu/getMenu", "POST"},
|
||||
{"p", "888", "/menu/getMenuList", "POST"},
|
||||
{"p", "888", "/menu/addBaseMenu", "POST"},
|
||||
{"p", "888", "/menu/getBaseMenuTree", "POST"},
|
||||
{"p", "888", "/menu/addMenuAuthority", "POST"},
|
||||
{"p", "888", "/menu/getMenuAuthority", "POST"},
|
||||
{"p", "888", "/menu/deleteBaseMenu", "POST"},
|
||||
{"p", "888", "/menu/updateBaseMenu", "POST"},
|
||||
{"p", "888", "/menu/getBaseMenuById", "POST"},
|
||||
{"p", "888", "/user/changePassword", "POST"},
|
||||
{"p", "888", "/user/getUserList", "POST"},
|
||||
{"p", "888", "/user/setUserAuthority", "POST"},
|
||||
{"p", "888", "/user/deleteUser", "DELETE"},
|
||||
{"p", "888", "/fileUploadAndDownload/upload", "POST"},
|
||||
{"p", "888", "/fileUploadAndDownload/getFileList", "POST"},
|
||||
{"p", "888", "/fileUploadAndDownload/deleteFile", "POST"},
|
||||
{"p", "888", "/casbin/updateCasbin", "POST"},
|
||||
{"p", "888", "/casbin/getPolicyPathByAuthorityId", "POST"},
|
||||
{"p", "888", "/casbin/casbinTest/:pathParam", "GET"},
|
||||
{"p", "888", "/jwt/jsonInBlacklist", "POST"},
|
||||
{"p", "888", "/system/getSystemConfig", "POST"},
|
||||
{"p", "888", "/system/setSystemConfig", "POST"},
|
||||
{"p", "888", "/system/getServerInfo", "POST"},
|
||||
{"p", "888", "/customer/customer", "POST"},
|
||||
{"p", "888", "/customer/customer", "PUT"},
|
||||
{"p", "888", "/customer/customer", "DELETE"},
|
||||
{"p", "888", "/customer/customer", "GET"},
|
||||
{"p", "888", "/customer/customerList", "GET"},
|
||||
{"p", "888", "/autoCode/createTemp", "POST"},
|
||||
{"p", "888", "/autoCode/getTables", "GET"},
|
||||
{"p", "888", "/autoCode/getDB", "GET"},
|
||||
{"p", "888", "/autoCode/getColume", "GET"},
|
||||
{"p", "888", "/sysDictionaryDetail/createSysDictionaryDetail", "POST"},
|
||||
{"p", "888", "/sysDictionaryDetail/deleteSysDictionaryDetail", "DELETE"},
|
||||
{"p", "888", "/sysDictionaryDetail/updateSysDictionaryDetail", "PUT"},
|
||||
{"p", "888", "/sysDictionaryDetail/findSysDictionaryDetail", "GET"},
|
||||
{"p", "888", "/sysDictionaryDetail/getSysDictionaryDetailList", "GET"},
|
||||
{"p", "888", "/sysDictionary/createSysDictionary", "POST"},
|
||||
{"p", "888", "/sysDictionary/deleteSysDictionary", "DELETE"},
|
||||
{"p", "888", "/sysDictionary/updateSysDictionary", "PUT"},
|
||||
{"p", "888", "/sysDictionary/findSysDictionary", "GET"},
|
||||
{"p", "888", "/sysDictionary/getSysDictionaryList", "GET"},
|
||||
{"p", "888", "/sysOperationRecord/createSysOperationRecord", "POST"},
|
||||
{"p", "888", "/sysOperationRecord/deleteSysOperationRecord", "DELETE"},
|
||||
{"p", "888", "/sysOperationRecord/updateSysOperationRecord", "PUT"},
|
||||
{"p", "888", "/sysOperationRecord/findSysOperationRecord", "GET"},
|
||||
{"p", "888", "/sysOperationRecord/getSysOperationRecordList", "GET"},
|
||||
{"p", "888", "/sysOperationRecord/deleteSysOperationRecordByIds", "DELETE"},
|
||||
{"p", "888", "/user/setUserInfo", "PUT"},
|
||||
{"p", "888", "/email/emailTest", "POST"},
|
||||
{"p", "8881", "/base/login", "POST"},
|
||||
{"p", "8881", "/user/register", "POST"},
|
||||
{"p", "8881", "/api/createApi", "POST"},
|
||||
{"p", "8881", "/api/getApiList", "POST"},
|
||||
{"p", "8881", "/api/getApiById", "POST"},
|
||||
{"p", "8881", "/api/deleteApi", "POST"},
|
||||
{"p", "8881", "/api/updateApi", "POST"},
|
||||
{"p", "8881", "/api/getAllApis", "POST"},
|
||||
{"p", "8881", "/authority/createAuthority", "POST"},
|
||||
{"p", "8881", "/authority/deleteAuthority", "POST"},
|
||||
{"p", "8881", "/authority/getAuthorityList", "POST"},
|
||||
{"p", "8881", "/authority/setDataAuthority", "POST"},
|
||||
{"p", "8881", "/menu/getMenu", "POST"},
|
||||
{"p", "8881", "/menu/getMenuList", "POST"},
|
||||
{"p", "8881", "/menu/addBaseMenu", "POST"},
|
||||
{"p", "8881", "/menu/getBaseMenuTree", "POST"},
|
||||
{"p", "8881", "/menu/addMenuAuthority", "POST"},
|
||||
{"p", "8881", "/menu/getMenuAuthority", "POST"},
|
||||
{"p", "8881", "/menu/deleteBaseMenu", "POST"},
|
||||
{"p", "8881", "/menu/updateBaseMenu", "POST"},
|
||||
{"p", "8881", "/menu/getBaseMenuById", "POST"},
|
||||
{"p", "8881", "/user/changePassword", "POST"},
|
||||
{"p", "8881", "/user/getUserList", "POST"},
|
||||
{"p", "8881", "/user/setUserAuthority", "POST"},
|
||||
{"p", "8881", "/fileUploadAndDownload/upload", "POST"},
|
||||
{"p", "8881", "/fileUploadAndDownload/getFileList", "POST"},
|
||||
{"p", "8881", "/fileUploadAndDownload/deleteFile", "POST"},
|
||||
{"p", "8881", "/casbin/updateCasbin", "POST"},
|
||||
{"p", "8881", "/casbin/getPolicyPathByAuthorityId", "POST"},
|
||||
{"p", "8881", "/jwt/jsonInBlacklist", "POST"},
|
||||
{"p", "8881", "/system/getSystemConfig", "POST"},
|
||||
{"p", "8881", "/system/setSystemConfig", "POST"},
|
||||
{"p", "8881", "/customer/customer", "POST"},
|
||||
{"p", "8881", "/customer/customer", "PUT"},
|
||||
{"p", "8881", "/customer/customer", "DELETE"},
|
||||
{"p", "8881", "/customer/customer", "GET"},
|
||||
{"p", "8881", "/customer/customerList", "GET"},
|
||||
{"p", "9528", "/base/login", "POST"},
|
||||
{"p", "9528", "/user/register", "POST"},
|
||||
{"p", "9528", "/api/createApi", "POST"},
|
||||
{"p", "9528", "/api/getApiList", "POST"},
|
||||
{"p", "9528", "/api/getApiById", "POST"},
|
||||
{"p", "9528", "/api/deleteApi", "POST"},
|
||||
{"p", "9528", "/api/updateApi", "POST"},
|
||||
{"p", "9528", "/api/getAllApis", "POST"},
|
||||
{"p", "9528", "/authority/createAuthority", "POST"},
|
||||
{"p", "9528", "/authority/deleteAuthority", "POST"},
|
||||
{"p", "9528", "/authority/getAuthorityList", "POST"},
|
||||
{"p", "9528", "/authority/setDataAuthority", "POST"},
|
||||
{"p", "9528", "/menu/getMenu", "POST"},
|
||||
{"p", "9528", "/menu/getMenuList", "POST"},
|
||||
{"p", "9528", "/menu/addBaseMenu", "POST"},
|
||||
{"p", "9528", "/menu/getBaseMenuTree", "POST"},
|
||||
{"p", "9528", "/menu/addMenuAuthority", "POST"},
|
||||
{"p", "9528", "/menu/getMenuAuthority", "POST"},
|
||||
{"p", "9528", "/menu/deleteBaseMenu", "POST"},
|
||||
{"p", "9528", "/menu/updateBaseMenu", "POST"},
|
||||
{"p", "9528", "/menu/getBaseMenuById", "POST"},
|
||||
{"p", "9528", "/user/changePassword", "POST"},
|
||||
{"p", "9528", "/user/getUserList", "POST"},
|
||||
{"p", "9528", "/user/setUserAuthority", "POST"},
|
||||
{"p", "9528", "/fileUploadAndDownload/upload", "POST"},
|
||||
{"p", "9528", "/fileUploadAndDownload/getFileList", "POST"},
|
||||
{"p", "9528", "/fileUploadAndDownload/deleteFile", "POST"},
|
||||
{"p", "9528", "/casbin/updateCasbin", "POST"},
|
||||
{"p", "9528", "/casbin/getPolicyPathByAuthorityId", "POST"},
|
||||
{"p", "9528", "/jwt/jsonInBlacklist", "POST"},
|
||||
{"p", "9528", "/system/getSystemConfig", "POST"},
|
||||
{"p", "9528", "/system/setSystemConfig", "POST"},
|
||||
{"p", "9528", "/customer/customer", "POST"},
|
||||
{"p", "9528", "/customer/customer", "PUT"},
|
||||
{"p", "9528", "/customer/customer", "DELETE"},
|
||||
{"p", "9528", "/customer/customer", "GET"},
|
||||
{"p", "9528", "/customer/customerList", "GET"},
|
||||
{"p", "9528", "/autoCode/createTemp", "POST"},
|
||||
}
|
||||
if tx.Table("casbin_rule").Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitSysAuthority() (err error) {
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []model.SysAuthority{
|
||||
{CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0"},
|
||||
{CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888"},
|
||||
{CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0"},
|
||||
}
|
||||
if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitSysBaseMenus() (err error) {
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []model.SysBaseMenu{
|
||||
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "dashboard", Name: "dashboard", Hidden: false, Component: "view/dashboard/index.vue", Sort: 1, Meta: model.Meta{Title: "仪表盘", Icon: "setting"}},
|
||||
{Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "about", Name: "about", Component: "view/about/index.vue", Sort: 7, Meta: model.Meta{Title: "关于我们", Icon: "info"}},
|
||||
{Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "admin", Name: "superAdmin", Component: "view/superAdmin/index.vue", Sort: 3, Meta: model.Meta{Title: "超级管理员", Icon: "user-solid"}},
|
||||
{Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "authority", Name: "authority", Component: "view/superAdmin/authority/authority.vue", Sort: 1, Meta: model.Meta{Title: "角色管理", Icon: "s-custom"}},
|
||||
{Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "menu", Name: "menu", Component: "view/superAdmin/menu/menu.vue", Sort: 2, Meta: model.Meta{Title: "菜单管理", Icon: "s-order", KeepAlive: true}},
|
||||
{Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "api", Name: "api", Component: "view/superAdmin/api/api.vue", Sort: 3, Meta: model.Meta{Title: "api管理", Icon: "s-platform", KeepAlive: true}},
|
||||
{Model: gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "user", Name: "user", Component: "view/superAdmin/user/user.vue", Sort: 4, Meta: model.Meta{Title: "用户管理", Icon: "coordinate"}},
|
||||
{Model: gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "0", Path: "person", Name: "person", Component: "view/person/person.vue", Sort: 4, Meta: model.Meta{Title: "个人信息", Icon: "message-solid"}},
|
||||
{Model: gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "example", Name: "example", Component: "view/example/index.vue", Sort: 6, Meta: model.Meta{Title: "示例文件", Icon: "s-management"}},
|
||||
{Model: gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "table", Name: "table", Component: "view/example/table/table.vue", Sort: 1, Meta: model.Meta{Title: "表格示例", Icon: "s-order"}},
|
||||
{Model: gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "form", Name: "form", Component: "view/example/form/form.vue", Sort: 2, Meta: model.Meta{Title: "表单示例", Icon: "document"}},
|
||||
{Model: gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "rte", Name: "rte", Component: "view/example/rte/rte.vue", Sort: 3, Meta: model.Meta{Title: "富文本编辑器", Icon: "reading"}},
|
||||
{Model: gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "excel", Name: "excel", Component: "view/example/excel/excel.vue", Sort: 4, Meta: model.Meta{Title: "excel导入导出", Icon: "s-marketing"}},
|
||||
{Model: gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "upload", Name: "upload", Component: "view/example/upload/upload.vue", Sort: 5, Meta: model.Meta{Title: "上传下载", Icon: "upload"}},
|
||||
{Model: gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "breakpoint", Name: "breakpoint", Component: "view/example/breakpoint/breakpoint.vue", Sort: 6, Meta: model.Meta{Title: "断点续传", Icon: "upload"}},
|
||||
{Model: gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "customer", Name: "customer", Component: "view/example/customer/customer.vue", Sort: 7, Meta: model.Meta{Title: "客户列表(资源示例)", Icon: "s-custom"}},
|
||||
{Model: gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "systemTools", Name: "systemTools", Component: "view/systemTools/index.vue", Sort: 5, Meta: model.Meta{Title: "系统工具", Icon: "s-cooperation"}},
|
||||
{Model: gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "autoCode", Name: "autoCode", Component: "view/systemTools/autoCode/index.vue", Sort: 1, Meta: model.Meta{Title: "代码生成器", Icon: "cpu", KeepAlive: true}},
|
||||
{Model: gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "formCreate", Name: "formCreate", Component: "view/systemTools/formCreate/index.vue", Sort: 2, Meta: model.Meta{Title: "表单生成器", Icon: "magic-stick", KeepAlive: true}},
|
||||
{Model: gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "system", Name: "system", Component: "view/systemTools/system/system.vue", Sort: 3, Meta: model.Meta{Title: "系统配置", Icon: "s-operation"}},
|
||||
{Model: gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "iconList", Name: "iconList", Component: "view/iconList/index.vue", Sort: 2, Meta: model.Meta{Title: "图标集合", Icon: "star-on"}},
|
||||
{Model: gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "dictionary", Name: "dictionary", Component: "view/superAdmin/dictionary/sysDictionary.vue", Sort: 5, Meta: model.Meta{Title: "字典管理", Icon: "notebook-2"}},
|
||||
{Model: gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "3", Path: "dictionaryDetail/:id", Name: "dictionaryDetail", Component: "view/superAdmin/dictionary/sysDictionaryDetail.vue", Sort: 1, Meta: model.Meta{Title: "字典详情", Icon: "s-order"}},
|
||||
{Model: gorm.Model{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "operation", Name: "operation", Component: "view/superAdmin/operation/sysOperationRecord.vue", Sort: 6, Meta: model.Meta{Title: "操作历史", Icon: "time"}},
|
||||
{Model: gorm.Model{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "simpleUploader", Name: "simpleUploader", Component: "view/example/simpleUploader/simpleUploader", Sort: 6, Meta: model.Meta{Title: "断点续传(插件版)", Icon: "upload"}},
|
||||
{Model: gorm.Model{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "https://www.gin-vue-admin.com", Name: "https://www.gin-vue-admin.com", Hidden: false, Component: "/", Sort: 0, Meta: model.Meta{Title: "官方网站", Icon: "s-home"}},
|
||||
{Model: gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "state", Name: "state", Hidden: false, Component: "view/system/state.vue", Sort: 6, Meta: model.Meta{Title: "服务器状态", Icon: "cloudy"}},
|
||||
}
|
||||
if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitAuthorityMenu() (err error) {
|
||||
return global.GVA_DB.Exec("CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `authority_menu` AS select `sys_base_menus`.`id` AS `id`,`sys_base_menus`.`created_at` AS `created_at`, `sys_base_menus`.`updated_at` AS `updated_at`, `sys_base_menus`.`deleted_at` AS `deleted_at`, `sys_base_menus`.`menu_level` AS `menu_level`,`sys_base_menus`.`parent_id` AS `parent_id`,`sys_base_menus`.`path` AS `path`,`sys_base_menus`.`name` AS `name`,`sys_base_menus`.`hidden` AS `hidden`,`sys_base_menus`.`component` AS `component`, `sys_base_menus`.`title` AS `title`,`sys_base_menus`.`icon` AS `icon`,`sys_base_menus`.`sort` AS `sort`,`sys_authority_menus`.`sys_authority_authority_id` AS `authority_id`,`sys_authority_menus`.`sys_base_menu_id` AS `menu_id`,`sys_base_menus`.`keep_alive` AS `keep_alive`,`sys_base_menus`.`default_menu` AS `default_menu` from (`sys_authority_menus` join `sys_base_menus` on ((`sys_authority_menus`.`sys_base_menu_id` = `sys_base_menus`.`id`)))").Error
|
||||
}
|
||||
|
||||
func InitSysDictionary() (err error) {
|
||||
status := new(bool)
|
||||
*status = true
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []model.SysDictionary{
|
||||
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Desc: "性别字典"},
|
||||
{Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"},
|
||||
{Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"},
|
||||
{Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库浮点型", Type: "float64", Status: status, Desc: "数据库浮点型"},
|
||||
{Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"},
|
||||
{Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"},
|
||||
}
|
||||
if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitSysAuthorityMenus() (err error) {
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []SysAuthorityMenus{
|
||||
{"888", 1},
|
||||
{"888", 2},
|
||||
{"888", 3},
|
||||
{"888", 4},
|
||||
{"888", 5},
|
||||
{"888", 6},
|
||||
{"888", 7},
|
||||
{"888", 8},
|
||||
{"888", 9},
|
||||
{"888", 10},
|
||||
{"888", 11},
|
||||
{"888", 12},
|
||||
{"888", 13},
|
||||
{"888", 14},
|
||||
{"888", 15},
|
||||
{"888", 16},
|
||||
{"888", 17},
|
||||
{"888", 18},
|
||||
{"888", 19},
|
||||
{"888", 20},
|
||||
{"888", 21},
|
||||
{"888", 22},
|
||||
{"888", 23},
|
||||
{"888", 24},
|
||||
{"888", 25},
|
||||
{"888", 26},
|
||||
{"888", 27},
|
||||
{"8881", 1},
|
||||
{"8881", 2},
|
||||
{"8881", 8},
|
||||
{"8881", 17},
|
||||
{"8881", 18},
|
||||
{"8881", 19},
|
||||
{"8881", 20},
|
||||
{"9528", 1},
|
||||
{"9528", 2},
|
||||
{"9528", 3},
|
||||
{"9528", 4},
|
||||
{"9528", 5},
|
||||
{"9528", 6},
|
||||
{"9528", 7},
|
||||
{"9528", 8},
|
||||
{"9528", 9},
|
||||
{"9528", 10},
|
||||
{"9528", 11},
|
||||
{"9528", 12},
|
||||
{"9528", 13},
|
||||
{"9528", 14},
|
||||
{"9528", 15},
|
||||
{"9528", 17},
|
||||
{"9528", 18},
|
||||
{"9528", 19},
|
||||
{"9528", 20},
|
||||
}
|
||||
if tx.Table("sys_authority_menus").Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitSysDataAuthorityId() (err error) {
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []SysDataAuthorityId{
|
||||
{"888", "888"},
|
||||
{"888", "8881"},
|
||||
{"888", "9528"},
|
||||
{"9528", "8881"},
|
||||
{"9528", "9528"},
|
||||
}
|
||||
if global.GVA_DB.Migrator().HasTable("sys_data_authority_ids") {
|
||||
if tx.Table("sys_data_authority_ids").Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
if tx.Table("sys_data_authority_id").Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitSysDictionaryDetail() (err error) {
|
||||
status := new(bool)
|
||||
*status = true
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []model.SysDictionaryDetail{
|
||||
{gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "smallint", 1, status, 1, 2},
|
||||
{gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumint", 2, status, 2, 2},
|
||||
{gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "int", 3, status, 3, 2},
|
||||
{gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "bigint", 4, status, 4, 2},
|
||||
{gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "data", 0, status, 0, 3},
|
||||
{gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "time", 1, status, 1, 3},
|
||||
{gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "year", 2, status, 2, 3},
|
||||
{gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "datetime", 3, status, 3, 3},
|
||||
{gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "timestamp", 5, status, 5, 3},
|
||||
{gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "float", 0, status, 0, 4},
|
||||
{gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "double", 1, status, 1, 4},
|
||||
{gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "decimal", 2, status, 2, 4},
|
||||
{gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "char", 0, status, 0, 5},
|
||||
{gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "varchar", 1, status, 1, 5},
|
||||
{gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyblob", 2, status, 2, 5},
|
||||
{gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinytext", 3, status, 3, 5},
|
||||
{gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "text", 4, status, 4, 5},
|
||||
{gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "blob", 5, status, 5, 5},
|
||||
{gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumblob", 6, status, 6, 5},
|
||||
{gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumtext", 7, status, 7, 5},
|
||||
{gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longblob", 8, status, 8, 5},
|
||||
{gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longtext", 9, status, 9, 5},
|
||||
{gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6},
|
||||
}
|
||||
if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitExaFileUploadAndDownload() (err error) {
|
||||
tx := global.GVA_DB.Begin() // 开始事务
|
||||
insert := []model.ExaFileUploadAndDownload{
|
||||
{gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"},
|
||||
{gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "http://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"},
|
||||
}
|
||||
if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
|
||||
tx.Rollback()
|
||||
}
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func InitData() {
|
||||
var err error
|
||||
err = InitSysApi()
|
||||
err = InitSysUser()
|
||||
err = InitExaCustomer()
|
||||
err = InitCasbinModel()
|
||||
err = InitSysAuthority()
|
||||
err = InitSysBaseMenus()
|
||||
err = InitAuthorityMenu()
|
||||
err = InitSysDictionary()
|
||||
err = InitSysAuthorityMenus()
|
||||
err = InitSysDataAuthorityId()
|
||||
err = InitSysDictionaryDetail()
|
||||
err = InitExaFileUploadAndDownload()
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("initialize data failed", zap.Any("err", err))
|
||||
}
|
||||
global.GVA_LOG.Info("initialize data success")
|
||||
}
|
||||
+61
-87
@@ -2,36 +2,37 @@ package initialize
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/initialize/internal"
|
||||
"gin-vue-admin/model"
|
||||
"os"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/driver/sqlserver"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
"os"
|
||||
)
|
||||
|
||||
var err error
|
||||
//@author: SliverHorn
|
||||
//@function: Gorm
|
||||
//@description: 初始化数据库并产生数据库全局变量
|
||||
//@return: *gorm.DB
|
||||
|
||||
// Gorm 初始化数据库并产生数据库全局变量
|
||||
func Gorm() {
|
||||
func Gorm() *gorm.DB {
|
||||
switch global.GVA_CONFIG.System.DbType {
|
||||
case "mysql":
|
||||
GormMysql()
|
||||
case "postgresql":
|
||||
GormPostgreSql()
|
||||
//case "sqlite": // sqlite需要gcc支持 windows用户需要自行安装gcc 如需使用打开注释即可
|
||||
// GormSqlite()
|
||||
case "sqlserver":
|
||||
GormSqlServer()
|
||||
return GormMysql()
|
||||
default:
|
||||
GormMysql()
|
||||
return GormMysql()
|
||||
}
|
||||
}
|
||||
|
||||
// GormDBTables 注册数据库表专用
|
||||
func GormDBTables(db *gorm.DB) {
|
||||
// MysqlTables
|
||||
//@author: SliverHorn
|
||||
//@function: MysqlTables
|
||||
//@description: 注册数据库表专用
|
||||
//@param: db *gorm.DB
|
||||
|
||||
func MysqlTables(db *gorm.DB) {
|
||||
err := db.AutoMigrate(
|
||||
model.SysUser{},
|
||||
model.SysAuthority{},
|
||||
@@ -39,8 +40,6 @@ func GormDBTables(db *gorm.DB) {
|
||||
model.SysBaseMenu{},
|
||||
model.SysBaseMenuParameter{},
|
||||
model.JwtBlacklist{},
|
||||
model.SysWorkflow{},
|
||||
model.SysWorkflowStepInfo{},
|
||||
model.SysDictionary{},
|
||||
model.SysDictionaryDetail{},
|
||||
model.ExaFileUploadAndDownload{},
|
||||
@@ -49,6 +48,9 @@ func GormDBTables(db *gorm.DB) {
|
||||
model.ExaSimpleUploader{},
|
||||
model.ExaCustomer{},
|
||||
model.SysOperationRecord{},
|
||||
|
||||
// Code generated by gin-vue-admin Begin; DO NOT EDIT.
|
||||
// Code generated by gin-vue-admin End; DO NOT EDIT.
|
||||
)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("register table failed", zap.Any("err", err))
|
||||
@@ -57,9 +59,17 @@ func GormDBTables(db *gorm.DB) {
|
||||
global.GVA_LOG.Info("register table success")
|
||||
}
|
||||
|
||||
// GormMysql 初始化Mysql数据库
|
||||
func GormMysql() {
|
||||
//
|
||||
//@author: SliverHorn
|
||||
//@function: GormMysql
|
||||
//@description: 初始化Mysql数据库
|
||||
//@return: *gorm.DB
|
||||
|
||||
func GormMysql() *gorm.DB {
|
||||
m := global.GVA_CONFIG.Mysql
|
||||
if m.Dbname == "" {
|
||||
return nil
|
||||
}
|
||||
dsn := m.Username + ":" + m.Password + "@tcp(" + m.Path + ")/" + m.Dbname + "?" + m.Config
|
||||
mysqlConfig := mysql.Config{
|
||||
DSN: dsn, // DSN data source name
|
||||
@@ -69,80 +79,44 @@ func GormMysql() {
|
||||
DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
|
||||
SkipInitializeWithVersion: false, // 根据版本自动配置
|
||||
}
|
||||
gormConfig := config(m.LogMode)
|
||||
if global.GVA_DB, err = gorm.Open(mysql.New(mysqlConfig), gormConfig); err != nil {
|
||||
global.GVA_LOG.Error("MySQL启动异常", zap.Any("err", err))
|
||||
os.Exit(0)
|
||||
if db, err := gorm.Open(mysql.New(mysqlConfig), gormConfig(m.LogMode)); err != nil {
|
||||
//global.GVA_LOG.Error("MySQL启动异常", zap.Any("err", err))
|
||||
//os.Exit(0)
|
||||
//return nil
|
||||
return nil
|
||||
} else {
|
||||
GormDBTables(global.GVA_DB)
|
||||
sqlDB, _ := global.GVA_DB.DB()
|
||||
sqlDB, _ := db.DB()
|
||||
sqlDB.SetMaxIdleConns(m.MaxIdleConns)
|
||||
sqlDB.SetMaxOpenConns(m.MaxOpenConns)
|
||||
return db
|
||||
}
|
||||
}
|
||||
|
||||
// GormPostgreSql 初始化PostgreSql数据库
|
||||
func GormPostgreSql() {
|
||||
p := global.GVA_CONFIG.Postgresql
|
||||
dsn := "host="+ p.Host + " user=" + p.Username + " password=" + p.Password + " dbname=" + p.Dbname + " port=" + p.Port + " " + p.Config
|
||||
postgresConfig := postgres.Config{
|
||||
DSN: dsn, // DSN data source name
|
||||
PreferSimpleProtocol: p.PreferSimpleProtocol, // 禁用隐式 prepared statement
|
||||
}
|
||||
gormConfig := config(p.Logger)
|
||||
if global.GVA_DB, err = gorm.Open(postgres.New(postgresConfig), gormConfig); err != nil {
|
||||
global.GVA_LOG.Error("PostgreSql启动异常", zap.Any("err", err))
|
||||
os.Exit(0)
|
||||
} else {
|
||||
GormDBTables(global.GVA_DB)
|
||||
sqlDB, _ := global.GVA_DB.DB()
|
||||
sqlDB.SetMaxIdleConns(p.MaxIdleConns)
|
||||
sqlDB.SetMaxOpenConns(p.MaxOpenConns)
|
||||
}
|
||||
}
|
||||
//@author: SliverHorn
|
||||
//@function: gormConfig
|
||||
//@description: 根据配置决定是否开启日志
|
||||
//@param: mod bool
|
||||
//@return: *gorm.Config
|
||||
|
||||
// GormSqlite 初始化Sqlite数据库 sqlite需要gcc支持 windows用户需要自行安装gcc 如需使用打开注释即可
|
||||
//func GormSqlite() {
|
||||
// s := global.GVA_CONFIG.Sqlite
|
||||
// gormConfig := config(s.Logger)
|
||||
// if global.GVA_DB, err = gorm.Open(sqlite.Open(s.Path), gormConfig); err != nil {
|
||||
// global.GVA_LOG.Error("Sqlite启动异常", zap.Any("err", err))
|
||||
// os.Exit(0)
|
||||
// } else {
|
||||
// GormDBTables(global.GVA_DB)
|
||||
// sqlDB, _ := global.GVA_DB.DB()
|
||||
// sqlDB.SetMaxIdleConns(s.MaxIdleConns)
|
||||
// sqlDB.SetMaxOpenConns(s.MaxOpenConns)
|
||||
// }
|
||||
//}
|
||||
|
||||
// GormSqlServer 初始化SqlServer数据库
|
||||
func GormSqlServer() {
|
||||
ss := global.GVA_CONFIG.Sqlserver
|
||||
dsn := "sqlserver://" + ss.Username + ":" + ss.Password + "@" + ss.Path + "?database=" + ss.Dbname
|
||||
if global.GVA_DB, err = gorm.Open(sqlserver.Open(dsn), &gorm.Config{}); err != nil {
|
||||
global.GVA_LOG.Error("SqlServer启动异常", zap.Any("err", err))
|
||||
os.Exit(0)
|
||||
} else {
|
||||
GormDBTables(global.GVA_DB)
|
||||
sqlDB, _ := global.GVA_DB.DB()
|
||||
sqlDB.SetMaxIdleConns(ss.MaxIdleConns)
|
||||
sqlDB.SetMaxOpenConns(ss.MaxOpenConns)
|
||||
}
|
||||
}
|
||||
|
||||
// config 根据配置决定是否开启日志
|
||||
func config(mod bool) (c *gorm.Config) {
|
||||
if mod {
|
||||
c = &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
DisableForeignKeyConstraintWhenMigrating: true,
|
||||
}
|
||||
} else {
|
||||
c = &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Silent),
|
||||
DisableForeignKeyConstraintWhenMigrating: true,
|
||||
func gormConfig(mod bool) *gorm.Config {
|
||||
var config = &gorm.Config{DisableForeignKeyConstraintWhenMigrating: true}
|
||||
switch global.GVA_CONFIG.Mysql.LogZap {
|
||||
case "silent", "Silent":
|
||||
config.Logger = internal.Default.LogMode(logger.Silent)
|
||||
case "error", "Error":
|
||||
config.Logger = internal.Default.LogMode(logger.Error)
|
||||
case "warn", "Warn":
|
||||
config.Logger = internal.Default.LogMode(logger.Warn)
|
||||
case "info", "Info":
|
||||
config.Logger = internal.Default.LogMode(logger.Info)
|
||||
case "zap", "Zap":
|
||||
config.Logger = internal.Default.LogMode(logger.Info)
|
||||
default:
|
||||
if mod {
|
||||
config.Logger = internal.Default.LogMode(logger.Info)
|
||||
break
|
||||
}
|
||||
config.Logger = internal.Default.LogMode(logger.Silent)
|
||||
}
|
||||
return
|
||||
return config
|
||||
}
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gin-vue-admin/global"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm/logger"
|
||||
"gorm.io/gorm/utils"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// writer log writer interface
|
||||
type writer interface {
|
||||
Printf(string, ...interface{})
|
||||
}
|
||||
|
||||
type config struct {
|
||||
SlowThreshold time.Duration
|
||||
Colorful bool
|
||||
LogLevel logger.LogLevel
|
||||
}
|
||||
|
||||
var (
|
||||
Discard = New(log.New(ioutil.Discard, "", log.LstdFlags), config{})
|
||||
Default = New(log.New(os.Stdout, "\r\n", log.LstdFlags), config{
|
||||
SlowThreshold: 200 * time.Millisecond,
|
||||
LogLevel: logger.Warn,
|
||||
Colorful: true,
|
||||
})
|
||||
Recorder = traceRecorder{Interface: Default, BeginAt: time.Now()}
|
||||
)
|
||||
|
||||
func New(writer writer, config config) logger.Interface {
|
||||
var (
|
||||
infoStr = "%s\n[info] "
|
||||
warnStr = "%s\n[warn] "
|
||||
errStr = "%s\n[error] "
|
||||
traceStr = "%s\n[%.3fms] [rows:%v] %s"
|
||||
traceWarnStr = "%s %s\n[%.3fms] [rows:%v] %s"
|
||||
traceErrStr = "%s %s\n[%.3fms] [rows:%v] %s"
|
||||
)
|
||||
|
||||
if config.Colorful {
|
||||
infoStr = logger.Green + "%s\n" + logger.Reset + logger.Green + "[info] " + logger.Reset
|
||||
warnStr = logger.BlueBold + "%s\n" + logger.Reset + logger.Magenta + "[warn] " + logger.Reset
|
||||
errStr = logger.Magenta + "%s\n" + logger.Reset + logger.Red + "[error] " + logger.Reset
|
||||
traceStr = logger.Green + "%s\n" + logger.Reset + logger.Yellow + "[%.3fms] " + logger.BlueBold + "[rows:%v]" + logger.Reset + " %s"
|
||||
traceWarnStr = logger.Green + "%s " + logger.Yellow + "%s\n" + logger.Reset + logger.RedBold + "[%.3fms] " + logger.Yellow + "[rows:%v]" + logger.Magenta + " %s" + logger.Reset
|
||||
traceErrStr = logger.RedBold + "%s " + logger.MagentaBold + "%s\n" + logger.Reset + logger.Yellow + "[%.3fms] " + logger.BlueBold + "[rows:%v]" + logger.Reset + " %s"
|
||||
}
|
||||
|
||||
return &customLogger{
|
||||
writer: writer,
|
||||
config: config,
|
||||
infoStr: infoStr,
|
||||
warnStr: warnStr,
|
||||
errStr: errStr,
|
||||
traceStr: traceStr,
|
||||
traceWarnStr: traceWarnStr,
|
||||
traceErrStr: traceErrStr,
|
||||
}
|
||||
}
|
||||
|
||||
type customLogger struct {
|
||||
writer
|
||||
config
|
||||
infoStr, warnStr, errStr string
|
||||
traceStr, traceErrStr, traceWarnStr string
|
||||
}
|
||||
|
||||
// LogMode log mode
|
||||
func (c *customLogger) LogMode(level logger.LogLevel) logger.Interface {
|
||||
newLogger := *c
|
||||
newLogger.LogLevel = level
|
||||
return &newLogger
|
||||
}
|
||||
|
||||
// Info print info
|
||||
func (c *customLogger) Info(ctx context.Context, message string, data ...interface{}) {
|
||||
if c.LogLevel >= logger.Info {
|
||||
c.Printf(c.infoStr+message, append([]interface{}{utils.FileWithLineNum()}, data...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// Warn print warn messages
|
||||
func (c *customLogger) Warn(ctx context.Context, message string, data ...interface{}) {
|
||||
if c.LogLevel >= logger.Warn {
|
||||
c.Printf(c.warnStr+message, append([]interface{}{utils.FileWithLineNum()}, data...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// Error print error messages
|
||||
func (c *customLogger) Error(ctx context.Context, message string, data ...interface{}) {
|
||||
if c.LogLevel >= logger.Error {
|
||||
c.Printf(c.errStr+message, append([]interface{}{utils.FileWithLineNum()}, data...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// Trace print sql message
|
||||
func (c *customLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) {
|
||||
if c.LogLevel > 0 {
|
||||
elapsed := time.Since(begin)
|
||||
switch {
|
||||
case err != nil && c.LogLevel >= logger.Error:
|
||||
sql, rows := fc()
|
||||
if rows == -1 {
|
||||
c.Printf(c.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, "-", sql)
|
||||
} else {
|
||||
c.Printf(c.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, rows, sql)
|
||||
}
|
||||
case elapsed > c.SlowThreshold && c.SlowThreshold != 0 && c.LogLevel >= logger.Warn:
|
||||
sql, rows := fc()
|
||||
slowLog := fmt.Sprintf("SLOW SQL >= %v", c.SlowThreshold)
|
||||
if rows == -1 {
|
||||
c.Printf(c.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, "-", sql)
|
||||
} else {
|
||||
c.Printf(c.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, rows, sql)
|
||||
}
|
||||
case c.LogLevel >= logger.Info:
|
||||
sql, rows := fc()
|
||||
if rows == -1 {
|
||||
c.Printf(c.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, "-", sql)
|
||||
} else {
|
||||
c.Printf(c.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, rows, sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *customLogger) Printf(message string, data ...interface{}) {
|
||||
if global.GVA_CONFIG.Mysql.LogZap != "" {
|
||||
switch len(data) {
|
||||
case 0:
|
||||
global.GVA_LOG.Info(message)
|
||||
case 1:
|
||||
global.GVA_LOG.Info("gorm", zap.Any("src", data[0]))
|
||||
case 2:
|
||||
global.GVA_LOG.Info("gorm", zap.Any("src", data[0]), zap.Any("duration", data[1]))
|
||||
case 3:
|
||||
global.GVA_LOG.Info("gorm", zap.Any("src", data[0]), zap.Any("duration", data[1]), zap.Any("rows", data[2]))
|
||||
case 4:
|
||||
global.GVA_LOG.Info("gorm", zap.Any("src", data[0]), zap.Any("duration", data[1]), zap.Any("rows", data[2]), zap.Any("sql", data[3]))
|
||||
}
|
||||
return
|
||||
}
|
||||
switch len(data) {
|
||||
case 0:
|
||||
c.writer.Printf(message, "")
|
||||
case 1:
|
||||
c.writer.Printf(message, data[0])
|
||||
case 2:
|
||||
c.writer.Printf(message, data[0], data[1])
|
||||
case 3:
|
||||
c.writer.Printf(message, data[0], data[1], data[2])
|
||||
case 4:
|
||||
c.writer.Printf(message, data[0], data[1], data[2], data[3])
|
||||
case 5:
|
||||
c.writer.Printf(message, data[0], data[1], data[2], data[3], data[4])
|
||||
}
|
||||
}
|
||||
|
||||
type traceRecorder struct {
|
||||
logger.Interface
|
||||
BeginAt time.Time
|
||||
SQL string
|
||||
RowsAffected int64
|
||||
Err error
|
||||
}
|
||||
|
||||
func (t traceRecorder) New() *traceRecorder {
|
||||
return &traceRecorder{Interface: t.Interface, BeginAt: time.Now()}
|
||||
}
|
||||
|
||||
func (t *traceRecorder) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) {
|
||||
t.BeginAt = begin
|
||||
t.SQL, t.RowsAffected = fc()
|
||||
t.Err = err
|
||||
}
|
||||
@@ -17,7 +17,7 @@ func Redis() {
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("redis connect ping failed, err:", zap.Any("err", err))
|
||||
} else {
|
||||
global.GVA_LOG.Info("redis connect ping response:", zap.String("pong",pong))
|
||||
global.GVA_LOG.Info("redis connect ping response:", zap.String("pong", pong))
|
||||
global.GVA_REDIS = client
|
||||
}
|
||||
}
|
||||
|
||||
+30
-20
@@ -5,10 +5,11 @@ import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/middleware"
|
||||
"gin-vue-admin/router"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/swaggo/gin-swagger"
|
||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 初始化总路由
|
||||
@@ -19,30 +20,39 @@ func Routers() *gin.Engine {
|
||||
// Router.Use(middleware.LoadTls()) // 打开就能玩https了
|
||||
global.GVA_LOG.Info("use middleware logger")
|
||||
// 跨域
|
||||
Router.Use(middleware.Cors())
|
||||
//Router.Use(middleware.Cors()) // 如需跨域可以打开
|
||||
global.GVA_LOG.Info("use middleware cors")
|
||||
Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
global.GVA_LOG.Info("register swagger handler")
|
||||
// 方便统一添加路由组前缀 多服务器上线使用
|
||||
ApiGroup := Router.Group("")
|
||||
router.InitUserRouter(ApiGroup) // 注册用户路由
|
||||
router.InitBaseRouter(ApiGroup) // 注册基础功能路由 不做鉴权
|
||||
router.InitMenuRouter(ApiGroup) // 注册menu路由
|
||||
router.InitAuthorityRouter(ApiGroup) // 注册角色路由
|
||||
router.InitApiRouter(ApiGroup) // 注册功能api路由
|
||||
router.InitFileUploadAndDownloadRouter(ApiGroup) // 文件上传下载功能路由
|
||||
router.InitSimpleUploaderRouter(ApiGroup) // 断点续传(插件版)
|
||||
router.InitWorkflowRouter(ApiGroup) // 工作流相关路由
|
||||
router.InitCasbinRouter(ApiGroup) // 权限相关路由
|
||||
router.InitJwtRouter(ApiGroup) // jwt相关路由
|
||||
router.InitSystemRouter(ApiGroup) // system相关路由
|
||||
router.InitCustomerRouter(ApiGroup) // 客户路由
|
||||
router.InitAutoCodeRouter(ApiGroup) // 创建自动化代码
|
||||
router.InitSysDictionaryDetailRouter(ApiGroup) // 字典详情管理
|
||||
router.InitSysDictionaryRouter(ApiGroup) // 字典管理
|
||||
router.InitSysOperationRecordRouter(ApiGroup) // 操作记录
|
||||
router.InitEmailRouter(ApiGroup) // 邮件相关路由
|
||||
PublicGroup := Router.Group("")
|
||||
{
|
||||
router.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权
|
||||
router.InitInitRouter(PublicGroup) // 自动初始化相关
|
||||
}
|
||||
PrivateGroup := Router.Group("")
|
||||
PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
|
||||
{
|
||||
router.InitApiRouter(PrivateGroup) // 注册功能api路由
|
||||
router.InitJwtRouter(PrivateGroup) // jwt相关路由
|
||||
router.InitUserRouter(PrivateGroup) // 注册用户路由
|
||||
router.InitMenuRouter(PrivateGroup) // 注册menu路由
|
||||
router.InitEmailRouter(PrivateGroup) // 邮件相关路由
|
||||
router.InitSystemRouter(PrivateGroup) // system相关路由
|
||||
router.InitCasbinRouter(PrivateGroup) // 权限相关路由
|
||||
router.InitCustomerRouter(PrivateGroup) // 客户路由
|
||||
router.InitAutoCodeRouter(PrivateGroup) // 创建自动化代码
|
||||
router.InitAuthorityRouter(PrivateGroup) // 注册角色路由
|
||||
router.InitSimpleUploaderRouter(PrivateGroup) // 断点续传(插件版)
|
||||
router.InitSysDictionaryRouter(PrivateGroup) // 字典管理
|
||||
router.InitSysOperationRecordRouter(PrivateGroup) // 操作记录
|
||||
router.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理
|
||||
router.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由
|
||||
router.InitExcelRouter(PrivateGroup) // 表格导入导出
|
||||
|
||||
// Code generated by gin-vue-admin Begin; DO NOT EDIT.
|
||||
// Code generated by gin-vue-admin End; DO NOT EDIT.
|
||||
}
|
||||
global.GVA_LOG.Info("router register success")
|
||||
return Router
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/config"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/utils"
|
||||
)
|
||||
|
||||
func Timer() {
|
||||
if global.GVA_CONFIG.Timer.Start {
|
||||
for _, detail := range global.GVA_CONFIG.Timer.Detail {
|
||||
fmt.Println(detail)
|
||||
go func(detail config.Detail) {
|
||||
global.GVA_Timer.AddTaskByFunc("ClearDB", global.GVA_CONFIG.Timer.Spec, func() {
|
||||
err := utils.ClearTable(global.GVA_DB, detail.TableName, detail.CompareField, detail.Interval)
|
||||
if err != nil {
|
||||
fmt.Println("timer error:", err)
|
||||
}
|
||||
})
|
||||
}(detail)
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-8
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"gin-vue-admin/core"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/gva/init_data"
|
||||
"gin-vue-admin/initialize"
|
||||
)
|
||||
|
||||
@@ -15,13 +14,15 @@ import (
|
||||
// @name x-token
|
||||
// @BasePath /
|
||||
func main() {
|
||||
initialize.Gorm()
|
||||
if global.GVA_CONFIG.System.NeedInitData {
|
||||
init_data.InitData() // 通过配置文件初始化数据 默认为 false 首次运行需要将 ./config.yaml中 system下的 need-init-data 修改为true
|
||||
global.GVA_VP = core.Viper() // 初始化Viper
|
||||
global.GVA_LOG = core.Zap() // 初始化zap日志库
|
||||
global.GVA_DB = initialize.Gorm() // gorm连接数据库
|
||||
initialize.Timer()
|
||||
if global.GVA_DB != nil {
|
||||
initialize.MysqlTables(global.GVA_DB) // 初始化表
|
||||
// 程序结束前关闭数据库链接
|
||||
db, _ := global.GVA_DB.DB()
|
||||
defer db.Close()
|
||||
}
|
||||
// 程序结束前关闭数据库链接
|
||||
db, _ := global.GVA_DB.DB()
|
||||
defer db.Close()
|
||||
|
||||
core.RunWindowsServer()
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package middleware
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/model/request"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -25,7 +25,7 @@ func CasbinHandler() gin.HandlerFunc {
|
||||
if global.GVA_CONFIG.System.Env == "develop" || success {
|
||||
c.Next()
|
||||
} else {
|
||||
response.Result(response.ERROR, gin.H{}, "权限不足", c)
|
||||
response.FailWithDetailed(gin.H{}, "权限不足", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -11,7 +11,7 @@ func Cors() gin.HandlerFunc {
|
||||
method := c.Request.Method
|
||||
origin := c.Request.Header.Get("Origin")
|
||||
c.Header("Access-Control-Allow-Origin", origin)
|
||||
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token,X-Token,X-User-Id\"")
|
||||
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token,X-Token,X-User-Id")
|
||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS,DELETE,PUT")
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
|
||||
c.Header("Access-Control-Allow-Credentials", "true")
|
||||
|
||||
+21
-31
@@ -3,9 +3,9 @@ package middleware
|
||||
import (
|
||||
"errors"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
"gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -16,19 +16,15 @@ import (
|
||||
|
||||
func JWTAuth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 我们这里jwt鉴权取头部信息 x-token 登录时回返回token信息 这里前端需要把token存储到cookie或者本地localSstorage中 不过需要跟后端协商过期时间 可以约定刷新令牌或者重新登录
|
||||
// 我们这里jwt鉴权取头部信息 x-token 登录时回返回token信息 这里前端需要把token存储到cookie或者本地localStorage中 不过需要跟后端协商过期时间 可以约定刷新令牌或者重新登录
|
||||
token := c.Request.Header.Get("x-token")
|
||||
if token == "" {
|
||||
response.Result(response.ERROR, gin.H{
|
||||
"reload": true,
|
||||
}, "未登录或非法访问", c)
|
||||
response.FailWithDetailed(gin.H{"reload": true}, "未登录或非法访问", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
if service.IsBlacklist(token) {
|
||||
response.Result(response.ERROR, gin.H{
|
||||
"reload": true,
|
||||
}, "您的帐户异地登陆或令牌失效", c)
|
||||
response.FailWithDetailed(gin.H{"reload": true}, "您的帐户异地登陆或令牌失效", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -37,40 +33,34 @@ func JWTAuth() gin.HandlerFunc {
|
||||
claims, err := j.ParseToken(token)
|
||||
if err != nil {
|
||||
if err == TokenExpired {
|
||||
response.Result(response.ERROR, gin.H{
|
||||
"reload": true,
|
||||
}, "授权已过期", c)
|
||||
response.FailWithDetailed(gin.H{"reload": true}, "授权已过期", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
response.Result(response.ERROR, gin.H{
|
||||
"reload": true,
|
||||
}, err.Error(), c)
|
||||
response.FailWithDetailed(gin.H{"reload": true}, err.Error(), c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
if err, _ = service.FindUserByUuid(claims.UUID.String()); err != nil{
|
||||
response.Result(response.ERROR, gin.H{
|
||||
"reload": true,
|
||||
}, err.Error(), c)
|
||||
if err, _ = service.FindUserByUuid(claims.UUID.String()); err != nil {
|
||||
_ = service.JsonInBlacklist(model.JwtBlacklist{Jwt: token})
|
||||
response.FailWithDetailed(gin.H{"reload": true}, err.Error(), c)
|
||||
c.Abort()
|
||||
}
|
||||
if claims.ExpiresAt - time.Now().Unix()<claims.BufferTime {
|
||||
claims.ExpiresAt = time.Now().Unix() + 60*60*24*7
|
||||
newToken,_ := j.CreateToken(*claims)
|
||||
newClaims,_ := j.ParseToken(newToken)
|
||||
c.Header("new-token",newToken)
|
||||
c.Header("new-expires-at",strconv.FormatInt(newClaims.ExpiresAt,10))
|
||||
if claims.ExpiresAt-time.Now().Unix() < claims.BufferTime {
|
||||
claims.ExpiresAt = time.Now().Unix() + global.GVA_CONFIG.JWT.ExpiresTime
|
||||
newToken, _ := j.CreateToken(*claims)
|
||||
newClaims, _ := j.ParseToken(newToken)
|
||||
c.Header("new-token", newToken)
|
||||
c.Header("new-expires-at", strconv.FormatInt(newClaims.ExpiresAt, 10))
|
||||
if global.GVA_CONFIG.System.UseMultipoint {
|
||||
err,RedisJwtToken := service.GetRedisJWT(newClaims.Username)
|
||||
if err!=nil {
|
||||
global.GVA_LOG.Error("get redis jwt failed", zap.Any("err", err))
|
||||
}else{
|
||||
service.JsonInBlacklist(model.JwtBlacklist{Jwt: RedisJwtToken})
|
||||
//当之前的取成功时才进行拉黑操作
|
||||
err, RedisJwtToken := service.GetRedisJWT(newClaims.Username)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("get redis jwt failed", zap.Any("err", err))
|
||||
} else { // 当之前的取成功时才进行拉黑操作
|
||||
_ = service.JsonInBlacklist(model.JwtBlacklist{Jwt: RedisJwtToken})
|
||||
}
|
||||
// 无论如何都要记录当前的活跃状态
|
||||
_ = service.SetRedisJWT(newToken,newClaims.Username)
|
||||
_ = service.SetRedisJWT(newToken, newClaims.Username)
|
||||
}
|
||||
}
|
||||
c.Set("claims", claims)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 处理跨域请求,支持options访问
|
||||
func NeedInit() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if global.GVA_DB == nil {
|
||||
response.OkWithDetailed(gin.H{
|
||||
"needInit": true,
|
||||
}, "前往初始化数据库", c)
|
||||
c.Abort()
|
||||
} else {
|
||||
c.Next()
|
||||
}
|
||||
// 处理请求
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -31,7 +30,7 @@ func OperationRecord() gin.HandlerFunc {
|
||||
if claims, ok := c.Get("claims"); ok {
|
||||
waitUse := claims.(*request.CustomClaims)
|
||||
userId = int(waitUse.ID)
|
||||
}else {
|
||||
} else {
|
||||
id, err := strconv.Atoi(c.Request.Header.Get("x-user-id"))
|
||||
if err != nil {
|
||||
userId = 0
|
||||
@@ -46,10 +45,11 @@ func OperationRecord() gin.HandlerFunc {
|
||||
Body: string(body),
|
||||
UserID: userId,
|
||||
}
|
||||
values := c.Request.Header.Values("content-type")
|
||||
if len(values) >0 && strings.Contains(values[0], "boundary") {
|
||||
record.Body = "file"
|
||||
}
|
||||
// 存在某些未知错误 TODO
|
||||
//values := c.Request.Header.Values("content-type")
|
||||
//if len(values) >0 && strings.Contains(values[0], "boundary") {
|
||||
// record.Body = "file"
|
||||
//}
|
||||
writer := responseBodyWriter{
|
||||
ResponseWriter: c.Writer,
|
||||
body: &bytes.Buffer{},
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gin-vue-admin/global"
|
||||
)
|
||||
|
||||
// file struct, 文件结构体
|
||||
type ExaFile struct {
|
||||
gorm.Model
|
||||
global.GVA_MODEL
|
||||
FileName string
|
||||
FileMd5 string
|
||||
FilePath string
|
||||
@@ -17,7 +17,7 @@ type ExaFile struct {
|
||||
|
||||
// file chunk struct, 切片结构体
|
||||
type ExaFileChunk struct {
|
||||
gorm.Model
|
||||
global.GVA_MODEL
|
||||
ExaFileID uint
|
||||
FileChunkNumber int
|
||||
FileChunkPath string
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gin-vue-admin/global"
|
||||
)
|
||||
|
||||
type ExaCustomer struct {
|
||||
gorm.Model
|
||||
CustomerName string `json:"customerName" form:"customerName" gorm:"comment:客户名"`
|
||||
CustomerPhoneData string `json:"customerPhoneData" form:"customerPhoneData" gorm:"comment:客户手机号"`
|
||||
SysUserID uint `json:"sysUserId" form:"sysUserId" gorm:"comment:管理ID"`
|
||||
SysUserAuthorityID string `json:"sysUserAuthorityID" form:"sysUserAuthorityID" gorm:"comment:管理角色ID"`
|
||||
SysUser SysUser `json:"sysUser" form:"sysUser" gorm:"comment:管理详情"`
|
||||
global.GVA_MODEL
|
||||
CustomerName string `json:"customerName" form:"customerName" gorm:"comment:客户名"` // 客户名
|
||||
CustomerPhoneData string `json:"customerPhoneData" form:"customerPhoneData" gorm:"comment:客户手机号"` // 客户手机号
|
||||
SysUserID uint `json:"sysUserId" form:"sysUserId" gorm:"comment:管理ID"` // 管理ID
|
||||
SysUserAuthorityID string `json:"sysUserAuthorityID" form:"sysUserAuthorityID" gorm:"comment:管理角色ID"` // 管理角色ID
|
||||
SysUser SysUser `json:"sysUser" form:"sysUser" gorm:"comment:管理详情"` // 管理详情
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
type ExcelInfo struct {
|
||||
FileName string `json:"fileName"` // 文件名
|
||||
InfoList []SysBaseMenu `json:"infoList"`
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gin-vue-admin/global"
|
||||
)
|
||||
|
||||
type ExaFileUploadAndDownload struct {
|
||||
gorm.Model
|
||||
Name string `json:"name" gorm:"comment:文件名"`
|
||||
Url string `json:"url" gorm:"comment:文件地址"`
|
||||
Tag string `json:"tag" gorm:"comment:文件标签"`
|
||||
Key string `json:"key" gorm:"comment:编号"`
|
||||
global.GVA_MODEL
|
||||
Name string `json:"name" gorm:"comment:文件名"` // 文件名
|
||||
Url string `json:"url" gorm:"comment:文件地址"` // 文件地址
|
||||
Tag string `json:"tag" gorm:"comment:文件标签"` // 文件标签
|
||||
Key string `json:"key" gorm:"comment:编号"` // 编号
|
||||
}
|
||||
|
||||
@@ -2,15 +2,22 @@ package request
|
||||
|
||||
// Paging common input parameter structure
|
||||
type PageInfo struct {
|
||||
Page int `json:"page" form:"page"`
|
||||
PageSize int `json:"pageSize" form:"pageSize"`
|
||||
Page int `json:"page" form:"page"` // 页码
|
||||
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
|
||||
}
|
||||
|
||||
// Find by id structure
|
||||
type GetById struct {
|
||||
Id float64 `json:"id" form:"id"`
|
||||
ID float64 `json:"id" form:"id"` // 主键ID
|
||||
}
|
||||
|
||||
type IdsReq struct {
|
||||
Ids []int `json:"ids" form:"ids"`
|
||||
}
|
||||
}
|
||||
|
||||
// Get role by id structure
|
||||
type GetAuthorityId struct {
|
||||
AuthorityId string // 角色ID
|
||||
}
|
||||
|
||||
type Empty struct{}
|
||||
|
||||
@@ -6,6 +6,6 @@ import "gin-vue-admin/model"
|
||||
type SearchApiParams struct {
|
||||
model.SysApi
|
||||
PageInfo
|
||||
OrderKey string `json:"orderKey"`
|
||||
Desc bool `json:"desc"`
|
||||
OrderKey string `json:"orderKey"` // 排序
|
||||
Desc bool `json:"desc"` // 排序方式:升序false(默认)|降序true
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package request
|
||||
|
||||
type DBReq struct {
|
||||
Database string `json:"database";gorm:"column:database"`
|
||||
Database string `json:"database" gorm:"column:database"`
|
||||
}
|
||||
|
||||
type TableReq struct {
|
||||
TableName string `json:"tableName"`
|
||||
}
|
||||
|
||||
type ColumeReq struct {
|
||||
ColumeName string `json:"columeName";gorm:"column:colume_name"`
|
||||
DataType string `json:"dataType";gorm:"column:data_type"`
|
||||
DataTypeLong string `json:"dataTypeLong";gorm:"column:data_type_long"`
|
||||
ColumeComment string `json:"columeComment";gorm:"column:colume_comment"`
|
||||
type ColumnReq struct {
|
||||
ColumnName string `json:"columnName" gorm:"column:column_name"`
|
||||
DataType string `json:"dataType" gorm:"column:data_type"`
|
||||
DataTypeLong string `json:"dataTypeLong" gorm:"column:data_type_long"`
|
||||
ColumnComment string `json:"columnComment" gorm:"column:column_comment"`
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package request
|
||||
|
||||
// Casbin info structure
|
||||
type CasbinInfo struct {
|
||||
Path string `json:"path"`
|
||||
Method string `json:"method"`
|
||||
Path string `json:"path"` // 路径
|
||||
Method string `json:"method"` // 方法
|
||||
}
|
||||
|
||||
// Casbin structure for input parameters
|
||||
type CasbinInReceive struct {
|
||||
AuthorityId string `json:"authorityId"`
|
||||
AuthorityId string `json:"authorityId"` // 权限id
|
||||
CasbinInfos []CasbinInfo `json:"casbinInfos"`
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package request
|
||||
|
||||
import "gin-vue-admin/model"
|
||||
|
||||
type SysDictionarySearch struct{
|
||||
model.SysDictionary
|
||||
PageInfo
|
||||
}
|
||||
type SysDictionarySearch struct {
|
||||
model.SysDictionary
|
||||
PageInfo
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package request
|
||||
|
||||
import "gin-vue-admin/model"
|
||||
|
||||
type SysDictionaryDetailSearch struct{
|
||||
model.SysDictionaryDetail
|
||||
PageInfo
|
||||
}
|
||||
type SysDictionaryDetailSearch struct {
|
||||
model.SysDictionaryDetail
|
||||
PageInfo
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package request
|
||||
|
||||
type InitDB struct {
|
||||
Host string `json:"host"` // 服务器地址
|
||||
Port string `json:"port"` // 数据库连接端口
|
||||
UserName string `json:"userName" binding:"required"` // 数据库用户名
|
||||
Password string `json:"password"` // 数据库密码
|
||||
DBName string `json:"dbName" binding:"required"` // 数据库名
|
||||
}
|
||||
@@ -5,10 +5,5 @@ import "gin-vue-admin/model"
|
||||
// Add menu authority info structure
|
||||
type AddMenuAuthorityInfo struct {
|
||||
Menus []model.SysBaseMenu
|
||||
AuthorityId string
|
||||
}
|
||||
|
||||
// Get role by id structure
|
||||
type AuthorityIdInfo struct {
|
||||
AuthorityId string
|
||||
AuthorityId string // 角色ID
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package request
|
||||
import uuid "github.com/satori/go.uuid"
|
||||
|
||||
// User register structure
|
||||
type RegisterStruct struct {
|
||||
type Register struct {
|
||||
Username string `json:"userName"`
|
||||
Password string `json:"passWord"`
|
||||
NickName string `json:"nickName" gorm:"default:'QMPlusUser'"`
|
||||
@@ -12,22 +12,22 @@ type RegisterStruct struct {
|
||||
}
|
||||
|
||||
// User login structure
|
||||
type RegisterAndLoginStruct struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Captcha string `json:"captcha"`
|
||||
CaptchaId string `json:"captchaId"`
|
||||
type Login struct {
|
||||
Username string `json:"username"` // 用户名
|
||||
Password string `json:"password"` // 密码
|
||||
Captcha string `json:"captcha"` // 验证码
|
||||
CaptchaId string `json:"captchaId"` // 验证码ID
|
||||
}
|
||||
|
||||
// Modify password structure
|
||||
type ChangePasswordStruct struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
NewPassword string `json:"newPassword"`
|
||||
Username string `json:"username"` // 用户名
|
||||
Password string `json:"password"` // 密码
|
||||
NewPassword string `json:"newPassword"` // 新密码
|
||||
}
|
||||
|
||||
// Modify user's auth structure
|
||||
type SetUserAuth struct {
|
||||
UUID uuid.UUID `json:"uuid"`
|
||||
AuthorityId string `json:"authorityId"`
|
||||
UUID uuid.UUID `json:"uuid"` // 用户UUID
|
||||
AuthorityId string `json:"authorityId"` // 角色ID
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func OkWithData(data interface{}, c *gin.Context) {
|
||||
Result(SUCCESS, data, "操作成功", c)
|
||||
}
|
||||
|
||||
func OkDetailed(data interface{}, message string, c *gin.Context) {
|
||||
func OkWithDetailed(data interface{}, message string, c *gin.Context) {
|
||||
Result(SUCCESS, data, message, c)
|
||||
}
|
||||
|
||||
@@ -49,6 +49,6 @@ func FailWithMessage(message string, c *gin.Context) {
|
||||
Result(ERROR, map[string]interface{}{}, message, c)
|
||||
}
|
||||
|
||||
func FailWithDetailed(code int, data interface{}, message string, c *gin.Context) {
|
||||
Result(code, data, message, c)
|
||||
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
|
||||
Result(ERROR, data, message, c)
|
||||
}
|
||||
@@ -8,5 +8,5 @@ type SysAuthorityResponse struct {
|
||||
|
||||
type SysAuthorityCopyResponse struct {
|
||||
Authority model.SysAuthority `json:"authority"`
|
||||
OldAuthorityId string `json:"oldAuthorityId"`
|
||||
OldAuthorityId string `json:"oldAuthorityId"` // 旧角色ID
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gin-vue-admin/global"
|
||||
)
|
||||
|
||||
type SysApi struct {
|
||||
gorm.Model
|
||||
Path string `json:"path" gorm:"comment:api路径"`
|
||||
Description string `json:"description" gorm:"comment:api中文描述"`
|
||||
ApiGroup string `json:"apiGroup" gorm:"comment:api组"`
|
||||
Method string `json:"method" gorm:"default:POST" gorm:"comment:方法"`
|
||||
global.GVA_MODEL
|
||||
Path string `json:"path" gorm:"comment:api路径"` // api路径
|
||||
Description string `json:"description" gorm:"comment:api中文描述"` // api中文描述
|
||||
ApiGroup string `json:"apiGroup" gorm:"comment:api组"` // api组
|
||||
Method string `json:"method" gorm:"default:POST" gorm:"comment:方法"` // 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@ import (
|
||||
)
|
||||
|
||||
type SysAuthority struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
CreatedAt time.Time // 创建时间
|
||||
UpdatedAt time.Time // 更新时间
|
||||
DeletedAt *time.Time `sql:"index"`
|
||||
AuthorityId string `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"`
|
||||
AuthorityName string `json:"authorityName" gorm:"comment:角色名"`
|
||||
ParentId string `json:"parentId" gorm:"comment:父角色ID"`
|
||||
AuthorityId string `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"` // 角色ID
|
||||
AuthorityName string `json:"authorityName" gorm:"comment:角色名"` // 角色名
|
||||
ParentId string `json:"parentId" gorm:"comment:父角色ID"` // 父角色ID
|
||||
DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"`
|
||||
Children []SysAuthority `json:"children" gorm:"-"`
|
||||
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"`
|
||||
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard)
|
||||
}
|
||||
|
||||
@@ -1,25 +1,30 @@
|
||||
package model
|
||||
|
||||
import "errors"
|
||||
|
||||
// 初始版本自动化代码工具
|
||||
type AutoCodeStruct struct {
|
||||
StructName string `json:"structName"`
|
||||
TableName string `json:"tableName"`
|
||||
PackageName string `json:"packageName"`
|
||||
Abbreviation string `json:"abbreviation"`
|
||||
Description string `json:"description"`
|
||||
AutoCreateApiToSql bool `json:"autoCreateApiToSql"`
|
||||
Fields []Field `json:"fields"`
|
||||
StructName string `json:"structName"` // Struct名称
|
||||
TableName string `json:"tableName"` // 表名
|
||||
PackageName string `json:"packageName"` // 文件名称
|
||||
Abbreviation string `json:"abbreviation"` // Struct简称
|
||||
Description string `json:"description"` // Struct中文名称
|
||||
AutoCreateApiToSql bool `json:"autoCreateApiToSql"` // 是否自动创建api
|
||||
AutoMoveFile bool `json:"autoMoveFile"` // 是否自动移动文件
|
||||
Fields []*Field `json:"fields"`
|
||||
}
|
||||
|
||||
type Field struct {
|
||||
FieldName string `json:"fieldName"`
|
||||
FieldDesc string `json:"fieldDesc"`
|
||||
FieldType string `json:"fieldType"`
|
||||
FieldJson string `json:"fieldJson"`
|
||||
DataType string `json:"dataType"`
|
||||
DataTypeLong string `json:"dataTypeLong"`
|
||||
Comment string `json:"comment"`
|
||||
ColumnName string `json:"columnName"`
|
||||
FieldSearchType string `json:"fieldSearchType"`
|
||||
DictType string `json:"dictType"`
|
||||
FieldName string `json:"fieldName"` // Field名
|
||||
FieldDesc string `json:"fieldDesc"` // 中文名
|
||||
FieldType string `json:"fieldType"` // Field数据类型
|
||||
FieldJson string `json:"fieldJson"` // FieldJson
|
||||
DataType string `json:"dataType"` // 数据库字段类型
|
||||
DataTypeLong string `json:"dataTypeLong"` // 数据库字段长度
|
||||
Comment string `json:"comment"` // 数据库字段描述
|
||||
ColumnName string `json:"columnName"` // 数据库字段
|
||||
FieldSearchType string `json:"fieldSearchType"` // 搜索条件
|
||||
DictType string `json:"dictType"` // 字典
|
||||
}
|
||||
|
||||
var AutoMoveErr error = errors.New("创建代码成功并移动文件成功")
|
||||
|
||||
@@ -1,35 +1,36 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gin-vue-admin/global"
|
||||
)
|
||||
|
||||
type SysBaseMenu struct {
|
||||
gorm.Model
|
||||
MenuLevel uint `json:"-"`
|
||||
ParentId string `json:"parentId" gorm:"comment:父菜单ID"`
|
||||
Path string `json:"path" gorm:"comment:路由path"`
|
||||
Name string `json:"name" gorm:"comment:路由name"`
|
||||
Hidden bool `json:"hidden" gorm:"comment:是否在列表隐藏"`
|
||||
Component string `json:"component" gorm:"comment:对应前端文件路径"`
|
||||
Sort int `json:"sort" gorm:"comment:排序标记"`
|
||||
Meta `json:"meta" gorm:"comment:附加属性"`
|
||||
global.GVA_MODEL
|
||||
MenuLevel uint `json:"-"`
|
||||
ParentId string `json:"parentId" gorm:"comment:父菜单ID"` // 父菜单ID
|
||||
Path string `json:"path" gorm:"comment:路由path"` // 路由path
|
||||
Name string `json:"name" gorm:"comment:路由name"` // 路由name
|
||||
Hidden bool `json:"hidden" gorm:"comment:是否在列表隐藏"` // 是否在列表隐藏
|
||||
Component string `json:"component" gorm:"comment:对应前端文件路径"` // 对应前端文件路径
|
||||
Sort int `json:"sort" gorm:"comment:排序标记"` // 排序标记
|
||||
Meta `json:"meta" gorm:"comment:附加属性"` // 附加属性
|
||||
SysAuthoritys []SysAuthority `json:"authoritys" gorm:"many2many:sys_authority_menus;"`
|
||||
Children []SysBaseMenu `json:"children" gorm:"-"`
|
||||
Parameters []SysBaseMenuParameter `json:"parameters"`
|
||||
}
|
||||
|
||||
type Meta struct {
|
||||
KeepAlive bool `json:"keepAlive" gorm:"comment:是否缓存"`
|
||||
DefaultMenu bool `json:"defaultMenu" gorm:"comment:是否是基础路由(开发中)"`
|
||||
Title string `json:"title" gorm:"comment:菜单名"`
|
||||
Icon string `json:"icon" gorm:"comment:菜单图标"`
|
||||
KeepAlive bool `json:"keepAlive" gorm:"comment:是否缓存"` // 是否缓存
|
||||
DefaultMenu bool `json:"defaultMenu" gorm:"comment:是否是基础路由(开发中)"` // 是否是基础路由(开发中)
|
||||
Title string `json:"title" gorm:"comment:菜单名"` // 菜单名
|
||||
Icon string `json:"icon" gorm:"comment:菜单图标"` // 菜单图标
|
||||
CloseTab bool `json:"closeTab" gorm:"comment:自动关闭tab"` // 自动关闭tab
|
||||
}
|
||||
|
||||
type SysBaseMenuParameter struct {
|
||||
gorm.Model
|
||||
global.GVA_MODEL
|
||||
SysBaseMenuID uint
|
||||
Type string `json:"type" gorm:"commit:'地址栏携带参数为params还是query'"`
|
||||
Key string `json:"key" gorm:"commit:'地址栏携带参数的key'"`
|
||||
Value string `json:"value" gorm:"commit:'地址栏携带参数的值'"`
|
||||
Type string `json:"type" gorm:"comment:地址栏携带参数为params还是query"` // 地址栏携带参数为params还是query
|
||||
Key string `json:"key" gorm:"comment:地址栏携带参数的key"` // 地址栏携带参数的key
|
||||
Value string `json:"value" gorm:"comment:地址栏携带参数的值"` // 地址栏携带参数的值
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package model
|
||||
|
||||
type CasbinModel struct {
|
||||
Ptype string `json:"ptype" gorm:"column:p_type"`
|
||||
Ptype string `json:"ptype" gorm:"column:ptype"`
|
||||
AuthorityId string `json:"rolename" gorm:"column:v0"`
|
||||
Path string `json:"path" gorm:"column:v1"`
|
||||
Method string `json:"method" gorm:"column:v2"`
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gin-vue-admin/global"
|
||||
)
|
||||
|
||||
// 如果含有time.Time 请自行import time包
|
||||
type SysDictionary struct {
|
||||
gorm.Model
|
||||
Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"`
|
||||
Type string `json:"type" form:"type" gorm:"column:type;comment:字典名(英)"`
|
||||
Status *bool `json:"status" form:"status" gorm:"column:status;comment:状态"`
|
||||
Desc string `json:"desc" form:"desc" gorm:"column:desc;comment:描述"`
|
||||
global.GVA_MODEL
|
||||
Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"` // 字典名(中)
|
||||
Type string `json:"type" form:"type" gorm:"column:type;comment:字典名(英)"` // 字典名(英)
|
||||
Status *bool `json:"status" form:"status" gorm:"column:status;comment:状态"` // 状态
|
||||
Desc string `json:"desc" form:"desc" gorm:"column:desc;comment:描述"` // 描述
|
||||
SysDictionaryDetails []SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"`
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gin-vue-admin/global"
|
||||
)
|
||||
|
||||
// 如果含有time.Time 请自行import time包
|
||||
type SysDictionaryDetail struct {
|
||||
gorm.Model
|
||||
Label string `json:"label" form:"label" gorm:"column:label;comment:展示值"`
|
||||
Value int `json:"value" form:"value" gorm:"column:value;comment:字典值"`
|
||||
Status *bool `json:"status" form:"status" gorm:"column:status;comment:启用状态"`
|
||||
Sort int `json:"sort" form:"sort" gorm:"column:sort;comment:排序标记"`
|
||||
SysDictionaryID int `json:"sysDictionaryID" form:"sysDictionaryID" gorm:"column:sys_dictionary_id;comment:关联标记"`
|
||||
global.GVA_MODEL
|
||||
Label string `json:"label" form:"label" gorm:"column:label;comment:展示值"` // 展示值
|
||||
Value int `json:"value" form:"value" gorm:"column:value;comment:字典值"` // 字典值
|
||||
Status *bool `json:"status" form:"status" gorm:"column:status;comment:启用状态"` // 启用状态
|
||||
Sort int `json:"sort" form:"sort" gorm:"column:sort;comment:排序标记"` // 排序标记
|
||||
SysDictionaryID int `json:"sysDictionaryID" form:"sysDictionaryID" gorm:"column:sys_dictionary_id;comment:关联标记"` // 关联标记
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package model
|
||||
|
||||
type InitDBFunc interface {
|
||||
Init() (err error)
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gin-vue-admin/global"
|
||||
)
|
||||
|
||||
type JwtBlacklist struct {
|
||||
gorm.Model
|
||||
global.GVA_MODEL
|
||||
Jwt string `gorm:"type:text;comment:jwt"`
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gin-vue-admin/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 如果含有time.Time 请自行import time包
|
||||
type SysOperationRecord struct {
|
||||
gorm.Model
|
||||
Ip string `json:"ip" form:"ip" gorm:"column:ip;comment:请求ip"`
|
||||
Method string `json:"method" form:"method" gorm:"column:method;comment:请求方法"`
|
||||
Path string `json:"path" form:"path" gorm:"column:path;comment:请求路径"`
|
||||
Status int `json:"status" form:"status" gorm:"column:status;comment:请求状态"`
|
||||
Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:延迟"`
|
||||
Agent string `json:"agent" form:"agent" gorm:"column:agent;comment:代理"`
|
||||
ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"`
|
||||
Body string `json:"body" form:"body" gorm:"type:longtext;column:body;comment:请求Body"`
|
||||
Resp string `json:"resp" form:"resp" gorm:"type:longtext;column:resp;comment:响应Body"`
|
||||
UserID int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"`
|
||||
global.GVA_MODEL
|
||||
Ip string `json:"ip" form:"ip" gorm:"column:ip;comment:请求ip"` // 请求ip
|
||||
Method string `json:"method" form:"method" gorm:"column:method;comment:请求方法"` // 请求方法
|
||||
Path string `json:"path" form:"path" gorm:"column:path;comment:请求路径"` // 请求路径
|
||||
Status int `json:"status" form:"status" gorm:"column:status;comment:请求状态"` // 请求状态
|
||||
Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:延迟" swaggertype:"string"` // 延迟
|
||||
Agent string `json:"agent" form:"agent" gorm:"column:agent;comment:代理"` // 代理
|
||||
ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"` // 错误信息
|
||||
Body string `json:"body" form:"body" gorm:"type:longtext;column:body;comment:请求Body"` // 请求Body
|
||||
Resp string `json:"resp" form:"resp" gorm:"type:longtext;column:resp;comment:响应Body"` // 响应Body
|
||||
UserID int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"` // 用户id
|
||||
User SysUser `json:"user"`
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"github.com/satori/go.uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type SysUser struct {
|
||||
gorm.Model
|
||||
UUID uuid.UUID `json:"uuid" gorm:"comment:用户UUID"`
|
||||
Username string `json:"userName" gorm:"comment:用户登录名"`
|
||||
Password string `json:"-" gorm:"comment:用户登录密码"`
|
||||
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称" `
|
||||
HeaderImg string `json:"headerImg" gorm:"default:http://qmplusimg.henrongyi.top/head.png;comment:用户头像"`
|
||||
global.GVA_MODEL
|
||||
UUID uuid.UUID `json:"uuid" gorm:"comment:用户UUID"` // 用户UUID
|
||||
Username string `json:"userName" gorm:"comment:用户登录名"` // 用户登录名
|
||||
Password string `json:"-" gorm:"comment:用户登录密码"` // 用户登录密码
|
||||
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
|
||||
HeaderImg string `json:"headerImg" gorm:"default:http://qmplusimg.henrongyi.top/head.png;comment:用户头像"` // 用户头像
|
||||
Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"`
|
||||
AuthorityId string `json:"authorityId" gorm:"default:888;comment:用户角色ID"`
|
||||
AuthorityId string `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 工作流属性表
|
||||
type SysWorkflow struct {
|
||||
gorm.Model
|
||||
WorkflowNickName string `json:"workflowNickName" gorm:"comment:工作流中文名称"` // 工作流名称
|
||||
WorkflowName string `json:"workflowName" gorm:"comment:工作流英文名称"` // 工作流英文id
|
||||
WorkflowDescription string `json:"workflowDescription" gorm:"comment:工作流描述"` // 工作流描述
|
||||
WorkflowStepInfo []SysWorkflowStepInfo `json:"workflowStep" gorm:"comment:工作流步骤"` // 工作流步骤
|
||||
}
|
||||
|
||||
// 工作流状态表
|
||||
type SysWorkflowStepInfo struct {
|
||||
gorm.Model
|
||||
SysWorkflowID uint `json:"workflowID" gorm:"comment:所属工作流ID"` // 所属工作流ID
|
||||
IsStart bool `json:"isStart" gorm:"comment:是否是开始流节点"` // 是否是开始流节点
|
||||
StepName string `json:"stepName" gorm:"comment:工作流节点名称"` // 工作流名称
|
||||
StepNo float64 `json:"stepNo" gorm:"comment:步骤id (第几步)"` // 步骤id (第几步)
|
||||
StepAuthorityID string `json:"stepAuthorityID" gorm:"comment:操作者级别id"` // 操作者级别id
|
||||
IsEnd bool `json:"isEnd" gorm:"comment:是否是完结流节点"` // 是否是完结流节点
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package model
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
// 工作流流转表
|
||||
type SysWorkFlowProcess struct {
|
||||
gorm.Model
|
||||
ApplicationID uint `json:"applicationID" gorm:"comment:当前工作流所属申请的ID"` // 当前工作流所属申请的ID
|
||||
CurrentNode string `json:"currentNode" gorm:"comment:当前进度节点"` // 当前进度节点
|
||||
HistoricalNode string `json:"historicalNode" gorm:"comment:上一个进度节点"` // 上一个进度节点
|
||||
CurrentUser string `json:"currentUser" gorm:"comment:当前进度操作人"` // 当前进度操作人
|
||||
HistoricalUser string `json:"historicalUser" gorm:"comment:上一个进度的操作人"` // 上一个进度的操作人
|
||||
State bool `json:"state" gorm:"comment:是否是正在进行的状态"` // 状态 是否是正在进行的状态
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
.test-form[data-v-77b1aafa]{margin:15px auto;width:800px;padding:15px}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user