diff --git a/README.md b/README.md
index 9632bcb..bc634e5 100644
--- a/README.md
+++ b/README.md
@@ -144,7 +144,7 @@ PicPick | 屏幕取色工具 | https://picpick.app/zh/
JDK | 1.8 | https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Mysql | 5.7 | https://www.mysql.com/
Redis | 3.2 | https://redis.io/download
-Elasticsearch | 2.4.6 | https://www.elastic.co/downloads
+Elasticsearch | 6.2.2 | https://www.elastic.co/downloads
MongoDb | 3.2 | https://www.mongodb.com/download-center
RabbitMq | 5.25 | http://www.rabbitmq.com/download.html
nginx | 1.10 | http://nginx.org/en/download.html
diff --git a/document/reference/deploy-windows.md b/document/reference/deploy-windows.md
index 448e52d..e9e4517 100644
--- a/document/reference/deploy-windows.md
+++ b/document/reference/deploy-windows.md
@@ -25,17 +25,19 @@
- 下载地址:https://github.com/MicrosoftArchive/redis/releases
- 下载后按提示进行安装
+- 启动redis:redis-server.exe redis.windows.conf
## elasticsearch
-- 下载地址:https://www.elastic.co/downloads/past-releases/elasticsearch-2-4-6
+- 下载地址:https://www.elastic.co/downloads/past-releases/elasticsearch-6-2-2
- 下载.zip文件,解压到指定目录
-- 安装head插件,在elasticsearch-2.4.6\bin目录下执行以下命令:plugin install mobz/elasticsearch-head
-- 安装中文分词插件:https://github.com/medcl/elasticsearch-analysis-ik
-- 下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v1.10.6/elasticsearch-analysis-ik-1.10.6.zip
-- 解压并拷贝到elasticsearch-2.4.6\plugins目录下
-- 启动elasticsearch:运行elasticsearch-2.4.6\bin\elasticsearch.bat
+- 安装head插件,具体参考:https://github.com/mobz/elasticsearch-head
+- 中文分词插件地址:https://github.com/medcl/elasticsearch-analysis-ik
+- 安装中文分词插件,在elasticsearch-6.2.2\bin目录下执行以下命令:
+elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.2/elasticsearch-analysis-ik-6.2.2.zip
+- 启动elasticsearch:运行elasticsearch-6.2.2\bin\elasticsearch.bat
- 打开该地址测试是否安装成功:http://localhost:9200/_plugin/head/
+- 不使用head插件的可以使用kibana,请下载6.2.2版本,具体参考:https://www.elastic.co/downloads/kibana
## mongodb
diff --git a/document/sql/mall.sql b/document/sql/mall.sql
index adc9f8c..4d02484 100644
--- a/document/sql/mall.sql
+++ b/document/sql/mall.sql
@@ -10,7 +10,7 @@ Target Server Type : MYSQL
Target Server Version : 50719
File Encoding : 65001
-Date: 2019-01-29 14:14:36
+Date: 2019-03-21 15:44:19
*/
SET FOREIGN_KEY_CHECKS=0;
@@ -211,7 +211,7 @@ CREATE TABLE `cms_subject_product_relation` (
`subject_id` bigint(20) DEFAULT NULL,
`product_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8 COMMENT='专题商品关系表';
+) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8 COMMENT='专题商品关系表';
-- ----------------------------
-- Records of cms_subject_product_relation
@@ -421,7 +421,7 @@ INSERT INTO `oms_order` VALUES ('22', '1', '2', '201809150101000005', '2018-09-1
INSERT INTO `oms_order` VALUES ('23', '1', '2', '201809150102000006', '2018-09-15 14:24:29', 'test', '18732.00', '16377.75', '0.00', '2344.25', '0.00', '10.00', '0.00', '1', '1', '1', '0', '顺丰快递', 'xxx', '15', '0', '0', '单品促销,打折优惠:满3件,打7.50折,满减优惠:满1000.00元,减120.00元,满减优惠:满1000.00元,减120.00元,无优惠', null, null, null, null, null, '大梨', '18033441849', '518000', '广东省', '深圳市', '福田区', '东晓街道', null, '0', '0', '1000', null, '2018-10-16 14:41:28', null, null, null);
INSERT INTO `oms_order` VALUES ('24', '1', '2', '201809130101000005', '2018-09-13 16:57:40', 'test', '18732.00', '16377.75', '0.00', '2344.25', '0.00', '10.00', '0.00', '2', '1', '2', '0', null, null, '15', '18682', '18682', '单品促销,打折优惠:满3件,打7.50折,满减优惠:满1000.00元,减120.00元,满减优惠:满1000.00元,减120.00元,无优惠', null, null, null, null, null, '大梨', '18033441849', '518000', '广东省', '深圳市', '福田区', '东晓街道', null, '0', '0', null, null, null, null, null, null);
INSERT INTO `oms_order` VALUES ('25', '1', '2', '201809130102000006', '2018-09-13 17:03:00', 'test', '18732.00', '16377.75', '10.00', '2344.25', '0.00', '10.00', '5.00', '1', '1', '4', '0', null, null, '15', '18682', '18682', '单品促销,打折优惠:满3件,打7.50折,满减优惠:满1000.00元,减120.00元,满减优惠:满1000.00元,减120.00元,无优惠', null, null, null, null, null, '大梨22', '18033441849', '518000', '北京市', '北京城区', '东城区', '东城街道', 'xxx', '0', '0', null, null, null, null, null, '2018-10-30 15:08:31');
-INSERT INTO `oms_order` VALUES ('26', '1', '2', '201809140101000003', '2018-09-14 16:16:16', 'test', '18732.00', '16377.75', '0.00', '2344.25', '0.00', '10.00', '0.00', '2', '1', '4', '0', null, null, '15', '18682', '18682', '单品促销,打折优惠:满3件,打7.50折,满减优惠:满1000.00元,减120.00元,满减优惠:满1000.00元,减120.00元,无优惠', null, null, null, null, null, '大梨', '18033441849', '518000', '广东省', '深圳市', '福田区', '东晓街道', null, '0', '1', null, null, null, null, null, null);
+INSERT INTO `oms_order` VALUES ('26', '1', '2', '201809140101000003', '2018-09-14 16:16:16', 'test', '18732.00', '16377.75', '0.00', '2344.25', '0.00', '10.00', '0.00', '0', '1', '4', '0', null, null, '15', '18682', '18682', '单品促销,打折优惠:满3件,打7.50折,满减优惠:满1000.00元,减120.00元,满减优惠:满1000.00元,减120.00元,无优惠', null, null, null, null, null, '大梨', '18033441849', '518000', '广东省', '深圳市', '福田区', '东晓街道', null, '0', '0', null, null, null, null, null, null);
-- ----------------------------
-- Table structure for oms_order_item
@@ -1090,7 +1090,7 @@ CREATE TABLE `pms_product_category` (
`keywords` varchar(255) DEFAULT NULL,
`description` text COMMENT '描述',
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8 COMMENT='产品分类';
+) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=utf8 COMMENT='产品分类';
-- ----------------------------
-- Records of pms_product_category
@@ -1405,7 +1405,7 @@ CREATE TABLE `sms_coupon_history` (
-- ----------------------------
-- Records of sms_coupon_history
-- ----------------------------
-INSERT INTO `sms_coupon_history` VALUES ('2', '2', '1', '4931048380330002', 'windir', '1', '2018-08-29 14:04:12', '1', '2018-11-12 14:38:47', '12', '201809150101000001');
+INSERT INTO `sms_coupon_history` VALUES ('2', '2', '1', '4931048380330002', 'windir', '1', '2018-08-29 14:04:12', '0', '2019-03-21 15:03:40', '12', '201809150101000001');
INSERT INTO `sms_coupon_history` VALUES ('3', '3', '1', '4931048380330003', 'windir', '1', '2018-08-29 14:04:29', '0', null, null, null);
INSERT INTO `sms_coupon_history` VALUES ('4', '4', '1', '4931048380330004', 'windir', '1', '2018-08-29 14:04:32', '0', null, null, null);
INSERT INTO `sms_coupon_history` VALUES ('11', '7', '1', '4931048380330001', 'windir', '1', '2018-09-04 16:21:50', '0', null, null, null);
@@ -1740,13 +1740,13 @@ CREATE TABLE `ums_admin` (
`login_time` datetime DEFAULT NULL COMMENT '最后登录时间',
`status` int(1) DEFAULT '1' COMMENT '帐号启用状态:0->禁用;1->启用',
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='后台用户表';
+) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='后台用户表';
-- ----------------------------
-- Records of ums_admin
-- ----------------------------
-INSERT INTO `ums_admin` VALUES ('1', 'test', '202cb962ac59075b964b07152d234b70', 'http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180607/timg.jpg', null, '测试账号', null, '2018-09-29 13:55:30', '2018-09-29 13:55:39', '1');
-INSERT INTO `ums_admin` VALUES ('3', 'admin', 'e10adc3949ba59abbe56e057f20f883e', 'http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20190129/170157_yIl3_1767531.jpg', 'admin@163.com', '系统管理员', '系统管理员', '2018-10-08 13:32:47', '2019-01-29 10:10:51', '1');
+INSERT INTO `ums_admin` VALUES ('1', 'test', '$2a$10$NZ5o7r2E.ayT2ZoxgjlI.eJ6OEYqjH7INR/F.mXDbjZJi9HF0YCVG', 'http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180607/timg.jpg', null, '测试账号', null, '2018-09-29 13:55:30', '2018-09-29 13:55:39', '1');
+INSERT INTO `ums_admin` VALUES ('3', 'admin', '$2a$10$NZ5o7r2E.ayT2ZoxgjlI.eJ6OEYqjH7INR/F.mXDbjZJi9HF0YCVG', 'http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20190129/170157_yIl3_1767531.jpg', 'admin@163.com', '系统管理员', '系统管理员', '2018-10-08 13:32:47', '2019-03-20 15:38:50', '1');
-- ----------------------------
-- Table structure for ums_admin_login_log
@@ -1760,7 +1760,7 @@ CREATE TABLE `ums_admin_login_log` (
`address` varchar(100) DEFAULT NULL,
`user_agent` varchar(100) DEFAULT NULL COMMENT '浏览器登录类型',
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COMMENT='后台用户登录日志表';
+) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COMMENT='后台用户登录日志表';
-- ----------------------------
-- Records of ums_admin_login_log
@@ -1772,6 +1772,12 @@ INSERT INTO `ums_admin_login_log` VALUES ('8', '3', '2018-12-18 13:51:51', '0:0:
INSERT INTO `ums_admin_login_log` VALUES ('9', '3', '2019-01-28 16:20:41', '0:0:0:0:0:0:0:1', null, null);
INSERT INTO `ums_admin_login_log` VALUES ('10', '3', '2019-01-29 09:16:25', '0:0:0:0:0:0:0:1', null, null);
INSERT INTO `ums_admin_login_log` VALUES ('11', '3', '2019-01-29 10:10:51', '0:0:0:0:0:0:0:1', null, null);
+INSERT INTO `ums_admin_login_log` VALUES ('12', '3', '2019-02-18 11:03:06', '0:0:0:0:0:0:0:1', null, null);
+INSERT INTO `ums_admin_login_log` VALUES ('13', '3', '2019-03-12 10:03:55', '0:0:0:0:0:0:0:1', null, null);
+INSERT INTO `ums_admin_login_log` VALUES ('14', '3', '2019-03-12 10:06:19', '0:0:0:0:0:0:0:1', null, null);
+INSERT INTO `ums_admin_login_log` VALUES ('15', '3', '2019-03-12 10:15:22', '0:0:0:0:0:0:0:1', null, null);
+INSERT INTO `ums_admin_login_log` VALUES ('16', '3', '2019-03-20 15:35:33', '0:0:0:0:0:0:0:1', null, null);
+INSERT INTO `ums_admin_login_log` VALUES ('17', '3', '2019-03-20 15:38:50', '0:0:0:0:0:0:0:1', null, null);
-- ----------------------------
-- Table structure for ums_admin_permission_relation
@@ -1898,14 +1904,14 @@ CREATE TABLE `ums_member` (
-- ----------------------------
-- Records of ums_member
-- ----------------------------
-INSERT INTO `ums_member` VALUES ('1', '4', 'test', '202cb962ac59075b964b07152d234b70', 'windir', '18061581849', '1', '2018-08-02 10:35:44', null, '1', '2009-06-01', '上海', '学生', 'test', null, '5000', null, null, null);
-INSERT INTO `ums_member` VALUES ('3', '4', 'windy', 'e10adc3949ba59abbe56e057f20f883e', 'windy', '18061581848', '1', '2018-08-03 16:46:38', null, null, null, null, null, null, null, null, null, null, null);
-INSERT INTO `ums_member` VALUES ('4', '4', 'zhengsan', 'e10adc3949ba59abbe56e057f20f883e', 'zhengsan', '18061581847', '1', '2018-11-12 14:12:04', null, null, null, null, null, null, null, null, null, null, null);
-INSERT INTO `ums_member` VALUES ('5', '4', 'lisi', 'e10adc3949ba59abbe56e057f20f883e', 'lisi', '18061581841', '1', '2018-11-12 14:12:38', null, null, null, null, null, null, null, null, null, null, null);
-INSERT INTO `ums_member` VALUES ('6', '4', 'wangwu', 'e10adc3949ba59abbe56e057f20f883e', 'wangwu', '18061581842', '1', '2018-11-12 14:13:09', null, null, null, null, null, null, null, null, null, null, null);
-INSERT INTO `ums_member` VALUES ('7', '4', 'lion', 'e10adc3949ba59abbe56e057f20f883e', 'lion', '18061581845', '1', '2018-11-12 14:21:39', null, null, null, null, null, null, null, null, null, null, null);
-INSERT INTO `ums_member` VALUES ('8', '4', 'shari', 'e10adc3949ba59abbe56e057f20f883e', 'shari', '18061581844', '1', '2018-11-12 14:22:00', null, null, null, null, null, null, null, null, null, null, null);
-INSERT INTO `ums_member` VALUES ('9', '4', 'aewen', 'e10adc3949ba59abbe56e057f20f883e', 'aewen', '18061581843', '1', '2018-11-12 14:22:55', null, null, null, null, null, null, null, null, null, null, null);
+INSERT INTO `ums_member` VALUES ('1', '4', 'test', '$2a$10$NZ5o7r2E.ayT2ZoxgjlI.eJ6OEYqjH7INR/F.mXDbjZJi9HF0YCVG', 'windir', '18061581849', '1', '2018-08-02 10:35:44', null, '1', '2009-06-01', '上海', '学生', 'test', null, '5000', null, null, null);
+INSERT INTO `ums_member` VALUES ('3', '4', 'windy', '$2a$10$NZ5o7r2E.ayT2ZoxgjlI.eJ6OEYqjH7INR/F.mXDbjZJi9HF0YCVG', 'windy', '18061581848', '1', '2018-08-03 16:46:38', null, null, null, null, null, null, null, null, null, null, null);
+INSERT INTO `ums_member` VALUES ('4', '4', 'zhengsan', '$2a$10$NZ5o7r2E.ayT2ZoxgjlI.eJ6OEYqjH7INR/F.mXDbjZJi9HF0YCVG', 'zhengsan', '18061581847', '1', '2018-11-12 14:12:04', null, null, null, null, null, null, null, null, null, null, null);
+INSERT INTO `ums_member` VALUES ('5', '4', 'lisi', '$2a$10$NZ5o7r2E.ayT2ZoxgjlI.eJ6OEYqjH7INR/F.mXDbjZJi9HF0YCVG', 'lisi', '18061581841', '1', '2018-11-12 14:12:38', null, null, null, null, null, null, null, null, null, null, null);
+INSERT INTO `ums_member` VALUES ('6', '4', 'wangwu', '$2a$10$NZ5o7r2E.ayT2ZoxgjlI.eJ6OEYqjH7INR/F.mXDbjZJi9HF0YCVG', 'wangwu', '18061581842', '1', '2018-11-12 14:13:09', null, null, null, null, null, null, null, null, null, null, null);
+INSERT INTO `ums_member` VALUES ('7', '4', 'lion', '$2a$10$NZ5o7r2E.ayT2ZoxgjlI.eJ6OEYqjH7INR/F.mXDbjZJi9HF0YCVG', 'lion', '18061581845', '1', '2018-11-12 14:21:39', null, null, null, null, null, null, null, null, null, null, null);
+INSERT INTO `ums_member` VALUES ('8', '4', 'shari', '$2a$10$NZ5o7r2E.ayT2ZoxgjlI.eJ6OEYqjH7INR/F.mXDbjZJi9HF0YCVG', 'shari', '18061581844', '1', '2018-11-12 14:22:00', null, null, null, null, null, null, null, null, null, null, null);
+INSERT INTO `ums_member` VALUES ('9', '4', 'aewen', '$2a$10$NZ5o7r2E.ayT2ZoxgjlI.eJ6OEYqjH7INR/F.mXDbjZJi9HF0YCVG', 'aewen', '18061581843', '1', '2018-11-12 14:22:55', null, null, null, null, null, null, null, null, null, null, null);
-- ----------------------------
-- Table structure for ums_member_level
diff --git a/mall-admin/pom.xml b/mall-admin/pom.xml
index fb21d33..e65b610 100644
--- a/mall-admin/pom.xml
+++ b/mall-admin/pom.xml
@@ -13,7 +13,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.14.RELEASE
+ 2.1.3.RELEASE
diff --git a/mall-admin/src/main/java/com/macro/mall/config/SecurityConfig.java b/mall-admin/src/main/java/com/macro/mall/config/SecurityConfig.java
index 6ad7523..c1ba851 100644
--- a/mall-admin/src/main/java/com/macro/mall/config/SecurityConfig.java
+++ b/mall-admin/src/main/java/com/macro/mall/config/SecurityConfig.java
@@ -12,8 +12,7 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
-import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
-import org.springframework.security.authentication.encoding.PasswordEncoder;
+import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -22,6 +21,8 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
@@ -90,7 +91,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder passwordEncoder() {
- return new Md5PasswordEncoder();
+ return new BCryptPasswordEncoder();
}
@Bean
@@ -127,4 +128,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
bean.setOrder(0);
return new CorsFilter(source);
}
+
+ @Bean
+ @Override
+ public AuthenticationManager authenticationManagerBean() throws Exception {
+ return super.authenticationManagerBean();
+ }
+
}
diff --git a/mall-admin/src/main/java/com/macro/mall/service/impl/UmsAdminServiceImpl.java b/mall-admin/src/main/java/com/macro/mall/service/impl/UmsAdminServiceImpl.java
index 2dfe8f5..c6aaf36 100644
--- a/mall-admin/src/main/java/com/macro/mall/service/impl/UmsAdminServiceImpl.java
+++ b/mall-admin/src/main/java/com/macro/mall/service/impl/UmsAdminServiceImpl.java
@@ -17,13 +17,13 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.authentication.encoding.PasswordEncoder;
-import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -91,7 +91,7 @@ public class UmsAdminServiceImpl implements UmsAdminService {
return null;
}
//将密码进行加密操作
- String md5Password = passwordEncoder.encodePassword(umsAdmin.getPassword(), null);
+ String md5Password = passwordEncoder.encode(umsAdmin.getPassword());
umsAdmin.setPassword(md5Password);
adminMapper.insert(umsAdmin);
return umsAdmin;
@@ -101,11 +101,13 @@ public class UmsAdminServiceImpl implements UmsAdminService {
public String login(String username, String password) {
String token = null;
//密码需要客户端加密后传递
- UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, passwordEncoder.encodePassword(password, null));
try {
- Authentication authentication = authenticationManager.authenticate(authenticationToken);
- SecurityContextHolder.getContext().setAuthentication(authentication);
UserDetails userDetails = userDetailsService.loadUserByUsername(username);
+ if(!passwordEncoder.matches(password,userDetails.getPassword())){
+ throw new BadCredentialsException("密码不正确");
+ }
+ UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
+ SecurityContextHolder.getContext().setAuthentication(authentication);
token = jwtTokenUtil.generateToken(userDetails);
updateLoginTimeByUsername(username);
insertLoginLog(username);
diff --git a/mall-admin/src/main/resources/application-dev.properties b/mall-admin/src/main/resources/application-dev.properties
index b458a3e..cd6cae4 100644
--- a/mall-admin/src/main/resources/application-dev.properties
+++ b/mall-admin/src/main/resources/application-dev.properties
@@ -1,5 +1,5 @@
#===datasource start===
-spring.datasource.url=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8
+spring.datasource.url=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
#===datasource end===
diff --git a/mall-admin/src/main/resources/application.properties b/mall-admin/src/main/resources/application.properties
index 2825a90..c10ccc6 100644
--- a/mall-admin/src/main/resources/application.properties
+++ b/mall-admin/src/main/resources/application.properties
@@ -19,7 +19,7 @@ logging.level.com.macro.mall=debug
#===thymeleaf start===
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
-spring.thymeleaf.content-type=text/html
+spring.thymeleaf.server.content-type=text/html
#\u5F00\u53D1\u65F6\u5173\u95ED\u7F13\u5B58,\u4E0D\u7136\u6CA1\u6CD5\u770B\u5230\u5B9E\u65F6\u9875\u9762
spring.thymeleaf.cache=false
#===thymeleaf end==
diff --git a/mall-demo/pom.xml b/mall-demo/pom.xml
index f330599..e057c45 100644
--- a/mall-demo/pom.xml
+++ b/mall-demo/pom.xml
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.14.RELEASE
+ 2.1.3.RELEASE
diff --git a/mall-demo/src/main/java/com/macro/mall/demo/config/SecurityConfig.java b/mall-demo/src/main/java/com/macro/mall/demo/config/SecurityConfig.java
index 9643c5f..b672478 100644
--- a/mall-demo/src/main/java/com/macro/mall/demo/config/SecurityConfig.java
+++ b/mall-demo/src/main/java/com/macro/mall/demo/config/SecurityConfig.java
@@ -7,7 +7,6 @@ import com.macro.mall.model.UmsAdminExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -15,6 +14,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.util.List;
@@ -58,7 +58,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth.userDetailsService(userDetailsService()).passwordEncoder(new Md5PasswordEncoder());
+ auth.userDetailsService(userDetailsService()).passwordEncoder(new BCryptPasswordEncoder());
}
@Bean
diff --git a/mall-demo/src/main/resources/application.properties b/mall-demo/src/main/resources/application.properties
index 0d3f8fb..4fd8f4d 100644
--- a/mall-demo/src/main/resources/application.properties
+++ b/mall-demo/src/main/resources/application.properties
@@ -3,7 +3,7 @@ server.port=8082
#===server end===
#\u6570\u636E\u5E93\u8FDE\u63A5\u6C60\u914D\u7F6E
-spring.datasource.url=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8
+spring.datasource.url=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
@@ -22,7 +22,7 @@ logging.level.com.macro.mall=debug
#thymeleaf start
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
-spring.thymeleaf.content-type=text/html
+spring.thymeleaf.servlet.content-type=text/html
#\u5F00\u53D1\u65F6\u5173\u95ED\u7F13\u5B58,\u4E0D\u7136\u6CA1\u6CD5\u770B\u5230\u5B9E\u65F6\u9875\u9762
spring.thymeleaf.cache=false
#thymeleaf end
diff --git a/mall-portal/pom.xml b/mall-portal/pom.xml
index 8bc159a..a94eec3 100644
--- a/mall-portal/pom.xml
+++ b/mall-portal/pom.xml
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.14.RELEASE
+ 2.1.3.RELEASE
diff --git a/mall-portal/src/main/java/com/macro/mall/portal/config/SecurityConfig.java b/mall-portal/src/main/java/com/macro/mall/portal/config/SecurityConfig.java
index 09ddd3f..fa107cd 100644
--- a/mall-portal/src/main/java/com/macro/mall/portal/config/SecurityConfig.java
+++ b/mall-portal/src/main/java/com/macro/mall/portal/config/SecurityConfig.java
@@ -8,8 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
-import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
-import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -17,6 +15,8 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.security.crypto.password.PasswordEncoder;
/**
* SpringSecurity的配置
@@ -90,7 +90,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder passwordEncoder() {
- return new Md5PasswordEncoder();
+ return new BCryptPasswordEncoder();
}
@Bean
diff --git a/mall-portal/src/main/java/com/macro/mall/portal/config/TomcatConfig.java b/mall-portal/src/main/java/com/macro/mall/portal/config/TomcatConfig.java
index a7775e3..2c2d518 100644
--- a/mall-portal/src/main/java/com/macro/mall/portal/config/TomcatConfig.java
+++ b/mall-portal/src/main/java/com/macro/mall/portal/config/TomcatConfig.java
@@ -2,8 +2,7 @@ package com.macro.mall.portal.config;
import org.apache.catalina.connector.Connector;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
-import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
+import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@@ -18,8 +17,8 @@ public class TomcatConfig {
@Value("${http.port}")
private Integer port;
@Bean
- public EmbeddedServletContainerFactory servletContainer() {
- TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
+ public TomcatServletWebServerFactory servletContainer() {
+ TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addAdditionalTomcatConnectors(createStandardConnector()); // 添加http
return tomcat;
}
diff --git a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberReadHistoryServiceImpl.java b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberReadHistoryServiceImpl.java
index 38c67c6..d8ed9f5 100644
--- a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberReadHistoryServiceImpl.java
+++ b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberReadHistoryServiceImpl.java
@@ -34,7 +34,7 @@ public class MemberReadHistoryServiceImpl implements MemberReadHistoryService {
memberReadHistory.setId(id);
deleteList.add(memberReadHistory);
}
- memberReadHistoryRepository.delete(deleteList);
+ memberReadHistoryRepository.deleteAll(deleteList);
return ids.size();
}
diff --git a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPortalOrderServiceImpl.java b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPortalOrderServiceImpl.java
index 800669f..ef7d3b5 100644
--- a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPortalOrderServiceImpl.java
+++ b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPortalOrderServiceImpl.java
@@ -286,7 +286,9 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
orderItemExample.createCriteria().andOrderIdEqualTo(orderId);
List orderItemList = orderItemMapper.selectByExample(orderItemExample);
//解除订单商品库存锁定
- portalOrderDao.releaseSkuStockLock(orderItemList);
+ if(!CollectionUtils.isEmpty(orderItemList)){
+ portalOrderDao.releaseSkuStockLock(orderItemList);
+ }
//修改优惠券使用状态
updateCouponStatus(cancelOrder.getCouponId(),cancelOrder.getMemberId(),0);
//返还使用积分
diff --git a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/UmsMemberServiceImpl.java b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/UmsMemberServiceImpl.java
index 0a40893..4fc41d2 100644
--- a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/UmsMemberServiceImpl.java
+++ b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/UmsMemberServiceImpl.java
@@ -12,10 +12,10 @@ import com.macro.mall.portal.service.RedisService;
import com.macro.mall.portal.service.UmsMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -77,7 +77,7 @@ public class UmsMemberServiceImpl implements UmsMemberService {
UmsMember umsMember = new UmsMember();
umsMember.setUsername(username);
umsMember.setPhone(telephone);
- umsMember.setPassword(passwordEncoder.encodePassword(password, null));
+ umsMember.setPassword(passwordEncoder.encode(password));
umsMember.setCreateTime(new Date());
umsMember.setStatus(1);
//获取默认会员等级并设置
@@ -118,7 +118,7 @@ public class UmsMemberServiceImpl implements UmsMemberService {
return new CommonResult().failed("验证码错误");
}
UmsMember umsMember = memberList.get(0);
- umsMember.setPassword(passwordEncoder.encodePassword(password,null));
+ umsMember.setPassword(passwordEncoder.encode(password));
memberMapper.updateByPrimaryKeySelective(umsMember);
return new CommonResult().success("密码修改成功",null);
}
diff --git a/mall-portal/src/main/resources/application-dev.properties b/mall-portal/src/main/resources/application-dev.properties
index 785e584..d46aab5 100644
--- a/mall-portal/src/main/resources/application-dev.properties
+++ b/mall-portal/src/main/resources/application-dev.properties
@@ -14,7 +14,7 @@ logging.level.com.macro.mall.portal.dao=debug
#===logging end===
#===datasource start===
-spring.datasource.url=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8
+spring.datasource.url=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
#===datasource end===
@@ -49,15 +49,15 @@ spring.redis.port=6379
# Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09
spring.redis.password=
# \u8FDE\u63A5\u6C60\u6700\u5927\u8FDE\u63A5\u6570\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09
-spring.redis.pool.max-active=8
+spring.redis.jedis.pool.max-active=8
# \u8FDE\u63A5\u6C60\u6700\u5927\u963B\u585E\u7B49\u5F85\u65F6\u95F4\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09
-spring.redis.pool.max-wait=-1
+spring.redis.jedis.pool.max-wait=-1ms
# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5
-spring.redis.pool.max-idle=8
+spring.redis.jedis.pool.max-idle=8
# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5
-spring.redis.pool.min-idle=0
+spring.redis.jedis.pool.min-idle=0
# \u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09
-spring.redis.timeout=0
+spring.redis.timeout=0ms
#===redis end===
#===rabbitMq start===
diff --git a/mall-portal/src/main/resources/application-prod.properties b/mall-portal/src/main/resources/application-prod.properties
index 36d6327..34bc8b0 100644
--- a/mall-portal/src/main/resources/application-prod.properties
+++ b/mall-portal/src/main/resources/application-prod.properties
@@ -41,13 +41,13 @@ spring.redis.port=6379
# Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09
spring.redis.password=
# \u8FDE\u63A5\u6C60\u6700\u5927\u8FDE\u63A5\u6570\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09
-spring.redis.pool.max-active=8
+spring.redis.jedis.pool.max-active=8
# \u8FDE\u63A5\u6C60\u6700\u5927\u963B\u585E\u7B49\u5F85\u65F6\u95F4\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09
-spring.redis.pool.max-wait=-1
+spring.redis.jedis.pool.max-wait=-1ms
# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5
-spring.redis.pool.max-idle=8
+spring.redis.jedis.pool.max-idle=8
# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5
-spring.redis.pool.min-idle=0
+spring.redis.jedis.pool.min-idle=0
# \u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09
-spring.redis.timeout=0
+spring.redis.timeout=0ms
#===redis end===
diff --git a/mall-search/pom.xml b/mall-search/pom.xml
index 95c987f..28de626 100644
--- a/mall-search/pom.xml
+++ b/mall-search/pom.xml
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.14.RELEASE
+ 2.1.3.RELEASE
diff --git a/mall-search/src/main/java/com/macro/mall/search/domain/EsProduct.java b/mall-search/src/main/java/com/macro/mall/search/domain/EsProduct.java
index 6c77287..0360c10 100644
--- a/mall-search/src/main/java/com/macro/mall/search/domain/EsProduct.java
+++ b/mall-search/src/main/java/com/macro/mall/search/domain/EsProduct.java
@@ -3,7 +3,6 @@ package com.macro.mall.search.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
-import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.io.Serializable;
@@ -19,20 +18,20 @@ public class EsProduct implements Serializable {
private static final long serialVersionUID = -1L;
@Id
private Long id;
- @Field(index = FieldIndex.not_analyzed,type = FieldType.String)
+ @Field(index = false)
private String productSn;
private Long brandId;
- @Field(index = FieldIndex.not_analyzed,type = FieldType.String)
+ @Field(index = false)
private String brandName;
private Long productCategoryId;
- @Field(index = FieldIndex.not_analyzed,type = FieldType.String)
+ @Field(index = false)
private String productCategoryName;
private String pic;
- @Field(analyzer = "ik_max_word",type = FieldType.String)
+ @Field(analyzer = "ik_max_word")
private String name;
- @Field(analyzer = "ik_max_word",type = FieldType.String)
+ @Field(analyzer = "ik_max_word")
private String subTitle;
- @Field(analyzer = "ik_max_word",type = FieldType.String)
+ @Field(analyzer = "ik_max_word")
private String keywords;
private BigDecimal price;
private Integer sale;
diff --git a/mall-search/src/main/java/com/macro/mall/search/domain/EsProductAttributeValue.java b/mall-search/src/main/java/com/macro/mall/search/domain/EsProductAttributeValue.java
index 11cd251..827bc9a 100644
--- a/mall-search/src/main/java/com/macro/mall/search/domain/EsProductAttributeValue.java
+++ b/mall-search/src/main/java/com/macro/mall/search/domain/EsProductAttributeValue.java
@@ -1,8 +1,6 @@
package com.macro.mall.search.domain;
import org.springframework.data.elasticsearch.annotations.Field;
-import org.springframework.data.elasticsearch.annotations.FieldIndex;
-import org.springframework.data.elasticsearch.annotations.FieldType;
import java.io.Serializable;
@@ -15,12 +13,12 @@ public class EsProductAttributeValue implements Serializable {
private Long id;
private Long productAttributeId;
//属性值
- @Field(index = FieldIndex.not_analyzed, type = FieldType.String)
+ @Field(index = false)
private String value;
//属性参数:0->规格;1->参数
private Integer type;
//属性名称
- @Field(index = FieldIndex.not_analyzed, type = FieldType.String)
+ @Field(index = false)
private String name;
public Long getId() {
return id;
diff --git a/mall-search/src/main/java/com/macro/mall/search/service/impl/EsProductServiceImpl.java b/mall-search/src/main/java/com/macro/mall/search/service/impl/EsProductServiceImpl.java
index 64ac5c3..28cf29d 100644
--- a/mall-search/src/main/java/com/macro/mall/search/service/impl/EsProductServiceImpl.java
+++ b/mall-search/src/main/java/com/macro/mall/search/service/impl/EsProductServiceImpl.java
@@ -6,6 +6,7 @@ import com.macro.mall.search.domain.EsProductRelatedInfo;
import com.macro.mall.search.repository.EsProductRepository;
import com.macro.mall.search.service.EsProductService;
import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
@@ -55,7 +56,7 @@ public class EsProductServiceImpl implements EsProductService {
@Override
public int importAll() {
List esProductList = productDao.getAllEsProductList(null);
- Iterable esProductIterable = productRepository.save(esProductList);
+ Iterable esProductIterable = productRepository.saveAll(esProductList);
Iterator iterator = esProductIterable.iterator();
int result = 0;
while (iterator.hasNext()) {
@@ -67,7 +68,7 @@ public class EsProductServiceImpl implements EsProductService {
@Override
public void delete(Long id) {
- productRepository.delete(id);
+ productRepository.deleteById(id);
}
@Override
@@ -90,19 +91,19 @@ public class EsProductServiceImpl implements EsProductService {
esProduct.setId(id);
esProductList.add(esProduct);
}
- productRepository.delete(esProductList);
+ productRepository.deleteAll(esProductList);
}
}
@Override
public Page search(String keyword, Integer pageNum, Integer pageSize) {
- Pageable pageable = new PageRequest(pageNum, pageSize);
+ Pageable pageable = PageRequest.of(pageNum, pageSize);
return productRepository.findByNameOrSubTitleOrKeywords(keyword, keyword, keyword, pageable);
}
@Override
public Page search(String keyword, Long brandId, Long productCategoryId, Integer pageNum, Integer pageSize,Integer sort) {
- Pageable pageable = new PageRequest(pageNum, pageSize);
+ Pageable pageable = PageRequest.of(pageNum, pageSize);
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
//分页
nativeSearchQueryBuilder.withPageable(pageable);
@@ -117,19 +118,32 @@ public class EsProductServiceImpl implements EsProductService {
}
nativeSearchQueryBuilder.withFilter(boolQueryBuilder);
}
+ //elasticsearch2.4.6的用法
+// FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery()
+// .add(QueryBuilders.matchQuery("name", keyword),
+// ScoreFunctionBuilders.weightFactorFunction(10))
+// .add(QueryBuilders.matchQuery("subTitle", keyword),
+// ScoreFunctionBuilders.weightFactorFunction(5))
+// .add(QueryBuilders.matchQuery("keywords", keyword),
+// ScoreFunctionBuilders.weightFactorFunction(2))
+// .scoreMode("sum")
+// .setMinScore(2);
//搜索
- FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery()
- .add(QueryBuilders.matchQuery("name", keyword),
- ScoreFunctionBuilders.weightFactorFunction(10))
- .add(QueryBuilders.matchQuery("subTitle", keyword),
- ScoreFunctionBuilders.weightFactorFunction(5))
- .add(QueryBuilders.matchQuery("keywords", keyword),
- ScoreFunctionBuilders.weightFactorFunction(2))
- .scoreMode("sum")
- .setMinScore(2);
if (StringUtils.isEmpty(keyword)) {
nativeSearchQueryBuilder.withQuery(QueryBuilders.matchAllQuery());
} else {
+ List filterFunctionBuilders = new ArrayList<>();
+ filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("name", keyword),
+ ScoreFunctionBuilders.weightFactorFunction(10)));
+ filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("subTitle", keyword),
+ ScoreFunctionBuilders.weightFactorFunction(5)));
+ filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("keywords", keyword),
+ ScoreFunctionBuilders.weightFactorFunction(2)));
+ FunctionScoreQueryBuilder.FilterFunctionBuilder[] builders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[filterFunctionBuilders.size()];
+ filterFunctionBuilders.toArray(builders);
+ FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(builders)
+ .scoreMode(FunctionScoreQuery.ScoreMode.SUM)
+ .setMinScore(2);
nativeSearchQueryBuilder.withQuery(functionScoreQueryBuilder);
}
//排序
@@ -157,7 +171,7 @@ public class EsProductServiceImpl implements EsProductService {
@Override
public Page recommend(Long id, Integer pageNum, Integer pageSize) {
- Pageable pageable = new PageRequest(pageNum, pageSize);
+ Pageable pageable = PageRequest.of(pageNum, pageSize);
List esProductList = productDao.getAllEsProductList(id);
if (esProductList.size() > 0) {
EsProduct esProduct = esProductList.get(0);
@@ -165,13 +179,30 @@ public class EsProductServiceImpl implements EsProductService {
Long brandId = esProduct.getBrandId();
Long productCategoryId = esProduct.getProductCategoryId();
//根据商品标题、品牌、分类进行搜索
- FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery()
- .add(QueryBuilders.matchQuery("name",keyword),ScoreFunctionBuilders.weightFactorFunction(8))
- .add(QueryBuilders.matchQuery("subTitle",keyword),ScoreFunctionBuilders.weightFactorFunction(2))
- .add(QueryBuilders.matchQuery("keywords",keyword),ScoreFunctionBuilders.weightFactorFunction(2))
- .add(QueryBuilders.termQuery("brandId",brandId),ScoreFunctionBuilders.weightFactorFunction(10))
- .add(QueryBuilders.matchQuery("productCategoryId",productCategoryId),ScoreFunctionBuilders.weightFactorFunction(6))
- .scoreMode("sum")
+ //elasticsearch2.4.6的用法
+// FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery()
+// .add(QueryBuilders.matchQuery("name",keyword),ScoreFunctionBuilders.weightFactorFunction(8))
+// .add(QueryBuilders.matchQuery("subTitle",keyword),ScoreFunctionBuilders.weightFactorFunction(2))
+// .add(QueryBuilders.matchQuery("keywords",keyword),ScoreFunctionBuilders.weightFactorFunction(2))
+// .add(QueryBuilders.termQuery("brandId",brandId),ScoreFunctionBuilders.weightFactorFunction(10))
+// .add(QueryBuilders.matchQuery("productCategoryId",productCategoryId),ScoreFunctionBuilders.weightFactorFunction(6))
+// .scoreMode("sum")
+// .setMinScore(2);
+ List filterFunctionBuilders = new ArrayList<>();
+ filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("name", keyword),
+ ScoreFunctionBuilders.weightFactorFunction(8)));
+ filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("subTitle", keyword),
+ ScoreFunctionBuilders.weightFactorFunction(2)));
+ filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("keywords", keyword),
+ ScoreFunctionBuilders.weightFactorFunction(2)));
+ filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("brandId", brandId),
+ ScoreFunctionBuilders.weightFactorFunction(10)));
+ filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchQuery("productCategoryId", productCategoryId),
+ ScoreFunctionBuilders.weightFactorFunction(6)));
+ FunctionScoreQueryBuilder.FilterFunctionBuilder[] builders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[filterFunctionBuilders.size()];
+ filterFunctionBuilders.toArray(builders);
+ FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(builders)
+ .scoreMode(FunctionScoreQuery.ScoreMode.SUM)
.setMinScore(2);
NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder();
builder.withQuery(functionScoreQueryBuilder);
@@ -197,10 +228,8 @@ public class EsProductServiceImpl implements EsProductService {
//集合搜索分类名称
builder.addAggregation(AggregationBuilders.terms("productCategoryNames").field("productCategoryName"));
//聚合搜索商品属性,去除type=1的属性
- AbstractAggregationBuilder aggregationBuilder = AggregationBuilders.nested("allAttrValues")
- .path("attrValueList")
- .subAggregation(AggregationBuilders.filter("productAttrs")
- .filter(QueryBuilders.termQuery("attrValueList.type",1))
+ AbstractAggregationBuilder aggregationBuilder = AggregationBuilders.nested("allAttrValues","attrValueList")
+ .subAggregation(AggregationBuilders.filter("productAttrs",QueryBuilders.termQuery("attrValueList.type",1))
.subAggregation(AggregationBuilders.terms("attrIds")
.field("attrValueList.productAttributeId")
.subAggregation(AggregationBuilders.terms("attrValues")
@@ -224,38 +253,38 @@ public class EsProductServiceImpl implements EsProductService {
//设置品牌
Aggregation brandNames = aggregationMap.get("brandNames");
List brandNameList = new ArrayList<>();
- for(int i = 0; i<((StringTerms) brandNames).getBuckets().size(); i++){
- brandNameList.add(((StringTerms) brandNames).getBuckets().get(i).getKeyAsString());
+ for(int i = 0; i<((Terms) brandNames).getBuckets().size(); i++){
+ brandNameList.add(((Terms) brandNames).getBuckets().get(i).getKeyAsString());
}
productRelatedInfo.setBrandNames(brandNameList);
//设置分类
Aggregation productCategoryNames = aggregationMap.get("productCategoryNames");
List productCategoryNameList = new ArrayList<>();
- for(int i=0;i<((StringTerms) productCategoryNames).getBuckets().size();i++){
- productCategoryNameList.add(((StringTerms) productCategoryNames).getBuckets().get(i).getKeyAsString());
+ for(int i=0;i<((Terms) productCategoryNames).getBuckets().size();i++){
+ productCategoryNameList.add(((Terms) productCategoryNames).getBuckets().get(i).getKeyAsString());
}
productRelatedInfo.setProductCategoryNames(productCategoryNameList);
//设置参数
Aggregation productAttrs = aggregationMap.get("allAttrValues");
- List attrIds = ((LongTerms) ((InternalFilter)productAttrs.getProperty("productAttrs")).getAggregations().getProperty("attrIds")).getBuckets();
- List attrList = new ArrayList<>();
- for (Terms.Bucket attrId : attrIds) {
- EsProductRelatedInfo.ProductAttr attr = new EsProductRelatedInfo.ProductAttr();
- attr.setAttrId((Long) attrId.getKey());
- List attrValueList = new ArrayList<>();
- List attrValues = ((StringTerms) attrId.getAggregations().get("attrValues")).getBuckets();
- List attrNames = ((StringTerms) attrId.getAggregations().get("attrNames")).getBuckets();
- for (Terms.Bucket attrValue : attrValues) {
- attrValueList.add(attrValue.getKeyAsString());
- }
- attr.setAttrValues(attrValueList);
- if(!CollectionUtils.isEmpty(attrNames)){
- String attrName = attrNames.get(0).getKeyAsString();
- attr.setAttrName(attrName);
- }
- attrList.add(attr);
- }
- productRelatedInfo.setProductAttrs(attrList);
+// List attrIds = ((LongTerms) ((InternalFilter)productAttrs.getProperty("productAttrs")).getAggregations().getProperty("attrIds")).getBuckets();
+// List attrList = new ArrayList<>();
+// for (Terms.Bucket attrId : attrIds) {
+// EsProductRelatedInfo.ProductAttr attr = new EsProductRelatedInfo.ProductAttr();
+// attr.setAttrId((Long) attrId.getKey());
+// List attrValueList = new ArrayList<>();
+// List attrValues = ((StringTerms) attrId.getAggregations().get("attrValues")).getBuckets();
+// List attrNames = ((StringTerms) attrId.getAggregations().get("attrNames")).getBuckets();
+// for (Terms.Bucket attrValue : attrValues) {
+// attrValueList.add(attrValue.getKeyAsString());
+// }
+// attr.setAttrValues(attrValueList);
+// if(!CollectionUtils.isEmpty(attrNames)){
+// String attrName = attrNames.get(0).getKeyAsString();
+// attr.setAttrName(attrName);
+// }
+// attrList.add(attr);
+// }
+// productRelatedInfo.setProductAttrs(attrList);
return productRelatedInfo;
}
}
diff --git a/mall-search/src/main/resources/application-dev.properties b/mall-search/src/main/resources/application-dev.properties
index 25d199e..c5fd3e8 100644
--- a/mall-search/src/main/resources/application-dev.properties
+++ b/mall-search/src/main/resources/application-dev.properties
@@ -1,5 +1,5 @@
#===datasource start===
-spring.datasource.url=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8
+spring.datasource.url=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
#===datasource end===