├── .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 | ![image-20200725160228211](https://ikaros-picture.oss-cn-shenzhen.aliyuncs.com/typora/Ikaros/image-20200725160228211.png) 111 | 112 | ![image-20200725160333009](https://ikaros-picture.oss-cn-shenzhen.aliyuncs.com/typora/Ikaros/image-20200725160333009.png) -------------------------------------------------------------------------------- /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 | 6 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /restaurantServer/.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | 6 | -------------------------------------------------------------------------------- /restaurantServer/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /restaurantServer/.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /restaurantServer/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /restaurantServer/.idea/restaurantServer.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /restaurantServer/.idea/saveactions_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 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 {} 10 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/dao/MenuTypeRepository.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.dao; 2 | 3 | import cn.ikarosx.restaurant.entity.MenuType; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | /** 6 | * @author Ikaros 7 | * @date 2020/07/07 22:43 8 | */ 9 | public interface MenuTypeRepository extends JpaRepository {} 10 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/dao/OrderDetailRepository.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.dao; 2 | 3 | import cn.ikarosx.restaurant.entity.OrderDetail; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | /** 6 | * @author Ikaros 7 | * @date 2020/07/07 22:43 8 | */ 9 | public interface OrderDetailRepository extends JpaRepository {} 10 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/dao/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.dao; 2 | 3 | import cn.ikarosx.restaurant.entity.Order; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | /** 6 | * @author Ikaros 7 | * @date 2020/07/07 22:43 8 | */ 9 | public interface OrderRepository extends JpaRepository {} 10 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/dao/UserRepository.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.dao; 2 | 3 | import cn.ikarosx.restaurant.entity.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | /** 6 | * @author Ikaros 7 | * @date 2020/07/07 22:43 8 | */ 9 | public interface UserRepository extends JpaRepository {} 10 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/Menu.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity; 2 | 3 | import lombok.Data; 4 | import org.hibernate.annotations.GenericGenerator; 5 | 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | import javax.persistence.Table; 10 | 11 | /** 12 | * 菜单 13 | * 14 | * @author Ikarosx 15 | * @date 2020/7/7 20:15 16 | */ 17 | @Data 18 | @Entity 19 | @Table 20 | @GenericGenerator(name = "uuid", strategy = "uuid") 21 | public class Menu { 22 | @Id 23 | @GeneratedValue(generator = "uuid") 24 | private String id; 25 | 26 | private String name; 27 | private Double price; 28 | private String type; 29 | } 30 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/MenuType.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity; 2 | 3 | import lombok.Data; 4 | import org.hibernate.annotations.GenericGenerator; 5 | 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | import javax.persistence.Table; 10 | 11 | /** 12 | * 菜系类型 13 | * 14 | * @author Ikarosx 15 | * @date 2020/7/7 20:45 16 | */ 17 | @Data 18 | @Entity 19 | @Table 20 | @GenericGenerator(name = "uuid", strategy = "uuid") 21 | public class MenuType { 22 | @Id 23 | @GeneratedValue(generator = "uuid") 24 | private String id; 25 | 26 | private String name; 27 | } 28 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/Order.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity; 2 | 3 | import lombok.Data; 4 | import org.hibernate.annotations.GenericGenerator; 5 | import org.springframework.data.annotation.CreatedDate; 6 | import org.springframework.data.annotation.LastModifiedDate; 7 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; 8 | 9 | import javax.persistence.*; 10 | import java.util.Date; 11 | 12 | /** 13 | * @author Ikarosx 14 | * @date 2020/7/7 20:49 15 | */ 16 | @Data 17 | @Entity 18 | @Table(name = "orders") 19 | @GenericGenerator(name = "uuid", strategy = "uuid") 20 | @EntityListeners(value = AuditingEntityListener.class) 21 | public class Order { 22 | @Id 23 | @GeneratedValue(generator = "uuid") 24 | private String id; 25 | 26 | private String userId; 27 | private Double sum; 28 | private Integer status; 29 | @CreatedDate private Date createTime; 30 | @LastModifiedDate private Date updateTime; 31 | } 32 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/OrderDetail.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity; 2 | 3 | import lombok.Data; 4 | import org.hibernate.annotations.GenericGenerator; 5 | import org.springframework.data.annotation.CreatedDate; 6 | import org.springframework.data.annotation.LastModifiedDate; 7 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; 8 | 9 | import javax.persistence.*; 10 | import java.util.Date; 11 | 12 | /** 13 | * @author Ikarosx 14 | * @date 2020/7/7 21:24 15 | */ 16 | @Data 17 | @Entity 18 | @Table 19 | @GenericGenerator(name = "uuid", strategy = "uuid") 20 | @EntityListeners(value = AuditingEntityListener.class) 21 | public class OrderDetail { 22 | @Id 23 | @GeneratedValue(generator = "uuid") 24 | private String id; 25 | 26 | private String orderId; 27 | private String menuId; 28 | private String menuName; 29 | private Double price; 30 | private Integer num; 31 | private Double sum; 32 | @CreatedDate private Date createTime; 33 | @LastModifiedDate private Date updateTime; 34 | } 35 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/User.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity; 2 | 3 | import cn.ikarosx.restaurant.entity.jpa.Insert; 4 | import cn.ikarosx.restaurant.entity.jpa.Update; 5 | import lombok.Data; 6 | import org.hibernate.annotations.GenericGenerator; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.data.annotation.CreatedDate; 9 | import org.springframework.data.annotation.LastModifiedDate; 10 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; 11 | 12 | import javax.persistence.*; 13 | import javax.validation.constraints.Max; 14 | import javax.validation.constraints.Min; 15 | import javax.validation.constraints.NotEmpty; 16 | import javax.validation.constraints.NotNull; 17 | import java.util.Date; 18 | 19 | /** 20 | * @author Ikarosx 21 | * @date 2020/7/7 20:48 22 | */ 23 | @Data 24 | @Entity 25 | @Table 26 | @GenericGenerator(name = "uuid", strategy = "uuid") 27 | @EntityListeners(value = AuditingEntityListener.class) 28 | public class User { 29 | @Id 30 | @GeneratedValue(generator = "uuid") 31 | @NotNull(groups = Update.class) 32 | private String id; 33 | 34 | @NotEmpty(groups = {Insert.class}) 35 | private String username; 36 | 37 | @NotEmpty(groups = {Insert.class}) 38 | private String password; 39 | 40 | @Min(0) 41 | @Max(1) 42 | private Integer type; 43 | 44 | @CreatedDate private Date createTime; 45 | @LastModifiedDate private Date updateTime; 46 | } 47 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/jpa/Delete.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity.jpa; 2 | 3 | /** 4 | * @author Ikarosx 5 | * @date 2020/7/10 8:46 6 | */ 7 | public interface Delete { 8 | } 9 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/jpa/Get.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity.jpa; 2 | 3 | /** 4 | * @author Ikarosx 5 | * @date 2020/7/10 8:46 6 | */ 7 | public interface Get { 8 | } 9 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/jpa/Insert.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity.jpa; 2 | 3 | /** 4 | * @author Ikarosx 5 | * @date 2020/7/10 8:46 6 | */ 7 | public interface Insert { 8 | } 9 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/jpa/Update.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity.jpa; 2 | 3 | /** 4 | * @author Ikarosx 5 | * @date 2020/7/10 8:46 6 | */ 7 | public interface Update { 8 | } 9 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/query/MenuQueryParam.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity.query; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author Ikarosx 7 | * @date 2020/7/7 22:44 8 | */ 9 | @Data 10 | public class MenuQueryParam {} 11 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/query/MenuTypeQueryParam.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity.query; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author Ikarosx 7 | * @date 2020/7/7 22:45 8 | */ 9 | @Data 10 | public class MenuTypeQueryParam {} 11 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/query/OrderDetailQueryParam.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity.query; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author Ikarosx 7 | * @date 2020/7/7 22:46 8 | */ 9 | @Data 10 | public class OrderDetailQueryParam { 11 | private String orderId; 12 | } 13 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/query/OrderQueryParam.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity.query; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author Ikarosx 7 | * @date 2020/7/7 22:46 8 | */ 9 | @Data 10 | public class OrderQueryParam { 11 | private String userId; 12 | } 13 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/query/PostOrder.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity.query; 2 | 3 | import cn.ikarosx.restaurant.entity.OrderDetail; 4 | import lombok.Data; 5 | 6 | import javax.validation.constraints.Min; 7 | import javax.validation.constraints.NotNull; 8 | import java.util.List; 9 | 10 | /** 11 | * @author Ikarosx 12 | * @date 2020/7/11 17:08 13 | */ 14 | @Data 15 | public class PostOrder { 16 | @NotNull 17 | @Min(0) 18 | private Double sum; 19 | 20 | @NotNull private String userId; 21 | @NotNull private List orderDetails; 22 | } 23 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/entity/query/UserQueryParam.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.entity.query; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author Ikarosx 7 | * @date 2020/7/7 22:47 8 | */ 9 | @Data 10 | public class UserQueryParam {} 11 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/exception/CommonCodeEnum.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.exception; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | * @author Ikaros 10 | * @date 2020/1/26 16:58 11 | */ 12 | @JsonFormat(shape = JsonFormat.Shape.OBJECT) 13 | public enum CommonCodeEnum implements ResponseResult { 14 | 15 | /** 通用错误代码 10000 */ 16 | SUCCESS(true, 10000, "操作成功!"), 17 | INVALID_PARAM(false, 10001, "非法参数"), 18 | DATA_INTEGRITY_VIOLATION_EXCEPTION(false, 10002, "数据完整性约束异常"), 19 | JSON_PARSE_ERROR0(false, 10003, "json解析失败"), 20 | FILE_SIZE_LIMIT_EXCEEDED(false, 10004, "上传文件过大"), 21 | IO_EXCEPTION(false, 10005, "IO异常"), 22 | DATA_NOT_FOUND(false, 10006, "数据不存在"), 23 | FAIL(false, 11111, "操作失败!"), 24 | SERVER_ERROR(false, 99999, "系统繁忙,请稍后重试!"), 25 | /** 用户相关 11000 */ 26 | USERNAME_OR_PASSWORD_ERROR(false, 11001, "用户名或密码错误"), 27 | RE_LOGIN(false, 11002, "请重新登陆"), 28 | PERMISSION_DENY(false, 11003, "没有操作权限"); 29 | private boolean success; 30 | private int code; 31 | private String message; 32 | private Map data; 33 | 34 | CommonCodeEnum(boolean success, int code, String message) { 35 | this.success = success; 36 | this.code = code; 37 | this.message = message; 38 | } 39 | 40 | @Override 41 | public boolean getSuccess() { 42 | return success; 43 | } 44 | 45 | @Override 46 | public int getCode() { 47 | return code; 48 | } 49 | 50 | @Override 51 | public String getMessage() { 52 | return message; 53 | } 54 | 55 | @Override 56 | public Map getData() { 57 | return data; 58 | } 59 | 60 | public ResponseResult clearData() { 61 | data = null; 62 | return this; 63 | } 64 | 65 | @Override 66 | public ResponseResult addData(Object... objects) { 67 | data = new HashMap<>(); 68 | assert (objects.length & 1) == 0; 69 | for (int i = 0; i < objects.length; i++) { 70 | data.put((String) objects[i], objects[++i]); 71 | } 72 | return this; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/exception/CustomException.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.exception; 2 | 3 | /** 4 | * @author Ikaros 5 | * @date 2020/1/26 18:19 6 | */ 7 | public class CustomException extends RuntimeException { 8 | private ResponseResult responseResult; 9 | 10 | public CustomException() {} 11 | 12 | public CustomException(ResponseResult resultCode) { 13 | super("错误代码:" + resultCode.getCode() + "错误信息:" + resultCode.getMessage()); 14 | this.responseResult = resultCode; 15 | } 16 | 17 | public ResponseResult getResponseResult() { 18 | return responseResult; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/exception/ExceptionCast.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.exception; 2 | 3 | public class ExceptionCast { 4 | /** 使用此静态方法抛出自定义异常 */ 5 | public static void cast(ResponseResult resultCode) { 6 | throw new CustomException(resultCode); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/exception/ExceptionCatch.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.exception; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.hibernate.exception.ConstraintViolationException; 6 | import org.springframework.dao.DataIntegrityViolationException; 7 | import org.springframework.dao.EmptyResultDataAccessException; 8 | import org.springframework.http.converter.HttpMessageNotReadableException; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | import org.springframework.web.bind.annotation.RestControllerAdvice; 11 | 12 | /** 13 | * @author Ikaros 14 | * @date 2020/1/26 18:24 15 | */ 16 | @RestControllerAdvice 17 | @Slf4j 18 | public class ExceptionCatch { 19 | 20 | /** 使用EXCEPTIONS存放异常类型和错误代码的映射, ImmutableMap的特点的一旦创建不可改变,并且线程安全 */ 21 | private static ImmutableMap, ResponseResult> EXCEPTIONS; 22 | 23 | /** 使用builder来构建一个异常类型和错误代码的异常 */ 24 | private static ImmutableMap.Builder, ResponseResult> builder = 25 | ImmutableMap.builder(); 26 | 27 | static { 28 | // 在这里加入一些基础的异常类型判断 29 | builder.put(HttpMessageNotReadableException.class, CommonCodeEnum.INVALID_PARAM); 30 | builder.put( 31 | DataIntegrityViolationException.class, CommonCodeEnum.DATA_INTEGRITY_VIOLATION_EXCEPTION); 32 | } 33 | 34 | @ExceptionHandler(CustomException.class) 35 | public ResponseResult customException(CustomException e) { 36 | log.error("catch exception : {}", e.getMessage()); 37 | return e.getResponseResult(); 38 | } 39 | @ExceptionHandler(EmptyResultDataAccessException.class) 40 | public ResponseResult customException(EmptyResultDataAccessException e) { 41 | log.error("catch exception : {}", e.getMessage()); 42 | // DAO访问数据为空 43 | // TODO 44 | return CommonCodeEnum.SUCCESS.clearData(); 45 | } 46 | 47 | @ExceptionHandler(Exception.class) 48 | public ResponseResult exception(Exception exception) { 49 | // 记录日志 50 | log.error("catch exception:{}", exception.getClass() + "------" + exception.getMessage()); 51 | if (EXCEPTIONS == null) { 52 | EXCEPTIONS = builder.build(); 53 | } 54 | final ResponseResult resultCode = EXCEPTIONS.get(exception.getClass()); 55 | final ResponseResult responseResult; 56 | if (resultCode != null) { 57 | responseResult = resultCode; 58 | } else { 59 | responseResult = CommonCodeEnum.SERVER_ERROR; 60 | } 61 | return responseResult; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/exception/ResponseResult.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.exception; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * @author Ikaros 7 | * @date 2020/1/26 16:59 8 | */ 9 | public interface ResponseResult { 10 | /** @return 操作是否成功, true为成功,false操作失败 */ 11 | boolean getSuccess(); 12 | 13 | /** 14 | * 10000-- 通用错误代码 15 | * 16 | * @return 操作代码 17 | */ 18 | int getCode(); 19 | 20 | /** @return 提示信息 */ 21 | String getMessage(); 22 | 23 | Map getData(); 24 | 25 | ResponseResult addData(Object... objects); 26 | } 27 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/filter/AuthorizationFilter.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.filter; 2 | 3 | import cn.ikarosx.restaurant.exception.CommonCodeEnum; 4 | import cn.ikarosx.restaurant.util.SessionUtils; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import org.apache.commons.lang3.StringUtils; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.filter.OncePerRequestFilter; 11 | 12 | import javax.servlet.FilterChain; 13 | import javax.servlet.ServletException; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | import java.io.IOException; 17 | 18 | /** 19 | * @author Ikarosx 20 | * @date 2020/7/9 12:09 21 | */ 22 | @Component 23 | @Order(100) 24 | public class AuthorizationFilter extends OncePerRequestFilter { 25 | @Override 26 | protected void doFilterInternal( 27 | HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 28 | throws ServletException, IOException { 29 | String requestURI = request.getRequestURI(); 30 | if (requestURI.equals("/user/login") 31 | || (requestURI.equals("/user") 32 | && request.getMethod().equalsIgnoreCase(HttpMethod.POST.name())) 33 | || StringUtils.startsWithAny(requestURI, "/swagger", "/favicon.ico", "/webjars", "/v2")) { 34 | doFilter(request, response, filterChain); 35 | return; 36 | } 37 | Object user = SessionUtils.getAttribute("user"); 38 | if (user != null) { 39 | doFilter(request, response, filterChain); 40 | return; 41 | } 42 | response.setStatus(200); 43 | response.setContentType("application/json;charset=utf-8"); 44 | ObjectMapper objectMapper = new ObjectMapper(); 45 | objectMapper.writeValue(response.getWriter(), CommonCodeEnum.RE_LOGIN); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/filter/CorsFilter.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.filter; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.core.annotation.Order; 5 | import org.springframework.http.HttpMethod; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.web.filter.OncePerRequestFilter; 8 | 9 | import javax.servlet.FilterChain; 10 | import javax.servlet.ServletException; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import java.io.IOException; 14 | 15 | /** 16 | * @author Ikaros 17 | * @date 2020/07/11 09:04 18 | */ 19 | @Component 20 | @Slf4j 21 | @Order(10) 22 | public class CorsFilter extends OncePerRequestFilter { 23 | 24 | @Override 25 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { 26 | response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin")); 27 | response.setHeader("Access-Control-Allow-Credentials", "true"); 28 | response.setHeader("Access-Control-Allow-Headers", "authorization, content-type"); 29 | response.setHeader("Access-Control-Allow-Methods", "POST, GET, DELETE, PUT"); 30 | response.setHeader("Access-Control-Expose-Headers", "x-forwared-port, x-forwared-host"); 31 | response.setHeader("Vary", "Origin,Access-Control-Request-Method,Access-Control-Request-Headers"); 32 | if (request.getMethod().equals(HttpMethod.OPTIONS.name())) { 33 | return; 34 | } 35 | filterChain.doFilter(request, response); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/MenuService.java: -------------------------------------------------------------------------------- 1 | 2 | package cn.ikarosx.restaurant.service; 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 MenuService { 11 | ResponseResult insertMenu( Menu menu); 12 | 13 | ResponseResult deleteMenuById(String id); 14 | 15 | ResponseResult updateMenu(Menu menu); 16 | 17 | ResponseResult getMenuById(String id); 18 | 19 | ResponseResult listMenusByPage(int page, int size, MenuQueryParam menuQueryParam); 20 | 21 | ResponseResult listAllMenus(); 22 | } 23 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/MenuTypeService.java: -------------------------------------------------------------------------------- 1 | 2 | package cn.ikarosx.restaurant.service; 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 MenuTypeService { 11 | ResponseResult insertMenuType( MenuType menuType); 12 | 13 | ResponseResult deleteMenuTypeById(String id); 14 | 15 | ResponseResult updateMenuType(MenuType menuType); 16 | 17 | ResponseResult getMenuTypeById(String id); 18 | 19 | ResponseResult listMenuTypesByPage(int page, int size, MenuTypeQueryParam menuTypeQueryParam); 20 | 21 | ResponseResult listAllMenuTypes(); 22 | } 23 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/OrderDetailService.java: -------------------------------------------------------------------------------- 1 | 2 | package cn.ikarosx.restaurant.service; 3 | import cn.ikarosx.restaurant.entity.OrderDetail; 4 | import cn.ikarosx.restaurant.entity.query.OrderDetailQueryParam; 5 | import cn.ikarosx.restaurant.exception.ResponseResult; 6 | /** 7 | * @author Ikaros 8 | * @date 2020/07/07 22:43 9 | */ 10 | public interface OrderDetailService { 11 | ResponseResult insertOrderDetail( OrderDetail orderDetail); 12 | 13 | ResponseResult deleteOrderDetailById(String id); 14 | 15 | ResponseResult updateOrderDetail(OrderDetail orderDetail); 16 | 17 | ResponseResult getOrderDetailById(String id); 18 | 19 | ResponseResult listOrderDetailsByPage(int page, int size, OrderDetailQueryParam orderDetailQueryParam); 20 | 21 | ResponseResult listAllOrderDetails(OrderDetailQueryParam orderDetailQueryParam); 22 | } 23 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.service; 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 OrderService { 12 | ResponseResult insertOrder(PostOrder order); 13 | 14 | ResponseResult deleteOrderById(String id); 15 | 16 | ResponseResult updateOrder(Order order); 17 | 18 | ResponseResult getOrderById(String id); 19 | 20 | ResponseResult listOrdersByPage(int page, int size, OrderQueryParam orderQueryParam); 21 | 22 | ResponseResult listAllOrders(OrderQueryParam orderQueryParam); 23 | 24 | ResponseResult payOrder(String orderId); 25 | } 26 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/SecurityService.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.service; 2 | 3 | /** 4 | * @author Ikarosx 5 | * @date 2020/7/25 9:34 6 | */ 7 | public interface SecurityService { 8 | boolean orderIdAuth(String orderId); 9 | } 10 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/UserService.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.service; 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 UserService { 11 | ResponseResult insertUser(User user); 12 | 13 | ResponseResult deleteUserById(String id); 14 | 15 | ResponseResult updateUser(User user); 16 | 17 | ResponseResult getUserById(String id); 18 | 19 | ResponseResult listUsersByPage(int page, int size, UserQueryParam userQueryParam); 20 | 21 | ResponseResult listAllUsers(); 22 | 23 | ResponseResult login(String username, String password); 24 | 25 | ResponseResult logout(); 26 | } 27 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/impl/MenuServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.service.impl; 2 | 3 | import cn.ikarosx.restaurant.dao.MenuRepository; 4 | import cn.ikarosx.restaurant.entity.Menu; 5 | import cn.ikarosx.restaurant.entity.query.MenuQueryParam; 6 | import cn.ikarosx.restaurant.exception.CommonCodeEnum; 7 | import cn.ikarosx.restaurant.exception.ExceptionCast; 8 | import cn.ikarosx.restaurant.exception.ResponseResult; 9 | import cn.ikarosx.restaurant.service.MenuService; 10 | import org.springframework.beans.BeanUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.data.domain.*; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.List; 16 | import java.util.Optional; 17 | /** 18 | * @author Ikaros 19 | * @date 2020/07/07 22:43 20 | */ 21 | @Service("MenuService") 22 | public class MenuServiceImpl implements MenuService { 23 | 24 | @Autowired private MenuRepository menuRepository; 25 | 26 | @Override 27 | public ResponseResult insertMenu(Menu menu) { 28 | menuRepository.save(menu); 29 | return CommonCodeEnum.SUCCESS.clearData(); 30 | } 31 | 32 | @Override 33 | public ResponseResult deleteMenuById(String id) { 34 | menuRepository.deleteById(id); 35 | return CommonCodeEnum.SUCCESS.clearData(); 36 | } 37 | 38 | @Override 39 | public ResponseResult updateMenu(Menu menu) { 40 | menuRepository.save(menu); 41 | return CommonCodeEnum.SUCCESS.clearData(); 42 | } 43 | 44 | @Override 45 | public ResponseResult getMenuById(String id) { 46 | Optional optional = menuRepository.findById(id); 47 | Menu menu = optional.orElse(null); 48 | if (menu == null) { 49 | ExceptionCast.cast(CommonCodeEnum.DATA_NOT_FOUND); 50 | } 51 | return CommonCodeEnum.SUCCESS.addData("menu", menu); 52 | } 53 | 54 | @Override 55 | public ResponseResult listMenusByPage(int page, int size, MenuQueryParam menuQueryParam) { 56 | Menu menu = new Menu(); 57 | BeanUtils.copyProperties(menuQueryParam, menu); 58 | // 筛选 59 | ExampleMatcher matcher = 60 | ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING); 61 | Example example = Example.of(menu, matcher); 62 | // 分页 63 | Pageable pageable = PageRequest.of(page - 1, size); 64 | Page menuPage = menuRepository.findAll(example, pageable); 65 | return CommonCodeEnum.SUCCESS.addData( 66 | "list", 67 | menuPage.getContent(), 68 | "total", 69 | menuPage.getTotalElements(), 70 | "totalPage", 71 | menuPage.getTotalPages()); 72 | } 73 | 74 | @Override 75 | public ResponseResult listAllMenus() { 76 | List list = menuRepository.findAll(); 77 | return CommonCodeEnum.SUCCESS.addData("list", list, "total", list.size()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/impl/MenuTypeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.service.impl; 2 | 3 | import cn.ikarosx.restaurant.dao.MenuTypeRepository; 4 | import cn.ikarosx.restaurant.entity.MenuType; 5 | import cn.ikarosx.restaurant.entity.query.MenuTypeQueryParam; 6 | import cn.ikarosx.restaurant.exception.CommonCodeEnum; 7 | import cn.ikarosx.restaurant.exception.ExceptionCast; 8 | import cn.ikarosx.restaurant.exception.ResponseResult; 9 | import cn.ikarosx.restaurant.service.MenuTypeService; 10 | import org.springframework.beans.BeanUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.data.domain.*; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.List; 16 | import java.util.Optional; 17 | /** 18 | * @author Ikaros 19 | * @date 2020/07/07 22:43 20 | */ 21 | @Service("MenuTypeService") 22 | public class MenuTypeServiceImpl implements MenuTypeService { 23 | 24 | @Autowired private MenuTypeRepository menuTypeRepository; 25 | 26 | @Override 27 | public ResponseResult insertMenuType(MenuType menuType) { 28 | menuTypeRepository.save(menuType); 29 | return CommonCodeEnum.SUCCESS.clearData(); 30 | } 31 | 32 | @Override 33 | public ResponseResult deleteMenuTypeById(String id) { 34 | menuTypeRepository.deleteById(id); 35 | return CommonCodeEnum.SUCCESS.clearData(); 36 | } 37 | 38 | @Override 39 | public ResponseResult updateMenuType(MenuType menuType) { 40 | menuTypeRepository.save(menuType); 41 | return CommonCodeEnum.SUCCESS.clearData(); 42 | } 43 | 44 | @Override 45 | public ResponseResult getMenuTypeById(String id) { 46 | Optional optional = menuTypeRepository.findById(id); 47 | MenuType menuType = optional.orElse(null); 48 | if (menuType == null) { 49 | ExceptionCast.cast(CommonCodeEnum.DATA_NOT_FOUND); 50 | } 51 | return CommonCodeEnum.SUCCESS.addData("menuType", menuType); 52 | } 53 | 54 | @Override 55 | public ResponseResult listMenuTypesByPage( 56 | int page, int size, MenuTypeQueryParam menuTypeQueryParam) { 57 | MenuType menuType = new MenuType(); 58 | BeanUtils.copyProperties(menuTypeQueryParam, menuType); 59 | // 筛选 60 | ExampleMatcher matcher = 61 | ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING); 62 | Example example = Example.of(menuType, matcher); 63 | // 分页 64 | Pageable pageable = PageRequest.of(page - 1, size); 65 | Page menuTypePage = menuTypeRepository.findAll(example, pageable); 66 | return CommonCodeEnum.SUCCESS.addData( 67 | "list", 68 | menuTypePage.getContent(), 69 | "total", 70 | menuTypePage.getTotalElements(), 71 | "totalPage", 72 | menuTypePage.getTotalPages()); 73 | } 74 | 75 | @Override 76 | public ResponseResult listAllMenuTypes() { 77 | List list = menuTypeRepository.findAll(); 78 | return CommonCodeEnum.SUCCESS.addData("list", list, "total", list.size()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/impl/OrderDetailServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.service.impl; 2 | 3 | import cn.ikarosx.restaurant.dao.OrderDetailRepository; 4 | import cn.ikarosx.restaurant.entity.OrderDetail; 5 | import cn.ikarosx.restaurant.entity.query.OrderDetailQueryParam; 6 | import cn.ikarosx.restaurant.exception.CommonCodeEnum; 7 | import cn.ikarosx.restaurant.exception.ExceptionCast; 8 | import cn.ikarosx.restaurant.exception.ResponseResult; 9 | import cn.ikarosx.restaurant.service.OrderDetailService; 10 | import org.springframework.beans.BeanUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.data.domain.*; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.List; 16 | import java.util.Optional; 17 | /** 18 | * @author Ikaros 19 | * @date 2020/07/07 22:43 20 | */ 21 | @Service("OrderDetailService") 22 | public class OrderDetailServiceImpl implements OrderDetailService { 23 | 24 | @Autowired private OrderDetailRepository orderDetailRepository; 25 | 26 | @Override 27 | public ResponseResult insertOrderDetail(OrderDetail orderDetail) { 28 | orderDetailRepository.save(orderDetail); 29 | return CommonCodeEnum.SUCCESS.clearData(); 30 | } 31 | 32 | @Override 33 | public ResponseResult deleteOrderDetailById(String id) { 34 | orderDetailRepository.deleteById(id); 35 | return CommonCodeEnum.SUCCESS.clearData(); 36 | } 37 | 38 | @Override 39 | public ResponseResult updateOrderDetail(OrderDetail orderDetail) { 40 | orderDetailRepository.save(orderDetail); 41 | return CommonCodeEnum.SUCCESS.clearData(); 42 | } 43 | 44 | @Override 45 | public ResponseResult getOrderDetailById(String id) { 46 | Optional optional = orderDetailRepository.findById(id); 47 | OrderDetail orderDetail = optional.orElse(null); 48 | if (orderDetail == null) { 49 | ExceptionCast.cast(CommonCodeEnum.DATA_NOT_FOUND); 50 | } 51 | return CommonCodeEnum.SUCCESS.addData("orderDetail", orderDetail); 52 | } 53 | 54 | @Override 55 | public ResponseResult listOrderDetailsByPage( 56 | int page, int size, OrderDetailQueryParam orderDetailQueryParam) { 57 | OrderDetail orderDetail = new OrderDetail(); 58 | BeanUtils.copyProperties(orderDetailQueryParam, orderDetail); 59 | // 筛选 60 | ExampleMatcher matcher = 61 | ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING); 62 | Example example = Example.of(orderDetail, matcher); 63 | // 分页 64 | Pageable pageable = PageRequest.of(page - 1, size); 65 | Page orderDetailPage = orderDetailRepository.findAll(example, pageable); 66 | return CommonCodeEnum.SUCCESS 67 | .addData("list", orderDetailPage.getContent()) 68 | .addData("total", orderDetailPage.getTotalElements()) 69 | .addData("totalPage", orderDetailPage.getTotalPages()); 70 | } 71 | 72 | @Override 73 | public ResponseResult listAllOrderDetails(OrderDetailQueryParam orderDetailQueryParam) { 74 | OrderDetail orderDetail = new OrderDetail(); 75 | BeanUtils.copyProperties(orderDetailQueryParam, orderDetail); 76 | // 筛选 77 | ExampleMatcher matcher = 78 | ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING); 79 | Example example = Example.of(orderDetail, matcher); 80 | List list = orderDetailRepository.findAll(example); 81 | return CommonCodeEnum.SUCCESS.addData("list", list, "total", list.size()); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.service.impl; 2 | 3 | import cn.ikarosx.restaurant.dao.OrderDetailRepository; 4 | import cn.ikarosx.restaurant.dao.OrderRepository; 5 | import cn.ikarosx.restaurant.entity.Order; 6 | import cn.ikarosx.restaurant.entity.OrderDetail; 7 | import cn.ikarosx.restaurant.entity.query.PostOrder; 8 | import cn.ikarosx.restaurant.entity.query.OrderQueryParam; 9 | import cn.ikarosx.restaurant.exception.CommonCodeEnum; 10 | import cn.ikarosx.restaurant.exception.ExceptionCast; 11 | import cn.ikarosx.restaurant.exception.ResponseResult; 12 | import cn.ikarosx.restaurant.service.OrderService; 13 | import cn.ikarosx.restaurant.util.SessionUtils; 14 | import org.springframework.beans.BeanUtils; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.data.domain.*; 17 | import org.springframework.stereotype.Service; 18 | import org.springframework.transaction.annotation.Transactional; 19 | 20 | import java.util.List; 21 | import java.util.Optional; 22 | 23 | /** 24 | * @author Ikaros 25 | * @date 2020/07/07 22:43 26 | */ 27 | @Service("OrderService") 28 | public class OrderServiceImpl implements OrderService { 29 | 30 | @Autowired private OrderRepository orderRepository; 31 | @Autowired private OrderDetailRepository orderDetailRepository; 32 | 33 | @Override 34 | @Transactional(rollbackFor = Exception.class) 35 | public ResponseResult insertOrder(PostOrder postOrder) { 36 | Order order = new Order(); 37 | BeanUtils.copyProperties(postOrder, order); 38 | order.setStatus(0); 39 | order = orderRepository.save(order); 40 | List orderDetails = postOrder.getOrderDetails(); 41 | for (OrderDetail orderDetail : orderDetails) { 42 | orderDetail.setOrderId(order.getId()); 43 | } 44 | orderDetailRepository.saveAll(orderDetails); 45 | return CommonCodeEnum.SUCCESS.addData("orderId", order.getId()); 46 | } 47 | 48 | @Override 49 | public ResponseResult deleteOrderById(String id) { 50 | Order order = new Order(); 51 | order.setUserId(SessionUtils.getId()); 52 | order.setId(id); 53 | orderRepository.delete(order); 54 | return CommonCodeEnum.SUCCESS.clearData(); 55 | } 56 | 57 | @Override 58 | public ResponseResult updateOrder(Order order) { 59 | order.setId(SessionUtils.getId()); 60 | orderRepository.save(order); 61 | return CommonCodeEnum.SUCCESS.clearData(); 62 | } 63 | 64 | @Override 65 | public ResponseResult getOrderById(String id) { 66 | Order order = new Order(); 67 | order.setId(id); 68 | order.setUserId(SessionUtils.getId()); 69 | Optional optional = orderRepository.findOne(Example.of(order)); 70 | order = optional.orElse(null); 71 | if (order == null) { 72 | ExceptionCast.cast(CommonCodeEnum.DATA_NOT_FOUND); 73 | } 74 | return CommonCodeEnum.SUCCESS.addData("order", order); 75 | } 76 | 77 | @Override 78 | public ResponseResult listOrdersByPage(int page, int size, OrderQueryParam orderQueryParam) { 79 | Order order = new Order(); 80 | BeanUtils.copyProperties(orderQueryParam, order); 81 | // 筛选 82 | ExampleMatcher matcher = 83 | ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING); 84 | Example example = Example.of(order, matcher); 85 | // 分页 86 | Pageable pageable = PageRequest.of(page - 1, size); 87 | Page orderPage = orderRepository.findAll(example, pageable); 88 | return CommonCodeEnum.SUCCESS.addData( 89 | "list", 90 | orderPage.getContent(), 91 | "total", 92 | orderPage.getTotalElements(), 93 | "totalPage", 94 | orderPage.getTotalPages()); 95 | } 96 | 97 | @Override 98 | public ResponseResult listAllOrders(OrderQueryParam orderQueryParam) { 99 | Order order = new Order(); 100 | BeanUtils.copyProperties(orderQueryParam, order); 101 | // 筛选 102 | ExampleMatcher matcher = 103 | ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING); 104 | Example example = Example.of(order, matcher); 105 | List list = orderRepository.findAll(example); 106 | return CommonCodeEnum.SUCCESS.addData("list", list, "total", list.size()); 107 | } 108 | 109 | @Override 110 | public ResponseResult payOrder(String orderId) { 111 | Order order = new Order(); 112 | order.setStatus(0); 113 | order.setId(orderId); 114 | Optional optional = orderRepository.findOne(Example.of(order)); 115 | Order order1 = optional.orElse(null); 116 | if (order1 != null) { 117 | order1.setStatus(1); 118 | orderRepository.save(order1); 119 | } 120 | return CommonCodeEnum.SUCCESS.clearData(); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/impl/SecurityServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.service.impl; 2 | 3 | import cn.ikarosx.restaurant.dao.OrderRepository; 4 | import cn.ikarosx.restaurant.entity.Order; 5 | import cn.ikarosx.restaurant.service.SecurityService; 6 | import cn.ikarosx.restaurant.util.SessionUtils; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.Optional; 12 | 13 | /** 14 | * @author Ikarosx 15 | * @date 2020/7/25 9:34 16 | */ 17 | @Service 18 | public class SecurityServiceImpl implements SecurityService { 19 | @Autowired private OrderRepository orderRepository; 20 | /** 21 | * 判断该订单是否属于当前登录用户 22 | * 23 | * @param orderId 24 | * @return 25 | */ 26 | @Override 27 | public boolean orderIdAuth(String orderId) { 28 | Optional orderOptional = orderRepository.findById(orderId); 29 | Order order = orderOptional.orElse(null); 30 | return order != null && StringUtils.equals(order.getUserId(), SessionUtils.getId()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.service.impl; 2 | 3 | import cn.ikarosx.restaurant.dao.UserRepository; 4 | import cn.ikarosx.restaurant.entity.User; 5 | import cn.ikarosx.restaurant.entity.query.UserQueryParam; 6 | import cn.ikarosx.restaurant.exception.CommonCodeEnum; 7 | import cn.ikarosx.restaurant.exception.CustomException; 8 | import cn.ikarosx.restaurant.exception.ExceptionCast; 9 | import cn.ikarosx.restaurant.exception.ResponseResult; 10 | import cn.ikarosx.restaurant.service.UserService; 11 | import cn.ikarosx.restaurant.util.SessionUtils; 12 | import org.springframework.beans.BeanUtils; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.data.domain.*; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.util.DigestUtils; 17 | 18 | import java.util.List; 19 | import java.util.Optional; 20 | /** 21 | * @author Ikaros 22 | * @date 2020/07/07 22:43 23 | */ 24 | @Service("UserService") 25 | public class UserServiceImpl implements UserService { 26 | 27 | @Autowired private UserRepository userRepository; 28 | 29 | @Override 30 | public ResponseResult insertUser(User user) { 31 | if (!SessionUtils.isAdmin()) { 32 | // 如果不是管理员,强制用户类型为普通用户 33 | user.setType(0); 34 | } 35 | user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes())); 36 | userRepository.save(user); 37 | return CommonCodeEnum.SUCCESS.clearData(); 38 | } 39 | 40 | @Override 41 | public ResponseResult deleteUserById(String id) { 42 | userRepository.deleteById(id); 43 | return CommonCodeEnum.SUCCESS.clearData(); 44 | } 45 | 46 | @Override 47 | public ResponseResult updateUser(User user) { 48 | user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes())); 49 | userRepository.save(user); 50 | return CommonCodeEnum.SUCCESS.clearData(); 51 | } 52 | 53 | @Override 54 | public ResponseResult getUserById(String id) { 55 | Optional optional = userRepository.findById(id); 56 | User user = optional.orElse(null); 57 | if (user == null) { 58 | ExceptionCast.cast(CommonCodeEnum.DATA_NOT_FOUND); 59 | } 60 | return CommonCodeEnum.SUCCESS.addData("user", user); 61 | } 62 | 63 | @Override 64 | public ResponseResult listUsersByPage(int page, int size, UserQueryParam userQueryParam) { 65 | User user = new User(); 66 | BeanUtils.copyProperties(userQueryParam, user); 67 | // 筛选 68 | ExampleMatcher matcher = 69 | ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING); 70 | Example example = Example.of(user, matcher); 71 | // 分页 72 | Pageable pageable = PageRequest.of(page - 1, size); 73 | Page userPage = userRepository.findAll(example, pageable); 74 | return CommonCodeEnum.SUCCESS.addData( 75 | "list", 76 | userPage.getContent(), 77 | "total", 78 | userPage.getTotalElements(), 79 | "totalPage", 80 | userPage.getTotalPages()); 81 | } 82 | 83 | @Override 84 | public ResponseResult listAllUsers() { 85 | List list = userRepository.findAll(); 86 | return CommonCodeEnum.SUCCESS.addData("list", list, "total", list.size()); 87 | } 88 | 89 | @Override 90 | public ResponseResult login(String username, String password) { 91 | User user = new User(); 92 | user.setUsername(username); 93 | Example example = Example.of(user); 94 | Optional optional = userRepository.findOne(example); 95 | user = 96 | optional 97 | .map( 98 | u -> 99 | u.getPassword().equals(DigestUtils.md5DigestAsHex(password.getBytes())) 100 | ? u 101 | : null) 102 | .orElseThrow(() -> new CustomException(CommonCodeEnum.USERNAME_OR_PASSWORD_ERROR)); 103 | SessionUtils.setAttribute("user", user); 104 | user.setPassword(null); 105 | return CommonCodeEnum.SUCCESS.addData("user", user); 106 | } 107 | 108 | @Override 109 | public ResponseResult logout() { 110 | SessionUtils.invalidate(); 111 | return CommonCodeEnum.SUCCESS.clearData(); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/util/AuthorizationUtils.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.util; 2 | 3 | import cn.ikarosx.restaurant.entity.User; 4 | import org.apache.commons.lang3.StringUtils; 5 | 6 | /** 7 | * @author Ikarosx 8 | * @date 2020/7/9 12:58 9 | */ 10 | public class AuthorizationUtils { 11 | public static boolean isOwner(String id) { 12 | User user = SessionUtils.getUser(); 13 | return StringUtils.equals(user.getId(), id); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /restaurantServer/src/main/java/cn/ikarosx/restaurant/util/SessionUtils.java: -------------------------------------------------------------------------------- 1 | package cn.ikarosx.restaurant.util; 2 | 3 | import cn.ikarosx.restaurant.entity.User; 4 | import org.springframework.web.context.request.RequestContextHolder; 5 | import org.springframework.web.context.request.ServletRequestAttributes; 6 | 7 | import javax.servlet.http.HttpSession; 8 | 9 | /** 10 | * @author Ikarosx 11 | * @date 2020/7/9 0:48 12 | */ 13 | public class SessionUtils { 14 | public static HttpSession getSession() { 15 | ServletRequestAttributes requestAttributes = 16 | (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 17 | assert requestAttributes != null; 18 | return requestAttributes.getRequest().getSession(); 19 | } 20 | 21 | public static void setAttribute(String key, Object value) { 22 | getSession().setAttribute(key, value); 23 | } 24 | 25 | public static Object getAttribute(String key) { 26 | return getSession().getAttribute(key); 27 | } 28 | 29 | public static void removeAttribute(String key) { 30 | getSession().removeAttribute(key); 31 | } 32 | 33 | public static void invalidate() { 34 | getSession().invalidate(); 35 | } 36 | 37 | public static User getUser() { 38 | return (User) getAttribute("user"); 39 | } 40 | 41 | public static String getId() { 42 | return getUser().getId(); 43 | } 44 | public static boolean isAdmin(){ 45 | User user = getUser(); 46 | return user != null && user.getType() == 1; 47 | } 48 | 49 | public static String getUserName() { 50 | return getUser().getUsername(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /restaurantServer/src/main/resources/application-template.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | username: root 4 | password: newLife2016 5 | url: jdbc:mysql://192.168.1.101:3306/restaurant?useSSL=false&CharacterEncoding=UTF-8 6 | driver-class-name: com.mysql.cj.jdbc.Driver 7 | hikari: 8 | max-lifetime: 900000 9 | minimum-idle: 10 10 | jpa: 11 | # 自动生成表,不过还是建议手动建 12 | generate-ddl: true 13 | database-platform: org.hibernate.dialect.MySQL5InnoDBDialect -------------------------------------------------------------------------------- /restaurantServer/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 80 3 | servlet: 4 | session: 5 | timeout: 30m 6 | cookie: 7 | secure: true 8 | 9 | spring: 10 | profiles: 11 | active: template -------------------------------------------------------------------------------- /restaurantui/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | -------------------------------------------------------------------------------- /restaurantui/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | pnpm-debug.log* 14 | 15 | # Editor directories and files 16 | .idea 17 | .vscode 18 | *.suo 19 | *.ntvs* 20 | *.njsproj 21 | *.sln 22 | *.sw? 23 | -------------------------------------------------------------------------------- /restaurantui/README.md: -------------------------------------------------------------------------------- 1 | # restaurantui 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Run your tests 19 | ``` 20 | npm run test 21 | ``` 22 | 23 | ### Lints and fixes files 24 | ``` 25 | npm run lint 26 | ``` 27 | 28 | ### Customize configuration 29 | See [Configuration Reference](https://cli.vuejs.org/config/). 30 | -------------------------------------------------------------------------------- /restaurantui/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /restaurantui/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "restaurantui", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build" 8 | }, 9 | "dependencies": { 10 | "axios": "^0.21.2", 11 | "core-js": "^3.6.5", 12 | "es6-promise": "^4.2.8", 13 | "js-md5": "^0.7.3", 14 | "sass": "^1.26.10", 15 | "sass-loader": "^9.0.2", 16 | "vue": "^2.6.11", 17 | "vue-router": "^3.2.0", 18 | "vuetify": "^2.6.10" 19 | }, 20 | "devDependencies": { 21 | "@vue/cli-plugin-babel": "^4.4.0", 22 | "@vue/cli-service": "^4.4.0", 23 | "vue-cli-plugin-vuetify": "^2.0.6", 24 | "vue-template-compiler": "^2.6.11" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /restaurantui/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ikarosx/RestaurantOrder/0822bb03f5d65982b75d59be17197fd6a54d8a1b/restaurantui/public/favicon.ico -------------------------------------------------------------------------------- /restaurantui/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 13 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 34 |
35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /restaurantui/src/App.vue: -------------------------------------------------------------------------------- 1 | 34 | 35 | 61 | -------------------------------------------------------------------------------- /restaurantui/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ikarosx/RestaurantOrder/0822bb03f5d65982b75d59be17197fd6a54d8a1b/restaurantui/src/assets/logo.png -------------------------------------------------------------------------------- /restaurantui/src/base/api/login.js: -------------------------------------------------------------------------------- 1 | import http from "./public"; 2 | import qs from "qs" 3 | import { systemConfig } from '@/base/config/system' 4 | var apiUrl = systemConfig.apiUrl 5 | 6 | export const login = params => { 7 | return http.requestPostForm(apiUrl + "/user/login", qs.stringify(params)); 8 | }; 9 | 10 | export const logout =() => { 11 | return http.requestQuickGet(apiUrl + "/user/logout"); 12 | }; 13 | export const register = params => { 14 | return http.requestPost(apiUrl + "/user", params); 15 | }; 16 | 17 | export const getAccessToken = () => { 18 | return http.requestGet(adminApiUrl + "/oauth/jwt"); 19 | }; 20 | -------------------------------------------------------------------------------- /restaurantui/src/base/api/menu.js: -------------------------------------------------------------------------------- 1 | import http from "./public"; 2 | import qs from "qs"; 3 | import { systemConfig } from "@/base/config/system"; 4 | var apiUrl = systemConfig.apiUrl; 5 | 6 | export const listAllMenuType = () => { 7 | return http.requestQuickGet(apiUrl + "/menu/type/all"); 8 | }; 9 | 10 | export const listMenuByPage = (page, size, param) => { 11 | return http.requestQuickGet( 12 | apiUrl + "/menu/" + page + "/" + size + "?" + qs.stringify(param) 13 | ); 14 | }; 15 | 16 | export const listAllMenu = () => { 17 | return http.requestQuickGet(apiUrl + "/menu/all"); 18 | }; 19 | 20 | export const generateOrder = (order) => { 21 | return http.requestPost(apiUrl + "/order", order); 22 | }; 23 | 24 | export const getOrderById = (orderId) => { 25 | return http.requestQuickGet(apiUrl + "/order/" + orderId); 26 | }; 27 | 28 | export const listAllOrderByUserId = (userId) => { 29 | return http.requestQuickGet(apiUrl + "/order?userId=" + userId); 30 | }; 31 | 32 | export const listOrderDetailsByOrderId = (orderId) => { 33 | return http.requestQuickGet(apiUrl + "/order/detail?orderId=" + orderId); 34 | }; 35 | export const insertMenu = (menu) => { 36 | return http.requestPost(apiUrl + "/menu/", menu); 37 | }; 38 | 39 | export const insertMenuType = (menuType) => { 40 | return http.requestPost(apiUrl + "/menu/type", menuType); 41 | }; 42 | -------------------------------------------------------------------------------- /restaurantui/src/base/api/public.js: -------------------------------------------------------------------------------- 1 | require('es6-promise').polyfill() 2 | import axios from 'axios' 3 | axios.defaults.withCredentials = true //跨域 4 | axios.defaults.timeout = 10000 5 | axios.defaults.headers.post['Content-Type'] = 'application/x-www=form-urlencoded' 6 | //axios.defaults.headers['Authorization'] = '' 7 | // 请求之前拦截 8 | /*axios.interceptors.request.use(config => { 9 | // 判断token 10 | //if (localStorage.token) { 11 | config.headers.Authorization = 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MjEwODA4ODYsInVzZXJfbmFtZSI6IjEyMyIsImF1dGhvcml0aWVzIjpbIlJPTEVfQURNSU4iLCJST0xFX1VTRVIiXSwianRpIjoiYTNiM2RiYjgtODJkYS00YWI2LWIwZjEtMWMyZDI5ZjM3MjExIiwiY2xpZW50X2lkIjoibWFuYWdlciIsInNjb3BlIjpbIm1hbmFnZXIiXX0.YivH7foaYfSJs9nPBR40TbJ7T0sGXBGaZV2g8Ivktiatdv0Sjkl4PbS3tsjSBtbyqLekYDLoWSojiDLyvgMy5qskeRLefVk4FYpEMzpxfb5JtaxoIRH0o-Re1MC2quq-J7kxRKAL1DUEmr-_GEEmB8zswYJNwYn3vZK0FMQlbsIty4LCfgIwXfH9XnPcUhojUUIBRUDT2W3s8j-qZQ-iKk1y2kesrXloiOtPEL5CljmlOyZ3GED_HNude5b41TqCQyv2VS1baE9DEPo-P0Hb33rSCMILk3rZg-hO7zuDMGfbGWKMQRgY6Fb2uUtqokYa5aLtXyEwW67FKAi2mK2cPA' 12 | //} 13 | return config 14 | },error =>{ 15 | alert("参数错误", 'fail') 16 | return Promise.reject(error) 17 | })*/ 18 | 19 | export default { 20 | //get请求 21 | requestGet (url, params = {}) { 22 | return new Promise((resolve, reject) => { 23 | let params_v = { 24 | params:params 25 | } 26 | axios.get(url, params_v).then(res => { 27 | resolve(res.data) 28 | }).catch(error => { 29 | reject(error) 30 | }) 31 | }) 32 | }, 33 | //get请求不带参数 34 | requestQuickGet (url) { 35 | return new Promise((resolve, reject) => { 36 | axios.get(url).then(res => { 37 | resolve(res.data) 38 | }).catch(error => { 39 | reject(error) 40 | }) 41 | }) 42 | }, 43 | //post请求 44 | requestPost (url, params = {}) { 45 | return new Promise((resolve, reject) => { 46 | axios.post(url, params).then(res => { 47 | resolve(res.data) 48 | }).catch(error => { 49 | reject(error) 50 | }) 51 | }) 52 | }, 53 | //post请求 54 | requestPostForm (url, params = {}) { 55 | return new Promise((resolve, reject) => { 56 | axios.post(url, params, { 57 | headers: { 58 | 'Content-Type': 'application/x-www-form-urlencoded', 59 | }, 60 | }).then(res => { 61 | resolve(res.data)//注意res是axios封装的对象,res.data才是服务端返回的信息 62 | }).catch(error => { 63 | reject(error) 64 | }) 65 | }) 66 | }, 67 | //put请求 68 | requestPut (url, params = {}) { 69 | return new Promise((resolve, reject) => { 70 | axios.put(url, params).then(res => { 71 | resolve(res.data) 72 | }).catch(error => { 73 | reject(error) 74 | }) 75 | }) 76 | }, 77 | //delete请求 78 | requestDelete (url, params = {}) { 79 | return new Promise((resolve, reject) => { 80 | axios.delete(url, params).then(res => { 81 | resolve(res.data) 82 | }).catch(error => { 83 | reject(error) 84 | }) 85 | }) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /restaurantui/src/base/components/snackbar/Snackbar.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 42 | 43 | -------------------------------------------------------------------------------- /restaurantui/src/base/components/snackbar/index.js: -------------------------------------------------------------------------------- 1 | import Snackbar from "./Snackbar.vue"; 2 | import vuetify from "@/plugins/vuetify"; 3 | import Vue from "vue"; 4 | 5 | const v = new Vue({ 6 | vuetify, 7 | render(createElement) { 8 | return createElement(Snackbar); 9 | } 10 | }); 11 | 12 | v.$mount(); 13 | 14 | document.body.appendChild(v.$el); 15 | 16 | const snackbar = v.$children[0]; 17 | 18 | function info(mes) { 19 | snackbar.info(mes); 20 | } 21 | 22 | function error(mes) { 23 | snackbar.error(mes); 24 | } 25 | 26 | function warning(mes) { 27 | snackbar.warning(mes); 28 | } 29 | 30 | function success(mes) { 31 | snackbar.success(mes); 32 | } 33 | export default { 34 | info, 35 | success, 36 | warning, 37 | error 38 | }; 39 | -------------------------------------------------------------------------------- /restaurantui/src/base/config/router.js: -------------------------------------------------------------------------------- 1 | import VueRouter from "vue-router"; 2 | import Vue from "vue"; 3 | import routes from "@/router"; 4 | Vue.use(VueRouter); 5 | const router = new VueRouter({ 6 | routes: routes, 7 | // mode: "history" 8 | }); 9 | 10 | router.beforeEach((to, from, next) => { 11 | //!***********身份校验*************** 12 | var user = window.localStorage.getItem("user"); 13 | if (to.path == "/") { 14 | next({ path: "/menu" }); 15 | } else if (user != null && to.path == "/login") { 16 | next({ path: "/menu" }); 17 | } else if (user != null || to.path == "/login") { 18 | next(); 19 | } else { 20 | next({ path: "/login" }); 21 | } 22 | }); 23 | // 授权 24 | // router.afterEach((to, from, next) => { 25 | // if (openAuthorize) { 26 | // let activeUser; 27 | // try { 28 | // activeUser = utilApi.getActiveUser(); 29 | // } catch (e) { 30 | // //alert(e) 31 | // } 32 | // if (activeUser) { 33 | // //权限校验 34 | // let requiresAuth = to.meta.requiresAuth; 35 | // let permission = to.meta.permission; 36 | // if (requiresAuth && permission) { 37 | // utilApi.checkAuthorities(router, permission); 38 | // } 39 | // } 40 | // } 41 | // }); 42 | 43 | import axios from "axios"; 44 | import * as loginApi from "@/base/api/login"; 45 | // 添加请求拦截器 46 | // axios.interceptors.request.use( 47 | // (config) => { 48 | // // 在发送请求向header添加jwt 49 | // let token = localStorage.getItem("access_token"); 50 | // if (token) { 51 | // config.headers["Authorization"] = "bearer " + token; 52 | // } 53 | // return config; 54 | // }, 55 | // (error) => { 56 | // return Promise.reject(error); 57 | // } 58 | // ); 59 | // 响应拦截 60 | axios.interceptors.response.use((data) => { 61 | if (data && data.data) { 62 | if (data.data.code == "11002") { 63 | window.localStorage.removeItem('user'); 64 | router.push('/login') 65 | } else if (data.data.code && data.data.code == "401") { 66 | 67 | } 68 | } 69 | return data; 70 | }); 71 | 72 | export default router; 73 | -------------------------------------------------------------------------------- /restaurantui/src/base/config/system.js: -------------------------------------------------------------------------------- 1 | export const systemConfig = { 2 | apiUrl: "http://127.0.0.1", 3 | }; -------------------------------------------------------------------------------- /restaurantui/src/components/addMenu.vue: -------------------------------------------------------------------------------- 1 | 47 | -------------------------------------------------------------------------------- /restaurantui/src/components/login.vue: -------------------------------------------------------------------------------- 1 | 43 | -------------------------------------------------------------------------------- /restaurantui/src/components/menu.vue: -------------------------------------------------------------------------------- 1 | 49 | -------------------------------------------------------------------------------- /restaurantui/src/components/orderHistory.vue: -------------------------------------------------------------------------------- 1 | 33 | -------------------------------------------------------------------------------- /restaurantui/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import App from "./App.vue"; 3 | import router from "@/base/config/router"; 4 | import vuetify from "@/plugins/vuetify"; // path to vuetify export 5 | import qs from "qs"; 6 | 7 | Vue.config.productionTip = false; 8 | var store = { 9 | debug: true, 10 | state: { 11 | username: "", 12 | }, 13 | setUsernameAction(newValue) { 14 | this.state.username = newValue; 15 | }, 16 | clearUsernameAction() { 17 | this.state.username = ""; 18 | }, 19 | }; 20 | var user = qs.parse(localStorage.getItem("user")); 21 | var username = ""; 22 | var userId = ""; 23 | if (user != null) { 24 | username = user.username; 25 | userId = user.id; 26 | } 27 | // 引入snackbar 28 | import snackbar from "@/base/components/snackbar"; 29 | Vue.prototype.$snackbar = snackbar; 30 | new Vue({ 31 | router, 32 | vuetify, 33 | data: { 34 | username: username, 35 | userId: userId, 36 | }, 37 | render: (h) => h(App), 38 | }).$mount("#app"); 39 | -------------------------------------------------------------------------------- /restaurantui/src/plugins/vuetify.js: -------------------------------------------------------------------------------- 1 | // src/plugins/vuetify.js 2 | 3 | import Vue from 'vue' 4 | import Vuetify from 'vuetify' 5 | import 'vuetify/dist/vuetify.min.css' 6 | Vue.use(Vuetify) 7 | 8 | const opts = {} 9 | 10 | export default new Vuetify(opts) -------------------------------------------------------------------------------- /restaurantui/src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueRouter from 'vue-router' 3 | 4 | 5 | const routes = [ 6 | { 7 | path: '/login', 8 | name: 'Login', 9 | component: () => import(/* webpackChunkName: "about" */ '../components/login.vue') 10 | }, 11 | { 12 | path: '/menu', 13 | name: 'Menu', 14 | // route level code-splitting 15 | // this generates a separate chunk (about.[hash].js) for this route 16 | // which is lazy-loaded when the route is visited. 17 | component: () => import(/* webpackChunkName: "about" */ '../components/menu.vue') 18 | }, 19 | { 20 | path: '/admin/menu/add', 21 | name: 'AdminMenuAdd', 22 | // route level code-splitting 23 | // this generates a separate chunk (about.[hash].js) for this route 24 | // which is lazy-loaded when the route is visited. 25 | component: () => import(/* webpackChunkName: "about" */ '../components/addMenu.vue') 26 | }, 27 | { 28 | path: '/order/history', 29 | name: 'orderHistory', 30 | // route level code-splitting 31 | // this generates a separate chunk (about.[hash].js) for this route 32 | // which is lazy-loaded when the route is visited. 33 | component: () => import(/* webpackChunkName: "about" */ '../components/orderHistory.vue') 34 | } 35 | ] 36 | 37 | export default routes 38 | -------------------------------------------------------------------------------- /restaurantui/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | chainWebpack: (config) => { 3 | config.plugin("html").tap((args) => { 4 | args[0].title = "Is点餐系统"; 5 | return args; 6 | }); 7 | }, 8 | configureWebpack: { 9 | resolve: { 10 | extensions: [".js", ".json", ".vue", ".scss", ".css"], 11 | }, 12 | externals: { 13 | vue: "Vue", 14 | "vue-router": "VueRouter", 15 | // vuetify: "Vuetify", 16 | axios: "axios", 17 | }, 18 | }, 19 | }; 20 | -------------------------------------------------------------------------------- /restaurantui/webpack.config.js: -------------------------------------------------------------------------------- 1 | // webpack.config.js 2 | 3 | module.exports = { 4 | rules: [ 5 | { 6 | test: /\.s(c|a)ss$/, 7 | use: [ 8 | 'vue-style-loader', 9 | 'css-loader', 10 | { 11 | loader: 'sass-loader', 12 | // Requires sass-loader@^7.0.0 13 | options: { 14 | implementation: require('sass'), 15 | fiber: require('fibers'), 16 | indentedSyntax: true // optional 17 | }, 18 | // Requires sass-loader@^8.0.0 19 | options: { 20 | implementation: require('sass'), 21 | sassOptions: { 22 | fiber: require('fibers'), 23 | indentedSyntax: true // optional 24 | }, 25 | }, 26 | }, 27 | ], 28 | }, 29 | ], 30 | } --------------------------------------------------------------------------------