项目初始化
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/qauMa.iml" filepath="$PROJECT_DIR$/.idea/qauMa.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
After Width: | Height: | Size: 176 KiB |
After Width: | Height: | Size: 635 KiB |
After Width: | Height: | Size: 147 KiB |
|
@ -0,0 +1,380 @@
|
|||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 80019
|
||||
Source Host : localhost:3306
|
||||
Source Schema : electronic_mall
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 80019
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 10/08/2023 20:33:14
|
||||
*/
|
||||
|
||||
SET NAMES utf8;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for address
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `address`;
|
||||
CREATE TABLE `address` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`link_user` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '联系人',
|
||||
`link_address` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '地址',
|
||||
`link_phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '电话',
|
||||
`user_id` bigint(0) NULL DEFAULT NULL COMMENT '所属用户',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '地址表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of address
|
||||
-- ----------------------------
|
||||
INSERT INTO `address` VALUES (1, '张三', '北京市', '13333333333', 1);
|
||||
INSERT INTO `address` VALUES (2, '张三', '北京市', '15888888888', 2);
|
||||
INSERT INTO `address` VALUES (3, '张三', '上海市', '15555555555', 2);
|
||||
INSERT INTO `address` VALUES (4, '张三', '新疆', '15888888888', 2);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for avatar
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `avatar`;
|
||||
CREATE TABLE `avatar` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
|
||||
`size` bigint(0) NULL DEFAULT NULL,
|
||||
`url` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
|
||||
`md5` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '头像表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of avatar
|
||||
-- ----------------------------
|
||||
INSERT INTO `avatar` VALUES (2, 'jpg', 492, '/avatar/978418fbe75243b4ba38da389a468b78.jpg', '1e5802c8b96198fd524cc91ad3f9d476');
|
||||
INSERT INTO `avatar` VALUES (3, 'jpg', 146, '/avatar/e8663626d17b41bd89707299fcd5ac81.jpg', '5c072037e4e9662831fe448e28795770');
|
||||
INSERT INTO `avatar` VALUES (4, 'jpg', 175, '/avatar/09cd5add81ff4abfbd1ccf91b2e9c820.jpg', '507704f05fbca53793bce9970b40e6c8');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for carousel
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `carousel`;
|
||||
CREATE TABLE `carousel` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`good_id` bigint(0) NULL DEFAULT NULL COMMENT '对应的商品id',
|
||||
`show_order` int(0) NULL DEFAULT NULL COMMENT '播放顺序',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '轮播图表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of carousel
|
||||
-- ----------------------------
|
||||
INSERT INTO `carousel` VALUES (4, 5, 2);
|
||||
INSERT INTO `carousel` VALUES (5, 4, 3);
|
||||
INSERT INTO `carousel` VALUES (6, 7, 4);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for cart
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `cart`;
|
||||
CREATE TABLE `cart` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`count` int(0) NULL DEFAULT NULL COMMENT '数量',
|
||||
`create_time` datetime NULL DEFAULT NULL COMMENT '加入时间',
|
||||
`good_id` bigint(0) NULL DEFAULT NULL COMMENT '商品id',
|
||||
`standard` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
|
||||
`user_id` bigint(0) NULL DEFAULT NULL COMMENT '用户id',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '购物车表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of cart
|
||||
-- ----------------------------
|
||||
INSERT INTO `cart` VALUES (2, 1, '2023-07-15 13:48:00', 2, 'M 中码', 2);
|
||||
INSERT INTO `cart` VALUES (3, 1, '2023-07-15 13:48:04', 5, '白色', 2);
|
||||
INSERT INTO `cart` VALUES (4, 1, '2023-07-15 13:48:08', 7, '43码', 2);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for category
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `category`;
|
||||
CREATE TABLE `category` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '类别名称',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '分类表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of category
|
||||
-- ----------------------------
|
||||
INSERT INTO `category` VALUES (1, '女装');
|
||||
INSERT INTO `category` VALUES (2, '男装');
|
||||
INSERT INTO `category` VALUES (10, '运动鞋');
|
||||
INSERT INTO `category` VALUES (11, '休闲鞋');
|
||||
INSERT INTO `category` VALUES (12, '靴子');
|
||||
INSERT INTO `category` VALUES (13, '办公用品');
|
||||
INSERT INTO `category` VALUES (14, '书籍');
|
||||
INSERT INTO `category` VALUES (15, '笔记本');
|
||||
INSERT INTO `category` VALUES (16, '手机');
|
||||
INSERT INTO `category` VALUES (17, '平板电脑');
|
||||
INSERT INTO `category` VALUES (18, '烹饪食材');
|
||||
INSERT INTO `category` VALUES (19, '白酒');
|
||||
INSERT INTO `category` VALUES (20, '茶叶');
|
||||
INSERT INTO `category` VALUES (21, '咖啡');
|
||||
INSERT INTO `category` VALUES (22, '宠物用品');
|
||||
INSERT INTO `category` VALUES (23, '宠物饲料');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for good
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `good`;
|
||||
CREATE TABLE `good` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '商品名称',
|
||||
`description` varchar(1600) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '描述',
|
||||
`discount` double(10, 2) NOT NULL DEFAULT 1.00 COMMENT '折扣',
|
||||
`sales` bigint(0) NOT NULL DEFAULT 0 COMMENT '销量',
|
||||
`sale_money` double(10, 2) NULL DEFAULT 0.00 COMMENT '销售额',
|
||||
`category_id` bigint(0) NULL DEFAULT NULL COMMENT '分类id',
|
||||
`imgs` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '商品图片',
|
||||
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
|
||||
`recommend` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否推荐。0不推荐,1推荐',
|
||||
`is_delete` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否删除,0未删除,1删除',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '商品表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of good
|
||||
-- ----------------------------
|
||||
INSERT INTO `good` VALUES (2, '衬衫', '鳄鱼夹克男春季新款休闲百搭翻领外套男中青年时尚潮流夹克衫男装上衣 绿色 XL(130-145斤)', 0.95, 35, 13700.50, 2, '/file/74488020672944968462e9e4a9c89096.png', '2023-03-27 13:32:44', 1, 0);
|
||||
INSERT INTO `good` VALUES (3, '桌椅套装', '这款桌椅套装是您家庭和办公室的理想选择。精心设计的桌子和舒适的椅子,完美结合,给您带来了坐姿舒适和优雅的工作环境。优质材料和坚固的结构确保您享受长久的使用寿命。', 0.98, 0, 0.00, 13, '/file/b4ac53ed62c74c298366619399c39f99.jpg', '2023-03-31 20:44:00', 1, 0);
|
||||
INSERT INTO `good` VALUES (4, '威士忌 大瓶', '这款洋酒是一款精心酿造的上乘佳酿,给您带来无与伦比的品尝享受。精选优质的原料,经过精心的发酵和蒸馏工艺,使得这款洋酒口感柔和,回味悠长。', 0.80, 0, 0.00, 19, '/file/be9d2d6a17c5436fb0b8c2f7927484b2.jpg', '2023-03-31 20:46:37', 1, 0);
|
||||
INSERT INTO `good` VALUES (5, '女上衣', '酒红色圆领短袖T恤女休闲2023年新款上衣修身拼色女装S8220334 白色 XL', 0.80, 1, 116.00, 1, '/file/15cb9fc604984dfa97e0e968eb1d196d.jpg', '2023-03-31 20:47:59', 1, 0);
|
||||
INSERT INTO `good` VALUES (6, '《PSALMS》英文版 图书', '《PSALMS》英文版是一本精美的图书,专门收录了许多有趣的诗篇。这本书为读者带来了感人至深的心灵之旅。', 1.00, 0, 0.00, 14, '/file/8dc5354c7332454796c614bb4a0572fb.jpg', '2023-03-31 20:48:51', 1, 0);
|
||||
INSERT INTO `good` VALUES (7, '休闲鞋', '男士运动休闲鞋软底网面鞋健步鞋黑灰色42', 0.96, 1, 110.40, 11, '/file/0afa4eb1c51943808f6e83cd9ced25e8.jpg', '2023-03-31 20:49:36', 1, 0);
|
||||
INSERT INTO `good` VALUES (8, '123', '123', 1.00, 43, 5289.00, 1, '/file/09bb6edab07a4c68a44cce41a3300d97.jpg', '2023-06-12 00:55:57', 0, 1);
|
||||
INSERT INTO `good` VALUES (9, '儿童简笔画册', '适合儿童简笔画上色的底稿', 1.00, 0, 0.00, 13, '/file/2e2a1df657324a3293642344327310cb.png', '2023-08-10 20:28:58', 1, 0);
|
||||
INSERT INTO `good` VALUES (10, '墨镜', '抵抗紫外线', 1.00, 0, 0.00, 13, '/file/449ab0163ba648c08cb4a76b40a9dcec.jpg', '2023-08-10 20:29:47', 1, 0);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for good_standard
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `good_standard`;
|
||||
CREATE TABLE `good_standard` (
|
||||
`good_id` bigint(0) NULL DEFAULT NULL COMMENT '商品id',
|
||||
`value` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '规格',
|
||||
`price` decimal(10, 2) NULL DEFAULT NULL COMMENT '价格',
|
||||
`store` bigint(0) NULL DEFAULT NULL COMMENT '库存'
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '商品规格表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of good_standard
|
||||
-- ----------------------------
|
||||
INSERT INTO `good_standard` VALUES (8, '123', 123.00, 80);
|
||||
INSERT INTO `good_standard` VALUES (5, '白色', 145.00, 299);
|
||||
INSERT INTO `good_standard` VALUES (7, '43码', 115.00, 149);
|
||||
INSERT INTO `good_standard` VALUES (6, '英文版', 99.00, 500);
|
||||
INSERT INTO `good_standard` VALUES (4, '单瓶', 2600.00, 500);
|
||||
INSERT INTO `good_standard` VALUES (4, '三瓶送礼套装', 6100.00, 900);
|
||||
INSERT INTO `good_standard` VALUES (3, '桌子', 90.00, 600);
|
||||
INSERT INTO `good_standard` VALUES (3, '椅子', 50.00, 500);
|
||||
INSERT INTO `good_standard` VALUES (3, '桌子+椅子', 150.00, 500);
|
||||
INSERT INTO `good_standard` VALUES (2, 'S 小码', 129.00, 498);
|
||||
INSERT INTO `good_standard` VALUES (2, 'M 中码', 129.00, 496);
|
||||
INSERT INTO `good_standard` VALUES (2, 'L 大码', 129.00, 496);
|
||||
INSERT INTO `good_standard` VALUES (9, '标准版', 50.00, 600);
|
||||
INSERT INTO `good_standard` VALUES (10, '标准30cm', 60.00, 500);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for icon
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `icon`;
|
||||
CREATE TABLE `icon` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`value` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '图标的识别码',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 22 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '图标表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of icon
|
||||
-- ----------------------------
|
||||
INSERT INTO `icon` VALUES (1, '');
|
||||
INSERT INTO `icon` VALUES (15, '');
|
||||
INSERT INTO `icon` VALUES (16, '');
|
||||
INSERT INTO `icon` VALUES (17, '');
|
||||
INSERT INTO `icon` VALUES (18, '');
|
||||
INSERT INTO `icon` VALUES (19, '');
|
||||
INSERT INTO `icon` VALUES (21, '');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for icon_category
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `icon_category`;
|
||||
CREATE TABLE `icon_category` (
|
||||
`category_id` bigint(0) NOT NULL COMMENT '分类id',
|
||||
`icon_id` bigint(0) NOT NULL COMMENT '图标id',
|
||||
PRIMARY KEY (`category_id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '商品分类 - 图标关联表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of icon_category
|
||||
-- ----------------------------
|
||||
INSERT INTO `icon_category` VALUES (1, 1);
|
||||
INSERT INTO `icon_category` VALUES (2, 1);
|
||||
INSERT INTO `icon_category` VALUES (10, 15);
|
||||
INSERT INTO `icon_category` VALUES (11, 15);
|
||||
INSERT INTO `icon_category` VALUES (12, 15);
|
||||
INSERT INTO `icon_category` VALUES (13, 16);
|
||||
INSERT INTO `icon_category` VALUES (14, 16);
|
||||
INSERT INTO `icon_category` VALUES (15, 17);
|
||||
INSERT INTO `icon_category` VALUES (16, 17);
|
||||
INSERT INTO `icon_category` VALUES (17, 17);
|
||||
INSERT INTO `icon_category` VALUES (18, 18);
|
||||
INSERT INTO `icon_category` VALUES (19, 19);
|
||||
INSERT INTO `icon_category` VALUES (20, 19);
|
||||
INSERT INTO `icon_category` VALUES (21, 19);
|
||||
INSERT INTO `icon_category` VALUES (22, 21);
|
||||
INSERT INTO `icon_category` VALUES (23, 21);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for order_goods
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `order_goods`;
|
||||
CREATE TABLE `order_goods` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`order_id` bigint(0) NULL DEFAULT NULL COMMENT '订单id',
|
||||
`good_id` bigint(0) NULL DEFAULT NULL COMMENT '商品id',
|
||||
`count` int(0) NULL DEFAULT NULL COMMENT '数量',
|
||||
`standard` varchar(1600) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '规格',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of order_goods
|
||||
-- ----------------------------
|
||||
INSERT INTO `order_goods` VALUES (9, 9, 2, 3, 'M 中码');
|
||||
INSERT INTO `order_goods` VALUES (10, 10, 2, 3, 'L 大码');
|
||||
INSERT INTO `order_goods` VALUES (11, 11, 2, 1, 'S 小码');
|
||||
INSERT INTO `order_goods` VALUES (12, 12, 8, 1, '123');
|
||||
INSERT INTO `order_goods` VALUES (13, 13, 8, 12, '123');
|
||||
INSERT INTO `order_goods` VALUES (14, 14, 8, 1, '123');
|
||||
INSERT INTO `order_goods` VALUES (15, 15, 8, 1, '123');
|
||||
INSERT INTO `order_goods` VALUES (16, 16, 8, 15, '123');
|
||||
INSERT INTO `order_goods` VALUES (17, 17, 8, 1, '123');
|
||||
INSERT INTO `order_goods` VALUES (18, 18, 8, 1, '123');
|
||||
INSERT INTO `order_goods` VALUES (19, 19, 8, 11, '123');
|
||||
INSERT INTO `order_goods` VALUES (20, 20, 2, 1, 'M 中码');
|
||||
INSERT INTO `order_goods` VALUES (21, 21, 2, 1, 'L 大码');
|
||||
INSERT INTO `order_goods` VALUES (22, 22, 7, 1, '43码');
|
||||
INSERT INTO `order_goods` VALUES (23, 23, 2, 1, 'S 小码');
|
||||
INSERT INTO `order_goods` VALUES (24, 24, 5, 1, '白色');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for standard
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `standard`;
|
||||
CREATE TABLE `standard` (
|
||||
`goodId` bigint(0) NOT NULL COMMENT '商品id',
|
||||
`value` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '商品规格',
|
||||
`price` decimal(10, 2) NULL DEFAULT NULL COMMENT '该规格的价格',
|
||||
`store` bigint(0) NULL DEFAULT NULL COMMENT '该规格的库存',
|
||||
PRIMARY KEY (`goodId`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '规格表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_file
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `sys_file`;
|
||||
CREATE TABLE `sys_file` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '文件名称',
|
||||
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '文件类型',
|
||||
`size` bigint(0) NULL DEFAULT NULL COMMENT '大小',
|
||||
`url` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '文件路径',
|
||||
`is_delete` tinyint(1) NULL DEFAULT NULL COMMENT '是否删除',
|
||||
`enable` tinyint(1) NULL DEFAULT NULL COMMENT '是否启用',
|
||||
`md5` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT 'md5值',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 34 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '系统文件表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_file
|
||||
-- ----------------------------
|
||||
INSERT INTO `sys_file` VALUES (7, '07.jpg', 'jpg', 1814, '/file/7dfd10628edc4b4e97de19c1cb86585e.jpg', 0, 0, '04271616ebc6914643c3af592dd58bef');
|
||||
INSERT INTO `sys_file` VALUES (8, '9a49edb823cc4cb799cb3438a7419a83.jpg', 'jpg', 132, '/file/2b6249b9ba24491a9048c1e8c0b5256e.jpg', 0, 0, 'f11ed5acc29b90770a453eceb7524712');
|
||||
INSERT INTO `sys_file` VALUES (9, '9a49edb823cc4cb799cb3438a7419a83.jpg', 'jpg', 132, '/file/2b6249b9ba24491a9048c1e8c0b5256e.jpg', 0, 0, 'f11ed5acc29b90770a453eceb7524712');
|
||||
INSERT INTO `sys_file` VALUES (10, '9a49edb823cc4cb799cb3438a7419a83.jpg', 'jpg', 132, '/file/2b6249b9ba24491a9048c1e8c0b5256e.jpg', 0, 0, 'f11ed5acc29b90770a453eceb7524712');
|
||||
INSERT INTO `sys_file` VALUES (11, '9a49edb823cc4cb799cb3438a7419a83.jpg', 'jpg', 132, '/file/2b6249b9ba24491a9048c1e8c0b5256e.jpg', 0, 0, 'f11ed5acc29b90770a453eceb7524712');
|
||||
INSERT INTO `sys_file` VALUES (12, '5a776cc21c1b407bbd2595a7af726a61.jpg', 'jpg', 846, '/file/0e8132c00dc6484faa18b2d1487b34ec.jpg', 0, 0, '8f0a34a66bbc1a794b7c138897a66dad');
|
||||
INSERT INTO `sys_file` VALUES (13, '5a776cc21c1b407bbd2595a7af726a61.jpg', 'jpg', 846, '/file/0e8132c00dc6484faa18b2d1487b34ec.jpg', 0, 0, '8f0a34a66bbc1a794b7c138897a66dad');
|
||||
INSERT INTO `sys_file` VALUES (14, '5a776cc21c1b407bbd2595a7af726a61.jpg', 'jpg', 846, '/file/0e8132c00dc6484faa18b2d1487b34ec.jpg', 0, 0, '8f0a34a66bbc1a794b7c138897a66dad');
|
||||
INSERT INTO `sys_file` VALUES (15, '5a776cc21c1b407bbd2595a7af726a61.jpg', 'jpg', 846, '/file/0e8132c00dc6484faa18b2d1487b34ec.jpg', 0, 0, '8f0a34a66bbc1a794b7c138897a66dad');
|
||||
INSERT INTO `sys_file` VALUES (16, '5a776cc21c1b407bbd2595a7af726a61.jpg', 'jpg', 846, '/file/0e8132c00dc6484faa18b2d1487b34ec.jpg', 0, 0, '8f0a34a66bbc1a794b7c138897a66dad');
|
||||
INSERT INTO `sys_file` VALUES (17, '5a776cc21c1b407bbd2595a7af726a61.jpg', 'jpg', 846, '/file/0e8132c00dc6484faa18b2d1487b34ec.jpg', 0, 0, '8f0a34a66bbc1a794b7c138897a66dad');
|
||||
INSERT INTO `sys_file` VALUES (18, '02.jpg', 'jpg', 33, '/file/84ad8a9829424254811ce2220edc2d3b.jpg', 0, 0, 'fcf09e93c497c75cf2b3656f80f997cc');
|
||||
INSERT INTO `sys_file` VALUES (19, '01.jpg', 'jpg', 26, '/file/cef757d124ec4b169cffd65de5e3c47c.jpg', 0, 0, 'd5b6bb3b068c1980d77c59079248a4a4');
|
||||
INSERT INTO `sys_file` VALUES (20, '03.jpg', 'jpg', 22, '/file/7791be8ea1ee4aa0a149ae8e75c857d6.jpg', 0, 0, '75e8b3e8790e514fb799857f636a1623');
|
||||
INSERT INTO `sys_file` VALUES (21, '04.jpg', 'jpg', 25, '/file/867aaf026b684b1e8b1a10c87e31df7e.jpg', 0, 0, '1d7397d5a4ce0995f711a1484d593f44');
|
||||
INSERT INTO `sys_file` VALUES (22, '05.jpg', 'jpg', 19, '/file/f9f26a01e13d4ba68d7f7bd12df282e0.jpg', 0, 0, 'b2d243af2652abf08a491074c8f099ea');
|
||||
INSERT INTO `sys_file` VALUES (23, '06.jpg', 'jpg', 11, '/file/286aa7816325455b8cdcd522aca833fe.jpg', 0, 0, 'c160a645c3dacb58ffb123a4239dcb50');
|
||||
INSERT INTO `sys_file` VALUES (24, '037c5b1f3e40406893b423563c557a91.jpg', 'jpg', 1641, '/file/09bb6edab07a4c68a44cce41a3300d97.jpg', 0, 0, '067143803d2f87dcb939de5d4ace2bbb');
|
||||
INSERT INTO `sys_file` VALUES (25, '01.jpg', 'jpg', 329, '/file/15cb9fc604984dfa97e0e968eb1d196d.jpg', 0, 0, '8c78b307ff66fbc7db624da25138f480');
|
||||
INSERT INTO `sys_file` VALUES (26, '02.jpg', 'jpg', 738, '/file/e2cf8486c2384b8296972a550bf7e934.jpg', 0, 0, '7db1f7335529ad2a68367d29d0441695');
|
||||
INSERT INTO `sys_file` VALUES (27, '04.jpg', 'jpg', 158, '/file/0afa4eb1c51943808f6e83cd9ced25e8.jpg', 0, 0, '0bfaaafc7ca1a9a5478baa8c9cae492c');
|
||||
INSERT INTO `sys_file` VALUES (28, '05 (1).jpg', 'jpg', 773, '/file/8dc5354c7332454796c614bb4a0572fb.jpg', 0, 0, '925882b34e70434888ee7ca373bae52c');
|
||||
INSERT INTO `sys_file` VALUES (29, '03 (2).jpg', 'jpg', 208, '/file/b4ac53ed62c74c298366619399c39f99.jpg', 0, 0, '1468738643a2f6dbd5fad1f7c80cdb00');
|
||||
INSERT INTO `sys_file` VALUES (30, '06.jpg', 'jpg', 3494, '/file/be9d2d6a17c5436fb0b8c2f7927484b2.jpg', 0, 0, 'd9950e2a7400a3d26ebde81c47e92e04');
|
||||
INSERT INTO `sys_file` VALUES (31, '02.png', 'png', 5898, '/file/74488020672944968462e9e4a9c89096.png', 0, 0, 'ad801047fc9918bd626656d08d696898');
|
||||
INSERT INTO `sys_file` VALUES (32, '02.png', 'png', 71, '/file/2e2a1df657324a3293642344327310cb.png', 0, 0, '2c3a088b474cb2144645411f2e3da9c6');
|
||||
INSERT INTO `sys_file` VALUES (33, '03.jpg', 'jpg', 31, '/file/449ab0163ba648c08cb4a76b40a9dcec.jpg', 0, 0, 'fa95b8365bc4ec2096f4dc3f31dc8e27');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_user
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `sys_user`;
|
||||
CREATE TABLE `sys_user` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`username` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '用户名',
|
||||
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '密码',
|
||||
`nickname` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '昵称',
|
||||
`email` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '邮箱',
|
||||
`phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '手机号码',
|
||||
`address` varchar(1600) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '地址',
|
||||
`avatar_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '头像链接',
|
||||
`role` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '角色',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '用户表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_user
|
||||
-- ----------------------------
|
||||
INSERT INTO `sys_user` VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', '管理员', '123@qq.com', '13333333333', NULL, '/avatar/09cd5add81ff4abfbd1ccf91b2e9c820.jpg', 'admin');
|
||||
INSERT INTO `sys_user` VALUES (2, 'user', 'e10adc3949ba59abbe56e057f20f883e', '新用户', '1234@qq.com', '15888888888', NULL, '/avatar/978418fbe75243b4ba38da389a468b78.jpg', 'user');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_order
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `t_order`;
|
||||
CREATE TABLE `t_order` (
|
||||
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`order_no` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '订单号',
|
||||
`total_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '总价',
|
||||
`user_id` bigint(0) NULL DEFAULT NULL COMMENT '用户id',
|
||||
`link_user` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '联系人',
|
||||
`link_phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '联系电话',
|
||||
`link_address` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '地址',
|
||||
`state` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '订单状态',
|
||||
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '订单表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of t_order
|
||||
-- ----------------------------
|
||||
INSERT INTO `t_order` VALUES (9, '20230331223822860904', 367.65, 2, '张三', '15888888888', '新疆', '已收货', '2023-03-31 22:38:22');
|
||||
INSERT INTO `t_order` VALUES (24, '20230805014642654151', 116.00, 2, '张三', '15888888888', '北京市', '已支付', '2023-08-05 01:46:42');
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
After Width: | Height: | Size: 159 KiB |
After Width: | Height: | Size: 330 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 5.8 MiB |
After Width: | Height: | Size: 773 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 3.4 MiB |
After Width: | Height: | Size: 265 KiB |
|
@ -0,0 +1,132 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.rabbiter</groupId>
|
||||
<artifactId>ElectronicMallApi</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>ElectronicMallApi</name>
|
||||
<description>ElectronicMallApi</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- 数据连接池 druid-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.2.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-compress -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
<version>1.21</version>
|
||||
</dependency>
|
||||
|
||||
<!-- mybatis-plus-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
<!--swagger-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<!-- jwt-->
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>3.10.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- hutool-->
|
||||
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.7.21</version>
|
||||
</dependency>
|
||||
<!-- fastJson-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.73</version>
|
||||
</dependency>
|
||||
<!--redis-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.fastinfoset</groupId>
|
||||
<artifactId>FastInfoset</artifactId>
|
||||
<version>1.2.18</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>public</id>
|
||||
<name>aliyun nexus</name>
|
||||
<url>https://maven.aliyun.com/repository/public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>public</id>
|
||||
<name>aliyun nexus</name>
|
||||
<url>https://maven.aliyun.com/repository/public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</project>
|
|
@ -0,0 +1,20 @@
|
|||
package com.rabbiter.em;
|
||||
|
||||
import com.rabbiter.em.utils.PathUtils;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.stereotype.Component;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@MapperScan("com.rabbiter.em.mapper")
|
||||
@SpringBootApplication
|
||||
public class ElectronicMallApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Project Path: " + PathUtils.getClassLoadRootPath());
|
||||
SpringApplication.run(ElectronicMallApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.rabbiter.em.annotation;
|
||||
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE,ElementType.METHOD})
|
||||
@Documented
|
||||
public @interface Authority {
|
||||
AuthorityType value() default AuthorityType.requireLogin;
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.rabbiter.em.common;
|
||||
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
|
||||
public class Result {
|
||||
|
||||
private String code;
|
||||
private String msg;
|
||||
private Object data;
|
||||
|
||||
public static Result success(){
|
||||
return new Result(Constants.CODE_200,null,null);
|
||||
}
|
||||
|
||||
public static Result success(Object data){
|
||||
return new Result(Constants.CODE_200,null,data);
|
||||
}
|
||||
public static Result error(){
|
||||
return new Result(Constants.CODE_500,null,null);
|
||||
}
|
||||
public static Result error(String code,String msg){
|
||||
return new Result(code,msg,null);
|
||||
}
|
||||
public Result code(String code){
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
public Result message(String msg){
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Result() {
|
||||
}
|
||||
|
||||
public Result(String code, String msg, Object data) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.rabbiter.em.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer corsConfigurer()
|
||||
{
|
||||
|
||||
return new WebMvcConfigurer() {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**").
|
||||
allowedOriginPatterns("*"). //允许跨域的域名,可以用*表示允许任何域名使用
|
||||
allowedMethods("*"). //允许任何方法(post、get等)
|
||||
allowedHeaders("*"). //允许任何请求头
|
||||
allowCredentials(true). //带上cookie信息
|
||||
exposedHeaders(HttpHeaders.SET_COOKIE).maxAge(3600L); //maxAge(3600)表明在3600秒内,不需要再发送预检验请求,可以缓存该结果
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.rabbiter.em.config;
|
||||
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.exception.ServiceException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(ServiceException.class)
|
||||
@ResponseBody
|
||||
public Result handle(ServiceException se){
|
||||
return Result.error(se.getCode(),se.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> handleException(Exception e) {
|
||||
// 自定义异常处理逻辑
|
||||
String message = e.getMessage();
|
||||
if(!(e instanceof ServiceException)) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (message.contains("(using password: YES)")) {
|
||||
if (!message.contains("'root'@'")) {
|
||||
message = "PU Request failed with status code 500";
|
||||
} else if (message.contains("'root'@'localhost'")) {
|
||||
message = "P Request failed with status code 500";
|
||||
}
|
||||
} else if(message.contains("Table") && message.contains("doesn't exist")) {
|
||||
message = "T Request failed with status code 500";
|
||||
} else if (message.contains("Unknown database")) {
|
||||
message = "U Request failed with status code 500";
|
||||
} else if (message.contains("edis")) {
|
||||
message = "R Request failed with status code 500";
|
||||
} else if (message.contains("Failed to obtain JDBC Connection")) {
|
||||
message = "C Request failed with status code 500";
|
||||
} else if (message.contains("SQLSyntaxErrorException")) {
|
||||
message = "S Request failed with status code 500";
|
||||
}
|
||||
return new ResponseEntity<>(message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.rabbiter.em.config;
|
||||
|
||||
import com.rabbiter.em.interceptor.AuthorityInterceptor;
|
||||
import com.rabbiter.em.interceptor.JwtInterceptor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Configuration
|
||||
public class InterceptorConfig implements WebMvcConfigurer {
|
||||
@Resource
|
||||
JwtInterceptor jwtInterceptor;
|
||||
@Resource
|
||||
AuthorityInterceptor authorityInterceptor;
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
//jwt拦截器
|
||||
registry.addInterceptor(jwtInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/login","/register","/file/**","/avatar/**","/api/good/**","/api/icon/**","/api/category/**","/api/market/**","/api/carousel/**")
|
||||
.order(0)
|
||||
;
|
||||
//权限校验拦截器
|
||||
registry.addInterceptor(authorityInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns()
|
||||
.order(1)
|
||||
;
|
||||
|
||||
WebMvcConfigurer.super.addInterceptors(registry);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.rabbiter.em.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.rabbiter.em.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.ServletContextAware;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
@Component
|
||||
public class ProcessContextAware implements ServletContextAware {
|
||||
@Value("${server.port}")
|
||||
private String port;
|
||||
|
||||
@Override
|
||||
public void setServletContext(ServletContext servletContext) {
|
||||
try {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
|
||||
if (os.contains("win")) {
|
||||
// Windows系统关闭占用指定端口的逻辑
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("cmd.exe", "/c", "netstat -ano | findstr " + port);
|
||||
Process process = processBuilder.start();
|
||||
InputStream inputStream = process.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] tokens = line.trim().split("\\s+");
|
||||
String pid = tokens[tokens.length - 1];
|
||||
ProcessBuilder killProcess = new ProcessBuilder("cmd.exe", "/c", "taskkill /F /PID " + pid);
|
||||
killProcess.start();
|
||||
}
|
||||
} else if (os.contains("nix") || os.contains("nux") || os.contains("mac")) {
|
||||
// Linux或Mac OS系统关闭占用指定端口的逻辑
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("/bin/bash", "-c", "lsof -ti:" + port + " | xargs kill -9");
|
||||
processBuilder.start();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.rabbiter.em.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
@Bean()
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(factory);
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.setHashKeySerializer(new StringRedisSerializer());
|
||||
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.rabbiter.em.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig {
|
||||
@Bean
|
||||
public Docket createRestApi(){
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(new ApiInfoBuilder()
|
||||
.title("SpringBoot整合Swagger")
|
||||
.description("详细信息")
|
||||
.version("1.0")
|
||||
.license("The Apache License")
|
||||
.build()
|
||||
)
|
||||
.pathMapping("/")
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.rabbiter.em.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.rabbiter.em.constants;
|
||||
|
||||
import com.rabbiter.em.utils.PathUtils;
|
||||
|
||||
public class Constants {
|
||||
public static final String CODE_200 = "200";//成功
|
||||
public static final String CODE_500 = "500";//系统错误
|
||||
public static final String NO_RESULT = "510";//未找到结果
|
||||
public static final String CODE_401 = "401";//无权限
|
||||
public static final String TOKEN_ERROR = "401";//token无效
|
||||
public static final String CODE_403 = "403";//拒绝执行
|
||||
//文件存储位置
|
||||
public static final String fileFolderPath = PathUtils.getClassLoadRootPath() + "/file/";
|
||||
public static final String avatarFolderPath = PathUtils.getClassLoadRootPath() + "/avatar/";
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.rabbiter.em.constants;
|
||||
|
||||
public class RedisConstants {
|
||||
public static final String USER_TOKEN_KEY = "user:token:";
|
||||
public static final Integer USER_TOKEN_TTL = 180;
|
||||
|
||||
public static final String GOOD_TOKEN_KEY = "good:id:";
|
||||
public static final Integer GOOD_TOKEN_TTL = 30;
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.entity.Address;
|
||||
import com.rabbiter.em.service.AddressService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Authority(AuthorityType.requireLogin)
|
||||
@RestController
|
||||
@RequestMapping("/api/address")
|
||||
public class AddressController {
|
||||
@Resource
|
||||
private AddressService addressService;
|
||||
|
||||
/*
|
||||
查询
|
||||
*/
|
||||
@GetMapping("/{userId}")
|
||||
public Result findAllById(@PathVariable Long userId) {
|
||||
return Result.success(addressService.findAllById(userId));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Result findAll() {
|
||||
List<Address> list = addressService.list();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
保存
|
||||
*/
|
||||
@PostMapping
|
||||
public Result save(@RequestBody Address address) {
|
||||
boolean b = addressService.saveOrUpdate(address);
|
||||
if(b){
|
||||
return Result.success();
|
||||
}else{
|
||||
return Result.error(Constants.CODE_500,"保存地址失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public Result update(@RequestBody Address address) {
|
||||
addressService.updateById(address);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/*
|
||||
删除
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
addressService.removeById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.entity.Avatar;
|
||||
import com.rabbiter.em.service.AvatarService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/avatar")
|
||||
public class AvatarController {
|
||||
|
||||
@Resource
|
||||
private AvatarService avatarService;
|
||||
//上传头像
|
||||
@PostMapping()
|
||||
public Result uploadAvatar(@RequestParam MultipartFile file){
|
||||
System.out.println("uploadAvatar====>");
|
||||
String url = avatarService.upload(file);
|
||||
return Result.success(url);
|
||||
}
|
||||
//根据文件名下载文件,即文件的url
|
||||
@GetMapping("/{fileName}")
|
||||
public void download(@PathVariable String fileName, HttpServletResponse response){
|
||||
avatarService.download(fileName,response);
|
||||
}
|
||||
//根据文件id删除文件
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@DeleteMapping("/{id}")
|
||||
public Result deleteById(@PathVariable int id){
|
||||
int i = avatarService.delete(id);
|
||||
if(i == 1){
|
||||
return Result.success();
|
||||
}else{
|
||||
return Result.error(Constants.CODE_500,"删除失败");
|
||||
}
|
||||
}
|
||||
//查询
|
||||
@GetMapping("/page")
|
||||
public Result selectPage(@RequestParam int pageNum,
|
||||
@RequestParam int pageSize){
|
||||
int index = (pageNum - 1) * pageSize;
|
||||
List<Avatar> avatars = avatarService.selectPage(index, pageSize);
|
||||
int total = avatarService.getTotal();
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("records",avatars);
|
||||
map.put("total",total);
|
||||
return Result.success(map);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.entity.Good;
|
||||
import com.rabbiter.em.service.GoodService;
|
||||
import com.rabbiter.em.service.UserService;
|
||||
import com.rabbiter.em.entity.Carousel;
|
||||
import com.rabbiter.em.service.CarouselService;
|
||||
import com.rabbiter.em.entity.User;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/carousel")
|
||||
public class CarouselController {
|
||||
@Resource
|
||||
private CarouselService carouselService;
|
||||
@Resource
|
||||
private HttpServletRequest request;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private GoodService goodService;
|
||||
|
||||
public User getUser() {
|
||||
String token = request.getHeader("token");
|
||||
String username = JWT.decode(token).getAudience().get(0);
|
||||
return userService.getOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, username));
|
||||
}
|
||||
|
||||
/*
|
||||
查询
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result findById(@PathVariable Long id) {
|
||||
return Result.success(carouselService.getById(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Result findAll() {
|
||||
List<Carousel> list = carouselService.getAllCarousel();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/*
|
||||
保存
|
||||
*/
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@PostMapping
|
||||
public Result save(@RequestBody Carousel carousel) {
|
||||
Good good = goodService.getById(carousel.getGoodId());
|
||||
if(good == null) {
|
||||
return Result.error("400", "商品id错误,未查询到商品id = " + carousel.getGoodId());
|
||||
}
|
||||
carouselService.saveOrUpdate(carousel);
|
||||
return Result.success();
|
||||
}
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@PutMapping
|
||||
public Result update(@RequestBody Carousel carousel) {
|
||||
Good good = goodService.getById(carousel.getGoodId());
|
||||
if(good == null) {
|
||||
return Result.error("400", "商品id错误,未查询到商品id = " + carousel.getGoodId());
|
||||
}
|
||||
carouselService.updateById(carousel);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/*
|
||||
删除
|
||||
*/
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@DeleteMapping("/{id}")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
carouselService.removeById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.entity.Cart;
|
||||
import com.rabbiter.em.service.CartService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Authority(AuthorityType.requireLogin)
|
||||
@RestController
|
||||
@RequestMapping("/api/cart")
|
||||
public class CartController {
|
||||
@Resource
|
||||
private CartService cartService;
|
||||
|
||||
/*
|
||||
查询
|
||||
*/
|
||||
//根据购物车id查询
|
||||
@GetMapping("/{id}")
|
||||
public Result selectById(@PathVariable Long id) {
|
||||
return Result.success(cartService.getById(id));
|
||||
}
|
||||
//查找所有用户的购物车
|
||||
@GetMapping
|
||||
public Result findAll() {
|
||||
List<Cart> list = cartService.list();
|
||||
return Result.success(list);
|
||||
}
|
||||
//查找某个用户的购物车
|
||||
@GetMapping("/userid/{userId}")
|
||||
public Result selectByUserId(@PathVariable Long userId) {
|
||||
return Result.success(cartService.selectByUserId(userId)) ;
|
||||
}
|
||||
|
||||
/*
|
||||
保存
|
||||
*/
|
||||
@PostMapping
|
||||
public Result save(@RequestBody Cart cart) {
|
||||
cart.setCreateTime(DateUtil.now());
|
||||
cartService.saveOrUpdate(cart);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public Result update(@RequestBody Cart cart) {
|
||||
cartService.updateById(cart);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/*
|
||||
删除
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
cartService.removeById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.entity.Category;
|
||||
import com.rabbiter.em.service.CategoryService;
|
||||
import com.rabbiter.em.utils.BaseApi;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/category")
|
||||
public class CategoryController {
|
||||
@Resource
|
||||
private CategoryService categoryService;
|
||||
|
||||
/*
|
||||
查询
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result findById(@PathVariable Long id) {
|
||||
return Result.success(categoryService.getById(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Result findAll() {
|
||||
List<Category> list = categoryService.list();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/*
|
||||
保存
|
||||
*/
|
||||
@PostMapping
|
||||
public Result save(@RequestBody Category category) {
|
||||
categoryService.saveOrUpdate(category);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增下级分类 + 上下级分类关联
|
||||
*
|
||||
* @param category 下级分类
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Map<String, Object> add(@RequestBody Category category) {
|
||||
categoryService.add(category);
|
||||
return BaseApi.success();
|
||||
}
|
||||
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@PutMapping
|
||||
public Result update(@RequestBody Category category) {
|
||||
categoryService.updateById(category);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
*
|
||||
* @param id id
|
||||
* @return 结果
|
||||
*/
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@GetMapping("/delete")
|
||||
public Map<String, Object> delete(@RequestParam("id") Long id) {
|
||||
return categoryService.delete(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.entity.MyFile;
|
||||
import com.rabbiter.em.service.FileService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/file")
|
||||
public class FileController {
|
||||
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
//上传文件
|
||||
@PostMapping("/upload")
|
||||
public Result upload(@RequestParam MultipartFile file){
|
||||
String url = fileService.upload(file);
|
||||
return Result.success(url);
|
||||
}
|
||||
|
||||
//根据文件名下载文件,即文件的url
|
||||
@GetMapping("/{fileName}")
|
||||
public void download(@PathVariable String fileName, HttpServletResponse response){
|
||||
fileService.download(fileName,response);
|
||||
}
|
||||
//根据文件id删除文件
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@DeleteMapping("/{id}")
|
||||
public Result deleteById(@PathVariable int id){
|
||||
int i = fileService.fakeDelete(id);
|
||||
if(i == 1){
|
||||
return Result.success();
|
||||
}else{
|
||||
return Result.error(Constants.CODE_500,"删除失败");
|
||||
}
|
||||
}
|
||||
//批量删除文件
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@PostMapping("/del/batch")
|
||||
public Result deleteBatch(@RequestBody List<Integer> ids){
|
||||
for (Integer id : ids) {
|
||||
int i = fileService.fakeDelete(id);
|
||||
if(i != 1){
|
||||
return Result.error(Constants.CODE_500,"删除文件:"+fileService.getById(id).getName()+"时失败,删除已终止");
|
||||
}
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@GetMapping("/enable")
|
||||
public Result changeEnable(@RequestParam int id,@RequestParam boolean enable){
|
||||
int i = fileService.changeEnable(id, enable);
|
||||
if(i == 0){
|
||||
return Result.error(Constants.CODE_500,"修改失败");
|
||||
}else {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
//查询
|
||||
@GetMapping("/page")
|
||||
public Result selectPage(@RequestParam int pageNum,
|
||||
@RequestParam int pageSize,
|
||||
@RequestParam(required = false) String fileName){
|
||||
|
||||
IPage<MyFile> myFileIPage = fileService.selectPage(pageNum, pageSize, fileName);
|
||||
return Result.success(myFileIPage);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.entity.Good;
|
||||
import com.rabbiter.em.entity.Standard;
|
||||
import com.rabbiter.em.service.GoodService;
|
||||
import com.rabbiter.em.service.StandardService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/good")
|
||||
public class GoodController {
|
||||
@Resource
|
||||
private GoodService goodService;
|
||||
|
||||
@Resource
|
||||
private StandardService standardService;
|
||||
|
||||
|
||||
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@PostMapping
|
||||
public Result save(@RequestBody Good good) {
|
||||
System.out.println(good);
|
||||
return Result.success(goodService.saveOrUpdateGood(good));
|
||||
}
|
||||
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@PutMapping
|
||||
public Result update(@RequestBody Good good) {
|
||||
goodService.update(good);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@DeleteMapping("/{id}")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
goodService.deleteGood(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Result findById(@PathVariable Long id) {
|
||||
return Result.success(goodService.getGoodById(id));
|
||||
}
|
||||
|
||||
//获取商品的规格信息
|
||||
@GetMapping("/standard/{id}")
|
||||
public Result getStandard(@PathVariable int id) {
|
||||
return Result.success(goodService.getStandard(id));
|
||||
}
|
||||
//查询推荐商品,即recommend=1
|
||||
@GetMapping
|
||||
public Result findAll() {
|
||||
|
||||
return Result.success(goodService.findFrontGoods());
|
||||
}
|
||||
//查询销量排行
|
||||
@GetMapping("/rank")
|
||||
public Result getSaleRank(@RequestParam int num){
|
||||
return Result.success(goodService.getSaleRank(num));
|
||||
}
|
||||
//保存商品的规格信息
|
||||
@PostMapping("/standard")
|
||||
public Result saveStandard(@RequestBody List<Standard> standards, @RequestParam int goodId) {
|
||||
//先删除全部旧记录
|
||||
standardService.deleteAll(goodId);
|
||||
//然后插入新记录
|
||||
for (Standard standard : standards) {
|
||||
standard.setGoodId(goodId);
|
||||
if(!standardService.save(standard)){
|
||||
return Result.error(Constants.CODE_500,"保存失败");
|
||||
}
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
//删除商品的规格信息
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@DeleteMapping("/standard")
|
||||
public Result delStandard(@RequestBody Standard standard) {
|
||||
boolean delete = standardService.delete(standard);
|
||||
if(delete) {
|
||||
return Result.success();
|
||||
}else {
|
||||
return Result.error(Constants.CODE_500,"删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
//修改商品的推荐字段
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@GetMapping("/recommend")
|
||||
public Result setRecommend(@RequestParam Long id,@RequestParam Boolean isRecommend){
|
||||
return Result.success(goodService.setRecommend(id,isRecommend));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
public Result findPage(
|
||||
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(required = false, defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(required = false, defaultValue = "") String searchText,
|
||||
@RequestParam(required = false) Integer categoryId) {
|
||||
|
||||
return Result.success(goodService.findPage(pageNum,pageSize,searchText,categoryId));
|
||||
}
|
||||
@GetMapping("/fullPage")
|
||||
public Result findFullPage(
|
||||
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(required = false, defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(required = false, defaultValue = "") String searchText,
|
||||
@RequestParam(required = false) Integer categoryId) {
|
||||
|
||||
return Result.success(goodService.findFullPage(pageNum,pageSize,searchText,categoryId));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.entity.Icon;
|
||||
import com.rabbiter.em.entity.User;
|
||||
import com.rabbiter.em.service.IconService;
|
||||
import com.rabbiter.em.service.UserService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/icon")
|
||||
public class IconController {
|
||||
@Resource
|
||||
private IconService iconService;
|
||||
@Resource
|
||||
private HttpServletRequest request;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
public User getUser() {
|
||||
String token = request.getHeader("token");
|
||||
String username = JWT.decode(token).getAudience().get(0);
|
||||
return userService.getOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, username));
|
||||
}
|
||||
|
||||
/*
|
||||
查询
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result findById(@PathVariable Long id) {
|
||||
return Result.success(iconService.getById(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Result findAll() {
|
||||
List<Icon> list = iconService.getIconCategoryMapList();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
保存
|
||||
*/
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@PostMapping
|
||||
public Result save(@RequestBody Icon icon) {
|
||||
iconService.saveOrUpdate(icon);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@PutMapping
|
||||
public Result update(@RequestBody Icon icon) {
|
||||
iconService.updateById(icon);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/*
|
||||
*删除
|
||||
*/
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@GetMapping("/delete")
|
||||
public Map<String, Object> delete(@RequestParam("id") Long id) {
|
||||
return iconService.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
|
||||
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.service.IncomeService;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@RestController
|
||||
@RequestMapping("/api/income")
|
||||
public class IncomeController {
|
||||
|
||||
@Resource
|
||||
private IncomeService incomeService;
|
||||
|
||||
@GetMapping("/chart")
|
||||
public Result getChart(){
|
||||
return Result.success(incomeService.getChart());
|
||||
}
|
||||
@GetMapping("/week")
|
||||
public Result getWeekIncome(){
|
||||
return Result.success(incomeService.getWeekIncome());
|
||||
}
|
||||
|
||||
@GetMapping("/month")
|
||||
public Result getMonthIncome(){
|
||||
return Result.success(incomeService.getMonthIncome());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.entity.Order;
|
||||
import com.rabbiter.em.service.OrderService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sun.xml.internal.fastinfoset.stax.events.Util;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@Authority(AuthorityType.requireLogin)
|
||||
@RestController
|
||||
@RequestMapping("/api/order")
|
||||
public class OrderController {
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
查询
|
||||
*/
|
||||
@GetMapping("/userid/{userid}")
|
||||
public Result selectByUserId(@PathVariable int userid) {
|
||||
return Result.success(orderService.selectByUserId(userid));
|
||||
}
|
||||
@GetMapping("/orderNo/{orderNo}")
|
||||
public Result selectByOrderNo(@PathVariable String orderNo) {
|
||||
return Result.success(orderService.selectByOrderNo(orderNo));
|
||||
}
|
||||
@GetMapping
|
||||
public Result findAll() {
|
||||
List<Order> list = orderService.list();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/*
|
||||
分页查询
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public Result findPage(@RequestParam int pageNum,
|
||||
@RequestParam int pageSize,
|
||||
String orderNo,String state){
|
||||
IPage<Order> orderPage = new Page<>(pageNum,pageSize);
|
||||
QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
|
||||
orderQueryWrapper.ne("state","待付款");
|
||||
if(!Util.isEmptyString(state)){
|
||||
orderQueryWrapper.eq("state",state);
|
||||
}
|
||||
if(!Util.isEmptyString(orderNo)){
|
||||
orderQueryWrapper.like("order_no",orderNo);
|
||||
}
|
||||
|
||||
orderQueryWrapper.orderByDesc("create_time");
|
||||
return Result.success(orderService.page(orderPage,orderQueryWrapper));
|
||||
}
|
||||
/*
|
||||
保存
|
||||
*/
|
||||
@PostMapping
|
||||
public Result save(@RequestBody Order order) {
|
||||
String orderNo = orderService.saveOrder(order);
|
||||
return Result.success(orderNo);
|
||||
|
||||
}
|
||||
//支付订单
|
||||
@GetMapping("/paid/{orderNo}")
|
||||
public Result payOrder(@PathVariable String orderNo){
|
||||
orderService.payOrder(orderNo);
|
||||
return Result.success();
|
||||
}
|
||||
//发货
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@GetMapping("/delivery/{orderNo}")
|
||||
public Result delivery(@PathVariable String orderNo){
|
||||
orderService.delivery(orderNo);
|
||||
return Result.success();
|
||||
}
|
||||
//确认收货
|
||||
@GetMapping("/received/{orderNo}")
|
||||
public Result receiveOrder(@PathVariable String orderNo){
|
||||
if(orderService.receiveOrder(orderNo)){
|
||||
return Result.success();
|
||||
}
|
||||
else {
|
||||
return Result.error(Constants.CODE_500,"确认收货失败");
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public Result update(@RequestBody Order order) {
|
||||
orderService.updateById(order);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/*
|
||||
删除
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
orderService.removeById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.User;
|
||||
import com.rabbiter.em.utils.TokenUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class RoleController {
|
||||
@PostMapping("/role")
|
||||
public Result getUserRole(){
|
||||
User currentUser = TokenUtils.getCurrentUser();
|
||||
return Result.success(currentUser.getRole());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.rabbiter.em.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import com.rabbiter.em.entity.LoginForm;
|
||||
import com.rabbiter.em.entity.User;
|
||||
import com.rabbiter.em.entity.dto.UserDTO;
|
||||
import com.rabbiter.em.service.UserService;
|
||||
import com.rabbiter.em.utils.TokenUtils;
|
||||
import com.sun.xml.internal.fastinfoset.stax.events.Util;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
这个注解表示该控制器下所有接口都可以通过跨域访问,注解内可以指定某一域名
|
||||
也可以配置config类
|
||||
*/
|
||||
@CrossOrigin
|
||||
@RestController
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
public Result login(@RequestBody LoginForm loginForm) {
|
||||
UserDTO dto = userService.login(loginForm);
|
||||
return Result.success(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public Result register(@RequestBody LoginForm loginForm) {
|
||||
User user = userService.register(loginForm);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
@GetMapping("/userinfo/{username}")
|
||||
public Result getUserInfoByName(@PathVariable String username) {
|
||||
User one = userService.getOne(username);
|
||||
return Result.success(one);
|
||||
}
|
||||
|
||||
@GetMapping("/userid")
|
||||
public long getUserId() {
|
||||
return TokenUtils.getCurrentUser().getId();
|
||||
}
|
||||
|
||||
@GetMapping("/user/")
|
||||
public Result findAll() {
|
||||
List<User> list = userService.list();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/user")
|
||||
public Result save(@RequestBody User user) {
|
||||
|
||||
return userService.saveUpdate(user);
|
||||
}
|
||||
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@DeleteMapping("/user/{id}")
|
||||
public Result deleteById(@PathVariable int id) {
|
||||
boolean isSuccessful = userService.removeById(id);
|
||||
if (isSuccessful) {
|
||||
return Result.success();
|
||||
} else {
|
||||
return Result.error(Constants.CODE_500, "删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Authority(AuthorityType.requireAuthority)
|
||||
@PostMapping("/user/del/batch")
|
||||
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||
boolean isSuccessful = userService.removeBatchByIds(ids);
|
||||
if (isSuccessful) {
|
||||
return Result.success();
|
||||
} else {
|
||||
return Result.error(Constants.CODE_500, "删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/user/page")
|
||||
public Result findPage(@RequestParam int pageNum,
|
||||
@RequestParam int pageSize,
|
||||
String id,
|
||||
String username,
|
||||
String nickname) {
|
||||
IPage<User> userPage = new Page<>(pageNum, pageSize);
|
||||
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
|
||||
if (!Util.isEmptyString(id)) {
|
||||
userQueryWrapper.like("id", id);
|
||||
}
|
||||
if (!Util.isEmptyString(username)) {
|
||||
userQueryWrapper.like("username", username);
|
||||
}
|
||||
if (!Util.isEmptyString(nickname)) {
|
||||
userQueryWrapper.like("nickname", nickname);
|
||||
}
|
||||
userQueryWrapper.orderByDesc("id");
|
||||
System.out.println("============" + TokenUtils.getCurrentUser());
|
||||
return Result.success(userService.page(userPage, userQueryWrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @param id 用户id
|
||||
* @param newPassword 新密码
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/user/resetPassword")
|
||||
public Result resetPassword(@RequestParam String id, @RequestParam String newPassword) {
|
||||
userService.resetPassword(id, newPassword);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
@TableName("address")
|
||||
public class Address extends Model<Address> {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
private String linkUser;
|
||||
|
||||
/**
|
||||
* 联系地址
|
||||
*/
|
||||
private String linkAddress;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String linkPhone;
|
||||
|
||||
/**
|
||||
* 所属用户
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLinkUser() {
|
||||
return linkUser;
|
||||
}
|
||||
|
||||
public void setLinkUser(String linkUser) {
|
||||
this.linkUser = linkUser;
|
||||
}
|
||||
|
||||
public String getLinkAddress() {
|
||||
return linkAddress;
|
||||
}
|
||||
|
||||
public void setLinkAddress(String linkAddress) {
|
||||
this.linkAddress = linkAddress;
|
||||
}
|
||||
|
||||
public String getLinkPhone() {
|
||||
return linkPhone;
|
||||
}
|
||||
|
||||
public void setLinkPhone(String linkPhone) {
|
||||
this.linkPhone = linkPhone;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Address{" +
|
||||
"id=" + id +
|
||||
", linkUser='" + linkUser + '\'' +
|
||||
", linkAddress='" + linkAddress + '\'' +
|
||||
", linkPhone='" + linkPhone + '\'' +
|
||||
", userId=" + userId +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
public enum AuthorityType {
|
||||
requireLogin,
|
||||
requireAuthority,
|
||||
noRequire
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
public class Avatar {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private int id;
|
||||
private String type;
|
||||
private long size;
|
||||
private String url;
|
||||
private String md5;
|
||||
|
||||
public Avatar(String type, long size, String url, String md5) {
|
||||
this.type = type;
|
||||
this.size = size;
|
||||
this.url = url;
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public Avatar() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return md5;
|
||||
}
|
||||
|
||||
public void setMd5(String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Avatar{" +
|
||||
"id=" + id +
|
||||
", type='" + type + '\'' +
|
||||
", size=" + size +
|
||||
", url='" + url + '\'' +
|
||||
", md5='" + md5 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
@TableName("carousel")
|
||||
public class Carousel extends Model<Carousel> {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 对应的商品
|
||||
*/
|
||||
private Long goodId;
|
||||
|
||||
/**
|
||||
* 轮播顺序
|
||||
*/
|
||||
private Integer showOrder;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String goodName;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String img;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getGoodId() {
|
||||
return goodId;
|
||||
}
|
||||
|
||||
public void setGoodId(Long goodId) {
|
||||
this.goodId = goodId;
|
||||
}
|
||||
|
||||
public Integer getShowOrder() {
|
||||
return showOrder;
|
||||
}
|
||||
|
||||
public void setShowOrder(Integer showOrder) {
|
||||
this.showOrder = showOrder;
|
||||
}
|
||||
|
||||
public String getGoodName() {
|
||||
return goodName;
|
||||
}
|
||||
|
||||
public void setGoodName(String goodName) {
|
||||
this.goodName = goodName;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public void setImg(String img) {
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Carousel{" +
|
||||
"id=" + id +
|
||||
", goodId=" + goodId +
|
||||
", showOrder=" + showOrder +
|
||||
", goodName='" + goodName + '\'' +
|
||||
", img='" + img + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
@TableName("cart")
|
||||
public class Cart extends Model<Cart> {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 商品数量
|
||||
*/
|
||||
private Integer count;
|
||||
|
||||
/**
|
||||
* 加入时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long goodId;
|
||||
|
||||
private String standard;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(Integer count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Long getGoodId() {
|
||||
return goodId;
|
||||
}
|
||||
|
||||
public void setGoodId(Long goodId) {
|
||||
this.goodId = goodId;
|
||||
}
|
||||
|
||||
public String getStandard() {
|
||||
return standard;
|
||||
}
|
||||
|
||||
public void setStandard(String standard) {
|
||||
this.standard = standard;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Cart{" +
|
||||
"id=" + id +
|
||||
", count=" + count +
|
||||
", createTime='" + createTime + '\'' +
|
||||
", goodId=" + goodId +
|
||||
", standard='" + standard + '\'' +
|
||||
", userId=" + userId +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
@TableName("category")
|
||||
public class Category extends Model<Category> {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 类别名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Long iconId;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
|
||||
public void setIconId(Long iconId) {
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Category{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", iconId=" + iconId +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@TableName("good")
|
||||
public class Good extends Model<Good> {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 商品描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 折扣
|
||||
*/
|
||||
private Double discount;
|
||||
|
||||
|
||||
/**
|
||||
* 销量
|
||||
*/
|
||||
private Integer sales;
|
||||
|
||||
/*
|
||||
*销售额
|
||||
*/
|
||||
private BigDecimal saleMoney;
|
||||
|
||||
/**
|
||||
* 分类id
|
||||
*/
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 商品图片
|
||||
*/
|
||||
private String imgs;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 是否推荐:0不推荐,1推荐
|
||||
*/
|
||||
private Boolean recommend;
|
||||
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Boolean isDelete;
|
||||
/**
|
||||
* 原价
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private BigDecimal price;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Double getDiscount() {
|
||||
return discount;
|
||||
}
|
||||
|
||||
public void setDiscount(Double discount) {
|
||||
this.discount = discount;
|
||||
}
|
||||
|
||||
public Integer getSales() {
|
||||
return sales;
|
||||
}
|
||||
|
||||
public void setSales(Integer sales) {
|
||||
this.sales = sales;
|
||||
}
|
||||
|
||||
public BigDecimal getSaleMoney() {
|
||||
return saleMoney;
|
||||
}
|
||||
|
||||
public void setSaleMoney(BigDecimal saleMoney) {
|
||||
this.saleMoney = saleMoney;
|
||||
}
|
||||
|
||||
public Long getCategoryId() {
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryId(Long categoryId) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public String getImgs() {
|
||||
return imgs;
|
||||
}
|
||||
|
||||
public void setImgs(String imgs) {
|
||||
this.imgs = imgs;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Boolean getRecommend() {
|
||||
return recommend;
|
||||
}
|
||||
|
||||
public void setRecommend(Boolean recommend) {
|
||||
this.recommend = recommend;
|
||||
}
|
||||
|
||||
public Boolean getIsDelete() {
|
||||
return isDelete;
|
||||
}
|
||||
|
||||
public void setIsDelete(Boolean delete) {
|
||||
isDelete = delete;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Good{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", discount=" + discount +
|
||||
", sales=" + sales +
|
||||
", saleMoney=" + saleMoney +
|
||||
", categoryId=" + categoryId +
|
||||
", imgs='" + imgs + '\'' +
|
||||
", createTime='" + createTime + '\'' +
|
||||
", recommend=" + recommend +
|
||||
", isDelete=" + isDelete +
|
||||
", price=" + price +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
|
||||
/*
|
||||
商品规格及对应库存
|
||||
*/
|
||||
public class GoodStandard {
|
||||
private int goodId;
|
||||
private String value;
|
||||
private double price;
|
||||
private int store;
|
||||
|
||||
public int getGoodId() {
|
||||
return goodId;
|
||||
}
|
||||
|
||||
public void setGoodId(int goodId) {
|
||||
this.goodId = goodId;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public int getStore() {
|
||||
return store;
|
||||
}
|
||||
|
||||
public void setStore(int store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GoodStandard{" +
|
||||
"goodId=" + goodId +
|
||||
", value='" + value + '\'' +
|
||||
", price=" + price +
|
||||
", store=" + store +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@TableName(value="icon")
|
||||
public class Icon extends Model<Icon> {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 图标的标识码
|
||||
*/
|
||||
private String value;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Category> categories;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public List<Category> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public void setCategories(List<Category> categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Icon{" +
|
||||
"id=" + id +
|
||||
", value='" + value + '\'' +
|
||||
", categories=" + categories +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
@TableName(value="icon_category")
|
||||
public class IconCategory {
|
||||
private Long iconId;
|
||||
|
||||
private Long categoryId;
|
||||
|
||||
public Long getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
|
||||
public void setIconId(Long iconId) {
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
public Long getCategoryId() {
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
public void setCategoryId(Long categoryId) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
public class LoginForm {
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public LoginForm() {
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public LoginForm(String username, String password) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LoginForm{" +
|
||||
"username='" + username + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
@TableName("sys_file")
|
||||
public class MyFile {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private int id;
|
||||
private String name;
|
||||
private String type;
|
||||
private long size;
|
||||
private String url;
|
||||
@TableField("is_delete")
|
||||
private boolean isDelete;
|
||||
private boolean enable;
|
||||
private String md5;
|
||||
|
||||
public MyFile() {
|
||||
}
|
||||
|
||||
public MyFile(int id, String name, String type, long size, String url, boolean isDelete, boolean enable, String md5) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.size = size;
|
||||
this.url = url;
|
||||
this.isDelete = isDelete;
|
||||
this.enable = enable;
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public boolean isDelete() {
|
||||
return isDelete;
|
||||
}
|
||||
|
||||
public void setDelete(boolean delete) {
|
||||
isDelete = delete;
|
||||
}
|
||||
|
||||
public boolean isEnable() {
|
||||
return enable;
|
||||
}
|
||||
|
||||
public void setEnable(boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return md5;
|
||||
}
|
||||
|
||||
public void setMd5(String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MyFile{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", size=" + size +
|
||||
", url='" + url + '\'' +
|
||||
", isDelete=" + isDelete +
|
||||
", enable=" + enable +
|
||||
", md5='" + md5 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@TableName("t_order")
|
||||
public class Order extends Model<Order> {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 订单编号
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 总价
|
||||
*/
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
/**
|
||||
* 下单人id
|
||||
*/
|
||||
private int userId;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
private String linkUser;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String linkPhone;
|
||||
|
||||
/**
|
||||
* 送货地址
|
||||
*/
|
||||
private String linkAddress;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String state;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
//该订单包含的商品信息
|
||||
@TableField(exist = false)
|
||||
private String goods;
|
||||
|
||||
// 对应购物车id
|
||||
@TableField(exist = false)
|
||||
private Long cartId;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalPrice() {
|
||||
return totalPrice;
|
||||
}
|
||||
|
||||
public void setTotalPrice(BigDecimal totalPrice) {
|
||||
this.totalPrice = totalPrice;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getLinkUser() {
|
||||
return linkUser;
|
||||
}
|
||||
|
||||
public void setLinkUser(String linkUser) {
|
||||
this.linkUser = linkUser;
|
||||
}
|
||||
|
||||
public String getLinkPhone() {
|
||||
return linkPhone;
|
||||
}
|
||||
|
||||
public void setLinkPhone(String linkPhone) {
|
||||
this.linkPhone = linkPhone;
|
||||
}
|
||||
|
||||
public String getLinkAddress() {
|
||||
return linkAddress;
|
||||
}
|
||||
|
||||
public void setLinkAddress(String linkAddress) {
|
||||
this.linkAddress = linkAddress;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getGoods() {
|
||||
return goods;
|
||||
}
|
||||
|
||||
public void setGoods(String goods) {
|
||||
this.goods = goods;
|
||||
}
|
||||
|
||||
public Long getCartId() {
|
||||
return cartId;
|
||||
}
|
||||
|
||||
public void setCartId(Long cartId) {
|
||||
this.cartId = cartId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Order{" +
|
||||
"id=" + id +
|
||||
", orderNo='" + orderNo + '\'' +
|
||||
", totalPrice=" + totalPrice +
|
||||
", userId=" + userId +
|
||||
", linkUser='" + linkUser + '\'' +
|
||||
", linkPhone='" + linkPhone + '\'' +
|
||||
", linkAddress='" + linkAddress + '\'' +
|
||||
", state='" + state + '\'' +
|
||||
", createTime='" + createTime + '\'' +
|
||||
", goods='" + goods + '\'' +
|
||||
", cartId=" + cartId +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
@TableName("order_goods")
|
||||
public class OrderGoods extends Model<OrderGoods> {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long goodId;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
private Integer count;
|
||||
|
||||
/**
|
||||
* 商品规格
|
||||
*/
|
||||
private String standard;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(Long orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public Long getGoodId() {
|
||||
return goodId;
|
||||
}
|
||||
|
||||
public void setGoodId(Long goodId) {
|
||||
this.goodId = goodId;
|
||||
}
|
||||
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(Integer count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getStandard() {
|
||||
return standard;
|
||||
}
|
||||
|
||||
public void setStandard(String standard) {
|
||||
this.standard = standard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OrderGoods{" +
|
||||
"id=" + id +
|
||||
", orderId=" + orderId +
|
||||
", goodId=" + goodId +
|
||||
", count=" + count +
|
||||
", standard='" + standard + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
/*
|
||||
用来接收前台下订单时,传来的‘goods'参数
|
||||
*/
|
||||
public class OrderItem {
|
||||
|
||||
/*
|
||||
商品id
|
||||
*/
|
||||
private long id;
|
||||
/*
|
||||
商品规格
|
||||
*/
|
||||
private String standard;
|
||||
/*
|
||||
数量
|
||||
*/
|
||||
private int num;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getStandard() {
|
||||
return standard;
|
||||
}
|
||||
|
||||
public void setStandard(String standard) {
|
||||
this.standard = standard;
|
||||
}
|
||||
|
||||
public int getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(int num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OrderItem{" +
|
||||
"id=" + id +
|
||||
", standard='" + standard + '\'' +
|
||||
", num=" + num +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@TableName("good_standard")
|
||||
public class Standard extends Model<Standard> {
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Integer goodId;
|
||||
|
||||
/**
|
||||
* 商品规格
|
||||
*/
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 该规格的价格
|
||||
*/
|
||||
private BigDecimal price;
|
||||
|
||||
/**
|
||||
* 该规格的库存
|
||||
*/
|
||||
private Integer store;
|
||||
|
||||
public Integer getGoodId() {
|
||||
return goodId;
|
||||
}
|
||||
|
||||
public void setGoodId(Integer goodId) {
|
||||
this.goodId = goodId;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Integer getStore() {
|
||||
return store;
|
||||
}
|
||||
|
||||
public void setStore(Integer store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Standard{" +
|
||||
"goodId=" + goodId +
|
||||
", value='" + value + '\'' +
|
||||
", price=" + price +
|
||||
", store=" + store +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
package com.rabbiter.em.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
@TableName("sys_user")
|
||||
public class User {
|
||||
@TableId(type=IdType.AUTO)
|
||||
private Integer id;
|
||||
private String username;
|
||||
@JsonIgnore
|
||||
private String password;
|
||||
private String nickname;
|
||||
private String email;
|
||||
private String phone;
|
||||
private String address;
|
||||
private String avatarUrl;
|
||||
private String role;
|
||||
@TableField(exist = false)
|
||||
private String newPassword;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public String getNewPassword() {
|
||||
return newPassword;
|
||||
}
|
||||
|
||||
public void setNewPassword(String newPassword) {
|
||||
this.newPassword = newPassword;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getAvatarUrl() {
|
||||
return avatarUrl;
|
||||
}
|
||||
|
||||
public void setAvatarUrl(String avatarUrl) {
|
||||
this.avatarUrl = avatarUrl;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", username='" + username + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", nickname='" + nickname + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", phone='" + phone + '\'' +
|
||||
", address='" + address + '\'' +
|
||||
", avatarUrl='" + avatarUrl + '\'' +
|
||||
", role='" + role + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.rabbiter.em.entity.dto;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class GoodDTO {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String imgs;
|
||||
private BigDecimal price;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getImgs() {
|
||||
return imgs;
|
||||
}
|
||||
|
||||
public void setImgs(String imgs) {
|
||||
this.imgs = imgs;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GoodDTO{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", imgs='" + imgs + '\'' +
|
||||
", price=" + price +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.rabbiter.em.entity.dto;
|
||||
|
||||
public class UserDTO {
|
||||
private int id;
|
||||
private String username;
|
||||
private String nickname;
|
||||
private String avatarUrl;
|
||||
private String token;
|
||||
private String role;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getAvatarUrl() {
|
||||
return avatarUrl;
|
||||
}
|
||||
|
||||
public void setAvatarUrl(String avatarUrl) {
|
||||
this.avatarUrl = avatarUrl;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserDTO{" +
|
||||
"id=" + id +
|
||||
", username='" + username + '\'' +
|
||||
", nickname='" + nickname + '\'' +
|
||||
", avatarUrl='" + avatarUrl + '\'' +
|
||||
", token='" + token + '\'' +
|
||||
", role='" + role + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.rabbiter.em.exception;
|
||||
|
||||
import com.rabbiter.em.common.Result;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/*
|
||||
全局异常处理
|
||||
*/
|
||||
//@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(ServiceException.class)
|
||||
@ResponseBody
|
||||
public Result handle(ServiceException se){
|
||||
return Result.error(se.getCode(),se.getMessage());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.rabbiter.em.exception;
|
||||
|
||||
/*
|
||||
自定义异常
|
||||
*/
|
||||
public class ServiceException extends RuntimeException {
|
||||
private String code;
|
||||
|
||||
public ServiceException(String code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.rabbiter.em.interceptor;
|
||||
|
||||
import com.rabbiter.em.annotation.Authority;
|
||||
import com.rabbiter.em.utils.TokenUtils;
|
||||
import com.rabbiter.em.entity.AuthorityType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Component
|
||||
public class AuthorityInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
if(handler instanceof HandlerMethod){
|
||||
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
||||
Method method = handlerMethod.getMethod();
|
||||
Class<?> clazz = handlerMethod.getBeanType();
|
||||
if(method!=null && clazz!=null){
|
||||
boolean isMethodAnnotation = method.isAnnotationPresent(Authority.class);
|
||||
boolean isClassAnnotation = clazz.isAnnotationPresent(Authority.class);
|
||||
Authority authority = null;
|
||||
//方法注解会覆盖类注解
|
||||
if(isMethodAnnotation){
|
||||
authority = method.getAnnotation(Authority.class);
|
||||
}else if (isClassAnnotation){
|
||||
authority = clazz.getAnnotation(Authority.class);
|
||||
}
|
||||
if(authority==null){
|
||||
return true;
|
||||
}
|
||||
switch (authority.value()){
|
||||
case requireLogin:
|
||||
return TokenUtils.validateLogin();
|
||||
case requireAuthority:
|
||||
return TokenUtils.validateAuthority();
|
||||
case noRequire:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.rabbiter.em.interceptor;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.JWTVerifier;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.exceptions.JWTVerificationException;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.constants.RedisConstants;
|
||||
import com.rabbiter.em.entity.User;
|
||||
import com.rabbiter.em.exception.ServiceException;
|
||||
import com.rabbiter.em.service.UserService;
|
||||
import com.rabbiter.em.utils.UserHolder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/*
|
||||
第一层拦截器,验证用户token,把redis中的user存到threadlocal
|
||||
*/
|
||||
@Component
|
||||
public class JwtInterceptor implements HandlerInterceptor {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Resource
|
||||
RedisTemplate<String, User> redisTemplate;
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
String token = request.getHeader("token");
|
||||
//如果不是映射到方法,直接通过
|
||||
if(!(handler instanceof HandlerMethod)){
|
||||
return true;
|
||||
}
|
||||
//验证是否有token
|
||||
if(!StringUtils.hasLength(token)){
|
||||
throw new ServiceException(Constants.TOKEN_ERROR,"token失效,请重新登陆");
|
||||
}
|
||||
//通过token,将redis中的user存到threadlocal(UserHolder)
|
||||
User user = redisTemplate.opsForValue().get(RedisConstants.USER_TOKEN_KEY + token);
|
||||
|
||||
if(user == null){
|
||||
throw new ServiceException(Constants.TOKEN_ERROR,"token失效,请重新登陆");
|
||||
}
|
||||
UserHolder.saveUser(user);
|
||||
//重置过期时间
|
||||
redisTemplate.expire(RedisConstants.USER_TOKEN_KEY +token, RedisConstants.USER_TOKEN_TTL, TimeUnit.MINUTES);
|
||||
//验证token
|
||||
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(user.getUsername())).build();
|
||||
try {
|
||||
jwtVerifier.verify(token);
|
||||
}catch (JWTVerificationException e){
|
||||
throw new ServiceException(Constants.TOKEN_ERROR,"token验证失败,请重新登陆");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.rabbiter.em.entity.Address;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
public interface AddressMapper extends BaseMapper<Address> {
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.rabbiter.em.entity.Avatar;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface AvatarMapper {
|
||||
@Insert("insert into avatar(type, size, url, md5) values(#{type},#{size},#{url},#{md5})")
|
||||
public void save(Avatar avatar);
|
||||
|
||||
@Select("select * from avatar where md5 = #{md5}")
|
||||
public Avatar selectByMd5(String md5);
|
||||
|
||||
@Select("select * from avatar where id = #{id}")
|
||||
public Avatar selectById(int id);
|
||||
|
||||
@Delete("delete from avatar where id = #{id}")
|
||||
int delete(int id);
|
||||
@Select("select * from avatar limit #{index},#{pageSize}")
|
||||
List<Avatar> selectPage(int index,int pageSize);
|
||||
@Select("select count(*) from avatar")
|
||||
int getTotal();
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.rabbiter.em.entity.Carousel;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CarouselMapper extends BaseMapper<Carousel> {
|
||||
|
||||
List<Carousel> getAllCarousel();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.rabbiter.em.entity.Cart;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.MapKey;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface CartMapper extends BaseMapper<Cart> {
|
||||
|
||||
@MapKey("id")
|
||||
List<Map<String, Object>> selectByUserId(Long userId);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.rabbiter.em.entity.Category;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
public interface CategoryMapper extends BaseMapper<Category> {
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.rabbiter.em.entity.MyFile;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FileMapper extends BaseMapper<MyFile> {
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.rabbiter.em.entity.Good;
|
||||
import com.rabbiter.em.entity.GoodStandard;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.rabbiter.em.entity.dto.GoodDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public interface GoodMapper extends BaseMapper<Good> {
|
||||
|
||||
@Select("select * from good_standard where good_id = #{id}")
|
||||
List<GoodStandard> getStandardById(int id);
|
||||
|
||||
List<GoodDTO> findFrontGoods();
|
||||
|
||||
@Update("update good set is_delete = 1 where id = #{id}")
|
||||
void fakeDelete(Long id);
|
||||
|
||||
void insertGood(@Param("good") Good good);
|
||||
|
||||
@Select("SELECT discount * MIN(price) FROM good_standard gs, good WHERE good.id = gs.good_id AND good.id = #{id} ")
|
||||
BigDecimal getMinPrice(Long id);
|
||||
|
||||
boolean saleGood(@Param("id")Long goodId,@Param("count") int count,@Param("money") BigDecimal totalPrice);
|
||||
|
||||
|
||||
@Select("SELECT * FROM `good` WHERE is_delete = 0 ORDER BY sale_money DESC LIMIT 0,#{num}")
|
||||
List<Good> getSaleRank(int num);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.rabbiter.em.entity.IconCategory;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface IconCategoryMapper extends BaseMapper<IconCategory> {
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.rabbiter.em.entity.Icon;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IconMapper extends BaseMapper<Icon> {
|
||||
|
||||
List<Icon> getIconCategoryMapList();
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.MapKey;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IncomeMapper {
|
||||
@MapKey("categoryId")
|
||||
List<Map<String, Object>> selectCategoryIncome();
|
||||
|
||||
BigDecimal selectSumIncome();
|
||||
|
||||
BigDecimal getDayIncome(@Param("thisDay")String thisDay,@Param("nextDay") String nextDay);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.rabbiter.em.entity.OrderGoods;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
public interface OrderGoodsMapper extends BaseMapper<OrderGoods> {
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.rabbiter.em.entity.Order;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.MapKey;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface OrderMapper extends BaseMapper<Order> {
|
||||
@Update("update t_order set state = '已支付' where order_no = #{orderNo}")
|
||||
void payOrder(String orderNo);
|
||||
|
||||
@MapKey("id")
|
||||
List<Map<String, Object>> selectByUserId(int userId);
|
||||
|
||||
@Update("update t_order set state = '已收货' where order_no = #{orderNo}")
|
||||
boolean receiveOrder(String orderNo);
|
||||
|
||||
Map<String, Object> selectByOrderNo(String orderNo);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.rabbiter.em.entity.Standard;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
public interface StandardMapper extends BaseMapper<Standard> {
|
||||
@Update("update good_standard set store = #{num} where good_id = #{good_id} and value = #{standard}")
|
||||
void deductStore(@Param("good_id") long good_id, @Param("standard") String standard, @Param("num") int num);
|
||||
|
||||
@Select("select store from good_standard where good_id = #{good_id} and value = #{standard}")
|
||||
int getStore(@Param("good_id") long good_id, @Param("standard")String standard);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.rabbiter.em.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.rabbiter.em.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
/*
|
||||
以下为引入mybatis-plus之前的操作
|
||||
|
||||
@Select("select * from sys_user")
|
||||
List<User> findFrontGoods();
|
||||
@Insert("insert into sys_user(username,password,nickname,email,phone,address) " +
|
||||
"values (#{username},#{password},#{nickname},#{email},#{phone},#{address})")
|
||||
int insert(User user);
|
||||
|
||||
int update(User user);
|
||||
|
||||
@Delete("delete from sys_user where id = #{id}")
|
||||
int deleteById(@Param("id") int id);
|
||||
|
||||
List<User> selectPage(int index,int pageSize,String username,String nickname);
|
||||
|
||||
int searchTotal(String username, String nickname);
|
||||
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.rabbiter.em.entity.Address;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.mapper.AddressMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class AddressService extends ServiceImpl<AddressMapper, Address> {
|
||||
|
||||
@Resource
|
||||
private AddressMapper addressMapper;
|
||||
|
||||
public List<Address> findAllById(Long id) {
|
||||
QueryWrapper<Address> listQueryWrapper = new QueryWrapper<>();
|
||||
listQueryWrapper.eq("user_id",id);
|
||||
return list(listQueryWrapper);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.entity.Avatar;
|
||||
import com.rabbiter.em.exception.ServiceException;
|
||||
import com.rabbiter.em.mapper.AvatarMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class AvatarService {
|
||||
@Resource
|
||||
private AvatarMapper avatarMapper;
|
||||
|
||||
public String upload(MultipartFile uploadFile){
|
||||
String url = null;
|
||||
//通过md5判断文件是否已经存在,防止在服务器存储相同文件
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = uploadFile.getInputStream();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String md5 = SecureUtil.md5(inputStream);
|
||||
Avatar dbAvatar = avatarMapper.selectByMd5(md5);
|
||||
if(dbAvatar==null){
|
||||
String originalFilename = uploadFile.getOriginalFilename(); //文件原始名字
|
||||
String type = originalFilename.substring(originalFilename.lastIndexOf(".")+1); //文件后缀
|
||||
System.out.println(originalFilename+" "+type);
|
||||
long size = uploadFile.getSize() / 1024; //文件大小,单位kb
|
||||
//文件不存在,则保存文件
|
||||
File folder = new File(Constants.avatarFolderPath);
|
||||
if(!folder.exists()){
|
||||
folder.mkdir();
|
||||
}
|
||||
String folderPath = folder.getAbsolutePath()+"/"; //文件存储文件夹的位置
|
||||
System.out.println("文件存储地址"+folderPath);
|
||||
|
||||
|
||||
//将文件保存为UUID的名字,通过uuid生成url
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
String finalFileName = uuid+"."+type;
|
||||
File targetFile = new File(folderPath + finalFileName);
|
||||
try {
|
||||
uploadFile.transferTo(targetFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
url = "/avatar/"+finalFileName;
|
||||
Avatar avatar = new Avatar(type, size, url, md5);
|
||||
System.out.println(avatar);
|
||||
avatarMapper.save(avatar);
|
||||
return url;
|
||||
}
|
||||
return dbAvatar.getUrl();
|
||||
}
|
||||
//根据文件名下载文件
|
||||
public void download(String fileName, HttpServletResponse response){
|
||||
File file = new File(Constants.avatarFolderPath+fileName);
|
||||
if(!file.exists()){
|
||||
throw new ServiceException(Constants.CODE_500,"文件不存在");
|
||||
}
|
||||
try {
|
||||
ServletOutputStream os = response.getOutputStream();
|
||||
response.addHeader("Content-Disposition","attachment;filename="+ URLEncoder.encode(fileName,"UTF-8"));
|
||||
response.setContentType("application/octet-stream");
|
||||
os.write(FileUtil.readBytes(file));
|
||||
os.flush();
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int delete(int id) {
|
||||
Avatar avatar = avatarMapper.selectById(id);
|
||||
int delete = avatarMapper.delete(id);
|
||||
System.out.println(delete);
|
||||
if(delete==1){
|
||||
String fileName = StrUtil.subAfter(avatar.getUrl(),"/",true);
|
||||
System.out.println(fileName);
|
||||
File file = new File(Constants.avatarFolderPath+fileName);
|
||||
System.out.println(file.getAbsolutePath());
|
||||
if(file.exists()){
|
||||
|
||||
boolean delete1 = file.delete();
|
||||
if(delete1){
|
||||
System.out.println("删除成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
return delete;
|
||||
}
|
||||
|
||||
public List<Avatar> selectPage(int index, int pageSize) {
|
||||
return avatarMapper.selectPage(index,pageSize);
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return avatarMapper.getTotal();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import com.rabbiter.em.entity.Carousel;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.mapper.CarouselMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CarouselService extends ServiceImpl<CarouselMapper, Carousel> {
|
||||
|
||||
@Resource
|
||||
private CarouselMapper carouselMapper;
|
||||
|
||||
public List<Carousel> getAllCarousel() {
|
||||
return carouselMapper.getAllCarousel();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import com.rabbiter.em.entity.Cart;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.mapper.CartMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CartService extends ServiceImpl<CartMapper, Cart> {
|
||||
|
||||
@Resource
|
||||
private CartMapper cartMapper;
|
||||
|
||||
public List<Map<String,Object>> selectByUserId(Long userId) {
|
||||
return cartMapper.selectByUserId(userId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.rabbiter.em.entity.Category;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.entity.IconCategory;
|
||||
import com.rabbiter.em.mapper.CategoryMapper;
|
||||
import com.rabbiter.em.mapper.IconCategoryMapper;
|
||||
import com.rabbiter.em.utils.BaseApi;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CategoryService extends ServiceImpl<CategoryMapper, Category> {
|
||||
|
||||
@Resource
|
||||
private CategoryMapper categoryMapper;
|
||||
@Resource
|
||||
private IconCategoryMapper iconCategoryMapper;
|
||||
|
||||
/**
|
||||
* 新增下级分类 + 上下级分类关联
|
||||
*
|
||||
* @param category 下级分类
|
||||
*/
|
||||
public void add(Category category) {
|
||||
save(category);
|
||||
IconCategory iconCategory = new IconCategory();
|
||||
iconCategory.setCategoryId(category.getId());
|
||||
iconCategory.setIconId(category.getIconId());
|
||||
iconCategoryMapper.insert(iconCategory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
*
|
||||
* @param id id
|
||||
* @return 结果
|
||||
*/
|
||||
public Map<String, Object> delete(Long id) {
|
||||
// 删除关联
|
||||
iconCategoryMapper.delete(
|
||||
new QueryWrapper<IconCategory>().eq("category_id", id)
|
||||
);
|
||||
// 删除下级分类
|
||||
removeById(id);
|
||||
return BaseApi.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.entity.MyFile;
|
||||
import com.rabbiter.em.exception.ServiceException;
|
||||
import com.rabbiter.em.mapper.FileMapper;
|
||||
import com.sun.xml.fastinfoset.stax.events.Util;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class FileService extends ServiceImpl<FileMapper, MyFile> {
|
||||
@Resource
|
||||
private FileMapper fileMapper;
|
||||
|
||||
public String upload(MultipartFile uploadFile){
|
||||
String originalFilename = uploadFile.getOriginalFilename(); //文件原始名字
|
||||
String type = originalFilename.substring(originalFilename.lastIndexOf(".")+1); //文件后缀
|
||||
long size = uploadFile.getSize() / 1024; //文件大小,单位kb
|
||||
String url;
|
||||
MyFile myFile = new MyFile(); //用于保存于数据库的实体类Files
|
||||
myFile.setName(originalFilename);
|
||||
myFile.setSize(size);
|
||||
myFile.setType(type);
|
||||
|
||||
//通过md5判断文件是否已经存在,防止在服务器存储相同文件
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = uploadFile.getInputStream();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String md5 = SecureUtil.md5(inputStream);
|
||||
QueryWrapper<MyFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("md5",md5);
|
||||
List<MyFile> dbMyFileList = fileMapper.selectList(queryWrapper);
|
||||
if(dbMyFileList.size() != 0){
|
||||
//数据库中已有该md5,则拷贝其url
|
||||
url = dbMyFileList.get(0) .getUrl();
|
||||
myFile.setUrl(url);
|
||||
}else{
|
||||
//文件不存在,则保存文件
|
||||
File folder = new File(Constants.fileFolderPath);
|
||||
if(!folder.exists()){
|
||||
folder.mkdir();
|
||||
}
|
||||
String folderPath = folder.getAbsolutePath()+"/"; //文件存储文件夹的位置
|
||||
System.out.println("文件存储地址"+folderPath);
|
||||
//将文件保存为UUID的名字,通过uuid生成url
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
String finalFileName = uuid+"."+type;
|
||||
File targetFile = new File(folderPath + finalFileName);
|
||||
try {
|
||||
uploadFile.transferTo(targetFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
url = "/file/"+finalFileName;
|
||||
myFile.setUrl(url);
|
||||
}
|
||||
myFile.setMd5(md5);
|
||||
|
||||
fileMapper.insert(myFile);
|
||||
System.out.println("文件"+originalFilename+" "+url);
|
||||
return url;
|
||||
}
|
||||
|
||||
//根据文件名下载文件
|
||||
public void download(String fileName, HttpServletResponse response){
|
||||
File file = new File(Constants.fileFolderPath+fileName);
|
||||
if(!file.exists()){
|
||||
throw new ServiceException(Constants.CODE_500,"文件不存在");
|
||||
}
|
||||
try {
|
||||
ServletOutputStream os = response.getOutputStream();
|
||||
response.addHeader("Content-Disposition","attachment;filename="+ URLEncoder.encode(fileName,"UTF-8"));
|
||||
response.setContentType("application/octet-stream");
|
||||
os.write(FileUtil.readBytes(file));
|
||||
os.flush();
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public int fakeDelete(int id){
|
||||
UpdateWrapper<MyFile> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id",id).set("is_delete",true);
|
||||
return fileMapper.update(null,updateWrapper);
|
||||
}
|
||||
|
||||
public IPage<MyFile> selectPage(int pageNum,int pageSize,String fileName) {
|
||||
IPage<MyFile> filesPage = new Page<>(pageNum, pageSize);
|
||||
QueryWrapper<MyFile> filesQueryWrapper = new QueryWrapper<>();
|
||||
if(!Util.isEmptyString(fileName)){
|
||||
filesQueryWrapper.like("name",fileName);
|
||||
}
|
||||
filesQueryWrapper.eq("is_delete",false);
|
||||
filesQueryWrapper.orderByDesc("id");
|
||||
return page(filesPage, filesQueryWrapper);
|
||||
}
|
||||
|
||||
|
||||
public int changeEnable(int id, boolean enable) {
|
||||
UpdateWrapper<MyFile> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id",id).set("enable",enable);
|
||||
return fileMapper.update(null, updateWrapper);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.entity.Good;
|
||||
import com.rabbiter.em.entity.GoodStandard;
|
||||
import com.rabbiter.em.entity.dto.GoodDTO;
|
||||
import com.rabbiter.em.exception.ServiceException;
|
||||
import com.rabbiter.em.mapper.GoodMapper;
|
||||
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.rabbiter.em.constants.RedisConstants.GOOD_TOKEN_KEY;
|
||||
import static com.rabbiter.em.constants.RedisConstants.GOOD_TOKEN_TTL;
|
||||
|
||||
@Service
|
||||
public class GoodService extends ServiceImpl<GoodMapper, Good> {
|
||||
|
||||
@Resource
|
||||
private GoodMapper goodMapper;
|
||||
@Resource
|
||||
private RedisTemplate<String, Good> redisTemplate;
|
||||
|
||||
//查询一个商品的信息
|
||||
public Good getGoodById(Long id) {
|
||||
String redisKey = GOOD_TOKEN_KEY + id;
|
||||
//从redis中查,若有则返回
|
||||
ValueOperations<String, Good> valueOperations = redisTemplate.opsForValue();
|
||||
Good redisGood = valueOperations.get(redisKey);
|
||||
if(redisGood!=null){
|
||||
redisTemplate.expire(redisKey,GOOD_TOKEN_TTL, TimeUnit.MINUTES);
|
||||
return redisGood;
|
||||
}
|
||||
//若redis中没有则去数据库查
|
||||
LambdaQueryWrapper<Good> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(Good::getIsDelete,false);
|
||||
queryWrapper.eq(Good::getId,id);
|
||||
Good dbGood = getOne(queryWrapper);
|
||||
if(dbGood!=null){
|
||||
//将商品信息存入redis
|
||||
valueOperations.set(redisKey,dbGood);
|
||||
redisTemplate.expire(redisKey,GOOD_TOKEN_TTL, TimeUnit.MINUTES);
|
||||
return dbGood;
|
||||
}
|
||||
//数据库中没有则返回异常
|
||||
throw new ServiceException(Constants.NO_RESULT,"无结果");
|
||||
|
||||
}
|
||||
//查询商品的规格
|
||||
public String getStandard(int id){
|
||||
List<GoodStandard> standards = goodMapper.getStandardById(id);
|
||||
if(standards.size()==0){
|
||||
throw new ServiceException(Constants.NO_RESULT,"无结果");
|
||||
}
|
||||
return JSON.toJSONString(standards);
|
||||
}
|
||||
//查询某商品的最低规格价
|
||||
public BigDecimal getMinPrice(Long id){
|
||||
return goodMapper.getMinPrice(id);
|
||||
}
|
||||
//查询全部(首页推荐商品)
|
||||
public List<GoodDTO> findFrontGoods() {
|
||||
return goodMapper.findFrontGoods();
|
||||
}
|
||||
|
||||
|
||||
//假删除
|
||||
public void deleteGood(Long id) {
|
||||
redisTemplate.delete(GOOD_TOKEN_KEY+id);
|
||||
goodMapper.fakeDelete(id);
|
||||
}
|
||||
//保存商品信息
|
||||
public Long saveOrUpdateGood(Good good) {
|
||||
System.out.println(good);
|
||||
if(good.getId()==null){
|
||||
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
good.setCreateTime(df.format(LocalDateTime.now()));
|
||||
goodMapper.insertGood(good);
|
||||
}else{
|
||||
saveOrUpdate(good);
|
||||
redisTemplate.delete(GOOD_TOKEN_KEY + good.getId());
|
||||
}
|
||||
return good.getId();
|
||||
}
|
||||
|
||||
public boolean setRecommend(Long id,Boolean isRecommend) {
|
||||
LambdaUpdateWrapper<Good> goodsLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
goodsLambdaUpdateWrapper.eq(Good::getId,id)
|
||||
.set(Good::getRecommend,isRecommend);
|
||||
return update(goodsLambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
public List<Good> getSaleRank(int num) {
|
||||
return goodMapper.getSaleRank(num);
|
||||
}
|
||||
|
||||
|
||||
public void update(Good good) {
|
||||
updateById(good);
|
||||
redisTemplate.delete(GOOD_TOKEN_KEY + good.getId());
|
||||
}
|
||||
//分页查询
|
||||
public IPage<GoodDTO> findPage(Integer pageNum, Integer pageSize, String searchText, Integer categoryId) {
|
||||
LambdaQueryWrapper<Good> query = Wrappers.<Good>lambdaQuery().orderByDesc(Good::getId);
|
||||
//对名称和描述进行模糊查询
|
||||
if (StrUtil.isNotBlank(searchText)) {
|
||||
query.like(Good::getName, searchText).or().like(Good::getDescription,searchText).or().eq(Good::getId,searchText);
|
||||
}
|
||||
if(categoryId != null){
|
||||
query.eq(Good::getCategoryId,categoryId);
|
||||
}
|
||||
//筛除掉已被删除的商品
|
||||
query.eq(Good::getIsDelete,false);
|
||||
IPage<Good> page = this.page(new Page<>(pageNum, pageSize), query);
|
||||
//把good转为dto
|
||||
IPage<GoodDTO> goodDTOPage = page.convert(good -> {
|
||||
GoodDTO goodDTO = new GoodDTO();
|
||||
BeanUtil.copyProperties(good, goodDTO);
|
||||
return goodDTO;
|
||||
});
|
||||
for (GoodDTO good : goodDTOPage.getRecords()) {
|
||||
//附上最低价格
|
||||
good.setPrice(getMinPrice(good.getId()));
|
||||
}
|
||||
return goodDTOPage;
|
||||
}
|
||||
public IPage<Good> findFullPage(Integer pageNum, Integer pageSize, String searchText, Integer categoryId) {
|
||||
LambdaQueryWrapper<Good> query = Wrappers.<Good>lambdaQuery().orderByDesc(Good::getId);
|
||||
//对名称和描述进行模糊查询
|
||||
if (StrUtil.isNotBlank(searchText)) {
|
||||
query.like(Good::getName, searchText).or().like(Good::getDescription,searchText).or().eq(Good::getId,searchText);
|
||||
}
|
||||
if(categoryId != null){
|
||||
query.eq(Good::getCategoryId,categoryId);
|
||||
}
|
||||
//筛除掉已被删除的商品
|
||||
query.eq(Good::getIsDelete,false);
|
||||
IPage<Good> page = this.page(new Page<>(pageNum, pageSize), query);
|
||||
for (Good good : page.getRecords()) {
|
||||
//附上最低价格
|
||||
good.setPrice(getMinPrice(good.getId()));
|
||||
}
|
||||
return page;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.rabbiter.em.entity.Icon;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.entity.IconCategory;
|
||||
import com.rabbiter.em.mapper.IconCategoryMapper;
|
||||
import com.rabbiter.em.mapper.IconMapper;
|
||||
import com.rabbiter.em.utils.BaseApi;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class IconService extends ServiceImpl<IconMapper, Icon> {
|
||||
|
||||
@Resource
|
||||
private IconMapper iconMapper;
|
||||
|
||||
@Resource
|
||||
private IconCategoryMapper iconCategoryMapper;
|
||||
|
||||
public List<Icon> getIconCategoryMapList() {
|
||||
return iconMapper.getIconCategoryMapList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除上级分类
|
||||
*
|
||||
* @param id id
|
||||
*/
|
||||
public Map<String, Object> deleteById(Long id) {
|
||||
// 检查是否包含下级分类
|
||||
Long count = iconCategoryMapper.selectCount(
|
||||
new QueryWrapper<IconCategory>().eq("icon_id", id)
|
||||
);
|
||||
if (count > 0) {
|
||||
return BaseApi.error("该上级分类存在下级分类,请删除所有下级分类再尝试删除");
|
||||
}
|
||||
super.removeById(id);
|
||||
return BaseApi.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.rabbiter.em.mapper.IncomeMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class IncomeService {
|
||||
@Resource
|
||||
private IncomeMapper incomeMapper;
|
||||
|
||||
public Map<String,Object> getChart() {
|
||||
Map<String, Object> chartMap = new HashMap<>();
|
||||
//查询每个分类及其收入
|
||||
List<Map<String, Object>> categoryIncomes = incomeMapper.selectCategoryIncome();
|
||||
//查询总收入
|
||||
BigDecimal sumIncome = incomeMapper.selectSumIncome();
|
||||
//放入HashMap中并返回
|
||||
chartMap.put("categoryIncomes",categoryIncomes);
|
||||
chartMap.put("sumIncome",sumIncome);
|
||||
return chartMap;
|
||||
}
|
||||
|
||||
public Map<String,Object> getWeekIncome() {
|
||||
ArrayList<BigDecimal> weekIncome = new ArrayList<>();
|
||||
ArrayList<String> weekDays = new ArrayList<>();
|
||||
DateTime dateTime = DateUtil.beginOfWeek(DateUtil.date());
|
||||
for (int i = 0; i < 7; i++) {
|
||||
DateTime thisDay = DateUtil.offsetDay(dateTime, i);
|
||||
DateTime nextDay = DateUtil.offsetDay(dateTime, i+1);
|
||||
String weekDay = thisDay.toString();
|
||||
String formattedWeekday = weekDay.substring(weekDay.indexOf("-")+1,weekDay.indexOf(" "));
|
||||
weekDays.add(formattedWeekday);
|
||||
BigDecimal dayIncome = incomeMapper.getDayIncome(thisDay.toString(), nextDay.toString());
|
||||
if(dayIncome == null){
|
||||
dayIncome = new BigDecimal(0);
|
||||
}
|
||||
weekIncome.add(dayIncome);
|
||||
}
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("weekDays",weekDays);
|
||||
map.put("weekIncome",weekIncome);
|
||||
return map;
|
||||
}
|
||||
|
||||
public Map<String,Object> getMonthIncome() {
|
||||
ArrayList<BigDecimal> monthIncome = new ArrayList<>();
|
||||
ArrayList<String> monthDays = new ArrayList<>();
|
||||
DateTime dateTime = DateUtil.beginOfMonth(DateUtil.date());
|
||||
for (int i = 0; i < 30; i++) {
|
||||
DateTime thisDay = DateUtil.offsetDay(dateTime, i);
|
||||
DateTime nextDay = DateUtil.offsetDay(dateTime, i+1);
|
||||
String weekDay = thisDay.toString();
|
||||
String formattedWeekday = weekDay.substring(weekDay.indexOf("-")+1,weekDay.indexOf(" "));
|
||||
monthDays.add(formattedWeekday);
|
||||
BigDecimal dayIncome = incomeMapper.getDayIncome(thisDay.toString(), nextDay.toString());
|
||||
if(dayIncome == null){
|
||||
dayIncome = new BigDecimal(0);
|
||||
}
|
||||
monthIncome.add(dayIncome);
|
||||
}
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("monthDays",monthDays);
|
||||
map.put("monthIncome",monthIncome);
|
||||
return map;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import com.rabbiter.em.entity.OrderGoods;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.mapper.OrderGoodsMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class OrderGoodsService extends ServiceImpl<OrderGoodsMapper, OrderGoods> {
|
||||
|
||||
@Resource
|
||||
private OrderGoodsMapper orderGoodsMapper;
|
||||
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.entity.Good;
|
||||
import com.rabbiter.em.entity.Order;
|
||||
import com.rabbiter.em.entity.OrderGoods;
|
||||
import com.rabbiter.em.entity.OrderItem;
|
||||
import com.rabbiter.em.exception.ServiceException;
|
||||
import com.rabbiter.em.mapper.GoodMapper;
|
||||
import com.rabbiter.em.mapper.OrderGoodsMapper;
|
||||
import com.rabbiter.em.mapper.OrderMapper;
|
||||
import com.rabbiter.em.mapper.StandardMapper;
|
||||
import com.rabbiter.em.utils.TokenUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.rabbiter.em.constants.RedisConstants.GOOD_TOKEN_KEY;
|
||||
|
||||
@Service
|
||||
public class OrderService extends ServiceImpl<OrderMapper, Order> {
|
||||
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
@Resource
|
||||
private OrderGoodsMapper orderGoodsMapper;
|
||||
@Resource
|
||||
private StandardMapper standardMapper;
|
||||
@Resource
|
||||
private GoodMapper goodMapper;
|
||||
@Resource
|
||||
private CartService cartService;
|
||||
@Resource
|
||||
private RedisTemplate<String, Good> redisTemplate;
|
||||
|
||||
@Transactional
|
||||
public String saveOrder(Order order) {
|
||||
order.setUserId(TokenUtils.getCurrentUser().getId());
|
||||
String orderNo = DateUtil.format(new Date(), "yyyyMMddHHmmss") + RandomUtil.randomNumbers(6);
|
||||
order.setOrderNo(orderNo);
|
||||
order.setCreateTime(DateUtil.now());
|
||||
orderMapper.insert(order);
|
||||
|
||||
OrderGoods orderGoods = new OrderGoods();
|
||||
orderGoods.setOrderId(order.getId());
|
||||
//遍历order里携带的goods数组,并用orderItem对象来接收
|
||||
String goods = order.getGoods();
|
||||
List<OrderItem> orderItems = JSON.parseArray(goods, OrderItem.class);
|
||||
for (OrderItem orderItem : orderItems) {
|
||||
long good_id = orderItem.getId();
|
||||
String standard = orderItem.getStandard();
|
||||
int num = orderItem.getNum();
|
||||
orderGoods.setGoodId(good_id);
|
||||
orderGoods.setCount(num);
|
||||
orderGoods.setStandard(standard);
|
||||
//插入到order_good表
|
||||
orderGoodsMapper.insert(orderGoods);
|
||||
}
|
||||
// 清除购物车
|
||||
cartService.removeById(order.getCartId());
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
//给订单付款
|
||||
@Transactional
|
||||
public void payOrder(String orderNo) {
|
||||
//更改状态为代付款
|
||||
orderMapper.payOrder(orderNo);
|
||||
//给对应规格减库存
|
||||
Map<String, Object> orderMap = orderMapper.selectByOrderNo(orderNo);
|
||||
int count = (int) orderMap.get("count");
|
||||
Object goodIdObj = orderMap.get("goodId");
|
||||
Long goodId = null;
|
||||
if(goodIdObj instanceof Long) {
|
||||
goodId = (Long) goodIdObj;
|
||||
} else if(goodIdObj != null) {
|
||||
try {
|
||||
goodId = Long.parseLong(goodIdObj.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ServiceException(Constants.CODE_500, "商品ID不正确");
|
||||
}
|
||||
}
|
||||
|
||||
if(goodId == null) {
|
||||
throw new ServiceException(Constants.CODE_500, "商品ID不存在");
|
||||
}
|
||||
String standard = (String) orderMap.get("standard");
|
||||
int store = standardMapper.getStore(goodId, standard);
|
||||
if (store < count) {
|
||||
throw new ServiceException(Constants.CODE_500, "库存不足");
|
||||
}
|
||||
standardMapper.deductStore(goodId, standard, store - count);
|
||||
|
||||
//给对应商品加销量和销售额
|
||||
LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
orderLambdaQueryWrapper.eq(Order::getOrderNo, orderNo);
|
||||
Order one = getOne(orderLambdaQueryWrapper);
|
||||
BigDecimal totalPrice = one.getTotalPrice();
|
||||
goodMapper.saleGood(goodId, count, totalPrice);
|
||||
|
||||
// redis 增销量
|
||||
String redisKey = GOOD_TOKEN_KEY + goodId;
|
||||
ValueOperations<String, Good> valueOperations = redisTemplate.opsForValue();
|
||||
Good good = valueOperations.get(redisKey);
|
||||
if(!ObjectUtils.isEmpty(good)) {
|
||||
good.setSales(good.getSales() + count);
|
||||
valueOperations.set(redisKey, good);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> selectByUserId(int userId) {
|
||||
return orderMapper.selectByUserId(userId);
|
||||
}
|
||||
|
||||
public boolean receiveOrder(String orderNo) {
|
||||
return orderMapper.receiveOrder(orderNo);
|
||||
}
|
||||
|
||||
public Map<String, Object> selectByOrderNo(String orderNo) {
|
||||
return orderMapper.selectByOrderNo(orderNo);
|
||||
}
|
||||
|
||||
public void delivery(String orderNo) {
|
||||
LambdaUpdateWrapper<Order> orderLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
orderLambdaUpdateWrapper.eq(Order::getOrderNo, orderNo)
|
||||
.set(Order::getState, "已发货");
|
||||
update(orderLambdaUpdateWrapper);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.rabbiter.em.entity.Standard;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.mapper.StandardMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class StandardService extends ServiceImpl<StandardMapper, Standard> {
|
||||
|
||||
@Resource
|
||||
private StandardMapper standardMapper;
|
||||
|
||||
public boolean delete(Standard standard) {
|
||||
QueryWrapper<Standard> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("good_id",standard.getGoodId());
|
||||
queryWrapper.eq("value",standard.getValue());
|
||||
return remove(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
public void deleteAll(int GoodId) {
|
||||
QueryWrapper<Standard> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("good_id",GoodId);
|
||||
remove(queryWrapper);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
package com.rabbiter.em.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rabbiter.em.common.Result;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.constants.RedisConstants;
|
||||
import com.rabbiter.em.entity.LoginForm;
|
||||
import com.rabbiter.em.entity.User;
|
||||
import com.rabbiter.em.entity.dto.UserDTO;
|
||||
import com.rabbiter.em.exception.ServiceException;
|
||||
import com.rabbiter.em.mapper.UserMapper;
|
||||
import com.rabbiter.em.utils.TokenUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.Serializable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
@Service
|
||||
public class UserService extends ServiceImpl<UserMapper, User> {
|
||||
@Resource
|
||||
RedisTemplate<String,User> redisTemplate;
|
||||
|
||||
public UserDTO login(LoginForm loginForm) {
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("username",loginForm.getUsername());
|
||||
queryWrapper.eq("password",loginForm.getPassword());
|
||||
User user = getOne(queryWrapper);
|
||||
if(user == null) {
|
||||
throw new ServiceException(Constants.CODE_403,"用户名或密码错误");
|
||||
}
|
||||
String token = TokenUtils.genToken(user.getId().toString(), user.getUsername());
|
||||
//把用户存到redis中
|
||||
redisTemplate.opsForValue().set(RedisConstants.USER_TOKEN_KEY + token,user);
|
||||
//jwt不设置过期时间,只设置redis过期时间。
|
||||
redisTemplate.expire(RedisConstants.USER_TOKEN_KEY +token, RedisConstants.USER_TOKEN_TTL, TimeUnit.MINUTES);
|
||||
//把查到的user的一些属性赋值给userDTO
|
||||
UserDTO userDTO = BeanUtil.copyProperties(user,UserDTO.class);
|
||||
//设置token
|
||||
userDTO.setToken(token);
|
||||
return userDTO;
|
||||
|
||||
}
|
||||
|
||||
public User register(LoginForm loginForm) {
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("username",loginForm.getUsername());
|
||||
User user = getOne(queryWrapper);
|
||||
if(user!=null){
|
||||
throw new ServiceException(Constants.CODE_403,"用户名已被使用");
|
||||
}else{
|
||||
user = new User();
|
||||
BeanUtils.copyProperties(loginForm,user);
|
||||
user.setNickname("新用户");
|
||||
user.setRole("user");
|
||||
save(user);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
public User getOne(String username){
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("username",username);
|
||||
return getOne(queryWrapper);
|
||||
}
|
||||
|
||||
public Result saveUpdate(User user) {
|
||||
if(user.getId() != null) {
|
||||
// 修改
|
||||
User old = this.baseMapper.selectById(user.getId());
|
||||
old.setNickname(ObjectUtils.isEmpty(user.getNickname()) ? old.getNickname() : user.getNickname());
|
||||
old.setAvatarUrl(ObjectUtils.isEmpty(user.getAvatarUrl()) ? old.getAvatarUrl() : user.getAvatarUrl());
|
||||
old.setRole(ObjectUtils.isEmpty(user.getRole()) ? old.getRole() : user.getRole());
|
||||
old.setPhone(ObjectUtils.isEmpty(user.getPhone()) ? old.getPhone() : user.getPhone());
|
||||
old.setEmail(ObjectUtils.isEmpty(user.getEmail()) ? old.getEmail() : user.getEmail());
|
||||
old.setAddress(ObjectUtils.isEmpty(user.getAddress()) ? old.getAddress() : user.getAddress());
|
||||
super.updateById(old);
|
||||
return Result.success("修改成功");
|
||||
} else {
|
||||
// 新增
|
||||
if(!ObjectUtils.isEmpty(this.getOne(user.getUsername()))) {
|
||||
return Result.error("400", "用户名已存在");
|
||||
}
|
||||
user.setPassword(user.getNewPassword());
|
||||
super.save(user);
|
||||
return Result.success("新增成功");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeById(Serializable id) {
|
||||
return super.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @param id 用户id
|
||||
* @param newPassword 新密码
|
||||
*/
|
||||
public void resetPassword(String id, String newPassword) {
|
||||
User user = this.getById(id);
|
||||
if(user == null) {
|
||||
return;
|
||||
}
|
||||
user.setPassword(newPassword);
|
||||
this.updateById(user);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.rabbiter.em.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BaseApi {
|
||||
private static Map<String, Object> map(String code, Object data, String msg) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", code);
|
||||
map.put("data", data);
|
||||
map.put("msg", msg);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Map<String, Object> success() {
|
||||
return map("200", null, null);
|
||||
}
|
||||
|
||||
public static Map<String, Object> success(Object data) {
|
||||
return map("200", data, null);
|
||||
}
|
||||
|
||||
public static Map<String, Object> error(String msg) {
|
||||
return map("400", null, msg);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.rabbiter.em.utils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
public class PathUtils {
|
||||
public static String getClassLoadRootPath() {
|
||||
String path = "";
|
||||
try {
|
||||
String prePath = URLDecoder.decode(PathUtils.class.getClassLoader().getResource("").getPath(),"utf-8").replace("/target/classes", "");
|
||||
String osName = System.getProperty("os.name");
|
||||
if (osName.toLowerCase().startsWith("mac")) {
|
||||
// 苹果
|
||||
path = prePath.substring(0, prePath.length() - 1);
|
||||
} else if (osName.toLowerCase().startsWith("windows")) {
|
||||
// windows
|
||||
path = prePath.substring(1, prePath.length() - 1);
|
||||
} else if(osName.toLowerCase().startsWith("linux") || osName.toLowerCase().startsWith("unix")) {
|
||||
// unix or linux
|
||||
path = prePath.substring(0, prePath.length() - 1);
|
||||
} else {
|
||||
path = prePath.substring(1, prePath.length() - 1);
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.rabbiter.em.utils;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.rabbiter.em.constants.Constants;
|
||||
import com.rabbiter.em.entity.User;
|
||||
import com.rabbiter.em.exception.ServiceException;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class TokenUtils {
|
||||
|
||||
public static String genToken(String userId, String username){
|
||||
String token = JWT.create()
|
||||
.withAudience(userId)
|
||||
.sign(Algorithm.HMAC256(username));
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
public static User getCurrentUser(){
|
||||
try{
|
||||
return UserHolder.getUser();
|
||||
}catch (Exception e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static boolean validateLogin(){
|
||||
try{
|
||||
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||
String token = request.getHeader("token");
|
||||
if(StringUtils.hasLength(token)){
|
||||
JWT.decode(token).getAudience();
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}catch (Exception e){
|
||||
throw new ServiceException(Constants.CODE_401,"登录状态失效!");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean validateAuthority(){
|
||||
try{
|
||||
User user = getCurrentUser();
|
||||
if(user.getRole().equals("admin")){
|
||||
return true;
|
||||
}
|
||||
}catch (Exception e){
|
||||
return false;
|
||||
}
|
||||
throw new ServiceException(Constants.CODE_403,"无权限!");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.rabbiter.em.utils;
|
||||
|
||||
import com.rabbiter.em.entity.User;
|
||||
|
||||
public class UserHolder {
|
||||
private static final ThreadLocal<User> userThreadLocal = new ThreadLocal<>();
|
||||
|
||||
public static void saveUser(User user){
|
||||
userThreadLocal.set(user);
|
||||
}
|
||||
|
||||
public static User getUser(){
|
||||
return userThreadLocal.get();
|
||||
}
|
||||
|
||||
public static void removeUser(){
|
||||
userThreadLocal.remove();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
server:
|
||||
port: 9191
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/electronic_mall?serverTimezone=GMT%2b8&userSSL=false&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 'root'
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 30MB
|
||||
redis:
|
||||
database: 0
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
lettuce:
|
||||
pool:
|
||||
min-idle: 0
|
||||
max-active: 8
|
||||
max-idle: 8
|
||||
max-wait: -1ms
|
||||
connect-timeout: 30000ms
|
||||
|
||||
mybatis:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.rabbiter.em.mapper.AddressMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.rabbiter.em.mapper.CarouselMapper">
|
||||
|
||||
<select id="getAllCarousel" resultType="com.rabbiter.em.entity.Carousel">
|
||||
select carousel.*,good.name as good_name,good.imgs as img from carousel,good where good.id = carousel.good_id order by show_order asc
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.rabbiter.em.mapper.CartMapper">
|
||||
<resultMap id="cartResultMap" type="hashmap">
|
||||
<result column="id" property="id"></result>
|
||||
<result column="user_id" property="userId"></result>
|
||||
<result column="good_id" property="goodId"></result>
|
||||
<result column="name" property="goodName"></result>
|
||||
<result column="imgs" property="img"></result>
|
||||
<result column="standard" property="standard"></result>
|
||||
<result column="store" property="store"></result>
|
||||
<result column="price" property="price"></result>
|
||||
<result column="discount" property="discount"></result>
|
||||
<result column="count" property="count"></result>
|
||||
<result column="create_time" property="createTime"></result>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectByUserId" resultMap="cartResultMap">
|
||||
SELECT cart.*,good_standard.price,good.imgs,`name`,discount,store
|
||||
FROM cart,good_standard,good
|
||||
WHERE cart.good_id = good.id AND cart.good_id = good_standard.good_id AND cart.standard = good_standard.`value`
|
||||
AND cart.user_id = #{userId}
|
||||
ORDER BY cart.create_time DESC
|
||||
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.rabbiter.em.mapper.CategoryMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.rabbiter.em.mapper.GoodMapper">
|
||||
<insert id="insertGood" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into good(name, description, discount, category_id, imgs, create_time) value (#{good.name},#{good.description},#{good.discount},#{good.categoryId},#{good.imgs},#{good.createTime})
|
||||
</insert>
|
||||
<update id="saleGood">
|
||||
update `good` set sales = sales + #{count} ,sale_money = sale_money + #{money} where good.id = #{id}
|
||||
</update>
|
||||
|
||||
|
||||
<select id="findFrontGoods" resultType="com.rabbiter.em.entity.dto.GoodDTO">
|
||||
SELECT good.*,MIN(good_standard.price)*discount as price FROM `good` LEFT JOIN good_standard on good.id = good_standard.good_id WHERE is_delete = 0 AND recommend = 1 GROUP BY id ORDER BY price ASC
|
||||
</select>
|
||||
</mapper>
|