Browse Source

Merge branch 'dev' into release-201818-wangcz

wangdy 7 years ago
parent
commit
1cc068ad14

+ 14 - 3
pom.xml

@@ -217,6 +217,14 @@
 			<groupId>org.hibernate</groupId>
 			<artifactId>hibernate-ehcache</artifactId>
 		</dependency>
+
+
+		<dependency>
+			<groupId>com.github.debop</groupId>
+			<artifactId>hibernate-redis</artifactId>
+			<version>2.3.1</version>
+		</dependency>
+
 		<!-- jdbc -->
 		<dependency>
 			<groupId>com.oracle</groupId>
@@ -273,14 +281,17 @@
 		<dependency>
 			<groupId>com.fasterxml.jackson.core</groupId>
 			<artifactId>jackson-core</artifactId>
+			<version>2.9.6</version>
 		</dependency>
 		<dependency>
 			<groupId>com.fasterxml.jackson.core</groupId>
 			<artifactId>jackson-databind</artifactId>
+			<version>2.9.6</version>
 		</dependency>
 		<dependency>
 			<groupId>com.fasterxml.jackson.core</groupId>
 			<artifactId>jackson-annotations</artifactId>
+			<version>2.9.6</version>
 		</dependency>
 		<dependency>
 			<groupId>com.alibaba</groupId>
@@ -532,8 +543,8 @@
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-compiler-plugin</artifactId>
 				<configuration>
-					<source>1.7</source>
-					<target>1.7</target>
+					<source>1.8</source>
+					<target>1.8</target>
 				</configuration>
 			</plugin>
 			<plugin>
@@ -652,7 +663,7 @@
 				<version>2.2</version>
 				<configuration>
 					<port>8080</port>
-					<path>/platform-b2c</path>
+					<path>/</path>
 					<uriEncoding>utf-8</uriEncoding>
 				</configuration>
 			</plugin>

+ 42 - 15
src/main/java/com/uas/platform/b2c/common/account/service/impl/UserServiceImpl.java

@@ -6,9 +6,7 @@ import com.uas.platform.b2c.common.account.model.*;
 import com.uas.platform.b2c.common.account.service.UserService;
 import com.uas.platform.b2c.core.config.MessageConf;
 import com.uas.platform.b2c.core.support.SystemSession;
-import com.uas.platform.b2c.core.utils.ThreadUtils;
 import com.uas.platform.b2c.trade.util.BoundedExecutor;
-import com.uas.platform.core.concurrent.IRunnable;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.exception.SystemException;
 import com.uas.platform.core.model.PageInfo;
@@ -16,6 +14,7 @@ import com.uas.platform.core.model.PageParams;
 import com.uas.platform.core.util.AgentUtils;
 import com.uas.platform.core.util.encry.Md5Utils;
 import com.uas.sso.entity.UserView;
+import com.uas.sso.util.AccountUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
@@ -24,7 +23,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.ui.ModelMap;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
-import com.uas.sso.util.AccountUtils;
+
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
@@ -77,6 +76,13 @@ public class UserServiceImpl implements UserService {
 	@Autowired
 	private UserLoginTimeDao userLoginTimeDao;
 
+	private BoundedExecutor executor;
+
+	{
+		ExecutorService executorService = Executors.newCachedThreadPool();
+		executor = new BoundedExecutor(executorService, 1000);
+	}
+
 	@Override
 	public User findUserByUserUU(Long uu) {
 		List<User> users = userDao.findUserByUserUU(uu);
@@ -201,10 +207,17 @@ public class UserServiceImpl implements UserService {
 			enterpriseDao.callInitProcedure(SystemSession.getUser().getEnterprise().getUu());
 		}
 		userDao.save(user);
+		Enterprise enterprise = SystemSession.getUser().getEnterprise();
+
+		//判断是否个人用户
+		if(enterprise == null){
+			throw new RuntimeException("个人账户不能新增企业用户");
+		}
+		// 同步账户中心
 		try {
-			postToAccountCenter(user);
+			postToAccountCenter(user, enterprise);
 		} catch (Exception e) {
-			throw new SystemException(e.getMessage());
+			e.printStackTrace();
 		}
 	}
 	@Override
@@ -278,8 +291,16 @@ public class UserServiceImpl implements UserService {
 			userOld.setUserEmail(user.getUserEmail());
 			userOld.setUserTel(user.getUserTel());
 			userOld.setUserName(user.getUserName());
+
+			Enterprise enterprise = SystemSession.getUser().getEnterprise();
+
+			//判断是否个人用户
+			if(enterprise == null){
+				throw new RuntimeException("个人账户不能新增企业用户");
+			}
+
 			try {
-				postToAccountCenter(userOld);
+				postToAccountCenter(userOld, enterprise);
 			} catch (Exception e) {
 //				throw new RuntimeException(e.getMessage());
 			}
@@ -415,12 +436,21 @@ public class UserServiceImpl implements UserService {
 		return user;
 	}
 
-	public void postToAccountCenter(User user) throws Exception {
-		//判断是否个人用户
-		if(SystemSession.getUser().getEnterprise()==null){
-			throw new RuntimeException("个人账户不能新增企业用户");
-		}else{
-			AccountUtils.addUser(user.getUserUU(),SystemSession.getUser().getEnterprise().getUu());
+	public void postToAccountCenter(final User user, final Enterprise enterprise) throws Exception {
+		// 同步账户中心
+		try {
+			executor.submitTask(new Runnable() {
+				@Override
+				public void run() {
+					try {
+						AccountUtils.addUser(user.getUserUU(),enterprise.getUu());
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+			});
+		} catch (Exception e) {
+			throw new SystemException(e.getMessage());
 		}
 	}
 	@Override
@@ -432,9 +462,6 @@ public class UserServiceImpl implements UserService {
 			userDao.flush();
 			final Long enUU = SystemSession.getUser().getEnterprise().getUu();
 			// 同步账户中心
-			ExecutorService executorService = Executors.newCachedThreadPool();
-			BoundedExecutor executor = new BoundedExecutor(executorService, 1000);
-
 			try {
 				executor.submitTask(new Runnable() {
 					@Override

+ 2 - 0
src/main/java/com/uas/platform/b2c/core/utils/ThreadUtils.java

@@ -58,6 +58,8 @@ public class ThreadUtils {
 		}
 
 		public void run() {
+			// shutdown()后,不能再提交新的任务进去;但是awaitTermination()后,可以继续提交。
+			// awaitTermination()是阻塞的,返回结果是线程池是否已停止(true/false);shutdown()不阻塞。
 			threadPool.shutdown();
 			try {
 				threadPool.awaitTermination(timeout, TimeUnit.SECONDS);

+ 27 - 0
src/main/resources/dev/redisson.yaml

@@ -0,0 +1,27 @@
+# redisson configuration for redis servers
+# see : https://github.com/mrniko/redisson/wiki/2.-Configuration
+
+singleServerConfig:
+  idleConnectionTimeout: 10000
+  pingTimeout: 1000
+  connectTimeout: 1000
+  timeout: 1000
+  retryAttempts: 3
+  retryInterval: 1000
+  reconnectionTimeout: 3000
+  failedAttempts: 3
+  password: null
+  subscriptionsPerConnection: 5
+  clientName: null
+  address: ["redis://192.168.253.6:6379"]
+  subscriptionConnectionMinimumIdleSize: 1
+  subscriptionConnectionPoolSize: 25
+  connectionMinimumIdleSize: 5
+  connectionPoolSize: 100
+  database: 0
+  dnsMonitoring: false
+  dnsMonitoringInterval: 5000
+threads: 0
+codec: !<org.redisson.codec.SnappyCodec> {}
+useLinuxNativeEpoll: false
+eventLoopGroup: null

+ 27 - 0
src/main/resources/prod/redisson.yaml

@@ -0,0 +1,27 @@
+# redisson configuration for redis servers
+# see : https://github.com/mrniko/redisson/wiki/2.-Configuration
+
+singleServerConfig:
+  idleConnectionTimeout: 10000
+  pingTimeout: 1000
+  connectTimeout: 1000
+  timeout: 1000
+  retryAttempts: 3
+  retryInterval: 1000
+  reconnectionTimeout: 3000
+  failedAttempts: 3
+  password: null
+  subscriptionsPerConnection: 5
+  clientName: null
+  address: ["redis://10.10.0.200:6379"]
+  subscriptionConnectionMinimumIdleSize: 1
+  subscriptionConnectionPoolSize: 25
+  connectionMinimumIdleSize: 5
+  connectionPoolSize: 100
+  database: 0
+  dnsMonitoring: false
+  dnsMonitoringInterval: 5000
+threads: 0
+codec: !<org.redisson.codec.SnappyCodec> {}
+useLinuxNativeEpoll: false
+eventLoopGroup: null

+ 3 - 2
src/main/resources/spring/context.xml

@@ -128,9 +128,10 @@
 		</property>
 		<property name="jpaProperties">
 			<props>
-				<prop key="hibernate.cache.provider_configuration_file_resource_path">classpath:spring/ehcache.xml</prop>
-				<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
+				<prop key="hibernate.cache.provider_configuration_file_resource_path">classpath:spring/hibernate-redis.properties</prop>
+				<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.redis.hibernate4.SingletonRedisRegionFactory
 				</prop>
+                <prop key="hibernate.cache.region_prefix">hibernate</prop>
 				<prop key="hibernate.cache.use_query_cache">true</prop>
 				<prop key="hibernate.cache.use_second_level_cache">true</prop>
 				<prop key="hibernate.generate_statistics">true</prop>

+ 26 - 0
src/main/resources/spring/hibernate-redis.properties

@@ -0,0 +1,26 @@
+#
+# Copyright (c) 2017. Sunghyouk Bae <sunghyouk.bae@gmail.com>
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+redisson-config=classpath:${profile}/redisson.yaml
+#
+# Cache Expiry settings
+# 'hibernate' is second cache prefix
+# 'common', 'account' is actual region name
+#
+# default = 120 seconds (2 minutes) (see RedisCacheUtil.DEFAULT_EXPIRY_IN_SECONDS)
+#
+redis.expiryInSeconds.default=120
+redis.expiryInSeconds.hibernate.common=0
+redis.expiryInSeconds.hibernate.com.uas.platform.b2c.model.User=10