173 Commits

Author SHA1 Message Date
cuijiawang
8ccfe35b49 rename 2025-08-13 10:17:02 +08:00
cuijiawang
b12f104161 del 2025-08-13 10:03:56 +08:00
cuijiawang
a9bb36dacc 添加后台系统模块 2025-08-13 09:59:58 +08:00
wol
8a73e9bec4 Merge branch 'dev-cloud-v3.5.4' into dev-boot-v3.5.4
# Conflicts:
#	pom.xml
2025-08-12 23:33:57 +08:00
wol
0002cf457d 1 2025-08-12 23:30:14 +08:00
wol
01748fe738 Merge branch 'refs/heads/dev-boot-v3.5.4-module-ai' into dev-boot-v3.5.4 2025-08-12 23:12:24 +08:00
wol
bf2956c51c Merge branch 'refs/heads/dev-boot-v3.5.4-auth' into dev-boot-v3.5.4 2025-08-12 23:11:32 +08:00
wol
1e9baade51 Merge branch 'dev-boot-v3.5.4-redis' into dev-boot-v3.5.4 2025-08-12 22:56:01 +08:00
wol
0babec14cf add RedisConfiguration 2025-08-12 22:55:45 +08:00
wol
4806918ef9 auth 2025-08-12 22:50:03 +08:00
wol
0c87b1d63e 1 2025-08-12 22:42:10 +08:00
wol
cbaa3e7c42 module-ai 2025-08-12 22:10:00 +08:00
wol
30f8584d33 run 2025-08-12 22:09:14 +08:00
cuijiawang
29e43f6e36 boot-start 2025-08-12 18:12:47 +08:00
cuijiawang
985b82c604 modules 2025-08-12 17:46:36 +08:00
cuijiawang
54cc4c4ba5 server-cloud 2025-08-12 17:40:09 +08:00
cuijiawang
302e085a18 common-json 2025-08-12 17:21:44 +08:00
cuijiawang
ff174056a0 common-web 2025-08-12 16:50:21 +08:00
cuijiawang
c2a9f58926 del 2025-08-12 16:40:37 +08:00
wol
c80d8909dd common-redis 2025-08-11 23:49:28 +08:00
wol
e04a663fdb common-mybatis 2025-08-11 23:01:07 +08:00
wol
b92f6a6f53 common-doc 2025-08-10 22:28:58 +08:00
wol
99e64a9295 aop 2025-08-10 21:53:29 +08:00
wol
c13efa788c common-core 2025-08-10 21:48:49 +08:00
wol
ea916df3ce fix 2025-08-10 19:52:35 +08:00
wol
3b7501458a fix 2025-08-10 19:49:54 +08:00
wol
f301ea5840 javax -> jakarta 2025-08-10 19:24:38 +08:00
wol
084dad491e del test 2025-08-10 17:22:49 +08:00
cuijiawang
0bb060b273 refactor(admin): 重构开发环境配置并添加 Docker 支持
- 修改应用端口为 18080
- 更新数据库配置,使用加密凭据
- 调整 Redis 配置
- 添加 Jasypt 加密器配置
- 新增 Dockerfile 用于构建 Docker 镜像
- 更新 Maven 依赖,添加 Jasypt 支持
2025-07-31 16:06:55 +08:00
valarchie
4e9ab30d68 Merge pull request #81 from BruceBlink/dev
更新junit单元测试的相关依赖
2025-06-04 20:26:41 +08:00
valarchie
454bdd44bc Merge pull request #80 from BruceBlink/main
增加Github Actions的CI/CD配置
2025-06-04 20:24:11 +08:00
likanug
2fa20aaaf3 更新junit的相关依赖及版本,修复admin模块中maven test批量跑单元测试时报错的问题 2025-06-04 20:09:26 +08:00
likanug
d017e2bb64 更新AgileBootConfigTest单元测试 2025-06-04 19:08:03 +08:00
likanug
e2f398b794 Revert "添加发布release的GitHub Actions配置"
This reverts commit 9fbc14c171.
2025-06-04 18:30:50 +08:00
likanug
664d845ea4 Revert "增加GitHub打包配置"
This reverts commit 5b3809abd9.
2025-06-04 18:30:18 +08:00
likanug
5b3809abd9 增加GitHub打包配置 2025-06-04 17:55:54 +08:00
likanug
9fbc14c171 添加发布release的GitHub Actions配置 2025-06-04 17:45:56 +08:00
likanug
bc1b97f720 删除更新依赖图的配置 2025-06-04 17:31:27 +08:00
likanug
f5c6125d74 修复Java 17更新依赖图时报错的问题 2025-06-04 17:18:47 +08:00
likanug
4ed71fdf5d 删除构建完成后的slack通知配置 2025-06-04 17:08:28 +08:00
likanug
ab3bcda857 修复发送构建通知失败的问题 2025-06-04 17:03:24 +08:00
likanug
68575d141c 修复Missing download info for actions/cache@v2的问题 2025-06-04 16:56:46 +08:00
likanug
dd535bfa50 增加Java 8的构建配置 2025-06-04 16:53:25 +08:00
likanug
47394d92ae 修复更新“依赖图”错误的问题 2025-06-04 16:52:18 +08:00
likanug
2644ed4368 更新actions/upload-artifact为v4 2025-06-04 16:41:30 +08:00
likanug
c09c7e4ca8 增加GitHub Actions的CI/CD配置 2025-06-04 16:38:06 +08:00
valarchie
ce83324c44 Merge pull request #79 from BruceBlink/main
更新Lombok版本,修复在JDK21下,代码编译报错的问题
更新h2的sql脚本以及增加h2的MySQL语法兼容设置,修复test模式下项目启动报错的问题
2025-05-07 16:15:16 +08:00
likanug
9ad9895510 Revert "删除无用的pom依赖"
This reverts commit f489ef45fd.
2025-05-07 15:49:06 +08:00
likanug
f489ef45fd 删除无用的pom依赖 2025-05-07 12:10:18 +08:00
likanug
f1b3ca650d 更新h2的sql脚本以及增加h2的MySQL语法兼容设置,修复test模式下项目启动报错的问题 2025-05-07 12:07:33 +08:00
likanug
42bf932d86 更新Lombok版本,修复在JDK21下,代码编译报错的问题 2025-05-07 11:13:04 +08:00
valarchie
1ccbfa2881 Merge pull request #77 from gongxuanzhang/main
Util classes should have private constructors
2024-12-31 14:26:28 +08:00
Xuan-Zhang Gong
6e4155a146 Util classes should have private constructors 2024-11-18 14:11:20 +08:00
valarchie
0bc4148a34 Merge pull request #75 from 1065700104/develop
fix(DeptModel): 修复父级部门为null时NPE的bug
2024-09-12 16:06:49 +08:00
李嘉伟
6a4245f541 feat(DeptModel): 修复父级部门为null时NPE的bug 2024-09-04 17:05:42 +08:00
valarchie
660dfa6a1e Update README.md 2024-05-29 08:29:38 +08:00
valarchie
62f81adc74 Merge pull request #71 from deepbreath/main
update:更新 pgsql 表
2024-04-09 17:14:24 +08:00
Yuchen
21ed5ef781 update:更新 pgsql 表 2024-04-09 17:09:06 +08:00
valarchie
073cda31e8 Merge pull request #70 from habyss/main
fix: xxxQuery放到对应目录
2024-04-03 17:06:20 +08:00
hankun
a845cf66ce fix: xxxQuery放到对应目录 2024-04-03 13:35:17 +08:00
valarchie
d2eb733ab3 Merge pull request #61 from aniyayee/main
fix: 删除角色时将操作类型更正为DELETE
2023-11-13 16:07:28 +08:00
yayee
f09c1fa47f fix: 删除角色时将操作类型更正为DELETE 2023-11-13 15:57:41 +08:00
valarchie
4716b3c977 Merge pull request #60 from burningimlam/main
fix: 分页查询时可能出现的NPE
2023-11-08 19:32:42 +08:00
imlam
aa2de6a6f2 fix: 分页查询时可能出现的NPE 2023-11-08 19:02:57 +08:00
valarchie
e9df8f01a1 Merge remote-tracking branch 'origin/main' 2023-10-12 16:09:24 +08:00
valarchie
9793f97613 fix: 修复缓存问题 2023-10-12 16:09:10 +08:00
valarchie
ea6117cf4e Merge pull request #56 from qcxy/main
修改引入包注释
2023-10-12 09:49:49 +08:00
gzy
a8afdce2fa 修改引入包注释 2023-10-12 09:36:21 +08:00
valarchie
7b78527e6d Merge pull request #55 from qcxy/main
去掉多余的两个引入的包
2023-10-12 09:35:37 +08:00
gzy
5a20edaff8 去掉多余的两个引入的包
结构变为common->infrastructure->domain->admin
2023-10-12 09:30:40 +08:00
valarchie
c054f3e3e8 Merge pull request #54 from gyzhang/fix_by_kevin_20231004
fix: 修改“岗位管理”-查询功能中的1-默认排序为数据库中的post_sort,2-设置漏掉的前端查询条件“创建时间”对应的字段cre…
2023-10-06 22:11:58 +08:00
Kevin Zhang
1ba6a55e93 fix: 代码异动位置:“岗位管理”-查询功能中的1-默认排序为数据库中的post_sort,2-设置漏掉的前端查询条件“创建时间”对应的字段 2023-10-06 15:30:29 +08:00
Kevin Zhang
72cde4c5cf fix: 修改“岗位管理”-查询功能中的1-默认排序为数据库中的post_sort,2-设置漏掉的前端查询条件“创建时间”对应的字段create_time 2023-10-04 23:40:14 +08:00
valarchie
050905fbc0 Merge pull request #53 from gyzhang/fix_by_kevin_20231003
fix: 修改“岗位管理”-删除-按钮功能错误:前端传递参数和后端不匹配,参照操作日志的删除功能做了修改。
2023-10-03 18:14:28 +08:00
Kevin Zhang
135a135d0f fix: 修改“岗位管理”-删除-按钮功能错误:前端传递参数和后端不匹配,参照操作日志的删除功能做了修改。 2023-10-03 16:39:30 +08:00
valarchie
0c4f58fd23 Merge pull request #52 from gyzhang/fix_by_kevin_20231002
fix: 修改“岗位管理”-全部导出-按钮功能错误:请求类型修改为get,请求路径修改为/excel,重新提供方法返回不分页的查询结果。
2023-10-02 18:38:22 +08:00
Kevin Zhang
a6344a2662 fix: 修改“岗位管理”-全部导出-按钮功能错误:请求类型修改为get,请求路径修改为/excel,重新提供方法返回不分页的查询结果。 2023-10-02 16:53:18 +08:00
Kevin Zhang
9527c95734 fix: 修改“岗位管理”-全部导出-按钮功能错误:请求类型修改为get,请求路径修改为/excel,重新提供方法返回不分页的查询结果。 2023-10-02 16:44:54 +08:00
valarchie
fcf41c68da Merge pull request #51 from penbox/main
fix: AddRoleCommand 中的 roleSort 约束为 @NotBlank,导致新增角色报错
2023-09-22 16:50:18 +08:00
penbox
c7436ec289 Merge branch 'main' into main 2023-09-22 16:45:36 +08:00
penbox86@126.com
90f80a7d27 fix: AddRoleCommand 中的 roleSort 约束为 @NotBlank,导致新增角色报错 2023-09-22 16:39:16 +08:00
valarchie
4aeafb8ab1 Merge pull request #47 from wunaidouzi/fixed-20230914
fixed: roleSort使用NotBlank导致无法update
2023-09-14 19:20:13 +08:00
LiuZhiYun
d8093fffe9 fixed: roleSort使用NotBlank导致无法update 2023-09-14 18:35:18 +08:00
valarchie
33ce250371 Merge pull request #45 from penbox/main
fix:移除 selectMenuListByUserId 中无效的排序字段
2023-09-07 10:36:19 +08:00
penbox86@126.com
88841b7ed0 fix:移除 selectMenuListByUserId 中无效的排序字段 2023-09-07 10:13:08 +08:00
valarchie
1a93fe4d95 refactor: 更新readMe 2023-08-16 18:52:54 +08:00
valarchie
251db3a146 refactor: 更新readMe 2023-08-15 11:01:19 +08:00
valarchie
18cba6b975 refactor: 更新gitignore 2023-08-15 09:53:44 +08:00
valarchie
a6792705ba refactor: 去除NonNull注解 2023-08-15 09:42:58 +08:00
valarchie
02fb771994 refactor: 修改Readme 2023-08-15 08:50:53 +08:00
valarchie
6ebea15fb3 refactor: 添加初始化sql文件 2023-08-15 08:40:08 +08:00
valarchie
76f1ddc9fe refactor: 修改ReadMe 2023-08-15 08:38:54 +08:00
valarchie
198b0856af refactor: 修改ReadMe 2023-08-15 08:32:07 +08:00
valarchie
0ab467dc6c Merge branch 'For-Pure'
# Conflicts:
#	agileboot-common/src/main/java/com/agileboot/common/enums/BasicEnumUtil.java
#	agileboot-common/src/test/java/com/agileboot/common/enums/BasicEnumUtilTest.java
2023-08-15 08:22:36 +08:00
valarchie
b920a748ed refactor: 使用final修饰符取代 @NonNull注解 进行bean注入 2023-08-14 23:22:11 +08:00
valarchie
4e0c6b80b7 refactor: 规范全局事务管理器 2023-08-14 22:47:41 +08:00
valarchie
16a06edb89 refactor: 移除orm模块 以及xml内容 2023-08-14 22:28:09 +08:00
valarchie
53e63c8b8e refactor: 修改数据类服务切面 2023-08-14 22:14:41 +08:00
valarchie
00f65d91ab refactor: 将orm包中数据相关类 挪到domain包中 2023-08-14 22:10:24 +08:00
valarchie
f3aaa771f6 refactor: 修复addTimeCondition方法 2023-08-14 20:45:27 +08:00
valarchie
5f31b9c27e refactor: 将orm包中的common类挪到common模块 2023-08-14 20:44:09 +08:00
valarchie
01afc4505f refactor: 将enum接口挪到common包 2023-08-14 17:16:23 +08:00
valarchie
b340bff225 refactor: 将RoleInfo与orm包解耦 2023-08-14 17:11:04 +08:00
valarchie
74c71156f0 refactor: 把MapCache挪到domain包 2023-08-14 17:03:42 +08:00
valarchie
90c231221f refactor: 把GuavaCacheService挪到domain包 2023-08-14 16:56:51 +08:00
valarchie
58b0d14340 refactor: 把RedisCacheService挪到domain包 2023-08-14 16:46:57 +08:00
valarchie
d72be1a446 refactor: 清理RoleInfo缓存 2023-08-14 16:21:26 +08:00
valarchie
157afb3673 refactor: 将异步工厂类挪到admin模块 2023-08-14 16:10:16 +08:00
valarchie
0ae219e942 refactor: 将操作日志AOP挪到 2023-08-14 16:00:46 +08:00
valarchie
377afbb8fc Merge remote-tracking branch 'origin/For-Pure' into For-Pure 2023-08-14 15:13:33 +08:00
valarchie
64e2fc9912 refactor: 新增dev 配置文件 2023-08-14 14:55:56 +08:00
valarchie
3e25d18463 refactor: 将集成测试模块挪到领域逻辑domain模块中 2023-08-14 14:35:52 +08:00
valarchie
37e052ef62 refactor: 上传dev配置文件 2023-08-08 19:19:37 +08:00
valarchie
aa0e1f91c5 refactor: 调整包结构以便二次开发 2023-08-05 14:33:08 +08:00
valarchie
242f536986 feature: 新增filter填入requestId方便跟踪日志 2023-08-01 20:25:43 +08:00
valarchie
df7f6950d1 refactor: 新增API的请求拦截 2023-08-01 14:02:27 +08:00
valarchie
3f384fbe79 refactor: 去掉返回类中的requestId API模块使用undertow服务器 2023-08-01 13:44:43 +08:00
valarchie
7c9b86a304 refactor: 把配置文件挪到admin和api模块 2023-07-30 16:07:08 +08:00
valarchie
917050e543 refactor: 把登录用户 拆分为系统用户和App用户 2023-07-30 13:44:43 +08:00
valarchie
6f96216248 refactor: 把登录逻辑移到admin 因为不同项目的登录 可能是不一样的 2023-07-30 13:32:25 +08:00
valarchie
fcb88e5a94 refactor: 把登录逻辑移到admin 因为不同项目的登录 可能是不一样的 2023-07-30 12:55:54 +08:00
valarchie
37f2b63038 refactor: 调整基础设施模块 2023-07-30 12:03:23 +08:00
valarchie
b59ed7d7d6 refactor: 将请求重复提交和请求限流重构区分为App和Web 2023-07-30 11:49:05 +08:00
valarchie
3a9fbb563e refactor: 将请求重复提交和请求限流重构区分为App和Web 2023-07-30 11:35:05 +08:00
valarchie
ec8dda127a fix: 调整common包 2023-07-30 00:45:09 +08:00
valarchie
59f6693005 refactor: 重构错误码的设计以及错误处理 2023-07-26 22:12:23 +08:00
valarchie
7a570300b5 refactor: 重构个人中心功能 2023-07-25 19:50:43 +08:00
valarchie
4174c15934 refactor: 新增用户页面 2023-07-24 21:46:55 +08:00
Lyp
891f908522 fix: 修改新增角色参数的序号类型 2023-07-23 20:52:16 +08:00
valarchie
d52a5bcbe5 refactor: 重构路由菜单功能 2023-07-22 17:22:10 +08:00
valarchie
7da7481887 refactor: 重构路由菜单功能 2023-07-22 17:15:43 +08:00
valarchie
71c9a7589d refactor: 重构部门页面 2023-07-20 22:53:47 +08:00
valarchie
3b091cbd4a Merge pull request #43 from daniyyer/exportExcel
Update CustomExcelUtil.java
2023-07-20 16:34:36 +08:00
daniyyer
df4996096c Update CustomExcelUtil.java
ExcelUtil.getWriter()默认创建xls格式的Excel,因此写出到客户端也需要自定义文件名为XXX.xls,现在配套的前端代码中设置的文件扩展名为xlsx,导出后打开会出现文件损坏的提示。改为ExcelUtil.getWriter(true)后,可生成xlsx格式的文件。
2023-07-20 16:06:38 +08:00
valarchie
f148232f0a refactor: 重构配置页面 2023-07-20 15:07:26 +08:00
valarchie
2318ce903d refactor: 重构缓存监控页面 2023-07-19 23:02:12 +08:00
valarchie
83df81583c refactor: 重构在线用户页面 2023-07-19 10:35:07 +08:00
valarchie
aa3b050b3f fix: 修复DB层异常捕获失败 2023-07-18 22:21:05 +08:00
valarchie
4605289348 feat: 更新数据库 2023-07-18 21:35:43 +08:00
valarchie
fc0a41a4e6 feat: 重构接口文档页面 2023-07-18 15:15:34 +08:00
valarchie
1382d2a32d refactor: 适配pure-admin登录日志页面 2023-07-16 21:39:07 +08:00
valarchie
97fc6d0367 refactor: 修改操作日志的后台导出excel 2023-07-16 14:04:22 +08:00
valarchie
52890e6e6e feat: 重构操作日志 2023-07-15 17:51:28 +08:00
valarchie
259e948325 Merge remote-tracking branch 'origin/For-Pure' into For-Pure 2023-07-15 08:18:01 +08:00
valarchie
9859bb1360 fix: 重构日志模块 2023-07-15 08:16:45 +08:00
valarchie
f03f441cb4 Merge pull request #42 from burningimlam/For-Pure
补充缺少的javadoc&消除部分代码检查警告
2023-07-14 22:05:29 +08:00
imlam
92782b9407 消除部分Sonar代码检查警告 2023-07-14 20:17:40 +08:00
imlam
0573b66ddc 补充缺少的javadoc&消除部分代码检查警告 2023-07-14 17:08:39 +08:00
valarchie
fb40f307b9 Update README.md 2023-07-14 16:03:29 +08:00
valarchie
2e435497b9 Update README.md 2023-07-14 16:02:46 +08:00
valarchie
32e95e858e Merge pull request #41 from burningimlam/For-Pure
fix: 补充缺少的javadoc注释
2023-07-14 15:50:59 +08:00
imlam
92b698a313 补充缺少的javadoc注释 2023-07-14 14:20:20 +08:00
valarchie
bcc9d7c757 Merge pull request #39 from TheLastSunset/mvnw
feat: add maven wrapper
2023-07-13 16:07:08 +08:00
valarchie
8d214bc4d1 Merge pull request #40 from TheLastSunset/optimize
refactor: optimize BasicEnumUtil
2023-07-13 15:41:29 +08:00
TheLastSunset
7bb6d625e4 refactor: optimize BasicEnumUtil 2023-07-13 14:11:40 +08:00
valarchie
2401ec2c62 refactor: 通知公告模块重构为更严格的restful风格 2023-07-13 12:13:08 +08:00
valarchie
7fdd8ef871 refactor: 规范字典类的名称 2023-07-12 21:03:32 +08:00
valarchie
4f7ada223a factor: 适配新的前端pure admin. 重构query基础类 2023-07-12 16:53:22 +08:00
TheLastSunset
88e22c270d feat: add mvnw execute permission 2023-07-12 08:40:48 +00:00
valarchie
19f4eb29bb factor: 适配新的前端pure admin. 重构query基础类 2023-07-12 16:01:18 +08:00
TheLastSunset
37e297626b feat: add maven wrapper 2023-07-12 10:58:12 +08:00
valarchie
0b0edfa7a5 docs: 添加关于securityConfig的注释 2023-07-07 18:20:50 +08:00
valarchie
c56dd18064 feat: 实现登录登出的逻辑,拆分配置接口 2023-07-04 21:55:41 +08:00
valarchie
d6bb477219 refactor: 拆分一个getConfig接口用于返回系统的配置参数,重构错误码类,使其可以跳转到i18n文件 2023-07-02 20:55:30 +08:00
valarchie
aea62eb6e2 feat: 新增pure项目对应的sql文件 2023-07-01 16:45:51 +08:00
valarchie
76d5cccf95 refactor: 新增路由代码 2023-06-29 23:01:20 +08:00
valarchie
d27352ecbc Merge branch 'main' into For-Pure 2023-06-29 19:29:20 +08:00
valarchie
c46dbc512b refactor: 使用固定的版本号, revision会导致子module install不成功 2023-06-27 21:23:12 +08:00
valarchie
aeb3576be6 Merge branch 'main' into For-Pure 2023-06-27 15:22:02 +08:00
valarchie
afddd03fda feat: 新增密码加密登录操作,重构登录代码 2023-06-25 21:44:02 +08:00
valarchie
a37997583a doc: 添加内置redis关于macos启动失败的说明 2023-06-20 22:32:38 +08:00
valarchie
8976a867e3 refactor: 把前端端口从80改成3000,避免有些用户启用不了80端口 2023-06-20 22:30:14 +08:00
valarchie
fdef3ed7ad refactor: 修改mysql启动步骤 2023-06-17 21:54:02 +08:00
393 changed files with 8696 additions and 6438 deletions

View File

@@ -1,36 +0,0 @@
---
name: Bug 报告
about: 创建BUG报告以改进项目
title: ''
labels: ''
assignees: ''
---
**BUG描述**
关于BUG清晰简洁的描述。
**复现步骤**
详细的复现步骤。
**正确的行为**
你认为这个修复这个BUG后正确的行为应该是什么。
**详细截图**
如果可以的话请添加截图以帮助调查BUG.
**桌面端:**
- 操作系统: [例如. iOS]
- 浏览器及版本 [例如. chrome 11]
- 项目版本 [例如. 1.6.0]
**手机端:**
- 设备: [例如. iPhone6]
- 操作系统: [例如. iOS8.1]
- 浏览器及版本 [例如.safari 8]
- 项目版本 [例如. 1.6.0]
**Additional context**
任何其他你认为有助于排查错误的信息,或者你的猜测。

View File

@@ -1,20 +0,0 @@
---
name: 功能建议
about: 关于该项目的建议
title: ''
labels: ''
assignees: ''
---
**您的功能请求是否与问题相关? 请描述。**
清楚简明地描述问题所在。
**描述您想要的解决方案**
对您所设想的问题的清晰简洁的描述。
**描述您考虑过的替代方案**
对您考虑过的任何替代解决方案或功能的清晰简洁的描述。
**附加上下文**
在此处添加有关功能请求的任何其他上下文或屏幕截图。

6
.gitignore vendored
View File

@@ -45,6 +45,6 @@ nbdist/
!*/build/*.java
!*/build/*.html
!*/build/*.xml
/agileboot-admin/src/main/resources/application-dev.yml
/agileboot-infrastructure/src/main/resources/application-prod.yml
/agileboot-infrastructure/src/main/resources/logback-prod.xml
/agileboot-admin/src/main/resources/application-prod.yml

8
Dockerfile Normal file
View File

@@ -0,0 +1,8 @@
FROM amazoncorretto:17
ADD agileboot-admin/target/agileboot-admin-1.0.0.jar /agileboot-admin.jar
EXPOSE 18080
#ENV CONTEXT_PATH /
# ENV NACOS_ENABLED true
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
ENTRYPOINT ["java", "-jar", "/agileboot-admin.jar"]

21
LICENSE
View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2022 valarchie
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -15,8 +15,7 @@
<img alt="logo" height="200" src="https://oscimg.oschina.net/oscnet/up-eda2a402cc061f1f5f40d9ac4c084f4c98c.png">
</p>
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">AgileBoot v1.8.0</h1>
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">AgileBoot v2.0.0 </h1>
<h4 align="center">基于SpringBoot+Vue3前后端分离的Java快速开发脚手架</h4>
<p align="center">
</p>
@@ -27,7 +26,8 @@ AgileBoot是一套开源的全栈精简快速开发平台毫无保留给个
适合个人开发者的小型项目或者公司内部项目使用。也可作为供初学者学习使用的案例。
* 前端采用Vue3、Element Plus。对应前端仓库 [AgileBoot-Front-End](https://github.com/valarchie/AgileBoot-Front-End) ,保持同步更新
* 前端是基于优秀的开源项目[Pure-Admin](https://github.com/pure-admin/vue-pure-admin)开发而成。在此感谢Pure-Admin作者
* 前端采用Vue3、Element Plus、TypeScript、Pinia。对应前端仓库 [AgileBoot-Front-End](https://github.com/valarchie/AgileBoot-Front-End) ,保持同步更新。
* 后端采用Spring Boot、Spring Security & Jwt、Redis & MySql、Mybatis Plus、Hutool工具包。
* 权限认证使用Jwt支持多终端认证系统。
* 支持注解式主从数据库切换,注解式请求限流,注解式重复请求拦截。
@@ -35,6 +35,9 @@ AgileBoot是一套开源的全栈精简快速开发平台毫无保留给个
* 支持加载动态权限菜单,实时权限控制。
* ***有大量的单元测试,集成测试覆盖确保业务逻辑正确***。
***V1.0.0版本使用JS开发V2.0.0版本使用TS开发***。
***V1.0.0地址:[后端(AgileBoot-Back-End-Basic)](https://github.com/valarchie/AgileBoot-Back-End-Basic) - [前端(AgileBoot-Front-End-Basic)](https://github.com/valarchie/AgileBoot-Front-End-Basic)***
> 有任何问题或者建议,可以在 _Issues_ 中提给作者。
>
> 您的Issue比Star更重要
@@ -148,9 +151,9 @@ git clone https://github.com/valarchie/AgileBoot-Front-End
#### 后端启动
```
1. 生成所需的数据库表
找到后端项目根目录下的sql目录中的agileboot_xxxxx.sql脚本文件。 导入到你新建的数据库中。
找到后端项目根目录下的sql目录中的agileboot_xxxxx.sql脚本文件(取最新的sql文件)。 导入到你新建的数据库中。
2. 在infrastructure模块底下找到resource目录下的application-dev.yml文件
2. 在admin模块底下找到resource目录下的application-dev.yml文件
配置数据库以及Redis的 地址、端口、账号密码
3. 在根目录执行mvn install
@@ -168,10 +171,12 @@ git clone https://github.com/valarchie/AgileBoot-Front-End
```
#### 前端启动
```
1. npm install
详细步骤请查看对应前端部分
2. npm run dev
```
1. pnpm install
2. pnpm run dev
3. 当出现以下字样时即为启动成功
@@ -202,6 +207,8 @@ agileboot.embedded.redis: false
agileboot.embedded.mysql: true
agileboot.embedded.redis: true
请注意:高版本的MacOS系统无法启动内置的Redis
3. 找到agileboot-admin模块中的AgileBootAdminApplication启动类直接启动即可
```
@@ -230,8 +237,6 @@ agileboot.embedded.redis: true
| | 连接池监视 | 监视当前系统数据库连接池状态可进行分析SQL找出系统性能瓶颈 |
目前版本是V1.8.0将在2.0版本后陆续新增新功能。
## 🐯 工程结构 🐯
```
@@ -242,25 +247,20 @@ agileboot
├── agileboot-common -- 精简基础工具模块
├── agileboot-infrastructure -- 基础设施模块(主要是配置和集成)
├── agileboot-infrastructure -- 基础设施模块(主要是配置和集成,不包含业务逻辑
├── agileboot-domain -- 业务模块
├ ├── user -- 用户模块(举例)
├ ├── command -- 命令参数接收模型(命令)
├ ├── dto -- 返回数据类
├ ├── db -- DB操作类
├ ├── entity -- 实体类
├ ├── service -- DB Service
├ ├── mapper -- DB Dao
├ ├── model -- 领域模型类
├ ├── query -- 查询参数模型(查询)
│ ├────── UserApplicationService -- 应用服务(事务层,操作领域模型类完成业务逻辑)
├── agileboot-integration-test -- 集成测试模块
├── agileboot-orm -- 数据映射模块(仅包含数据相关逻辑)
├ ├── entiy -- 实体类
├ ├── enums -- 数据相关枚举
├ ├── mapper -- DAO
├ ├── query -- 封装查询对象
├ ├── result -- 封装多表查询对象
└── └── service -- 服务层
```
### 代码流转
@@ -284,11 +284,16 @@ agileboot
│ ├── member -- 会员模块
├── agileboot-domain --
├ ├── member -- 会员模块
── agileboot-orm --
├── member -- 会员模块
├ ├── member -- 会员模块(举例)
├ ├── command -- 命令参数接收模型(命令)
├── dto -- 返回数据类
├── db -- DB操作类
├ ├── entity -- 实体类
├ ├── service -- DB Service
├ ├── mapper -- DB Dao
├ ├── model -- 领域模型类
├ ├── query -- 查询参数模型(查询)
│ ├────── MemberApplicationService -- 应用服务(事务层,操作领域模型类完成业务逻辑)
└─
```
@@ -313,11 +318,12 @@ agileboot
- 请导入统一的代码格式化模板Google: Settings > Editor > Code Style > Java > 设置按钮 > import schema > 选择项目根目录下的GoogleStyle.xml文件
- 如需要生成新的表请使用CodeGenerator类进行生成。
- 填入数据库地址,账号密码,库名。然后填入所需的表名执行代码即可。(大概看一下代码就知道怎么填啦)
- 生成的类在orm模块下的target/classes目录下
- 生成的类在infrastructure模块下的target/classes目录下
- 不同的数据库keywordsHandler方法请填入对应不同数据库handler。搜索keywordsHandler关键字
- 项目基础环境搭建请参考docker目录下的指南搭建。保姆级启动说明
- [AgileBoot - 手把手一步一步带你Run起全栈项目(SpringBoot+Vue3)](https://juejin.cn/post/7153812187834744845)
- 注意管理后台的后端启动类是AgileBoot**Admin**Application
- Swagger的API地址为 http://localhost:8080/v3/api-docs
## 🎬 AgileBoot全栈交流群 🎬

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>agileboot</artifactId>
<groupId>com.agileboot</groupId>
<version>${revision}</version>
<version>1.0.0</version>
</parent>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
@@ -18,12 +18,6 @@
<dependencies>
<!-- 核心模块-->
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>agileboot-infrastructure</artifactId>
</dependency>
<!-- 业务领域 -->
<dependency>
<groupId>com.agileboot</groupId>
@@ -61,6 +55,15 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<!-- 想跑test的话 设置成false -->
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
</plugins>
</build>

View File

@@ -16,7 +16,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -30,7 +30,7 @@ import org.springframework.web.multipart.MultipartFile;
/**
* 通用请求处理
*
* TODO 需要重构
* @author valarchie
*/
@Tag(name = "上传API", description = "上传相关接口")
@@ -52,7 +52,7 @@ public class FileController {
if (!FileUploadUtils.isAllowDownload(fileName)) {
// 返回类型是ResponseEntity 不能捕获异常, 需要手动将错误填到 ResponseEntity
ResponseDTO<Object> fail = ResponseDTO.fail(
new ApiException(Business.FILE_NOT_ALLOWED_TO_DOWNLOAD, fileName));
new ApiException(Business.COMMON_FILE_NOT_ALLOWED_TO_DOWNLOAD, fileName));
return new ResponseEntity<>(JacksonUtil.to(fail).getBytes(), null, HttpStatus.OK);
}

View File

@@ -3,28 +3,27 @@ package com.agileboot.admin.controller.common;
import cn.hutool.core.util.StrUtil;
import com.agileboot.common.config.AgileBootConfig;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode.Business;
import com.agileboot.domain.common.cache.CacheCenter;
import com.agileboot.domain.common.dto.UserPermissionDTO;
import com.agileboot.domain.common.dto.CurrentLoginUserDTO;
import com.agileboot.domain.common.dto.TokenDTO;
import com.agileboot.domain.system.menu.MenuApplicationService;
import com.agileboot.domain.system.menu.dto.RouterDTO;
import com.agileboot.domain.system.user.UserApplicationService;
import com.agileboot.domain.system.user.command.AddUserCommand;
import com.agileboot.domain.system.user.dto.UserDTO;
import com.agileboot.infrastructure.annotations.RateLimit;
import com.agileboot.infrastructure.annotations.RateLimit.CacheType;
import com.agileboot.infrastructure.annotations.RateLimit.LimitType;
import com.agileboot.infrastructure.cache.map.MapCache;
import com.agileboot.infrastructure.security.AuthenticationUtils;
import com.agileboot.infrastructure.web.domain.login.CaptchaDTO;
import com.agileboot.infrastructure.web.domain.login.LoginDTO;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.domain.login.TokenDTO;
import com.agileboot.infrastructure.web.domain.ratelimit.RateLimitKey;
import com.agileboot.infrastructure.web.service.LoginService;
import com.agileboot.infrastructure.annotations.ratelimit.RateLimit;
import com.agileboot.infrastructure.annotations.ratelimit.RateLimit.CacheType;
import com.agileboot.infrastructure.annotations.ratelimit.RateLimit.LimitType;
import com.agileboot.infrastructure.user.AuthenticationUtils;
import com.agileboot.admin.customize.service.login.dto.CaptchaDTO;
import com.agileboot.admin.customize.service.login.dto.ConfigDTO;
import com.agileboot.admin.customize.service.login.command.LoginCommand;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.infrastructure.annotations.ratelimit.RateLimitKey;
import com.agileboot.admin.customize.service.login.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@@ -41,14 +40,13 @@ import org.springframework.web.bind.annotation.RestController;
@RequiredArgsConstructor
public class LoginController {
@NonNull
private LoginService loginService;
private final LoginService loginService;
@NonNull
private MenuApplicationService menuApplicationService;
private final MenuApplicationService menuApplicationService;
@NonNull
private AgileBootConfig agileBootConfig;
private final UserApplicationService userApplicationService;
private final AgileBootConfig agileBootConfig;
/**
* 访问首页,提示语
@@ -62,6 +60,18 @@ public class LoginController {
agileBootConfig.getName(), agileBootConfig.getVersion());
}
/**
* 获取系统的内置配置
*
* @return 配置信息
*/
@GetMapping("/getConfig")
public ResponseDTO<ConfigDTO> getConfig() {
ConfigDTO configDTO = loginService.getConfig();
return ResponseDTO.ok(configDTO);
}
/**
* 生成验证码
*/
@@ -77,16 +87,18 @@ public class LoginController {
/**
* 登录方法
*
* @param loginDTO 登录信息
* @param loginCommand 登录信息
* @return 结果
*/
@Operation(summary = "登录")
@PostMapping("/login")
public ResponseDTO<TokenDTO> login(@RequestBody LoginDTO loginDTO) {
public ResponseDTO<TokenDTO> login(@RequestBody LoginCommand loginCommand) {
// 生成令牌
String token = loginService.login(loginDTO);
String token = loginService.login(loginCommand);
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
CurrentLoginUserDTO currentUserDTO = userApplicationService.getLoginUserInfo(loginUser);
return ResponseDTO.ok(new TokenDTO(token));
return ResponseDTO.ok(new TokenDTO(token, currentUserDTO));
}
/**
@@ -96,28 +108,23 @@ public class LoginController {
*/
@Operation(summary = "获取当前登录用户信息")
@GetMapping("/getLoginUserInfo")
public ResponseDTO<UserPermissionDTO> getLoginUserInfo() {
LoginUser loginUser = AuthenticationUtils.getLoginUser();
public ResponseDTO<CurrentLoginUserDTO> getLoginUserInfo() {
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
UserPermissionDTO permissionDTO = new UserPermissionDTO();
CurrentLoginUserDTO currentUserDTO = userApplicationService.getLoginUserInfo(loginUser);
permissionDTO.setUser(new UserDTO(CacheCenter.userCache.getObjectById(loginUser.getUserId())));
permissionDTO.setRoleKey(loginUser.getRoleInfo().getRoleKey());
permissionDTO.setPermissions(loginUser.getRoleInfo().getMenuPermissions());
permissionDTO.setDictTypes(MapCache.dictionaryCache());
return ResponseDTO.ok(permissionDTO);
return ResponseDTO.ok(currentUserDTO);
}
/**
* 获取路由信息
*
* TODO 如果要在前端开启路由缓存的话 需要在ServerConfig.json 中 设置CachingAsyncRoutes=true 避免一直重复请求路由接口
* @return 路由信息
*/
@Operation(summary = "获取用户对应的菜单路由", description = "用于动态生成路由")
@GetMapping("/getRouters")
public ResponseDTO<List<RouterDTO>> getRouters() {
LoginUser loginUser = AuthenticationUtils.getLoginUser();
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
List<RouterDTO> routerTree = menuApplicationService.getRouterTree(loginUser);
return ResponseDTO.ok(routerTree);
}
@@ -126,7 +133,7 @@ public class LoginController {
@Operation(summary = "注册接口", description = "暂未实现")
@PostMapping("/register")
public ResponseDTO<Void> register(@RequestBody AddUserCommand command) {
return ResponseDTO.fail(Business.UNSUPPORTED_OPERATION);
return ResponseDTO.fail(new ApiException(Business.COMMON_UNSUPPORTED_OPERATION));
}
}

View File

@@ -1,19 +1,18 @@
package com.agileboot.admin.controller.monitor;
package com.agileboot.admin.controller.system;
import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.domain.common.cache.CacheCenter;
import com.agileboot.domain.system.monitor.MonitorApplicationService;
import com.agileboot.domain.system.monitor.dto.OnlineUserInfo;
import com.agileboot.domain.system.monitor.dto.OnlineUserDTO;
import com.agileboot.domain.system.monitor.dto.RedisCacheInfoDTO;
import com.agileboot.domain.system.monitor.dto.ServerInfo;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -33,8 +32,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequiredArgsConstructor
public class MonitorController extends BaseController {
@NonNull
private MonitorApplicationService monitorApplicationService;
private final MonitorApplicationService monitorApplicationService;
@Operation(summary = "Redis信息")
@PreAuthorize("@permission.has('monitor:cache:list')")
@@ -55,15 +53,16 @@ public class MonitorController extends BaseController {
/**
* 获取在线用户列表
* @param ipaddr
* @param userName
* @return
*
* @param ipAddress ip地址
* @param username 用户名
* @return 分页处理后的在线用户信息
*/
@Operation(summary = "在线用户列表")
@PreAuthorize("@permission.has('monitor:online:list')")
@GetMapping("/onlineUser/list")
public ResponseDTO<PageDTO<OnlineUserInfo>> list(String ipaddr, String userName) {
List<OnlineUserInfo> onlineUserList = monitorApplicationService.getOnlineUserList(userName, ipaddr);
@GetMapping("/onlineUsers")
public ResponseDTO<PageDTO<OnlineUserDTO>> onlineUsers(String ipAddress, String username) {
List<OnlineUserDTO> onlineUserList = monitorApplicationService.getOnlineUserList(username, ipAddress);
return ResponseDTO.ok(new PageDTO<>(onlineUserList));
}
@@ -74,7 +73,7 @@ public class MonitorController extends BaseController {
@PreAuthorize("@permission.has('monitor:online:forceLogout')")
@AccessLog(title = "在线用户", businessType = BusinessTypeEnum.FORCE_LOGOUT)
@DeleteMapping("/onlineUser/{tokenId}")
public ResponseDTO<Void> forceLogout(@PathVariable String tokenId) {
public ResponseDTO<Void> logoutOnlineUser(@PathVariable String tokenId) {
CacheCenter.loginUserCache.delete(tokenId);
return ResponseDTO.ok();
}

View File

@@ -8,17 +8,12 @@ import com.agileboot.domain.system.config.ConfigApplicationService;
import com.agileboot.domain.system.config.command.ConfigUpdateCommand;
import com.agileboot.domain.system.config.dto.ConfigDTO;
import com.agileboot.domain.system.config.query.ConfigQuery;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.infrastructure.cache.map.MapCache;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import com.agileboot.orm.common.result.DictionaryData;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import lombok.NonNull;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@@ -35,44 +30,30 @@ import org.springframework.web.bind.annotation.RestController;
* @author valarchie
*/
@RestController
@RequestMapping("/system/config")
@RequestMapping("/system")
@Validated
@RequiredArgsConstructor
@Tag(name = "配置API", description = "配置相关的增删查改")
public class SysConfigController extends BaseController {
@NonNull
private ConfigApplicationService configApplicationService;
private final ConfigApplicationService configApplicationService;
/**
* 获取参数配置列表
*/
@Operation(summary = "参数列表", description = "分页获取配置参数列表")
@PreAuthorize("@permission.has('system:config:list')")
@GetMapping("/list")
@GetMapping("/configs")
public ResponseDTO<PageDTO<ConfigDTO>> list(ConfigQuery query) {
PageDTO<ConfigDTO> page = configApplicationService.getConfigList(query);
return ResponseDTO.ok(page);
}
/**
* 根据字典类型查询字典数据信息
* 换成用Enum
*/
@GetMapping(value = "/dict/{dictType}")
@Operation(summary = "字典数据", description = "获取字典列表")
@Parameter(name = "dictType", description = "字典对应类别")
public ResponseDTO<List<DictionaryData>> dictType(@PathVariable String dictType) {
List<DictionaryData> dictionaryData = MapCache.dictionaryCache().get(dictType);
return ResponseDTO.ok(dictionaryData);
}
/**
* 根据参数编号获取详细信息
*/
@PreAuthorize("@permission.has('system:config:query')")
@GetMapping(value = "/{configId}")
@GetMapping(value = "/config/{configId}")
@Operation(summary = "配置信息", description = "配置的详细信息")
public ResponseDTO<ConfigDTO> getInfo(@NotNull @Positive @PathVariable Long configId) {
ConfigDTO config = configApplicationService.getConfigInfo(configId);
@@ -86,8 +67,9 @@ public class SysConfigController extends BaseController {
@PreAuthorize("@permission.has('system:config:edit')")
@AccessLog(title = "参数管理", businessType = BusinessTypeEnum.MODIFY)
@Operation(summary = "配置修改", description = "配置修改")
@PutMapping
public ResponseDTO<Void> edit(@RequestBody ConfigUpdateCommand config) {
@PutMapping(value = "/config/{configId}")
public ResponseDTO<Void> edit(@NotNull @Positive @PathVariable Long configId, @RequestBody ConfigUpdateCommand config) {
config.setConfigId(configId);
configApplicationService.updateConfig(config);
return ResponseDTO.ok();
}
@@ -98,7 +80,7 @@ public class SysConfigController extends BaseController {
@Operation(summary = "刷新配置缓存")
@PreAuthorize("@permission.has('system:config:remove')")
@AccessLog(title = "参数管理", businessType = BusinessTypeEnum.CLEAN)
@DeleteMapping("/refreshCache")
@DeleteMapping("/configs/cache")
public ResponseDTO<Void> refreshCache() {
CacheCenter.configCache.invalidateAll();
return ResponseDTO.ok();

View File

@@ -8,13 +8,12 @@ import com.agileboot.domain.system.dept.command.AddDeptCommand;
import com.agileboot.domain.system.dept.command.UpdateDeptCommand;
import com.agileboot.domain.system.dept.dto.DeptDTO;
import com.agileboot.domain.system.dept.query.DeptQuery;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.NonNull;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@@ -33,21 +32,20 @@ import org.springframework.web.bind.annotation.RestController;
* @author valarchie
*/
@RestController
@RequestMapping("/system/dept")
@RequestMapping("/system")
@Validated
@RequiredArgsConstructor
@Tag(name = "部门API", description = "部门相关的增删查改")
public class SysDeptController extends BaseController {
@NonNull
private DeptApplicationService deptApplicationService;
private final DeptApplicationService deptApplicationService;
/**
* 获取部门列表
*/
@Operation(summary = "部门列表")
@PreAuthorize("@permission.has('system:dept:list')")
@GetMapping("/list")
@GetMapping("/depts")
public ResponseDTO<List<DeptDTO>> list(DeptQuery query) {
List<DeptDTO> deptList = deptApplicationService.getDeptList(query);
return ResponseDTO.ok(deptList);
@@ -58,7 +56,7 @@ public class SysDeptController extends BaseController {
*/
@Operation(summary = "部门详情")
@PreAuthorize("@permission.has('system:dept:query')")
@GetMapping(value = "/{deptId}")
@GetMapping(value = "/dept/{deptId}")
public ResponseDTO<DeptDTO> getInfo(@PathVariable Long deptId) {
DeptDTO dept = deptApplicationService.getDeptInfo(deptId);
return ResponseDTO.ok(dept);
@@ -68,7 +66,7 @@ public class SysDeptController extends BaseController {
* 获取部门下拉树列表
*/
@Operation(summary = "获取部门树级结构")
@GetMapping("/dropdownList")
@GetMapping("/depts/dropdown")
public ResponseDTO<List<Tree<Long>>> dropdownList() {
List<Tree<Long>> deptTree = deptApplicationService.getDeptTree();
return ResponseDTO.ok(deptTree);
@@ -80,7 +78,7 @@ public class SysDeptController extends BaseController {
@Operation(summary = "新增部门")
@PreAuthorize("@permission.has('system:dept:add')")
@AccessLog(title = "部门管理", businessType = BusinessTypeEnum.ADD)
@PostMapping
@PostMapping("/dept")
public ResponseDTO<Void> add(@RequestBody AddDeptCommand addCommand) {
deptApplicationService.addDept(addCommand);
return ResponseDTO.ok();
@@ -92,8 +90,9 @@ public class SysDeptController extends BaseController {
@Operation(summary = "修改部门")
@PreAuthorize("@permission.has('system:dept:edit') AND @dataScope.checkDeptId(#updateCommand.deptId)")
@AccessLog(title = "部门管理", businessType = BusinessTypeEnum.MODIFY)
@PutMapping
public ResponseDTO<Void> edit(@RequestBody UpdateDeptCommand updateCommand) {
@PutMapping("/dept/{deptId}")
public ResponseDTO<Void> edit(@PathVariable("deptId")Long deptId, @RequestBody UpdateDeptCommand updateCommand) {
updateCommand.setDeptId(deptId);
deptApplicationService.updateDept(updateCommand);
return ResponseDTO.ok();
}
@@ -104,7 +103,7 @@ public class SysDeptController extends BaseController {
@Operation(summary = "删除部门")
@PreAuthorize("@permission.has('system:dept:remove') AND @dataScope.checkDeptId(#deptId)")
@AccessLog(title = "部门管理", businessType = BusinessTypeEnum.DELETE)
@DeleteMapping("/{deptId}")
@DeleteMapping("/dept/{deptId}")
public ResponseDTO<Void> remove(@PathVariable @NotNull Long deptId) {
deptApplicationService.removeDept(deptId);
return ResponseDTO.ok();

View File

@@ -1,80 +0,0 @@
package com.agileboot.admin.controller.system;
import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.common.utils.poi.CustomExcelUtil;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.system.logininfo.LoginInfoApplicationService;
import com.agileboot.domain.system.logininfo.dto.LoginInfoDTO;
import com.agileboot.domain.system.logininfo.query.LoginInfoQuery;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 系统访问记录
*
* @author valarchie
*/
@Tag(name = "登录日志API", description = "登录日志相关API")
@RestController
@RequestMapping("/loginInfo")
@Validated
@RequiredArgsConstructor
public class SysLoginInfoController extends BaseController {
@NonNull
private LoginInfoApplicationService loginInfoApplicationService;
@Operation(summary = "日志列表")
@PreAuthorize("@permission.has('monitor:logininfor:list')")
@GetMapping("/list")
public ResponseDTO<PageDTO<LoginInfoDTO>> list(LoginInfoQuery query) {
PageDTO<LoginInfoDTO> pageDTO = loginInfoApplicationService.getLoginInfoList(query);
return ResponseDTO.ok(pageDTO);
}
@Operation(summary = "日志列表导出", description = "将登录日志导出到excel")
@AccessLog(title = "登录日志", businessType = BusinessTypeEnum.EXPORT)
@PreAuthorize("@permission.has('monitor:logininfor:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, LoginInfoQuery query) {
PageDTO<LoginInfoDTO> pageDTO = loginInfoApplicationService.getLoginInfoList(query);
CustomExcelUtil.writeToResponse(pageDTO.getRows(), LoginInfoDTO.class, response);
}
@Operation(summary = "删除登录日志")
@PreAuthorize("@permission.has('monitor:logininfor:remove')")
@AccessLog(title = "登录日志", businessType = BusinessTypeEnum.DELETE)
@DeleteMapping("/{infoIds}")
public ResponseDTO<Void> remove(@PathVariable @NotNull @NotEmpty List<Long> infoIds) {
loginInfoApplicationService.deleteLoginInfo(new BulkOperationCommand<>(infoIds));
return ResponseDTO.ok();
}
@Operation(summary = "清空登录日志", description = "暂时不支持")
@PreAuthorize("@permission.has('monitor:logininfor:remove')")
@AccessLog(title = "登录日志", businessType = BusinessTypeEnum.CLEAN)
@DeleteMapping("/clean")
public ResponseDTO<Void> clean() {
return ResponseDTO.fail(ErrorCode.Business.UNSUPPORTED_OPERATION);
}
}

View File

@@ -0,0 +1,120 @@
package com.agileboot.admin.controller.system;
import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.common.utils.poi.CustomExcelUtil;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.system.log.LogApplicationService;
import com.agileboot.domain.system.log.dto.LoginLogDTO;
import com.agileboot.domain.system.log.query.LoginLogQuery;
import com.agileboot.domain.system.log.dto.OperationLogDTO;
import com.agileboot.domain.system.log.query.OperationLogQuery;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 系统访问记录
*
* @author valarchie
*/
@Tag(name = "日志API", description = "日志相关API")
@RestController
@RequestMapping("/logs")
@Validated
@RequiredArgsConstructor
public class SysLogsController extends BaseController {
private final LogApplicationService logApplicationService;
@Operation(summary = "登录日志列表")
@PreAuthorize("@permission.has('monitor:logininfor:list')")
@GetMapping("/loginLogs")
public ResponseDTO<PageDTO<LoginLogDTO>> loginInfoList(LoginLogQuery query) {
PageDTO<LoginLogDTO> pageDTO = logApplicationService.getLoginInfoList(query);
return ResponseDTO.ok(pageDTO);
}
@Operation(summary = "登录日志导出", description = "将登录日志导出到excel")
@AccessLog(title = "登录日志", businessType = BusinessTypeEnum.EXPORT)
@PreAuthorize("@permission.has('monitor:logininfor:export')")
@GetMapping("/loginLogs/excel")
public void loginInfosExcel(HttpServletResponse response, LoginLogQuery query) {
PageDTO<LoginLogDTO> pageDTO = logApplicationService.getLoginInfoList(query);
CustomExcelUtil.writeToResponse(pageDTO.getRows(), LoginLogDTO.class, response);
}
@Operation(summary = "删除登录日志")
@PreAuthorize("@permission.has('monitor:logininfor:remove')")
@AccessLog(title = "登录日志", businessType = BusinessTypeEnum.DELETE)
@DeleteMapping("/loginLogs")
public ResponseDTO<Void> removeLoginInfos(@RequestParam @NotNull @NotEmpty List<Long> ids) {
logApplicationService.deleteLoginInfo(new BulkOperationCommand<>(ids));
return ResponseDTO.ok();
}
@Operation(summary = "操作日志列表")
@PreAuthorize("@permission.has('monitor:operlog:list')")
@GetMapping("/operationLogs")
public ResponseDTO<PageDTO<OperationLogDTO>> operationLogs(OperationLogQuery query) {
PageDTO<OperationLogDTO> pageDTO = logApplicationService.getOperationLogList(query);
return ResponseDTO.ok(pageDTO);
}
// @GetMapping("/download")
// public ResponseEntity<InputStreamResource> downloadFile() throws IOException {
// // 从文件系统或其他位置获取文件输入流
// File file = new File("path/to/file");
// InputStream inputStream = new FileInputStream(file);
// CustomExcelUtil.wri
//
// // 创建一个 InputStreamResource 对象,将文件输入流包装在其中
// InputStreamResource resource = new InputStreamResource(inputStream);
//
// // 返回 ResponseEntity 对象,其中包含 InputStreamResource 对象和文件名
// return ResponseEntity.ok()
// .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + file.getName())
// .contentType(MediaType.APPLICATION_OCTET_STREAM)
// .contentLength(file.length())
// .body(resource);
// }
/**
* 可否改成以上的形式 TODO
* @param response
* @param query
*/
@Operation(summary = "操作日志导出")
@AccessLog(title = "操作日志", businessType = BusinessTypeEnum.EXPORT)
@PreAuthorize("@permission.has('monitor:operlog:export')")
@GetMapping("/operationLogs/excel")
public void operationLogsExcel(HttpServletResponse response, OperationLogQuery query) {
PageDTO<OperationLogDTO> pageDTO = logApplicationService.getOperationLogList(query);
CustomExcelUtil.writeToResponse(pageDTO.getRows(), OperationLogDTO.class, response);
}
@Operation(summary = "删除操作日志")
@AccessLog(title = "操作日志", businessType = BusinessTypeEnum.DELETE)
@PreAuthorize("@permission.has('monitor:operlog:remove')")
@DeleteMapping("/operationLogs")
public ResponseDTO<Void> removeOperationLogs(@RequestParam List<Long> operationIds) {
logApplicationService.deleteOperationLog(new BulkOperationCommand<>(operationIds));
return ResponseDTO.ok();
}
}

View File

@@ -7,17 +7,17 @@ import com.agileboot.domain.system.menu.MenuApplicationService;
import com.agileboot.domain.system.menu.command.AddMenuCommand;
import com.agileboot.domain.system.menu.command.UpdateMenuCommand;
import com.agileboot.domain.system.menu.dto.MenuDTO;
import com.agileboot.domain.system.menu.dto.MenuDetailDTO;
import com.agileboot.domain.system.menu.query.MenuQuery;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.infrastructure.security.AuthenticationUtils;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.infrastructure.user.AuthenticationUtils;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import lombok.NonNull;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PositiveOrZero;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@@ -37,22 +37,21 @@ import org.springframework.web.bind.annotation.RestController;
*/
@Tag(name = "菜单API", description = "菜单相关的增删查改")
@RestController
@RequestMapping("/system/menu")
@RequestMapping("/system/menus")
@Validated
@RequiredArgsConstructor
public class SysMenuController extends BaseController {
@NonNull
MenuApplicationService menuApplicationService;
private final MenuApplicationService menuApplicationService;
/**
* 获取菜单列表
*/
@Operation(summary = "菜单列表")
@PreAuthorize("@permission.has('system:menu:list')")
@GetMapping("/list")
public ResponseDTO<List<MenuDTO>> list(MenuQuery query) {
List<MenuDTO> menuList = menuApplicationService.getMenuList(query);
@GetMapping
public ResponseDTO<List<MenuDTO>> menuList(MenuQuery menuQuery) {
List<MenuDTO> menuList = menuApplicationService.getMenuList(menuQuery);
return ResponseDTO.ok(menuList);
}
@@ -62,8 +61,8 @@ public class SysMenuController extends BaseController {
@Operation(summary = "菜单详情")
@PreAuthorize("@permission.has('system:menu:query')")
@GetMapping(value = "/{menuId}")
public ResponseDTO<MenuDTO> getInfo(@PathVariable @NotNull @PositiveOrZero Long menuId) {
MenuDTO menu = menuApplicationService.getMenuInfo(menuId);
public ResponseDTO<MenuDetailDTO> menuInfo(@PathVariable @NotNull @PositiveOrZero Long menuId) {
MenuDetailDTO menu = menuApplicationService.getMenuInfo(menuId);
return ResponseDTO.ok(menu);
}
@@ -71,15 +70,18 @@ public class SysMenuController extends BaseController {
* 获取菜单下拉树列表
*/
@Operation(summary = "菜单列表(树级)", description = "菜单树级下拉框")
@GetMapping("/dropdownList")
@GetMapping("/dropdown")
public ResponseDTO<List<Tree<Long>>> dropdownList() {
LoginUser loginUser = AuthenticationUtils.getLoginUser();
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
List<Tree<Long>> dropdownList = menuApplicationService.getDropdownList(loginUser);
return ResponseDTO.ok(dropdownList);
}
/**
* 新增菜单
* 需支持一级菜单以及 多级菜单 子菜单为一个 或者 多个的情况
* 隐藏菜单不显示 以及rank排序
* 内链 和 外链
*/
@Operation(summary = "添加菜单")
@PreAuthorize("@permission.has('system:menu:add')")
@@ -96,8 +98,9 @@ public class SysMenuController extends BaseController {
@Operation(summary = "编辑菜单")
@PreAuthorize("@permission.has('system:menu:edit')")
@AccessLog(title = "菜单管理", businessType = BusinessTypeEnum.MODIFY)
@PutMapping
public ResponseDTO<Void> edit(@RequestBody UpdateMenuCommand updateCommand) {
@PutMapping("/{menuId}")
public ResponseDTO<Void> edit(@PathVariable("menuId") Long menuId, @RequestBody UpdateMenuCommand updateCommand) {
updateCommand.setMenuId(menuId);
menuApplicationService.updateMenu(updateCommand);
return ResponseDTO.ok();
}
@@ -114,5 +117,4 @@ public class SysMenuController extends BaseController {
return ResponseDTO.ok();
}
}

View File

@@ -9,16 +9,16 @@ import com.agileboot.domain.system.notice.command.NoticeAddCommand;
import com.agileboot.domain.system.notice.command.NoticeUpdateCommand;
import com.agileboot.domain.system.notice.dto.NoticeDTO;
import com.agileboot.domain.system.notice.query.NoticeQuery;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.infrastructure.annotations.Unrepeatable;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.infrastructure.annotations.unrepeatable.Unrepeatable;
import com.agileboot.infrastructure.annotations.unrepeatable.Unrepeatable.CheckType;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import com.baomidou.dynamic.datasource.annotation.DS;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import lombok.NonNull;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
@@ -38,20 +39,19 @@ import org.springframework.web.bind.annotation.RestController;
*/
@Tag(name = "公告API", description = "公告相关的增删查改")
@RestController
@RequestMapping("/system/notice")
@RequestMapping("/system/notices")
@Validated
@RequiredArgsConstructor
public class SysNoticeController extends BaseController {
@NonNull
private NoticeApplicationService noticeApplicationService;
private final NoticeApplicationService noticeApplicationService;
/**
* 获取通知公告列表
*/
@Operation(summary = "公告列表")
@PreAuthorize("@permission.has('system:notice:list')")
@GetMapping("/list")
@GetMapping
public ResponseDTO<PageDTO<NoticeDTO>> list(NoticeQuery query) {
PageDTO<NoticeDTO> pageDTO = noticeApplicationService.getNoticeList(query);
return ResponseDTO.ok(pageDTO);
@@ -64,7 +64,7 @@ public class SysNoticeController extends BaseController {
@Operation(summary = "公告列表(从数据库从库获取)", description = "演示主从库的例子")
@DS("slave")
@PreAuthorize("@permission.has('system:notice:list')")
@GetMapping("/listFromSlave")
@GetMapping("/database/slave")
public ResponseDTO<PageDTO<NoticeDTO>> listFromSlave(NoticeQuery query) {
PageDTO<NoticeDTO> pageDTO = noticeApplicationService.getNoticeList(query);
return ResponseDTO.ok(pageDTO);
@@ -84,7 +84,7 @@ public class SysNoticeController extends BaseController {
* 新增通知公告
*/
@Operation(summary = "添加公告")
@Unrepeatable(interval = 60)
@Unrepeatable(interval = 60, checkType = CheckType.SYSTEM_USER)
@PreAuthorize("@permission.has('system:notice:add')")
@AccessLog(title = "通知公告", businessType = BusinessTypeEnum.ADD)
@PostMapping
@@ -99,8 +99,9 @@ public class SysNoticeController extends BaseController {
@Operation(summary = "修改公告")
@PreAuthorize("@permission.has('system:notice:edit')")
@AccessLog(title = "通知公告", businessType = BusinessTypeEnum.MODIFY)
@PutMapping
public ResponseDTO<Void> edit(@RequestBody NoticeUpdateCommand updateCommand) {
@PutMapping("/{noticeId}")
public ResponseDTO<Void> edit(@PathVariable Long noticeId, @RequestBody NoticeUpdateCommand updateCommand) {
updateCommand.setNoticeId(noticeId);
noticeApplicationService.updateNotice(updateCommand);
return ResponseDTO.ok();
}
@@ -111,8 +112,8 @@ public class SysNoticeController extends BaseController {
@Operation(summary = "删除公告")
@PreAuthorize("@permission.has('system:notice:remove')")
@AccessLog(title = "通知公告", businessType = BusinessTypeEnum.DELETE)
@DeleteMapping("/{noticeIds}")
public ResponseDTO<Void> remove(@PathVariable List<Integer> noticeIds) {
@DeleteMapping
public ResponseDTO<Void> remove(@RequestParam List<Integer> noticeIds) {
noticeApplicationService.deleteNotice(new BulkOperationCommand<>(noticeIds));
return ResponseDTO.ok();
}

View File

@@ -1,75 +0,0 @@
package com.agileboot.admin.controller.system;
import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.common.utils.poi.CustomExcelUtil;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.system.operationlog.OperationLogApplicationService;
import com.agileboot.domain.system.operationlog.dto.OperationLogDTO;
import com.agileboot.domain.system.operationlog.query.OperationLogQuery;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 操作日志记录
*
* @author valarchie
*/
@Tag(name = "操作日志API", description = "操作日志相关接口")
@RestController
@RequestMapping("/operationLog")
@RequiredArgsConstructor
public class SysOperationLogController extends BaseController {
@NonNull
private OperationLogApplicationService operationLogApplicationService;
@Operation(summary = "操作日志列表")
@PreAuthorize("@permission.has('monitor:operlog:list')")
@GetMapping("/list")
public ResponseDTO<PageDTO<OperationLogDTO>> list(OperationLogQuery query) {
PageDTO<OperationLogDTO> pageDTO = operationLogApplicationService.getOperationLogList(query);
return ResponseDTO.ok(pageDTO);
}
@Operation(summary = "操作日志导出")
@AccessLog(title = "操作日志", businessType = BusinessTypeEnum.EXPORT)
@PreAuthorize("@permission.has('monitor:operlog:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, OperationLogQuery query) {
PageDTO<OperationLogDTO> pageDTO = operationLogApplicationService.getOperationLogList(query);
CustomExcelUtil.writeToResponse(pageDTO.getRows(), OperationLogDTO.class, response);
}
@Operation(summary = "删除操作日志")
@AccessLog(title = "操作日志", businessType = BusinessTypeEnum.DELETE)
@PreAuthorize("@permission.has('monitor:operlog:remove')")
@DeleteMapping("/{operationIds}")
public ResponseDTO<Void> remove(@PathVariable List<Long> operationIds) {
operationLogApplicationService.deleteOperationLog(new BulkOperationCommand<>(operationIds));
return ResponseDTO.ok();
}
@Operation(summary = "清空操作日志", description = "暂未支持")
@AccessLog(title = "操作日志", businessType = BusinessTypeEnum.CLEAN)
@PreAuthorize("@permission.has('monitor:operlog:remove')")
@DeleteMapping("/clean")
public ResponseDTO<Void> clean() {
return ResponseDTO.fail(ErrorCode.Business.UNSUPPORTED_OPERATION);
}
}

View File

@@ -1,8 +1,10 @@
package com.agileboot.admin.controller.system;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import com.agileboot.common.utils.poi.CustomExcelUtil;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.system.post.PostApplicationService;
@@ -10,13 +12,12 @@ import com.agileboot.domain.system.post.command.AddPostCommand;
import com.agileboot.domain.system.post.command.UpdatePostCommand;
import com.agileboot.domain.system.post.dto.PostDTO;
import com.agileboot.domain.system.post.query.PostQuery;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import lombok.NonNull;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@@ -27,6 +28,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
@@ -41,8 +43,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequiredArgsConstructor
public class SysPostController extends BaseController {
@NonNull
private PostApplicationService postApplicationService;
private final PostApplicationService postApplicationService;
/**
* 获取岗位列表
@@ -55,13 +56,20 @@ public class SysPostController extends BaseController {
return ResponseDTO.ok(pageDTO);
}
/**
* 导出查询到的所有岗位信息到excel文件
* @param response http响应
* @param query 查询参数
* @author Kevin Zhang
* @date 2023-10-02
*/
@Operation(summary = "职位列表导出")
@AccessLog(title = "岗位管理", businessType = BusinessTypeEnum.EXPORT)
@PreAuthorize("@permission.has('system:post:export')")
@PostMapping("/export")
@GetMapping("/excel")
public void export(HttpServletResponse response, PostQuery query) {
PageDTO<PostDTO> pageDTO = postApplicationService.getPostList(query);
CustomExcelUtil.writeToResponse(pageDTO.getRows(), PostDTO.class, response);
List<PostDTO> all = postApplicationService.getPostListAll(query);
CustomExcelUtil.writeToResponse(all, PostDTO.class, response);
}
/**
@@ -105,9 +113,9 @@ public class SysPostController extends BaseController {
@Operation(summary = "删除职位")
@PreAuthorize("@permission.has('system:post:remove')")
@AccessLog(title = "岗位管理", businessType = BusinessTypeEnum.DELETE)
@DeleteMapping("/{postIds}")
public ResponseDTO<Void> remove(@PathVariable List<Long> postIds) {
postApplicationService.deletePost(new BulkOperationCommand<>(postIds));
@DeleteMapping
public ResponseDTO<Void> remove(@RequestParam @NotNull @NotEmpty List<Long> ids) {
postApplicationService.deletePost(new BulkOperationCommand<>(ids));
return ResponseDTO.ok();
}

View File

@@ -12,13 +12,12 @@ import com.agileboot.domain.system.user.command.UpdateProfileCommand;
import com.agileboot.domain.system.user.command.UpdateUserAvatarCommand;
import com.agileboot.domain.system.user.command.UpdateUserPasswordCommand;
import com.agileboot.domain.system.user.dto.UserProfileDTO;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.infrastructure.security.AuthenticationUtils;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.infrastructure.user.AuthenticationUtils;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@@ -40,8 +39,7 @@ import org.springframework.web.multipart.MultipartFile;
@RequiredArgsConstructor
public class SysProfileController extends BaseController {
@NonNull
private UserApplicationService userApplicationService;
private final UserApplicationService userApplicationService;
/**
* 个人信息
@@ -49,7 +47,7 @@ public class SysProfileController extends BaseController {
@Operation(summary = "获取个人信息")
@GetMapping
public ResponseDTO<UserProfileDTO> profile() {
LoginUser user = AuthenticationUtils.getLoginUser();
SystemLoginUser user = AuthenticationUtils.getSystemLoginUser();
UserProfileDTO userProfile = userApplicationService.getUserProfile(user.getUserId());
return ResponseDTO.ok(userProfile);
}
@@ -61,7 +59,7 @@ public class SysProfileController extends BaseController {
@AccessLog(title = "个人信息", businessType = BusinessTypeEnum.MODIFY)
@PutMapping
public ResponseDTO<Void> updateProfile(@RequestBody UpdateProfileCommand command) {
LoginUser loginUser = AuthenticationUtils.getLoginUser();
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
command.setUserId(loginUser.getUserId());
userApplicationService.updateUserProfile(command);
return ResponseDTO.ok();
@@ -74,7 +72,7 @@ public class SysProfileController extends BaseController {
@AccessLog(title = "个人信息", businessType = BusinessTypeEnum.MODIFY)
@PutMapping("/password")
public ResponseDTO<Void> updatePassword(@RequestBody UpdateUserPasswordCommand command) {
LoginUser loginUser = AuthenticationUtils.getLoginUser();
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
command.setUserId(loginUser.getUserId());
userApplicationService.updatePasswordBySelf(loginUser, command);
return ResponseDTO.ok();
@@ -90,7 +88,7 @@ public class SysProfileController extends BaseController {
if (file.isEmpty()) {
throw new ApiException(ErrorCode.Business.USER_UPLOAD_FILE_FAILED);
}
LoginUser loginUser = AuthenticationUtils.getLoginUser();
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
String avatarUrl = FileUploadUtils.upload(UploadSubDir.AVATAR_PATH, file);
userApplicationService.updateUserAvatar(new UpdateUserAvatarCommand(loginUser.getUserId(), avatarUrl));

View File

@@ -14,14 +14,13 @@ import com.agileboot.domain.system.role.query.AllocatedRoleQuery;
import com.agileboot.domain.system.role.query.RoleQuery;
import com.agileboot.domain.system.role.query.UnallocatedRoleQuery;
import com.agileboot.domain.system.user.dto.UserDTO;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import lombok.NonNull;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@@ -46,8 +45,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequiredArgsConstructor
public class SysRoleController extends BaseController {
@NonNull
private RoleApplicationService roleApplicationService;
private final RoleApplicationService roleApplicationService;
@Operation(summary = "角色列表")
@PreAuthorize("@permission.has('system:role:list')")
@@ -94,7 +92,7 @@ public class SysRoleController extends BaseController {
*/
@Operation(summary = "删除角色")
@PreAuthorize("@permission.has('system:role:remove')")
@AccessLog(title = "角色管理", businessType = BusinessTypeEnum.ADD)
@AccessLog(title = "角色管理", businessType = BusinessTypeEnum.DELETE)
@DeleteMapping(value = "/{roleId}")
public ResponseDTO<Void> remove(@PathVariable("roleId") List<Long> roleIds) {
roleApplicationService.deleteRoleByBulk(roleIds);

View File

@@ -14,16 +14,15 @@ import com.agileboot.domain.system.user.command.UpdateUserCommand;
import com.agileboot.domain.system.user.dto.UserDTO;
import com.agileboot.domain.system.user.dto.UserDetailDTO;
import com.agileboot.domain.system.user.query.SearchUserQuery;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.infrastructure.security.AuthenticationUtils;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import com.agileboot.orm.system.result.SearchUserDO;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.infrastructure.user.AuthenticationUtils;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import com.agileboot.domain.system.user.db.SearchUserDO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import lombok.NonNull;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@@ -39,25 +38,23 @@ import org.springframework.web.multipart.MultipartFile;
/**
* 用户信息
*
* @author ruoyi
* @author valarchie
*/
@Tag(name = "用户API", description = "用户相关的增删查改")
@RestController
@RequestMapping("/system/user")
@RequestMapping("/system/users")
@RequiredArgsConstructor
public class SysUserController extends BaseController {
@NonNull
private UserApplicationService userApplicationService;
private final UserApplicationService userApplicationService;
/**
* 获取用户列表
*/
@Operation(summary = "用户列表")
@PreAuthorize("@permission.has('system:user:list') AND @dataScope.checkDeptId(#query.deptId)")
@GetMapping("/list")
public ResponseDTO<PageDTO<UserDTO>> list(SearchUserQuery<SearchUserDO> query) {
@GetMapping
public ResponseDTO<PageDTO<UserDTO>> userList(SearchUserQuery<SearchUserDO> query) {
PageDTO<UserDTO> page = userApplicationService.getUserList(query);
return ResponseDTO.ok(page);
}
@@ -65,8 +62,8 @@ public class SysUserController extends BaseController {
@Operation(summary = "用户列表导出")
@AccessLog(title = "用户管理", businessType = BusinessTypeEnum.EXPORT)
@PreAuthorize("@permission.has('system:user:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, SearchUserQuery<SearchUserDO> query) {
@GetMapping("/excel")
public void exportUserByExcel(HttpServletResponse response, SearchUserQuery<SearchUserDO> query) {
PageDTO<UserDTO> userList = userApplicationService.getUserList(query);
CustomExcelUtil.writeToResponse(userList.getRows(), UserDTO.class, response);
}
@@ -74,8 +71,8 @@ public class SysUserController extends BaseController {
@Operation(summary = "用户列表导入")
@AccessLog(title = "用户管理", businessType = BusinessTypeEnum.IMPORT)
@PreAuthorize("@permission.has('system:user:import')")
@PostMapping("/importData")
public ResponseDTO<Void> importData(MultipartFile file) {
@PostMapping("/excel")
public ResponseDTO<Void> importUserByExcel(MultipartFile file) {
List<AddUserCommand> commands = CustomExcelUtil.readFromRequest(AddUserCommand.class, file);
for (AddUserCommand command : commands) {
@@ -88,8 +85,8 @@ public class SysUserController extends BaseController {
* 下载批量导入模板
*/
@Operation(summary = "用户导入excel下载")
@PostMapping("/downloadTemplate")
public void downloadTemplate(HttpServletResponse response) {
@GetMapping("/excelTemplate")
public void downloadExcelTemplate(HttpServletResponse response) {
CustomExcelUtil.writeToResponse(ListUtil.toList(new AddUserCommand()), AddUserCommand.class, response);
}
@@ -98,7 +95,7 @@ public class SysUserController extends BaseController {
*/
@Operation(summary = "用户详情")
@PreAuthorize("@permission.has('system:user:query')")
@GetMapping(value = {"/", "/{userId}"})
@GetMapping("/{userId}")
public ResponseDTO<UserDetailDTO> getUserDetailInfo(@PathVariable(value = "userId", required = false) Long userId) {
UserDetailDTO userDetailInfo = userApplicationService.getUserDetailInfo(userId);
return ResponseDTO.ok(userDetailInfo);
@@ -122,7 +119,7 @@ public class SysUserController extends BaseController {
@Operation(summary = "修改用户")
@PreAuthorize("@permission.has('system:user:edit') AND @dataScope.checkUserId(#command.userId)")
@AccessLog(title = "用户管理", businessType = BusinessTypeEnum.MODIFY)
@PutMapping
@PutMapping("/{userId}")
public ResponseDTO<Void> edit(@Validated @RequestBody UpdateUserCommand command) {
userApplicationService.updateUser(command);
return ResponseDTO.ok();
@@ -137,7 +134,7 @@ public class SysUserController extends BaseController {
@DeleteMapping("/{userIds}")
public ResponseDTO<Void> remove(@PathVariable List<Long> userIds) {
BulkOperationCommand<Long> bulkDeleteCommand = new BulkOperationCommand<>(userIds);
LoginUser loginUser = AuthenticationUtils.getLoginUser();
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
userApplicationService.deleteUsers(loginUser, bulkDeleteCommand);
return ResponseDTO.ok();
}
@@ -148,7 +145,7 @@ public class SysUserController extends BaseController {
@Operation(summary = "重置用户密码")
@PreAuthorize("@permission.has('system:user:resetPwd') AND @dataScope.checkUserId(#userId)")
@AccessLog(title = "用户管理", businessType = BusinessTypeEnum.MODIFY)
@PutMapping("/{userId}/password/reset")
@PutMapping("/{userId}/password")
public ResponseDTO<Void> resetPassword(@PathVariable Long userId, @RequestBody ResetPasswordCommand command) {
command.setUserId(userId);
userApplicationService.resetUserPassword(command);

View File

@@ -1,46 +0,0 @@
package com.agileboot.admin.controller.tool;
import cn.hutool.core.net.URLEncodeUtil;
import cn.hutool.core.util.CharsetUtil;
import com.agileboot.common.config.AgileBootConfig;
import com.agileboot.common.core.base.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* swagger 接口
* TODO Swagger这边权限拦截并没有生效需要改进
* PreAuthorize注解加在transfer接口上 获取不到登录用户 iframe请求header中没有token
* @author valarchie
*/
@Tag(name = "文档API", description = "角色相关接口")
@RestController
public class SwaggerController extends BaseController {
/**
* TODO 这个接口没有触发, 后续看如何改进, 应该把权限拦截放在下面的接口
*/
@Operation(summary = "文档首页")
@PreAuthorize("@permission.has('tool:swagger:view')")
@GetMapping("/tool/swagger")
public String index() {
return redirect("/doc.html");
}
/**
* 访问首页,提示语
*/
@Operation(summary = "文档接口数据")
@GetMapping("/v3/api-docs/{url}")
public void transfer(HttpServletResponse response, @PathVariable String url) throws IOException {
response.sendRedirect(AgileBootConfig.getApiDocsPathPrefix() + "/v3/api-docs/" + URLEncodeUtil.encode(url,
CharsetUtil.CHARSET_UTF_8));
}
}

View File

@@ -1,7 +1,7 @@
package com.agileboot.infrastructure.annotations;
package com.agileboot.admin.customize.aop.accessLog;
import com.agileboot.orm.common.enums.BusinessTypeEnum;
import com.agileboot.orm.common.enums.OperatorTypeEnum;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import com.agileboot.common.enums.common.OperatorTypeEnum;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@@ -1,9 +1,7 @@
package com.agileboot.infrastructure.aspectj;
package com.agileboot.admin.customize.aop.accessLog;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.infrastructure.thread.AsyncTaskFactory;
import com.agileboot.admin.customize.async.AsyncTaskFactory;
import com.agileboot.infrastructure.thread.ThreadPoolManager;
import com.agileboot.infrastructure.web.domain.operationLog.OperationLogModel;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
@@ -53,9 +51,7 @@ public class AccessLogAspect {
// 保存数据库
ThreadPoolManager.execute(AsyncTaskFactory.recordOperationLog(operationLog));
} catch (Exception exp) {
// 记录本地异常日志
log.error("生成操作日志异常,异常信息:{}", exp.getMessage());
exp.printStackTrace();
log.error("写入操作日式失败", exp);
}
}

View File

@@ -1,26 +1,24 @@
package com.agileboot.infrastructure.web.domain.operationLog;
package com.agileboot.admin.customize.aop.accessLog;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONUtil;
import com.agileboot.common.utils.ServletHolderUtil;
import com.agileboot.infrastructure.annotations.AccessLog;
import com.agileboot.infrastructure.security.AuthenticationUtils;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.orm.common.enums.OperationStatusEnum;
import com.agileboot.orm.common.enums.RequestMethodEnum;
import com.agileboot.orm.common.util.BasicEnumUtil;
import com.agileboot.orm.system.entity.SysOperationLogEntity;
import com.agileboot.infrastructure.user.AuthenticationUtils;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.common.enums.common.OperationStatusEnum;
import com.agileboot.common.enums.common.RequestMethodEnum;
import com.agileboot.common.enums.BasicEnumUtil;
import com.agileboot.domain.system.log.db.SysOperationLogEntity;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.springframework.validation.BindingResult;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.HandlerMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.util.Collection;
import java.util.Map;
@@ -36,9 +34,9 @@ public class OperationLogModel extends SysOperationLogEntity {
public void fillOperatorInfo() {
// 获取当前的用户
String ip = ServletUtil.getClientIP(request);
String ip = ServletHolderUtil.getClientIp();
setOperatorIp(ip);
LoginUser loginUser = AuthenticationUtils.getLoginUser();
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
if (loginUser != null) {
this.setUsername(loginUser.getUsername());
}

View File

@@ -1,15 +1,14 @@
package com.agileboot.infrastructure.thread;
package com.agileboot.admin.customize.async;
import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.agileboot.common.utils.ServletHolderUtil;
import com.agileboot.common.utils.ip.IpRegionUtil;
import com.agileboot.orm.common.enums.LoginStatusEnum;
import com.agileboot.orm.system.entity.SysLoginInfoEntity;
import com.agileboot.orm.system.entity.SysOperationLogEntity;
import com.agileboot.orm.system.service.ISysLoginInfoService;
import com.agileboot.orm.system.service.ISysOperationLogService;
import com.agileboot.common.enums.common.LoginStatusEnum;
import com.agileboot.domain.system.log.db.SysLoginInfoEntity;
import com.agileboot.domain.system.log.db.SysOperationLogEntity;
import com.agileboot.domain.system.log.db.SysLoginInfoService;
import com.agileboot.domain.system.log.db.SysOperationLogService;
import eu.bitwalker.useragentutils.UserAgent;
import lombok.extern.slf4j.Slf4j;
@@ -38,7 +37,7 @@ public class AsyncTaskFactory {
ServletHolderUtil.getRequest().getHeader("User-Agent"));
// 获取客户端浏览器
final String browser = userAgent.getBrowser() != null ? userAgent.getBrowser().getName() : "";
final String ip = ServletUtil.getClientIP(ServletHolderUtil.getRequest());
final String ip = ServletHolderUtil.getClientIp();
final String address = IpRegionUtil.getBriefLocationByIp(ip);
// 获取客户端操作系统
final String os = userAgent.getOperatingSystem() != null ? userAgent.getOperatingSystem().getName() : "";
@@ -57,7 +56,7 @@ public class AsyncTaskFactory {
loginInfo.setLoginTime(DateUtil.date());
loginInfo.setStatus(loginStatusEnum.getValue());
// 插入数据
SpringUtil.getBean(ISysLoginInfoService.class).save(loginInfo);
SpringUtil.getBean(SysLoginInfoService.class).save(loginInfo);
};
}
@@ -71,7 +70,7 @@ public class AsyncTaskFactory {
return () -> {
// 远程查询操作地点
operationLog.setOperatorLocation(IpRegionUtil.getBriefLocationByIp(operationLog.getOperatorIp()));
SpringUtil.getBean(ISysOperationLogService.class).save(operationLog);
SpringUtil.getBean(SysOperationLogService.class).save(operationLog);
};
}

View File

@@ -1,14 +1,13 @@
package com.agileboot.infrastructure.filter;
package com.agileboot.admin.customize.config;
import com.agileboot.infrastructure.security.AuthenticationUtils;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.service.TokenService;
import com.agileboot.infrastructure.user.AuthenticationUtils;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.admin.customize.service.login.TokenService;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.NonNull;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -27,13 +26,12 @@ import org.springframework.web.filter.OncePerRequestFilter;
@RequiredArgsConstructor
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
@NonNull
private TokenService tokenService;
private final TokenService tokenService;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
LoginUser loginUser = tokenService.getLoginUser(request);
SystemLoginUser loginUser = tokenService.getLoginUser(request);
if (loginUser != null && AuthenticationUtils.getAuthentication() == null) {
tokenService.refreshToken(loginUser);
// 如果没有将当前登录用户放入到上下文中的话会认定用户未授权返回用户未登陆的错误
@@ -45,7 +43,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
}
private void putCurrentLoginUserIntoContext(HttpServletRequest request, LoginUser loginUser) {
private void putCurrentLoginUserIntoContext(HttpServletRequest request, SystemLoginUser loginUser) {
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(loginUser,
null, loginUser.getAuthorities());
authToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));

View File

@@ -1,18 +1,17 @@
package com.agileboot.infrastructure.config;
package com.agileboot.admin.customize.config;
import cn.hutool.json.JSONUtil;
import com.agileboot.admin.customize.service.login.LoginService;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode.Client;
import com.agileboot.common.utils.ServletHolderUtil;
import com.agileboot.infrastructure.cache.redis.RedisCacheService;
import com.agileboot.infrastructure.filter.JwtAuthenticationTokenFilter;
import com.agileboot.infrastructure.thread.AsyncTaskFactory;
import com.agileboot.domain.common.cache.RedisCacheService;
import com.agileboot.admin.customize.async.AsyncTaskFactory;
import com.agileboot.infrastructure.thread.ThreadPoolManager;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.service.TokenService;
import com.agileboot.infrastructure.web.service.UserDetailsServiceImpl;
import com.agileboot.orm.common.enums.LoginStatusEnum;
import lombok.NonNull;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.admin.customize.service.login.TokenService;
import com.agileboot.common.enums.common.LoginStatusEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -38,7 +37,7 @@ import org.springframework.web.filter.CorsFilter;
* @see this#unauthorizedHandler() 用于用户未授权或登录失败处理
* @see this#logOutSuccessHandler 用于退出登录成功后的逻辑
* @see JwtAuthenticationTokenFilter#doFilter token的校验和刷新
* @see com.agileboot.infrastructure.web.service.LoginService#login 登录逻辑
* @see LoginService#login 登录逻辑
* @author valarchie
*/
@Configuration
@@ -47,26 +46,21 @@ import org.springframework.web.filter.CorsFilter;
@RequiredArgsConstructor
public class SecurityConfig {
@NonNull
private TokenService tokenService;
private final TokenService tokenService;
@NonNull
private RedisCacheService redisCache;
private final RedisCacheService redisCache;
/**
* token认证过滤器
*/
@NonNull
private JwtAuthenticationTokenFilter jwtTokenFilter;
private final JwtAuthenticationTokenFilter jwtTokenFilter;
@NonNull
private UserDetailsService userDetailsService;
private final UserDetailsService userDetailsService;
/**
* 跨域过滤器
*/
@NonNull
private CorsFilter corsFilter;
private final CorsFilter corsFilter;
/**
@@ -76,7 +70,9 @@ public class SecurityConfig {
@Bean
public AuthenticationEntryPoint unauthorizedHandler() {
return (request, response, exception) -> {
ResponseDTO<Object> responseDTO = ResponseDTO.fail(Client.COMMON_NO_AUTHORIZATION, request.getRequestURI());
ResponseDTO<Object> responseDTO = ResponseDTO.fail(
new ApiException(Client.COMMON_NO_AUTHORIZATION, request.getRequestURI())
);
ServletHolderUtil.renderString(response, JSONUtil.toJsonStr(responseDTO));
};
}
@@ -89,7 +85,7 @@ public class SecurityConfig {
@Bean
public LogoutSuccessHandler logOutSuccessHandler() {
return (request, response, authentication) -> {
LoginUser loginUser = tokenService.getLoginUser(request);
SystemLoginUser loginUser = tokenService.getLoginUser(request);
if (loginUser != null) {
String userName = loginUser.getUsername();
// 删除用户缓存记录
@@ -137,14 +133,16 @@ public class SecurityConfig {
// 过滤请求
.authorizeRequests()
// 对于登录login 注册register 验证码captchaImage 以及公共Api的请求允许匿名访问
.antMatchers("/login", "/register", "/captchaImage","/api/**").anonymous()
// 注意 当携带token请求以下这几个接口时 会返回403的错误
.antMatchers("/login", "/register", "/getConfig", "/captchaImage", "/api/**").anonymous()
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js",
"/profile/**").permitAll()
// TODO this is danger.
.antMatchers("/swagger-ui.html").anonymous()
.antMatchers("/swagger-resources/**").anonymous()
.antMatchers("/webjars/**").anonymous()
.antMatchers("/**/api-docs/**" ).anonymous()
.antMatchers("/*/api-docs","/*/api-docs/swagger-config").anonymous()
.antMatchers("/**/api-docs.yaml" ).anonymous()
.antMatchers("/druid/**").anonymous()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated()

View File

@@ -1,4 +1,4 @@
package com.agileboot.infrastructure.web.service;
package com.agileboot.admin.customize.service.login;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.convert.Convert;
@@ -9,33 +9,36 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.extra.servlet.ServletUtil;
import com.agileboot.common.utils.ServletHolderUtil;
import com.agileboot.common.config.AgileBootConfig;
import com.agileboot.common.constant.Constants.Captcha;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.common.exception.error.ErrorCode.Business;
import com.agileboot.common.utils.ServletHolderUtil;
import com.agileboot.common.utils.i18n.MessageUtils;
import com.agileboot.infrastructure.cache.guava.GuavaCacheService;
import com.agileboot.infrastructure.cache.redis.RedisCacheService;
import com.agileboot.infrastructure.thread.AsyncTaskFactory;
import com.agileboot.domain.common.cache.GuavaCacheService;
import com.agileboot.domain.common.cache.MapCache;
import com.agileboot.domain.common.cache.RedisCacheService;
import com.agileboot.admin.customize.async.AsyncTaskFactory;
import com.agileboot.infrastructure.thread.ThreadPoolManager;
import com.agileboot.infrastructure.web.domain.login.CaptchaDTO;
import com.agileboot.infrastructure.web.domain.login.LoginDTO;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.orm.common.enums.ConfigKeyEnum;
import com.agileboot.orm.common.enums.LoginStatusEnum;
import com.agileboot.orm.system.entity.SysUserEntity;
import com.agileboot.admin.customize.service.login.dto.CaptchaDTO;
import com.agileboot.admin.customize.service.login.dto.ConfigDTO;
import com.agileboot.admin.customize.service.login.command.LoginCommand;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.common.enums.common.ConfigKeyEnum;
import com.agileboot.common.enums.common.LoginStatusEnum;
import com.agileboot.domain.system.user.db.SysUserEntity;
import com.google.code.kaptcha.Producer;
import java.awt.image.BufferedImage;
import javax.annotation.Resource;
import lombok.NonNull;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.FastByteArrayOutputStream;
@@ -50,17 +53,13 @@ import org.springframework.util.FastByteArrayOutputStream;
@RequiredArgsConstructor
public class LoginService {
@NonNull
private TokenService tokenService;
private final TokenService tokenService;
@NonNull
private RedisCacheService redisCache;
private final RedisCacheService redisCache;
@NonNull
private GuavaCacheService guavaCache;
private final GuavaCacheService guavaCache;
@NonNull
private AuthenticationManager authenticationManager;
private final AuthenticationManager authenticationManager;
@Resource(name = "captchaProducer")
private Producer captchaProducer;
@@ -71,35 +70,36 @@ public class LoginService {
/**
* 登录验证
*
* @param loginDTO 登录参数
* @param loginCommand 登录参数
* @return 结果
*/
public String login(LoginDTO loginDTO) {
public String login(LoginCommand loginCommand) {
// 验证码开关
if (isCaptchaOn()) {
validateCaptcha(loginDTO.getUsername(), loginDTO.getCode(), loginDTO.getUuid());
validateCaptcha(loginCommand.getUsername(), loginCommand.getCaptchaCode(), loginCommand.getCaptchaCodeKey());
}
// 用户验证
Authentication authentication;
String decryptPassword = decryptPassword(loginDTO.getPassword());
String decryptPassword = decryptPassword(loginCommand.getPassword());
try {
// 该方法会去调用UserDetailsServiceImpl#loadUserByUsername 校验用户名和密码 认证鉴权
authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(
loginDTO.getUsername(), decryptPassword));
loginCommand.getUsername(), decryptPassword));
} catch (BadCredentialsException e) {
ThreadPoolManager.execute(AsyncTaskFactory.loginInfoTask(loginCommand.getUsername(), LoginStatusEnum.LOGIN_FAIL,
MessageUtils.message("Business.LOGIN_WRONG_USER_PASSWORD")));
throw new ApiException(e, ErrorCode.Business.LOGIN_WRONG_USER_PASSWORD);
} catch (AuthenticationException e) {
ThreadPoolManager.execute(AsyncTaskFactory.loginInfoTask(loginCommand.getUsername(), LoginStatusEnum.LOGIN_FAIL, e.getMessage()));
throw new ApiException(e, ErrorCode.Business.LOGIN_ERROR, e.getMessage());
} catch (Exception e) {
if (e instanceof BadCredentialsException) {
ThreadPoolManager.execute(AsyncTaskFactory.loginInfoTask(loginDTO.getUsername(), LoginStatusEnum.LOGIN_FAIL,
MessageUtils.message("user.password.not.match")));
throw new ApiException(ErrorCode.Business.LOGIN_WRONG_USER_PASSWORD);
} else {
ThreadPoolManager.execute(AsyncTaskFactory.loginInfoTask(loginDTO.getUsername(), LoginStatusEnum.LOGIN_FAIL, e.getMessage()));
throw new ApiException(e.getCause(), ErrorCode.Business.LOGIN_ERROR, e.getMessage());
}
ThreadPoolManager.execute(AsyncTaskFactory.loginInfoTask(loginCommand.getUsername(), LoginStatusEnum.LOGIN_FAIL, e.getMessage()));
throw new ApiException(e, Business.LOGIN_ERROR, e.getMessage());
}
// 把当前登录用户 放入上下文中
SecurityContextHolder.getContext().setAuthentication(authentication);
// 这里获取的loginUser是UserDetailsServiceImpl#loadUserByUsername方法返回的LoginUser
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
SystemLoginUser loginUser = (SystemLoginUser) authentication.getPrincipal();
recordLoginInfo(loginUser);
// 生成token
return tokenService.createTokenAndPutUserInCache(loginUser);
@@ -107,7 +107,22 @@ public class LoginService {
/**
* 获取验证码 data
* @return
*
* @return {@link ConfigDTO}
*/
public ConfigDTO getConfig() {
ConfigDTO configDTO = new ConfigDTO();
boolean isCaptchaOn = isCaptchaOn();
configDTO.setIsCaptchaOn(isCaptchaOn);
configDTO.setDictionary(MapCache.dictionaryCache());
return configDTO;
}
/**
* 获取验证码 data
*
* @return 验证码
*/
public CaptchaDTO generateCaptchaImg() {
CaptchaDTO captchaDTO = new CaptchaDTO();
@@ -116,7 +131,8 @@ public class LoginService {
captchaDTO.setIsCaptchaOn(isCaptchaOn);
if (isCaptchaOn) {
String expression, answer = null;
String expression;
String answer = null;
BufferedImage image = null;
// 生成验证码
@@ -139,15 +155,15 @@ public class LoginService {
}
// 保存验证码信息
String uuid = IdUtil.simpleUUID();
String imgKey = IdUtil.simpleUUID();
redisCache.captchaCache.set(uuid, answer);
redisCache.captchaCache.set(imgKey, answer);
// 转换流信息写出
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
ImgUtil.writeJpg(image, os);
captchaDTO.setUuid(uuid);
captchaDTO.setImg(Base64.encode(os.toByteArray()));
captchaDTO.setCaptchaCodeKey(imgKey);
captchaDTO.setCaptchaCodeImg(Base64.encode(os.toByteArray()));
}
@@ -159,18 +175,18 @@ public class LoginService {
* 校验验证码
*
* @param username 用户名
* @param code 验证码
* @param uuid 唯一标识
* @param captchaCode 验证码
* @param captchaCodeKey 验证码对应的缓存key
*/
public void validateCaptcha(String username, String code, String uuid) {
String captcha = redisCache.captchaCache.getObjectById(uuid);
redisCache.captchaCache.delete(uuid);
public void validateCaptcha(String username, String captchaCode, String captchaCodeKey) {
String captcha = redisCache.captchaCache.getObjectById(captchaCodeKey);
redisCache.captchaCache.delete(captchaCodeKey);
if (captcha == null) {
ThreadPoolManager.execute(AsyncTaskFactory.loginInfoTask(username, LoginStatusEnum.LOGIN_FAIL,
ErrorCode.Business.LOGIN_CAPTCHA_CODE_EXPIRE.message()));
throw new ApiException(ErrorCode.Business.LOGIN_CAPTCHA_CODE_EXPIRE);
}
if (!code.equalsIgnoreCase(captcha)) {
if (!captchaCode.equalsIgnoreCase(captcha)) {
ThreadPoolManager.execute(AsyncTaskFactory.loginInfoTask(username, LoginStatusEnum.LOGIN_FAIL,
ErrorCode.Business.LOGIN_CAPTCHA_CODE_WRONG.message()));
throw new ApiException(ErrorCode.Business.LOGIN_CAPTCHA_CODE_WRONG);
@@ -179,15 +195,15 @@ public class LoginService {
/**
* 记录登录信息
* @param loginUser
* @param loginUser 登录用户
*/
public void recordLoginInfo(LoginUser loginUser) {
public void recordLoginInfo(SystemLoginUser loginUser) {
ThreadPoolManager.execute(AsyncTaskFactory.loginInfoTask(loginUser.getUsername(), LoginStatusEnum.LOGIN_SUCCESS,
LoginStatusEnum.LOGIN_SUCCESS.description()));
SysUserEntity entity = redisCache.userCache.getObjectById(loginUser.getUserId());
entity.setLoginIp(ServletUtil.getClientIP(ServletHolderUtil.getRequest()));
entity.setLoginIp(ServletHolderUtil.getClientIp());
entity.setLoginDate(DateUtil.date());
entity.updateById();
}

View File

@@ -1,4 +1,4 @@
package com.agileboot.infrastructure.web.service;
package com.agileboot.admin.customize.service.login;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
@@ -6,8 +6,8 @@ import cn.hutool.core.util.StrUtil;
import com.agileboot.common.constant.Constants.Token;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.infrastructure.cache.redis.RedisCacheService;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.domain.common.cache.RedisCacheService;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.MalformedJwtException;
@@ -16,9 +16,8 @@ import io.jsonwebtoken.SignatureException;
import io.jsonwebtoken.UnsupportedJwtException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@@ -55,15 +54,14 @@ public class TokenService {
@Value("${token.autoRefreshTime}")
private long autoRefreshTime;
@NonNull
private RedisCacheService redisCache;
private final RedisCacheService redisCache;
/**
* 获取用户身份信息
*
* @return 用户信息
*/
public LoginUser getLoginUser(HttpServletRequest request) {
public SystemLoginUser getLoginUser(HttpServletRequest request) {
// 获取请求携带的令牌
String token = getTokenFromRequest(request);
if (StrUtil.isNotEmpty(token)) {
@@ -74,11 +72,11 @@ public class TokenService {
return redisCache.loginUserCache.getObjectOnlyInCacheById(uuid);
} catch (SignatureException | MalformedJwtException | UnsupportedJwtException | IllegalArgumentException jwtException) {
log.error("parse token failed. due to:{}", jwtException.getMessage());
throw new ApiException(jwtException, ErrorCode.Internal.INVALID_TOKEN);
log.error("parse token failed.", jwtException);
throw new ApiException(jwtException, ErrorCode.Client.INVALID_TOKEN);
} catch (Exception e) {
log.error("fail to get cached user from redis", e);
throw new ApiException(e, ErrorCode.UNKNOWN_ERROR);
throw new ApiException(e, ErrorCode.Client.TOKEN_PROCESS_FAILED, e.getMessage());
}
}
@@ -91,7 +89,7 @@ public class TokenService {
* @param loginUser 用户信息
* @return 令牌
*/
public String createTokenAndPutUserInCache(LoginUser loginUser) {
public String createTokenAndPutUserInCache(SystemLoginUser loginUser) {
loginUser.setCachedKey(IdUtil.fastUUID());
redisCache.loginUserCache.set(loginUser.getCachedKey(), loginUser);
@@ -103,7 +101,7 @@ public class TokenService {
* 当超过20分钟自动刷新token
* @param loginUser 登录用户
*/
public void refreshToken(LoginUser loginUser) {
public void refreshToken(SystemLoginUser loginUser) {
long currentTime = System.currentTimeMillis();
if (currentTime > loginUser.getAutoRefreshCacheTime()) {
loginUser.setAutoRefreshCacheTime(currentTime + TimeUnit.MINUTES.toMillis(autoRefreshTime));
@@ -156,8 +154,8 @@ public class TokenService {
*/
private String getTokenFromRequest(HttpServletRequest request) {
String token = request.getHeader(header);
if (StrUtil.isNotEmpty(token) && token.startsWith(Token.TOKEN_PREFIX)) {
token = StrUtil.stripIgnoreCase(token, Token.TOKEN_PREFIX, null);
if (StrUtil.isNotEmpty(token) && token.startsWith(Token.PREFIX)) {
token = StrUtil.stripIgnoreCase(token, Token.PREFIX, null);
}
return token;
}

View File

@@ -1,20 +1,21 @@
package com.agileboot.infrastructure.web.service;
package com.agileboot.admin.customize.service.login;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import java.util.Collections;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.domain.login.RoleInfo;
import com.agileboot.orm.common.enums.DataScopeEnum;
import com.agileboot.orm.common.enums.UserStatusEnum;
import com.agileboot.orm.common.util.BasicEnumUtil;
import com.agileboot.orm.system.entity.SysMenuEntity;
import com.agileboot.orm.system.entity.SysRoleEntity;
import com.agileboot.orm.system.entity.SysUserEntity;
import com.agileboot.orm.system.service.ISysMenuService;
import com.agileboot.orm.system.service.ISysRoleService;
import com.agileboot.orm.system.service.ISysUserService;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.infrastructure.user.web.RoleInfo;
import com.agileboot.infrastructure.user.web.DataScopeEnum;
import com.agileboot.common.enums.common.UserStatusEnum;
import com.agileboot.common.enums.BasicEnumUtil;
import com.agileboot.domain.system.menu.db.SysMenuEntity;
import com.agileboot.domain.system.role.db.SysRoleEntity;
import com.agileboot.domain.system.user.db.SysUserEntity;
import com.agileboot.domain.system.menu.db.SysMenuService;
import com.agileboot.domain.system.role.db.SysRoleService;
import com.agileboot.domain.system.user.db.SysUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.List;
@@ -22,10 +23,8 @@ import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.SetUtils;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -35,6 +34,7 @@ import org.springframework.stereotype.Service;
/**
* 自定义加载用户信息通过用户名
* 用于SpringSecurity 登录流程
* 没有办法把这个类 放进loginService中 会在SecurityConfig中造成循环依赖
* @see com.agileboot.infrastructure.config.SecurityConfig#filterChain(HttpSecurity)
* @author valarchie
*/
@@ -43,17 +43,13 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {
@NonNull
private ISysUserService userService;
private final SysUserService userService;
@NonNull
private ISysMenuService menuService;
private final SysMenuService menuService;
@NonNull
private ISysRoleService roleService;
private final SysRoleService roleService;
@NonNull
private TokenService tokenService;
private final TokenService tokenService;
@Override
@@ -67,27 +63,30 @@ public class UserDetailsServiceImpl implements UserDetailsService {
log.info("登录用户:{} 已被停用.", username);
throw new ApiException(ErrorCode.Business.USER_IS_DISABLE, username);
}
LoginUser loginUser = new LoginUser(userEntity.getUserId(), userEntity.getIsAdmin(), userEntity.getUsername(),
userEntity.getPassword());
loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setAutoRefreshCacheTime(loginUser.getLoginTime() + TimeUnit.MINUTES.toMillis(tokenService.getAutoRefreshTime()));
loginUser.fillUserAgent();
RoleInfo roleInfo = getRoleInfo(userEntity.getRoleId(), userEntity.getIsAdmin());
SystemLoginUser loginUser = new SystemLoginUser(userEntity.getUserId(), userEntity.getIsAdmin(), userEntity.getUsername(),
userEntity.getPassword(), roleInfo, userEntity.getDeptId());
loginUser.fillLoginInfo();
loginUser.setAutoRefreshCacheTime(loginUser.getLoginInfo().getLoginTime()
+ TimeUnit.MINUTES.toMillis(tokenService.getAutoRefreshTime()));
return loginUser;
}
public RoleInfo getRoleInfo(Long roleId) {
public RoleInfo getRoleInfo(Long roleId, boolean isAdmin) {
if (roleId == null) {
return RoleInfo.EMPTY_ROLE;
}
if (roleId == RoleInfo.ADMIN_ROLE_ID) {
if (isAdmin) {
LambdaQueryWrapper<SysMenuEntity> menuQuery = Wrappers.lambdaQuery();
menuQuery.select(SysMenuEntity::getMenuId);
List<SysMenuEntity> allMenus = menuService.list(menuQuery);
Set<Long> allMenuIds = allMenus.stream().map(SysMenuEntity::getMenuId).collect(Collectors.toSet());
return new RoleInfo(RoleInfo.ADMIN_ROLE_ID, RoleInfo.ADMIN_ROLE_KEY, DataScopeEnum.ALL, SetUtils.emptySet(),
return new RoleInfo(RoleInfo.ADMIN_ROLE_ID, RoleInfo.ADMIN_ROLE_KEY, DataScopeEnum.ALL, Collections.emptySet(),
RoleInfo.ADMIN_PERMISSIONS, allMenuIds);
}
@@ -101,11 +100,11 @@ public class UserDetailsServiceImpl implements UserDetailsService {
List<SysMenuEntity> menuList = roleService.getMenuListByRoleId(roleId);
Set<Long> menuIds = menuList.stream().map(SysMenuEntity::getMenuId).collect(Collectors.toSet());
Set<String> permissions = menuList.stream().map(SysMenuEntity::getPerms).collect(Collectors.toSet());
Set<String> permissions = menuList.stream().map(SysMenuEntity::getPermission).collect(Collectors.toSet());
DataScopeEnum dataScopeEnum = BasicEnumUtil.fromValue(DataScopeEnum.class, roleEntity.getDataScope());
Set<Long> deptIdSet = SetUtils.emptySet();
Set<Long> deptIdSet = Collections.emptySet();
if (StrUtil.isNotEmpty(roleEntity.getDeptIdSet())) {
deptIdSet = StrUtil.split(roleEntity.getDeptIdSet(), ",").stream()
.map(Convert::toLong).collect(Collectors.toSet());
@@ -115,5 +114,4 @@ public class UserDetailsServiceImpl implements UserDetailsService {
}
}

View File

@@ -1,4 +1,4 @@
package com.agileboot.infrastructure.web.domain.login;
package com.agileboot.admin.customize.service.login.command;
import lombok.Data;
@@ -8,7 +8,7 @@ import lombok.Data;
* @author valarchie
*/
@Data
public class LoginDTO {
public class LoginCommand {
/**
* 用户名
@@ -23,11 +23,11 @@ public class LoginDTO {
/**
* 验证码
*/
private String code;
private String captchaCode;
/**
* 唯一标识
*/
private String uuid;
private String captchaCodeKey;
}

View File

@@ -0,0 +1,15 @@
package com.agileboot.admin.customize.service.login.dto;
import lombok.Data;
/**
* @author valarchie
*/
@Data
public class CaptchaDTO {
private Boolean isCaptchaOn;
private String captchaCodeKey;
private String captchaCodeImg;
}

View File

@@ -0,0 +1,18 @@
package com.agileboot.admin.customize.service.login.dto;
import com.agileboot.common.enums.dictionary.DictionaryData;
import java.util.List;
import java.util.Map;
import lombok.Data;
/**
* @author valarchie
*/
@Data
public class ConfigDTO {
private Boolean isCaptchaOn;
private Map<String, List<DictionaryData>> dictionary;
}

View File

@@ -1,16 +1,17 @@
package com.agileboot.infrastructure.web.domain.permission;
package com.agileboot.admin.customize.service.permission;
import cn.hutool.extra.spring.SpringUtil;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.domain.permission.checker.AllDataPermissionChecker;
import com.agileboot.infrastructure.web.domain.permission.checker.CustomDataPermissionChecker;
import com.agileboot.infrastructure.web.domain.permission.checker.DefaultDataPermissionChecker;
import com.agileboot.infrastructure.web.domain.permission.checker.DeptTreeDataPermissionChecker;
import com.agileboot.infrastructure.web.domain.permission.checker.OnlySelfDataPermissionChecker;
import com.agileboot.infrastructure.web.domain.permission.checker.SingleDeptDataPermissionChecker;
import com.agileboot.orm.common.enums.DataScopeEnum;
import com.agileboot.orm.system.service.ISysDeptService;
import javax.annotation.PostConstruct;
import com.agileboot.admin.customize.service.permission.model.AbstractDataPermissionChecker;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.admin.customize.service.permission.model.checker.AllDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.checker.CustomDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.checker.DefaultDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.checker.DeptTreeDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.checker.OnlySelfDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.checker.SingleDeptDataPermissionChecker;
import com.agileboot.infrastructure.user.web.DataScopeEnum;
import com.agileboot.domain.system.dept.db.SysDeptService;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Component;
/**
@@ -29,7 +30,7 @@ public class DataPermissionCheckerFactory {
@PostConstruct
public void initAllChecker() {
ISysDeptService deptService = SpringUtil.getBean(ISysDeptService.class);
SysDeptService deptService = SpringUtil.getBean(SysDeptService.class);
allChecker = new AllDataPermissionChecker();
customChecker = new CustomDataPermissionChecker(deptService);
@@ -40,7 +41,7 @@ public class DataPermissionCheckerFactory {
}
public static AbstractDataPermissionChecker getChecker(LoginUser loginUser) {
public static AbstractDataPermissionChecker getChecker(SystemLoginUser loginUser) {
if (loginUser == null) {
return deptTreeChecker;
}

View File

@@ -1,15 +1,13 @@
package com.agileboot.infrastructure.web.service;
package com.agileboot.admin.customize.service.permission;
import cn.hutool.core.collection.CollUtil;
import com.agileboot.infrastructure.security.AuthenticationUtils;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.domain.permission.AbstractDataPermissionChecker;
import com.agileboot.infrastructure.web.domain.permission.DataCondition;
import com.agileboot.infrastructure.web.domain.permission.DataPermissionCheckerFactory;
import com.agileboot.orm.system.entity.SysUserEntity;
import com.agileboot.orm.system.service.ISysUserService;
import com.agileboot.admin.customize.service.permission.model.AbstractDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.DataCondition;
import com.agileboot.infrastructure.user.AuthenticationUtils;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.domain.system.user.db.SysUserEntity;
import com.agileboot.domain.system.user.db.SysUserService;
import java.util.List;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -21,16 +19,16 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class DataPermissionService {
@NonNull
private ISysUserService userService;
private final SysUserService userService;
/**
* 通过userId 校验当前用户 目标用户是否有操作权限
* @param userId
*
* @param userId 用户id
* @return 检验结果
*/
public boolean checkUserId(Long userId) {
LoginUser loginUser = AuthenticationUtils.getLoginUser();
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
SysUserEntity targetUser = userService.getById(userId);
if (targetUser == null) {
return true;
@@ -40,8 +38,8 @@ public class DataPermissionService {
/**
* 通过userId 校验当前用户 目标用户是否有操作权限
* @param userIds
* @return
* @param userIds 用户id列表
* @return 校验结果
*/
public boolean checkUserIds(List<Long> userIds) {
if (CollUtil.isNotEmpty(userIds)) {
@@ -56,12 +54,12 @@ public class DataPermissionService {
}
public boolean checkDeptId(Long deptId) {
LoginUser loginUser = AuthenticationUtils.getLoginUser();
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
return checkDataScope(loginUser, deptId, null);
}
public boolean checkDataScope(LoginUser loginUser, Long targetDeptId, Long targetUserId) {
public boolean checkDataScope(SystemLoginUser loginUser, Long targetDeptId, Long targetUserId) {
DataCondition dataCondition = DataCondition.builder().targetDeptId(targetDeptId).targetUserId(targetUserId).build();
AbstractDataPermissionChecker checker = DataPermissionCheckerFactory.getChecker(loginUser);
return checker.check(loginUser, dataCondition);

View File

@@ -1,10 +1,10 @@
package com.agileboot.infrastructure.web.service;
package com.agileboot.admin.customize.service.permission;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.agileboot.infrastructure.security.AuthenticationUtils;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.domain.login.RoleInfo;
import com.agileboot.infrastructure.user.AuthenticationUtils;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.infrastructure.user.web.RoleInfo;
import java.util.Set;
import org.springframework.stereotype.Service;
@@ -26,7 +26,7 @@ public class MenuPermissionService {
if (StrUtil.isEmpty(permission)) {
return false;
}
LoginUser loginUser = AuthenticationUtils.getLoginUser();
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
if (loginUser == null || CollUtil.isEmpty(loginUser.getRoleInfo().getMenuPermissions())) {
return false;
}

View File

@@ -0,0 +1,25 @@
package com.agileboot.admin.customize.service.permission.model;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.domain.system.dept.db.SysDeptService;
import lombok.Data;
/**
* 数据权限测试接口
* @author valarchie
*/
@Data
public abstract class AbstractDataPermissionChecker {
private SysDeptService deptService;
/**
* 检测当前用户对于 给定条件的数据 是否有权限
*
* @param loginUser 登录用户
* @param condition 条件
* @return 校验结果
*/
public abstract boolean check(SystemLoginUser loginUser, DataCondition condition);
}

View File

@@ -1,4 +1,4 @@
package com.agileboot.infrastructure.web.domain.permission;
package com.agileboot.admin.customize.service.permission.model;
import lombok.AllArgsConstructor;
import lombok.Builder;

View File

@@ -0,0 +1,25 @@
package com.agileboot.admin.customize.service.permission.model.checker;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.admin.customize.service.permission.model.AbstractDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.DataCondition;
import com.agileboot.domain.system.dept.db.SysDeptService;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 数据权限测试接口
* @author valarchie
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class AllDataPermissionChecker extends AbstractDataPermissionChecker {
private SysDeptService deptService;
@Override
public boolean check(SystemLoginUser loginUser, DataCondition condition) {
return true;
}
}

View File

@@ -1,29 +1,31 @@
package com.agileboot.infrastructure.web.domain.permission.checker;
package com.agileboot.admin.customize.service.permission.model.checker;
import cn.hutool.core.collection.CollUtil;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.domain.permission.AbstractDataPermissionChecker;
import com.agileboot.infrastructure.web.domain.permission.DataCondition;
import com.agileboot.orm.system.service.ISysDeptService;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.admin.customize.service.permission.model.AbstractDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.DataCondition;
import com.agileboot.domain.system.dept.db.SysDeptService;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* 数据权限测试接口
* @author valarchie
*/
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CustomDataPermissionChecker extends AbstractDataPermissionChecker {
private ISysDeptService deptService;
private SysDeptService deptService;
@Override
public boolean check(LoginUser loginUser, DataCondition condition) {
public boolean check(SystemLoginUser loginUser, DataCondition condition) {
if (condition == null || loginUser == null) {
return false;
}

View File

@@ -0,0 +1,25 @@
package com.agileboot.admin.customize.service.permission.model.checker;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.admin.customize.service.permission.model.AbstractDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.DataCondition;
import com.agileboot.domain.system.dept.db.SysDeptService;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 数据权限测试接口
* @author valarchie
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class DefaultDataPermissionChecker extends AbstractDataPermissionChecker {
private SysDeptService deptService;
@Override
public boolean check(SystemLoginUser loginUser, DataCondition condition) {
return false;
}
}

View File

@@ -1,27 +1,29 @@
package com.agileboot.infrastructure.web.domain.permission.checker;
package com.agileboot.admin.customize.service.permission.model.checker;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.domain.permission.AbstractDataPermissionChecker;
import com.agileboot.infrastructure.web.domain.permission.DataCondition;
import com.agileboot.orm.system.service.ISysDeptService;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.admin.customize.service.permission.model.AbstractDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.DataCondition;
import com.agileboot.domain.system.dept.db.SysDeptService;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* 数据权限测试接口
* @author valarchie
*/
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DeptTreeDataPermissionChecker extends AbstractDataPermissionChecker {
private ISysDeptService deptService;
private SysDeptService deptService;
@Override
public boolean check(LoginUser loginUser, DataCondition condition) {
public boolean check(SystemLoginUser loginUser, DataCondition condition) {
if (condition == null || loginUser == null) {
return false;
}

View File

@@ -1,27 +1,29 @@
package com.agileboot.infrastructure.web.domain.permission.checker;
package com.agileboot.admin.customize.service.permission.model.checker;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.domain.permission.AbstractDataPermissionChecker;
import com.agileboot.infrastructure.web.domain.permission.DataCondition;
import com.agileboot.orm.system.service.ISysDeptService;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.admin.customize.service.permission.model.AbstractDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.DataCondition;
import com.agileboot.domain.system.dept.db.SysDeptService;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* 数据权限测试接口
* @author valarchie
*/
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class OnlySelfDataPermissionChecker extends AbstractDataPermissionChecker {
private ISysDeptService deptService;
private SysDeptService deptService;
@Override
public boolean check(LoginUser loginUser, DataCondition condition) {
public boolean check(SystemLoginUser loginUser, DataCondition condition) {
if (condition == null || loginUser == null) {
return false;
}

View File

@@ -1,27 +1,29 @@
package com.agileboot.infrastructure.web.domain.permission.checker;
package com.agileboot.admin.customize.service.permission.model.checker;
import com.agileboot.infrastructure.web.domain.login.LoginUser;
import com.agileboot.infrastructure.web.domain.permission.AbstractDataPermissionChecker;
import com.agileboot.infrastructure.web.domain.permission.DataCondition;
import com.agileboot.orm.system.service.ISysDeptService;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.agileboot.admin.customize.service.permission.model.AbstractDataPermissionChecker;
import com.agileboot.admin.customize.service.permission.model.DataCondition;
import com.agileboot.domain.system.dept.db.SysDeptService;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* 数据权限测试接口
* @author valarchie
*/
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SingleDeptDataPermissionChecker extends AbstractDataPermissionChecker {
private ISysDeptService deptService;
private SysDeptService deptService;
@Override
public boolean check(LoginUser loginUser, DataCondition condition) {
public boolean check(SystemLoginUser loginUser, DataCondition condition) {
if (condition == null || loginUser == null) {
return false;
}

View File

@@ -50,25 +50,21 @@ spring:
datasource:
# 主库数据源
master:
url: jdbc:mysql://localhost:33067/agileboot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 12345
url: jdbc:mysql://mysql2.sqlpub.com:3307/agileboot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&sslMode=REQUIRED
username: ENC(s4kjpEsplGGLeV3YRNvJpJhDSOAO0tEf)
password: ENC(hg/hxmducWsI8u83/eXgAi8yHBDFbB5z0xzwNtBejPc=)
# 从库数据源
# slave:
# url: jdbc:mysql://localhost:33067/agileboot2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: root
# password: 12345
# slave:
# url: jdbc:mysql://localhost:33067/agileboot2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: root
# password: 12345
# redis 配置
redis:
# 地址
host: localhost
# 端口默认为6379
port: 36379
# 数据库索引
database: 0
# 密码
password: 12345
host: redis
port: 6379
database: 1
password: ENC(s3HU866TUAjzrWStN7kpQQ==)
# 连接超时时间
timeout: 10s
lettuce:
@@ -84,17 +80,25 @@ spring:
logging:
file:
path: D:/logs/agileboot-dev
path: ./logs/agileboot-dev
springdoc:
api-docs:
path: ${agileboot.api-docs-path-prefix}/v3/api-docs
swagger-ui:
# ***注意*** 开启Swagger UI界面 **安全考虑的话生产环境需要关掉**
# 因为knife4j的一些配置不灵活 所以重新改回springdoc+swagger的组合 真实开发的时候 使用apifox这种工具效率更高
enabled: true
url: ${agileboot.api-prefix}/v3/api-docs
config-url: ${agileboot.api-prefix}/v3/api-docs/swagger-config
# 项目相关配置
agileboot:
# 文件基路径 示例( Windows配置D:\agilebootLinux配置 /home/agileboot
file-base-dir: D:\agileboot
# 因为knife4j不能给configUrl 配置前缀, 所以只能自己配置一个,然后通过转发来实现
api-docs-path-prefix: /dev-api
# 前端url请求转发前缀
api-prefix: /dev-api
demo-enabled: false
jasypt:
encryptor:
password: ${JASYPT_ENCRYPTOR_PASSWORD:}

View File

@@ -10,7 +10,7 @@ spring:
datasource:
master:
# h2 内存数据库 内存模式连接配置 库名: agileboot
url: jdbc:h2:mem:agileboot;DB_CLOSE_DELAY=-1
url: jdbc:h2:mem:agileboot;DB_CLOSE_DELAY=-1;MODE=MySQL
h2:
# 开启console 访问 默认false
console:

View File

@@ -1,7 +1,7 @@
# 开发环境配置
server:
# 服务器的HTTP端口默认为8080
port: 8080
port: 18080
servlet:
# 应用的访问路径
context-path: /
@@ -38,12 +38,9 @@ springdoc:
groups:
enabled: true
group-configs:
- group: '公共管理API'
- group: '公共API'
packages-to-scan: com.agileboot.admin.controller.common
- group: '监控管理API'
packages-to-scan: com.agileboot.admin.controller.monitor
- group: '系统管理API'
- group: '内置系统API'
packages-to-scan: com.agileboot.admin.controller.system
- group: '工具管理API'
packages-to-scan: com.agileboot.admin.controller.tool

View File

@@ -1,44 +0,0 @@
package com.agileboot.admin.config;
import com.agileboot.admin.AgileBootAdminApplication;
import com.agileboot.common.config.AgileBootConfig;
import com.agileboot.common.constant.Constants.UploadSubDir;
import java.io.File;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest(classes = AgileBootAdminApplication.class)
@RunWith(SpringRunner.class)
public class AgileBootConfigTest {
@Resource
private AgileBootConfig config;
@Test
public void testConfig() {
String fileBaseDir = "D:\\agileboot\\profile";
Assertions.assertEquals("AgileBoot", config.getName());
Assertions.assertEquals("1.0.0", config.getVersion());
Assertions.assertEquals("2022", config.getCopyrightYear());
Assertions.assertTrue(config.isDemoEnabled());
Assertions.assertEquals(fileBaseDir, AgileBootConfig.getFileBaseDir());
Assertions.assertFalse(AgileBootConfig.isAddressEnabled());
Assertions.assertEquals("math", AgileBootConfig.getCaptchaType());
Assertions.assertEquals("math", AgileBootConfig.getCaptchaType());
Assertions.assertEquals(fileBaseDir + "\\import",
AgileBootConfig.getFileBaseDir() + File.separator + UploadSubDir.IMPORT_PATH);
Assertions.assertEquals(fileBaseDir + "\\avatar",
AgileBootConfig.getFileBaseDir() + File.separator + UploadSubDir.AVATAR_PATH);
Assertions.assertEquals(fileBaseDir + "\\download",
AgileBootConfig.getFileBaseDir() + File.separator + UploadSubDir.DOWNLOAD_PATH);
Assertions.assertEquals(fileBaseDir + "\\upload",
AgileBootConfig.getFileBaseDir() + File.separator + UploadSubDir.UPLOAD_PATH);
}
}

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>agileboot</artifactId>
<groupId>com.agileboot</groupId>
<version>${revision}</version>
<version>1.0.0</version>
</parent>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
@@ -22,6 +22,18 @@
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>agileboot-infrastructure</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--使用undertow依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<!-- 业务领域 -->

View File

@@ -6,12 +6,12 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
/**
* 启动程序
* 定制banner.txt的网站
* http://patorjk.com/software/taag
* http://www.network-science.de/ascii/
* http://www.degraeve.com/img2txt.php
* http://life.chacuo.net/convertfont2char
* 启动程序 定制banner.txt的网站
* <a href="http://patorjk.com/software/taag">http://patorjk.com/software/taag</a>
* <a href="http://www.network-science.de/ascii/">http://www.network-science.de/ascii/</a>
* <a href="http://www.degraeve.com/img2txt.php">http://www.degraeve.com/img2txt.php</a>
* <a href="http://life.chacuo.net/convertfont2char">http://life.chacuo.net/convertfont2char</a>
*
* @author valarchie
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

View File

@@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* 调度日志操作处理
*
* @author ruoyi
* @author valarchie
*/
@RestController
@RequestMapping("/api/order")

View File

@@ -0,0 +1,39 @@
package com.agileboot.api.controller.app;
import com.agileboot.api.customize.service.JwtTokenService;
import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 调度日志操作处理
*
* @author ruoyi
*/
@RestController
@RequestMapping("/app")
@AllArgsConstructor
public class AppController extends BaseController {
private final JwtTokenService jwtTokenService;
/**
* 访问首页,提示语
*/
@PreAuthorize("hasAuthority('annie')")
@GetMapping("/list")
public ResponseDTO<?> appLogin() {
return ResponseDTO.ok();
}
}

View File

@@ -0,0 +1,38 @@
package com.agileboot.api.controller.common;
import cn.hutool.core.map.MapUtil;
import com.agileboot.api.customize.service.JwtTokenService;
import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import java.util.Map;
import lombok.AllArgsConstructor;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 调度日志操作处理
*
* @author ruoyi
*/
@RestController
@RequestMapping("/common")
@AllArgsConstructor
public class LoginController extends BaseController {
private final JwtTokenService jwtTokenService;
/**
* 访问首页,提示语
*/
@PostMapping("/app/{appId}/login")
public ResponseDTO<String> appLogin() {
String token = jwtTokenService.generateToken(MapUtil.of("token", "user1"));
return ResponseDTO.ok(token);
}
}

View File

@@ -0,0 +1,52 @@
package com.agileboot.api.customize.config;
import com.agileboot.api.customize.service.JwtTokenService;
import com.agileboot.infrastructure.user.app.AppLoginUser;
import io.jsonwebtoken.Claims;
import java.io.IOException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
/**
* token过滤器 验证token有效性
* 继承OncePerRequestFilter类的话 可以确保只执行filter一次 避免执行多次
* @author valarchie
*/
@Component
@Slf4j
@RequiredArgsConstructor
public class JwtAuthenticationFilter extends OncePerRequestFilter {
@Autowired
private JwtTokenService jwtTokenService;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String tokenFromRequest = jwtTokenService.getTokenFromRequest(request);
if (tokenFromRequest != null) {
Claims claims = jwtTokenService.parseToken(tokenFromRequest);
String token = (String) claims.get("token");
// 根据token去查缓存里面 有没有对应的App用户
// 没有的话 再去数据库中查询
if (token != null && token.equals("user1")) {
AppLoginUser loginUser = new AppLoginUser(23232323L, false, "dasdsadsds");
loginUser.grantAppPermission("annie");
UsernamePasswordAuthenticationToken suer1 = new UsernamePasswordAuthenticationToken(loginUser, null,
loginUser.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(suer1);
}
}
filterChain.doFilter(request, response);
}
}

View File

@@ -0,0 +1,85 @@
package com.agileboot.api.customize.config;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode.Client;
import com.agileboot.common.utils.ServletHolderUtil;
import com.agileboot.common.utils.jackson.JacksonUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.filter.CorsFilter;
/**
* 主要配置登录流程逻辑涉及以下几个类
* @author valarchie
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@RequiredArgsConstructor
public class SecurityConfig {
/**
* token认证过滤器
*/
private final JwtAuthenticationFilter jwtTokenFilter;
/**
* 跨域过滤器
*/
private final CorsFilter corsFilter;
/**
* 登录异常处理类
* 用户未登陆的话 在这个Bean中处理
*/
@Bean
public AuthenticationEntryPoint customAuthenticationEntryPoint() {
return (request, response, exception) -> {
ResponseDTO<Void> responseDTO = ResponseDTO.fail(
new ApiException(Client.COMMON_NO_AUTHORIZATION, request.getRequestURI())
);
ServletHolderUtil.renderString(response, JacksonUtil.to(responseDTO));
};
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable()
// 不配这个错误处理的话 会直接返回403
.exceptionHandling().authenticationEntryPoint(customAuthenticationEntryPoint())
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 禁用 session
.and()
.authorizeRequests()
.antMatchers("/common/**").permitAll()
.anyRequest().authenticated()
.and()
// 禁用 X-Frame-Options 响应头。下面是具体解释:
// X-Frame-Options 是一个 HTTP 响应头,用于防止网页被嵌入到其他网页的 <frame>、<iframe> 或 <object> 标签中,从而可以减少点击劫持攻击的风险
.headers().frameOptions().disable()
.and()
.formLogin().disable();
httpSecurity.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class);
// 添加CORS filter
httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationFilter.class);
return httpSecurity.build();
}
}

View File

@@ -0,0 +1,127 @@
package com.agileboot.api.customize.service;
import cn.hutool.core.util.StrUtil;
import com.agileboot.common.constant.Constants.Token;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.common.cache.RedisCacheService;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.MalformedJwtException;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.SignatureException;
import io.jsonwebtoken.UnsupportedJwtException;
import java.util.Map;
import jakarta.servlet.http.HttpServletRequest;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* token验证处理
*
* @author valarchie
*/
@Component
@Slf4j
@Data
@RequiredArgsConstructor
public class JwtTokenService {
/**
* 自定义令牌标识
*/
@Value("${token.header}")
private String header;
/**
* 令牌秘钥
*/
@Value("${token.secret}")
private String secret;
private final RedisCacheService redisCache;
/**
* 获取用户身份信息
*
* @return 用户信息
*/
public SystemLoginUser getLoginUser(HttpServletRequest request) {
// 获取请求携带的令牌
String token = getTokenFromRequest(request);
if (StrUtil.isNotEmpty(token)) {
try {
Claims claims = parseToken(token);
// 解析对应的权限以及用户信息
String uuid = (String) claims.get(Token.LOGIN_USER_KEY);
return redisCache.loginUserCache.getObjectOnlyInCacheById(uuid);
} catch (SignatureException | MalformedJwtException | UnsupportedJwtException | IllegalArgumentException jwtException) {
log.error("parse token failed.", jwtException);
throw new ApiException(jwtException, ErrorCode.Client.INVALID_TOKEN);
} catch (Exception e) {
log.error("fail to get cached user from redis", e);
throw new ApiException(e, ErrorCode.Client.TOKEN_PROCESS_FAILED, e.getMessage());
}
}
return null;
}
/**
* 从数据声明生成令牌
*
* @param claims 数据声明
* @return 令牌
*/
public String generateToken(Map<String, Object> claims) {
return Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret).compact();
}
/**
* 从令牌中获取数据声明
*
* @param token 令牌
* @return 数据声明
*/
public Claims parseToken(String token) {
return Jwts.parser()
.setSigningKey(secret)
.parseClaimsJws(token)
.getBody();
}
/**
* 从令牌中获取用户名
*
* @param token 令牌
* @return 用户名
*/
private String getUsernameFromToken(String token) {
Claims claims = parseToken(token);
return claims.getSubject();
}
/**
* 获取请求token
*
* @return token
*/
public String getTokenFromRequest(HttpServletRequest request) {
String token = request.getHeader(header);
if (StrUtil.isNotEmpty(token) && token.startsWith(Token.PREFIX)) {
token = StrUtil.stripIgnoreCase(token, Token.PREFIX, null);
}
return token;
}
}

View File

@@ -0,0 +1,12 @@
package com.agileboot.api.customize.util;
public class ApiEncryptor {
public static void main(String[] args) {
}
}

View File

@@ -0,0 +1,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.agileboot</groupId>
<artifactId>agileboot</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>agileboot-boot-start</artifactId>
<dependencies>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-web</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-module-ai</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,24 @@
package com.agileboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @Author cuiJiaWang
* @Create 2025-08-12 18:07
*/
@SpringBootApplication
public class AgilebootBootApplication {
public static void main(String[] args) {
SpringApplication.run(AgilebootBootApplication.class, args);
String successMsg = " ____ _ _ __ _ _ \n"
+ " / ___| | |_ __ _ _ __ | |_ _ _ _ __ ___ _ _ ___ ___ ___ ___ ___ / _| _ _ | || |\n"
+ " \\___ \\ | __|/ _` || '__|| __| | | | || '_ \\ / __|| | | | / __|/ __|/ _ \\/ __|/ __|| |_ | | | || || |\n"
+ " ___) || |_| (_| || | | |_ | |_| || |_) | \\__ \\| |_| || (__| (__| __/\\__ \\\\__ \\| _|| |_| || ||_|\n"
+ " |____/ \\__|\\__,_||_| \\__| \\__,_|| .__/ |___/ \\__,_| \\___|\\___|\\___||___/|___/|_| \\__,_||_|(_)\n"
+ " |_| ";
System.out.println(successMsg);
}
}

View File

@@ -0,0 +1,4 @@
server:
port: 8080
servlet:
context-path: /api

View File

@@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.agileboot</groupId>
<artifactId>agileboot-cloud</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>agileboot-cloud-start</artifactId>
<dependencies>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-web</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,11 @@
package com.agileboot;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @Author cuiJiaWang
* @Create 2025-08-12 17:35
*/
@SpringBootApplication
public class AgilebootCloudApplication {
}

15
agileboot-cloud/pom.xml Normal file
View File

@@ -0,0 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.agileboot</groupId>
<artifactId>agileboot</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>agileboot-cloud</artifactId>
<packaging>pom</packaging>
<modules>
<module>agileboot-cloud-start</module>
</modules>
</project>

View File

@@ -5,10 +5,21 @@
<parent>
<artifactId>agileboot</artifactId>
<groupId>com.agileboot</groupId>
<version>${revision}</version>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<modules>
<module>wol-common-box</module>
<module>wol-common-core</module>
<module>wol-common-doc</module>
<module>wol-common-web</module>
<module>wol-common-mybatis</module>
<module>wol-common-redis</module>
<module>wol-common-json</module>
</modules>
<packaging>pom</packaging>
<artifactId>agileboot-common</artifactId>
<description>
@@ -17,176 +28,78 @@
<dependencies>
<!-- Spring框架基本的核心工具 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<!-- SpringWeb模块 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- spring security 安全认证 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- 自定义验证注解 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!--常用工具类 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- JSON工具类 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- io常用工具类 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>-->
<!-- 文件上传工具类 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<!-- excel工具 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>commons-fileupload</groupId>-->
<!-- <artifactId>commons-fileupload</artifactId>-->
<!-- </dependency>-->
<!-- yml解析器 -->
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.yaml</groupId>-->
<!-- <artifactId>snakeyaml</artifactId>-->
<!-- </dependency>-->
<!-- Token生成与解析-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.jsonwebtoken</groupId>-->
<!-- <artifactId>jjwt</artifactId>-->
<!-- </dependency>-->
<!-- Jaxb -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>javax.xml.bind</groupId>-->
<!-- <artifactId>jaxb-api</artifactId>-->
<!-- </dependency>-->
<!-- redis 缓存操作 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- pool 对象池 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-redis</artifactId>-->
<!-- </dependency>-->
<!-- 解析客户端操作系统、浏览器等 -->
<dependency>
<groupId>eu.bitwalker</groupId>
<artifactId>UserAgentUtils</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>eu.bitwalker</groupId>-->
<!-- <artifactId>UserAgentUtils</artifactId>-->
<!-- </dependency>-->
<!-- servlet包 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>it.ozimov</groupId>-->
<!-- <artifactId>embedded-redis</artifactId>-->
<!-- &lt;!&ndash; 不排除掉slf4j的话 会冲突&ndash;&gt;-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.slf4j</groupId>-->
<!-- <artifactId>slf4j-simple</artifactId>-->
<!-- </exclusion>-->
<!-- &lt;!&ndash; 排除掉guava依赖以本项目的guava依赖为准 &ndash;&gt;-->
<!-- <exclusion>-->
<!-- <groupId>com.google.guava</groupId>-->
<!-- <artifactId>guava</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>
<dependency>
<groupId>it.ozimov</groupId>
<artifactId>embedded-redis</artifactId>
<!-- 不排除掉slf4j的话 会冲突-->
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
<!-- 排除掉guava依赖以本项目的guava依赖为准 -->
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 多数据源 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.baomidou</groupId>-->
<!-- <artifactId>dynamic-datasource-spring-boot-starter</artifactId>-->
<!-- </dependency>-->
<!-- swagger注解 -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<!--ENC加密-->
<!-- <dependency>-->
<!-- <groupId>com.github.ulisesbocchio</groupId>-->
<!-- <artifactId>jasypt-spring-boot-starter</artifactId>-->
<!-- <version>2.1.1</version>-->
<!-- </dependency>-->
</dependencies>

View File

@@ -1,86 +0,0 @@
package com.agileboot.common.constant;
/**
* 通用常量信息
*
* @author valarchie
*/
public class Constants {
private Constants() {
}
public static final int KB = 1024;
public static final int MB = KB * 1024;
public static final int GB = MB * 1024;
/**
* http请求
*/
public static final String HTTP = "http://";
/**
* https请求
*/
public static final String HTTPS = "https://";
public static class Token {
private Token() {
}
/**
* 令牌前缀
*/
public static final String TOKEN_PREFIX = "Bearer ";
/**
* 令牌前缀
*/
public static final String LOGIN_USER_KEY = "login_user_key";
}
public static class Captcha {
private Captcha() {
}
/**
* 令牌
*/
public static final String MATH_TYPE = "math";
/**
* 令牌前缀
*/
public static final String CHAR_TYPE = "char";
}
/**
* 资源映射路径 前缀
*/
public static final String RESOURCE_PREFIX = "profile";
public static class UploadSubDir {
private UploadSubDir() {
}
public static final String IMPORT_PATH = "import";
public static final String AVATAR_PATH = "avatar";
public static final String DOWNLOAD_PATH = "download";
public static final String UPLOAD_PATH = "upload";
}
}

View File

@@ -1,46 +0,0 @@
package com.agileboot.common.core.base;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* Entity基类
*
* @author valarchie
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class BaseEntity<T extends Model<?>> extends Model<T> {
@ApiModelProperty("创建者ID")
@TableField(value = "creator_id", fill = FieldFill.INSERT)
private Long creatorId;
@ApiModelProperty("创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty("更新者ID")
@TableField(value = "updater_id", fill = FieldFill.UPDATE, updateStrategy = FieldStrategy.NOT_NULL)
private Long updaterId;
@ApiModelProperty("更新时间")
@TableField(value = "update_time", fill = FieldFill.UPDATE)
private Date updateTime;
/**
* deleted字段请在数据库中 设置为tinyInt 并且非null 默认值为0
*/
@ApiModelProperty("删除标志0代表存在 1代表删除")
@TableField("deleted")
@TableLogic
private Boolean deleted;
}

View File

@@ -1,62 +0,0 @@
package com.agileboot.common.core.dto;
import cn.hutool.core.util.StrUtil;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.common.exception.error.ErrorCodeInterface;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* 响应信息主体
*
* @author valarchie
*/
@Data
@AllArgsConstructor
public class ResponseDTO<T> {
private Integer code;
private String msg;
private T data;
public static <T> ResponseDTO<T> ok() {
return build(null, ErrorCode.SUCCESS);
}
public static <T> ResponseDTO<T> ok(T data) {
return build(data, ErrorCode.SUCCESS);
}
public static <T> ResponseDTO<T> fail() {
return build(null, ErrorCode.FAIL);
}
public static <T> ResponseDTO<T> fail(T data) {
return build(data, ErrorCode.FAIL);
}
public static <T> ResponseDTO<T> fail(ErrorCodeInterface code) {
return build(null, code);
}
public static <T> ResponseDTO<T> fail(ErrorCodeInterface code, Object... args) {
return build(null, code, args);
}
public static <T> ResponseDTO<T> fail(ApiException exception) {
return build(exception.getErrorCode().code(), exception.getMessage());
}
public static <T> ResponseDTO<T> build(T data, ErrorCodeInterface code, Object... args) {
return new ResponseDTO<>(code.code(), StrUtil.format(code.message(), args), data);
}
public static <T> ResponseDTO<T> build(Integer code, String msg) {
return new ResponseDTO<>(code, msg, null);
}
}

View File

@@ -1,38 +0,0 @@
package com.agileboot.common.core.page;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import lombok.Data;
/**
* 分页模型类
* @author valarchie
*/
@Data
public class PageDTO<T> {
/**
* 总记录数
*/
private Long total;
/**
* 列表数据
*/
private List<T> rows;
public PageDTO(List<T> list) {
this.rows = list;
this.total = (long) list.size();
}
public PageDTO(Page<T> page) {
this.rows = page.getRecords();
this.total = page.getTotal();
}
public PageDTO(List<T> list, Long count) {
this.rows = list;
this.total = count;
}
}

View File

@@ -1,66 +0,0 @@
package com.agileboot.common.exception;
import cn.hutool.core.util.StrUtil;
import com.agileboot.common.exception.error.ErrorCodeInterface;
import com.agileboot.common.utils.i18n.MessageUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
/**
* 统一异常类
* @author valarchie
*/
@EqualsAndHashCode(callSuper = true)
@Slf4j
@Data
public class ApiException extends RuntimeException{
protected ErrorCodeInterface errorCode;
protected String message;
protected Object[] args;
protected String formattedMessage;
protected String i18nFormattedMessage;
public ApiException(Throwable e, ErrorCodeInterface errorCode, Object... args) {
super(e);
fillErrorCode(errorCode, args);
}
public ApiException(ErrorCodeInterface errorCode, Object... args) {
fillErrorCode(errorCode, args);
}
public ApiException(ErrorCodeInterface errorCode) {
fillErrorCode(errorCode);
}
private void fillErrorCode(ErrorCodeInterface errorCode, Object... args) {
this.errorCode = errorCode;
this.message = errorCode.message();
this.args = args;
this.formattedMessage = StrUtil.format(this.message, args);
try {
this.i18nFormattedMessage = MessageUtils.message(errorCode.i18nKey(), args);
} catch (Exception e) {
log.error("could not found i18nMessage entry for key: " + errorCode.i18nKey());
}
}
@Override
public String getMessage() {
return i18nFormattedMessage != null ? i18nFormattedMessage : formattedMessage;
}
@Override
public String getLocalizedMessage() {
return i18nFormattedMessage;
}
}

View File

@@ -1,328 +0,0 @@
package com.agileboot.common.exception.error;
/**
* 错误码集合
*
* @author valarchie
*/
public enum ErrorCode implements ErrorCodeInterface {
/**
* 错误码集合
* 1~9999 为保留错误码 或者 常用错误码
* 10000~19999 为内部错误码
* 20000~29999 客户端错误码 (客户端异常调用之类的错误)
* 30000~39999 为第三方错误码 (代码正常,但是第三方异常)
* 40000~49999 为业务逻辑 错误码 (无异常,代码正常流转,并返回提示给用户)
* 由于系统内的错误码都是独一无二的所以错误码应该放在common包集中管理
*/
// -------------- 普通错误码 及保留错误码 ---------------
SUCCESS(0, "操作成功"),
FAIL(9999, "操作失败"),
UNKNOWN_ERROR(99999, "未知错误");
private final int code;
private final String msg;
ErrorCode(int code, String msg) {
this.code = code;
this.msg = msg;
}
@Override
public int code() {
return this.code;
}
@Override
public String message() {
return this.msg;
}
/**
* 40000~49999 为业务逻辑 错误码 (无代码异常,代码正常流转,并返回提示给用户)
*/
public enum Business implements ErrorCodeInterface {
// ----------------------------- Common --------------------------------------
OBJECT_NOT_FOUND(Module.COMMON, 1, "找不到ID为 {} 的 {}"),
UNSUPPORTED_OPERATION(Module.COMMON, 2, "不支持的操作"),
BULK_DELETE_IDS_IS_INVALID(Module.COMMON, 3, "批量参数ID列表为空"),
FILE_NOT_ALLOWED_TO_DOWNLOAD(Module.COMMON, 3, "文件名称({})非法,不允许下载"),
// ----------------------------- Permission -----------------------------------
FORBIDDEN_TO_MODIFY_ADMIN(Module.PERMISSION, 1, "不允许修改管理员的信息"),
NO_PERMISSION_TO_OPERATE(Module.PERMISSION, 2, "没有权限进行此操作,请联系管理员"),
// ----------------------------- Login -----------------------------------------
LOGIN_WRONG_USER_PASSWORD(Module.LOGIN, 1, "用户密码错误,请重输"),
LOGIN_ERROR(Module.LOGIN, 2, "登录失败:{}"),
LOGIN_CAPTCHA_CODE_WRONG(Module.LOGIN, 3, "验证码错误"),
LOGIN_CAPTCHA_CODE_EXPIRE(Module.LOGIN, 4, "验证码过期"),
LOGIN_CAPTCHA_CODE_NULL(Module.LOGIN, 5, "验证码为空"),
// ----------------------------- Upload -----------------------------------------
UPLOAD_FILE_TYPE_NOT_ALLOWED(Module.UPLOAD, 1, "不允许上传的文件类型,仅允许:{}"),
UPLOAD_FILE_NAME_EXCEED_MAX_LENGTH(Module.UPLOAD, 2, "文件名长度超过:{} "),
UPLOAD_FILE_SIZE_EXCEED_MAX_SIZE(Module.UPLOAD, 3, "文件名大小超过:{} MB"),
UPLOAD_IMPORT_EXCEL_FAILED(Module.UPLOAD, 4, "导入excel失败{}"),
UPLOAD_FILE_IS_EMPTY(Module.UPLOAD, 5, "上传文件为空"),
UPLOAD_FILE_FAILED(Module.UPLOAD, 6, "上传文件失败:{}"),
// ----------------------------- Config -----------------------------------------
CONFIG_VALUE_IS_NOT_ALLOW_TO_EMPTY(Module.CONFIG, 1, "参数键值不允许为空"),
CONFIG_VALUE_IS_NOT_IN_OPTIONS(Module.CONFIG, 2, "参数键值不存在列表中"),
// ------------------------------- Post --------------------------------------------
POST_NAME_IS_NOT_UNIQUE(Module.POST, 1, "岗位名称:{}, 已存在"),
POST_CODE_IS_NOT_UNIQUE(Module.POST, 2, "岗位编号:{}, 已存在"),
POST_ALREADY_ASSIGNED_TO_USER_CAN_NOT_BE_DELETED(Module.POST, 3, "职位已分配给用户,请先取消分配再删除"),
// ------------------------------- Dept ---------------------------------------------
DEPT_NAME_IS_NOT_UNIQUE(Module.DEPT, 1, "部门名称:{}, 已存在"),
DEPT_PARENT_ID_IS_NOT_ALLOWED_SELF(Module.DEPT, 2, "父级部门不能选择自己"),
DEPT_STATUS_ID_IS_NOT_ALLOWED_CHANGE(Module.DEPT, 3, "子部门还有正在启用的部门,暂时不能停用该部门"),
DEPT_EXIST_CHILD_DEPT_NOT_ALLOW_DELETE(Module.DEPT, 4, "该部门存在下级部门不允许删除"),
DEPT_EXIST_LINK_USER_NOT_ALLOW_DELETE(Module.DEPT, 5, "该部门存在关联的用户不允许删除"),
DEPT_PARENT_DEPT_NO_EXIST_OR_DISABLED(Module.DEPT, 6, "该父级部门不存在或已停用"),
// ------------------------------- Menu -------------------------------------------------
MENU_NAME_IS_NOT_UNIQUE(Module.MENU, 1, "新增菜单:{} 失败,菜单名称已存在"),
MENU_EXTERNAL_LINK_MUST_BE_HTTP(Module.MENU, 2, "菜单外链必须以 http(s)://开头"),
MENU_PARENT_ID_NOT_ALLOW_SELF(Module.MENU, 3, "父级菜单不能选择自身"),
MENU_EXIST_CHILD_MENU_NOT_ALLOW_DELETE(Module.MENU, 4, "存在子菜单不允许删除"),
MENU_ALREADY_ASSIGN_TO_ROLE_NOT_ALLOW_DELETE(Module.MENU, 5, "菜单已分配给角色,不允许"),
// -------------------------------- Role -------------------------------------------------
ROLE_NAME_IS_NOT_UNIQUE(Module.ROLE, 1, "角色名称:{}, 已存在"),
ROLE_KEY_IS_NOT_UNIQUE(Module.ROLE, 2, "角色标识:{}, 已存在"),
ROLE_DATA_SCOPE_DUPLICATED_DEPT(Module.ROLE, 3, "重复的部门id"),
ROLE_ALREADY_ASSIGN_TO_USER(Module.ROLE, 4, "角色已分配给用户,请先取消分配,再删除角色"),
ROLE_IS_NOT_AVAILABLE(Module.ROLE, 5, "角色:{} 已禁用,无法分配给用户"),
// ---------------------------------- User -----------------------------------------------
USER_NON_EXIST(Module.USER, 1, "登录用户:{} 不存在"),
USER_IS_DISABLE(Module.USER, 2, "对不起, 您的账号:{} 已停用"),
USER_CACHE_IS_EXPIRE(Module.USER, 3, "用户缓存信息已经过期"),
USER_FAIL_TO_GET_USER_ID(Module.USER, 3, "获取用户ID失败"),
USER_FAIL_TO_GET_DEPT_ID(Module.USER, 4, "获取用户部门ID失败"),
USER_FAIL_TO_GET_ACCOUNT(Module.USER, 5, "获取用户账户失败"),
USER_FAIL_TO_GET_USER_INFO(Module.USER, 6, "获取用户信息失败"),
USER_IMPORT_DATA_IS_NULL(Module.USER, 7, "导入的用户为空"),
USER_PHONE_NUMBER_IS_NOT_UNIQUE(Module.USER, 8, "该电话号码已被其他用户占用"),
USER_EMAIL_IS_NOT_UNIQUE(Module.USER, 9, "该邮件地址已被其他用户占用"),
USER_PASSWORD_IS_NOT_CORRECT(Module.USER, 10, "用户密码错误"),
USER_NEW_PASSWORD_IS_THE_SAME_AS_OLD(Module.USER, 11, "用户新密码与旧密码相同"),
USER_UPLOAD_FILE_FAILED(Module.USER, 12, "用户上传文件失败"),
USER_NAME_IS_NOT_UNIQUE(Module.USER, 13, "用户名已被其他用户占用"),
USER_CURRENT_USER_CAN_NOT_BE_DELETE(Module.USER, 14, "当前用户不允许被删除"),
USER_ADMIN_CAN_NOT_BE_MODIFY(Module.USER, 15, "管理员不允许做任何修改"),
;
private final int code;
private final String msg;
private static final int BASE_CODE = 40000;
Business(Module module, int code, String msg) {
this.code = BASE_CODE + module.code() + code;
this.msg = msg;
}
@Override
public int code() {
return this.code;
}
@Override
public String message() {
return this.msg;
}
}
/**
* 30000~39999是外部错误码 比如调用支付失败
*/
public enum External implements ErrorCodeInterface {
/**
* 支付宝调用失败
*/
FAIL_TO_PAY_ON_ALIPAY(Module.COMMON, 1, "支付宝调用失败");
private final int code;
private final String msg;
private static final int BASE_CODE = 30000;
External(Module module, int code, String msg) {
this.code = BASE_CODE + module.code() + code;
this.msg = msg;
}
@Override
public int code() {
return this.code;
}
@Override
public String message() {
return this.msg;
}
}
/**
* 20000~29999是客户端错误码
*/
public enum Client implements ErrorCodeInterface {
/**
* 客户端错误码
*/
COMMON_FORBIDDEN_TO_CALL(Module.COMMON, 1, "禁止调用"),
COMMON_REQUEST_TOO_OFTEN(Module.COMMON, 2, "调用太过频繁"),
COMMON_REQUEST_PARAMETERS_INVALID(Module.COMMON, 3, "请求参数异常,{}"),
COMMON_REQUEST_METHOD_INVALID(Module.COMMON, 4, "请求方式: {} 不支持"),
COMMON_REQUEST_RESUBMIT(Module.COMMON, 5, "请求重复提交"),
COMMON_NO_AUTHORIZATION(Module.PERMISSION, 1, "请求接口:{} 失败,用户未授权"),
;
private final int code;
private final String msg;
private static final int BASE_CODE = 20000;
Client(Module module, int code, String msg) {
this.code = BASE_CODE + module.code() + code;
this.msg = msg;
}
@Override
public int code() {
return this.code;
}
@Override
public String message() {
return this.msg;
}
}
/**
* 10000~19999是内部错误码 例如 框架有问题之类的
*/
public enum Internal implements ErrorCodeInterface {
/**
* 内部错误码
*/
INVALID_PARAMETER(Module.COMMON, 1, "参数异常:{}"),
UNKNOWN_ERROR(Module.COMMON, 2, "未知异常, 请查看系统日志"),
GET_ENUM_FAILED(Module.COMMON, 3, "获取枚举类型失败, 枚举类: {}"),
GET_CACHE_FAILED(Module.COMMON, 4, "获取缓存失败"),
INTERNAL_ERROR(Module.COMMON, 5, "系统内部错误:{}"),
LOGIN_CAPTCHA_GENERATE_FAIL(Module.LOGIN, 1, "验证码生成失败"),
INVALID_TOKEN(Module.PERMISSION, 1, "token异常"),
DB_INTERNAL_ERROR(Module.DB, 1, "数据库异常: {}"),
;
private final int code;
private final String msg;
private static final int BASE_CODE = 10000;
Internal(Module module, int code, String msg) {
this.code = BASE_CODE + module.code() + code;
this.msg = msg;
}
@Override
public int code() {
return this.code;
}
@Override
public String message() {
return this.msg;
}
}
}

View File

@@ -1,73 +0,0 @@
package com.agileboot.common.exception.error;
/**
* 系统内的模块
* @author valarchie
*/
public enum Module {
/**
* 普通模块
*/
COMMON(0),
/**
* 权限模块
*/
PERMISSION(1),
/**
* 登录模块
*/
LOGIN(2),
/**
* 数据库模块
*/
DB(3),
/**
* 上传
*/
UPLOAD(4),
/**
* 用户
*/
USER(5),
/**
* 配置
*/
CONFIG(6),
/**
* 职位
*/
POST(7),
/**
* 部门
*/
DEPT(8),
/**
* 菜单
*/
MENU(9),
/**
* 角色
*/
ROLE(10),
;
private final int code;
Module(int code) { this.code = code * 100; }
public int code() {return code; }
}

View File

@@ -1,29 +0,0 @@
package com.agileboot.common.core.exception;
import org.junit.Assert;
import org.junit.Test;
public class ApiExceptionTest {
@Test
public void testVarargsWithArrayArgs() {
String errorMsg = "these parameters are null: %s, %s, %s.";
Object[] array = new Object[] { "param1" , "param2" , "param3"};
String formatWithArray = String.format(errorMsg, array);
String formatWithVarargs = String.format(errorMsg, "param1", "param2", "param3");
Assert.assertEquals(formatWithVarargs, formatWithArray);
}
@Test
public void testVarargsWithNullArgs() {
String errorMsg = "these parameters are null: %s, %s, %s.";
String format = String.format(errorMsg, "param1", null, null);
Assert.assertEquals("these parameters are null: param1, null, null.", format);
}
}

View File

@@ -1,14 +0,0 @@
package com.agileboot.common.exception.error;
import com.agileboot.common.exception.error.ErrorCode.Client;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ErrorCodeInterfaceTest {
@Test
void testI18nKey() {
String i18nKey = Client.COMMON_FORBIDDEN_TO_CALL.i18nKey();
Assertions.assertEquals("20001_COMMON_FORBIDDEN_TO_CALL", i18nKey);
}
}

View File

@@ -1,119 +0,0 @@
package com.agileboot.common.utils.file;
import cn.hutool.core.util.StrUtil;
import com.agileboot.common.config.AgileBootConfig;
import com.agileboot.common.constant.Constants.UploadSubDir;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode.Business;
import com.agileboot.common.exception.error.ErrorCode.Internal;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.web.multipart.MultipartFile;
class FileUploadUtilsTest {
@Test
void testIsAllowedExtension() {
String[] imageTypes = new String[]{"img", "gif"};
boolean isAllow = FileUploadUtils.isExtensionAllowed("img", imageTypes);
boolean isNotAllow = FileUploadUtils.isExtensionAllowed("png", imageTypes);
Assertions.assertTrue(isAllow);
Assertions.assertFalse(isNotAllow);
}
@Test
void testIsAllowedExtensionWhenNull() {
String[] imageTypes = null;
boolean isAllow = FileUploadUtils.isExtensionAllowed("img", imageTypes);
Assertions.assertTrue(isAllow);
}
@Test
void testGetRelativeFileUrl() {
String relativeFilePath = FileUploadUtils.getRelativeFileUrl(UploadSubDir.UPLOAD_PATH, "test.jpg");
Assertions.assertEquals("/profile/upload/test.jpg", relativeFilePath);
}
@Test
void testSaveFileToLocal() {
MultipartFile fileMock = Mockito.mock(MultipartFile.class);
ApiException exceptionWithNullSubDir = Assertions.assertThrows(ApiException.class,
() -> FileUploadUtils.saveFileToLocal(fileMock, "", ""));
ApiException exceptionWitEmptyFileName = Assertions.assertThrows(ApiException.class,
() -> FileUploadUtils.saveFileToLocal(fileMock, "", ""));
Assertions.assertEquals(Internal.INVALID_PARAMETER, exceptionWithNullSubDir.getErrorCode());
Assertions.assertEquals(Internal.INVALID_PARAMETER, exceptionWitEmptyFileName.getErrorCode());
}
@Test
void testIsAllowedUploadWhenFileNameTooLong() {
MultipartFile fileMock = Mockito.mock(MultipartFile.class);
String longFileName = "this is a very very long sentence, this is a very very long sentence, "
+ "this is a very very long sentence, this is a very very long sentence, ";
Mockito.when(fileMock.getOriginalFilename()).thenReturn(longFileName);
ApiException exception = Assertions.assertThrows(ApiException.class,
() -> FileUploadUtils.isAllowedUpload(fileMock, null));
Assertions.assertEquals(Business.UPLOAD_FILE_NAME_EXCEED_MAX_LENGTH, exception.getErrorCode());
}
@Test
void testIsAllowedUploadWhenFileTooBig() {
MultipartFile fileMock = Mockito.mock(MultipartFile.class);
Mockito.when(fileMock.getOriginalFilename()).thenReturn("test.jpg");
Mockito.when(fileMock.getSize()).thenReturn(FileUploadUtils.MAX_FILE_SIZE + 1);
ApiException exception = Assertions.assertThrows(ApiException.class,
() -> FileUploadUtils.isAllowedUpload(fileMock, null));
Assertions.assertEquals(Business.UPLOAD_FILE_SIZE_EXCEED_MAX_SIZE, exception.getErrorCode());
}
@Test
void testisAllowDownload() {
Assertions.assertFalse(FileUploadUtils.isAllowDownload("../test.jpg"));
Assertions.assertFalse(FileUploadUtils.isAllowDownload("../test.exe"));
}
@Test
void testGetFileExtension() {
MultipartFile fileMock = Mockito.mock(MultipartFile.class);
Mockito.when(fileMock.getOriginalFilename()).thenReturn("test.jpg");
String fileExtension = FileUploadUtils.getFileExtension(fileMock);
Assertions.assertEquals("jpg", fileExtension);
}
@Test
void testGenerateFilename() {
String fileName = "test.jpg";
MultipartFile fileMock = Mockito.mock(MultipartFile.class);
Mockito.when(fileMock.getOriginalFilename()).thenReturn(fileName);
String randomFileName = FileUploadUtils.generateFilename(fileMock);
String[] nameParts = randomFileName.split("_");
Assertions.assertEquals("test", nameParts[1]);
Assertions.assertTrue(StrUtil.endWith(nameParts[2], ".jpg"));
}
@Test
void getFileAbsolutePath() {
AgileBootConfig agileBootConfig = new AgileBootConfig();
agileBootConfig.setFileBaseDir("D:\\agileboot");
String fileAbsolutePath = FileUploadUtils.getFileAbsolutePath(UploadSubDir.AVATAR_PATH, "test.jpg");
Assertions.assertEquals("D:\\agileboot\\profile\\avatar\\test.jpg", fileAbsolutePath);
}
}

View File

@@ -1,65 +0,0 @@
package com.agileboot.common.utils.ip;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class IpRegionUtilTest {
@Test
void testGetIpRegion() {
IpRegion ipRegion = IpRegionUtil.getIpRegion("110.81.189.80");
Assertions.assertEquals("中国", ipRegion.getCountry());
Assertions.assertEquals("福建省", ipRegion.getProvince());
Assertions.assertEquals("泉州市", ipRegion.getCity());
}
@Test
void testGetIpRegionWhenLocalHost() {
IpRegion ipRegion = IpRegionUtil.getIpRegion("127.0.0.1");
Assertions.assertEquals("内网IP", ipRegion.briefLocation());
}
@Test
void testGetIpRegionWithIpv6() {
IpRegion ipRegion = IpRegionUtil.getIpRegion("2001:0DB8:0000:0023:0008:0800:200C:417A");
Assertions.assertNotNull(ipRegion);
Assertions.assertNull(ipRegion.getCountry());
Assertions.assertEquals("未知 未知", ipRegion.briefLocation());
}
@Test
void testGetIpRegionWithEmpty() {
IpRegion ipRegion = IpRegionUtil.getIpRegion("");
Assertions.assertNotNull(ipRegion);
Assertions.assertNull(ipRegion.getCountry());
Assertions.assertEquals("未知 未知", ipRegion.briefLocation());
}
@Test
void testGetIpRegionWithNull() {
IpRegion ipRegion = IpRegionUtil.getIpRegion(null);
Assertions.assertNotNull(ipRegion);
Assertions.assertNull(ipRegion.getCountry());
Assertions.assertEquals("未知 未知", ipRegion.briefLocation());
}
@Test
void testGetIpRegionWithWrongIpString() {
IpRegion ipRegion = IpRegionUtil.getIpRegion("xsdfwefsfsd");
Assertions.assertNotNull(ipRegion);
Assertions.assertNull(ipRegion.getCountry());
Assertions.assertEquals("未知 未知", ipRegion.briefLocation());
}
@Test
void getBriefLocationByIp() {
String briefLocationByIp = IpRegionUtil.getBriefLocationByIp("110.81.189.80");
Assertions.assertEquals("福建省 泉州市", briefLocationByIp);
}
}

View File

@@ -1,41 +0,0 @@
package com.agileboot.common.utils.ip;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class IpUtilTest {
@Test
void isInnerIp() {
boolean innerIp1 = IpUtil.isLocalHost("127.0.0.1");
boolean innerIp2 = IpUtil.isLocalHost("0:0:0:0:0:0:0:1");
boolean innerIp3 = IpUtil.isLocalHost("localhost");
boolean innerIp4 = IpUtil.isLocalHost("192.168.1.1");
boolean innerIp5 = IpUtil.isLocalHost("10.32.1.1");
boolean innerIp6 = IpUtil.isLocalHost("172.16.1.1");
boolean notInnerIP = IpUtil.isLocalHost("110.81.189.80");
Assertions.assertTrue(innerIp1);
Assertions.assertTrue(innerIp2);
Assertions.assertTrue(innerIp3);
Assertions.assertTrue(innerIp4);
Assertions.assertTrue(innerIp5);
Assertions.assertTrue(innerIp6);
Assertions.assertFalse(notInnerIP);
}
@Test
void isLocalHost() {
boolean localHost1 = IpUtil.isLocalHost("127.0.0.1");
boolean localHost2 = IpUtil.isLocalHost("0:0:0:0:0:0:0:1");
boolean localHost4 = IpUtil.isLocalHost("localhost");
boolean notLocalHost = IpUtil.isLocalHost("110.81.189.80");
Assertions.assertTrue(localHost1);
Assertions.assertTrue(localHost2);
Assertions.assertTrue(localHost4);
Assertions.assertFalse(notLocalHost);
}
}

View File

@@ -1,52 +0,0 @@
package com.agileboot.common.utils.ip;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class OfflineIpRegionUtilTest {
@Test
void testGetIpRegionWhenIpv4() {
IpRegion ipRegion = OfflineIpRegionUtil.getIpRegion("110.81.189.80");
Assertions.assertEquals("中国", ipRegion.getCountry());
Assertions.assertEquals("福建省", ipRegion.getProvince());
Assertions.assertEquals("泉州市", ipRegion.getCity());
}
@Test
void testGetIpRegionWithIpv6() {
IpRegion region = Assertions.assertDoesNotThrow(() ->
OfflineIpRegionUtil.getIpRegion("2001:0DB8:0000:0023:0008:0800:200C:417A")
);
Assertions.assertNull(region);
}
@Test
void testGetIpRegionWithEmpty() {
IpRegion region = Assertions.assertDoesNotThrow(() ->
OfflineIpRegionUtil.getIpRegion("")
);
Assertions.assertNull(region);
}
@Test
void testGetIpRegionWithNull() {
IpRegion region = Assertions.assertDoesNotThrow(() ->
OfflineIpRegionUtil.getIpRegion(null)
);
Assertions.assertNull(region);
}
@Test
void testGetIpRegionWithWrongIpString() {
IpRegion region = Assertions.assertDoesNotThrow(() ->
OfflineIpRegionUtil.getIpRegion("asfdsfdsff")
);
Assertions.assertNull(region);
}
}

View File

@@ -1,63 +0,0 @@
package com.agileboot.common.utils.ip;
import com.agileboot.common.config.AgileBootConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class OnlineIpRegionUtilTest {
@BeforeEach
public void enableOnlineAddressQuery() {
AgileBootConfig agileBootConfig = new AgileBootConfig();
agileBootConfig.setAddressEnabled(true);
}
@Test
void getIpRegionWithIpv6() {
IpRegion region = Assertions.assertDoesNotThrow(() ->
OnlineIpRegionUtil.getIpRegion("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789")
);
Assertions.assertNull(region);
}
@Test
void getIpRegionWithIpv4() {
IpRegion ipRegion = OnlineIpRegionUtil.getIpRegion("120.42.247.130");
Assertions.assertEquals("福建省", ipRegion.getProvince());
Assertions.assertEquals("泉州市", ipRegion.getCity());
}
@Test
void getIpRegionWithEmpty() {
IpRegion region = Assertions.assertDoesNotThrow(() ->
OnlineIpRegionUtil.getIpRegion("")
);
Assertions.assertNull(region);
}
@Test
void getIpRegionWithNull() {
IpRegion region = Assertions.assertDoesNotThrow(() ->
OnlineIpRegionUtil.getIpRegion(null)
);
Assertions.assertNull(region);
}
@Test
void getIpRegionWithWrongIpString() {
IpRegion region = Assertions.assertDoesNotThrow(() ->
OnlineIpRegionUtil.getIpRegion("seffsdfsdf")
);
Assertions.assertNull(region);
}
}

View File

@@ -1,61 +0,0 @@
package com.agileboot.common.utils.jackson;
import cn.hutool.core.date.DateUtil;
import java.math.BigDecimal;
import java.math.BigInteger;
import org.junit.Assert;
import org.junit.Test;
/**
* @author duanxinyuan 2019/1/21 18:17
*/
public class JacksonUtilTest {
@Test
public void testObjectToJson() {
Person person = Person.newPerson();
String jacksonStr = JacksonUtil.to(person);
Assert.assertEquals(DateUtil.formatDateTime(person.getDate()), JacksonUtil.getAsString(jacksonStr, "date"));
Assert.assertEquals(DateUtil.formatLocalDateTime(person.getLocalDateTime()),
JacksonUtil.getAsString(jacksonStr, "localDateTime"));
Assert.assertEquals(person.getName(), JacksonUtil.getAsString(jacksonStr, "name"));
Assert.assertEquals(person.getAge(), JacksonUtil.getAsInt(jacksonStr, "age"));
Assert.assertEquals(person.isMan(), JacksonUtil.getAsBoolean(jacksonStr, "man"));
Assert.assertEquals(person.getMoney(), JacksonUtil.getAsBigDecimal(jacksonStr, "money"));
Assert.assertEquals(person.getTrait(), JacksonUtil.getAsList(jacksonStr, "trait", String.class));
Assert.assertNotNull(JacksonUtil.getAsString(jacksonStr, "name"));
}
/**
* 测试兼容情况
*/
@Test
public void testAllPrimitiveTypeToJson() {
String json = "{\n"
+ "\"code\": \"200\",\n"
+ "\"id\": \"2001215464647687987\",\n"
+ "\"message\": \"success\",\n"
+ "\"amount\": \"1.12345\",\n"
+ "\"amount1\": \"0.12345\",\n"
+ "\"isSuccess\": \"true\",\n"
+ "\"isSuccess1\": \"1\",\n"
+ "\"key\": \"8209167202090377654857374178856064487200234961995543450245362822537162918731039965956758726661669012305745755921310000297396309887550627402157318910581311\"\n"
+ "}";
Assert.assertEquals(200, JacksonUtil.getAsInt(json, "code"));
Assert.assertEquals(2001215464647687987L,JacksonUtil.getAsLong(json, "id"));
Assert.assertEquals("success", JacksonUtil.getAsString(json, "message"));
Assert.assertEquals(new BigDecimal("1.12345"), JacksonUtil.getAsBigDecimal(json, "amount"));
Assert.assertEquals(new BigDecimal("0.12345"), JacksonUtil.getAsBigDecimal(json, "amount1"));
Assert.assertEquals(1.12345d, JacksonUtil.getAsDouble(json, "amount"), 0.00001);
Assert.assertEquals(0.12345d, JacksonUtil.getAsDouble(json, "amount1"), 0.00001);
Assert.assertTrue(JacksonUtil.getAsBoolean(json, "isSuccess"));
Assert.assertTrue(JacksonUtil.getAsBoolean(json, "isSuccess1"));
Assert.assertEquals(new BigInteger(
"8209167202090377654857374178856064487200234961995543450245362822537162918731039965956758726661669012305745755921310000297396309887550627402157318910581311"),
JacksonUtil.getAsBigInteger(json, "key"));
Assert.assertEquals("1", JacksonUtil.getAsString(json, "isSuccess1"));
}
}

View File

@@ -1,42 +0,0 @@
package com.agileboot.common.utils.jackson;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import lombok.Data;
/**
* @author duanxinyuan
* 2018/6/29 14:17
*/
@Data
public class Person {
public String name;
public Date date;
public LocalDateTime localDateTime;
public int age;
public BigDecimal money;
public boolean man;
public ArrayList<String> trait;
public HashMap<String, String> cards;
public static Person newPerson() {
Person person = new Person();
person.name = "张三";
person.date = new Date();
person.localDateTime = LocalDateTime.now();
person.age = 100;
person.money = BigDecimal.valueOf(500.21);
person.man = true;
person.trait = new ArrayList<>();
person.trait.add("淡然");
person.trait.add("温和");
person.cards = new HashMap<>();
person.cards.put("身份证", "4a6d456as");
person.cards.put("建行卡", "649874545");
return person;
}
}

View File

@@ -1,40 +0,0 @@
package com.agileboot.common.utils.poi;
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HtmlUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class CustomExcelUtilTest {
@Test
void testImportAndExport() {
PostDTO post1 = new PostDTO(1L, "admin1", "管理员1", "1", "无备注", "1", "正常");
PostDTO post2 = new PostDTO(2L, "admin2", "管理员2<script>alert(1)</script>", "2", "无备注", "1", "正常");
List<PostDTO> postDTOList = new ArrayList<>();
postDTOList.add(post1);
postDTOList.add(post2);
File file = FileUtil.createTempFile();
CustomExcelUtil.writeToOutputStream(postDTOList, PostDTO.class, FileUtil.getOutputStream(file));
List<PostDTO> postListFromExcel = CustomExcelUtil.readFromInputStream(PostDTO.class, FileUtil.getInputStream(file));
PostDTO post1fromExcel = postListFromExcel.get(0);
PostDTO post2fromExcel = postListFromExcel.get(1);
Assertions.assertEquals(post1.getPostId(), post1fromExcel.getPostId());
Assertions.assertEquals(post1.getPostCode(), post1fromExcel.getPostCode());
Assertions.assertEquals(post2.getPostId(), post2fromExcel.getPostId());
Assertions.assertEquals(post2.getPostCode(), post2fromExcel.getPostCode());
// 检查脚本注入的字符串是否被去除
Assertions.assertNotEquals(post2.getPostName(), post2fromExcel.getPostName());
Assertions.assertEquals(HtmlUtil.cleanHtmlTag(post2.getPostName()), post2fromExcel.getPostName());
}
}

View File

@@ -1,37 +0,0 @@
package com.agileboot.common.utils.poi;
import com.agileboot.common.annotation.ExcelColumn;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
@EqualsAndHashCode
public class PostDTO {
@ExcelColumn(name = "岗位ID")
private Long postId;
@ExcelColumn(name = "岗位编码")
private String postCode;
@ExcelColumn(name = "岗位名称")
private String postName;
@ExcelColumn(name = "岗位排序")
private String postSort;
@ExcelColumn(name = "备注")
private String remark;
private String status;
@ExcelColumn(name = "状态")
private String statusStr;
}

View File

@@ -1,46 +0,0 @@
package com.agileboot.common.utils.time;
import java.util.Calendar;
import java.util.Date;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class DatePickUtilTest {
@Test
void testGetBeginOfTheDay() {
Date beginOfTheDay = DatePickUtil.getBeginOfTheDay(new Date());
Calendar instance = Calendar.getInstance();
instance.setTime(beginOfTheDay);
Assertions.assertEquals(0, instance.get(Calendar.HOUR));
Assertions.assertEquals(0, instance.get(Calendar.MINUTE));
Assertions.assertEquals(0, instance.get(Calendar.SECOND));
}
@Test
void testGetBeginOfTheDayWhenNull() {
Assertions.assertDoesNotThrow(() -> DatePickUtil.getBeginOfTheDay(null)
);
}
@Test
void testGetEndOfTheDay() {
Date endOfTheDay = DatePickUtil.getEndOfTheDay(new Date());
Calendar instance = Calendar.getInstance();
instance.setTime(endOfTheDay);
Assertions.assertEquals(23, instance.get(Calendar.HOUR_OF_DAY));
Assertions.assertEquals(59, instance.get(Calendar.MINUTE));
Assertions.assertEquals(59, instance.get(Calendar.SECOND));
}
@Test
void testGetEndOfTheDayWhenNull() {
Assertions.assertDoesNotThrow(() -> DatePickUtil.getEndOfTheDay(null)
);
}
}

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-box</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<properties>
<revision>1.0.0</revision>
</properties>
<dependencyManagement>
<dependencies>
<!-- 核心模块 -->
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-core</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-doc</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-mybatis</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-redis</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-web</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-json</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.agileboot</groupId>
<artifactId>agileboot-common</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>wol-common-core</artifactId>
<dependencies>
<!-- Spring框架基本的核心工具 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<!-- servlet包 -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
<!-- SpringWeb模块 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- pool 对象池 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<!-- 自定义验证注解 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
</dependency>
<!-- excel工具 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<!-- io常用工具类 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<!--常用工具类 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<!-- swagger注解 -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -1,4 +1,4 @@
package com.agileboot.common.annotation;
package com.agileboot.common.core.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@@ -1,4 +1,4 @@
package com.agileboot.common.annotation;
package com.agileboot.common.core.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@@ -1,6 +1,6 @@
package com.agileboot.common.config;
package com.agileboot.common.core.config;
import com.agileboot.common.constant.Constants;
import com.agileboot.common.core.constant.Constants;
import java.io.File;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -8,7 +8,7 @@ import org.springframework.stereotype.Component;
/**
* 读取项目相关配置
*
* TODO 移走 不合适放在这里common包底下
* @author valarchie
*/
@Component
@@ -56,7 +56,7 @@ public class AgileBootConfig {
*/
private static String rsaPrivateKey;
private static String apiDocsPathPrefix;
private static String apiPrefix;
public static String getFileBaseDir() {
return fileBaseDir;
@@ -66,12 +66,12 @@ public class AgileBootConfig {
AgileBootConfig.fileBaseDir = fileBaseDir + File.separator + Constants.RESOURCE_PREFIX;
}
public static String getApiDocsPathPrefix() {
return apiDocsPathPrefix;
public static String getApiPrefix() {
return apiPrefix;
}
public void setApiDocsPathPrefix(String apiDocsPathPrefix) {
AgileBootConfig.apiDocsPathPrefix = apiDocsPathPrefix;
public void setApiPrefix(String apiDocsPathPrefix) {
AgileBootConfig.apiPrefix = apiDocsPathPrefix;
}
public static boolean isAddressEnabled() {

View File

@@ -0,0 +1,85 @@
package com.agileboot.common.core.constant;
/**
* 通用常量信息
*
* @author ruoyi
*/
public interface Constants {
int KB = 1024;
int MB = KB * 1024;
int GB = MB * 1024;
/**
* 资源映射路径 前缀
*/
String RESOURCE_PREFIX = "profile";
/**
* UTF-8 字符集
*/
String UTF8 = "UTF-8";
/**
* GBK 字符集
*/
String GBK = "GBK";
/**
* www主域
*/
String WWW = "www.";
/**
* http请求
*/
String HTTP = "http://";
/**
* https请求
*/
String HTTPS = "https://";
/**
* 通用成功标识
*/
String SUCCESS = "0";
/**
* 通用失败标识
*/
String FAIL = "1";
/**
* 登录成功
*/
String LOGIN_SUCCESS = "Success";
/**
* 注销
*/
String LOGOUT = "Logout";
/**
* 注册
*/
String REGISTER = "Register";
/**
* 登录失败
*/
String LOGIN_FAIL = "Error";
/**
* 验证码有效期(分钟)
*/
Integer CAPTCHA_EXPIRATION = 2;
/**
* 顶级部门id
*/
Long TOP_PARENT_ID = 0L;
}

View File

@@ -0,0 +1,93 @@
package com.agileboot.common.core.constant;
/**
* 返回状态码
*
* @author Lion Li
*/
public interface HttpStatus {
/**
* 操作成功
*/
int SUCCESS = 200;
/**
* 对象创建成功
*/
int CREATED = 201;
/**
* 请求已经被接受
*/
int ACCEPTED = 202;
/**
* 操作已经执行成功,但是没有返回数据
*/
int NO_CONTENT = 204;
/**
* 资源已被移除
*/
int MOVED_PERM = 301;
/**
* 重定向
*/
int SEE_OTHER = 303;
/**
* 资源没有被修改
*/
int NOT_MODIFIED = 304;
/**
* 参数列表错误(缺少,格式不匹配)
*/
int BAD_REQUEST = 400;
/**
* 未授权
*/
int UNAUTHORIZED = 401;
/**
* 访问受限,授权过期
*/
int FORBIDDEN = 403;
/**
* 资源,服务未找到
*/
int NOT_FOUND = 404;
/**
* 不允许的http方法
*/
int BAD_METHOD = 405;
/**
* 资源冲突,或者资源被锁
*/
int CONFLICT = 409;
/**
* 不支持的数据,媒体类型
*/
int UNSUPPORTED_TYPE = 415;
/**
* 系统内部错误
*/
int ERROR = 500;
/**
* 接口未实现
*/
int NOT_IMPLEMENTED = 501;
/**
* 系统警告消息
*/
int WARN = 601;
}

View File

@@ -0,0 +1,120 @@
package com.agileboot.common.core.core;
import com.agileboot.common.core.constant.HttpStatus;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
/**
* 响应信息主体
*
* @author Lion Li
*/
@Data
@NoArgsConstructor
public class R<T> implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 成功
*/
public static final int SUCCESS = 200;
/**
* 失败
*/
public static final int FAIL = 500;
/**
* 消息状态码
*/
private int code;
/**
* 消息内容
*/
private String msg;
/**
* 数据对象
*/
private T data;
public static <T> R<T> ok() {
return restResult(null, SUCCESS, "操作成功");
}
public static <T> R<T> ok(T data) {
return restResult(data, SUCCESS, "操作成功");
}
public static <T> R<T> ok(String msg) {
return restResult(null, SUCCESS, msg);
}
public static <T> R<T> ok(String msg, T data) {
return restResult(data, SUCCESS, msg);
}
public static <T> R<T> fail() {
return restResult(null, FAIL, "操作失败");
}
public static <T> R<T> fail(String msg) {
return restResult(null, FAIL, msg);
}
public static <T> R<T> fail(T data) {
return restResult(data, FAIL, "操作失败");
}
public static <T> R<T> fail(String msg, T data) {
return restResult(data, FAIL, msg);
}
public static <T> R<T> fail(int code, String msg) {
return restResult(null, code, msg);
}
/**
* 返回警告消息
*
* @param msg 返回内容
* @return 警告消息
*/
public static <T> R<T> warn(String msg) {
return restResult(null, HttpStatus.WARN, msg);
}
/**
* 返回警告消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 警告消息
*/
public static <T> R<T> warn(String msg, T data) {
return restResult(data, HttpStatus.WARN, msg);
}
private static <T> R<T> restResult(T data, int code, String msg) {
R<T> r = new R<>();
r.setCode(code);
r.setData(data);
r.setMsg(msg);
return r;
}
public static <T> Boolean isError(R<T> ret) {
return !isSuccess(ret);
}
public static <T> Boolean isSuccess(R<T> ret) {
return R.SUCCESS == ret.getCode();
}
}

View File

@@ -1,4 +1,4 @@
package com.agileboot.common.core.base;
package com.agileboot.common.core.core.base;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;

View File

@@ -1,4 +1,4 @@
package com.agileboot.orm.common.interfaces;
package com.agileboot.common.core.enums;
/**
* @author valarchie

View File

@@ -1,9 +1,9 @@
package com.agileboot.orm.common.util;
package com.agileboot.common.core.enums;
import cn.hutool.core.convert.Convert;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.orm.common.interfaces.BasicEnum;
import com.agileboot.common.core.exception.ApiException;
import com.agileboot.common.core.exception.error.ErrorCode;
import com.agileboot.common.core.enums.BasicEnum;
import java.util.Objects;

View File

@@ -1,4 +1,4 @@
package com.agileboot.orm.common.interfaces;
package com.agileboot.common.core.enums;
/**
* 字典类型 接口

View File

@@ -1,23 +1,23 @@
package com.agileboot.orm.common.enums;
package com.agileboot.common.core.enums.common;
import com.agileboot.orm.common.CssTag;
import com.agileboot.orm.common.annotations.Dictionary;
import com.agileboot.orm.common.interfaces.DictionaryEnum;
import com.agileboot.common.core.enums.dictionary.CssTag;
import com.agileboot.common.core.enums.dictionary.Dictionary;
import com.agileboot.common.core.enums.DictionaryEnum;
/**
* 对应sys_operation_log的business_type
*
* @author valarchie
*/
@Dictionary(name = "sys_operation_type")
@Dictionary(name = "sysOperationLog.businessType")
public enum BusinessTypeEnum implements DictionaryEnum<Integer> {
/**
* 操作类型
*/
OTHER(0, "其他操作", CssTag.INFO),
ADD(1, "添加", CssTag.INFO),
MODIFY(2, "修改", CssTag.INFO),
ADD(1, "添加", CssTag.PRIMARY),
MODIFY(2, "修改", CssTag.PRIMARY),
DELETE(3, "删除", CssTag.DANGER),
GRANT(4, "授权", CssTag.PRIMARY),
EXPORT(5, "导出", CssTag.WARNING),

View File

@@ -1,6 +1,6 @@
package com.agileboot.orm.common.enums;
package com.agileboot.common.core.enums.common;
import com.agileboot.orm.common.interfaces.BasicEnum;
import com.agileboot.common.core.enums.BasicEnum;
/**
* 系统配置

Some files were not shown because too many files have changed in this diff Show More