├── .gitignore
├── LICENSE
├── README.md
├── restaurant.sql
├── restaurantServer
├── .gitignore
├── .idea
│ ├── .name
│ ├── codeStyles
│ │ ├── Project.xml
│ │ └── codeStyleConfig.xml
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── google-java-format.xml
│ ├── inspectionProfiles
│ │ └── Project_Default.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ ├── restaurantServer.iml
│ ├── saveactions_settings.xml
│ └── vcs.xml
├── Dockerfile
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── ikarosx
│ │ └── restaurant
│ │ ├── RestaurantApplication.java
│ │ ├── aspect
│ │ ├── AdminAspect.java
│ │ ├── IsOwner.java
│ │ ├── NeedAdmin.java
│ │ ├── OwnerAspect.java
│ │ ├── PreAuthorizaAspect.java
│ │ └── PreAuthorize.java
│ │ ├── config
│ │ ├── Swagger2Configuration.java
│ │ └── TomcatConfiguration.java
│ │ ├── controller
│ │ ├── MenuController.java
│ │ ├── MenuTypeController.java
│ │ ├── OrderController.java
│ │ ├── OrderDetailController.java
│ │ ├── UserController.java
│ │ └── impl
│ │ │ ├── MenuControllerImpl.java
│ │ │ ├── MenuTypeControllerImpl.java
│ │ │ ├── OrderControllerImpl.java
│ │ │ ├── OrderDetailControllerImpl.java
│ │ │ └── UserControllerImpl.java
│ │ ├── dao
│ │ ├── MenuRepository.java
│ │ ├── MenuTypeRepository.java
│ │ ├── OrderDetailRepository.java
│ │ ├── OrderRepository.java
│ │ └── UserRepository.java
│ │ ├── entity
│ │ ├── Menu.java
│ │ ├── MenuType.java
│ │ ├── Order.java
│ │ ├── OrderDetail.java
│ │ ├── User.java
│ │ ├── jpa
│ │ │ ├── Delete.java
│ │ │ ├── Get.java
│ │ │ ├── Insert.java
│ │ │ └── Update.java
│ │ └── query
│ │ │ ├── MenuQueryParam.java
│ │ │ ├── MenuTypeQueryParam.java
│ │ │ ├── OrderDetailQueryParam.java
│ │ │ ├── OrderQueryParam.java
│ │ │ ├── PostOrder.java
│ │ │ └── UserQueryParam.java
│ │ ├── exception
│ │ ├── CommonCodeEnum.java
│ │ ├── CustomException.java
│ │ ├── ExceptionCast.java
│ │ ├── ExceptionCatch.java
│ │ └── ResponseResult.java
│ │ ├── filter
│ │ ├── AuthorizationFilter.java
│ │ └── CorsFilter.java
│ │ ├── service
│ │ ├── MenuService.java
│ │ ├── MenuTypeService.java
│ │ ├── OrderDetailService.java
│ │ ├── OrderService.java
│ │ ├── SecurityService.java
│ │ ├── UserService.java
│ │ └── impl
│ │ │ ├── MenuServiceImpl.java
│ │ │ ├── MenuTypeServiceImpl.java
│ │ │ ├── OrderDetailServiceImpl.java
│ │ │ ├── OrderServiceImpl.java
│ │ │ ├── SecurityServiceImpl.java
│ │ │ └── UserServiceImpl.java
│ │ └── util
│ │ ├── AuthorizationUtils.java
│ │ └── SessionUtils.java
│ └── resources
│ ├── application-template.yaml
│ └── application.yaml
└── restaurantui
├── .browserslistrc
├── .gitignore
├── README.md
├── babel.config.js
├── package.json
├── public
├── favicon.ico
└── index.html
├── src
├── App.vue
├── assets
│ └── logo.png
├── base
│ ├── api
│ │ ├── login.js
│ │ ├── menu.js
│ │ └── public.js
│ ├── components
│ │ └── snackbar
│ │ │ ├── Snackbar.vue
│ │ │ └── index.js
│ └── config
│ │ ├── router.js
│ │ └── system.js
├── components
│ ├── addMenu.vue
│ ├── login.vue
│ ├── menu.vue
│ └── orderHistory.vue
├── main.js
├── plugins
│ └── vuetify.js
└── router
│ └── index.js
├── vue.config.js
├── webpack.config.js
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Maven template
3 | target/
4 | pom.xml.tag
5 | pom.xml.releaseBackup
6 | pom.xml.versionsBackup
7 | pom.xml.next
8 | release.properties
9 | dependency-reduced-pom.xml
10 | buildNumber.properties
11 | .mvn/timing.properties
12 | .mvn/wrapper/maven-wrapper.jar
13 |
14 | ### JetBrains template
15 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
16 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
17 |
18 | # User-specific stuff
19 | .idea/**/workspace.xml
20 | .idea/**/tasks.xml
21 | .idea/**/usage.statistics.xml
22 | .idea/**/dictionaries
23 | .idea/**/shelf
24 |
25 | # Generated files
26 | .idea/**/contentModel.xml
27 |
28 | # Sensitive or high-churn files
29 | .idea/**/dataSources/
30 | .idea/**/dataSources.ids
31 | .idea/**/dataSources.local.xml
32 | .idea/**/sqlDataSources.xml
33 | .idea/**/dynamic.xml
34 | .idea/**/uiDesigner.xml
35 | .idea/**/dbnavigator.xml
36 |
37 | # Gradle
38 | .idea/**/gradle.xml
39 | .idea/**/libraries
40 | .idea
41 | *.iml
42 | # Gradle and Maven with auto-import
43 | # When using Gradle or Maven with auto-import, you should exclude module files,
44 | # since they will be recreated, and may cause churn. Uncomment if using
45 | # auto-import.
46 | # .idea/modules.xml
47 | # .idea/*.iml
48 | # .idea/modules
49 | # *.iml
50 | # *.ipr
51 |
52 | # CMake
53 | cmake-build-*/
54 |
55 | # Mongo Explorer plugin
56 | .idea/**/mongoSettings.xml
57 |
58 | # File-based project format
59 | *.iws
60 |
61 | # IntelliJ
62 | out/
63 |
64 | # mpeltonen/sbt-idea plugin
65 | .idea_modules/
66 |
67 | # JIRA plugin
68 | atlassian-ide-plugin.xml
69 |
70 | # Cursive Clojure plugin
71 | .idea/replstate.xml
72 |
73 | # Crashlytics plugin (for Android Studio and IntelliJ)
74 | com_crashlytics_export_strings.xml
75 | crashlytics.properties
76 | crashlytics-build.properties
77 | fabric.properties
78 |
79 | # Editor-based Rest Client
80 | .idea/httpRequests
81 |
82 | # Android studio 3.1+ serialized cache file
83 | .idea/caches/build_file_checksums.ser
84 |
85 | ### Vue template
86 | # gitignore template for Vue.js projects
87 | #
88 | # Recommended template: Node.gitignore
89 |
90 | # TODO: where does this rule come from?
91 | docs/_book
92 |
93 | # TODO: where does this rule come from?
94 | test/
95 |
96 | ### Java template
97 | # Compiled class file
98 | *.class
99 |
100 | # Log file
101 | *.log
102 |
103 | # BlueJ files
104 | *.ctxt
105 |
106 | # Mobile Tools for Java (J2ME)
107 | .mtj.tmp/
108 |
109 | # Package Files #
110 | *.jar
111 | *.war
112 | *.nar
113 | *.ear
114 | *.zip
115 | *.tar.gz
116 | *.rar
117 |
118 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
119 | hs_err_pid*
120 |
121 | ### Node template
122 | # Logs
123 | logs
124 | *.log
125 | npm-debug.log*
126 | yarn-debug.log*
127 | yarn-error.log*
128 | lerna-debug.log*
129 |
130 | # Diagnostic reports (https://nodejs.org/api/report.html)
131 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
132 |
133 | # Runtime data
134 | pids
135 | *.pid
136 | *.seed
137 | *.pid.lock
138 |
139 | # Directory for instrumented libs generated by jscoverage/JSCover
140 | lib-cov
141 |
142 | # Coverage directory used by tools like istanbul
143 | coverage
144 | *.lcov
145 |
146 | # nyc test coverage
147 | .nyc_output
148 |
149 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
150 | .grunt
151 |
152 | # Bower dependency directory (https://bower.io/)
153 | bower_components
154 |
155 | # node-waf configuration
156 | .lock-wscript
157 |
158 | # Compiled binary addons (https://nodejs.org/api/addons.html)
159 | build/Release
160 |
161 | # Dependency directories
162 | node_modules/
163 | jspm_packages/
164 |
165 | # TypeScript v1 declaration files
166 | typings/
167 |
168 | # TypeScript cache
169 | *.tsbuildinfo
170 |
171 | # Optional npm cache directory
172 | .npm
173 |
174 | # Optional eslint cache
175 | .eslintcache
176 |
177 | # Optional REPL history
178 | .node_repl_history
179 |
180 | # Output of 'npm pack'
181 | *.tgz
182 |
183 | # Yarn Integrity file
184 | .yarn-integrity
185 |
186 | # dotenv environment variables file
187 | .env
188 | .env.test
189 |
190 | # parcel-bundler cache (https://parceljs.org/)
191 | .cache
192 |
193 | # next.js build output
194 | .next
195 |
196 | # nuxt.js build output
197 | .nuxt
198 |
199 | # vuepress build output
200 | .vuepress/dist
201 |
202 | # Serverless directories
203 | .serverless/
204 |
205 | # FuseBox cache
206 | .fusebox/
207 |
208 | # DynamoDB Local files
209 | .dynamodb/
210 |
211 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Ikaros
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RestaurantOrder
2 | 基于SpringBoot和Vue的餐馆点餐系统,单机版
3 |
4 | ## QuickStart
5 | ### 后端
6 |
7 | 1. 预先准备mysql,数据库名称为restaurant
8 | - restaurant.sql
9 |
10 | 2. 修改配置文件数据库账号密码
11 | `src/main/resources/application-template.yaml`
12 |
13 | 3. 运行RestaurantApplication.java
14 |
15 | ### 前端
16 |
17 | ```shell
18 | # npm/yarn安装依赖
19 | npm install
20 | # 运行
21 | npm run serve
22 | # 编译
23 | npm run build
24 | ```
25 | ### 访问
26 | http://localhost:8080/
27 |
28 | 默认账号密码
29 | 1. 管理员 Peggy : 123456
30 | 2. 普通用户 Ikaros : 123456
31 |
32 | 管理员多了可以添加菜单的功能
33 |
34 | ## 功能说明-后端
35 | ### 接口文档
36 | 采用Swagger2,启动后访问127.0.0.1/swagger-ui.html,默认端口80
37 |
38 | ### 数据库
39 |
40 | mysql
41 |
42 | 使用SpringJPA交互
43 |
44 | ### 身份校验
45 |
46 | 登陆:取出数据库用户,对上传的密码进行MD5加密,比较是否相同
47 |
48 | Session进行身份标识,默认30m过期
49 |
50 | ### 权限校验
51 |
52 | 用三个注解配合Aspect使用
53 |
54 | #### IsOwner
55 |
56 | 标识参数中的UserId是否与当前登录用户一致
57 |
58 | #### NeedAdmin
59 |
60 | 是否需要管理员权限,管理员的type为1,普通用户为0
61 |
62 | #### PreAuthorize
63 |
64 | SpEL表达式,可以自定义自己的权限验证方法,用于复杂校验
65 |
66 | ### 异常统一处理
67 |
68 | 用ControllerAdvice拦截自定义异常
69 |
70 | 错误代码都存放在CommonCodeEnum
71 |
72 | ### Docker
73 |
74 | 默认不开启打包成Docker,如果要开启,在pom.xml下`dockerfile-maven-plugin`插件中取消注释`build`
75 |
76 | DockerFile中以`openjdk:8-jdk-alpine`为基础镜像以减少打包后的体积
77 |
78 | 请自行修改pom.xml中docker相关参数,比如镜像名称与标签
79 |
80 | ```shell
81 | docker run --name restaurant -p 8888:80 -d --restart=always 镜像名称
82 | ```
83 |
84 |
85 |
86 | ## 功能说明-前端
87 |
88 | 前端不是很熟悉,这里就简单介绍一下
89 |
90 |
91 |
92 | ### 优化
93 |
94 | cdn
95 |
96 | ### 拦截器
97 |
98 | axios设置拦截器拦截响应,如果session过期则重新登录
99 |
100 | ### 配置
101 |
102 | #### API
103 |
104 | `src/base/config/system.js`里的apiUrl
105 |
106 | 所有的请求是基于这个apiUrl来拼接的
107 |
108 |
109 |
110 | 
111 |
112 | 
--------------------------------------------------------------------------------
/restaurant.sql:
--------------------------------------------------------------------------------
1 | /*
2 | Navicat Premium Data Transfer
3 |
4 | Source Server : restaurant
5 | Source Server Type : MySQL
6 | Source Server Version : 80019
7 | Source Host : ikarosx.cn:3307
8 | Source Schema : restaurant
9 |
10 | Target Server Type : MySQL
11 | Target Server Version : 80019
12 | File Encoding : 65001
13 |
14 | Date: 25/07/2020 16:43:46
15 | */
16 |
17 | SET NAMES utf8mb4;
18 | SET FOREIGN_KEY_CHECKS = 0;
19 |
20 | -- ----------------------------
21 | -- Table structure for menu
22 | -- ----------------------------
23 | DROP TABLE IF EXISTS `menu`;
24 | CREATE TABLE `menu` (
25 | `id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
26 | `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
27 | `price` decimal(10, 0) NOT NULL,
28 | `type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
29 | PRIMARY KEY (`id`) USING BTREE,
30 | INDEX `fk_menu_type`(`type`) USING BTREE
31 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
32 |
33 | -- ----------------------------
34 | -- Records of menu
35 | -- ----------------------------
36 | INSERT INTO `menu` VALUES ('8a80cb8173405a51017340a6bf020001', '剁椒鱼头', 30, '8a80cb8173405a51017340a53d2b0000');
37 | INSERT INTO `menu` VALUES ('8a80cb8173405a51017340a72db10002', '金鱼戏莲', 40, '8a80cb8173405a51017340a53d2b0000');
38 | INSERT INTO `menu` VALUES ('8a80cb8173405a51017340a776390003', '永州血鸭', 60, '8a80cb8173405a51017340a53d2b0000');
39 | INSERT INTO `menu` VALUES ('8a80cb8173405a51017340a853db0004', '红烧乳鸽', 60, '1');
40 | INSERT INTO `menu` VALUES ('8a80cb8173405a51017340a879ff0005', '白切贵妃鸡', 60, '1');
41 | INSERT INTO `menu` VALUES ('8a80cb8173405a51017340a8b9030006', '老火靓汤', 20, '1');
42 | INSERT INTO `menu` VALUES ('8a80cb8173405a51017340a8ede70007', '罗汉斋', 30, '1');
43 | INSERT INTO `menu` VALUES ('8a80cb8173405a51017340a964960008', '上汤焗龙虾', 100, '1');
44 | INSERT INTO `menu` VALUES ('8a80cb81734861ab0173487bd7930002', '培林炒菜', 123, '1');
45 |
46 | -- ----------------------------
47 | -- Table structure for menu_type
48 | -- ----------------------------
49 | DROP TABLE IF EXISTS `menu_type`;
50 | CREATE TABLE `menu_type` (
51 | `id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
52 | `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
53 | PRIMARY KEY (`id`) USING BTREE
54 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
55 |
56 | -- ----------------------------
57 | -- Records of menu_type
58 | -- ----------------------------
59 | INSERT INTO `menu_type` VALUES ('1', '粤菜');
60 | INSERT INTO `menu_type` VALUES ('8a80cb8173405a51017340a53d2b0000', '湘菜');
61 | INSERT INTO `menu_type` VALUES ('8a80cb81734861ab0173488088300004', '你家的菜');
62 |
63 | -- ----------------------------
64 | -- Table structure for order_detail
65 | -- ----------------------------
66 | DROP TABLE IF EXISTS `order_detail`;
67 | CREATE TABLE `order_detail` (
68 | `id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
69 | `menu_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
70 | `num` int(0) NOT NULL,
71 | `order_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
72 | `sum` decimal(10, 2) NOT NULL,
73 | `menu_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
74 | `create_time` datetime(3) NOT NULL,
75 | `update_time` datetime(3) NOT NULL,
76 | `price` decimal(10, 2) NOT NULL,
77 | PRIMARY KEY (`id`) USING BTREE
78 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
79 |
80 | -- ----------------------------
81 | -- Records of order_detail
82 | -- ----------------------------
83 | INSERT INTO `order_detail` VALUES ('2c91808573489ac00173489ff0730001', '8a80cb8173405a51017340a72db10002', 1, '2c91808573489ac00173489ff0360000', 40.00, '金鱼戏莲', '2020-07-13 14:41:48.146', '2020-07-13 14:41:48.146', 40.00);
84 | INSERT INTO `order_detail` VALUES ('2c91808573489ac00173489ff0800002', '8a80cb8173405a51017340a776390003', 1, '2c91808573489ac00173489ff0360000', 60.00, '永州血鸭', '2020-07-13 14:41:48.159', '2020-07-13 14:41:48.159', 60.00);
85 | INSERT INTO `order_detail` VALUES ('2c91808573489ac00173489ff08c0003', '8a80cb8173405a51017340a879ff0005', 1, '2c91808573489ac00173489ff0360000', 60.00, '白切贵妃鸡', '2020-07-13 14:41:48.172', '2020-07-13 14:41:48.172', 60.00);
86 | INSERT INTO `order_detail` VALUES ('2c91808573489ac00173489ff09b0004', '8a80cb8173405a51017340a8b9030006', 1, '2c91808573489ac00173489ff0360000', 20.00, '老火靓汤', '2020-07-13 14:41:48.187', '2020-07-13 14:41:48.187', 20.00);
87 | INSERT INTO `order_detail` VALUES ('2c91808573489ac0017348a207160006', '8a80cb8173405a51017340a853db0004', 1, '2c91808573489ac0017348a207050005', 60.00, '红烧乳鸽', '2020-07-13 14:44:05.014', '2020-07-13 14:44:05.014', 60.00);
88 | INSERT INTO `order_detail` VALUES ('2c91808573489ac0017348a207260007', '8a80cb8173405a51017340a879ff0005', 1, '2c91808573489ac0017348a207050005', 60.00, '白切贵妃鸡', '2020-07-13 14:44:05.030', '2020-07-13 14:44:05.030', 60.00);
89 | INSERT INTO `order_detail` VALUES ('2c91808573489ac0017348a2072b0008', '8a80cb8173405a51017340a8b9030006', 1, '2c91808573489ac0017348a207050005', 20.00, '老火靓汤', '2020-07-13 14:44:05.035', '2020-07-13 14:44:05.035', 20.00);
90 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fb30580001', '1', 0, '8a80cb817340f923017340fb2fc20000', 10.00, '炒生菜', '2020-07-12 03:04:30.551', '2020-07-12 03:04:30.551', 10.00);
91 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fb30d20002', '2', 0, '8a80cb817340f923017340fb2fc20000', 15.00, '蛋炒饭', '2020-07-12 03:04:30.674', '2020-07-12 03:04:30.674', 15.00);
92 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fb31580003', '8a80cb8173405a51017340a6bf020001', 0, '8a80cb817340f923017340fb2fc20000', 30.00, '剁椒鱼头', '2020-07-12 03:04:30.808', '2020-07-12 03:04:30.808', 30.00);
93 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fb31db0004', '8a80cb8173405a51017340a72db10002', 0, '8a80cb817340f923017340fb2fc20000', 0.00, '金鱼戏莲', '2020-07-12 03:04:30.939', '2020-07-12 03:04:30.939', 40.00);
94 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fb325a0005', '8a80cb8173405a51017340a776390003', 0, '8a80cb817340f923017340fb2fc20000', 0.00, '永州血鸭', '2020-07-12 03:04:31.065', '2020-07-12 03:04:31.065', 60.00);
95 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fb32b20006', '8a80cb8173405a51017340a853db0004', 0, '8a80cb817340f923017340fb2fc20000', 0.00, '红烧乳鸽', '2020-07-12 03:04:31.154', '2020-07-12 03:04:31.154', 60.00);
96 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fb33170007', '8a80cb8173405a51017340a879ff0005', 0, '8a80cb817340f923017340fb2fc20000', 0.00, '白切贵妃鸡', '2020-07-12 03:04:31.254', '2020-07-12 03:04:31.254', 60.00);
97 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fb337f0008', '8a80cb8173405a51017340a8b9030006', 0, '8a80cb817340f923017340fb2fc20000', 0.00, '老火靓汤', '2020-07-12 03:04:31.359', '2020-07-12 03:04:31.359', 20.00);
98 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fb33e80009', '8a80cb8173405a51017340a8ede70007', 0, '8a80cb817340f923017340fb2fc20000', 0.00, '罗汉斋', '2020-07-12 03:04:31.464', '2020-07-12 03:04:31.464', 30.00);
99 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fb345a000a', '8a80cb8173405a51017340a964960008', 0, '8a80cb817340f923017340fb2fc20000', 0.00, '上汤焗龙虾', '2020-07-12 03:04:31.578', '2020-07-12 03:04:31.578', 100.00);
100 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fe142d000c', '8a80cb8173405a51017340a72db10002', 0, '8a80cb817340f923017340fe13d0000b', 40.00, '金鱼戏莲', '2020-07-12 03:07:39.949', '2020-07-12 03:07:39.949', 40.00);
101 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fe148d000d', '8a80cb8173405a51017340a776390003', 0, '8a80cb817340f923017340fe13d0000b', 60.00, '永州血鸭', '2020-07-12 03:07:40.045', '2020-07-12 03:07:40.045', 60.00);
102 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fe14e0000e', '8a80cb8173405a51017340a853db0004', 0, '8a80cb817340f923017340fe13d0000b', 60.00, '红烧乳鸽', '2020-07-12 03:07:40.128', '2020-07-12 03:07:40.128', 60.00);
103 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fe885f0010', '1', 0, '8a80cb817340f923017340fe87d7000f', 10.00, '炒生菜', '2020-07-12 03:08:09.694', '2020-07-12 03:08:09.694', 10.00);
104 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340fe88bd0011', '2', 0, '8a80cb817340f923017340fe87d7000f', 15.00, '蛋炒饭', '2020-07-12 03:08:09.788', '2020-07-12 03:08:09.788', 15.00);
105 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340ff86470013', '1', 0, '8a80cb817340f923017340ff85ed0012', 10.00, '炒生菜', '2020-07-12 03:09:14.695', '2020-07-12 03:09:14.695', 10.00);
106 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017340ff86970014', '2', 0, '8a80cb817340f923017340ff85ed0012', 30.00, '蛋炒饭', '2020-07-12 03:09:14.774', '2020-07-12 03:09:14.774', 15.00);
107 | INSERT INTO `order_detail` VALUES ('8a80cb817340f9230173410081d90016', '2', 0, '8a80cb817340f9230173410081840015', 15.00, '蛋炒饭', '2020-07-12 03:10:19.097', '2020-07-12 03:10:19.097', 15.00);
108 | INSERT INTO `order_detail` VALUES ('8a80cb817340f9230173410082320017', '8a80cb8173405a51017340a6bf020001', 0, '8a80cb817340f9230173410081840015', 30.00, '剁椒鱼头', '2020-07-12 03:10:19.186', '2020-07-12 03:10:19.186', 30.00);
109 | INSERT INTO `order_detail` VALUES ('8a80cb817340f9230173410139fe0019', '8a80cb8173405a51017340a6bf020001', 1, '8a80cb817340f9230173410139770018', 30.00, '剁椒鱼头', '2020-07-12 03:11:06.238', '2020-07-12 03:11:06.238', 30.00);
110 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017341013a52001a', '8a80cb8173405a51017340a72db10002', 1, '8a80cb817340f9230173410139770018', 40.00, '金鱼戏莲', '2020-07-12 03:11:06.322', '2020-07-12 03:11:06.322', 40.00);
111 | INSERT INTO `order_detail` VALUES ('8a80cb817340f923017341013ab2001b', '8a80cb8173405a51017340a776390003', 1, '8a80cb817340f9230173410139770018', 60.00, '永州血鸭', '2020-07-12 03:11:06.418', '2020-07-12 03:11:06.418', 60.00);
112 | INSERT INTO `order_detail` VALUES ('8a80cb8173458c1d0173458d4b020001', 'string', 0, '8a80cb8173458c1d0173458d4a650000', 0.00, 'string', '2020-07-13 00:22:34.498', '2020-07-13 00:22:34.498', 0.00);
113 | INSERT INTO `order_detail` VALUES ('8a80cb817348826a01734882c1db0001', '8a80cb8173405a51017340a6bf020001', 1, '8a80cb817348826a01734882c14d0000', 30.00, '剁椒鱼头', '2020-07-13 14:09:55.674', '2020-07-13 14:09:55.674', 30.00);
114 | INSERT INTO `order_detail` VALUES ('8a80cb817348826a01734882c2430002', '8a80cb8173405a51017340a72db10002', 1, '8a80cb817348826a01734882c14d0000', 40.00, '金鱼戏莲', '2020-07-13 14:09:55.779', '2020-07-13 14:09:55.779', 40.00);
115 | INSERT INTO `order_detail` VALUES ('8a80cb817348826a01734882c2c60003', '8a80cb8173405a51017340a776390003', 1, '8a80cb817348826a01734882c14d0000', 60.00, '永州血鸭', '2020-07-13 14:09:55.910', '2020-07-13 14:09:55.910', 60.00);
116 |
117 | -- ----------------------------
118 | -- Table structure for orders
119 | -- ----------------------------
120 | DROP TABLE IF EXISTS `orders`;
121 | CREATE TABLE `orders` (
122 | `id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
123 | `create_time` datetime(0) NULL DEFAULT NULL,
124 | `status` int(0) NULL DEFAULT NULL,
125 | `sum` double NULL DEFAULT NULL,
126 | `update_time` datetime(0) NULL DEFAULT NULL,
127 | `user_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
128 | PRIMARY KEY (`id`) USING BTREE
129 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
130 |
131 | -- ----------------------------
132 | -- Records of orders
133 | -- ----------------------------
134 | INSERT INTO `orders` VALUES ('2c91808573489ac00173489ff0360000', '2020-07-13 14:41:48', 1, 180, '2020-07-13 14:43:30', '8a80cb817340b167017340b807110001');
135 | INSERT INTO `orders` VALUES ('2c91808573489ac0017348a207050005', '2020-07-13 14:44:05', 0, 140, '2020-07-13 14:44:05', '8a80cb817340b167017340b807110001');
136 | INSERT INTO `orders` VALUES ('8a80cb81733e1b6801733e1c0f1d0000', '2020-07-11 13:41:33', 1, 65, '2020-07-11 13:41:57', '8a80cb817336379001733637aed10000');
137 | INSERT INTO `orders` VALUES ('8a80cb81733e1b6801733e2113bf0003', '2020-07-11 13:47:02', 1, 20, '2020-07-12 01:21:34', '8a80cb817336379001733637aed10000');
138 | INSERT INTO `orders` VALUES ('8a80cb81733e1b6801733e22a8b20006', '2020-07-11 13:48:46', 1, 65, '2020-07-12 01:36:22', '8a80cb817336379001733637aed10000');
139 | INSERT INTO `orders` VALUES ('8a80cb81733e1b6801733e2817a90009', '2020-07-11 13:54:42', 1, 95, '2020-07-11 13:54:59', '8a80cb817336379001733637aed10000');
140 | INSERT INTO `orders` VALUES ('8a80cb81733e1b6801733e2abc68000c', '2020-07-11 13:57:35', 1, 65, '2020-07-11 13:57:52', '8a80cb817336379001733637aed10000');
141 | INSERT INTO `orders` VALUES ('8a80cb81733e1b6801733e39ccd1000f', '2020-07-11 14:14:02', 1, 20, '2020-07-11 14:14:12', '8a80cb817336379001733637aed10000');
142 | INSERT INTO `orders` VALUES ('8a80cb8173405a51017340aa0c850009', '2020-07-12 01:35:53', 1, 175, '2020-07-12 01:36:02', '8a80cb817336379001733637aed10000');
143 | INSERT INTO `orders` VALUES ('8a80cb817340bc1a017340bcb3230000', '2020-07-12 01:56:15', 1, 360, '2020-07-12 01:56:22', '8a80cb817340b167017340b807110001');
144 | INSERT INTO `orders` VALUES ('8a80cb817340bc1a017340bcf92b000b', '2020-07-12 01:56:33', 1, 160, '2020-07-12 01:56:40', '8a80cb817340b167017340b807110001');
145 | INSERT INTO `orders` VALUES ('8a80cb817340f923017340fb2fc20000', '2020-07-12 03:04:30', 1, 55, '2020-07-12 03:05:50', '8a80cb817340b167017340b807110001');
146 | INSERT INTO `orders` VALUES ('8a80cb817340f923017340fe13d0000b', '2020-07-12 03:07:40', 1, 160, '2020-07-12 03:08:00', '8a80cb817340b167017340b807110001');
147 | INSERT INTO `orders` VALUES ('8a80cb817340f923017340fe87d7000f', '2020-07-12 03:08:10', 1, 25, '2020-07-12 03:14:30', '8a80cb817340b167017340b807110001');
148 | INSERT INTO `orders` VALUES ('8a80cb817340f923017340ff85ed0012', '2020-07-12 03:09:15', 1, 40, '2020-07-12 03:14:27', '8a80cb817340b167017340b807110001');
149 | INSERT INTO `orders` VALUES ('8a80cb817340f9230173410081840015', '2020-07-12 03:10:19', 1, 45, '2020-07-12 03:14:24', '8a80cb817340b167017340b807110001');
150 | INSERT INTO `orders` VALUES ('8a80cb817340f9230173410139770018', '2020-07-12 03:11:06', 1, 130, '2020-07-12 03:14:22', '8a80cb817340b167017340b807110001');
151 | INSERT INTO `orders` VALUES ('8a80cb817348826a01734882c14d0000', '2020-07-13 14:09:56', 1, 130, '2020-07-13 14:10:03', '8a80cb81734861ab017348818a7d0005');
152 |
153 | -- ----------------------------
154 | -- Table structure for user
155 | -- ----------------------------
156 | DROP TABLE IF EXISTS `user`;
157 | CREATE TABLE `user` (
158 | `id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
159 | `password` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
160 | `create_time` datetime(3) NOT NULL,
161 | `update_time` datetime(3) NOT NULL,
162 | `username` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
163 | `type` tinyint(1) NOT NULL COMMENT '0为普通用户 1为管理员',
164 | PRIMARY KEY (`id`) USING BTREE,
165 | UNIQUE INDEX `un_user_username`(`username`) USING BTREE
166 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
167 |
168 | -- ----------------------------
169 | -- Records of user
170 | -- ----------------------------
171 | INSERT INTO `user` VALUES ('8a80cb817340b167017340b807110001', 'e10adc3949ba59abbe56e057f20f883e', '2020-07-12 01:51:09.072', '2020-07-12 01:51:09.072', 'Peggy', 1);
172 | INSERT INTO `user` VALUES ('8a80cb81734861ab017348818a7d0005', 'e10adc3949ba59abbe56e057f20f883e', '2020-07-13 14:08:35.960', '2020-07-13 14:08:35.960', 'Ikarosx', 0);
173 |
174 | SET FOREIGN_KEY_CHECKS = 1;
175 |
--------------------------------------------------------------------------------
/restaurantServer/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### JetBrains template
3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5 |
6 | # User-specific stuff
7 | .idea/**/workspace.xml
8 | .idea/**/tasks.xml
9 | .idea/**/usage.statistics.xml
10 | .idea/**/dictionaries
11 | .idea/**/shelf
12 | #src/main/resources/application.yaml
13 | # Generated files
14 | .idea/**/contentModel.xml
15 |
16 | # Sensitive or high-churn files
17 | .idea/**/dataSources/
18 | .idea/**/dataSources.ids
19 | .idea/**/dataSources.local.xml
20 | .idea/**/sqlDataSources.xml
21 | .idea/**/dynamic.xml
22 | .idea/**/uiDesigner.xml
23 | .idea/**/dbnavigator.xml
24 |
25 | # Gradle
26 | .idea/**/gradle.xml
27 | .idea/**/libraries
28 |
29 | # Gradle and Maven with auto-import
30 | # When using Gradle or Maven with auto-import, you should exclude module files,
31 | # since they will be recreated, and may cause churn. Uncomment if using
32 | # auto-import.
33 | # .idea/modules.xml
34 | # .idea/*.iml
35 | # .idea/modules
36 | # *.iml
37 | # *.ipr
38 |
39 | # CMake
40 | cmake-build-*/
41 |
42 | # Mongo Explorer plugin
43 | .idea/**/mongoSettings.xml
44 |
45 | # File-based project format
46 | *.iws
47 |
48 | # IntelliJ
49 | out/
50 |
51 | # mpeltonen/sbt-idea plugin
52 | .idea_modules/
53 |
54 | # JIRA plugin
55 | atlassian-ide-plugin.xml
56 |
57 | # Cursive Clojure plugin
58 | .idea/replstate.xml
59 |
60 | # Crashlytics plugin (for Android Studio and IntelliJ)
61 | com_crashlytics_export_strings.xml
62 | crashlytics.properties
63 | crashlytics-build.properties
64 | fabric.properties
65 |
66 | # Editor-based Rest Client
67 | .idea/httpRequests
68 |
69 | # Android studio 3.1+ serialized cache file
70 | .idea/caches/build_file_checksums.ser
71 |
72 | ### Java template
73 | # Compiled class file
74 | *.class
75 |
76 | # Log file
77 | *.log
78 |
79 | # BlueJ files
80 | *.ctxt
81 |
82 | # Mobile Tools for Java (J2ME)
83 | .mtj.tmp/
84 |
85 | # Package Files #
86 | *.jar
87 | *.war
88 | *.nar
89 | *.ear
90 | *.zip
91 | *.tar.gz
92 | *.rar
93 |
94 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
95 | hs_err_pid*
96 |
97 | ### Maven template
98 | target/
99 | pom.xml.tag
100 | pom.xml.releaseBackup
101 | pom.xml.versionsBackup
102 | pom.xml.next
103 | release.properties
104 | dependency-reduced-pom.xml
105 | buildNumber.properties
106 | .mvn/timing.properties
107 | .mvn/wrapper/maven-wrapper.jar
108 | *.iml
109 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/.name:
--------------------------------------------------------------------------------
1 | restaurant
--------------------------------------------------------------------------------
/restaurantServer/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/google-java-format.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/restaurantServer.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/saveactions_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/restaurantServer/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/restaurantServer/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jdk-alpine
2 | ARG JAR_FILE
3 | ADD target/${JAR_FILE} /app.jar
4 | EXPOSE 80
5 | ENTRYPOINT ["java", "-jar", "/app.jar"]
--------------------------------------------------------------------------------
/restaurantServer/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | cn.ikarosx
8 | restaurant
9 | 1.1-SNAPSHOT
10 |
11 | org.springframework.boot
12 | spring-boot-starter-parent
13 | 2.2.2.RELEASE
14 |
15 |
16 |
17 | ikarosx.cn:15000
18 | tcp://ikarosx.cn:2375
19 | 2.9.2
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-data-jpa
29 |
30 |
31 | org.projectlombok
32 | lombok
33 |
34 |
35 | mysql
36 | mysql-connector-java
37 |
38 |
39 |
40 | io.springfox
41 | springfox-swagger2
42 | ${springfox-swagger.version}
43 |
44 |
45 | io.springfox
46 | springfox-swagger-ui
47 | ${springfox-swagger.version}
48 |
49 |
50 | org.apache.commons
51 | commons-lang3
52 |
53 |
54 | org.springframework.boot
55 | spring-boot-starter-test
56 |
57 |
58 | com.alibaba
59 | fastjson
60 | 1.2.83
61 |
62 |
63 |
64 |
65 | ${project.artifactId}
66 |
67 |
68 | org.springframework.boot
69 | spring-boot-maven-plugin
70 |
71 |
72 | org.apache.maven.plugins
73 | maven-deploy-plugin
74 |
75 | true
76 |
77 |
78 |
79 | com.spotify
80 | dockerfile-maven-plugin
81 | 1.4.13
82 |
83 |
84 | default
85 |
86 |
87 |
88 | push
89 |
90 |
91 |
92 |
93 | ${docker.repostory}/${project.artifactId}
94 | ${project.version}
95 |
96 |
97 | ${project.build.finalName}.jar
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/RestaurantApplication.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
6 |
7 | /**
8 | * @author Ikarosx
9 | * @date 2020/7/6 23:45
10 | */
11 | @SpringBootApplication
12 | @EnableJpaAuditing
13 | public class RestaurantApplication {
14 | public static void main(String[] args) {
15 | SpringApplication.run(RestaurantApplication.class, args);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/aspect/AdminAspect.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.aspect;
2 |
3 | import cn.ikarosx.restaurant.exception.CommonCodeEnum;
4 | import cn.ikarosx.restaurant.exception.ExceptionCast;
5 | import cn.ikarosx.restaurant.util.SessionUtils;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.aspectj.lang.JoinPoint;
8 | import org.aspectj.lang.Signature;
9 | import org.aspectj.lang.annotation.Aspect;
10 | import org.aspectj.lang.annotation.Before;
11 | import org.aspectj.lang.annotation.Pointcut;
12 | import org.aspectj.lang.reflect.MethodSignature;
13 | import org.springframework.stereotype.Component;
14 |
15 | import java.lang.reflect.Method;
16 |
17 | /**
18 | * @author Ikarosx
19 | * @date 2020/7/9 13:52
20 | */
21 | @Aspect
22 | @Slf4j
23 | @Component
24 | public class AdminAspect {
25 | @Pointcut("@annotation(NeedAdmin)")
26 | public void needAdminPointCut() {}
27 |
28 | @Before("needAdminPointCut()()")
29 | public void needAdminBefore(JoinPoint joinPoint) {
30 | Signature signature = joinPoint.getSignature();
31 | MethodSignature methodSignature = (MethodSignature) signature;
32 | Method method = methodSignature.getMethod();
33 | if (!SessionUtils.isAdmin()) {
34 | log.error("此方法需要管理员权限:" + method.getName());
35 | ExceptionCast.cast(CommonCodeEnum.PERMISSION_DENY);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/aspect/IsOwner.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.aspect;
2 |
3 | import cn.ikarosx.restaurant.entity.User;
4 |
5 | import java.lang.annotation.*;
6 |
7 | @Documented
8 | @Target(ElementType.METHOD)
9 | @Inherited
10 | @Retention(RetentionPolicy.RUNTIME)
11 | public @interface IsOwner {
12 | /** ID的位置 */
13 | int position() default 0;
14 | /** 是什么的ID */
15 | Class clazz() default User.class;
16 | /** ID字段的名字,驼峰写法 */
17 | String name() default "Id";
18 | /** 主键的类型 */
19 | Class idClazz() default String.class;
20 | }
21 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/aspect/NeedAdmin.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.aspect;
2 |
3 | import java.lang.annotation.*;
4 |
5 | /**
6 | * @author Ikaros
7 | * @date 2020/07/10 09:15
8 | */
9 | @Documented
10 | @Target(ElementType.METHOD)
11 | @Inherited
12 | @Retention(RetentionPolicy.RUNTIME)
13 | public @interface NeedAdmin {}
14 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/aspect/OwnerAspect.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.aspect;
2 |
3 | import cn.ikarosx.restaurant.exception.CommonCodeEnum;
4 | import cn.ikarosx.restaurant.exception.ExceptionCast;
5 | import cn.ikarosx.restaurant.util.SessionUtils;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.apache.commons.lang3.StringUtils;
8 | import org.aspectj.lang.JoinPoint;
9 | import org.aspectj.lang.Signature;
10 | import org.aspectj.lang.annotation.Aspect;
11 | import org.aspectj.lang.annotation.Before;
12 | import org.aspectj.lang.annotation.Pointcut;
13 | import org.aspectj.lang.reflect.MethodSignature;
14 | import org.springframework.stereotype.Component;
15 |
16 | import java.lang.reflect.InvocationTargetException;
17 | import java.lang.reflect.Method;
18 |
19 | /**
20 | * @author Ikarosx
21 | * @date 2020/7/9 13:52
22 | */
23 | @Aspect
24 | @Slf4j
25 | @Component
26 | public class OwnerAspect {
27 | @Pointcut("@annotation(IsOwner)")
28 | public void ownerPointCut() {}
29 |
30 | @Before("ownerPointCut()")
31 | public void ownerBefore(JoinPoint joinPoint) {
32 | Signature signature = joinPoint.getSignature();
33 | MethodSignature methodSignature = (MethodSignature) signature;
34 | Method method = methodSignature.getMethod();
35 | if (SessionUtils.isAdmin()) {
36 | return;
37 | }
38 | IsOwner isOwner = method.getAnnotation(IsOwner.class);
39 | int position = isOwner.position();
40 | Class clazz = isOwner.clazz();
41 | Class idClazz = isOwner.idClazz();
42 | String name = isOwner.name();
43 | Object[] args = joinPoint.getArgs();
44 | if (args == null || args.length == 0) {
45 | log.warn("标记了IsOwner但参数为空:" + method.getName());
46 | ExceptionCast.cast(CommonCodeEnum.FAIL);
47 | }
48 | if (position > args.length) {
49 | log.warn("标记了IsOwner但position不对:" + method.getName());
50 | ExceptionCast.cast(CommonCodeEnum.FAIL);
51 | }
52 | Object arg = args[position];
53 | Object id = null;
54 | try {
55 | id = idClazz.newInstance();
56 | if (arg.getClass() == idClazz) {
57 | id = idClazz.cast(arg);
58 | } else if (arg.getClass() == clazz) {
59 | Method declaredMethod = clazz.getDeclaredMethod("get" + name);
60 | id = declaredMethod.invoke(arg);
61 | } else {
62 | log.warn("标记了IsOwner但目标参数既不是String也不是指定的class类型:" + method.getName());
63 | ExceptionCast.cast(CommonCodeEnum.FAIL);
64 | }
65 | } catch (InstantiationException
66 | | InvocationTargetException
67 | | NoSuchMethodException
68 | | IllegalAccessException e) {
69 | log.error("触发异常", e);
70 | ExceptionCast.cast(CommonCodeEnum.FAIL);
71 | }
72 | String userId = SessionUtils.getUser().getId();
73 | if (id == null || !StringUtils.equals(id.toString(), userId)) {
74 | log.warn(id + "没有对该资源的操作权限:" + userId);
75 | ExceptionCast.cast(CommonCodeEnum.PERMISSION_DENY);
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/aspect/PreAuthorizaAspect.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.aspect;
2 |
3 | import cn.ikarosx.restaurant.exception.CommonCodeEnum;
4 | import cn.ikarosx.restaurant.exception.ExceptionCast;
5 | import cn.ikarosx.restaurant.util.SessionUtils;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.aspectj.lang.JoinPoint;
8 | import org.aspectj.lang.Signature;
9 | import org.aspectj.lang.annotation.Aspect;
10 | import org.aspectj.lang.annotation.Before;
11 | import org.aspectj.lang.annotation.Pointcut;
12 | import org.aspectj.lang.reflect.MethodSignature;
13 | import org.springframework.beans.BeansException;
14 | import org.springframework.beans.factory.BeanFactory;
15 | import org.springframework.beans.factory.BeanFactoryAware;
16 | import org.springframework.context.expression.BeanFactoryResolver;
17 | import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
18 | import org.springframework.expression.Expression;
19 | import org.springframework.expression.ExpressionParser;
20 | import org.springframework.expression.spel.standard.SpelExpressionParser;
21 | import org.springframework.expression.spel.support.StandardEvaluationContext;
22 | import org.springframework.stereotype.Component;
23 |
24 | import java.lang.reflect.Method;
25 |
26 | /**
27 | * SpEL鉴权
28 | *
29 | * @author Ikarosx
30 | * @date 2020/7/25 9:38
31 | */
32 | @Aspect
33 | @Component
34 | @Slf4j
35 | public class PreAuthorizaAspect implements BeanFactoryAware {
36 | private ExpressionParser parser = new SpelExpressionParser();
37 | private LocalVariableTableParameterNameDiscoverer discoverer =
38 | new LocalVariableTableParameterNameDiscoverer();
39 |
40 | private BeanFactory beanFactory;
41 | private BeanFactoryResolver beanResolver;
42 |
43 | @Pointcut("@annotation(PreAuthorize)")
44 | public void preAuthorizaPointCut() {}
45 |
46 | @Before("preAuthorizaPointCut()")
47 | public void preAuthorizaBefore(JoinPoint joinPoint) {
48 | Signature signature = joinPoint.getSignature();
49 | MethodSignature methodSignature = (MethodSignature) signature;
50 | Method method = methodSignature.getMethod();
51 | PreAuthorize preAuthorize = method.getAnnotation(PreAuthorize.class);
52 | String spel = preAuthorize.value();
53 |
54 | String[] params = discoverer.getParameterNames(method);
55 | StandardEvaluationContext context = new StandardEvaluationContext();
56 | Object[] args = joinPoint.getArgs();
57 | for (int len = 0; len < params.length; len++) {
58 | context.setVariable(params[len], args[len]);
59 | }
60 | context.setBeanResolver(beanResolver);
61 | Expression expression = parser.parseExpression(spel);
62 | if (!expression.getValue(context, Boolean.class)) {
63 | log.warn(SessionUtils.getUserName() + "在越权访问" + method.getName());
64 | ExceptionCast.cast(CommonCodeEnum.PERMISSION_DENY);
65 | }
66 | }
67 |
68 | @Override
69 | public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
70 | this.beanFactory = beanFactory;
71 | this.beanResolver = new BeanFactoryResolver(beanFactory);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/aspect/PreAuthorize.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.aspect;
2 |
3 | import java.lang.annotation.*;
4 |
5 | /**
6 | * @author Ikarosx
7 | * @date 2020/7/25 9:36
8 | */
9 | @Target(value = ElementType.METHOD)
10 | @Documented
11 | @Retention(RetentionPolicy.RUNTIME)
12 | public @interface PreAuthorize {
13 | String value();
14 | }
15 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/config/Swagger2Configuration.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
6 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
7 | import springfox.documentation.builders.ApiInfoBuilder;
8 | import springfox.documentation.builders.PathSelectors;
9 | import springfox.documentation.builders.RequestHandlerSelectors;
10 | import springfox.documentation.service.ApiInfo;
11 | import springfox.documentation.spi.DocumentationType;
12 | import springfox.documentation.spring.web.plugins.Docket;
13 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
14 |
15 | /**
16 | * @author Ikaros
17 | * @date 2020/1/28 21:18
18 | */
19 | @Configuration
20 | @EnableSwagger2
21 | public class Swagger2Configuration {
22 | @Bean
23 | public Docket createTuYaApi() {
24 | return new Docket(DocumentationType.SWAGGER_2)
25 | .apiInfo(apiInfo())
26 | .groupName("点餐系统API")
27 | .select()
28 | .apis(RequestHandlerSelectors.basePackage("cn.ikarosx.restaurant.controller"))
29 | .paths(PathSelectors.any())
30 | .build();
31 | }
32 |
33 | private ApiInfo apiInfo() {
34 | return new ApiInfoBuilder().title("点餐系统API").description("点餐系统API").version("1.0").build();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/config/TomcatConfiguration.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.config;
2 |
3 | import org.apache.tomcat.util.http.Rfc6265CookieProcessor;
4 | import org.apache.tomcat.util.http.SameSiteCookies;
5 | import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 |
10 | @Configuration
11 | public class TomcatConfiguration {
12 |
13 | @Bean
14 | public TomcatContextCustomizer sameSiteCookiesConfig() {
15 | return context -> {
16 | final Rfc6265CookieProcessor cookieProcessor = new Rfc6265CookieProcessor();
17 | // 设置Cookie的SameSite
18 | cookieProcessor.setSameSiteCookies(SameSiteCookies.NONE.getValue());
19 | context.setCookieProcessor(cookieProcessor);
20 | };
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/controller/MenuController.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.controller;
2 |
3 | import cn.ikarosx.restaurant.entity.Menu;
4 | import cn.ikarosx.restaurant.entity.query.MenuQueryParam;
5 | import cn.ikarosx.restaurant.exception.ResponseResult;
6 | /**
7 | * @author Ikaros
8 | * @date 2020/07/07 22:43
9 | */
10 | public interface MenuController {
11 |
12 | ResponseResult insertMenu(Menu menu);
13 |
14 | ResponseResult deleteMenuById(String id);
15 |
16 | ResponseResult updateMenu(String id, Menu menu);
17 |
18 | ResponseResult getMenuById(String id);
19 |
20 | ResponseResult listMenusByPage(int page, int size, MenuQueryParam menuQueryParam);
21 |
22 | ResponseResult listAllMenus();
23 | }
24 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/controller/MenuTypeController.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.controller;
2 |
3 | import cn.ikarosx.restaurant.entity.MenuType;
4 | import cn.ikarosx.restaurant.entity.query.MenuTypeQueryParam;
5 | import cn.ikarosx.restaurant.exception.ResponseResult;
6 | /**
7 | * @author Ikaros
8 | * @date 2020/07/07 22:43
9 | */
10 | public interface MenuTypeController {
11 |
12 | ResponseResult insertMenuType(MenuType menuType);
13 |
14 | ResponseResult deleteMenuTypeById(String id);
15 |
16 | ResponseResult updateMenuType(String id, MenuType menuType);
17 |
18 | ResponseResult getMenuTypeById(String id);
19 |
20 | ResponseResult listMenuTypesByPage(int page, int size, MenuTypeQueryParam menuTypeQueryParam);
21 |
22 | ResponseResult listAllMenuTypes();
23 | }
24 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/controller/OrderController.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.controller;
2 |
3 | import cn.ikarosx.restaurant.entity.Order;
4 | import cn.ikarosx.restaurant.entity.query.PostOrder;
5 | import cn.ikarosx.restaurant.entity.query.OrderQueryParam;
6 | import cn.ikarosx.restaurant.exception.ResponseResult;
7 | /**
8 | * @author Ikaros
9 | * @date 2020/07/07 22:43
10 | */
11 | public interface OrderController {
12 |
13 | ResponseResult insertOrder(PostOrder order);
14 |
15 | ResponseResult payOrder(String orderId);
16 |
17 | ResponseResult deleteOrderById(String id);
18 |
19 | ResponseResult updateOrder(String id, Order order);
20 |
21 | ResponseResult getOrderById(String id);
22 |
23 | ResponseResult listOrdersByPage(int page, int size, OrderQueryParam orderQueryParam);
24 |
25 | ResponseResult listAllOrders(OrderQueryParam orderQueryParam);
26 | }
27 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/controller/OrderDetailController.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.controller;
2 |
3 | import cn.ikarosx.restaurant.entity.query.OrderDetailQueryParam;
4 | import cn.ikarosx.restaurant.exception.ResponseResult;
5 | /**
6 | * @author Ikaros
7 | * @date 2020/07/07 22:43
8 | */
9 | public interface OrderDetailController {
10 |
11 | // ResponseResult insertOrderDetail(OrderDetail orderDetail);
12 | //
13 | // ResponseResult deleteOrderDetailById(String id);
14 | //
15 | // ResponseResult updateOrderDetail(String id, OrderDetail orderDetail);
16 |
17 | // ResponseResult getOrderDetailById(String id);
18 | //
19 | // ResponseResult listOrderDetailsByPage(
20 | // int page, int size, OrderDetailQueryParam orderDetailQueryParam);
21 |
22 | ResponseResult listAllOrderDetails(OrderDetailQueryParam orderDetailQueryParam);
23 | }
24 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.controller;
2 |
3 | import cn.ikarosx.restaurant.entity.User;
4 | import cn.ikarosx.restaurant.entity.query.UserQueryParam;
5 | import cn.ikarosx.restaurant.exception.ResponseResult;
6 | /**
7 | * @author Ikaros
8 | * @date 2020/07/07 22:43
9 | */
10 | public interface UserController {
11 |
12 | ResponseResult login(String username, String password);
13 |
14 | ResponseResult logout();
15 |
16 | ResponseResult insertUser(User user);
17 |
18 | ResponseResult deleteUserById(String id);
19 |
20 | ResponseResult updateUser(String id, User user);
21 |
22 | ResponseResult getUserById(String id);
23 |
24 | ResponseResult listUsersByPage(int page, int size, UserQueryParam userQueryParam);
25 |
26 | ResponseResult listAllUsers();
27 | }
28 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/controller/impl/MenuControllerImpl.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.controller.impl;
2 |
3 | import cn.ikarosx.restaurant.aspect.NeedAdmin;
4 | import cn.ikarosx.restaurant.controller.MenuController;
5 | import cn.ikarosx.restaurant.entity.Menu;
6 | import cn.ikarosx.restaurant.entity.query.MenuQueryParam;
7 | import cn.ikarosx.restaurant.exception.ResponseResult;
8 | import cn.ikarosx.restaurant.service.MenuService;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.validation.annotation.Validated;
11 | import org.springframework.web.bind.annotation.*;
12 | /**
13 | * @author Ikaros
14 | * @date 2020/07/07 22:43
15 | */
16 | @RestController
17 | @RequestMapping("menu")
18 | public class MenuControllerImpl implements MenuController {
19 | @Autowired private MenuService menuService;
20 |
21 | @Override
22 | @PostMapping
23 | @NeedAdmin
24 | public ResponseResult insertMenu(@Validated @RequestBody Menu menu) {
25 | return menuService.insertMenu(menu);
26 | }
27 |
28 | @Override
29 | @DeleteMapping("/{id}")
30 | @NeedAdmin
31 | public ResponseResult deleteMenuById(@PathVariable String id) {
32 | return menuService.deleteMenuById(id);
33 | }
34 |
35 | @Override
36 | @PutMapping("/{id}")
37 | @NeedAdmin
38 | public ResponseResult updateMenu(@PathVariable String id, @Validated @RequestBody Menu menu) {
39 | return menuService.updateMenu(menu);
40 | }
41 |
42 | @Override
43 | @GetMapping("/{id}")
44 | @NeedAdmin
45 | public ResponseResult getMenuById(@PathVariable String id) {
46 | return menuService.getMenuById(id);
47 | }
48 |
49 | @Override
50 | @GetMapping("/{page}/{size}")
51 | @NeedAdmin
52 | public ResponseResult listMenusByPage(
53 | @PathVariable int page, @PathVariable int size, MenuQueryParam menuQueryParam) {
54 | if (page < 1) {
55 | page = 1;
56 | }
57 | if (size <= 0) {
58 | size = 10;
59 | }
60 | if (menuQueryParam == null) {
61 | menuQueryParam = new MenuQueryParam();
62 | }
63 | return menuService.listMenusByPage(page, size, menuQueryParam);
64 | }
65 |
66 | @Override
67 | @GetMapping("/all")
68 | public ResponseResult listAllMenus() {
69 | return menuService.listAllMenus();
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/controller/impl/MenuTypeControllerImpl.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.controller.impl;
2 |
3 | import cn.ikarosx.restaurant.aspect.NeedAdmin;
4 | import cn.ikarosx.restaurant.controller.MenuTypeController;
5 | import cn.ikarosx.restaurant.entity.MenuType;
6 | import cn.ikarosx.restaurant.entity.query.MenuTypeQueryParam;
7 | import cn.ikarosx.restaurant.exception.ResponseResult;
8 | import cn.ikarosx.restaurant.service.MenuTypeService;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.validation.annotation.Validated;
11 | import org.springframework.web.bind.annotation.*;
12 | /**
13 | * @author Ikaros
14 | * @date 2020/07/07 22:43
15 | */
16 | @RestController
17 | @RequestMapping("/menu/type")
18 | public class MenuTypeControllerImpl implements MenuTypeController {
19 | @Autowired private MenuTypeService menuTypeService;
20 |
21 | @Override
22 | @PostMapping
23 | @NeedAdmin
24 | public ResponseResult insertMenuType(@Validated @RequestBody MenuType menuType) {
25 | return menuTypeService.insertMenuType(menuType);
26 | }
27 |
28 | @Override
29 | @DeleteMapping("/{id}")
30 | @NeedAdmin
31 | public ResponseResult deleteMenuTypeById(@PathVariable String id) {
32 | return menuTypeService.deleteMenuTypeById(id);
33 | }
34 |
35 | @Override
36 | @PutMapping("/{id}")
37 | @NeedAdmin
38 | public ResponseResult updateMenuType(
39 | @PathVariable String id, @Validated @RequestBody MenuType menuType) {
40 | return menuTypeService.updateMenuType(menuType);
41 | }
42 |
43 | @Override
44 | @GetMapping("/{id}")
45 | @NeedAdmin
46 | public ResponseResult getMenuTypeById(@PathVariable String id) {
47 | return menuTypeService.getMenuTypeById(id);
48 | }
49 |
50 | @Override
51 | @GetMapping("/{page}/{size}")
52 | @NeedAdmin
53 | public ResponseResult listMenuTypesByPage(
54 | @PathVariable int page, @PathVariable int size, MenuTypeQueryParam menuTypeQueryParam) {
55 | if (page < 1) {
56 | page = 1;
57 | }
58 | if (size <= 0) {
59 | size = 10;
60 | }
61 | if (menuTypeQueryParam == null) {
62 | menuTypeQueryParam = new MenuTypeQueryParam();
63 | }
64 | return menuTypeService.listMenuTypesByPage(page, size, menuTypeQueryParam);
65 | }
66 |
67 | @Override
68 | @GetMapping("/all")
69 | public ResponseResult listAllMenuTypes() {
70 | return menuTypeService.listAllMenuTypes();
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/controller/impl/OrderControllerImpl.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.controller.impl;
2 |
3 | import cn.ikarosx.restaurant.aspect.IsOwner;
4 | import cn.ikarosx.restaurant.aspect.PreAuthorize;
5 | import cn.ikarosx.restaurant.controller.OrderController;
6 | import cn.ikarosx.restaurant.entity.Order;
7 | import cn.ikarosx.restaurant.entity.query.PostOrder;
8 | import cn.ikarosx.restaurant.entity.query.OrderQueryParam;
9 | import cn.ikarosx.restaurant.exception.ResponseResult;
10 | import cn.ikarosx.restaurant.service.OrderService;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.validation.annotation.Validated;
13 | import org.springframework.web.bind.annotation.*;
14 | /**
15 | * @author Ikaros
16 | * @date 2020/07/07 22:43
17 | */
18 | @RestController
19 | @RequestMapping("order")
20 | public class OrderControllerImpl implements OrderController {
21 | @Autowired private OrderService orderService;
22 |
23 | @Override
24 | @PostMapping
25 | @IsOwner(clazz = PostOrder.class, name = "UserId")
26 | public ResponseResult insertOrder(@Validated @RequestBody PostOrder order) {
27 | return orderService.insertOrder(order);
28 | }
29 |
30 | @Override
31 | @GetMapping("/{orderId}/pay")
32 | public ResponseResult payOrder(@PathVariable String orderId) {
33 | return orderService.payOrder(orderId);
34 | }
35 |
36 | @Override
37 | @DeleteMapping("/{id}")
38 | @PreAuthorize("@securityServiceImpl.orderIdAuth(#id)")
39 | public ResponseResult deleteOrderById(@PathVariable String id) {
40 | return orderService.deleteOrderById(id);
41 | }
42 |
43 | @Override
44 | @PutMapping("/{id}")
45 | @PreAuthorize("@securityServiceImpl.orderIdAuth(#id)")
46 | public ResponseResult updateOrder(@PathVariable String id, @Validated @RequestBody Order order) {
47 | return orderService.updateOrder(order);
48 | }
49 |
50 | @Override
51 | @GetMapping("/{id}")
52 | @PreAuthorize("@securityServiceImpl.orderIdAuth(#id)")
53 | public ResponseResult getOrderById(@PathVariable String id) {
54 | return orderService.getOrderById(id);
55 | }
56 |
57 | @Override
58 | @GetMapping("/{page}/{size}")
59 | @IsOwner(position = 2, clazz = OrderQueryParam.class, name = "UserId")
60 | public ResponseResult listOrdersByPage(
61 | @PathVariable int page, @PathVariable int size, OrderQueryParam orderQueryParam) {
62 | if (page < 1) {
63 | page = 1;
64 | }
65 | if (size <= 0) {
66 | size = 10;
67 | }
68 | if (orderQueryParam == null) {
69 | orderQueryParam = new OrderQueryParam();
70 | }
71 | return orderService.listOrdersByPage(page, size, orderQueryParam);
72 | }
73 |
74 | @Override
75 | @GetMapping
76 | @IsOwner(clazz = OrderQueryParam.class, name = "UserId")
77 | public ResponseResult listAllOrders(OrderQueryParam orderQueryParam) {
78 | return orderService.listAllOrders(orderQueryParam);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/controller/impl/OrderDetailControllerImpl.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.controller.impl;
2 |
3 | import cn.ikarosx.restaurant.aspect.PreAuthorize;
4 | import cn.ikarosx.restaurant.controller.OrderDetailController;
5 | import cn.ikarosx.restaurant.entity.query.OrderDetailQueryParam;
6 | import cn.ikarosx.restaurant.exception.ResponseResult;
7 | import cn.ikarosx.restaurant.service.OrderDetailService;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.web.bind.annotation.GetMapping;
10 | import org.springframework.web.bind.annotation.RequestMapping;
11 | import org.springframework.web.bind.annotation.RestController;
12 | /**
13 | * @author Ikaros
14 | * @date 2020/07/07 22:43
15 | */
16 | @RestController
17 | @RequestMapping("order/detail")
18 | public class OrderDetailControllerImpl implements OrderDetailController {
19 | @Autowired private OrderDetailService orderDetailService;
20 |
21 | // @Override
22 | // @PostMapping
23 | // public ResponseResult insertOrderDetail(
24 | // @Validated(value = Insert.class) @RequestBody OrderDetail orderDetail) {
25 | // return orderDetailService.insertOrderDetail(orderDetail);
26 | // }
27 | //
28 | // @Override
29 | // @DeleteMapping("/{id}")
30 | // public ResponseResult deleteOrderDetailById(@PathVariable String id) {
31 | // return orderDetailService.deleteOrderDetailById(id);
32 | // }
33 | //
34 | // @Override
35 | // @PutMapping("/{id}")
36 | // public ResponseResult updateOrderDetail(
37 | // @PathVariable String id, @Validated @RequestBody OrderDetail orderDetail) {
38 | // return orderDetailService.updateOrderDetail(orderDetail);
39 | // }
40 |
41 | // @Override
42 | // @GetMapping("/{id}")
43 | // public ResponseResult getOrderDetailById(@PathVariable String id) {
44 | // return orderDetailService.getOrderDetailById(id);
45 | // }
46 |
47 | // @Override
48 | // @GetMapping("/{page}/{size}")
49 | // public ResponseResult listOrderDetailsByPage(
50 | // @PathVariable int page, @PathVariable int size, OrderDetailQueryParam orderDetailQueryParam) {
51 | // if (page < 1) {
52 | // page = 1;
53 | // }
54 | // if (size <= 0) {
55 | // size = 10;
56 | // }
57 | // if (orderDetailQueryParam == null) {
58 | // orderDetailQueryParam = new OrderDetailQueryParam();
59 | // }
60 | // return orderDetailService.listOrderDetailsByPage(page, size, orderDetailQueryParam);
61 | // }
62 |
63 | @Override
64 | @GetMapping
65 | @PreAuthorize("@securityServiceImpl.orderIdAuth(#orderDetailQueryParam.orderId)")
66 | public ResponseResult listAllOrderDetails(OrderDetailQueryParam orderDetailQueryParam) {
67 | return orderDetailService.listAllOrderDetails(orderDetailQueryParam);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/controller/impl/UserControllerImpl.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.controller.impl;
2 |
3 | import cn.ikarosx.restaurant.aspect.IsOwner;
4 | import cn.ikarosx.restaurant.aspect.NeedAdmin;
5 | import cn.ikarosx.restaurant.controller.UserController;
6 | import cn.ikarosx.restaurant.entity.User;
7 | import cn.ikarosx.restaurant.entity.jpa.Insert;
8 | import cn.ikarosx.restaurant.entity.jpa.Update;
9 | import cn.ikarosx.restaurant.entity.query.UserQueryParam;
10 | import cn.ikarosx.restaurant.exception.CommonCodeEnum;
11 | import cn.ikarosx.restaurant.exception.ResponseResult;
12 | import cn.ikarosx.restaurant.service.UserService;
13 | import io.swagger.annotations.Api;
14 | import io.swagger.annotations.ApiOperation;
15 | import org.apache.commons.lang3.StringUtils;
16 | import org.springframework.beans.factory.annotation.Autowired;
17 | import org.springframework.validation.annotation.Validated;
18 | import org.springframework.web.bind.annotation.*;
19 |
20 | /**
21 | * @author Ikaros
22 | * @date 2020/07/07 22:43
23 | */
24 | @RestController
25 | @RequestMapping("/user")
26 | @Api(tags = "用户管理")
27 | public class UserControllerImpl implements UserController {
28 | @Autowired private UserService userService;
29 |
30 | @Override
31 | @PostMapping("/login")
32 | @ApiOperation("用户登录")
33 | public ResponseResult login(String username, String password) {
34 | if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
35 | return CommonCodeEnum.INVALID_PARAM;
36 | }
37 | return userService.login(username, password);
38 | }
39 |
40 | @Override
41 | @GetMapping("/logout")
42 | @ApiOperation("用户注销")
43 | public ResponseResult logout() {
44 | return userService.logout();
45 | }
46 |
47 | @Override
48 | @PostMapping
49 | @ApiOperation("增加用户,默认是普通用户")
50 | public ResponseResult insertUser(@Validated(Insert.class) @RequestBody User user) {
51 | return userService.insertUser(user);
52 | }
53 |
54 | @Override
55 | @DeleteMapping("/{id}")
56 | @ApiOperation("删除用户")
57 | @IsOwner
58 | public ResponseResult deleteUserById(@PathVariable String id) {
59 | return userService.deleteUserById(id);
60 | }
61 |
62 | @Override
63 | @PutMapping("/{id}")
64 | @ApiOperation("更新用户")
65 | @IsOwner
66 | public ResponseResult updateUser(
67 | @PathVariable String id, @Validated(value = Update.class) @RequestBody User user) {
68 | user.setId(id);
69 | return userService.updateUser(user);
70 | }
71 |
72 | @Override
73 | @GetMapping("/{id}")
74 | @IsOwner
75 | public ResponseResult getUserById(@PathVariable String id) {
76 | return userService.getUserById(id);
77 | }
78 |
79 | @Override
80 | @GetMapping("/{page}/{size}")
81 | @NeedAdmin
82 | public ResponseResult listUsersByPage(
83 | @PathVariable int page, @PathVariable int size, UserQueryParam userQueryParam) {
84 | if (page < 1) {
85 | page = 1;
86 | }
87 | if (size <= 0) {
88 | size = 10;
89 | }
90 | if (userQueryParam == null) {
91 | userQueryParam = new UserQueryParam();
92 | }
93 | return userService.listUsersByPage(page, size, userQueryParam);
94 | }
95 |
96 | @Override
97 | @GetMapping
98 | @NeedAdmin
99 | public ResponseResult listAllUsers() {
100 | return userService.listAllUsers();
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/restaurantServer/src/main/java/cn/ikarosx/restaurant/dao/MenuRepository.java:
--------------------------------------------------------------------------------
1 | package cn.ikarosx.restaurant.dao;
2 |
3 | import cn.ikarosx.restaurant.entity.Menu;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | /**
6 | * @author Ikaros
7 | * @date 2020/07/07 22:43
8 | */
9 | public interface MenuRepository extends JpaRepository