diff --git a/README.md b/README.md index b1ebfac..eb1ca99 100644 --- a/README.md +++ b/README.md @@ -130,92 +130,81 @@ # 如何部署? --- -### 1.下载源码 +### 下载源码 将源码下载下来,使用Idea选择open的方式打开项目(第一次打开需要下载项目对应的第三方依赖,需要等待2~3分钟) ![](https://img-blog.csdnimg.cn/e5e5f9f23bb24fc286caa56564df7857.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5LqR5Li26KiA,size_20,color_FFFFFF,t_70,g_se,x_16) -### 2.配置文件 +### 配置文件 修改项目配置文件application.yml,主要将服务器ip地址、MySQL、Redis连接信息按照自己的需求进行修改即可。 ![](https://img-blog.csdnimg.cn/1281208680ff4461a48202f71629a285.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5LqR5Li26KiA,size_20,color_FFFFFF,t_70,g_se,x_16) ![](https://img-blog.csdnimg.cn/0c0547bf787c4877b62557cd2d17e729.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5LqR5Li26KiA,size_20,color_FFFFFF,t_70,g_se,x_16) -### 3.打包项目 -填写好项目配置信息后,就可以开始打包项目了:按照下图所示的步骤依次执行,最后打包好的 **`jieyue.jar`** 将会存放在 **`target`** 目录中。 -![](https://img-blog.csdnimg.cn/11e170bd1863418d99b38caebcb12c10.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LqR5Li26KiA,size_20,color_FFFFFF,t_70,g_se,x_16) +### 打包项目 +填写好项目配置信息后,就可以开始打包项目了:按照下图所示的步骤依次执行,最后打包好的 **`ROOT.war`** 将会存放在 **`target`** 目录中。 + +![在这里插入图片描述](https://img-blog.csdnimg.cn/12fa198275c14466804d553efd8b17a7.png) -### 4.安装Docker + +### 安装Docker docker的安装流程可参考下面这篇文章,笔者在这里就不再赘述了:**[https://www.runoob.com/docker/centos-docker-install.html](https://www.runoob.com/docker/centos-docker-install.html)**
-### 5.安装MySQL -5.1:执行如下命令拉取MySQL的Docker镜像 +### 安装MySQL +1:执行如下命令拉取MySQL的Docker镜像 ```bash docker pull hub.c.163.com/library/mysql:latest ``` -5.2:镜像拉取后,执行如下命令运行MySQL(注意:MYSQL_ROOT_PASSWORD中的密码需要与项目配置文件中的MySQL密码保持一致) +2:镜像拉取后,执行如下命令运行MySQL(注意:MYSQL_ROOT_PASSWORD中的密码需要与项目配置文件中的MySQL密码保持一致) ```bash docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d hub.c.163.com/library/mysql:latest ``` -5.3:MySQL运行成功后,需要对MySQL的数据进行初始化,这里笔者推荐使用可视化工具Navicat,填入对应的信息即可成功连接 +3:MySQL运行成功后,需要对MySQL的数据进行初始化,这里笔者推荐使用可视化工具Navicat,填入对应的信息即可成功连接 ![](https://img-blog.csdnimg.cn/3bc392ebdbf249dd93a765bcf8d41733.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5LqR5Li26KiA,size_20,color_FFFFFF,t_70,g_se,x_16) -5.4:新建一个名为jieyue的数据库,创建成功后双击该数据库创立连接,接着右击,选择**运行SQL文件**,运行项目根目录下的 **`jieyue.sql`** 文件即可。 +4:新建一个名为jieyue的数据库,创建成功后双击该数据库创立连接,接着右击,选择**运行SQL文件**,运行项目根目录下的 **`jieyue.sql`** 文件即可。 ![](https://img-blog.csdnimg.cn/be8eccc8a0084db8a087d8287034cfc3.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5LqR5Li26KiA,size_19,color_FFFFFF,t_70,g_se,x_16) -### 6.安装Redis -6.1:执行如下命令拉取Redis的Docker镜像 +### 安装Redis +1:执行如下命令拉取Redis的Docker镜像 ```bash docker pull hub.c.163.com/library/redis:latest ``` -6.2:执行如下命令运行Redis +2:执行如下命令运行Redis ```bash docker run -d -p 6379:6379 --name redis hub.c.163.com/library/redis:latest ```
-### 7.安装OpenJDK -7.1:执行如下命令拉取OpenJDK的Docker镜像 +### 安装Tomcat +1:执行如下命令拉取Tomcat的Docker镜像 ```bash -docker pull hub.c.163.com/cloudndp/library/openjdk:8-jessie +docker pull hub.c.163.com/library/tomcat:8.5 ``` -7.2:在 **`jieyue.jar`** 包同一目录下创建 **`Dockerfile`** 文件,具体内容如下 - +2:执行如下命令运行Tomcat ```bash -FROM hub.c.163.com/cloudndp/library/openjdk:8-jessie - -COPY jieyue.jar /jieyue.jar - -CMD java -jar /jieyue.jar - -EXPOSE 80 +docker run -d -p 80:8080 -e LANG=C.UTF-8 -e TZ="Asia/Shanghai" --name tomcat hub.c.163.com/library/tomcat:8.5 ``` -7.3:在 **`jieyue.jar`** 包同一目录下执行如下命令,创建镜像 - +3:使用如下命令进入tomcat容器内,将`/usr/local/tomcat/webapps`路径下的`ROOT`文件夹删除 ```bash -docker build -t jieyue-image . +docker exec -it tomcat bash ``` -7.4:最后运行容器即可 +4:退出容器,来到存放 **`ROOT.war`** 的目录,执行如下命令,将项目文件拷贝进容器tomcat容器中 ```bash -docker run -d -p 80:80 -e LANG=C.UTF-8 -e TZ="Asia/Shanghai" --name jieyue jieyue-image +docker cp ROOT.war tomcat:/usr/local/tomcat/webapps ``` -7.5:使用如下命令可查看项目运行日志(若有如下字眼出现,则表明容器运行成功) +4:最后重启Tomcat ```bash -docker logs jieyue +docker restart tomcat ``` -![](https://img-blog.csdnimg.cn/1be4eb72a24a449d893a9d973310b073.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LqR5Li26KiA,size_20,color_FFFFFF,t_70,g_se,x_16) -7.6:成功运行后,访问配置文件中填写的服务器ip地址即可(如:笔者这里填写的是199.91.222.184,访问[http://119.91.222.184/](http://119.91.222.184/),就可以看到网站的主页)至此,捷阅网已成功部署~~!! +5:成功运行后,访问配置文件中填写的服务器ip地址即可(如:笔者这里填写的是199.91.222.184,访问 **[http://119.91.222.184/](http://119.91.222.184/)**,就可以看到网站的主页)至此,捷阅网已成功部署~~!! +
# 有关网站制作者 --- -**个 人 主 页: [云丶言](https://bosen-once.gitee.io/)** -![](https://img-blog.csdnimg.cn/c3f49c6533dc401b9d00bb3655f7e5fb.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5LqR5Li26KiA,size_15,color_FFFFFF,t_70,g_se,x_16#pic_center) - ---- - **CSDN博客:[云丶言](https://blog.csdn.net/weixin_47600880)** ![](https://img-blog.csdnimg.cn/45557a1b39054cc6ae793079c8e4f178.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5LqR5Li26KiA,size_15,color_FFFFFF,t_70,g_se,x_16#pic_center) diff --git a/jieyue.sql b/jieyue.sql index 905cfad..176f6c7 100644 --- a/jieyue.sql +++ b/jieyue.sql @@ -11,7 +11,7 @@ Target Server Version : 50716 File Encoding : 65001 - Date: 28/03/2022 20:07:01 + Date: 23/05/2022 00:43:13 */ SET NAMES utf8mb4; @@ -98,9 +98,9 @@ INSERT INTO `sys_cart` VALUES (10, 70, 1, 1); INSERT INTO `sys_cart` VALUES (11, 51, 1, 1); INSERT INTO `sys_cart` VALUES (12, 73, 1, 1); INSERT INTO `sys_cart` VALUES (13, 47, 1, 1); -INSERT INTO `sys_cart` VALUES (14, 47, 3, 1); -INSERT INTO `sys_cart` VALUES (15, 48, 3, 1); -INSERT INTO `sys_cart` VALUES (16, 46, 3, 1); +INSERT INTO `sys_cart` VALUES (14, 47, 2, 1); +INSERT INTO `sys_cart` VALUES (15, 48, 2, 1); +INSERT INTO `sys_cart` VALUES (16, 46, 2, 1); INSERT INTO `sys_cart` VALUES (17, 45, 3, 1); -- ---------------------------- @@ -171,7 +171,7 @@ CREATE TABLE `sys_goods` ( `merchant` int(11) NOT NULL COMMENT '商品所属的商户id', `stock` int(11) NOT NULL DEFAULT 0 COMMENT '商品库存', PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 75 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +) ENGINE = InnoDB AUTO_INCREMENT = 76 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sys_goods @@ -232,6 +232,7 @@ INSERT INTO `sys_goods` VALUES (71, '安踏官方旗舰老爹鞋女鞋', '安踏 INSERT INTO `sys_goods` VALUES (72, '安踏脉冲2代男鞋', '安踏脉冲2代男鞋男2021春季新款男士户外休闲鞋旅游鞋官方旗舰网店912118852 浅米白/墨水蓝-1 8.5(男42)', '/data/goods/14/20210330213810878030.jpg', 0.01, 1, 14, 9); INSERT INTO `sys_goods` VALUES (73, '安踏女休闲鞋2021春季新款', '安踏女休闲鞋2021春季新款轻便跑步鞋子潮流时尚女鞋老爹鞋女运动鞋子百搭猫爪鞋官方旗舰网店 象牙白/迷雾紫/浅雾灰-5 6.5(女37.5)', '/data/goods/14/20210330213829639750.jpg', 0.01, 1, 14, 10); INSERT INTO `sys_goods` VALUES (74, '测试商品(勿拍)', '这是一只用于测试的海绵宝宝,勿拍!!!', '/data/goods/11/20210330220346963836.jpg', 0.01, 0, 11, 4); +INSERT INTO `sys_goods` VALUES (75, '1', '1', '/data/goods/13/20220522235640383480.jpg', 1.00, 0, 13, 1); -- ---------------------------- -- Table structure for sys_mt @@ -309,15 +310,9 @@ CREATE TABLE `sys_notice` ( -- Records of sys_notice -- ---------------------------- INSERT INTO `sys_notice` VALUES (30, '系统群发消息测试', '系统群发消息测试(无需理会)', '2', 1, 1648468781372); -INSERT INTO `sys_notice` VALUES (31, '系统群发消息测试', '系统群发消息测试(无需理会)', '2', 3, 1648468781375); -INSERT INTO `sys_notice` VALUES (32, '系统群发消息测试', '系统群发消息测试(无需理会)', '2', 4, 1648468781376); -INSERT INTO `sys_notice` VALUES (33, '系统群发消息测试', '系统群发消息测试(无需理会)', '2', 5, 1648468781377); -INSERT INTO `sys_notice` VALUES (34, '系统群发消息测试', '系统群发消息测试(无需理会)', '2', 7, 1648468781378); +INSERT INTO `sys_notice` VALUES (31, '系统群发消息测试', '系统群发消息测试(无需理会)', '2', 2, 1648468781375); INSERT INTO `sys_notice` VALUES (35, '欢迎访问捷阅网~!!', '欢迎访问捷阅网~!!', '2', 1, 1648468890462); -INSERT INTO `sys_notice` VALUES (36, '欢迎访问捷阅网~!!', '欢迎访问捷阅网~!!', '2', 3, 1648468890464); -INSERT INTO `sys_notice` VALUES (37, '欢迎访问捷阅网~!!', '欢迎访问捷阅网~!!', '2', 4, 1648468890466); -INSERT INTO `sys_notice` VALUES (38, '欢迎访问捷阅网~!!', '欢迎访问捷阅网~!!', '2', 5, 1648468890467); -INSERT INTO `sys_notice` VALUES (39, '欢迎访问捷阅网~!!', '欢迎访问捷阅网~!!', '2', 7, 1648468890468); +INSERT INTO `sys_notice` VALUES (36, '欢迎访问捷阅网~!!', '欢迎访问捷阅网~!!', '2', 2, 1648468890464); -- ---------------------------- -- Table structure for sys_order @@ -346,7 +341,7 @@ CREATE TABLE `sys_order` ( `merchant_ratio` float(11, 1) NOT NULL DEFAULT 1.0 COMMENT '订单创建时商户的费率', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `order_id`(`order_id`) USING BTREE COMMENT '订单号唯一' -) ENGINE = InnoDB AUTO_INCREMENT = 113 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +) ENGINE = InnoDB AUTO_INCREMENT = 112 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of sys_order @@ -362,17 +357,17 @@ INSERT INTO `sys_order` VALUES (90, 'WVW202012341002151359796', 1607185311336, 1 INSERT INTO `sys_order` VALUES (91, 'QAK202012341002151746672', 1607185311336, 1607185323819, 1, 1, 'SDW202012341002151596097', 1, 5, 0.01, 19, '', '测试', '测试', '测试', '', 0, '/data/pay/SDW202012341002151596097.jpg', '1', 0.1); INSERT INTO `sys_order` VALUES (92, 'YYT202012341004300490850', 1607186580573, 1607186595850, 1, 1, 'NFF202012341004300926613', 1, 8, 0.01, 34, '', '测试', '测试', '测试', '', 0, '/data/pay/NFF202012341004300926613.jpg', '13', 0.1); INSERT INTO `sys_order` VALUES (93, 'LID202012341004300509122', 1607186580573, 1607186595850, 1, 1, 'NFF202012341004300926613', 1, 5, 0.01, 19, '', '测试', '测试', '测试', '', 0, '/data/pay/NFF202012341004300926613.jpg', '10', 0.1); -INSERT INTO `sys_order` VALUES (101, 'GKJ202112340211010176213', 1638796210886, 1638796384928, 1, 1, 'GAU202112340211010908695', 3, 13, 0.01, 45, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/11f3333f-6d68-4adb-9cf6-035a39a4a551.jpg', NULL, 0.0); -INSERT INTO `sys_order` VALUES (102, 'ZSS202112340211024283551', 1638796224161, 1638796384928, 1, 1, 'ELN202112340211024324951', 3, 13, 0.01, 46, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/147fb8b1-18ac-480a-8d57-2c21635d9519.jpg', NULL, 0.0); -INSERT INTO `sys_order` VALUES (103, 'ZDK202112340211037495045', 1638796237222, 1638796384928, 1, 1, 'IJD202112340211037974203', 3, 13, 0.01, 47, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/4801e190-5640-4f14-a593-66029aa2d0ea.jpg', NULL, 0.0); -INSERT INTO `sys_order` VALUES (104, 'UWU202112340211051689881', 1638796251864, 1638796384928, 1, 1, 'NTP202112340211051560839', 3, 13, 0.01, 48, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/896bd6fa-e609-405c-b601-caa56d71659f.jpg', NULL, 0.0); -INSERT INTO `sys_order` VALUES (105, 'LAW202112340211111244316', 1638796271424, 1638796384928, 1, 1, 'EVM202112340211111457150', 3, 13, 0.01, 49, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/814b7cf6-3e81-4356-aa27-023bf2eb0609.jpg', NULL, 0.0); -INSERT INTO `sys_order` VALUES (106, 'QZG202112340211127932176', 1638796287661, 1638796384928, 1, 1, 'CKX202112340211127838508', 3, 13, 0.01, 50, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/2a3ecc4c-62e4-4964-aa75-1c2a3d082ba1.jpg', NULL, 0.0); -INSERT INTO `sys_order` VALUES (107, 'MVF202112340211155962656', 1638796315927, 1638796384928, 1, 1, 'GXI202112340211155762974', 3, 13, 0.01, 51, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/175a4dc6-1077-46ef-b64e-0e2a9ae66ee0.jpg', NULL, 0.0); -INSERT INTO `sys_order` VALUES (108, 'GYV202112340211210918392', 1638796330108, 1638796384928, 1, 1, 'NJY202112340211210411460', 3, 13, 0.01, 52, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/b7e61e0a-fea6-4022-b9bb-a3949220c085.jpg', NULL, 0.0); -INSERT INTO `sys_order` VALUES (109, 'XAB202112340211229316121', 1638796349401, 1638796384928, 1, 1, 'BGA202112340211229992111', 3, 13, 0.01, 53, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/9d358e5a-638e-4437-8a00-d9f942e5f58f.jpg', NULL, 0.0); -INSERT INTO `sys_order` VALUES (110, 'YUL202112340211250396901', 1638796370482, 1638796384928, 1, 1, 'OAX202112340211250369042', 3, 13, 0.01, 54, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/3db2f150-1b6d-41fa-8b6d-eca59c5f39cc.jpg', NULL, 0.0); -INSERT INTO `sys_order` VALUES (111, 'BHY202112340211304317807', 1638796384928, 1638796384928, 1, 1, 'ETZ202112340211304214293', 3, 13, 0.01, 55, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/87b2e60d-464c-499a-90be-b93e1ea58911.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (101, 'GKJ202112340211010176213', 1638796210886, 1638796384928, 1, 1, 'GAU202112340211010908695', 2, 13, 0.01, 45, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/11f3333f-6d68-4adb-9cf6-035a39a4a551.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (102, 'ZSS202112340211024283551', 1638796224161, 1638796384928, 1, 1, 'ELN202112340211024324951', 2, 13, 0.01, 46, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/147fb8b1-18ac-480a-8d57-2c21635d9519.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (103, 'ZDK202112340211037495045', 1638796237222, 1638796384928, 1, 1, 'IJD202112340211037974203', 2, 13, 0.01, 47, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/4801e190-5640-4f14-a593-66029aa2d0ea.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (104, 'UWU202112340211051689881', 1638796251864, 1638796384928, 1, 1, 'NTP202112340211051560839', 2, 13, 0.01, 48, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/896bd6fa-e609-405c-b601-caa56d71659f.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (105, 'LAW202112340211111244316', 1638796271424, 1638796384928, 1, 1, 'EVM202112340211111457150', 2, 13, 0.01, 49, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/814b7cf6-3e81-4356-aa27-023bf2eb0609.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (106, 'QZG202112340211127932176', 1638796287661, 1638796384928, 1, 1, 'CKX202112340211127838508', 2, 13, 0.01, 50, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/2a3ecc4c-62e4-4964-aa75-1c2a3d082ba1.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (107, 'MVF202112340211155962656', 1638796315927, 1638796384928, 1, 1, 'GXI202112340211155762974', 2, 13, 0.01, 51, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/175a4dc6-1077-46ef-b64e-0e2a9ae66ee0.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (108, 'GYV202112340211210918392', 1638796330108, 1638796384928, 1, 1, 'NJY202112340211210411460', 2, 13, 0.01, 52, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/b7e61e0a-fea6-4022-b9bb-a3949220c085.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (109, 'XAB202112340211229316121', 1638796349401, 1638796384928, 1, 1, 'BGA202112340211229992111', 2, 13, 0.01, 53, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/9d358e5a-638e-4437-8a00-d9f942e5f58f.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (110, 'YUL202112340211250396901', 1638796370482, 1638796384928, 1, 1, 'OAX202112340211250369042', 2, 13, 0.01, 54, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/3db2f150-1b6d-41fa-8b6d-eca59c5f39cc.jpg', NULL, 0.0); +INSERT INTO `sys_order` VALUES (111, 'BHY202112340211304317807', 1638796384928, 1638796384928, 1, 1, 'ETZ202112340211304214293', 2, 13, 0.01, 55, '', 'xxxxxxxxxxxxx', 'Bosen', '123456', '', 0, 'data/pay/87b2e60d-464c-499a-90be-b93e1ea58911.jpg', NULL, 0.0); -- ---------------------------- -- Table structure for sys_role @@ -439,53 +434,9 @@ CREATE TABLE `sys_ui` ( INSERT INTO `sys_ui` VALUES (18, '/data/library/20210328110354280473.jpg', 1230, 535); INSERT INTO `sys_ui` VALUES (19, '/data/library/20210330181647732986.jpg', 3151, 282); INSERT INTO `sys_ui` VALUES (20, '/data/library/20210330181628569458.jpeg', 3152, 282); -INSERT INTO `sys_ui` VALUES (21, 'data/library/1f9be131-5b1b-4c29-a172-2f34b757fe77.jpeg', 475, 570); +INSERT INTO `sys_ui` VALUES (21, '/data/library/20210330190628805198.jpeg', 475, 570); INSERT INTO `sys_ui` VALUES (22, '/data/library/20210330185815215536.jpg', 674, 264); -INSERT INTO `sys_ui` VALUES (23, 'data/library/22f506db-2960-4756-b339-25760fe4dc40.jpg', 1920, 737); - --- ---------------------------- --- Table structure for sys_ui_copy1 --- ---------------------------- -DROP TABLE IF EXISTS `sys_ui_copy1`; -CREATE TABLE `sys_ui_copy1` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, - `width` int(7) NOT NULL, - `height` int(7) NOT NULL, - PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; - --- ---------------------------- --- Records of sys_ui_copy1 --- ---------------------------- -INSERT INTO `sys_ui_copy1` VALUES (18, '/data/library/20210328110354280473.jpg', 1230, 535); -INSERT INTO `sys_ui_copy1` VALUES (19, '/data/library/20210330181647732986.jpg', 3151, 282); -INSERT INTO `sys_ui_copy1` VALUES (20, '/data/library/20210330181628569458.jpeg', 3152, 282); -INSERT INTO `sys_ui_copy1` VALUES (21, '/data/library/20210330190628805198.jpeg', 475, 570); -INSERT INTO `sys_ui_copy1` VALUES (22, '/data/library/20210330185815215536.jpg', 674, 264); -INSERT INTO `sys_ui_copy1` VALUES (23, '/data/library/20210322125308458944.jpg', 1920, 737); - --- ---------------------------- --- Table structure for sys_ui_copy2 --- ---------------------------- -DROP TABLE IF EXISTS `sys_ui_copy2`; -CREATE TABLE `sys_ui_copy2` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, - `width` int(7) NOT NULL, - `height` int(7) NOT NULL, - PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; - --- ---------------------------- --- Records of sys_ui_copy2 --- ---------------------------- -INSERT INTO `sys_ui_copy2` VALUES (18, '/data/library/20210328110354280473.jpg', 1230, 535); -INSERT INTO `sys_ui_copy2` VALUES (19, '/data/library/20210330181647732986.jpg', 3151, 282); -INSERT INTO `sys_ui_copy2` VALUES (20, '/data/library/20210330181628569458.jpeg', 3152, 282); -INSERT INTO `sys_ui_copy2` VALUES (21, '/data/library/20210330190628805198.jpeg', 475, 570); -INSERT INTO `sys_ui_copy2` VALUES (22, '/data/library/20210330185815215536.jpg', 674, 264); -INSERT INTO `sys_ui_copy2` VALUES (23, '/data/library/20210322125308458944.jpg', 1920, 737); +INSERT INTO `sys_ui` VALUES (23, '/data/library/20210322125308458944.jpg', 1920, 737); -- ---------------------------- -- Table structure for sys_user @@ -505,10 +456,7 @@ CREATE TABLE `sys_user` ( -- ---------------------------- -- Records of sys_user -- ---------------------------- -INSERT INTO `sys_user` VALUES (1, 'Bosen', 'b9e1115fb6e950878b08e2433b53ed47', 'bosen_once@163.com', 1, 'data/header/user/5123ceb0-7f02-4a03-a6a8-32b70ddcbe08.jpg'); -INSERT INTO `sys_user` VALUES (3, 'guest', 'e10adc3949ba59abbe56e057f20f883e', 'guest@qq.com', 1, 'data/header/user/45bd348b-ba84-42ce-80b3-c4f852c943df.itc.cn_images01_20210825_919e1fbb709a4336b52c1cc4f3b8ef17.jpeg&refer=http___p9.itc.jfif'); -INSERT INTO `sys_user` VALUES (4, 'test111', 'e10adc3949ba59abbe56e057f20f883e', '806317173@qq.com', 0, '/data/header/user/default.jpg'); -INSERT INTO `sys_user` VALUES (5, 'lalalal', 'e10adc3949ba59abbe56e057f20f883e', '2390025288@qq.com', 0, '/data/header/user/default.jpg'); -INSERT INTO `sys_user` VALUES (7, '2390025289@qq.com', 'e10adc3949ba59abbe56e057f20f883e', '2390025289@qq.com', 1, '/data/header/user/default.jpg'); +INSERT INTO `sys_user` VALUES (1, 'Bosen', 'b9e1115fb6e950878b08e2433b53ed47', 'bosen_once@163.com', 1, '/data/header/user/1.jpg'); +INSERT INTO `sys_user` VALUES (2, 'guest', 'e10adc3949ba59abbe56e057f20f883e', 'guest@qq.com', 1, '/data/header/user/default.jpg'); SET FOREIGN_KEY_CHECKS = 1; diff --git a/pom.xml b/pom.xml index 767713b..28de8c1 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.example jieyue 0.0.1-SNAPSHOT - jar + war jieyue Demo project for Spring Boot @@ -19,6 +19,7 @@ UTF-8 UTF-8 1.8 + 8.5.29 @@ -59,32 +60,34 @@ org.springframework.boot spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-tomcat + + - org.springframework.boot spring-boot-devtools true - mysql mysql-connector-java runtime - org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.3 - org.projectlombok lombok true - org.springframework.boot spring-boot-starter-test @@ -124,13 +127,11 @@ qrgen 1.4 - com.alibaba fastjson 1.2.47 - org.springframework.data spring-data-redis @@ -139,10 +140,12 @@ org.springframework.boot spring-boot-starter-tomcat + provided org.apache.tomcat.embed tomcat-embed-jasper + provided @@ -155,27 +158,15 @@ org.springframework.boot spring-boot-starter-amqp - - - cn.hutool - hutool-all - 5.5.8 - - - org.springframework - spring-test - 5.3.12 - compile - - jieyue + ROOT - + org.apache.maven.plugins maven-compiler-plugin @@ -188,11 +179,6 @@ - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.0 - diff --git a/src/main/java/com/example/jieyue/JieyueApplication.java b/src/main/java/com/example/jieyue/JieyueApplication.java index bbb3e5e..d724c34 100644 --- a/src/main/java/com/example/jieyue/JieyueApplication.java +++ b/src/main/java/com/example/jieyue/JieyueApplication.java @@ -1,9 +1,15 @@ package com.example.jieyue; +import org.apache.catalina.connector.Connector; +import org.apache.coyote.http11.AbstractHttp11Protocol; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.servlet.ServletComponentScan; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Bean; import org.springframework.scheduling.annotation.EnableScheduling; /** @@ -15,10 +21,35 @@ import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @ServletComponentScan @EnableScheduling -public class JieyueApplication { +public class JieyueApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(JieyueApplication.class, args); } + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { + return builder.sources(JieyueApplication.class); + } + + /** + *

处理文件过大上传失败的问题

+ */ + @Bean + public TomcatServletWebServerFactory containerFactory() { + return new TomcatServletWebServerFactory() { + protected void customizeConnector(Connector connector) { + int maxSize = 50000000; + super.customizeConnector(connector); + connector.setMaxPostSize(maxSize); + connector.setMaxSavePostSize(maxSize); + if (connector.getProtocolHandler() instanceof AbstractHttp11Protocol) { + + ((AbstractHttp11Protocol ) connector.getProtocolHandler()).setMaxSwallowSize(maxSize); + logger.info("Set MaxSwallowSize "+ maxSize); + } + } + }; + + } } diff --git a/src/main/java/com/example/jieyue/admin/service/AdminMerchantService.java b/src/main/java/com/example/jieyue/admin/service/AdminMerchantService.java index 65ab1f7..06db5c3 100644 --- a/src/main/java/com/example/jieyue/admin/service/AdminMerchantService.java +++ b/src/main/java/com/example/jieyue/admin/service/AdminMerchantService.java @@ -2,7 +2,6 @@ package com.example.jieyue.admin.service; import com.example.jieyue.common.entity.SysMt; import com.example.jieyue.common.mapper.SysMtMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,13 +19,9 @@ public class AdminMerchantService { */ public List getMtInfo(int curPage,int pageSize){ int curRow = (curPage-1)*pageSize; - List list = mtMapper.findPage(curRow,pageSize); - for (SysMt sysMt : list) { - sysMt.setHeader(GiteeImgBedUtils.PRE + sysMt.getHeader()); - } - return list; + return mtMapper.findPage(curRow,pageSize); } - + /** *

删除商户

*/ @@ -46,7 +41,7 @@ public class AdminMerchantService { } return -1; } - + /** *

获取商户列表总页数

*/ diff --git a/src/main/java/com/example/jieyue/admin/service/AdminUiService.java b/src/main/java/com/example/jieyue/admin/service/AdminUiService.java index bcd5ae9..2349d23 100644 --- a/src/main/java/com/example/jieyue/admin/service/AdminUiService.java +++ b/src/main/java/com/example/jieyue/admin/service/AdminUiService.java @@ -1,16 +1,22 @@ package com.example.jieyue.admin.service; import com.example.jieyue.common.mapper.SysUiMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; +import com.example.jieyue.common.utils.DateUtil; +import com.example.jieyue.common.utils.FileUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import org.thymeleaf.util.StringUtils; import javax.servlet.http.HttpServletRequest; @Service public class AdminUiService { + @Autowired + FileUtil fileUtil; + @Autowired + DateUtil dateUtil; @Autowired SysUiMapper uiMapper; @@ -21,31 +27,33 @@ public class AdminUiService { * 文件名 上传成功 */ public String upImage(MultipartFile file, RedirectAttributes redirectAttributes, - HttpServletRequest request, String url,int weight,int height) { + HttpServletRequest request, String url,int weight,int height) { + // 设置filename 文件名由年月日时分秒以及六位随机数组成 + String filename = dateUtil.getNMDHIS()+Math.round(Math.random()*(999999-100000)+100000); // 接收文件工具类返回的文件位置 - String result = GiteeImgBedUtils.upload(url, file); - if (result == null){ + String result = fileUtil.upFile(file,redirectAttributes,request,url,filename); + if (result==null){ return null; }else{ if (uiMapper.findByMark(weight,height) == null) { int insertRes = uiMapper.insert(result, weight, height); if (insertRes == 1) { - return result; + return filename; } else { // sql语句执行失败,将已上传的图片移除 - GiteeImgBedUtils.delete(result); + fileUtil.deleteFile(result); return null; } }else{ // 删除旧图片 - GiteeImgBedUtils.delete(uiMapper.findByMark(weight,height).getUrl()); + fileUtil.deleteFile(uiMapper.findByMark(weight,height).getUrl()); // 更改图片 int updateRes = uiMapper.updateUrl(result,weight,height); if (updateRes == 1) { - return result; + return filename; } else { // sql语句执行失败,将已上传的图片移除 - GiteeImgBedUtils.delete(result); + fileUtil.deleteFile(result); return null; } } @@ -56,11 +64,11 @@ public class AdminUiService { *

删除海报逻辑处理

*/ public boolean delImg(int width,int height){ - if (uiMapper.findByMark(width,height) == null){ + if (uiMapper.findByMark(width,height)==null){ return false; }else{ - GiteeImgBedUtils.delete(uiMapper.findByMark(width, height).getUrl()); - int delResult = uiMapper.deleteByMark(width, height); + fileUtil.deleteFile(uiMapper.findByMark(width,height).getUrl()); + int delResult = uiMapper.deleteByMark(width,height); if (delResult == 1) { return true; } diff --git a/src/main/java/com/example/jieyue/admin/service/AdminUserService.java b/src/main/java/com/example/jieyue/admin/service/AdminUserService.java index 7379a3d..b491c84 100644 --- a/src/main/java/com/example/jieyue/admin/service/AdminUserService.java +++ b/src/main/java/com/example/jieyue/admin/service/AdminUserService.java @@ -2,7 +2,6 @@ package com.example.jieyue.admin.service; import com.example.jieyue.common.entity.SysUser; import com.example.jieyue.common.mapper.SysUserMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,11 +16,7 @@ public class AdminUserService { *

获取用户信息

*/ public List getUserList(int page, int num){ - List list = userMapper.findLimit((page-1)*num,num); - for (SysUser user : list) { - user.setHeader(GiteeImgBedUtils.PRE + user.getHeader()); - } - return list; + return userMapper.findLimit((page-1)*num,num); } /** diff --git a/src/main/java/com/example/jieyue/common/task/SchedulerTask.java b/src/main/java/com/example/jieyue/common/task/SchedulerTask.java index 3d78cdd..942d665 100644 --- a/src/main/java/com/example/jieyue/common/task/SchedulerTask.java +++ b/src/main/java/com/example/jieyue/common/task/SchedulerTask.java @@ -5,7 +5,7 @@ import com.example.jieyue.common.mapper.SysGoodsMapper; import com.example.jieyue.common.mapper.SysNoticeMapper; import com.example.jieyue.common.mapper.SysOrderMapper; import com.example.jieyue.common.service.MailService; -import com.example.jieyue.common.utils.GiteeImgBedUtils; +import com.example.jieyue.common.utils.FileUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.annotation.Scheduled; @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,6 +29,8 @@ public class SchedulerTask { @Autowired SysGoodsMapper goodsMapper; @Autowired + FileUtil fileUtil; + @Autowired RedisTemplate redisTemplate; @Autowired SysNoticeMapper noticeMapper; @@ -40,15 +43,15 @@ public class SchedulerTask { @Scheduled(cron="0 0/1 * * * ?") @Transactional public void delOverOrder(){ - // 订单过期时间,两小时 - long time = 2*60*60*1000; + long time = 2*60*60*1000;// 订单过期时间,两小时 List list = orderMapper.findByState(0); for (SysOrder sysOrder : list) { - if (System.currentTimeMillis() > sysOrder.getCreateTime() + time - && sysOrder.getOrderState() == 0){ - if (orderMapper.deleteById(sysOrder.getId()) != 1 || + if (System.currentTimeMillis() > sysOrder.getCreateTime()+time){ + if (orderMapper.deleteById(sysOrder.getId())!=1 || goodsMapper.addStock(sysOrder.getGoodsId(),sysOrder.getGoodsNum()) != 1){ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + }else{ + fileUtil.deleteFile(sysOrder.getPayCodeUrl()); } } } @@ -59,13 +62,11 @@ public class SchedulerTask { */ @Scheduled(cron="0 0/1 * * * ?") public void delQRCode(){ - // 订单过期时间,两小时 - long time = 2*60*60*1000; + long time = 2*60*60*1000;// 订单过期时间,两小时 List list = orderMapper.findAll(); for (SysOrder sysOrder : list) { - if (System.currentTimeMillis() > sysOrder.getCreateTime() + time - && sysOrder.getOrderState() == 0){ - GiteeImgBedUtils.delete(sysOrder.getPayCodeUrl()); + if (System.currentTimeMillis() > sysOrder.getCreateTime()+time){ + fileUtil.deleteFile(sysOrder.getPayCodeUrl()); } } } @@ -82,8 +83,19 @@ public class SchedulerTask { int type = Integer.valueOf(map.get("type")); int receive = Integer.valueOf(map.get("receive")); long createTime = Long.valueOf(map.get("createTime")); - - noticeMapper.insert(title,context,type,receive,createTime); + switch (type){ + case 0: + noticeMapper.insert(title,context,type,receive,createTime); + break; + case 1: + noticeMapper.insert(title,context,type,receive,createTime); + break; + case 2: + noticeMapper.insert(title,context,type,receive,createTime); + break; + default: + break; + } } } diff --git a/src/main/java/com/example/jieyue/common/utils/DateUtil.java b/src/main/java/com/example/jieyue/common/utils/DateUtil.java new file mode 100644 index 0000000..d9d9e99 --- /dev/null +++ b/src/main/java/com/example/jieyue/common/utils/DateUtil.java @@ -0,0 +1,22 @@ +package com.example.jieyue.common.utils; + +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + *

时间工具类

+ * @author Bosen + * 2020/11/6 10:36 + */ +@Component +public class DateUtil { + /** + *

获取纯年月日时分秒的字符串

+ */ + public String getNMDHIS(){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + return sdf.format(new Date()); + } +} diff --git a/src/main/java/com/example/jieyue/common/utils/FileUtil.java b/src/main/java/com/example/jieyue/common/utils/FileUtil.java new file mode 100644 index 0000000..5e4e5d5 --- /dev/null +++ b/src/main/java/com/example/jieyue/common/utils/FileUtil.java @@ -0,0 +1,78 @@ +package com.example.jieyue.common.utils; + +import org.apache.commons.io.FileUtils; +import org.springframework.stereotype.Component; +import org.springframework.util.ResourceUtils; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +/** + *

文件操作工具类

+ * @author Bosen + * 2020/11/5 22:55 + */ +@Component +public class FileUtil { + + String classpath; + public FileUtil() throws FileNotFoundException { + this.classpath = ResourceUtils.getFile("classpath:/static").getPath()+"\\"; + } + + /** + *

文件上传逻辑处理

+ * @return + * null 上传失败 + * 文件名 上传成功 + */ + public String upFile(MultipartFile file, RedirectAttributes redirectAttributes, + HttpServletRequest request,String url,String filename) { + // MultipartFile是对当前上传的文件的封装,当要同时上传多个文件时,可以给定多个MultipartFile参数(数组) + if (file.isEmpty()) { + redirectAttributes.addFlashAttribute("message", "Please select a file to upload"); + return null; + } + // 取文件格式后缀名 + // String type = file.getOriginalFilename().substring(file.getOriginalFilename().indexOf(".")); + + File savefile1 = new File(classpath+url); + //判断上传文件的保存目录是否存在 + if (!savefile1.exists() && !savefile1.isDirectory()) { + System.out.println(classpath+"目录不存在,需要创建"); + //创建目录 + savefile1.mkdir(); + } + String suffix = this.getSuffixName(file.getOriginalFilename()); + try { + // FileUtils.copyInputStreamToFile()这个方法里对IO进行了自动操作,不需要额外的再去关闭IO流 + // 加入原工程static目录 + FileUtils.copyInputStreamToFile(file.getInputStream(), new File(savefile1+"/"+filename+"."+suffix));// 复制临时文件到指定目录下 + } catch (IOException e) { + e.printStackTrace(); + } + return url+filename+"."+suffix; + } + + /** + *

获取文件后缀名

+ */ + public String getSuffixName(String filename){ + String[] strArray = filename.split("\\."); + int suffixIndex = strArray.length -1; + return strArray[suffixIndex]; + } + + /** + *

删除文件

+ */ + public void deleteFile(String url){ + File file1 = new File(classpath+url); + file1.delete(); + } + +} diff --git a/src/main/java/com/example/jieyue/common/utils/GiteeImgBedUtils.java b/src/main/java/com/example/jieyue/common/utils/GiteeImgBedUtils.java deleted file mode 100644 index 70b21d4..0000000 --- a/src/main/java/com/example/jieyue/common/utils/GiteeImgBedUtils.java +++ /dev/null @@ -1,186 +0,0 @@ -package com.example.jieyue.common.utils; - -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpUtil; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class GiteeImgBedUtils { - /** - * 码云私人令牌 - */ - private static final String ACCESS_TOKEN = "24a30786da41fe96ec7ee86daea78ee2"; - - /** - * 码云个人空间名 - */ - private static final String OWNER = "bosen-once"; - - /** - * 上传指定仓库 - */ - private static final String REPO = "cloud-disk"; - - /** - * 图片访问前缀 - */ - public static final String PRE = - "https://gitee.com/" + OWNER + "/" + REPO + "/raw/master/"; - - /** - * 新建(POST)、获取(GET)、删除(DELETE)文件:()中指的是使用对应的请求方式 - * %s =>仓库所属空间地址(企业、组织或个人的地址path) (owner) - * %s => 仓库路径(repo) - * %s => 文件的路径(path) - */ - private static final String API_CREATE_POST = - "https://gitee.com/api/v5/repos/%s/%s/contents/%s"; - - /** - * 用于提交描述 - */ - private static final String ADD_MESSAGE = "add file"; - private static final String DEL_MESSAGE = "del file"; - - /** - *

上传文件

- * @param multipartFile 文件 - * @return 返回文件下载路径后缀 - */ - public static String upload(String path, MultipartFile multipartFile) { - String originalFilename = multipartFile.getOriginalFilename(); - if(originalFilename == null){ - return null; - } - String targetUrl = GiteeImgBedUtils.createUploadFileUrl(path, originalFilename); - // 请求体封装 - Map map = null; - try { - map = GiteeImgBedUtils.getUploadBodyMap(multipartFile.getBytes()); - } catch (IOException e) { - return null; - } - // 借助HttpUtil工具类发送POST请求 - String jsonResult = HttpUtil.post(targetUrl, map); - // 解析响应JSON字符串 - JSONObject jsonObj = JSONUtil.parseObj(jsonResult); - // 请求失败 - if(jsonObj.getObj("commit") == null){ - return null; - } - //请求成功:返回下载地址 - JSONObject content = JSONUtil.parseObj(jsonObj.getObj("content")); - return content.getObj("path").toString(); - } - - /** - *

删除

- */ - public static boolean delete(String path) { - if(path.contains("default")) { - return true; - } - try { - String targetUrl = GiteeImgBedUtils.deleteFileUrl(path); - Map map = getDeleteBodyMap(path); - // 发送delete请求 - String jsonResult = HttpRequest.delete(targetUrl).form(map).execute().body(); - // 解析响应JSON字符串 - JSONObject jsonObj = JSONUtil.parseObj(jsonResult); - return jsonObj.getObj("commit") != null; - } catch (Exception e) { - return false; - } - } - - /** - *

获取sha信息

- */ - private static String getShaInfo(String path) { - String targetUrl = GiteeImgBedUtils.deleteFileUrl(path); - Map map = getFileInfoBodyMap(); - // 借助HttpUtil工具类发送get请求 - String jsonResult = HttpUtil.get(targetUrl, map); - // 解析响应JSON字符串 - JSONObject jsonObj = JSONUtil.parseObj(jsonResult); - if (jsonObj.getObj("sha") == null) { - return null; - } - return jsonObj.getObj("sha").toString(); - } - - /** - * 生成创建(获取、删除)的指定文件路径 - */ - private static String createUploadFileUrl(String path, String originalFilename){ - //获取文件后缀 - String suffix = getFileSuffix(originalFilename); - //拼接存储的图片名称 - String fileName = UUID.randomUUID().toString() + suffix; - //填充请求路径 - return String.format(GiteeImgBedUtils.API_CREATE_POST, - GiteeImgBedUtils.OWNER, - GiteeImgBedUtils.REPO, - path + "/" + fileName); - } - - /** - *

生成删除链接

- */ - private static String deleteFileUrl(String path) { - return String.format(GiteeImgBedUtils.API_CREATE_POST, - GiteeImgBedUtils.OWNER, - GiteeImgBedUtils.REPO, - path); - } - - /** - * 获取创建文件的请求体map集合:access_token、message、content - * @param multipartFile 文件字节数组 - * @return 封装成map的请求体集合 - */ - private static Map getUploadBodyMap(byte[] multipartFile){ - HashMap bodyMap = new HashMap<>(3); - bodyMap.put("access_token", GiteeImgBedUtils.ACCESS_TOKEN); - bodyMap.put("message", GiteeImgBedUtils.ADD_MESSAGE); - bodyMap.put("content", Base64.encode(multipartFile)); - return bodyMap; - } - - /** - * 获取删除文件的请求体map集合:access_token、path、sha、message - * @return 封装成map的请求体集合 - */ - private static Map getDeleteBodyMap(String path){ - HashMap bodyMap = new HashMap<>(3); - bodyMap.put("access_token", GiteeImgBedUtils.ACCESS_TOKEN); - bodyMap.put("message", GiteeImgBedUtils.DEL_MESSAGE); - bodyMap.put("sha", getShaInfo(path)); - return bodyMap; - } - - /** - * 获取sha的请求体map集合:access_token - * @return 封装成map的请求体集合 - */ - private static Map getFileInfoBodyMap(){ - HashMap bodyMap = new HashMap<>(3); - bodyMap.put("access_token", GiteeImgBedUtils.ACCESS_TOKEN); - return bodyMap; - } - - /** - * 获取文件名的后缀,如:changlu.jpg => .jpg - * @return 文件后缀名 - */ - private static String getFileSuffix(String fileName) { - return fileName.contains(".") ? fileName.substring(fileName.indexOf('.')) : null; - } -} \ No newline at end of file diff --git a/src/main/java/com/example/jieyue/common/utils/JsonUtil.java b/src/main/java/com/example/jieyue/common/utils/JsonUtil.java new file mode 100644 index 0000000..fb56850 --- /dev/null +++ b/src/main/java/com/example/jieyue/common/utils/JsonUtil.java @@ -0,0 +1,21 @@ +package com.example.jieyue.common.utils; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import org.springframework.stereotype.Component; + +@Component +public class JsonUtil { + + /** + * 字符串转整数型数组 + */ + public int[] jsonToIntArray(String json){ + JSONArray jsonArray = JSON.parseArray(json); + int[] array = new int[jsonArray.size()]; + for (int i = 0;i < jsonArray.size();i++){ + array[i] = (Integer) jsonArray.get(i); + } + return array; + } +} diff --git a/src/main/java/com/example/jieyue/common/utils/QRCodeUtil.java b/src/main/java/com/example/jieyue/common/utils/QRCodeUtil.java index 8ee11e4..8a865bb 100644 --- a/src/main/java/com/example/jieyue/common/utils/QRCodeUtil.java +++ b/src/main/java/com/example/jieyue/common/utils/QRCodeUtil.java @@ -4,7 +4,8 @@ import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; -import java.io.*; +import java.io.File; +import java.io.IOException; import java.util.*; import javax.imageio.ImageIO; import com.google.zxing.BarcodeFormat; @@ -21,8 +22,6 @@ import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.web.multipart.MultipartFile; /** * 二维码生成解析工具类 @@ -52,27 +51,27 @@ public class QRCodeUtil { * * @param content 二维码包含的内容,文本或网址 * @param path 生成的二维码图片存放位置 + * @param filename 生成的二维码图片存放位置 * @param size 生成的二维码图片尺寸 可以自定义或者默认(250) * @param logoPath logo的存放位置 */ - public static String zxingCodeCreate(String content, String path, Integer size, String logoPath) { + public static boolean zxingCodeCreate(String content, String path, String filename,Integer size, String logoPath) { try { //图片类型 String imageType = "jpg"; //获取二维码流的形式,写入到目录文件中 BufferedImage image = getBufferedImage(content, size, logoPath); - //创建一个ByteArrayOutputStream - ByteArrayOutputStream os = new ByteArrayOutputStream(); - //把BufferedImage写入ByteArrayOutputStream - ImageIO.write(image, imageType, os); - //ByteArrayOutputStream转成InputStream - InputStream input = new ByteArrayInputStream(os.toByteArray()); - //InputStream转成MultipartFile - MultipartFile multipartFile = new MockMultipartFile("file", "file.jpg", "text/plain", input); - return GiteeImgBedUtils.upload(path, multipartFile); + + //生成二维码存放文件 + File file = new File(path+filename+".jpg"); + if (!file.exists()) { + file.mkdirs(); + } + ImageIO.write(image, imageType, file); + return true; } catch (IOException e) { e.printStackTrace(); - return null; + return false; } } diff --git a/src/main/java/com/example/jieyue/common/utils/StringUtil.java b/src/main/java/com/example/jieyue/common/utils/StringUtil.java new file mode 100644 index 0000000..270a52c --- /dev/null +++ b/src/main/java/com/example/jieyue/common/utils/StringUtil.java @@ -0,0 +1,20 @@ +package com.example.jieyue.common.utils; + +import org.springframework.stereotype.Component; + +import java.util.Map; + +@Component +public class StringUtil { + public static String GetMapToXML(Map param){ + StringBuffer sb = new StringBuffer(); + sb.append(""); + for (Map.Entry entry : param.entrySet()) { + sb.append("<"+ entry.getKey() +">"); + sb.append(entry.getValue()); + sb.append(""); + } + sb.append(""); + return sb.toString(); + } +} diff --git a/src/main/java/com/example/jieyue/merchant/controller/MerchantGoodsController.java b/src/main/java/com/example/jieyue/merchant/controller/MerchantGoodsController.java index 3bd8e0e..8102d95 100644 --- a/src/main/java/com/example/jieyue/merchant/controller/MerchantGoodsController.java +++ b/src/main/java/com/example/jieyue/merchant/controller/MerchantGoodsController.java @@ -92,7 +92,7 @@ public class MerchantGoodsController { modelAndView.setViewName("redirect:goods"); return modelAndView; } - + /** *

通过id值删除商品

*/ @@ -108,7 +108,7 @@ public class MerchantGoodsController { modelAndView.setViewName("redirect:goods"); return modelAndView; } - + /** *

上架商品

*/ diff --git a/src/main/java/com/example/jieyue/merchant/controller/MerchantLoginController.java b/src/main/java/com/example/jieyue/merchant/controller/MerchantLoginController.java index b345e19..d2e1c94 100644 --- a/src/main/java/com/example/jieyue/merchant/controller/MerchantLoginController.java +++ b/src/main/java/com/example/jieyue/merchant/controller/MerchantLoginController.java @@ -1,7 +1,6 @@ package com.example.jieyue.merchant.controller; import com.example.jieyue.common.entity.SysMt; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import com.example.jieyue.merchant.service.MerchantLoginService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; @@ -28,7 +27,7 @@ public class MerchantLoginController { modelAndView.setViewName("merchant/login/index"); return modelAndView; } - + /** *

登录

*/ @@ -51,8 +50,7 @@ public class MerchantLoginController { modelAndView.addObject("msg","您的账号处于停用状态,请等待管理员处理"); break; } - merchant.setHeader(GiteeImgBedUtils.PRE + merchant.getHeader()); - session.setAttribute("merchant", merchant); + session.setAttribute("merchant",merchant); break; default: break; diff --git a/src/main/java/com/example/jieyue/merchant/controller/MerchantUiController.java b/src/main/java/com/example/jieyue/merchant/controller/MerchantUiController.java index 805d0b3..ca8fb55 100644 --- a/src/main/java/com/example/jieyue/merchant/controller/MerchantUiController.java +++ b/src/main/java/com/example/jieyue/merchant/controller/MerchantUiController.java @@ -36,7 +36,7 @@ public class MerchantUiController { return modelAndView; } - + /** *

删除

*/ @@ -57,7 +57,7 @@ public class MerchantUiController { modelAndView.setViewName("redirect:ui"); return modelAndView; } - + /** *

修改或添加商户在商城主页的宣传海报

*/ @@ -79,7 +79,7 @@ public class MerchantUiController { modelAndView.setViewName("redirect:ui"); return modelAndView; } - + /** *

修改用户头像

*/ diff --git a/src/main/java/com/example/jieyue/merchant/service/MerchantGoodsService.java b/src/main/java/com/example/jieyue/merchant/service/MerchantGoodsService.java index 53c2760..46d69ba 100644 --- a/src/main/java/com/example/jieyue/merchant/service/MerchantGoodsService.java +++ b/src/main/java/com/example/jieyue/merchant/service/MerchantGoodsService.java @@ -3,7 +3,8 @@ package com.example.jieyue.merchant.service; import com.example.jieyue.common.entity.SysGoods; import com.example.jieyue.common.entity.SysMt; import com.example.jieyue.common.mapper.SysGoodsMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; +import com.example.jieyue.common.utils.DateUtil; +import com.example.jieyue.common.utils.FileUtil; import com.example.jieyue.common.utils.IsEmptyUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +21,12 @@ public class MerchantGoodsService { @Autowired SysGoodsMapper goodsMapper; @Autowired + FileUtil fileUtil; + @Autowired + DateUtil dateUtil; + @Autowired IsEmptyUtil isEmptyUtil = new IsEmptyUtil(); - + /** *

获取全部商品

*/ @@ -35,19 +40,15 @@ public class MerchantGoodsService { public SysGoods getGoodsById(int id){ return goodsMapper.findById(id); } - + /** *

获取当前商户的商品列表

*/ public List getMtGoods(HttpSession session,int page,int num){ SysMt sysMt = (SysMt) session.getAttribute("merchant"); - List list = goodsMapper.findByMtLimit(sysMt.getId(),(page-1)*num,num); - for (SysGoods sysGoods : list) { - sysGoods.setImg(GiteeImgBedUtils.PRE + sysGoods.getImg()); - } - return list; + return goodsMapper.findByMtLimit(sysMt.getId(),(page-1)*num,num); } - + /** *

添加商品

* @return @@ -70,17 +71,20 @@ public class MerchantGoodsService { SysMt sysMt = (SysMt)request.getSession().getAttribute("merchant"); int merchant = sysMt.getId(); - if ("".equals(img.getOriginalFilename())){ + if (img.getOriginalFilename().equals("")){ // 执行插入 goodsMapperResult = goodsMapper.insert1(name,describe,price,merchant,stock); if(goodsMapperResult != 1){ return 0; } }else{ + // 设置filename 文件名由年月日时分秒以及六位随机数组成 + String filename = dateUtil.getNMDHIS()+Math.round(Math.random()*(999999-100000)+100000); // 获取商户id,一个商户对应一个文件夹 int id = ((SysMt) request.getSession().getAttribute("merchant")).getId(); // 接收文件工具类返回的文件位置 - String imgUrl = GiteeImgBedUtils.upload("/data/goods/" + id, img); + String imgUrl = fileUtil.upFile(img,redirectAttributes,request, + "/data/goods/"+id+"/",filename); // 文件上传失败 if (imgUrl == null){ return -1; @@ -89,7 +93,7 @@ public class MerchantGoodsService { goodsMapperResult = goodsMapper.insert2(name,describe,price,merchant,stock,imgUrl); if (goodsMapperResult != 1){ // sql语句执行失败,将已上传的图片移除 - GiteeImgBedUtils.delete(imgUrl); + fileUtil.deleteFile(imgUrl); return 0; } } @@ -110,8 +114,11 @@ public class MerchantGoodsService { if (sql!=1){ return -1; }else{ - // 删除源文件,与编译文件中对应的goods图片信息 - GiteeImgBedUtils.delete(imgUrl); + // 当文件路径在/data下时,才执行文件的删除 + if (imgUrl.indexOf("/data") == 0){ + // 删除源文件,与编译文件中对应的goods图片信息 + fileUtil.deleteFile(imgUrl); + } return 1; } } @@ -166,10 +173,13 @@ public class MerchantGoodsService { return 0; } }else{ + // 设置filename 文件名由年月日时分秒以及六位随机数组成 + String filename = dateUtil.getNMDHIS()+Math.round(Math.random()*(999999-100000)+100000); // 获取商户id,一个商户对应一个文件夹 int id = ((SysMt) request.getSession().getAttribute("merchant")).getId(); // 接收文件工具类返回的文件位置 - String imgUrl = GiteeImgBedUtils.upload("/data/goods/" + id, img); + String imgUrl = fileUtil.upFile(img,redirectAttributes,request, + "/data/goods/"+id+"/",filename); // 文件上传失败 if (imgUrl == null){ return -1; @@ -179,11 +189,11 @@ public class MerchantGoodsService { goodsMapperResult = goodsMapper.updateGoods2(name,describe,price,merchant,stock,goodsId,imgUrl); if (goodsMapperResult != 1){ // sql语句执行失败,将已上传的图片移除 - GiteeImgBedUtils.delete(imgUrl); + fileUtil.deleteFile(imgUrl); return 0; }else{ // 新图片已插入,将旧图删除 - GiteeImgBedUtils.delete(tempGoods.getImg()); + fileUtil.deleteFile(tempGoods.getImg()); } } return 1; diff --git a/src/main/java/com/example/jieyue/merchant/service/MerchantUiService.java b/src/main/java/com/example/jieyue/merchant/service/MerchantUiService.java index 559d74d..9a7664c 100644 --- a/src/main/java/com/example/jieyue/merchant/service/MerchantUiService.java +++ b/src/main/java/com/example/jieyue/merchant/service/MerchantUiService.java @@ -4,7 +4,8 @@ import com.example.jieyue.common.entity.SysMt; import com.example.jieyue.common.entity.SysMtUi; import com.example.jieyue.common.mapper.SysMtMapper; import com.example.jieyue.common.mapper.SysMtUiMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; +import com.example.jieyue.common.utils.DateUtil; +import com.example.jieyue.common.utils.FileUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -18,6 +19,10 @@ public class MerchantUiService { @Autowired SysMtUiMapper mtUiMapper; @Autowired + FileUtil fileUtil; + @Autowired + DateUtil dateUtil; + @Autowired SysMtMapper merchantMapper; /** @@ -37,21 +42,17 @@ public class MerchantUiService { *

获取商户用于商城首页宣传的海报图片对象

*/ public SysMtUi getHomeImg(int width,int height,HttpSession session){ - SysMtUi ui = mtUiMapper.findByMark(width,height,getMtId(session)); - if (ui != null) { - ui.setUrl(GiteeImgBedUtils.PRE + ui.getUrl()); - } - return ui; + return mtUiMapper.findByMark(width,height,getMtId(session)); } - + /** *

删除

*/ public int delHomeImg(int id){ String url = mtUiMapper.findById(id).getUrl(); int sql = mtUiMapper.deleteById(id); - if (sql == 1){ - GiteeImgBedUtils.delete(url); + if (sql==1){ + fileUtil.deleteFile(url); return 1; }else{ return 0; @@ -67,8 +68,11 @@ public class MerchantUiService { int id = ((SysMt)request.getSession().getAttribute("merchant")).getId(); SysMtUi sysMtUi = mtUiMapper.findByMark(width,height,id); + // 设置filename 文件名由年月日时分秒以及六位随机数组成 + String filename = dateUtil.getNMDHIS()+Math.round(Math.random()*(999999-100000)+100000); // 接收文件工具类返回的文件位置 - String imgUrl = GiteeImgBedUtils.upload("/data/mtui/" + id, img); + String imgUrl = fileUtil.upFile(img,redirectAttributes,request, + "/data/mtui/"+id+"/",filename); if (imgUrl==null){ // 上传图片失败 return 0; @@ -79,15 +83,15 @@ public class MerchantUiService { int sql = mtUiMapper.updateUrl(imgUrl,width,height,id); if (sql==1){ // sql语句执行成功,将旧图删除,加入新图 - GiteeImgBedUtils.delete(sysMtUi.getUrl()); + fileUtil.deleteFile(sysMtUi.getUrl()); }else{ // sql语句执行失败,将已上传的新图删除 - GiteeImgBedUtils.delete(imgUrl); + fileUtil.deleteFile(imgUrl); } return sql; } } - + /** *

增加商户商城首页的宣传海报

*/ @@ -101,15 +105,19 @@ public class MerchantUiService { public int updateHeard(RedirectAttributes redirectAttributes,HttpServletRequest request, MultipartFile img){ // 获取商户信息 SysMt merchant = (SysMt) request.getSession().getAttribute("merchant"); - String headerUrl = GiteeImgBedUtils.upload("/data/header/merchant/", img); + // 设置filename 文件名由年月日时分秒以及六位随机数组成 + String filename = dateUtil.getNMDHIS()+Math.round(Math.random()*(999999-100000)+100000); + String headerUrl = fileUtil.upFile(img,redirectAttributes,request,"/data/header/merchant/",filename); int sql = merchantMapper.updateHeader(merchant.getId(),headerUrl); - if (sql != 1){ - GiteeImgBedUtils.delete(headerUrl); + if (sql!=1){ + fileUtil.deleteFile(headerUrl); return -1; }else{ - GiteeImgBedUtils.delete(merchant.getHeader()); + if (!merchant.getHeader().equals("/lib/merchant/images/2.png")){ + fileUtil.deleteFile(merchant.getHeader()); + } // 修改会话信息 - merchant.setHeader(GiteeImgBedUtils.PRE + headerUrl); + merchant.setHeader(headerUrl); request.getSession().setAttribute("merchant",merchant); } return 1; diff --git a/src/main/java/com/example/jieyue/merchant/service/MerchantUserService.java b/src/main/java/com/example/jieyue/merchant/service/MerchantUserService.java index 5b3d29e..90d2bbb 100644 --- a/src/main/java/com/example/jieyue/merchant/service/MerchantUserService.java +++ b/src/main/java/com/example/jieyue/merchant/service/MerchantUserService.java @@ -2,7 +2,6 @@ package com.example.jieyue.merchant.service; import com.example.jieyue.common.entity.SysUser; import com.example.jieyue.common.mapper.SysUserMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,11 +16,7 @@ public class MerchantUserService { *

获取用户信息

*/ public List getUserList(int page, int num){ - List list = userMapper.findLimit((page-1)*num,num); - for (SysUser user : list) { - user.setHeader(GiteeImgBedUtils.PRE + user.getHeader()); - } - return list; + return userMapper.findLimit((page-1)*num,num); } /** diff --git a/src/main/java/com/example/jieyue/user/controller/UserLoginController.java b/src/main/java/com/example/jieyue/user/controller/UserLoginController.java index 1bb827c..5727fc9 100644 --- a/src/main/java/com/example/jieyue/user/controller/UserLoginController.java +++ b/src/main/java/com/example/jieyue/user/controller/UserLoginController.java @@ -1,7 +1,6 @@ package com.example.jieyue.user.controller; import com.example.jieyue.common.entity.SysUser; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import com.example.jieyue.user.service.UserLoginService; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; @@ -32,7 +31,7 @@ public class UserLoginController { modelAndView.setViewName("user/login/index"); return modelAndView; } - + /** *

退出登陆

*/ @@ -52,7 +51,6 @@ public class UserLoginController { if (result==1){ // 登陆成功 SysUser user = service.userInfo(email); - user.setHeader(GiteeImgBedUtils.PRE + user.getHeader()); session.setAttribute("user",user); modelAndView.setViewName("redirect:/"); }else if (result==-1){ diff --git a/src/main/java/com/example/jieyue/user/controller/UserPayController.java b/src/main/java/com/example/jieyue/user/controller/UserPayController.java index df7cecc..c0f46f2 100644 --- a/src/main/java/com/example/jieyue/user/controller/UserPayController.java +++ b/src/main/java/com/example/jieyue/user/controller/UserPayController.java @@ -6,7 +6,6 @@ import com.example.jieyue.common.entity.SysOrder; import com.example.jieyue.common.mapper.SysGoodsMapper; import com.example.jieyue.common.mapper.SysMtMapper; import com.example.jieyue.common.mapper.SysOrderMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import com.example.jieyue.user.service.WxPayService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; @@ -35,8 +34,8 @@ public class UserPayController { String orderMark = wxPayService.getOrderId(); // 添加订单 String res = wxPayService.addOrder(nums,orderMark,users,merchants,prices,notes,goods,address,name,phone,code,0,carts); - if(!"-1".equals(res) && !"0".equals(res) && !"".equals(res)){ - modelAndView.addObject("orderMark", orderMark); + if(!res.equals("-1") && !res.equals("0") && !res.equals("")){ + modelAndView.addObject("orderMark",orderMark); modelAndView.setViewName("redirect:/user/wxpay/index?mark="+orderMark); } return modelAndView; @@ -75,10 +74,10 @@ public class UserPayController { */ @RequestMapping("/user/wxpay/index") public ModelAndView wxNotify(ModelAndView modelAndView,String mark) { - String codeUrl = GiteeImgBedUtils.PRE + orderMapper.findByOrderMark(mark).get(0).getPayCodeUrl(); + String codeUrl = orderMapper.findByOrderMark(mark).get(0).getPayCodeUrl(); - modelAndView.addObject("codeUrl", codeUrl); - modelAndView.addObject("orderMark", mark); + modelAndView.addObject("codeUrl",codeUrl); + modelAndView.addObject("orderMark",mark); modelAndView.setViewName("user/pay/wx"); return modelAndView; diff --git a/src/main/java/com/example/jieyue/user/service/UserCartService.java b/src/main/java/com/example/jieyue/user/service/UserCartService.java index 5699f68..5b3715d 100644 --- a/src/main/java/com/example/jieyue/user/service/UserCartService.java +++ b/src/main/java/com/example/jieyue/user/service/UserCartService.java @@ -7,7 +7,6 @@ import com.example.jieyue.common.entity.SysUser; import com.example.jieyue.common.mapper.SysCartMapper; import com.example.jieyue.common.mapper.SysGoodsMapper; import com.example.jieyue.common.mapper.SysMtMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -51,7 +50,7 @@ public class UserCartService { } return -1; } - + /** *

整合购物车完整信息

*/ @@ -64,7 +63,7 @@ public class UserCartService { SysGoods goods = goodsMapper.findById(cart.getGoodsId()); SysMt merchant = merchantMapper.findById(goods.getMerchant()); Map map = new HashMap<>(); - map.put("goodsImg", GiteeImgBedUtils.PRE + goods.getImg()); + map.put("goodsImg",goods.getImg()); map.put("cartId",cart.getId()+""); map.put("goodsId",goods.getId()+""); map.put("goodsPrice",goods.getPrice().toPlainString()); diff --git a/src/main/java/com/example/jieyue/user/service/UserHomeService.java b/src/main/java/com/example/jieyue/user/service/UserHomeService.java index 6477d15..d1ba00a 100644 --- a/src/main/java/com/example/jieyue/user/service/UserHomeService.java +++ b/src/main/java/com/example/jieyue/user/service/UserHomeService.java @@ -6,7 +6,6 @@ import com.example.jieyue.common.entity.SysUi; import com.example.jieyue.common.mapper.SysGoodsMapper; import com.example.jieyue.common.mapper.SysMtUiMapper; import com.example.jieyue.common.mapper.SysUiMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -43,7 +42,7 @@ public class UserHomeService { redisTemplate.expire("homePageCache",10, TimeUnit.MINUTES); } - /** + /* * 获取商城网页的宣传海报 */ public Map getImage(){ @@ -56,25 +55,6 @@ public class UserHomeService { SysUi img3151 = uiMapper.findByMark(3151,282); SysUi img3152 = uiMapper.findByMark(3152,282); - if(img1920 != null) { - img1920.setUrl(GiteeImgBedUtils.PRE + img1920.getUrl()); - } - if(img1230 != null) { - img1230.setUrl(GiteeImgBedUtils.PRE + img1230.getUrl()); - } - if(img475 != null) { - img475.setUrl(GiteeImgBedUtils.PRE + img475.getUrl()); - } - if(img674 != null) { - img674.setUrl(GiteeImgBedUtils.PRE + img674.getUrl()); - } - if(img3151 != null) { - img3151.setUrl(GiteeImgBedUtils.PRE + img3151.getUrl()); - } - if(img3152 != null) { - img3152.setUrl(GiteeImgBedUtils.PRE + img3152.getUrl()); - } - map.put(1920+"",img1920); map.put(1230+"",img1230); map.put(475+"",img475); @@ -84,46 +64,51 @@ public class UserHomeService { return map; } - - /** + + /* * 获取热卖商品 */ public Map getEsc(int num){ - return common(goodsMapper.findAllEsc(num)); - } - - /** - * 获取新出商品 - */ - public Map getDesc(int num){ - return common(goodsMapper.findAllDesc(num)); - } - - /** - * 随机获取商品 - */ - public Map getRand(int num){ - return common(goodsMapper.findRand(num)); - } - - public Map common(List list) { + List list = goodsMapper.findAllEsc(num); Map map = new HashMap<>(); for (int i=0;i < list.size();i++) { - list.get(i).setImg(GiteeImgBedUtils.PRE + list.get(i).getImg()); - map.put(i+"", list.get(i)); + map.put(i+"",list.get(i)); } return map; } - /** + /* + * 获取新出商品 + */ + public Map getDesc(int num){ + List list = goodsMapper.findAllDesc(num); + Map map = new HashMap<>(); + for (int i=0;i < list.size();i++) { + map.put(i+"",list.get(i)); + } + return map; + } + + /* + * 随机获取商品 + */ + public Map getRand(int num){ + List list = goodsMapper.findRand(num); + Map map = new HashMap<>(); + for (int i=0;i < list.size();i++) { + map.put(i+"",list.get(i)); + } + return map; + } + + /* * 获取商户宣传店铺的海报 */ public Map getMtImg(int width,int height,int num){ Map map = new HashMap<>(); List list = mtUiMapper.findLimit(width,height,num); for (int i=0;i getGoodsList(List orderList){ List list = new ArrayList<>(); for (SysOrder order : orderList) { - SysGoods goods = goodsMapper.findById(order.getGoodsId()); - goods.setImg(GiteeImgBedUtils.PRE + goods.getImg()); - list.add(goods); + list.add(goodsMapper.findById(order.getGoodsId())); } return list; } diff --git a/src/main/java/com/example/jieyue/user/service/UserProductService.java b/src/main/java/com/example/jieyue/user/service/UserProductService.java index 81302ef..9f5483d 100644 --- a/src/main/java/com/example/jieyue/user/service/UserProductService.java +++ b/src/main/java/com/example/jieyue/user/service/UserProductService.java @@ -6,7 +6,6 @@ import com.example.jieyue.common.entity.SysUser; import com.example.jieyue.common.mapper.SysCommentMapper; import com.example.jieyue.common.mapper.SysGoodsMapper; import com.example.jieyue.common.mapper.SysUserMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,7 +21,7 @@ public class UserProductService { SysCommentMapper commentMapper; @Autowired SysUserMapper userMapper; - + /** *

整合用户信息和评论信息

*/ @@ -33,7 +32,7 @@ public class UserProductService { for (SysComment comment : commentInfo) { Map commentMap = new HashMap<>(); SysUser user = getUserInfo(comment.getUser()); - commentMap.put("userHeader",GiteeImgBedUtils.PRE + user.getHeader()); + commentMap.put("userHeader",user.getHeader()); commentMap.put("userId",user.getId()+""); commentMap.put("commentId",comment.getId()+""); commentMap.put("userName",user.getUsername()); @@ -44,7 +43,7 @@ public class UserProductService { } return list; } - + /** *

获取当前商品总评论页数

*/ @@ -52,14 +51,12 @@ public class UserProductService { int count = commentMapper.getAllCountByGoods(goods); return (int)Math.ceil((double)count/(double)num); } - + /** *

通过id值获取商品对象

*/ public SysGoods getGoods(int id){ - SysGoods goods = goodsMapper.findById(id); - goods.setImg(GiteeImgBedUtils.PRE + goods.getImg()); - return goods; + return goodsMapper.findById(id); } /** @@ -71,14 +68,14 @@ public class UserProductService { public List getCommentInfo(int goods, int page, int num){ return commentMapper.findByGoodsLimit(goods,(page-1)*num,page*num); } - + /** *

获取评论对应的商户信息

*/ public SysUser getUserInfo(int userId){ return userMapper.selectById(userId); } - + /** *

添加商品评论

* @return diff --git a/src/main/java/com/example/jieyue/user/service/UserSearchService.java b/src/main/java/com/example/jieyue/user/service/UserSearchService.java index c83fc24..b8ed25f 100644 --- a/src/main/java/com/example/jieyue/user/service/UserSearchService.java +++ b/src/main/java/com/example/jieyue/user/service/UserSearchService.java @@ -4,7 +4,6 @@ import com.example.jieyue.common.entity.SysGoods; import com.example.jieyue.common.index.GoodsIndex; import com.example.jieyue.common.mapper.SysGoodsMapper; import com.example.jieyue.common.repository.GoodsIndexRepository; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,11 +21,7 @@ public class UserSearchService { *

mysql通过关键字模糊查找商品

*/ public List mysqlSearchGoods(String keyword){ - List list = goodsMapper.search(keyword); - for (SysGoods goods : list) { - goods.setImg(GiteeImgBedUtils.PRE + goods.getImg()); - } - return list; + return goodsMapper.search(keyword); } /** diff --git a/src/main/java/com/example/jieyue/user/service/UserShopService.java b/src/main/java/com/example/jieyue/user/service/UserShopService.java index 88ac7da..5e27f92 100644 --- a/src/main/java/com/example/jieyue/user/service/UserShopService.java +++ b/src/main/java/com/example/jieyue/user/service/UserShopService.java @@ -4,7 +4,6 @@ import com.example.jieyue.common.entity.SysGoods; import com.example.jieyue.common.entity.SysMt; import com.example.jieyue.common.mapper.SysGoodsMapper; import com.example.jieyue.common.mapper.SysMtMapper; -import com.example.jieyue.common.utils.GiteeImgBedUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -23,34 +22,33 @@ public class UserShopService { *

获取商户信息

*/ public SysMt getMerchantInfo(int merchantId){ - SysMt merchant = merchantMapper.findById(merchantId); - merchant.setHeader(GiteeImgBedUtils.PRE + merchant.getHeader()); - return merchant; + return merchantMapper.findById(merchantId); } /** *

获取商户商品信息

*/ public Map getGoodsList(int merchantId, int page, int num){ - return common(goodsMapper.findByMtLimit(merchantId,(page-1)*num,page*num)); - } - - /** - *

随机获取商品

- */ - public Map getRandGoodsMap(int merchant,int num){ - return common(goodsMapper.findMerchantRand(merchant,num)); - } - - public Map common(List list) { + List list = goodsMapper.findByMtLimit(merchantId,(page-1)*num,page*num); Map map = new HashMap<>(); - for (int i = 0;i < list.size();i++) { - list.get(i).setImg(GiteeImgBedUtils.PRE + list.get(i).getImg()); + for (int i = 0;i < list.size();i++){ map.put(i,list.get(i)); } return map; } - + + /** + *

随机获取商品

+ */ + public Map getRandGoodsMap(int merchant,int num){ + List list = goodsMapper.findMerchantRand(merchant,num); + Map map = new HashMap<>(); + for (int i = 0;i < list.size();i++) { + map.put(i,list.get(i)); + } + return map; + } + /** *

获取总页数

*/ diff --git a/src/main/java/com/example/jieyue/user/service/WxPayService.java b/src/main/java/com/example/jieyue/user/service/WxPayService.java index 018a469..c6002a0 100644 --- a/src/main/java/com/example/jieyue/user/service/WxPayService.java +++ b/src/main/java/com/example/jieyue/user/service/WxPayService.java @@ -8,6 +8,7 @@ import com.example.jieyue.common.mapper.SysMtMapper; import com.example.jieyue.common.mapper.SysOrderMapper; import com.example.jieyue.common.utils.IsEmptyUtil; import com.example.jieyue.common.utils.QRCodeUtil; +import com.example.jieyue.common.utils.StringUtil; import com.example.jieyue.wxpay.config.MyWXPayConfig; import com.example.jieyue.wxpay.sdk.WXPay; import com.example.jieyue.wxpay.sdk.WXPayConstants; @@ -27,10 +28,7 @@ import java.io.InputStreamReader; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.SimpleDateFormat; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; +import java.util.*; /** *

微信支付服务类

@@ -39,6 +37,8 @@ import java.util.Random; */ @Service public class WxPayService { + @Autowired + StringUtil stringUtil; @Autowired SysOrderMapper orderMapper; @Autowired @@ -91,7 +91,7 @@ public class WxPayService { SysMt merchant = merchantMapper.findById(Integer.valueOf(merchantsArr[i])); // 执行sql语句 int sql = -1; - if ("0".equals(cartArr[i])){ + if (cartArr[i].equals("0")){ sql = orderMapper.insert1(orderId,createTime,Integer.valueOf(numArr[i]),mark,Integer.valueOf(userArr[i]), Integer.valueOf(merchantsArr[i]),new BigDecimal(dfPrice.format(Double.valueOf(pricesArr[i]))), Integer.valueOf(goodsArr[i]),notes,address,name,phone,code,way,merchant.getRatio()); @@ -117,9 +117,10 @@ public class WxPayService { *

分割js传递的数组

*/ public String[] getStringArray(String array){ + List list = new ArrayList<>(); return array.split(","); } - + /** *

总金额运算

*/ @@ -144,20 +145,21 @@ public class WxPayService { data.put("body", "捷阅网商品"); data.put("out_trade_no", orderMark); data.put("device_info", orderMark); + BigDecimal temp = new BigDecimal(100); data.put("total_fee", price); data.put("spbill_create_ip", "123.12.12.123"); - data.put("notify_url", siteUrl + "/user/wxpay/notify"); + data.put("notify_url", siteUrl+"/user/wxpay/notify"); data.put("trade_type", "NATIVE"); // 此处指定为扫码支付 data.put("product_id", orderMark); - String codeUrl = ""; try { Map resp = wxPay.unifiedOrder(data); System.out.println(resp); - codeUrl = QRCodeUtil.zxingCodeCreate(resp.get("code_url"), "/data/pay/", 500, ""); + QRCodeUtil.zxingCodeCreate(resp.get("code_url"),classPath+"/data/pay/",orderMark,500,""); } catch (Exception e) { e.printStackTrace(); } - orderMapper.updateCodeUrl(codeUrl, orderMark); + String codeUrl = "/data/pay/"+orderMark+".jpg"; + orderMapper.updateCodeUrl(codeUrl,orderMark); return codeUrl; } @@ -179,7 +181,7 @@ public class WxPayService { return result; } - + /** *

回调处理

*/ diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 20279fd..9fb9d90 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,10 +11,6 @@ server: error: include-exception: true spring: - servlet: - multipart: - max-file-size: 50MB - max-request-size: 100MB jmx: enabled: false application: @@ -26,7 +22,7 @@ spring: url: jdbc:mysql://${site-url}:3306/jieyue?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC data: elasticsearch: - cluster-nodes: ${site-url}:9200 + cluster-nodes: 127.0.0.1:9200 cluster-name: elasticsearch repositories: enabled: true diff --git a/src/main/resources/static/data/header/user/2.jpg b/src/main/resources/static/data/header/user/2.jpg deleted file mode 100644 index 42078da..0000000 Binary files a/src/main/resources/static/data/header/user/2.jpg and /dev/null differ