Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JAVA小学生-王铁柱
eladmin
提交
81078698
E
eladmin
项目概览
JAVA小学生-王铁柱
/
eladmin
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
eladmin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
81078698
编写于
12月 28, 2018
作者:
郑
郑杰
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
v1.2 版本发布,详细信息查看发行版说明
上级
d787ed30
变更
31
隐藏空白更改
内联
并排
Showing
31 changed file
with
1141 addition
and
72 deletion
+1141
-72
pom.xml
pom.xml
+7
-0
sql/eladmin.sql
sql/eladmin.sql
+89
-57
src/main/java/me/zhengjie/common/redis/RedisConfig.java
src/main/java/me/zhengjie/common/redis/RedisConfig.java
+1
-0
src/main/java/me/zhengjie/common/utils/ElAdminConstant.java
src/main/java/me/zhengjie/common/utils/ElAdminConstant.java
+32
-0
src/main/java/me/zhengjie/common/utils/FileUtil.java
src/main/java/me/zhengjie/common/utils/FileUtil.java
+119
-0
src/main/java/me/zhengjie/core/utils/EncryptUtils.java
src/main/java/me/zhengjie/core/utils/EncryptUtils.java
+76
-0
src/main/java/me/zhengjie/system/domain/Menu.java
src/main/java/me/zhengjie/system/domain/Menu.java
+1
-1
src/main/java/me/zhengjie/system/domain/VerificationCode.java
...main/java/me/zhengjie/system/domain/VerificationCode.java
+45
-0
src/main/java/me/zhengjie/system/repository/MenuRepository.java
...in/java/me/zhengjie/system/repository/MenuRepository.java
+1
-1
src/main/java/me/zhengjie/system/repository/VerificationCodeRepository.java
...hengjie/system/repository/VerificationCodeRepository.java
+12
-0
src/main/java/me/zhengjie/system/rest/MenuController.java
src/main/java/me/zhengjie/system/rest/MenuController.java
+3
-3
src/main/java/me/zhengjie/system/rest/PermissionController.java
...in/java/me/zhengjie/system/rest/PermissionController.java
+1
-1
src/main/java/me/zhengjie/system/rest/RoleController.java
src/main/java/me/zhengjie/system/rest/RoleController.java
+6
-6
src/main/java/me/zhengjie/system/rest/VerificationCodeController.java
...a/me/zhengjie/system/rest/VerificationCodeController.java
+33
-0
src/main/java/me/zhengjie/system/service/VerificationCodeService.java
...a/me/zhengjie/system/service/VerificationCodeService.java
+22
-0
src/main/java/me/zhengjie/system/service/dto/MenuDTO.java
src/main/java/me/zhengjie/system/service/dto/MenuDTO.java
+1
-1
src/main/java/me/zhengjie/system/service/impl/MenuServiceImpl.java
...java/me/zhengjie/system/service/impl/MenuServiceImpl.java
+27
-2
src/main/java/me/zhengjie/system/service/impl/VerificationCodeServiceImpl.java
...gjie/system/service/impl/VerificationCodeServiceImpl.java
+23
-0
src/main/java/me/zhengjie/tools/config/MultipartConfig.java
src/main/java/me/zhengjie/tools/config/MultipartConfig.java
+30
-0
src/main/java/me/zhengjie/tools/domain/EmailConfig.java
src/main/java/me/zhengjie/tools/domain/EmailConfig.java
+48
-0
src/main/java/me/zhengjie/tools/domain/Picture.java
src/main/java/me/zhengjie/tools/domain/Picture.java
+51
-0
src/main/java/me/zhengjie/tools/domain/vo/EmailVo.java
src/main/java/me/zhengjie/tools/domain/vo/EmailVo.java
+29
-0
src/main/java/me/zhengjie/tools/repository/EmailRepository.java
...in/java/me/zhengjie/tools/repository/EmailRepository.java
+11
-0
src/main/java/me/zhengjie/tools/repository/PictureRepository.java
.../java/me/zhengjie/tools/repository/PictureRepository.java
+12
-0
src/main/java/me/zhengjie/tools/rest/EmailController.java
src/main/java/me/zhengjie/tools/rest/EmailController.java
+50
-0
src/main/java/me/zhengjie/tools/rest/PictureController.java
src/main/java/me/zhengjie/tools/rest/PictureController.java
+74
-0
src/main/java/me/zhengjie/tools/service/EmailService.java
src/main/java/me/zhengjie/tools/service/EmailService.java
+41
-0
src/main/java/me/zhengjie/tools/service/PictureService.java
src/main/java/me/zhengjie/tools/service/PictureService.java
+39
-0
src/main/java/me/zhengjie/tools/service/impl/EmailServiceImpl.java
...java/me/zhengjie/tools/service/impl/EmailServiceImpl.java
+89
-0
src/main/java/me/zhengjie/tools/service/impl/PictureServiceImpl.java
...va/me/zhengjie/tools/service/impl/PictureServiceImpl.java
+102
-0
src/main/java/me/zhengjie/tools/service/query/PictureQueryService.java
.../me/zhengjie/tools/service/query/PictureQueryService.java
+66
-0
未找到文件。
pom.xml
浏览文件 @
81078698
...
...
@@ -151,6 +151,13 @@
<version>
1
</version>
</dependency>
<!--邮件依赖-->
<dependency>
<groupId>
javax.mail
</groupId>
<artifactId>
mail
</artifactId>
<version>
1.4.7
</version>
</dependency>
</dependencies>
<repositories>
...
...
sql/eladmin.sql
浏览文件 @
81078698
...
...
@@ -11,29 +11,25 @@
Target Server Version : 50559
File Encoding : 65001
Date: 2
5/12/2018 11:00:27
Date: 2
8/12/2018 17:50:46
*/
SET
NAMES
utf8mb4
;
SET
FOREIGN_KEY_CHECKS
=
0
;
-- ----------------------------
-- Table structure for
lo
g
-- Table structure for
email_confi
g
-- ----------------------------
DROP
TABLE
IF
EXISTS
`
lo
g`
;
CREATE
TABLE
`
lo
g`
(
DROP
TABLE
IF
EXISTS
`
email_confi
g`
;
CREATE
TABLE
`
email_confi
g`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`createTime`
datetime
NULL
DEFAULT
NULL
,
`description`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`exceptionDetail`
varchar
(
1500
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`logType`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`method`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`params`
varchar
(
1500
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`requestIp`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`time`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`username`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`fromUser`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`host`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`pass`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`port`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`user`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
3081
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
2
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
-- ----------------------------
-- Table structure for menu
...
...
@@ -46,11 +42,11 @@ CREATE TABLE `menu` (
`name`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`component`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`pid`
bigint
(
20
)
NOT
NULL
,
`so
f
t`
bigint
(
20
)
NOT
NULL
,
`so
r
t`
bigint
(
20
)
NOT
NULL
,
`icon`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`path`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
3
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
8
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
-- ----------------------------
-- Records of menu
...
...
@@ -64,9 +60,14 @@ INSERT INTO `menu` VALUES (6, '2018-12-18 15:17:48', b'0', '系统监控', NULL,
INSERT
INTO
`menu`
VALUES
(
7
,
'2018-12-18 15:18:26'
,
b
'0'
,
'系统日志'
,
'monitor/log/index'
,
6
,
11
,
'log'
,
'logs'
);
INSERT
INTO
`menu`
VALUES
(
8
,
'2018-12-18 15:19:01'
,
b
'0'
,
'系统缓存'
,
'monitor/redis/index'
,
6
,
12
,
'redis'
,
'redis'
);
INSERT
INTO
`menu`
VALUES
(
9
,
'2018-12-18 15:19:34'
,
b
'1'
,
'SQL监控'
,
NULL
,
6
,
14
,
'sqlMonitor'
,
'http://localhost/druid'
);
INSERT
INTO
`menu`
VALUES
(
10
,
'2018-12-19 13:38:16'
,
b
'0'
,
'组件管理'
,
NULL
,
0
,
2
0
,
'zujian'
,
'components'
);
INSERT
INTO
`menu`
VALUES
(
11
,
'2018-12-19 13:38:49'
,
b
'0'
,
'图标库'
,
'components/IconSelect'
,
10
,
2
1
,
'icon'
,
'icon'
);
INSERT
INTO
`menu`
VALUES
(
10
,
'2018-12-19 13:38:16'
,
b
'0'
,
'组件管理'
,
NULL
,
0
,
5
0
,
'zujian'
,
'components'
);
INSERT
INTO
`menu`
VALUES
(
11
,
'2018-12-19 13:38:49'
,
b
'0'
,
'图标库'
,
'components/IconSelect'
,
10
,
5
1
,
'icon'
,
'icon'
);
INSERT
INTO
`menu`
VALUES
(
12
,
'2018-12-24 20:37:35'
,
b
'0'
,
'实时控制台'
,
'monitor/log/msg'
,
6
,
13
,
'codeConsole'
,
'msg'
);
INSERT
INTO
`menu`
VALUES
(
13
,
'2018-12-27 10:11:26'
,
b
'0'
,
'三方工具'
,
''
,
0
,
20
,
'tools'
,
'tools'
);
INSERT
INTO
`menu`
VALUES
(
14
,
'2018-12-27 10:13:09'
,
b
'0'
,
'邮件工具'
,
'tools/email/index'
,
13
,
21
,
'email'
,
'email'
);
INSERT
INTO
`menu`
VALUES
(
15
,
'2018-12-27 11:58:25'
,
b
'0'
,
'富文本'
,
'components/Editor'
,
10
,
52
,
'fwb'
,
'tinymce'
);
INSERT
INTO
`menu`
VALUES
(
16
,
'2018-12-28 09:36:53'
,
b
'0'
,
'SM.MS图床'
,
'tools/picture/index'
,
13
,
22
,
'image'
,
'pictures'
);
INSERT
INTO
`menu`
VALUES
(
17
,
'2018-12-28 15:09:49'
,
b
'1'
,
'项目地址'
,
''
,
0
,
0
,
'github'
,
'https://github.com/elunez/eladmin'
);
-- ----------------------------
-- Table structure for menus_roles
...
...
@@ -96,6 +97,22 @@ INSERT INTO `menus_roles` VALUES (9, 1);
INSERT
INTO
`menus_roles`
VALUES
(
10
,
1
);
INSERT
INTO
`menus_roles`
VALUES
(
11
,
1
);
INSERT
INTO
`menus_roles`
VALUES
(
12
,
1
);
INSERT
INTO
`menus_roles`
VALUES
(
13
,
1
);
INSERT
INTO
`menus_roles`
VALUES
(
14
,
1
);
INSERT
INTO
`menus_roles`
VALUES
(
15
,
1
);
INSERT
INTO
`menus_roles`
VALUES
(
16
,
1
);
INSERT
INTO
`menus_roles`
VALUES
(
17
,
1
);
INSERT
INTO
`menus_roles`
VALUES
(
1
,
2
);
INSERT
INTO
`menus_roles`
VALUES
(
2
,
2
);
INSERT
INTO
`menus_roles`
VALUES
(
3
,
2
);
INSERT
INTO
`menus_roles`
VALUES
(
4
,
2
);
INSERT
INTO
`menus_roles`
VALUES
(
5
,
2
);
INSERT
INTO
`menus_roles`
VALUES
(
6
,
2
);
INSERT
INTO
`menus_roles`
VALUES
(
9
,
2
);
INSERT
INTO
`menus_roles`
VALUES
(
12
,
2
);
INSERT
INTO
`menus_roles`
VALUES
(
13
,
2
);
INSERT
INTO
`menus_roles`
VALUES
(
16
,
2
);
INSERT
INTO
`menus_roles`
VALUES
(
17
,
2
);
-- ----------------------------
-- Table structure for permission
...
...
@@ -108,7 +125,7 @@ CREATE TABLE `permission` (
`name`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`pid`
int
(
11
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
23
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
34
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
-- ----------------------------
-- Records of permission
...
...
@@ -119,11 +136,11 @@ INSERT INTO `permission` VALUES (3, '用户查询', '2018-12-03 12:31:35', 'USER
INSERT
INTO
`permission`
VALUES
(
4
,
'用户创建'
,
'2018-12-03 12:31:35'
,
'USER_CREATE'
,
2
);
INSERT
INTO
`permission`
VALUES
(
5
,
'用户编辑'
,
'2018-12-03 12:31:35'
,
'USER_EDIT'
,
2
);
INSERT
INTO
`permission`
VALUES
(
6
,
'用户删除'
,
'2018-12-03 12:31:35'
,
'USER_DELETE'
,
2
);
INSERT
INTO
`permission`
VALUES
(
7
,
'角色管理'
,
'2018-12-03 12:28:19'
,
'ROLE_ALL'
,
0
);
INSERT
INTO
`permission`
VALUES
(
8
,
'角色查询'
,
'2018-12-03 12:31:35'
,
'ROLE_SELECT'
,
7
);
INSERT
INTO
`permission`
VALUES
(
10
,
'角色创建'
,
'2018-12-09 20:10:16'
,
'ROLE_CREATE'
,
7
);
INSERT
INTO
`permission`
VALUES
(
11
,
'角色编辑'
,
'2018-12-09 20:10:42'
,
'ROLE_EDIT'
,
7
);
INSERT
INTO
`permission`
VALUES
(
12
,
'角色删除'
,
'2018-12-09 20:11:07'
,
'ROLE_DELETE'
,
7
);
INSERT
INTO
`permission`
VALUES
(
7
,
'角色管理'
,
'2018-12-03 12:28:19'
,
'ROLE
S
_ALL'
,
0
);
INSERT
INTO
`permission`
VALUES
(
8
,
'角色查询'
,
'2018-12-03 12:31:35'
,
'ROLE
S
_SELECT'
,
7
);
INSERT
INTO
`permission`
VALUES
(
10
,
'角色创建'
,
'2018-12-09 20:10:16'
,
'ROLE
S
_CREATE'
,
7
);
INSERT
INTO
`permission`
VALUES
(
11
,
'角色编辑'
,
'2018-12-09 20:10:42'
,
'ROLE
S
_EDIT'
,
7
);
INSERT
INTO
`permission`
VALUES
(
12
,
'角色删除'
,
'2018-12-09 20:11:07'
,
'ROLE
S
_DELETE'
,
7
);
INSERT
INTO
`permission`
VALUES
(
13
,
'权限管理'
,
'2018-12-09 20:11:37'
,
'PERMISSION_ALL'
,
0
);
INSERT
INTO
`permission`
VALUES
(
14
,
'权限查询'
,
'2018-12-09 20:11:55'
,
'PERMISSION_SELECT'
,
13
);
INSERT
INTO
`permission`
VALUES
(
15
,
'权限创建'
,
'2018-12-09 20:14:10'
,
'PERMISSION_CREATE'
,
13
);
...
...
@@ -134,6 +151,37 @@ INSERT INTO `permission` VALUES (19, '新增缓存', '2018-12-17 13:53:44', 'RED
INSERT
INTO
`permission`
VALUES
(
20
,
'缓存查询'
,
'2018-12-17 13:54:07'
,
'REDIS_SELECT'
,
18
);
INSERT
INTO
`permission`
VALUES
(
21
,
'缓存编辑'
,
'2018-12-17 13:54:26'
,
'REDIS_EDIT'
,
18
);
INSERT
INTO
`permission`
VALUES
(
22
,
'缓存删除'
,
'2018-12-17 13:55:04'
,
'REDIS_DELETE'
,
18
);
INSERT
INTO
`permission`
VALUES
(
23
,
'图床管理'
,
'2018-12-27 20:31:49'
,
'PICTURE_ALL'
,
0
);
INSERT
INTO
`permission`
VALUES
(
24
,
'查询图片'
,
'2018-12-27 20:32:04'
,
'PICTURE_SELECT'
,
23
);
INSERT
INTO
`permission`
VALUES
(
25
,
'上传图片'
,
'2018-12-27 20:32:24'
,
'PICTURE_UPLOAD'
,
23
);
INSERT
INTO
`permission`
VALUES
(
26
,
'删除图片'
,
'2018-12-27 20:32:45'
,
'PICTURE_DELETE'
,
23
);
INSERT
INTO
`permission`
VALUES
(
29
,
'菜单管理'
,
'2018-12-28 17:34:31'
,
'MENU_ALL'
,
0
);
INSERT
INTO
`permission`
VALUES
(
30
,
'菜单查询'
,
'2018-12-28 17:34:41'
,
'MENU_SELECT'
,
29
);
INSERT
INTO
`permission`
VALUES
(
31
,
'菜单创建'
,
'2018-12-28 17:34:52'
,
'MENU_CREATE'
,
29
);
INSERT
INTO
`permission`
VALUES
(
32
,
'菜单编辑'
,
'2018-12-28 17:35:20'
,
'MENU_EDIT'
,
29
);
INSERT
INTO
`permission`
VALUES
(
33
,
'菜单删除'
,
'2018-12-28 17:35:29'
,
'MENU_DELETE'
,
29
);
-- ----------------------------
-- Table structure for picture
-- ----------------------------
DROP
TABLE
IF
EXISTS
`picture`
;
CREATE
TABLE
`picture`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`createTime`
datetime
NULL
DEFAULT
NULL
,
`delete_url`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`filename`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`height`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`size`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`url`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`username`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`width`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
38
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
-- ----------------------------
-- Records of picture
-- ----------------------------
INSERT
INTO
`picture`
VALUES
(
34
,
'2018-12-28 16:02:42'
,
'https://sm.ms/delete/JDAtayhFMH56wCXE'
,
'1'
,
'220'
,
'3.73KB '
,
'https://i.loli.net/2018/12/28/5c25d8a253445.jpg'
,
'admin'
,
'229'
);
-- ----------------------------
-- Table structure for role
...
...
@@ -145,7 +193,7 @@ CREATE TABLE `role` (
`name`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NOT
NULL
,
`remark`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
3
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
4
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
-- ----------------------------
-- Records of role
...
...
@@ -170,9 +218,12 @@ CREATE TABLE `roles_permissions` (
-- Records of roles_permissions
-- ----------------------------
INSERT
INTO
`roles_permissions`
VALUES
(
1
,
1
);
INSERT
INTO
`roles_permissions`
VALUES
(
2
,
1
);
INSERT
INTO
`roles_permissions`
VALUES
(
2
,
3
);
INSERT
INTO
`roles_permissions`
VALUES
(
2
,
4
);
INSERT
INTO
`roles_permissions`
VALUES
(
2
,
8
);
INSERT
INTO
`roles_permissions`
VALUES
(
2
,
14
);
INSERT
INTO
`roles_permissions`
VALUES
(
2
,
19
);
INSERT
INTO
`roles_permissions`
VALUES
(
2
,
23
);
INSERT
INTO
`roles_permissions`
VALUES
(
2
,
30
);
-- ----------------------------
-- Table structure for user
...
...
@@ -190,12 +241,13 @@ CREATE TABLE `user` (
PRIMARY
KEY
(
`id`
)
USING
BTREE
,
UNIQUE
INDEX
`UK_kpubos9gc2cvtkb0thktkbkes`
(
`email`
)
USING
BTREE
,
UNIQUE
INDEX
`username`
(
`username`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
15
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
8
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT
INTO
`user`
VALUES
(
1
,
'https://i.loli.net/2018/12/06/5c08894d8de21.jpg'
,
'2018-08-23 09:11:56'
,
'zhengjie@tom.com'
,
1
,
'14e1b600b1fd579f47433b88e8d85291'
,
'admin'
,
'2018-11-23 10:12:36'
);
INSERT
INTO
`user`
VALUES
(
3
,
'https://i.loli.net/2018/12/06/5c08894d8de21.jpg'
,
'2018-12-27 20:05:26'
,
'test@qq.com'
,
1
,
'14e1b600b1fd579f47433b88e8d85291'
,
'test'
,
NULL
);
-- ----------------------------
-- Table structure for users_roles
...
...
@@ -214,41 +266,21 @@ CREATE TABLE `users_roles` (
-- Records of users_roles
-- ----------------------------
INSERT
INTO
`users_roles`
VALUES
(
1
,
1
);
INSERT
INTO
`users_roles`
VALUES
(
3
,
2
);
-- ----------------------------
-- Table structure for v
isits
-- Table structure for v
erification_code
-- ----------------------------
DROP
TABLE
IF
EXISTS
`v
isits
`
;
CREATE
TABLE
`v
isits
`
(
DROP
TABLE
IF
EXISTS
`v
erification_code
`
;
CREATE
TABLE
`v
erification_code
`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`date`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`ip_counts`
bigint
(
20
)
NULL
DEFAULT
NULL
,
`pv_counts`
bigint
(
20
)
NULL
DEFAULT
NULL
,
`weekDay`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`code`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`createTime`
datetime
NULL
DEFAULT
NULL
,
`status`
bit
(
1
)
NULL
DEFAULT
NULL
,
`type`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`value`
varchar
(
255
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
38
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Compact
;
-- ----------------------------
-- Records of visits
-- ----------------------------
INSERT
INTO
`visits`
VALUES
(
1
,
'2018-12-06'
,
30
,
45
,
'Thu'
,
'2018-12-06 18:06:14'
);
INSERT
INTO
`visits`
VALUES
(
2
,
'2018-12-07'
,
10
,
30
,
'Fri'
,
'2018-12-07 18:06:19'
);
INSERT
INTO
`visits`
VALUES
(
3
,
'2018-12-08'
,
10
,
30
,
'Sat'
,
'2018-12-08 18:06:23'
);
INSERT
INTO
`visits`
VALUES
(
4
,
'2018-12-09'
,
56
,
50
,
'Sun'
,
'2018-12-09 18:06:27'
);
INSERT
INTO
`visits`
VALUES
(
5
,
'2018-12-10'
,
20
,
50
,
'Mon'
,
'2018-12-10 18:06:32'
);
INSERT
INTO
`visits`
VALUES
(
6
,
'2018-12-11'
,
79
,
50
,
'Tue'
,
'2018-12-11 18:06:35'
);
INSERT
INTO
`visits`
VALUES
(
7
,
'2018-12-12'
,
54
,
23
,
'Wed'
,
'2018-12-12 18:06:38'
);
INSERT
INTO
`visits`
VALUES
(
11
,
'2018-12-13'
,
2
,
2
,
'Thu'
,
'2018-12-13 20:49:27'
);
INSERT
INTO
`visits`
VALUES
(
13
,
'2018-12-14'
,
1
,
27
,
'Fri'
,
'2018-12-14 09:21:00'
);
INSERT
INTO
`visits`
VALUES
(
15
,
'2018-12-17'
,
1
,
19
,
'Mon'
,
'2018-12-17 12:49:28'
);
INSERT
INTO
`visits`
VALUES
(
16
,
'2018-12-18'
,
1
,
72
,
'Tue'
,
'2018-12-18 15:13:33'
);
INSERT
INTO
`visits`
VALUES
(
26
,
'2018-12-19'
,
1
,
51
,
'Wed'
,
'2018-12-19 12:54:12'
);
INSERT
INTO
`visits`
VALUES
(
27
,
'2018-12-20'
,
1
,
226
,
'Thu'
,
'2018-12-20 09:21:13'
);
INSERT
INTO
`visits`
VALUES
(
28
,
'2018-12-21'
,
1
,
80
,
'Fri'
,
'2018-12-21 09:38:04'
);
INSERT
INTO
`visits`
VALUES
(
29
,
'2018-12-22'
,
1
,
42
,
'Sat'
,
'2018-12-22 10:06:59'
);
INSERT
INTO
`visits`
VALUES
(
30
,
'2018-12-23'
,
1
,
2
,
'Sun'
,
'2018-12-23 11:16:52'
);
INSERT
INTO
`visits`
VALUES
(
35
,
'2018-12-24'
,
1
,
8
,
'Mon'
,
'2018-12-24 19:12:01'
);
INSERT
INTO
`visits`
VALUES
(
36
,
'2018-12-25'
,
1
,
6
,
'Tue'
,
'2018-12-25 00:12:35'
);
SET
FOREIGN_KEY_CHECKS
=
1
;
src/main/java/me/zhengjie/common/redis/RedisConfig.java
浏览文件 @
81078698
...
...
@@ -94,6 +94,7 @@ public class RedisConfig extends CachingConfigurerSupport {
// 建议使用这种方式,小范围指定白名单
ParserConfig
.
getGlobalInstance
().
addAccept
(
"me.zhengjie.system.service.dto"
);
ParserConfig
.
getGlobalInstance
().
addAccept
(
"me.zhengjie.system.domain"
);
ParserConfig
.
getGlobalInstance
().
addAccept
(
"me.zhengjie.tools.domain"
);
// key的序列化采用StringRedisSerializer
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
...
...
src/main/java/me/zhengjie/common/utils/ElAdminConstant.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.common.utils
;
/**
* 常用静态常量
* @author jie
* @date 2018-12-26
*/
public
class
ElAdminConstant
{
/**
* 用于七牛云zone与机房对应关系
*/
public
static
class
QiNiu
{
public
static
final
String
HUAD
=
"华东"
;
public
static
final
String
HUAB
=
"华北"
;
public
static
final
String
HUAN
=
"华南"
;
public
static
final
String
BEIM
=
"北美"
;
public
static
final
String
DNY
=
"东南亚"
;
}
/**
* 常用接口
*/
public
static
class
Url
{
public
static
final
String
SM_MS_URL
=
"https://sm.ms/api/upload"
;
}
}
src/main/java/me/zhengjie/common/utils/FileUtil.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.common.utils
;
import
cn.hutool.core.util.IdUtil
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.IOException
;
import
java.text.DecimalFormat
;
/**
* File工具类
* @author jie
* @date 2018-12-27
*/
public
class
FileUtil
{
/**
* 定义GB的计算常量
*/
private
static
final
int
GB
=
1024
*
1024
*
1024
;
/**
* 定义MB的计算常量
*/
private
static
final
int
MB
=
1024
*
1024
;
/**
* 定义KB的计算常量
*/
private
static
final
int
KB
=
1024
;
/**
* 格式化小数
*/
private
static
final
DecimalFormat
DF
=
new
DecimalFormat
(
"0.00"
);
/**
* MultipartFile转File
* @param multipartFile
* @return
*/
public
static
File
toFile
(
MultipartFile
multipartFile
){
// 获取文件名
String
fileName
=
multipartFile
.
getOriginalFilename
();
// 获取文件后缀
String
prefix
=
"."
+
getExtensionName
(
fileName
);
File
file
=
null
;
try
{
// 用uuid作为文件名,防止生成的临时文件重复
file
=
File
.
createTempFile
(
IdUtil
.
simpleUUID
(),
prefix
);
// MultipartFile to File
multipartFile
.
transferTo
(
file
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
file
;
}
/**
* 删除
* @param files
*/
public
static
void
deleteFile
(
File
...
files
)
{
for
(
File
file
:
files
)
{
if
(
file
.
exists
())
{
file
.
delete
();
}
}
}
/**
* 获取文件扩展名
* @param filename
* @return
*/
public
static
String
getExtensionName
(
String
filename
)
{
if
((
filename
!=
null
)
&&
(
filename
.
length
()
>
0
))
{
int
dot
=
filename
.
lastIndexOf
(
'.'
);
if
((
dot
>-
1
)
&&
(
dot
<
(
filename
.
length
()
-
1
)))
{
return
filename
.
substring
(
dot
+
1
);
}
}
return
filename
;
}
/**
* Java文件操作 获取不带扩展名的文件名
* @param filename
* @return
*/
public
static
String
getFileNameNoEx
(
String
filename
)
{
if
((
filename
!=
null
)
&&
(
filename
.
length
()
>
0
))
{
int
dot
=
filename
.
lastIndexOf
(
'.'
);
if
((
dot
>-
1
)
&&
(
dot
<
(
filename
.
length
())))
{
return
filename
.
substring
(
0
,
dot
);
}
}
return
filename
;
}
/**
* 文件大小转换
* @param size
* @return
*/
public
static
String
getSize
(
int
size
){
String
resultSize
=
""
;
if
(
size
/
GB
>=
1
)
{
//如果当前Byte的值大于等于1GB
resultSize
=
DF
.
format
(
size
/
(
float
)
GB
)
+
"GB "
;
}
else
if
(
size
/
MB
>=
1
)
{
//如果当前Byte的值大于等于1MB
resultSize
=
DF
.
format
(
size
/
(
float
)
MB
)
+
"MB "
;
}
else
if
(
size
/
KB
>=
1
)
{
//如果当前Byte的值大于等于1KB
resultSize
=
DF
.
format
(
size
/
(
float
)
KB
)
+
"KB "
;
}
else
{
resultSize
=
size
+
"B "
;
}
return
resultSize
;
}
}
src/main/java/me/zhengjie/core/utils/EncryptUtils.java
浏览文件 @
81078698
package
me.zhengjie.core.utils
;
import
org.springframework.util.DigestUtils
;
import
javax.crypto.Cipher
;
import
javax.crypto.SecretKey
;
import
javax.crypto.SecretKeyFactory
;
import
javax.crypto.spec.DESKeySpec
;
import
javax.crypto.spec.IvParameterSpec
;
/**
* 加密
...
...
@@ -9,6 +14,77 @@ import org.springframework.util.DigestUtils;
*/
public
class
EncryptUtils
{
private
static
String
strKey
=
"Passw0rd"
,
strParam
=
"Passw0rd"
;
/**
* 对称加密
* @param source
* @return
* @throws Exception
*/
public
static
String
desEncrypt
(
String
source
)
throws
Exception
{
if
(
source
==
null
||
source
.
length
()
==
0
){
return
null
;
}
Cipher
cipher
=
Cipher
.
getInstance
(
"DES/CBC/PKCS5Padding"
);
DESKeySpec
desKeySpec
=
new
DESKeySpec
(
strKey
.
getBytes
(
"UTF-8"
));
SecretKeyFactory
keyFactory
=
SecretKeyFactory
.
getInstance
(
"DES"
);
SecretKey
secretKey
=
keyFactory
.
generateSecret
(
desKeySpec
);
IvParameterSpec
iv
=
new
IvParameterSpec
(
strParam
.
getBytes
(
"UTF-8"
));
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
secretKey
,
iv
);
return
byte2hex
(
cipher
.
doFinal
(
source
.
getBytes
(
"UTF-8"
))).
toUpperCase
();
}
public
static
String
byte2hex
(
byte
[]
inStr
)
{
String
stmp
;
StringBuffer
out
=
new
StringBuffer
(
inStr
.
length
*
2
);
for
(
int
n
=
0
;
n
<
inStr
.
length
;
n
++)
{
stmp
=
Integer
.
toHexString
(
inStr
[
n
]
&
0xFF
);
if
(
stmp
.
length
()
==
1
)
{
// 如果是0至F的单位字符串,则添加0
out
.
append
(
"0"
+
stmp
);
}
else
{
out
.
append
(
stmp
);
}
}
return
out
.
toString
();
}
public
static
byte
[]
hex2byte
(
byte
[]
b
)
{
if
((
b
.
length
%
2
)
!=
0
){
throw
new
IllegalArgumentException
(
"长度不是偶数"
);
}
byte
[]
b2
=
new
byte
[
b
.
length
/
2
];
for
(
int
n
=
0
;
n
<
b
.
length
;
n
+=
2
)
{
String
item
=
new
String
(
b
,
n
,
2
);
b2
[
n
/
2
]
=
(
byte
)
Integer
.
parseInt
(
item
,
16
);
}
return
b2
;
}
/**
* 对称解密
* @param source
* @return
* @throws Exception
*/
public
static
String
desDecrypt
(
String
source
)
throws
Exception
{
if
(
source
==
null
||
source
.
length
()
==
0
){
return
null
;
}
byte
[]
src
=
hex2byte
(
source
.
getBytes
());
Cipher
cipher
=
Cipher
.
getInstance
(
"DES/CBC/PKCS5Padding"
);
DESKeySpec
desKeySpec
=
new
DESKeySpec
(
strKey
.
getBytes
(
"UTF-8"
));
SecretKeyFactory
keyFactory
=
SecretKeyFactory
.
getInstance
(
"DES"
);
SecretKey
secretKey
=
keyFactory
.
generateSecret
(
desKeySpec
);
IvParameterSpec
iv
=
new
IvParameterSpec
(
strParam
.
getBytes
(
"UTF-8"
));
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
secretKey
,
iv
);
byte
[]
retByte
=
cipher
.
doFinal
(
src
);
return
new
String
(
retByte
);
}
/**
* 密码加密
* @param password
...
...
src/main/java/me/zhengjie/system/domain/Menu.java
浏览文件 @
81078698
...
...
@@ -26,7 +26,7 @@ public class Menu {
private
String
name
;
@Column
(
unique
=
true
)
private
Long
so
f
t
;
private
Long
so
r
t
;
@Column
(
name
=
"path"
)
private
String
path
;
...
...
src/main/java/me/zhengjie/system/domain/VerificationCode.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.system.domain
;
import
lombok.Data
;
import
org.hibernate.annotations.CreationTimestamp
;
import
javax.persistence.*
;
import
java.sql.Timestamp
;
/**
* @author jie
* @date 2018-12-26
*/
@Data
@Entity
@Table
(
name
=
"verification_code"
)
public
class
VerificationCode
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
private
String
code
;
/**
* true 为有效,false 为无效
*/
private
Boolean
status
=
true
;
/**
* 类型 :phone 和 email
*/
private
String
type
;
/**
* 具体的phone与email
*/
private
String
value
;
/**
* 创建日期
*/
@CreationTimestamp
private
Timestamp
createTime
;
}
src/main/java/me/zhengjie/system/repository/MenuRepository.java
浏览文件 @
81078698
...
...
@@ -25,7 +25,7 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
* @param roleSet
* @return
*/
Set
<
Menu
>
findByRolesOrderBySo
f
t
(
Set
<
Role
>
roleSet
);
Set
<
Menu
>
findByRolesOrderBySo
r
t
(
Set
<
Role
>
roleSet
);
/**
* findByPid
...
...
src/main/java/me/zhengjie/system/repository/VerificationCodeRepository.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.system.repository
;
import
me.zhengjie.system.domain.VerificationCode
;
import
org.springframework.data.jpa.repository.JpaRepository
;
/**
* @author jie
* @date 2018-12-26
*/
public
interface
VerificationCodeRepository
extends
JpaRepository
<
VerificationCode
,
Long
>
{
}
src/main/java/me/zhengjie/system/rest/MenuController.java
浏览文件 @
81078698
...
...
@@ -77,7 +77,7 @@ public class MenuController {
@Log
(
description
=
"新增菜单"
)
@PostMapping
(
value
=
"/menus"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','
PERMISSION_ALL','PERMISSION
_CREATE')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','
MENU_ALL','MENU
_CREATE')"
)
public
ResponseEntity
create
(
@Validated
@RequestBody
Menu
resources
){
if
(
resources
.
getId
()
!=
null
)
{
throw
new
BadRequestException
(
"A new "
+
ENTITY_NAME
+
" cannot already have an ID"
);
...
...
@@ -87,7 +87,7 @@ public class MenuController {
@Log
(
description
=
"修改菜单"
)
@PutMapping
(
value
=
"/menus"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','
PERMISSION_ALL','PERMISSION
_EDIT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','
MENU_ALL','MENU
_EDIT')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
Menu
resources
){
if
(
resources
.
getId
()
==
null
)
{
throw
new
BadRequestException
(
ENTITY_NAME
+
" ID Can not be empty"
);
...
...
@@ -98,7 +98,7 @@ public class MenuController {
@Log
(
description
=
"删除菜单"
)
@DeleteMapping
(
value
=
"/menus/{id}"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','
PERMISSION_ALL','PERMISSION
_DELETE')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','
MENU_ALL','MENU
_DELETE')"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
menuService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
...
...
src/main/java/me/zhengjie/system/rest/PermissionController.java
浏览文件 @
81078698
...
...
@@ -42,7 +42,7 @@ public class PermissionController {
* @return
*/
@GetMapping
(
value
=
"/permissions/tree"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PERMISSION_ALL','
ROLE_ALL','ROLE_ADD','ROLE_EDIT
')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PERMISSION_ALL','
PERMISSION_SELECT','ROLES_SELECT','ROLES_ALL
')"
)
public
ResponseEntity
getRoleTree
(){
return
new
ResponseEntity
(
permissionService
.
getPermissionTree
(
permissionService
.
findByPid
(
0L
)),
HttpStatus
.
OK
);
}
...
...
src/main/java/me/zhengjie/system/rest/RoleController.java
浏览文件 @
81078698
...
...
@@ -31,7 +31,7 @@ public class RoleController {
private
static
final
String
ENTITY_NAME
=
"role"
;
@GetMapping
(
value
=
"/roles/{id}"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLE
_ALL','ROLE
_SELECT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLE
S_ALL','ROLES
_SELECT')"
)
public
ResponseEntity
getRoles
(
@PathVariable
Long
id
){
return
new
ResponseEntity
(
roleService
.
findById
(
id
),
HttpStatus
.
OK
);
}
...
...
@@ -41,21 +41,21 @@ public class RoleController {
* @return
*/
@GetMapping
(
value
=
"/roles/tree"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','
ROLE_ALL','USER_ALL','USER_ADD','USER_EDI
T')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','
MENU_ALL','MENU_SELECT','ROLES_ALL','USER_ALL','USER_SELEC
T')"
)
public
ResponseEntity
getRoleTree
(){
return
new
ResponseEntity
(
roleService
.
getRoleTree
(),
HttpStatus
.
OK
);
}
@Log
(
description
=
"查询角色"
)
@GetMapping
(
value
=
"/roles"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLE
_ALL','ROLE
_SELECT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLE
S_ALL','ROLES
_SELECT')"
)
public
ResponseEntity
getRoles
(
RoleDTO
resources
,
Pageable
pageable
){
return
new
ResponseEntity
(
roleQueryService
.
queryAll
(
resources
,
pageable
),
HttpStatus
.
OK
);
}
@Log
(
description
=
"新增角色"
)
@PostMapping
(
value
=
"/roles"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLE
_ALL','ROLE
_CREATE')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLE
S_ALL','ROLES
_CREATE')"
)
public
ResponseEntity
create
(
@Validated
@RequestBody
Role
resources
){
if
(
resources
.
getId
()
!=
null
)
{
throw
new
BadRequestException
(
"A new "
+
ENTITY_NAME
+
" cannot already have an ID"
);
...
...
@@ -65,7 +65,7 @@ public class RoleController {
@Log
(
description
=
"修改角色"
)
@PutMapping
(
value
=
"/roles"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLE
_ALL','ROLE
_EDIT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLE
S_ALL','ROLES
_EDIT')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
Role
resources
){
if
(
resources
.
getId
()
==
null
)
{
throw
new
BadRequestException
(
ENTITY_NAME
+
" ID Can not be empty"
);
...
...
@@ -76,7 +76,7 @@ public class RoleController {
@Log
(
description
=
"删除角色"
)
@DeleteMapping
(
value
=
"/roles/{id}"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLE
_ALL','ROLE
_DELETE')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLE
S_ALL','ROLES
_DELETE')"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
roleService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
...
...
src/main/java/me/zhengjie/system/rest/VerificationCodeController.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.system.rest
;
import
me.zhengjie.system.domain.VerificationCode
;
import
me.zhengjie.system.service.VerificationCodeService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
/**
* @author jie
* @date 2018-12-26
*/
@RestController
@RequestMapping
(
"api"
)
public
class
VerificationCodeController
{
@Autowired
private
VerificationCodeService
verificationCodeService
;
@PostMapping
(
value
=
"/code/sendEmail"
)
public
ResponseEntity
sendEmail
(
@RequestBody
VerificationCode
code
){
code
.
setType
(
"email"
);
verificationCodeService
.
sendEmail
(
code
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@GetMapping
(
value
=
"/code/validated"
)
public
ResponseEntity
validated
(
VerificationCode
code
){
verificationCodeService
.
validated
(
code
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
src/main/java/me/zhengjie/system/service/VerificationCodeService.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.system.service
;
import
me.zhengjie.system.domain.VerificationCode
;
/**
* @author jie
* @date 2018-12-26
*/
public
interface
VerificationCodeService
{
/**
* 发送邮件验证码
* @param code
*/
void
sendEmail
(
VerificationCode
code
);
/**
* 验证
* @param code
*/
void
validated
(
VerificationCode
code
);
}
src/main/java/me/zhengjie/system/service/dto/MenuDTO.java
浏览文件 @
81078698
...
...
@@ -16,7 +16,7 @@ public class MenuDTO {
private
String
name
;
private
Long
so
f
t
;
private
Long
so
r
t
;
private
String
path
;
...
...
src/main/java/me/zhengjie/system/service/impl/MenuServiceImpl.java
浏览文件 @
81078698
...
...
@@ -37,7 +37,12 @@ public class MenuServiceImpl implements MenuService {
@Override
public
List
<
MenuDTO
>
findByRoles
(
Set
<
Role
>
roles
)
{
Set
<
Menu
>
menus
=
menuRepository
.
findByRolesOrderBySoft
(
roles
);
Set
<
Menu
>
menus
=
new
LinkedHashSet
<>();
for
(
Role
role
:
roles
)
{
Set
<
Role
>
roleSet
=
new
HashSet
<>();
roleSet
.
add
(
role
);
menus
.
addAll
(
menuRepository
.
findByRolesOrderBySort
(
roleSet
));
}
return
menus
.
stream
().
map
(
menuMapper:
:
toDto
).
collect
(
Collectors
.
toList
());
}
...
...
@@ -67,7 +72,7 @@ public class MenuServiceImpl implements MenuService {
menu
.
setIcon
(
resources
.
getIcon
());
menu
.
setIFrame
(
resources
.
getIFrame
());
menu
.
setPid
(
resources
.
getPid
());
menu
.
setSo
ft
(
resources
.
getSof
t
());
menu
.
setSo
rt
(
resources
.
getSor
t
());
menu
.
setRoles
(
resources
.
getRoles
());
menuRepository
.
save
(
menu
);
}
...
...
@@ -137,6 +142,8 @@ public class MenuServiceImpl implements MenuService {
MenuVo
menuVo
=
new
MenuVo
();
menuVo
.
setName
(
menuDTO
.
getName
());
menuVo
.
setPath
(
menuDTO
.
getPath
());
// 如果不是外链
if
(!
menuDTO
.
getIFrame
()){
if
(
menuDTO
.
getPid
().
equals
(
0L
)){
//一级目录需要加斜杠,不然访问不了
...
...
@@ -149,6 +156,24 @@ public class MenuServiceImpl implements MenuService {
if
(
menuDTOList
!=
null
&&
menuDTOList
.
size
()!=
0
){
menuVo
.
setAlwaysShow
(
true
);
menuVo
.
setChildren
(
buildMenus
(
menuDTOList
));
// 处理是一级菜单并且没有子菜单的情况
}
else
if
(
menuDTO
.
getPid
().
equals
(
0L
)){
MenuVo
menuVo1
=
new
MenuVo
();
menuVo1
.
setMeta
(
menuVo
.
getMeta
());
// 非外链
if
(!
menuDTO
.
getIFrame
()){
menuVo1
.
setPath
(
"index"
);
menuVo1
.
setName
(
menuVo
.
getName
());
menuVo1
.
setComponent
(
menuVo
.
getComponent
());
}
else
{
menuVo1
.
setPath
(
menuDTO
.
getPath
());
}
menuVo
.
setName
(
null
);
menuVo
.
setMeta
(
null
);
menuVo
.
setComponent
(
"Layout"
);
List
<
MenuVo
>
list1
=
new
ArrayList
<
MenuVo
>();
list1
.
add
(
menuVo1
);
menuVo
.
setChildren
(
list1
);
}
list
.
add
(
menuVo
);
}
...
...
src/main/java/me/zhengjie/system/service/impl/VerificationCodeServiceImpl.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.system.service.impl
;
import
me.zhengjie.system.domain.VerificationCode
;
import
me.zhengjie.system.service.VerificationCodeService
;
import
org.springframework.stereotype.Service
;
/**
* @author jie
* @date 2018-12-26
*/
@Service
public
class
VerificationCodeServiceImpl
implements
VerificationCodeService
{
@Override
public
void
sendEmail
(
VerificationCode
code
)
{
}
@Override
public
void
validated
(
VerificationCode
code
)
{
}
}
src/main/java/me/zhengjie/tools/config/MultipartConfig.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.config
;
import
org.springframework.boot.web.servlet.MultipartConfigFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.servlet.MultipartConfigElement
;
import
java.io.File
;
/**
* @date 2018-12-28
* @author https://blog.csdn.net/llibin1024530411/article/details/79474953
*/
@Configuration
public
class
MultipartConfig
{
/**
* 文件上传临时路径
*/
@Bean
MultipartConfigElement
multipartConfigElement
()
{
MultipartConfigFactory
factory
=
new
MultipartConfigFactory
();
String
location
=
System
.
getProperty
(
"user.dir"
)
+
"/data/tmp"
;
File
tmpFile
=
new
File
(
location
);
if
(!
tmpFile
.
exists
())
{
tmpFile
.
mkdirs
();
}
factory
.
setLocation
(
location
);
return
factory
.
createMultipartConfig
();
}
}
\ No newline at end of file
src/main/java/me/zhengjie/tools/domain/EmailConfig.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.domain
;
import
lombok.Data
;
import
javax.persistence.*
;
import
javax.validation.constraints.NotBlank
;
import
java.io.Serializable
;
/**
* 邮件配置类,数据存覆盖式存入数据存
* @author jie
* @date 2018-12-26
*/
@Entity
@Data
@Table
(
name
=
"email_config"
)
public
class
EmailConfig
implements
Serializable
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
/**
*邮件服务器SMTP地址
*/
@NotBlank
private
String
host
;
/**
* 邮件服务器SMTP端口
*/
@NotBlank
private
String
port
;
/**
* 发件者用户名,默认为发件人邮箱前缀
*/
@NotBlank
private
String
user
;
@NotBlank
private
String
pass
;
/**
* 发件人
*/
@NotBlank
private
String
fromUser
;
}
src/main/java/me/zhengjie/tools/domain/Picture.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.domain
;
import
lombok.Data
;
import
org.hibernate.annotations.CreationTimestamp
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* sm.ms图床
*
* @author jie
* @date 2018-12-27
*/
@Data
@Entity
@Table
(
name
=
"picture"
)
public
class
Picture
implements
Serializable
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
private
String
filename
;
private
String
url
;
private
String
size
;
private
String
height
;
private
String
width
;
/**
* delete URl
*/
@Column
(
name
=
"delete_url"
)
private
String
delete
;
private
String
username
;
@CreationTimestamp
private
Timestamp
createTime
;
@Override
public
String
toString
()
{
return
"Picture{"
+
"filename='"
+
filename
+
'\''
+
'}'
;
}
}
src/main/java/me/zhengjie/tools/domain/vo/EmailVo.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.domain.vo
;
import
lombok.Data
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotEmpty
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 发送邮件时,接收参数的类
* @author 郑杰
* @date 2018/09/28 12:02:14
*/
@Data
public
class
EmailVo
{
/**
* 收件人,支持多个收件人,用逗号分隔
*/
@NotEmpty
private
List
<
String
>
tos
;
@NotBlank
private
String
subject
;
@NotBlank
private
String
content
;
}
src/main/java/me/zhengjie/tools/repository/EmailRepository.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.repository
;
import
me.zhengjie.tools.domain.EmailConfig
;
import
org.springframework.data.jpa.repository.JpaRepository
;
/**
* @author jie
* @date 2018-12-26
*/
public
interface
EmailRepository
extends
JpaRepository
<
EmailConfig
,
Long
>
{
}
src/main/java/me/zhengjie/tools/repository/PictureRepository.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.repository
;
import
me.zhengjie.tools.domain.Picture
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
/**
* @author jie
* @date 2018-12-27
*/
public
interface
PictureRepository
extends
JpaRepository
<
Picture
,
Long
>,
JpaSpecificationExecutor
{
}
src/main/java/me/zhengjie/tools/rest/EmailController.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.rest
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.common.aop.log.Log
;
import
me.zhengjie.tools.domain.EmailConfig
;
import
me.zhengjie.tools.domain.vo.EmailVo
;
import
me.zhengjie.tools.service.EmailService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
/**
* 发送邮件
* @author 郑杰
* @date 2018/09/28 6:55:53
*/
@Slf4j
@RestController
@RequestMapping
(
"api"
)
public
class
EmailController
{
@Autowired
private
EmailService
emailService
;
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
@GetMapping
(
value
=
"/email"
)
public
ResponseEntity
get
(){
return
new
ResponseEntity
(
emailService
.
find
(),
HttpStatus
.
OK
);
}
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
@Log
(
description
=
"配置邮件"
)
@PutMapping
(
value
=
"/email"
)
public
ResponseEntity
emailConfig
(
@Validated
@RequestBody
EmailConfig
emailConfig
){
emailService
.
update
(
emailConfig
,
emailService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
@Log
(
description
=
"发送邮件"
)
@PostMapping
(
value
=
"/email"
)
public
ResponseEntity
send
(
@Validated
@RequestBody
EmailVo
emailVo
)
throws
Exception
{
log
.
warn
(
"REST request to send Email : {}"
+
emailVo
);
emailService
.
send
(
emailVo
,
emailService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
src/main/java/me/zhengjie/tools/rest/PictureController.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.rest
;
import
me.zhengjie.common.aop.log.Log
;
import
me.zhengjie.common.utils.RequestHolder
;
import
me.zhengjie.core.utils.JwtTokenUtil
;
import
me.zhengjie.tools.domain.Picture
;
import
me.zhengjie.tools.service.PictureService
;
import
me.zhengjie.tools.service.query.PictureQueryService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author 郑杰
* @date 2018/09/20 14:13:32
*/
@RestController
@RequestMapping
(
"/api"
)
public
class
PictureController
{
@Autowired
private
PictureService
pictureService
;
@Autowired
private
PictureQueryService
pictureQueryService
;
@Autowired
private
JwtTokenUtil
jwtTokenUtil
;
@Log
(
description
=
"查询图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_SELECT')"
)
@GetMapping
(
value
=
"/pictures"
)
public
ResponseEntity
getRoles
(
Picture
resources
,
Pageable
pageable
){
return
new
ResponseEntity
(
pictureQueryService
.
queryAll
(
resources
,
pageable
),
HttpStatus
.
OK
);
}
/**
* 上传图片
* @param file
* @return
* @throws Exception
*/
@Log
(
description
=
"上传图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_UPLOAD')"
)
@PostMapping
(
value
=
"/pictures"
)
public
ResponseEntity
upload
(
@RequestParam
MultipartFile
file
){
String
userName
=
jwtTokenUtil
.
getUserName
(
RequestHolder
.
getHttpServletRequest
());
Picture
picture
=
pictureService
.
upload
(
file
,
userName
);
Map
map
=
new
HashMap
();
map
.
put
(
"errno"
,
0
);
map
.
put
(
"id"
,
picture
.
getId
());
map
.
put
(
"data"
,
new
String
[]{
picture
.
getUrl
()});
return
new
ResponseEntity
(
map
,
HttpStatus
.
OK
);
}
/**
* 删除图片
* @param id
* @return
*/
@Log
(
description
=
"删除图片"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')"
)
@DeleteMapping
(
value
=
"/pictures/{id}"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
)
{
pictureService
.
delete
(
pictureService
.
findById
(
id
));
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
src/main/java/me/zhengjie/tools/service/EmailService.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.service
;
import
me.zhengjie.tools.domain.EmailConfig
;
import
me.zhengjie.tools.domain.vo.EmailVo
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.scheduling.annotation.Async
;
/**
* @author jie
* @date 2018-12-26
*/
@CacheConfig
(
cacheNames
=
"email"
)
public
interface
EmailService
{
/**
* 更新邮件配置
* @param emailConfig
* @param old
* @return
*/
@CachePut
(
key
=
"'1'"
)
EmailConfig
update
(
EmailConfig
emailConfig
,
EmailConfig
old
);
/**
* 查询配置
* @return
*/
@Cacheable
(
key
=
"'1'"
)
EmailConfig
find
();
/**
* 发送邮件
* @param emailVo
* @param emailConfig
* @throws Exception
*/
@Async
void
send
(
EmailVo
emailVo
,
EmailConfig
emailConfig
)
throws
Exception
;
}
src/main/java/me/zhengjie/tools/service/PictureService.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.service
;
import
me.zhengjie.tools.domain.Picture
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.web.multipart.MultipartFile
;
/**
* @author jie
* @date 2018-12-27
*/
@CacheConfig
(
cacheNames
=
"picture"
)
public
interface
PictureService
{
/**
* 上传图片
* @param file
* @param username
* @return
*/
@CacheEvict
(
allEntries
=
true
)
Picture
upload
(
MultipartFile
file
,
String
username
);
/**
* 根据ID查询
* @param id
* @return
*/
@Cacheable
(
key
=
"#p0"
)
Picture
findById
(
Long
id
);
/**
* 删除图片
* @param picture
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
Picture
picture
);
}
src/main/java/me/zhengjie/tools/service/impl/EmailServiceImpl.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.service.impl
;
import
cn.hutool.extra.mail.MailAccount
;
import
cn.hutool.extra.mail.MailUtil
;
import
me.zhengjie.common.exception.BadRequestException
;
import
me.zhengjie.core.utils.EncryptUtils
;
import
me.zhengjie.tools.domain.EmailConfig
;
import
me.zhengjie.tools.domain.vo.EmailVo
;
import
me.zhengjie.tools.repository.EmailRepository
;
import
me.zhengjie.tools.service.EmailService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Optional
;
/**
* @author jie
* @date 2018-12-26
*/
@Service
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
EmailServiceImpl
implements
EmailService
{
@Autowired
private
EmailRepository
emailRepository
;
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
EmailConfig
update
(
EmailConfig
emailConfig
,
EmailConfig
old
)
{
try
{
if
(!
emailConfig
.
getPass
().
equals
(
old
.
getPass
())){
// 对称加密
emailConfig
.
setPass
(
EncryptUtils
.
desEncrypt
(
emailConfig
.
getPass
()));
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
emailRepository
.
saveAndFlush
(
emailConfig
);
return
emailConfig
;
}
@Override
public
EmailConfig
find
()
{
Optional
<
EmailConfig
>
emailConfig
=
emailRepository
.
findById
(
1L
);
if
(
emailConfig
.
isPresent
()){
return
emailConfig
.
get
();
}
else
{
return
new
EmailConfig
();
}
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
send
(
EmailVo
emailVo
,
EmailConfig
emailConfig
){
if
(
emailConfig
==
null
){
throw
new
BadRequestException
(
"请先配置,再操作"
);
}
/**
* 封装
*/
MailAccount
account
=
new
MailAccount
();
account
.
setHost
(
emailConfig
.
getHost
());
account
.
setPort
(
Integer
.
parseInt
(
emailConfig
.
getPort
()));
account
.
setAuth
(
true
);
try
{
// 对称解密
account
.
setPass
(
EncryptUtils
.
desDecrypt
(
emailConfig
.
getPass
()));
}
catch
(
Exception
e
)
{
throw
new
BadRequestException
(
e
.
getMessage
());
}
account
.
setFrom
(
emailConfig
.
getUser
()+
"<"
+
emailConfig
.
getFromUser
()+
">"
);
//ssl方式发送
account
.
setStartttlsEnable
(
true
);
String
content
=
emailVo
.
getContent
()+
"<p style='text-align: right;'>----- 邮件来自<span style='color: rgb(194, 79, 74);'> <a href='http://auauz.net' target='_blank'>eladmin</a></span> 后台管理系统</p>"
;
/**
* 发送
*/
try
{
MailUtil
.
send
(
account
,
emailVo
.
getTos
(),
emailVo
.
getSubject
(),
content
,
true
);
}
catch
(
Exception
e
){
throw
new
BadRequestException
(
e
.
getMessage
());
}
}
}
src/main/java/me/zhengjie/tools/service/impl/PictureServiceImpl.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.service.impl
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.common.exception.BadRequestException
;
import
me.zhengjie.common.utils.FileUtil
;
import
me.zhengjie.common.utils.ValidationUtil
;
import
me.zhengjie.tools.domain.Picture
;
import
me.zhengjie.tools.repository.PictureRepository
;
import
me.zhengjie.tools.service.PictureService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.http.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.util.Arrays
;
import
java.util.Optional
;
/**
* @author jie
* @date 2018-12-27
*/
@Slf4j
@Service
(
value
=
"pictureService"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
PictureServiceImpl
implements
PictureService
{
@Autowired
private
PictureRepository
pictureRepository
;
public
static
final
String
SUCCESS
=
"success"
;
public
static
final
String
CODE
=
"code"
;
public
static
final
String
MSG
=
"msg"
;
@Override
@Transactional
(
rollbackFor
=
Throwable
.
class
)
public
Picture
upload
(
MultipartFile
multipartFile
,
String
username
)
{
File
file
=
FileUtil
.
toFile
(
multipartFile
);
//将参数合成一个请求
RestTemplate
rest
=
new
RestTemplate
();
FileSystemResource
resource
=
new
FileSystemResource
(
file
);
MultiValueMap
<
String
,
Object
>
param
=
new
LinkedMultiValueMap
<>();
param
.
add
(
"smfile"
,
resource
);
//设置头部,必须
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setAccept
(
Arrays
.
asList
(
MediaType
.
APPLICATION_JSON
));
headers
.
add
(
"user-agent"
,
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"
);
HttpEntity
<
MultiValueMap
<
String
,
Object
>>
httpEntity
=
new
HttpEntity
<
MultiValueMap
<
String
,
Object
>>(
param
,
headers
);
ResponseEntity
<
String
>
responseEntity
=
rest
.
exchange
(
"https://sm.ms/api/upload"
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
responseEntity
.
getBody
());
Picture
picture
=
null
;
if
(!
jsonObject
.
get
(
CODE
).
toString
().
equals
(
SUCCESS
)){
throw
new
BadRequestException
(
jsonObject
.
get
(
MSG
).
toString
());
}
//转成实体类
picture
=
JSON
.
parseObject
(
jsonObject
.
get
(
"data"
).
toString
(),
Picture
.
class
);
picture
.
setSize
(
FileUtil
.
getSize
(
Integer
.
valueOf
(
picture
.
getSize
())));
picture
.
setUsername
(
username
);
picture
.
setFilename
(
FileUtil
.
getFileNameNoEx
(
multipartFile
.
getOriginalFilename
()));
pictureRepository
.
save
(
picture
);
//删除临时文件
FileUtil
.
deleteFile
(
file
);
return
picture
;
}
@Override
public
Picture
findById
(
Long
id
)
{
Optional
<
Picture
>
picture
=
pictureRepository
.
findById
(
id
);
ValidationUtil
.
isNull
(
picture
,
"Picture"
,
"id"
,
id
);
return
picture
.
get
();
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Picture
picture
)
{
RestTemplate
rest
=
new
RestTemplate
();
try
{
ResponseEntity
<
String
>
str
=
rest
.
getForEntity
(
picture
.
getDelete
(),
String
.
class
);
if
(
str
.
getStatusCode
().
is2xxSuccessful
()){
pictureRepository
.
delete
(
picture
);
}
//如果删除的地址出错,直接删除数据库数据
}
catch
(
Exception
e
){
pictureRepository
.
delete
(
picture
);
}
}
}
src/main/java/me/zhengjie/tools/service/query/PictureQueryService.java
0 → 100644
浏览文件 @
81078698
package
me.zhengjie.tools.service.query
;
import
me.zhengjie.common.utils.PageUtil
;
import
me.zhengjie.tools.domain.Picture
;
import
me.zhengjie.tools.repository.PictureRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.domain.Specification
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.ObjectUtils
;
import
javax.persistence.criteria.CriteriaBuilder
;
import
javax.persistence.criteria.CriteriaQuery
;
import
javax.persistence.criteria.Predicate
;
import
javax.persistence.criteria.Root
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author jie
* @date 2018-12-03
*/
@Service
@CacheConfig
(
cacheNames
=
"picture"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
PictureQueryService
{
@Autowired
private
PictureRepository
pictureRepository
;
/**
* 分页
*/
@Cacheable
(
keyGenerator
=
"keyGenerator"
)
public
Object
queryAll
(
Picture
picture
,
Pageable
pageable
){
return
PageUtil
.
toPage
(
pictureRepository
.
findAll
(
new
Spec
(
picture
),
pageable
));
}
class
Spec
implements
Specification
<
Picture
>
{
private
Picture
picture
;
public
Spec
(
Picture
picture
){
this
.
picture
=
picture
;
}
@Override
public
Predicate
toPredicate
(
Root
<
Picture
>
root
,
CriteriaQuery
<?>
criteriaQuery
,
CriteriaBuilder
cb
)
{
List
<
Predicate
>
list
=
new
ArrayList
<
Predicate
>();
if
(!
ObjectUtils
.
isEmpty
(
picture
.
getFilename
())){
/**
* 模糊
*/
list
.
add
(
cb
.
like
(
root
.
get
(
"filename"
).
as
(
String
.
class
),
"%"
+
picture
.
getFilename
()+
"%"
));
}
Predicate
[]
p
=
new
Predicate
[
list
.
size
()];
return
cb
.
and
(
list
.
toArray
(
p
));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录