From 7c886cd20426425de5c2b40769689a9083847452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Thu, 17 Aug 2017 19:01:28 +0800 Subject: [PATCH 01/50] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=BA=90=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E7=BA=BF=E7=A8=8B=E5=86=85=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ibase4j/core/aspect/DataSourceAspect.java | 12 +++++++++++- .../main/java/org/ibase4j/core/base/BaseService.java | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/DataSourceAspect.java b/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/DataSourceAspect.java index 10bd1b75..a4b8efbd 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/DataSourceAspect.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/DataSourceAspect.java @@ -9,6 +9,7 @@ import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.core.NamedThreadLocal; /** * 切换数据源(不同方法调用不同数据源) @@ -20,8 +21,9 @@ @EnableAspectJAutoProxy(proxyTargetClass = true) public class DataSourceAspect { private final Logger logger = LogManager.getLogger(); + private final ThreadLocal threadLocal = new NamedThreadLocal("DataSourceAspect"); - @Pointcut("execution(* org.ibase4j..*Service.*(..))") + @Pointcut("execution(* org.ibase4j.service..*.*(..))") public void aspect() { } @@ -33,12 +35,20 @@ public void before(JoinPoint point) { String className = point.getTarget().getClass().getName(); String method = point.getSignature().getName(); logger.info(className + "." + method + "(" + StringUtils.join(point.getArgs(), ",") + ")"); + String dataSourceType = threadLocal.get(); + if (StringUtils.isNotBlank(threadLocal.get())) { + logger.info(dataSourceType); + HandleDataSource.putDataSource(dataSourceType); + threadLocal.set(dataSourceType); + return; + } try { L: for (String key : ChooseDataSource.METHODTYPE.keySet()) { for (String type : ChooseDataSource.METHODTYPE.get(key)) { if (method.startsWith(type)) { logger.info(key); HandleDataSource.putDataSource(key); + threadLocal.set(key); break L; } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java index 95da04fb..ed20c99d 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java @@ -389,6 +389,12 @@ protected

Page

query(Map params, Class

cls) { return getPage(page, cls); } + public Page> queryMap(Map params) { + Page page = getPage(params); + page.setRecords(mapper.selectIdPage(page, params)); + return getPageMap(page); + } + public T selectOne(T entity) { return mapper.selectOne(entity); } From 36c511e2101bcb2d41414ab66800024d1a8722bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Thu, 17 Aug 2017 19:10:46 +0800 Subject: [PATCH 02/50] =?UTF-8?q?=E5=B7=B2=E7=9F=A5bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Biz-Web/src/main/webapp/WEB-INF/web.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/iBase4J-Biz-Web/src/main/webapp/WEB-INF/web.xml b/iBase4J-Biz-Web/src/main/webapp/WEB-INF/web.xml index 32c3b198..b913e642 100644 --- a/iBase4J-Biz-Web/src/main/webapp/WEB-INF/web.xml +++ b/iBase4J-Biz-Web/src/main/webapp/WEB-INF/web.xml @@ -29,14 +29,6 @@ encodingFilter /* - - localeFilter - org.ibase4j.core.filter.LocaleFilter - - - localeFilter - /* - csrfFilter org.ibase4j.core.filter.CsrfFilter From 21628f41f300235ceb9dffe2c54d8992e162a36c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Thu, 17 Aug 2017 19:16:17 +0800 Subject: [PATCH 03/50] readme --- readme.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 0bc7210a..e755c614 100644 --- a/readme.md +++ b/readme.md @@ -51,10 +51,11 @@ iBase4J使用 [Apache License 2.0][] 协议. ## 分支说明 [NoSplit][] 未拆分版本. -[idubbo][] 原始dubbo接口版本,支持事务不支持分布式事务。 +[idubbo][] 原始dubbo接口版本,支持事务不支持分布式事务; +[springBoot][] 去xml版本; master是最新版本,统一dubbo服务接口,一个模块只对外提供一个接口。 - springBoot、docker待开发。 + docker待开发。 ## 加入QQ群[538240548](http://shang.qq.com/wpa/qunwpa?idkey=b0fb32618d54e6a7f3cb718cd469b2952c8a968b1ef6f17fd68c83338ae4bce3) 交流技术问题,下载项目文档和一键启动依赖服务工具。 @@ -75,4 +76,5 @@ iBase4J is released under version 2.0 of the [Apache License][]. [Apache License 2.0]: http://www.apache.org/licenses/LICENSE-2.0 [NoSplit]: http://git.oschina.net/iBase4J/iBase4J/tree/NoSplit [idubbo]: http://git.oschina.net/iBase4J/iBase4J/tree/idubbo +[springBoot]: https://gitee.com/iBase4J/iBase4J/tree/springBoot [Apache License]: http://www.apache.org/licenses/LICENSE-2.0 \ No newline at end of file From 4edbee571a73a9f43b931a57ee4b8639dc32e524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Thu, 17 Aug 2017 19:17:26 +0800 Subject: [PATCH 04/50] readme --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index e755c614..f7515145 100644 --- a/readme.md +++ b/readme.md @@ -52,6 +52,7 @@ iBase4J使用 [Apache License 2.0][] 协议. [NoSplit][] 未拆分版本. [idubbo][] 原始dubbo接口版本,支持事务不支持分布式事务; + [springBoot][] 去xml版本; master是最新版本,统一dubbo服务接口,一个模块只对外提供一个接口。 From 36999977e8550df02b72647dbf9d64ddf8dbe6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Sat, 19 Aug 2017 20:32:46 +0800 Subject: [PATCH 05/50] =?UTF-8?q?=E7=BC=93=E5=AD=98=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9AService=E4=BD=BF=E7=94=A8redisson=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BC=93=E5=AD=98=EF=BC=9BWeb=E4=BD=BF?= =?UTF-8?q?=E7=94=A8Spring-data-redis=E7=AE=A1=E7=90=86=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Biz-Service/pom.xml | 6 + .../src/main/resources/Spring-config.xml | 2 +- iBase4J-Biz-Web/pom.xml | 11 + .../src/main/resources/Spring-config.xml | 1 - iBase4J-Common/pom.xml | 16 + .../ibase4j/core/config/RedisCacheConfig.java | 2 +- .../core/listener/SessionListener.java | 11 +- .../core/support/cache/CacheManager.java | 14 +- .../core/support/cache/RedisHelper.java | 130 ------ .../core/support/cache/RedissonHelper.java | 161 ++++++++ .../cache/redisson/SpringCacheManager.java | 375 ++++++++++++++++++ .../core/support/cache/shiro/RedisCache.java | 189 +++++---- .../cache/shiro/RedisCacheManager.java | 83 ++-- .../ibase4j/core/support/pay/WxPayment.java | 2 +- .../java/org/ibase4j/core/util/CacheUtil.java | 14 +- .../java/org/ibase4j/core/util/HttpUtil.java | 4 +- .../src/main/resources/spring/redis.xml | 55 --- .../src/main/resources/spring/redisson.xml | 29 ++ .../src/main/resources/spring/session.xml | 31 ++ iBase4J-SYS-Service/pom.xml | 6 + .../src/main/resources/Spring-config.xml | 2 +- iBase4J-SYS-Web/pom.xml | 11 + .../src/main/resources/Spring-config.xml | 1 - pom.xml | 30 +- 24 files changed, 819 insertions(+), 367 deletions(-) delete mode 100644 iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java create mode 100644 iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedissonHelper.java create mode 100644 iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/SpringCacheManager.java delete mode 100644 iBase4J-Common/src/main/resources/spring/redis.xml create mode 100644 iBase4J-Common/src/main/resources/spring/redisson.xml diff --git a/iBase4J-Biz-Service/pom.xml b/iBase4J-Biz-Service/pom.xml index c6ce40ac..832c75e0 100644 --- a/iBase4J-Biz-Service/pom.xml +++ b/iBase4J-Biz-Service/pom.xml @@ -98,6 +98,12 @@ aspectjweaver ${aspectj.version} + + + org.redisson + redisson + ${redisson.version} + com.belerweb diff --git a/iBase4J-Biz-Service/src/main/resources/Spring-config.xml b/iBase4J-Biz-Service/src/main/resources/Spring-config.xml index c725bbdc..b069810d 100644 --- a/iBase4J-Biz-Service/src/main/resources/Spring-config.xml +++ b/iBase4J-Biz-Service/src/main/resources/Spring-config.xml @@ -36,7 +36,7 @@ - + \ No newline at end of file diff --git a/iBase4J-Biz-Web/pom.xml b/iBase4J-Biz-Web/pom.xml index 6a0ef13a..0f726253 100644 --- a/iBase4J-Biz-Web/pom.xml +++ b/iBase4J-Biz-Web/pom.xml @@ -58,6 +58,17 @@ spring-session ${spring-session.version} + + org.springframework.data + spring-data-redis + ${spring-data-redis.version} + + + + redis.clients + jedis + ${jedis.version} + org.apache.shiro diff --git a/iBase4J-Biz-Web/src/main/resources/Spring-config.xml b/iBase4J-Biz-Web/src/main/resources/Spring-config.xml index 7b0a8d83..c27bc233 100644 --- a/iBase4J-Biz-Web/src/main/resources/Spring-config.xml +++ b/iBase4J-Biz-Web/src/main/resources/Spring-config.xml @@ -39,7 +39,6 @@ - \ No newline at end of file diff --git a/iBase4J-Common/pom.xml b/iBase4J-Common/pom.xml index 9ef5d47b..ae3a4596 100644 --- a/iBase4J-Common/pom.xml +++ b/iBase4J-Common/pom.xml @@ -75,12 +75,28 @@ spring-oxm ${spring.version} + + org.springframework.data + spring-data-redis + ${spring-data-redis.version} + org.aspectj aspectjrt ${aspectj.version} + + + redis.clients + jedis + ${jedis.version} + + + org.redisson + redisson + ${redisson.version} + org.apache.shiro diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/config/RedisCacheConfig.java b/iBase4J-Common/src/main/java/org/ibase4j/core/config/RedisCacheConfig.java index edddb1d9..a9f32c1e 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/config/RedisCacheConfig.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/config/RedisCacheConfig.java @@ -34,7 +34,7 @@ public KeyGenerator keyGenerator() { return new KeyGenerator() { /** 重写生成key方法 */ public Object generate(Object o, Method method, Object... objects) { - StringBuilder sb = new StringBuilder(Constants.CACHE_NAMESPACE); + StringBuilder sb = new StringBuilder(Constants.CACHE_NAMESPACE + "M:"); CacheConfig cacheConfig = o.getClass().getAnnotation(CacheConfig.class); Cacheable cacheable = method.getAnnotation(Cacheable.class); CachePut cachePut = method.getAnnotation(CachePut.class); diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java b/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java index 7902a443..84b05a59 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java @@ -7,8 +7,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.ibase4j.core.Constants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; +import org.ibase4j.core.util.CacheUtil; /** * 会话监听器 @@ -19,8 +18,6 @@ public class SessionListener implements HttpSessionListener { private Logger logger = LogManager.getLogger(SessionListener.class); - @Autowired - RedisTemplate redisTemplate; /* * (non-Javadoc) * @@ -32,7 +29,7 @@ public void sessionCreated(HttpSessionEvent event) { HttpSession session = event.getSession(); session.setAttribute(Constants.WEBTHEME, "default"); logger.info("创建了一个Session连接:[" + session.getId() + "]"); - redisTemplate.opsForSet().add(Constants.ALLUSER_NUMBER, session.getId()); + CacheUtil.getCache().sadd(Constants.ALLUSER_NUMBER, session.getId()); } /* @@ -48,11 +45,11 @@ public void sessionDestroyed(HttpSessionEvent event) { logger.info("销毁了一个Session连接:[" + session.getId() + "]"); } session.removeAttribute(Constants.CURRENT_USER); - redisTemplate.opsForSet().remove(Constants.ALLUSER_NUMBER, session.getId()); + CacheUtil.getCache().sdel(Constants.ALLUSER_NUMBER, session.getId()); } /** 获取在线用户数量 */ public Integer getAllUserNumber() { - return redisTemplate.opsForSet().size(Constants.ALLUSER_NUMBER).intValue(); + return CacheUtil.getCache().sall(Constants.ALLUSER_NUMBER).size(); } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java index 92fd1246..429f9c90 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java @@ -32,11 +32,17 @@ public interface CacheManager { void unlock(String key); - void hset(String key, String field, String value); + void hset(String key, Serializable field, Serializable value); - Object hget(String key, String field); + Object hget(String key, Serializable field); - void hdel(String key, String field); + void hdel(String key, Serializable field); - boolean setnx(String key, Serializable value); + boolean setnx(String key, long value); + + void sadd(String key, Serializable value); + + Set sall(String key); + + boolean sdel(String key, Serializable value); } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java deleted file mode 100644 index ac9994ad..00000000 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.ibase4j.core.support.cache; - -import java.io.Serializable; -import java.util.Date; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import org.ibase4j.core.util.InstanceUtil; -import org.ibase4j.core.util.PropertiesUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; - -/** - * Redis缓存辅助类 - * - * @author ShenHuaJie - * @version 2016年4月2日 下午4:17:22 - */ -public final class RedisHelper implements CacheManager { - @Autowired - private RedisTemplate redisTemplate; - private Integer EXPIRE = PropertiesUtil.getInt("redis.expiration"); - - public final Object get(final String key) { - expire(key, EXPIRE); - return redisTemplate.boundValueOps(key).get(); - } - - public final Set getAll(final String pattern) { - Set values = InstanceUtil.newHashSet(); - Set keys = redisTemplate.keys(pattern); - for (Serializable key : keys) { - expire(key.toString(), EXPIRE); - values.add(redisTemplate.opsForValue().get(key)); - } - return values; - } - - public final void set(final String key, final Serializable value, int seconds) { - redisTemplate.boundValueOps(key).set(value); - expire(key, seconds); - } - - public final void set(final String key, final Serializable value) { - redisTemplate.boundValueOps(key).set(value); - expire(key, EXPIRE); - } - - public final Boolean exists(final String key) { - return redisTemplate.hasKey(key); - } - - public final void del(final String key) { - redisTemplate.delete(key); - } - - public final void delAll(final String pattern) { - redisTemplate.delete(redisTemplate.keys(pattern)); - } - - public final String type(final String key) { - expire(key, EXPIRE); - return redisTemplate.type(key).getClass().getName(); - } - - /** - * 在某段时间后失效 - * - * @return - */ - public final Boolean expire(final String key, final int seconds) { - return redisTemplate.expire(key, seconds, TimeUnit.SECONDS); - } - - /** - * 在某个时间点失效 - * - * @param key - * @param unixTime - * @return - */ - public final Boolean expireAt(final String key, final long unixTime) { - return redisTemplate.expireAt(key, new Date(unixTime)); - } - - public final Long ttl(final String key) { - return redisTemplate.getExpire(key, TimeUnit.SECONDS); - } - - public final void setrange(final String key, final long offset, final String value) { - redisTemplate.boundValueOps(key).set(value, offset); - expire(key, EXPIRE); - } - - public final String getrange(final String key, final long startOffset, final long endOffset) { - expire(key, EXPIRE); - return redisTemplate.boundValueOps(key).get(startOffset, endOffset); - } - - public final Object getSet(final String key, final Serializable value) { - expire(key, EXPIRE); - return redisTemplate.boundValueOps(key).getAndSet(value); - } - - public boolean setnx(String key, Serializable value) { - return redisTemplate.boundValueOps(key).setIfAbsent(value); - } - - public boolean lock(String key) { - return false; - } - - public void unlock(String key) { - del(key); - } - - public void hset(String key, String field, String value) { - redisTemplate.boundHashOps(key).put(field, value); - } - - public Object hget(String key, String field) { - return redisTemplate.boundHashOps(key).get(field); - } - - public void hdel(String key, String field) { - redisTemplate.boundHashOps(key).delete(field); - } - - // 未完,待续... -} diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedissonHelper.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedissonHelper.java new file mode 100644 index 00000000..4d782acf --- /dev/null +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedissonHelper.java @@ -0,0 +1,161 @@ +package org.ibase4j.core.support.cache; + +import java.io.Serializable; +import java.util.Date; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.ibase4j.core.util.CacheUtil; +import org.ibase4j.core.util.InstanceUtil; +import org.ibase4j.core.util.PropertiesUtil; +import org.redisson.api.RBucket; +import org.redisson.api.RType; +import org.redisson.api.RedissonClient; + +/** + * Redis缓存辅助类 + */ +public class RedissonHelper implements CacheManager { + private RedissonClient redissonClient; + private final Integer EXPIRE = PropertiesUtil.getInt("redis.expiration"); + + public void setRedissonClient(RedissonClient redissonClient) { + this.redissonClient = redissonClient; + CacheUtil.setCacheManager(this); + } + + private RBucket getRedisBucket(String key) { + return redissonClient.getBucket(key); + } + + public final Object get(final String key) { + RBucket temp = getRedisBucket(key); + expire(temp, EXPIRE); + return temp.get(); + } + + public final void set(final String key, final Serializable value) { + RBucket temp = getRedisBucket(key); + temp.set(value); + expire(temp, EXPIRE); + } + + public final void set(final String key, final Serializable value, int seconds) { + RBucket temp = getRedisBucket(key); + temp.set(value); + expire(temp, seconds); + } + + public final void multiSet(final Map temps) { + redissonClient.getBuckets().set(temps); + } + + public final Boolean exists(final String key) { + RBucket temp = getRedisBucket(key); + return temp.isExists(); + } + + public final void del(final String key) { + redissonClient.getKeys().delete(key); + } + + public final void delAll(final String pattern) { + redissonClient.getKeys().deleteByPattern(pattern); + } + + public final String type(final String key) { + RType type = redissonClient.getKeys().getType(key); + if (type == null) { + return null; + } + return type.getClass().getName(); + } + + /** + * 在某段时间后失效 + * + * @return + */ + private final void expire(final RBucket bucket, final int seconds) { + bucket.expire(seconds, TimeUnit.SECONDS); + } + + /** + * 在某个时间点失效 + * + * @param key + * @param unixTime + * @return + */ + public final Boolean expireAt(final String key, final long unixTime) { + return redissonClient.getBucket(key).expireAt(new Date(unixTime)); + } + + public final Long ttl(final String key) { + RBucket rBucket = getRedisBucket(key); + return rBucket.remainTimeToLive(); + } + + public final Object getSet(final String key, final Serializable value) { + RBucket rBucket = getRedisBucket(key); + return rBucket.getAndSet(value); + } + + public Set getAll(String pattern) { + Set set = InstanceUtil.newHashSet(); + Iterable keys = redissonClient.getKeys().getKeysByPattern(pattern); + for (Iterator iterator = keys.iterator(); iterator.hasNext();) { + String key = iterator.next(); + set.add(getRedisBucket(key).get()); + } + return set; + } + + public Boolean expire(String key, int seconds) { + RBucket bucket = getRedisBucket(key); + expire(bucket, seconds); + return true; + } + + public void hset(String key, Serializable field, Serializable value) { + redissonClient.getMap(key).put(field, value); + } + + public Object hget(String key, Serializable field) { + return redissonClient.getMap(key).get(field); + } + + public void hdel(String key, Serializable field) { + redissonClient.getMap(key).remove(field); + } + + public void sadd(String key, Serializable value) { + redissonClient.getSet(key).add(value); + } + + public Set sall(String key) { + return redissonClient.getSet(key).readAll(); + } + + public boolean sdel(String key, Serializable value) { + return redissonClient.getSet(key).remove(value); + } + + public boolean lock(String key) { + return redissonClient.getLock(key).tryLock(); + } + + public void unlock(String key) { + redissonClient.getLock(key).unlock(); + } + + public boolean setnx(String key, long value) { + try { + return redissonClient.getLock(key).tryLock(value, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + return false; + } + } +} \ No newline at end of file diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/SpringCacheManager.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/SpringCacheManager.java new file mode 100644 index 00000000..88bebc2d --- /dev/null +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/SpringCacheManager.java @@ -0,0 +1,375 @@ +package org.ibase4j.core.support.cache.redisson; + +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; + +import org.redisson.api.RMap; +import org.redisson.api.RMapCache; +import org.redisson.api.RedissonClient; +import org.redisson.client.codec.Codec; +import org.redisson.spring.cache.CacheConfig; +import org.redisson.spring.cache.RedissonCache; +import org.springframework.beans.factory.BeanDefinitionStoreException; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.context.ResourceLoaderAware; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; + +public class SpringCacheManager implements CacheManager, ResourceLoaderAware, InitializingBean { + private ResourceLoader resourceLoader; + private boolean allowNullValues; + private Codec codec; + private RedissonClient redisson; + private Map configMap = new LinkedHashMap(); + private Map patternMap = new LinkedHashMap(); + private String configLocation; + private String regExpConfigLocation; + + public SpringCacheManager() { + } + + /** + * Creates CacheManager supplied by Redisson instance and Cache config + * mapped by Cache name + * + * @param redisson + * object + * @param config + * object + */ + public SpringCacheManager(RedissonClient redisson, Map config) { + this(redisson, config, null, null); + } + + /** + * Creates CacheManager supplied by Redisson instance, Codec instance and + * Cache config mapped by Cache name. + *

+ * Each Cache instance share one Codec instance. + * + * @param redisson + * object + * @param config + * object + * @param codec + * object + */ + public SpringCacheManager(RedissonClient redisson, Map config, Codec codec) { + this(redisson, config, null, codec); + } + + /** + * Creates CacheManager supplied by Redisson instance and Cache config + * mapped by Cache name and RegExp config mapped by pattern. + * + * @param redisson + * object + * @param config + * object + * @param patternConfig + */ + public SpringCacheManager(RedissonClient redisson, Map config, + Map patternConfig) { + this(redisson, config, patternConfig, null); + } + + /** + * Creates CacheManager supplied by Redisson instance, Codec instance, Cache + * config mapped by Cache name and RegExp config mapped by pattern. + *

+ * Each Cache instance share one Codec instance. + * + * @param redisson + * object + * @param config + * object + * @param patternConfig + * @param codec + * object + */ + public SpringCacheManager(RedissonClient redisson, Map config, + Map patternConfig, Codec codec) { + this.redisson = redisson; + if (config != null) { + this.configMap.putAll(config); + } + if (patternConfig != null) { + this.patternMap.putAll(patternConfig); + } + this.codec = codec; + } + + /** + * Creates CacheManager supplied by Redisson instance and Cache config + * mapped by Cache name. + *

+ * Loads the config file from the class path, interpreting plain paths as + * class path resource names that include the package path (e.g. + * "mypackage/myresource.txt"). + * + * @param redisson + * object + * @param configLocation + * path + */ + public SpringCacheManager(RedissonClient redisson, String configLocation) { + this(redisson, configLocation, null, null); + } + + /** + * Creates CacheManager supplied by Redisson instance, Cache config location + * path and RegExp pattern config location path. + *

+ * Loads the config file from the class path, interpreting plain paths as + * class path resource names that include the package path (e.g. + * "mypackage/myresource.txt"). + * + * @param redisson + * object + * @param configLocation + * path + * @param regExpConfigLocation + */ + public SpringCacheManager(RedissonClient redisson, String configLocation, String regExpConfigLocation) { + this(redisson, configLocation, regExpConfigLocation, null); + } + + /** + * Creates CacheManager supplied by Redisson instance, Codec instance and + * Config location path. + *

+ * Each Cache instance share one Codec instance. + *

+ * Loads the config file from the class path, interpreting plain paths as + * class path resource names that include the package path (e.g. + * "mypackage/myresource.txt"). + * + * @param redisson + * object + * @param configLocation + * path + * @param codec + * object + */ + public SpringCacheManager(RedissonClient redisson, String configLocation, Codec codec) { + this(redisson, configLocation, null, codec); + } + + /** + * Creates CacheManager supplied by Redisson instance, Codec instance, + * Config location path and RegExp config location path. + *

+ * Each Cache instance share one Codec instance. + *

+ * Loads the config file from the class path, interpreting plain paths as + * class path resource names that include the package path (e.g. + * "mypackage/myresource.txt"). + * + * @param redisson + * object + * @param configLocation + * path + * @param regExpConfigLocation + * @param codec + * object + */ + public SpringCacheManager(RedissonClient redisson, String configLocation, String regExpConfigLocation, + Codec codec) { + this.allowNullValues = true; + this.redisson = redisson; + this.configLocation = configLocation; + this.regExpConfigLocation = regExpConfigLocation; + this.codec = codec; + } + + /** + * Set cache config location + * + * @param configLocation + * object + */ + public void setConfigLocation(String configLocation) { + this.configLocation = configLocation; + } + + /** + * Set RegExp pattern config location + * + * @param regExpConfigLocation + * object + */ + public void setRegExpConfigLocation(String regExpConfigLocation) { + this.regExpConfigLocation = regExpConfigLocation; + } + + /** + * Set cache config mapped by cache name + * + * @param config + * object + */ + public void setConfig(Map config) { + this.configMap.clear(); + if (config == null) { + return; + } + this.configMap.putAll(config); + } + + /** + * Set cache regexp config mapped by pattern + * + * @param config + * object + */ + public void setPatternConfig(Map config) { + this.patternMap.clear(); + if (config == null) { + return; + } + this.patternMap.putAll(config); + } + + /** + * Set Redisson instance + * + * @param redisson + * instance + */ + public void setRedisson(RedissonClient redisson) { + this.redisson = redisson; + } + + /** + * Set Codec instance shared between all Cache instances + * + * @param codec + * object + */ + public void setCodec(Codec codec) { + this.codec = codec; + } + + public void setAllowNullValues(boolean allowNullValues) { + this.allowNullValues = allowNullValues; + } + + @Override + public Cache getCache(String name) { + CacheConfig config = configMap.get(name); + final String cacheName; + if (config == null) { + Pattern pattern = testRegExp(name); + if (pattern == null) { + config = new CacheConfig(); + configMap.put(name, config); + + RMap map = createMap(name); + return new RedissonCache(map, this.allowNullValues); + } else { + config = patternMap.get(pattern); + cacheName = pattern.pattern(); + } + } else { + cacheName = name; + } + if (config.getMaxIdleTime() == 0 && config.getTTL() == 0) { + RMap map = createMap(cacheName); + return new RedissonCache(map, this.allowNullValues); + } + RMapCache map = createMapCache(cacheName); + return new RedissonCache(map, config, this.allowNullValues); + } + + private Pattern testRegExp(String name) { + for (String regex : patternMap.keySet()) { + Pattern pattern = Pattern.compile(regex); + if (pattern.matcher(name).matches()) { + return pattern; + } + } + return null; + } + + private RMap createMap(String name) { + if (codec != null) { + return redisson.getMap(name, codec); + } + return redisson.getMap(name); + } + + private RMapCache createMapCache(String name) { + if (codec != null) { + return redisson.getMapCache(name, codec); + } + return redisson.getMapCache(name); + } + + @Override + public Collection getCacheNames() { + Set names = Collections.emptySet(); + names.addAll(getConfigNames()); + names.addAll(getPatternNames()); + return Collections.unmodifiableSet(names); + } + + public Collection getConfigNames() { + return Collections.unmodifiableSet(configMap.keySet()); + } + + public Collection getPatternNames() { + Set patterns = Collections.emptySet(); + for (String k : patternMap.keySet()) { + patterns.add(k); + } + return Collections.unmodifiableSet(patterns); + } + + @Override + public void setResourceLoader(ResourceLoader resourceLoader) { + this.resourceLoader = resourceLoader; + } + + @Override + public void afterPropertiesSet() throws Exception { + if (configLocation != null) { + Resource resource = resourceLoader.getResource(configLocation); + try { + setConfig(CacheConfig.fromJSON(resource.getInputStream())); + } catch (IOException e) { + // try to read yaml + try { + setConfig(CacheConfig.fromYAML(resource.getInputStream())); + } catch (IOException e1) { + throw new BeanDefinitionStoreException( + "Could not parse cache configuration at [" + configLocation + "]", e1); + } + } + } + if (regExpConfigLocation != null) { + Resource resource = resourceLoader.getResource(regExpConfigLocation); + Map confs; + try { + confs = CacheConfig.fromJSON(resource.getInputStream()); + } catch (IOException e) { + // try to read yaml + try { + confs = CacheConfig.fromYAML(resource.getInputStream()); + } catch (IOException e1) { + throw new BeanDefinitionStoreException( + "Could not parse cache configuration at [" + configLocation + "]", e1); + } + } + for (Map.Entry conf : confs.entrySet()) { + patternMap.put(conf.getKey(), conf.getValue()); + } + } + } +} diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCache.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCache.java index 6a39f046..400b9e11 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCache.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCache.java @@ -3,7 +3,6 @@ */ package org.ibase4j.core.support.cache.shiro; -import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -16,117 +15,117 @@ import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; import org.apache.shiro.util.CollectionUtils; -import org.ibase4j.core.util.CacheUtil; +import org.springframework.data.redis.core.RedisTemplate; /** * * @author ShenHuaJie * @version 2017年3月24日 下午8:54:08 */ +@SuppressWarnings({ "unchecked", "rawtypes" }) public class RedisCache implements Cache { - private final Logger logger = LogManager.getLogger(); + private final Logger logger = LogManager.getLogger(); + private RedisTemplate redisTemplate; - /** - * The Redis key prefix for the sessions - */ - private String keyPrefix = "shiro_redis_session:"; + /** + * The Redis key prefix for the sessions + */ + private String keyPrefix = "shiro_redis_session:"; - /** - * Returns the Redis session keys - * prefix. - * @return The prefix - */ - public String getKeyPrefix() { - return keyPrefix; - } + /** + * Sets the Redis sessions key prefix. + * + * @param keyPrefix + * The prefix + */ + public void setKeyPrefix(String keyPrefix) { + this.keyPrefix = keyPrefix; + } - /** - * Sets the Redis sessions key - * prefix. - * @param keyPrefix The prefix - */ - public void setKeyPrefix(String keyPrefix) { - this.keyPrefix = keyPrefix; - } + /** + * @param redisTemplate + */ + public void setRedisTemplate(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } - /** - * Constructs a cache instance with the specified - * Redis manager and using a custom key prefix. - * @param prefix The Redis key prefix - */ - public RedisCache(String prefix) { - // set the prefix - this.keyPrefix = prefix; - } + /** + * Constructs a cache instance with the specified Redis manager and using a + * custom key prefix. + * + * @param prefix + * The Redis key prefix + */ + public RedisCache(String prefix, RedisTemplate redisTemplate) { + this.keyPrefix = prefix; + this.redisTemplate = redisTemplate; + } - @Override - public V get(K key) throws CacheException { - logger.debug("根据key从Redis中获取对象 key [" + key + "]"); - @SuppressWarnings("unchecked") - V value = (V)CacheUtil.getCache().get(getKey(key)); - return value; - } + @Override + public V get(K key) throws CacheException { + logger.debug("根据key从Redis中获取对象 key [" + key + "]"); + V value = (V) redisTemplate.boundValueOps(getKey(key)).get(); + return value; + } - @Override - public V put(K key, V value) throws CacheException { - logger.debug("根据key从存储 key [" + key + "]"); - CacheUtil.getCache().set(getKey(key), (Serializable)value); - return value; - } + @Override + public V put(K key, V value) throws CacheException { + logger.debug("根据key从存储 key [" + key + "]"); + redisTemplate.boundValueOps(getKey(key)).set(value); + return value; + } - @Override - public V remove(K key) throws CacheException { - logger.debug("从redis中删除 key [" + key + "]"); - V previous = get(key); - CacheUtil.getCache().del(getKey(key)); - return previous; - } + @Override + public V remove(K key) throws CacheException { + logger.debug("从redis中删除 key [" + key + "]"); + V previous = get(key); + redisTemplate.delete(getKey(key)); + return previous; + } - @Override - public void clear() throws CacheException { - logger.debug("从redis中删除所有元素"); - CacheUtil.getCache().delAll(this.keyPrefix + "*"); - } + @Override + public void clear() throws CacheException { + logger.debug("从redis中删除所有元素"); + redisTemplate.delete(redisTemplate.keys(this.keyPrefix + "*")); + } - @Override - public int size() { - return CacheUtil.getCache().getAll(this.keyPrefix + "*").size(); - } + @Override + public int size() { + return redisTemplate.keys(this.keyPrefix + "*").size(); + } - @SuppressWarnings("unchecked") - @Override - public Set keys() { - Set keys = CacheUtil.getCache().getAll(this.keyPrefix + "*"); - if (CollectionUtils.isEmpty(keys)) { - return Collections.emptySet(); - } else { - Set newKeys = new HashSet(); - for (Object key : keys) { - newKeys.add((K)key); - } - return newKeys; - } - } + @Override + public Set keys() { + Set keys = redisTemplate.keys(this.keyPrefix + "*"); + if (CollectionUtils.isEmpty(keys)) { + return Collections.emptySet(); + } else { + Set newKeys = new HashSet(); + for (Object key : keys) { + newKeys.add((K) key); + } + return newKeys; + } + } - @Override - public Collection values() { - Set keys = CacheUtil.getCache().getAll(this.keyPrefix + "*"); - if (!CollectionUtils.isEmpty(keys)) { - List values = new ArrayList(keys.size()); - for (Object key : keys) { - @SuppressWarnings("unchecked") - V value = get((K)key); - if (value != null) { - values.add(value); - } - } - return Collections.unmodifiableList(values); - } else { - return Collections.emptyList(); - } - } + @Override + public Collection values() { + Set keys = redisTemplate.keys(this.keyPrefix + "*"); + if (!CollectionUtils.isEmpty(keys)) { + List values = new ArrayList(keys.size()); + for (Object key : keys) { + V value = get((K) key); + if (value != null) { + values.add(value); + } + } + return Collections.unmodifiableList(values); + } else { + return Collections.emptyList(); + } + } - private String getKey(K key) { - return this.keyPrefix + key; - } + private String getKey(K key) { + return this.keyPrefix + key; + } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCacheManager.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCacheManager.java index b1098a63..12ce2877 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCacheManager.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCacheManager.java @@ -6,63 +6,68 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import javax.annotation.Resource; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; import org.apache.shiro.cache.CacheManager; import org.ibase4j.core.Constants; +import org.springframework.data.redis.core.RedisTemplate; /** * * @author ShenHuaJie * @version 2017年3月24日 下午8:50:14 */ +@SuppressWarnings({ "rawtypes", "unchecked" }) public class RedisCacheManager implements CacheManager { - private final Logger logger = LogManager.getLogger(); - - // fast lookup by name map - @SuppressWarnings("rawtypes") - private final ConcurrentMap caches = new ConcurrentHashMap(); - /** - * The Redis key prefix for caches - */ - private String keyPrefix = Constants.CACHE_NAMESPACE + "shiro_redis_cache:"; + private final Logger logger = LogManager.getLogger(); + @Resource + private RedisTemplate redisTemplate; - /** - * Returns the Redis session keys - * prefix. - * @return The prefix - */ - public String getKeyPrefix() { - return keyPrefix; - } + // fast lookup by name map + private final ConcurrentMap caches = new ConcurrentHashMap(); + /** + * The Redis key prefix for caches + */ + private String keyPrefix = Constants.CACHE_NAMESPACE + "shiro_redis_cache:"; - /** - * Sets the Redis sessions key - * prefix. - * @param keyPrefix The prefix - */ - public void setKeyPrefix(String keyPrefix) { - this.keyPrefix = keyPrefix; - } + /** + * Sets the Redis sessions key prefix. + * + * @param keyPrefix + * The prefix + */ + public void setKeyPrefix(String keyPrefix) { + this.keyPrefix = keyPrefix; + } - /* (non-Javadoc) - * @see org.apache.shiro.cache.CacheManager#getCache(java.lang.String) */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public Cache getCache(String name) throws CacheException { - logger.debug("获取名称为: " + name + " 的RedisCache实例"); + /** + * @param redisTemplate + */ + public void setRedisTemplate(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } - Cache c = caches.get(name); + /* + * (non-Javadoc) + * + * @see org.apache.shiro.cache.CacheManager#getCache(java.lang.String) + */ + public Cache getCache(String name) throws CacheException { + logger.debug("获取名称为: " + name + " 的RedisCache实例"); - if (c == null) { - // create a new cache instance - c = new RedisCache(keyPrefix); + Cache c = caches.get(name); - // add it to the cache collection - caches.put(name, c); - } - return c; - } + if (c == null) { + // create a new cache instance + c = new RedisCache(keyPrefix, redisTemplate); + // add it to the cache collection + caches.put(name, c); + } + return c; + } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/pay/WxPayment.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/pay/WxPayment.java index ee329b38..1e7553d7 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/pay/WxPayment.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/pay/WxPayment.java @@ -201,7 +201,7 @@ public static String packageSign(Map params, boolean urlEncoder) * 编码错误 */ public static String urlEncode(String src) throws UnsupportedEncodingException { - return URLEncoder.encode(src, Charsets.UTF_8.name()).replace("+", "%20"); + return URLEncoder.encode(src, Charsets.toCharset("UTF-8").name()).replace("+", "%20"); } /** diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java b/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java index 3a46062b..f93dd279 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java @@ -4,8 +4,7 @@ import org.apache.logging.log4j.Logger; import org.ibase4j.core.Constants; import org.ibase4j.core.support.cache.CacheManager; -import org.ibase4j.core.support.cache.RedisHelper; -import org.springframework.context.annotation.Bean; +import org.ibase4j.core.support.cache.RedissonHelper; import org.springframework.context.annotation.Configuration; @Configuration @@ -13,18 +12,15 @@ public class CacheUtil { private static Logger logger = LogManager.getLogger(CacheUtil.class); private static CacheManager cacheManager; - @Bean - @Deprecated - public CacheManager setCache() { - cacheManager = getCache(); - return cacheManager; + public static void setCacheManager(CacheManager cacheManager) { + CacheUtil.cacheManager = cacheManager; } public static CacheManager getCache() { if (cacheManager == null) { synchronized (CacheUtil.class) { if (cacheManager == null) { - cacheManager = new RedisHelper(); + cacheManager = new RedissonHelper(); } } } @@ -37,7 +33,7 @@ public static boolean getLock(String key) { if (!getCache().exists(key)) { synchronized (CacheUtil.class) { if (!getCache().exists(key)) { - if (getCache().setnx(key, String.valueOf(System.currentTimeMillis()))) { + if (getCache().setnx(key, System.currentTimeMillis())) { return true; } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/util/HttpUtil.java b/iBase4J-Common/src/main/java/org/ibase4j/core/util/HttpUtil.java index 47f208db..18ce4a92 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/util/HttpUtil.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/util/HttpUtil.java @@ -120,11 +120,11 @@ public static String postSSL(String url, String data, String certPath, String ce conn.connect(); out = conn.getOutputStream(); - out.write(data.getBytes(Charsets.UTF_8)); + out.write(data.getBytes(Charsets.toCharset("UTF-8"))); out.flush(); inputStream = conn.getInputStream(); - reader = new BufferedReader(new InputStreamReader(inputStream, Charsets.UTF_8)); + reader = new BufferedReader(new InputStreamReader(inputStream, Charsets.toCharset("UTF-8"))); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { diff --git a/iBase4J-Common/src/main/resources/spring/redis.xml b/iBase4J-Common/src/main/resources/spring/redis.xml deleted file mode 100644 index 858ec384..00000000 --- a/iBase4J-Common/src/main/resources/spring/redis.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/iBase4J-Common/src/main/resources/spring/redisson.xml b/iBase4J-Common/src/main/resources/spring/redisson.xml new file mode 100644 index 00000000..cb299436 --- /dev/null +++ b/iBase4J-Common/src/main/resources/spring/redisson.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/iBase4J-Common/src/main/resources/spring/session.xml b/iBase4J-Common/src/main/resources/spring/session.xml index 653f96bb..90872bf3 100644 --- a/iBase4J-Common/src/main/resources/spring/session.xml +++ b/iBase4J-Common/src/main/resources/spring/session.xml @@ -1,10 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/iBase4J-SYS-Service/pom.xml b/iBase4J-SYS-Service/pom.xml index 61788bd1..dc3852e2 100644 --- a/iBase4J-SYS-Service/pom.xml +++ b/iBase4J-SYS-Service/pom.xml @@ -126,6 +126,12 @@ aspectjweaver ${aspectj.version} + + + org.redisson + redisson + ${redisson.version} + com.belerweb diff --git a/iBase4J-SYS-Service/src/main/resources/Spring-config.xml b/iBase4J-SYS-Service/src/main/resources/Spring-config.xml index 64126b77..daba44c4 100644 --- a/iBase4J-SYS-Service/src/main/resources/Spring-config.xml +++ b/iBase4J-SYS-Service/src/main/resources/Spring-config.xml @@ -37,7 +37,7 @@ - + diff --git a/iBase4J-SYS-Web/pom.xml b/iBase4J-SYS-Web/pom.xml index 1675186f..eb82ceb6 100644 --- a/iBase4J-SYS-Web/pom.xml +++ b/iBase4J-SYS-Web/pom.xml @@ -51,6 +51,17 @@ spring-session ${spring-session.version} + + org.springframework.data + spring-data-redis + ${spring-data-redis.version} + + + + redis.clients + jedis + ${jedis.version} + org.apache.shiro diff --git a/iBase4J-SYS-Web/src/main/resources/Spring-config.xml b/iBase4J-SYS-Web/src/main/resources/Spring-config.xml index d11030ff..09310094 100644 --- a/iBase4J-SYS-Web/src/main/resources/Spring-config.xml +++ b/iBase4J-SYS-Web/src/main/resources/Spring-config.xml @@ -37,7 +37,6 @@ - \ No newline at end of file diff --git a/pom.xml b/pom.xml index d94cf85b..b18d967d 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,7 @@ 1.2.36 0.3.1 + 3.5.0 3.9 2.6.12 1.2.6 @@ -90,32 +91,32 @@ commons-net commons-net - 3.4 + 3.6 org.apache.commons commons-lang3 - 3.4 + 3.6 commons-codec commons-codec - 1.9 + 1.10 - commons-digester - commons-digester - 2.0 + org.apache.commons + commons-digester3 + 3.2 commons-beanutils commons-beanutils - 1.9.2 + 1.9.3 commons-fileupload commons-fileupload - 1.3.1 + 1.3.3 commons-io @@ -159,17 +160,6 @@ spring-web ${spring.version} - - org.springframework.data - spring-data-redis - ${spring-data-redis.version} - - - - redis.clients - jedis - ${jedis.version} - com.alibaba @@ -214,7 +204,7 @@ log4j-slf4j-impl ${log4j.version} - + org.javassist javassist From c1b8c8884c23c25a63dec0805e7d724ac765c2aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Sat, 19 Aug 2017 21:37:54 +0800 Subject: [PATCH 06/50] =?UTF-8?q?=E7=BC=93=E5=AD=98=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9AService=E4=BD=BF=E7=94=A8redisson=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BC=93=E5=AD=98=EF=BC=9BWeb=E4=BD=BF?= =?UTF-8?q?=E7=94=A8Spring-data-redis=E7=AE=A1=E7=90=86=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ibase4j/core/aspect/DataSourceAspect.java | 66 ------------------- .../ibase4j/core/base/BaseProviderImpl.java | 16 +++++ .../dbcp}/ChooseDataSource.java | 2 +- .../dbcp}/HandleDataSource.java | 2 +- .../src/main/resources/spring/dataSource.xml | 4 +- .../src/main/resources/spring/session.xml | 10 +-- pom.xml | 4 +- 7 files changed, 24 insertions(+), 80 deletions(-) delete mode 100644 iBase4J-Common/src/main/java/org/ibase4j/core/aspect/DataSourceAspect.java rename iBase4J-Common/src/main/java/org/ibase4j/core/{aspect => support/dbcp}/ChooseDataSource.java (96%) rename iBase4J-Common/src/main/java/org/ibase4j/core/{aspect => support/dbcp}/HandleDataSource.java (91%) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/DataSourceAspect.java b/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/DataSourceAspect.java deleted file mode 100644 index a4b8efbd..00000000 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/DataSourceAspect.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.ibase4j.core.aspect; - -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.After; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.aspectj.lang.annotation.Pointcut; -import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.core.NamedThreadLocal; - -/** - * 切换数据源(不同方法调用不同数据源) - * - * @author ShenHuaJie - * @version 2016年5月20日 下午3:17:52 - */ -@Aspect -@EnableAspectJAutoProxy(proxyTargetClass = true) -public class DataSourceAspect { - private final Logger logger = LogManager.getLogger(); - private final ThreadLocal threadLocal = new NamedThreadLocal("DataSourceAspect"); - - @Pointcut("execution(* org.ibase4j.service..*.*(..))") - public void aspect() { - } - - /** - * 配置前置通知,使用在方法aspect()上注册的切入点 - */ - @Before("aspect()") - public void before(JoinPoint point) { - String className = point.getTarget().getClass().getName(); - String method = point.getSignature().getName(); - logger.info(className + "." + method + "(" + StringUtils.join(point.getArgs(), ",") + ")"); - String dataSourceType = threadLocal.get(); - if (StringUtils.isNotBlank(threadLocal.get())) { - logger.info(dataSourceType); - HandleDataSource.putDataSource(dataSourceType); - threadLocal.set(dataSourceType); - return; - } - try { - L: for (String key : ChooseDataSource.METHODTYPE.keySet()) { - for (String type : ChooseDataSource.METHODTYPE.get(key)) { - if (method.startsWith(type)) { - logger.info(key); - HandleDataSource.putDataSource(key); - threadLocal.set(key); - break L; - } - } - } - } catch (Exception e) { - logger.error(e); - HandleDataSource.putDataSource("write"); - } - } - - @After("aspect()") - public void after(JoinPoint point) { - HandleDataSource.clear(); - } -} diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java index cb0f4f95..0d034a0e 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java @@ -6,6 +6,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.ibase4j.core.Constants; +import org.ibase4j.core.support.dbcp.ChooseDataSource; +import org.ibase4j.core.support.dbcp.HandleDataSource; import org.ibase4j.core.util.ExceptionUtil; import org.ibase4j.core.util.InstanceUtil; import org.springframework.beans.BeansException; @@ -33,6 +35,20 @@ public Parameter execute(Parameter parameter) { Map map = parameter.getMap(); String method = parameter.getMethod(); Object[] param = parameter.getParam(); + try { + L: for (String key : ChooseDataSource.METHODTYPE.keySet()) { + for (String type : ChooseDataSource.METHODTYPE.get(key)) { + if (method.startsWith(type)) { + logger.info(key); + HandleDataSource.putDataSource(key); + break L; + } + } + } + } catch (Exception e) { + logger.error(e); + HandleDataSource.putDataSource("write"); + } Object result = null; if (param != null) { result = InstanceUtil.invokeMethod(service, method, param); diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/ChooseDataSource.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/ChooseDataSource.java similarity index 96% rename from iBase4J-Common/src/main/java/org/ibase4j/core/aspect/ChooseDataSource.java rename to iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/ChooseDataSource.java index 5346824b..de816c14 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/ChooseDataSource.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/ChooseDataSource.java @@ -1,4 +1,4 @@ -package org.ibase4j.core.aspect; +package org.ibase4j.core.support.dbcp; import java.util.ArrayList; import java.util.HashMap; diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/HandleDataSource.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/HandleDataSource.java similarity index 91% rename from iBase4J-Common/src/main/java/org/ibase4j/core/aspect/HandleDataSource.java rename to iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/HandleDataSource.java index e7fadaf7..af04787f 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/aspect/HandleDataSource.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/HandleDataSource.java @@ -1,4 +1,4 @@ -package org.ibase4j.core.aspect; +package org.ibase4j.core.support.dbcp; /** * @author ShenHuaJie diff --git a/iBase4J-Common/src/main/resources/spring/dataSource.xml b/iBase4J-Common/src/main/resources/spring/dataSource.xml index c4832c50..79af1fbd 100644 --- a/iBase4J-Common/src/main/resources/spring/dataSource.xml +++ b/iBase4J-Common/src/main/resources/spring/dataSource.xml @@ -70,7 +70,7 @@ - + 数据源 @@ -90,8 +90,6 @@ - - diff --git a/iBase4J-Common/src/main/resources/spring/session.xml b/iBase4J-Common/src/main/resources/spring/session.xml index 90872bf3..53e2f995 100644 --- a/iBase4J-Common/src/main/resources/spring/session.xml +++ b/iBase4J-Common/src/main/resources/spring/session.xml @@ -19,11 +19,6 @@ - - - - - - + + p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.password}" + p:pool-config-ref="jedisPoolConfig" p:timeout="${redis.timeout}" /> diff --git a/pom.xml b/pom.xml index b18d967d..9902003f 100644 --- a/pom.xml +++ b/pom.xml @@ -29,9 +29,9 @@ UTF-8 - 5.0.0.M5 + 5.0.0.RC3 2.0.0.M2 - 2.0.0.M4 + 2.0.0.RC2 5.1.39 1.4.1 From 433424af76d78244c0583a388bd07e6e6fe0bb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Sat, 19 Aug 2017 22:22:45 +0800 Subject: [PATCH 07/50] =?UTF-8?q?=E7=BC=93=E5=AD=98=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9AService=E4=BD=BF=E7=94=A8redisson=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BC=93=E5=AD=98=EF=BC=9BWeb=E4=BD=BF?= =?UTF-8?q?=E7=94=A8Spring-data-redis=E7=AE=A1=E7=90=86=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ibase4j/core/listener/SessionListener.java | 13 +++++++++---- .../java/org/ibase4j/core/util/InstanceUtil.java | 2 +- pom.xml | 9 ++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java b/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java index 84b05a59..91f26386 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java @@ -7,7 +7,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.ibase4j.core.Constants; -import org.ibase4j.core.util.CacheUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; /** * 会话监听器 @@ -15,9 +16,13 @@ * @author ShenHuaJie * @version $Id: SessionListener.java, v 0.1 2014年3月28日 上午9:06:12 ShenHuaJie Exp */ +@SuppressWarnings({ "rawtypes", "unchecked" }) public class SessionListener implements HttpSessionListener { private Logger logger = LogManager.getLogger(SessionListener.class); + @Autowired + RedisTemplate redisTemplate; + /* * (non-Javadoc) * @@ -29,7 +34,7 @@ public void sessionCreated(HttpSessionEvent event) { HttpSession session = event.getSession(); session.setAttribute(Constants.WEBTHEME, "default"); logger.info("创建了一个Session连接:[" + session.getId() + "]"); - CacheUtil.getCache().sadd(Constants.ALLUSER_NUMBER, session.getId()); + redisTemplate.opsForSet().add(Constants.ALLUSER_NUMBER, session.getId()); } /* @@ -45,11 +50,11 @@ public void sessionDestroyed(HttpSessionEvent event) { logger.info("销毁了一个Session连接:[" + session.getId() + "]"); } session.removeAttribute(Constants.CURRENT_USER); - CacheUtil.getCache().sdel(Constants.ALLUSER_NUMBER, session.getId()); + redisTemplate.opsForSet().remove(Constants.ALLUSER_NUMBER, session.getId()); } /** 获取在线用户数量 */ public Integer getAllUserNumber() { - return CacheUtil.getCache().sall(Constants.ALLUSER_NUMBER).size(); + return redisTemplate.opsForSet().size(Constants.ALLUSER_NUMBER).intValue(); } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/util/InstanceUtil.java b/iBase4J-Common/src/main/java/org/ibase4j/core/util/InstanceUtil.java index 3f3da293..b83a403a 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/util/InstanceUtil.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/util/InstanceUtil.java @@ -298,7 +298,7 @@ public static final Object newInstance(String className, Object... args) { } } - public static Map methodMap = new HashMap(); + private static Map methodMap = new HashMap(); /** * 执行某对象方法 diff --git a/pom.xml b/pom.xml index 9902003f..34d42485 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ 5.0.0.RC3 2.0.0.M2 - 2.0.0.RC2 + 2.0.0.M2 5.1.39 1.4.1 @@ -57,7 +57,7 @@ 2.9.0 3.3.0 3.5.3-beta - 2.8.6 + 2.9.0 1.2.4 2.2.3 1.8.9 @@ -103,11 +103,6 @@ commons-codec 1.10 - - org.apache.commons - commons-digester3 - 3.2 - commons-beanutils commons-beanutils From 9fdc155c0fef3c770c66a4f56942fd8542c2ad44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Mon, 21 Aug 2017 13:49:02 +0800 Subject: [PATCH 08/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/listener/SessionListener.java | 13 +- .../core/support/cache/RedisHelper.java | 148 ++++++++++++++ .../support/cache/jedis/JedisShardInfo.java | 24 --- .../core/support/cache/shiro/RedisCache.java | 189 +++++++++--------- .../cache/shiro/RedisCacheManager.java | 14 +- .../src/main/resources/spring/session.xml | 3 +- pom.xml | 5 + 7 files changed, 255 insertions(+), 141 deletions(-) create mode 100644 iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java delete mode 100644 iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/jedis/JedisShardInfo.java diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java b/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java index 91f26386..84b05a59 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/listener/SessionListener.java @@ -7,8 +7,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.ibase4j.core.Constants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; +import org.ibase4j.core.util.CacheUtil; /** * 会话监听器 @@ -16,13 +15,9 @@ * @author ShenHuaJie * @version $Id: SessionListener.java, v 0.1 2014年3月28日 上午9:06:12 ShenHuaJie Exp */ -@SuppressWarnings({ "rawtypes", "unchecked" }) public class SessionListener implements HttpSessionListener { private Logger logger = LogManager.getLogger(SessionListener.class); - @Autowired - RedisTemplate redisTemplate; - /* * (non-Javadoc) * @@ -34,7 +29,7 @@ public void sessionCreated(HttpSessionEvent event) { HttpSession session = event.getSession(); session.setAttribute(Constants.WEBTHEME, "default"); logger.info("创建了一个Session连接:[" + session.getId() + "]"); - redisTemplate.opsForSet().add(Constants.ALLUSER_NUMBER, session.getId()); + CacheUtil.getCache().sadd(Constants.ALLUSER_NUMBER, session.getId()); } /* @@ -50,11 +45,11 @@ public void sessionDestroyed(HttpSessionEvent event) { logger.info("销毁了一个Session连接:[" + session.getId() + "]"); } session.removeAttribute(Constants.CURRENT_USER); - redisTemplate.opsForSet().remove(Constants.ALLUSER_NUMBER, session.getId()); + CacheUtil.getCache().sdel(Constants.ALLUSER_NUMBER, session.getId()); } /** 获取在线用户数量 */ public Integer getAllUserNumber() { - return redisTemplate.opsForSet().size(Constants.ALLUSER_NUMBER).intValue(); + return CacheUtil.getCache().sall(Constants.ALLUSER_NUMBER).size(); } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java new file mode 100644 index 00000000..9fd15f7c --- /dev/null +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java @@ -0,0 +1,148 @@ +package org.ibase4j.core.support.cache; + +import java.io.Serializable; +import java.util.Date; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.ibase4j.core.util.CacheUtil; +import org.ibase4j.core.util.InstanceUtil; +import org.ibase4j.core.util.PropertiesUtil; +import org.springframework.data.redis.core.RedisTemplate; + +/** + * Redis缓存辅助类 + * + * @author ShenHuaJie + * @version 2016年4月2日 下午4:17:22 + */ +@SuppressWarnings({ "rawtypes", "unchecked" }) +public final class RedisHelper implements CacheManager { + private RedisTemplate redisTemplate; + private final Integer EXPIRE = PropertiesUtil.getInt("redis.expiration"); + + public void setRedisTemplate(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + CacheUtil.setCacheManager(this); + } + + public final Object get(final String key) { + expire(key, EXPIRE); + return redisTemplate.boundValueOps(key).get(); + } + + public final Set getAll(final String pattern) { + Set values = InstanceUtil.newHashSet(); + Set keys = redisTemplate.keys(pattern); + for (Serializable key : keys) { + expire(key.toString(), EXPIRE); + values.add(redisTemplate.opsForValue().get(key)); + } + return values; + } + + public final void set(final String key, final Serializable value, int seconds) { + redisTemplate.boundValueOps(key).set(value); + expire(key, seconds); + } + + public final void set(final String key, final Serializable value) { + redisTemplate.boundValueOps(key).set(value); + expire(key, EXPIRE); + } + + public final Boolean exists(final String key) { + return redisTemplate.hasKey(key); + } + + public final void del(final String key) { + redisTemplate.delete(key); + } + + public final void delAll(final String pattern) { + redisTemplate.delete(redisTemplate.keys(pattern)); + } + + public final String type(final String key) { + expire(key, EXPIRE); + return redisTemplate.type(key).getClass().getName(); + } + + /** + * 在某段时间后失效 + * + * @return + */ + public final Boolean expire(final String key, final int seconds) { + return redisTemplate.expire(key, seconds, TimeUnit.SECONDS); + } + + /** + * 在某个时间点失效 + * + * @param key + * @param unixTime + * @return + */ + public final Boolean expireAt(final String key, final long unixTime) { + return redisTemplate.expireAt(key, new Date(unixTime)); + } + + public final Long ttl(final String key) { + return redisTemplate.getExpire(key, TimeUnit.SECONDS); + } + + public final void setrange(final String key, final long offset, final String value) { + redisTemplate.boundValueOps(key).set(value, offset); + expire(key, EXPIRE); + } + + public final String getrange(final String key, final long startOffset, final long endOffset) { + expire(key, EXPIRE); + return redisTemplate.boundValueOps(key).get(startOffset, endOffset); + } + + public final Object getSet(final String key, final Serializable value) { + expire(key, EXPIRE); + return redisTemplate.boundValueOps(key).getAndSet(value); + } + + public boolean setnx(String key, long value) { + return redisTemplate.boundValueOps(key).setIfAbsent(value); + } + + @Deprecated + public boolean lock(String key) { + throw new RuntimeException("not support."); + } + + public void unlock(String key) { + del(key); + } + + public void hset(String key, Serializable field, Serializable value) { + redisTemplate.boundHashOps(key).put(field, value); + } + + public Object hget(String key, Serializable field) { + return redisTemplate.boundHashOps(key).get(field); + } + + public void hdel(String key, Serializable field) { + redisTemplate.boundHashOps(key).delete(field); + } + + public void sadd(String key, Serializable value) { + redisTemplate.boundSetOps(key).add(value); + } + + public Set sall(String key) { + return redisTemplate.boundSetOps(key).members(); + } + + public boolean sdel(String key, Serializable value) { + return redisTemplate.boundSetOps(key).remove(value) == 1; + } + + // 未完,待续... +} \ No newline at end of file diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/jedis/JedisShardInfo.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/jedis/JedisShardInfo.java deleted file mode 100644 index 733fad05..00000000 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/jedis/JedisShardInfo.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * - */ -package org.ibase4j.core.support.cache.jedis; - -import org.apache.commons.lang3.StringUtils; - -/** - * - * @author ShenHuaJie - * @version 2017年3月27日 下午12:47:53 - */ -public class JedisShardInfo extends redis.clients.jedis.JedisShardInfo { - - public JedisShardInfo(String host, int port) { - super(host, port); - } - - public void setPassword(String password) { - if (StringUtils.isNotBlank(password)) { - super.setPassword(password); - } - } -} diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCache.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCache.java index 400b9e11..6a39f046 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCache.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCache.java @@ -3,6 +3,7 @@ */ package org.ibase4j.core.support.cache.shiro; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -15,117 +16,117 @@ import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; import org.apache.shiro.util.CollectionUtils; -import org.springframework.data.redis.core.RedisTemplate; +import org.ibase4j.core.util.CacheUtil; /** * * @author ShenHuaJie * @version 2017年3月24日 下午8:54:08 */ -@SuppressWarnings({ "unchecked", "rawtypes" }) public class RedisCache implements Cache { - private final Logger logger = LogManager.getLogger(); - private RedisTemplate redisTemplate; + private final Logger logger = LogManager.getLogger(); - /** - * The Redis key prefix for the sessions - */ - private String keyPrefix = "shiro_redis_session:"; + /** + * The Redis key prefix for the sessions + */ + private String keyPrefix = "shiro_redis_session:"; - /** - * Sets the Redis sessions key prefix. - * - * @param keyPrefix - * The prefix - */ - public void setKeyPrefix(String keyPrefix) { - this.keyPrefix = keyPrefix; - } + /** + * Returns the Redis session keys + * prefix. + * @return The prefix + */ + public String getKeyPrefix() { + return keyPrefix; + } - /** - * @param redisTemplate - */ - public void setRedisTemplate(RedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - } + /** + * Sets the Redis sessions key + * prefix. + * @param keyPrefix The prefix + */ + public void setKeyPrefix(String keyPrefix) { + this.keyPrefix = keyPrefix; + } - /** - * Constructs a cache instance with the specified Redis manager and using a - * custom key prefix. - * - * @param prefix - * The Redis key prefix - */ - public RedisCache(String prefix, RedisTemplate redisTemplate) { - this.keyPrefix = prefix; - this.redisTemplate = redisTemplate; - } + /** + * Constructs a cache instance with the specified + * Redis manager and using a custom key prefix. + * @param prefix The Redis key prefix + */ + public RedisCache(String prefix) { + // set the prefix + this.keyPrefix = prefix; + } - @Override - public V get(K key) throws CacheException { - logger.debug("根据key从Redis中获取对象 key [" + key + "]"); - V value = (V) redisTemplate.boundValueOps(getKey(key)).get(); - return value; - } + @Override + public V get(K key) throws CacheException { + logger.debug("根据key从Redis中获取对象 key [" + key + "]"); + @SuppressWarnings("unchecked") + V value = (V)CacheUtil.getCache().get(getKey(key)); + return value; + } - @Override - public V put(K key, V value) throws CacheException { - logger.debug("根据key从存储 key [" + key + "]"); - redisTemplate.boundValueOps(getKey(key)).set(value); - return value; - } + @Override + public V put(K key, V value) throws CacheException { + logger.debug("根据key从存储 key [" + key + "]"); + CacheUtil.getCache().set(getKey(key), (Serializable)value); + return value; + } - @Override - public V remove(K key) throws CacheException { - logger.debug("从redis中删除 key [" + key + "]"); - V previous = get(key); - redisTemplate.delete(getKey(key)); - return previous; - } + @Override + public V remove(K key) throws CacheException { + logger.debug("从redis中删除 key [" + key + "]"); + V previous = get(key); + CacheUtil.getCache().del(getKey(key)); + return previous; + } - @Override - public void clear() throws CacheException { - logger.debug("从redis中删除所有元素"); - redisTemplate.delete(redisTemplate.keys(this.keyPrefix + "*")); - } + @Override + public void clear() throws CacheException { + logger.debug("从redis中删除所有元素"); + CacheUtil.getCache().delAll(this.keyPrefix + "*"); + } - @Override - public int size() { - return redisTemplate.keys(this.keyPrefix + "*").size(); - } + @Override + public int size() { + return CacheUtil.getCache().getAll(this.keyPrefix + "*").size(); + } - @Override - public Set keys() { - Set keys = redisTemplate.keys(this.keyPrefix + "*"); - if (CollectionUtils.isEmpty(keys)) { - return Collections.emptySet(); - } else { - Set newKeys = new HashSet(); - for (Object key : keys) { - newKeys.add((K) key); - } - return newKeys; - } - } + @SuppressWarnings("unchecked") + @Override + public Set keys() { + Set keys = CacheUtil.getCache().getAll(this.keyPrefix + "*"); + if (CollectionUtils.isEmpty(keys)) { + return Collections.emptySet(); + } else { + Set newKeys = new HashSet(); + for (Object key : keys) { + newKeys.add((K)key); + } + return newKeys; + } + } - @Override - public Collection values() { - Set keys = redisTemplate.keys(this.keyPrefix + "*"); - if (!CollectionUtils.isEmpty(keys)) { - List values = new ArrayList(keys.size()); - for (Object key : keys) { - V value = get((K) key); - if (value != null) { - values.add(value); - } - } - return Collections.unmodifiableList(values); - } else { - return Collections.emptyList(); - } - } + @Override + public Collection values() { + Set keys = CacheUtil.getCache().getAll(this.keyPrefix + "*"); + if (!CollectionUtils.isEmpty(keys)) { + List values = new ArrayList(keys.size()); + for (Object key : keys) { + @SuppressWarnings("unchecked") + V value = get((K)key); + if (value != null) { + values.add(value); + } + } + return Collections.unmodifiableList(values); + } else { + return Collections.emptyList(); + } + } - private String getKey(K key) { - return this.keyPrefix + key; - } + private String getKey(K key) { + return this.keyPrefix + key; + } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCacheManager.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCacheManager.java index 12ce2877..202b4148 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCacheManager.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/shiro/RedisCacheManager.java @@ -6,15 +6,12 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import javax.annotation.Resource; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; import org.apache.shiro.cache.CacheManager; import org.ibase4j.core.Constants; -import org.springframework.data.redis.core.RedisTemplate; /** * @@ -24,8 +21,6 @@ @SuppressWarnings({ "rawtypes", "unchecked" }) public class RedisCacheManager implements CacheManager { private final Logger logger = LogManager.getLogger(); - @Resource - private RedisTemplate redisTemplate; // fast lookup by name map private final ConcurrentMap caches = new ConcurrentHashMap(); @@ -44,13 +39,6 @@ public void setKeyPrefix(String keyPrefix) { this.keyPrefix = keyPrefix; } - /** - * @param redisTemplate - */ - public void setRedisTemplate(RedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - } - /* * (non-Javadoc) * @@ -63,7 +51,7 @@ public Cache getCache(String name) throws CacheException { if (c == null) { // create a new cache instance - c = new RedisCache(keyPrefix, redisTemplate); + c = new RedisCache(keyPrefix); // add it to the cache collection caches.put(name, c); } diff --git a/iBase4J-Common/src/main/resources/spring/session.xml b/iBase4J-Common/src/main/resources/spring/session.xml index 53e2f995..b14599c4 100644 --- a/iBase4J-Common/src/main/resources/spring/session.xml +++ b/iBase4J-Common/src/main/resources/spring/session.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-4.0.xsd"> + http://www.springframework.org/schema/context/spring-context-4.0.xsd" default-autowire="byType"> @@ -52,4 +52,5 @@ + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 34d42485..531bc716 100644 --- a/pom.xml +++ b/pom.xml @@ -277,6 +277,11 @@ + + com.101tec + zkclient + 0.10 + org.apache.activemq From 4d248c14e2a7be6c57372cb36701b11814863daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Tue, 22 Aug 2017 18:39:08 +0800 Subject: [PATCH 09/50] =?UTF-8?q?web=E6=95=B0=E6=8D=AE=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E4=BD=BF=E7=94=A8JSON=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/ibase4j/web/LoginController.java | 7 +-- .../src/main/resources/Spring-config.xml | 1 + .../org/ibase4j/core/filter/TokenFilter.java | 2 +- .../core/interceptor/LocaleInterceptor.java | 4 ++ .../core/support/cache/CacheManager.java | 2 +- .../core/support/cache/RedisHelper.java | 7 ++- .../src/main/resources/spring/redis.xml | 49 +++++++++++++++++++ .../src/main/resources/spring/redisson.xml | 1 + .../src/main/resources/spring/session.xml | 29 +---------- .../src/main/resources/config/jdbc.properties | 8 +-- .../src/main/resources/Spring-config.xml | 1 + 11 files changed, 68 insertions(+), 43 deletions(-) create mode 100644 iBase4J-Common/src/main/resources/spring/redis.xml diff --git a/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java b/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java index bc0ce945..9efea753 100644 --- a/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java +++ b/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java @@ -31,7 +31,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; /** * 用户登录 @@ -50,8 +49,10 @@ public String getService() { // 登录 @ApiOperation(value = "用户登录") @PostMapping("app/login") - public Object login(@ApiParam(required = true, value = "登录帐号和密码") @RequestBody Login user, ModelMap modelMap, - HttpServletRequest request) { + public Object login(Login user, ModelMap modelMap, HttpServletRequest request) { + String uuid = request.getHeader("UUID"); + org.springframework.util.Assert.notNull(uuid, "非法操作."); + user = WebUtil.getParameter(request, Login.class); Assert.notNull(user.getAccount(), "ACCOUNT"); Assert.notNull(user.getPassword(), "PASSWORD"); diff --git a/iBase4J-Biz-Web/src/main/resources/Spring-config.xml b/iBase4J-Biz-Web/src/main/resources/Spring-config.xml index c27bc233..7b0a8d83 100644 --- a/iBase4J-Biz-Web/src/main/resources/Spring-config.xml +++ b/iBase4J-Biz-Web/src/main/resources/Spring-config.xml @@ -39,6 +39,7 @@ + \ No newline at end of file diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/filter/TokenFilter.java b/iBase4J-Common/src/main/java/org/ibase4j/core/filter/TokenFilter.java index 65319ecc..4b8591d9 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/filter/TokenFilter.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/filter/TokenFilter.java @@ -55,7 +55,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse response, Fi if (isWhiteReq(request.getRequestURI())) { chain.doFilter(request, response); } else { - String token = request.getHeader("token"); + String token = request.getHeader("UUID"); if (StringUtils.isNotBlank(token)) { try { Token tokenInfo = TokenUtil.getTokenInfo(token); diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/LocaleInterceptor.java b/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/LocaleInterceptor.java index 285042c5..6c58be83 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/LocaleInterceptor.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/LocaleInterceptor.java @@ -63,6 +63,10 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons try { UserAgentInfo userAgentInfo = uasParser.parse(request.getHeader("user-agent")); userAgent = userAgentInfo.getOsName() + " " + userAgentInfo.getType() + " " + userAgentInfo.getUaName(); + String uuid = request.getHeader("UUID"); + if ("unknown unknown unknown".equals(userAgent) && StringUtils.isNotBlank(uuid)) { + userAgent = uuid; + } session.setAttribute(Constants.USER_AGENT, userAgent); } catch (IOException e) { logger.error("", e); diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java index 429f9c90..786871fc 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java @@ -42,7 +42,7 @@ public interface CacheManager { void sadd(String key, Serializable value); - Set sall(String key); + Set sall(String key); boolean sdel(String key, Serializable value); } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java index 9fd15f7c..4fb90412 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java @@ -16,12 +16,11 @@ * @author ShenHuaJie * @version 2016年4月2日 下午4:17:22 */ -@SuppressWarnings({ "rawtypes", "unchecked" }) public final class RedisHelper implements CacheManager { - private RedisTemplate redisTemplate; + private RedisTemplate redisTemplate; private final Integer EXPIRE = PropertiesUtil.getInt("redis.expiration"); - public void setRedisTemplate(RedisTemplate redisTemplate) { + public void setRedisTemplate(RedisTemplate redisTemplate) { this.redisTemplate = redisTemplate; CacheUtil.setCacheManager(this); } @@ -136,7 +135,7 @@ public void sadd(String key, Serializable value) { redisTemplate.boundSetOps(key).add(value); } - public Set sall(String key) { + public Set sall(String key) { return redisTemplate.boundSetOps(key).members(); } diff --git a/iBase4J-Common/src/main/resources/spring/redis.xml b/iBase4J-Common/src/main/resources/spring/redis.xml new file mode 100644 index 00000000..c6799c2c --- /dev/null +++ b/iBase4J-Common/src/main/resources/spring/redis.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/iBase4J-Common/src/main/resources/spring/redisson.xml b/iBase4J-Common/src/main/resources/spring/redisson.xml index cb299436..e5fedb8e 100644 --- a/iBase4J-Common/src/main/resources/spring/redisson.xml +++ b/iBase4J-Common/src/main/resources/spring/redisson.xml @@ -11,6 +11,7 @@ + diff --git a/iBase4J-Common/src/main/resources/spring/session.xml b/iBase4J-Common/src/main/resources/spring/session.xml index b14599c4..e1a532f2 100644 --- a/iBase4J-Common/src/main/resources/spring/session.xml +++ b/iBase4J-Common/src/main/resources/spring/session.xml @@ -5,33 +5,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-4.0.xsd" default-autowire="byType"> - - - - - - - - - - - - - - - - - + http://www.springframework.org/schema/context/spring-context-4.0.xsd"> @@ -52,5 +26,4 @@ - \ No newline at end of file diff --git a/iBase4J-SYS-Service/src/main/resources/config/jdbc.properties b/iBase4J-SYS-Service/src/main/resources/config/jdbc.properties index 7bffcf34..d1faf672 100644 --- a/iBase4J-SYS-Service/src/main/resources/config/jdbc.properties +++ b/iBase4J-SYS-Service/src/main/resources/config/jdbc.properties @@ -13,19 +13,15 @@ db.writer.password=yYEtaRoo3QHpKaWpBJTW17== db.initialSize=5 #\u5b9a\u4e49\u6700\u5927\u8fde\u63a5\u6570 db.maxActive=20 -#\u5b9a\u4e49\u6700\u5927\u7a7a\u95f2 -db.maxIdle=10 #\u5b9a\u4e49\u6700\u5c0f\u7a7a\u95f2 -db.minIdle=1 +db.minIdle=5 #\u5b9a\u4e49\u6700\u957f\u7b49\u5f85\u65f6\u95f4 db.maxWait=60000 # -db.timeBetweenEvictionRunsMillis=3000 +db.timeBetweenEvictionRunsMillis=30000 # db.minEvictableIdleTimeMillis=300000 # -db.maxPoolPreparedStatementPerConnectionSize=10 -# druid.filters= # db.reader.list.maxThread=5 \ No newline at end of file diff --git a/iBase4J-SYS-Web/src/main/resources/Spring-config.xml b/iBase4J-SYS-Web/src/main/resources/Spring-config.xml index 09310094..d11030ff 100644 --- a/iBase4J-SYS-Web/src/main/resources/Spring-config.xml +++ b/iBase4J-SYS-Web/src/main/resources/Spring-config.xml @@ -37,6 +37,7 @@ + \ No newline at end of file From a3cc89b7b829a80a1d74c1c9f675160286262932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Wed, 23 Aug 2017 10:19:23 +0800 Subject: [PATCH 10/50] =?UTF-8?q?=E4=BC=98=E5=8C=96RedissonClient?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/interceptor/EventInterceptor.java | 147 +++++++++--------- .../core/support/cache/redisson/Client.java | 107 +++++++++++++ .../src/main/resources/spring/redisson.xml | 24 +-- 3 files changed, 195 insertions(+), 83 deletions(-) create mode 100644 iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/Client.java diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/EventInterceptor.java b/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/EventInterceptor.java index b78ecef1..860524f1 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/EventInterceptor.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/EventInterceptor.java @@ -52,84 +52,85 @@ public void afterCompletion(final HttpServletRequest request, HttpServletRespons final Exception ex) throws Exception { final Long startTime = startTimeThreadLocal.get(); final Long endTime = System.currentTimeMillis(); + String path = request.getServletPath(); // 保存日志 + if (handler instanceof HandlerMethod) { + try { + Object uid = WebUtil.getCurrentUser(request); + String userAgent = (String) request.getSession().getAttribute(Constants.USER_AGENT); + String clientIp = (String) request.getSession().getAttribute(Constants.USER_IP); + if (!path.contains("/read/") && !path.contains("/get") && !path.contains("/unauthorized") + && !path.contains("/forbidden")) { + final SysEvent record = new SysEvent(); + record.setMethod(request.getMethod()); + record.setRequestUri(path); + record.setClientHost(clientIp); + record.setUserAgent(userAgent); + if (path.contains("/upload")) { + record.setParameters(""); + } else { + String param = JSON.toJSONString(WebUtil.getParameterMap(request)); + record.setParameters(param.length() > 1024 ? param.substring(0, 1024) : param); + } + record.setStatus(response.getStatus()); + if (uid != null) { + record.setCreateBy(Long.parseLong(uid.toString())); + record.setUpdateBy(Long.parseLong(uid.toString())); + } + final String msg = (String) request.getAttribute("msg"); + try { + HandlerMethod handlerMethod = (HandlerMethod) handler; + ApiOperation apiOperation = handlerMethod.getMethod().getAnnotation(ApiOperation.class); + record.setTitle(apiOperation.value()); + } catch (Exception e) { + logger.error("", e); + } + executorService.submit(new Runnable() { + public void run() { + try { // 保存操作 + if (StringUtils.isNotBlank(msg)) { + record.setRemark(msg); + } else { + record.setRemark(ExceptionUtil.getStackTraceAsString(ex)); + } - try { - String path = request.getServletPath(); - Object uid = WebUtil.getCurrentUser(request); - String userAgent = (String) request.getSession().getAttribute(Constants.USER_AGENT); - String clientIp = (String) request.getSession().getAttribute(Constants.USER_IP); - if (!path.contains("/read/") && !path.contains("/get") && !path.contains("/unauthorized") - && !path.contains("/forbidden")) { - final SysEvent record = new SysEvent(); - record.setMethod(request.getMethod()); - record.setRequestUri(path); - record.setClientHost(clientIp); - record.setUserAgent(userAgent); - if (path.contains("/upload")) { - record.setParameters(""); - } else { - String param = JSON.toJSONString(WebUtil.getParameterMap(request)); - record.setParameters(param.length() > 1024 ? param.substring(0, 1024) : param); - } - record.setStatus(response.getStatus()); - if (uid != null) { - record.setCreateBy(Long.parseLong(uid.toString())); - record.setUpdateBy(Long.parseLong(uid.toString())); - } - final String msg = (String) request.getAttribute("msg"); - try { - HandlerMethod handlerMethod = (HandlerMethod) handler; - ApiOperation apiOperation = handlerMethod.getMethod().getAnnotation(ApiOperation.class); - record.setTitle(apiOperation.value()); - } catch (Exception e) { - logger.error("", e); - } - executorService.submit(new Runnable() { - public void run() { - try { // 保存操作 - if (StringUtils.isNotBlank(msg)) { - record.setRemark(msg); - } else { - record.setRemark(ExceptionUtil.getStackTraceAsString(ex)); - } - - Parameter parameter = new Parameter("sysEventService", "update").setModel(record); - sysProvider.execute(parameter); - - // 内存信息 - if (logger.isDebugEnabled()) { - String message = "开始时间: {}; 结束时间: {}; 耗时: {}s; URI: {}; "; - // 最大内存: {}M; 已分配内存: {}M; 已分配内存中的剩余空间: {}M; - // 最大可用内存: - // {}M. - // long total = - // Runtime.getRuntime().totalMemory() / - // 1024 / 1024; - // long max = Runtime.getRuntime().maxMemory() / - // 1024 / 1024; - // long free = Runtime.getRuntime().freeMemory() - // / - // 1024 / 1024; - // , max, total, free, max - total + free - logger.debug(message, DateUtil.format(startTime, "HH:mm:ss.SSS"), - DateUtil.format(endTime, "HH:mm:ss.SSS"), (endTime - startTime) / 1000.00, - record.getRequestUri()); + Parameter parameter = new Parameter("sysEventService", "update").setModel(record); + sysProvider.execute(parameter); + } catch (Exception e) { + logger.error("Save event log cause error :", e); } - } catch (Exception e) { - logger.error("Save event log cause error :", e); } - } - }); - } else if (path.contains("/unauthorized")) { - logger.warn("用户[{}]没有登录", clientIp + "@" + userAgent); - } else if (path.contains("/forbidden")) { - logger.warn("用户[{}]没有权限", WebUtil.getCurrentUser() + "@" + clientIp + "@" + userAgent); - } else { - logger.info(uid + "@" + path + "@" + clientIp + userAgent); + }); + } else if (path.contains("/unauthorized")) { + logger.warn("用户[{}]没有登录", clientIp + "@" + userAgent); + } else if (path.contains("/forbidden")) { + logger.warn("用户[{}]没有权限", WebUtil.getCurrentUser() + "@" + clientIp + "@" + userAgent); + } else { + logger.info(uid + "@" + path + "@" + clientIp + userAgent); + } + } catch (Exception e) { + logger.error("", e); } - } catch (Exception e) { - logger.error("", e); + } + // 内存信息 + if (logger.isDebugEnabled()) { + String message = "开始时间: {}; 结束时间: {}; 耗时: {}s; URI: {}; "; + // 最大内存: {}M; 已分配内存: {}M; 已分配内存中的剩余空间: {}M; + // 最大可用内存: + // {}M. + // long total = + // Runtime.getRuntime().totalMemory() / + // 1024 / 1024; + // long max = + // Runtime.getRuntime().maxMemory() / + // 1024 / 1024; + // long free = + // Runtime.getRuntime().freeMemory() + // / + // 1024 / 1024; + // , max, total, free, max - total + free + logger.debug(message, DateUtil.format(startTime, "HH:mm:ss.SSS"), DateUtil.format(endTime, "HH:mm:ss.SSS"), + (endTime - startTime) / 1000.00, path); } super.afterCompletion(request, response, handler, ex); } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/Client.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/Client.java new file mode 100644 index 00000000..acb2a634 --- /dev/null +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/Client.java @@ -0,0 +1,107 @@ +package org.ibase4j.core.support.cache.redisson; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.commons.lang3.StringUtils; +import org.redisson.Redisson; +import org.redisson.api.RedissonClient; +import org.redisson.config.ClusterServersConfig; +import org.redisson.config.Config; +import org.redisson.config.MasterSlaveServersConfig; +import org.redisson.config.SingleServerConfig; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Redis连接配置 + * + * @author ShenHuaJie + * @since 2017年8月23日 上午9:36:53 + */ +@Configuration +public class Client { + /** + * Redis server address + * + */ + private String address; + + /** + * Password for Redis authentication. Should be null if not needed + */ + private String password; + + /** + * Redis cluster node urls list + */ + private Set nodeAddresses = new HashSet(); + + /** + * Redis master server address + */ + private String masterAddress; + + /** + * Redis slave servers addresses + */ + private Set slaveAddresses = new HashSet(); + + @Bean(name = "redissonClient") + public RedissonClient getRedissonClient() { + Config config = new Config(); + if (StringUtils.isNotBlank(address)) { + SingleServerConfig serverConfig = config.useSingleServer().setAddress(address); + if (StringUtils.isNotBlank(password)) { + serverConfig.setPassword(password); + } + } else if (!nodeAddresses.isEmpty()) { + ClusterServersConfig serverConfig = config.useClusterServers() + .addNodeAddress(nodeAddresses.toArray(new String[] {})); + if (StringUtils.isNotBlank(password)) { + serverConfig.setPassword(password); + } + } else if (masterAddress != null && !slaveAddresses.isEmpty()) { + MasterSlaveServersConfig serverConfig = config.useMasterSlaveServers().setMasterAddress(masterAddress) + .addSlaveAddress(slaveAddresses.toArray(new String[] {})); + if (StringUtils.isNotBlank(password)) { + serverConfig.setPassword(password); + } + } + return Redisson.create(config); + } + + public void setAddress(String address) { + this.address = address; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setNodeAddresses(String nodeAddresse) { + if (nodeAddresse != null) { + String[] nodeAddresses = nodeAddresse.split(","); + for (int i = 0; i < nodeAddresses.length; i++) { + if (StringUtils.isNotEmpty(nodeAddresses[i])) { + this.nodeAddresses.add(nodeAddresses[i]); + } + } + } + } + + public void setMasterAddress(String masterAddress) { + this.masterAddress = masterAddress; + } + + public void setSlaveAddresses(String slaveAddresse) { + if (slaveAddresse != null) { + String[] slaveAddresses = slaveAddresse.split(","); + for (int i = 0; i < slaveAddresses.length; i++) { + if (StringUtils.isNotEmpty(slaveAddresses[i])) { + this.slaveAddresses.add(slaveAddresses[i]); + } + } + } + } +} diff --git a/iBase4J-Common/src/main/resources/spring/redisson.xml b/iBase4J-Common/src/main/resources/spring/redisson.xml index e5fedb8e..0b1097bc 100644 --- a/iBase4J-Common/src/main/resources/spring/redisson.xml +++ b/iBase4J-Common/src/main/resources/spring/redisson.xml @@ -1,18 +1,21 @@ - - - - + http://www.springframework.org/schema/context/spring-context-4.0.xsd"> + + + + + + + + + @@ -26,5 +29,6 @@ - + \ No newline at end of file From ca592312046d4a1e8ab6d88ae3e962fa58e620ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Wed, 23 Aug 2017 17:26:36 +0800 Subject: [PATCH 11/50] Set theme jekyll-theme-architect --- _config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 _config.yml diff --git a/_config.yml b/_config.yml new file mode 100644 index 00000000..3397c9a4 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-architect \ No newline at end of file From c917e12472e2319cfc1c7c944a47ea39d2d62a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Thu, 24 Aug 2017 18:09:19 +0800 Subject: [PATCH 12/50] =?UTF-8?q?Redis=E9=85=8D=E7=BD=AE=E9=9B=86=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/ibase4j/core/base/BaseProviderImpl.java | 2 ++ iBase4J-Common/src/main/resources/spring/redis.xml | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java index 0d034a0e..1ccc55c8 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java @@ -74,6 +74,8 @@ public Parameter execute(Parameter parameter) { String msg = ExceptionUtil.getStackTraceAsString(e); logger.error(no + " " + Constants.Exception_Head + msg, e); throw e; + } finally { + HandleDataSource.clear(); } } } diff --git a/iBase4J-Common/src/main/resources/spring/redis.xml b/iBase4J-Common/src/main/resources/spring/redis.xml index c6799c2c..fbbabfb2 100644 --- a/iBase4J-Common/src/main/resources/spring/redis.xml +++ b/iBase4J-Common/src/main/resources/spring/redis.xml @@ -26,12 +26,14 @@ c:name="redis.properties" c:resource="classpath:config/system.properties"/> - --> + + --> - + From 4719e703e288607ab661446ec47ba98a3d1a1fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 25 Aug 2017 09:46:12 +0800 Subject: [PATCH 13/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=94=AE=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/ibase4j/core/config/RedisCacheConfig.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/config/RedisCacheConfig.java b/iBase4J-Common/src/main/java/org/ibase4j/core/config/RedisCacheConfig.java index a9f32c1e..84ef956f 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/config/RedisCacheConfig.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/config/RedisCacheConfig.java @@ -28,13 +28,14 @@ @Configuration @EnableCaching public class RedisCacheConfig extends CachingConfigurerSupport { + String prefix = Constants.CACHE_NAMESPACE + "M:"; @Bean public KeyGenerator keyGenerator() { return new KeyGenerator() { /** 重写生成key方法 */ public Object generate(Object o, Method method, Object... objects) { - StringBuilder sb = new StringBuilder(Constants.CACHE_NAMESPACE + "M:"); + StringBuilder sb = new StringBuilder(prefix); CacheConfig cacheConfig = o.getClass().getAnnotation(CacheConfig.class); Cacheable cacheable = method.getAnnotation(Cacheable.class); CachePut cachePut = method.getAnnotation(CachePut.class); @@ -55,13 +56,13 @@ public Object generate(Object o, Method method, Object... objects) { sb.append(cacheNames[0]); } } - if (cacheConfig != null && sb.toString().equals(Constants.CACHE_NAMESPACE)) { + if (cacheConfig != null && sb.toString().equals(prefix)) { String[] cacheNames = cacheConfig.cacheNames(); if (ArrayUtils.isNotEmpty(cacheNames)) { sb.append(cacheNames[0]); } } - if (sb.toString().equals(Constants.CACHE_NAMESPACE)) { + if (sb.toString().equals(prefix)) { sb.append(o.getClass().getName()).append(".").append(method.getName()); } sb.append(":"); From 22e3b2c5408e7dcb84310cd5d98bd9781da929e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 25 Aug 2017 11:24:11 +0800 Subject: [PATCH 14/50] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dredisson=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Common/src/main/resources/spring/redisson.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iBase4J-Common/src/main/resources/spring/redisson.xml b/iBase4J-Common/src/main/resources/spring/redisson.xml index 0b1097bc..803a0b4b 100644 --- a/iBase4J-Common/src/main/resources/spring/redisson.xml +++ b/iBase4J-Common/src/main/resources/spring/redisson.xml @@ -9,7 +9,7 @@ - + From 25b8028eef16987a592e32b306f276805a83eea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 25 Aug 2017 15:14:01 +0800 Subject: [PATCH 15/50] =?UTF-8?q?redis=E9=9B=86=E7=BE=A4=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/spring/redis.xml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/iBase4J-Common/src/main/resources/spring/redis.xml b/iBase4J-Common/src/main/resources/spring/redis.xml index fbbabfb2..90694b11 100644 --- a/iBase4J-Common/src/main/resources/spring/redis.xml +++ b/iBase4J-Common/src/main/resources/spring/redis.xml @@ -20,24 +20,23 @@ - - + - - + - + From 66119176ba550d2d777d89a76a684691b8ee8ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 25 Aug 2017 15:18:28 +0800 Subject: [PATCH 16/50] =?UTF-8?q?redis=E9=9B=86=E7=BE=A4=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Common/src/main/resources/spring/redis.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iBase4J-Common/src/main/resources/spring/redis.xml b/iBase4J-Common/src/main/resources/spring/redis.xml index 90694b11..5c61517f 100644 --- a/iBase4J-Common/src/main/resources/spring/redis.xml +++ b/iBase4J-Common/src/main/resources/spring/redis.xml @@ -28,7 +28,8 @@ --> + c:cluster-config-ref="redisClusterConfiguration" c:pool-config-ref="jedisPoolConfig" p:timeout="${redis.timeout}" + p:password="${redis.password}" /> --> Date: Mon, 28 Aug 2017 15:38:02 +0800 Subject: [PATCH 17/50] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dweb=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=BC=82=E5=B8=B8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-SYS-Web/src/main/resources/Spring-config.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/iBase4J-SYS-Web/src/main/resources/Spring-config.xml b/iBase4J-SYS-Web/src/main/resources/Spring-config.xml index d11030ff..d36b0237 100644 --- a/iBase4J-SYS-Web/src/main/resources/Spring-config.xml +++ b/iBase4J-SYS-Web/src/main/resources/Spring-config.xml @@ -27,6 +27,7 @@ + From c809eed8730543bfa928de6bb9d4fca6aa68e972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Mon, 28 Aug 2017 15:59:06 +0800 Subject: [PATCH 18/50] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dweb=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Biz-Web/src/main/resources/Spring-config.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/iBase4J-Biz-Web/src/main/resources/Spring-config.xml b/iBase4J-Biz-Web/src/main/resources/Spring-config.xml index 7b0a8d83..dd893a74 100644 --- a/iBase4J-Biz-Web/src/main/resources/Spring-config.xml +++ b/iBase4J-Biz-Web/src/main/resources/Spring-config.xml @@ -27,6 +27,7 @@ + From 9f601721818c456b62adef5cf3ca279af86b9e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Tue, 29 Aug 2017 16:49:04 +0800 Subject: [PATCH 19/50] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dswagger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/ibase4j/core/config/SwaggerConfig.java | 6 +++--- .../main/java/org/ibase4j/core/config/SwaggerConfig.java | 5 +++-- .../src/main/java/org/ibase4j/web/LoginController.java | 3 +++ pom.xml | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/iBase4J-Biz-Web/src/main/java/org/ibase4j/core/config/SwaggerConfig.java b/iBase4J-Biz-Web/src/main/java/org/ibase4j/core/config/SwaggerConfig.java index 4e16abdb..cc1ca845 100644 --- a/iBase4J-Biz-Web/src/main/java/org/ibase4j/core/config/SwaggerConfig.java +++ b/iBase4J-Biz-Web/src/main/java/org/ibase4j/core/config/SwaggerConfig.java @@ -1,6 +1,7 @@ package org.ibase4j.core.config; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -18,12 +19,12 @@ @Configuration @EnableWebMvc @EnableSwagger2 +@ComponentScan(basePackages = { "org.ibase4j.web" }) public class SwaggerConfig { @Bean public Docket platformApi() { - return new Docket(DocumentationType.SWAGGER_2).groupName("full-platform").apiInfo(apiInfo()) - .forCodeGeneration(true); + return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).forCodeGeneration(true); } private ApiInfo apiInfo() { @@ -32,5 +33,4 @@ private ApiInfo apiInfo() { .contact(new Contact("iBase4J", "", "iBase4J@163.com")).license("Apache License Version 2.0") .licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE").version("2.0").build(); } - } \ No newline at end of file diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/core/config/SwaggerConfig.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/core/config/SwaggerConfig.java index 4e16abdb..e38a7dc0 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/core/config/SwaggerConfig.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/core/config/SwaggerConfig.java @@ -1,6 +1,7 @@ package org.ibase4j.core.config; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -18,12 +19,12 @@ @Configuration @EnableWebMvc @EnableSwagger2 +@ComponentScan(basePackages = { "org.ibase4j.web" }) public class SwaggerConfig { @Bean public Docket platformApi() { - return new Docket(DocumentationType.SWAGGER_2).groupName("full-platform").apiInfo(apiInfo()) - .forCodeGeneration(true); + return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).forCodeGeneration(true); } private ApiInfo apiInfo() { diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/LoginController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/LoginController.java index c3a59e58..686b182d 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/LoginController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/LoginController.java @@ -25,6 +25,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import springfox.documentation.annotations.ApiIgnore; /** * 用户登录 @@ -80,12 +81,14 @@ public Object regin(HttpServletRequest request, ModelMap modelMap, @RequestBody } // 没有登录 + @ApiIgnore @RequestMapping(value = "/unauthorized", method = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT }) public Object unauthorized(ModelMap modelMap) throws Exception { return setModelMap(modelMap, HttpCode.UNAUTHORIZED); } // 没有权限 + @ApiIgnore @RequestMapping(value = "/forbidden", method = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT }) public Object forbidden(ModelMap modelMap) { return setModelMap(modelMap, HttpCode.FORBIDDEN); diff --git a/pom.xml b/pom.xml index 531bc716..2cf8a672 100644 --- a/pom.xml +++ b/pom.xml @@ -64,8 +64,8 @@ 2.5.1 5.13.3 0.9.5 - 2.6.1 - 1.5.13 + 2.7.0 + 1.5.16 0.4.8 From 6545d74e17696c99fad4cb7f6a0a79bb6ce3b378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Thu, 31 Aug 2017 13:30:54 +0800 Subject: [PATCH 20/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ibase4j/core/base/BaseService.java | 113 +++++++++++------- 1 file changed, 67 insertions(+), 46 deletions(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java index ed20c99d..6c00e147 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java @@ -5,7 +5,6 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.RandomUtils; @@ -46,7 +45,9 @@ public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; } - int maxThread = PropertiesUtil.getInt("db.reader.list.maxThread", 5); + int maxThread = PropertiesUtil.getInt("db.reader.list.maxThread", 500); + int threadSleep = PropertiesUtil.getInt("db.reader.list.threadWait", 5); + ExecutorService executorService = Executors.newFixedThreadPool(maxThread); /** 分页查询 */ public static Page getPage(Map params) { @@ -86,21 +87,25 @@ public Page getPage(final Page ids) { for (int i = 0; i < ids.getRecords().size(); i++) { records.add(null); } - int thread = Math.min(maxThread, Math.max(1, records.size() / 2)); - ExecutorService executorService = Executors.newFixedThreadPool(thread); + final Map thread = InstanceUtil.newConcurrentHashMap(); for (int i = 0; i < ids.getRecords().size(); i++) { final int index = i; executorService.execute(new Runnable() { public void run() { - records.set(index, queryById(ids.getRecords().get(index))); + try { + records.set(index, queryById(ids.getRecords().get(index))); + } finally { + thread.put(index, 0); + } } }); } - executorService.shutdown(); - try { - executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - } catch (InterruptedException e) { - logger.error("awaitTermination", "", e); + while (thread.size() < records.size()) { + try { + Thread.sleep(threadSleep); + } catch (InterruptedException e) { + logger.error("", e); + } } page.setRecords(records); return page; @@ -117,21 +122,25 @@ public Page> getPageMap(final Page ids) { for (int i = 0; i < ids.getRecords().size(); i++) { records.add(null); } - int thread = Math.min(maxThread, Math.max(1, records.size() / 2)); - ExecutorService executorService = Executors.newFixedThreadPool(thread); + final Map thread = InstanceUtil.newConcurrentHashMap(); for (int i = 0; i < ids.getRecords().size(); i++) { final int index = i; executorService.execute(new Runnable() { public void run() { - records.set(index, InstanceUtil.transBean2Map(queryById(ids.getRecords().get(index)))); + try { + records.set(index, InstanceUtil.transBean2Map(queryById(ids.getRecords().get(index)))); + } finally { + thread.put(index, 0); + } } }); } - executorService.shutdown(); - try { - executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - } catch (InterruptedException e) { - logger.error("awaitTermination", "", e); + while (thread.size() < records.size()) { + try { + Thread.sleep(threadSleep); + } catch (InterruptedException e) { + logger.error("", e); + } } page.setRecords(records); return page; @@ -148,23 +157,27 @@ public Page getPage(final Page ids, final Class cls) { for (int i = 0; i < ids.getRecords().size(); i++) { records.add(null); } - int thread = Math.min(maxThread, Math.max(1, records.size() / 2)); - ExecutorService executorService = Executors.newFixedThreadPool(thread); + final Map thread = InstanceUtil.newConcurrentHashMap(); for (int i = 0; i < ids.getRecords().size(); i++) { final int index = i; executorService.execute(new Runnable() { public void run() { - T t = queryById(ids.getRecords().get(index)); - K k = InstanceUtil.to(t, cls); - records.set(index, k); + try { + T t = queryById(ids.getRecords().get(index)); + K k = InstanceUtil.to(t, cls); + records.set(index, k); + } finally { + thread.put(index, 0); + } } }); } - executorService.shutdown(); - try { - executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - } catch (InterruptedException e) { - logger.error("awaitTermination", "", e); + while (thread.size() < records.size()) { + try { + Thread.sleep(threadSleep); + } catch (InterruptedException e) { + logger.error("", e); + } } page.setRecords(records); return page; @@ -179,21 +192,25 @@ public List getList(final List ids) { for (int i = 0; i < ids.size(); i++) { list.add(null); } - int thread = Math.min(maxThread * 2, Math.max(1, list.size() / 2)); - ExecutorService executorService = Executors.newFixedThreadPool(thread); + final Map thread = InstanceUtil.newConcurrentHashMap(); for (int i = 0; i < ids.size(); i++) { final int index = i; executorService.execute(new Runnable() { public void run() { - list.set(index, queryById(ids.get(index))); + try { + list.set(index, queryById(ids.get(index))); + } finally { + thread.put(index, 0); + } } }); } - executorService.shutdown(); - try { - executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - } catch (InterruptedException e) { - logger.error("awaitTermination", "", e); + while (thread.size() < list.size()) { + try { + Thread.sleep(threadSleep); + } catch (InterruptedException e) { + logger.error("", e); + } } } return list; @@ -206,23 +223,27 @@ public List getList(final List ids, final Class cls) { for (int i = 0; i < ids.size(); i++) { list.add(null); } - int thread = Math.min(maxThread * 2, Math.max(1, list.size() / 2)); - ExecutorService executorService = Executors.newFixedThreadPool(thread); + final Map thread = InstanceUtil.newConcurrentHashMap(); for (int i = 0; i < ids.size(); i++) { final int index = i; executorService.execute(new Runnable() { public void run() { - T t = queryById(ids.get(index)); - K k = InstanceUtil.to(t, cls); - list.set(index, k); + try { + T t = queryById(ids.get(index)); + K k = InstanceUtil.to(t, cls); + list.set(index, k); + } finally { + thread.put(index, 0); + } } }); } - executorService.shutdown(); - try { - executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - } catch (InterruptedException e) { - logger.error("awaitTermination", "", e); + while (thread.size() < list.size()) { + try { + Thread.sleep(threadSleep); + } catch (InterruptedException e) { + logger.error("", e); + } } } return list; From 67a1997d4afecc3dd7d18ef23032033c3f968dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 1 Sep 2017 11:23:39 +0800 Subject: [PATCH 21/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/ibase4j/service/SysDicService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/iBase4J-SYS-Service/src/main/java/org/ibase4j/service/SysDicService.java b/iBase4J-SYS-Service/src/main/java/org/ibase4j/service/SysDicService.java index 62ba4172..a18f1085 100644 --- a/iBase4J-SYS-Service/src/main/java/org/ibase4j/service/SysDicService.java +++ b/iBase4J-SYS-Service/src/main/java/org/ibase4j/service/SysDicService.java @@ -50,9 +50,12 @@ public Map queryDicByTypeMap(Map params) { @Cacheable(value = Constants.CACHE_NAMESPACE + "sysDics") public Map queryDicByType(String key) { - Map resultMap = applicationContext.getBean(SysDicService.class).getAllDic().get(key); - if (resultMap == null) { - return InstanceUtil.newHashMap(); + Map params = InstanceUtil.newHashMap(); + params.put("type", key); + List list = queryList(params); + Map resultMap = InstanceUtil.newHashMap(); + for (SysDic sysDic : list) { + resultMap.put(sysDic.getCode(), sysDic.getCodeText()); } return resultMap; } From 4e6069f4ca8452ce2d157a5d17136011cc56c8b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Mon, 4 Sep 2017 14:41:57 +0800 Subject: [PATCH 22/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/ibase4j/core/base/BaseProviderImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java index 1ccc55c8..d400deb1 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java @@ -69,7 +69,7 @@ public Parameter execute(Parameter parameter) { return response; } logger.info("{} response empty.", no); - return null; + return new Parameter(); } catch (Exception e) { String msg = ExceptionUtil.getStackTraceAsString(e); logger.error(no + " " + Constants.Exception_Head + msg, e); From 63d38f47969b0511ba6b4bb96d02cbf16d6e946b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Thu, 7 Sep 2017 09:22:57 +0800 Subject: [PATCH 23/50] =?UTF-8?q?redis=E7=BC=93=E5=AD=98=E4=BA=8B=E5=8A=A1?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Biz-Service/src/main/resources/Spring-config.xml | 2 +- iBase4J-Common/src/main/resources/spring/redis.xml | 1 + iBase4J-SYS-Service/src/main/resources/Spring-config.xml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iBase4J-Biz-Service/src/main/resources/Spring-config.xml b/iBase4J-Biz-Service/src/main/resources/Spring-config.xml index b069810d..def38d68 100644 --- a/iBase4J-Biz-Service/src/main/resources/Spring-config.xml +++ b/iBase4J-Biz-Service/src/main/resources/Spring-config.xml @@ -36,7 +36,7 @@ - + \ No newline at end of file diff --git a/iBase4J-Common/src/main/resources/spring/redis.xml b/iBase4J-Common/src/main/resources/spring/redis.xml index 5c61517f..14a600f6 100644 --- a/iBase4J-Common/src/main/resources/spring/redis.xml +++ b/iBase4J-Common/src/main/resources/spring/redis.xml @@ -40,6 +40,7 @@ + diff --git a/iBase4J-SYS-Service/src/main/resources/Spring-config.xml b/iBase4J-SYS-Service/src/main/resources/Spring-config.xml index daba44c4..5cdb6bb8 100644 --- a/iBase4J-SYS-Service/src/main/resources/Spring-config.xml +++ b/iBase4J-SYS-Service/src/main/resources/Spring-config.xml @@ -37,7 +37,7 @@ - + From 96ec3c57cc86f617d3d4eeb20ebe01149dd89469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 8 Sep 2017 16:45:08 +0800 Subject: [PATCH 24/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=B7=BB=E5=8A=A0=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Biz-Service/pom.xml | 10 +++++ .../core/support/cache/CacheManager.java | 2 +- .../core/support/cache/RedisHelper.java | 2 +- .../core/support/cache/RedissonHelper.java | 4 +- .../core/support/scheduler/job/BaseJob.java | 45 ++++++++++++++----- iBase4J-SYS-Service/pom.xml | 10 +++++ pom.xml | 2 +- 7 files changed, 59 insertions(+), 16 deletions(-) diff --git a/iBase4J-Biz-Service/pom.xml b/iBase4J-Biz-Service/pom.xml index 832c75e0..3569ee6c 100644 --- a/iBase4J-Biz-Service/pom.xml +++ b/iBase4J-Biz-Service/pom.xml @@ -87,6 +87,11 @@ spring-jms ${spring.version} + + org.springframework.data + spring-data-redis + ${spring-data-redis.version} + org.aspectj @@ -99,6 +104,11 @@ ${aspectj.version} + + redis.clients + jedis + ${jedis.version} + org.redisson redisson diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java index 786871fc..b87b535f 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/CacheManager.java @@ -38,7 +38,7 @@ public interface CacheManager { void hdel(String key, Serializable field); - boolean setnx(String key, long value); + boolean setnx(String key, Serializable value); void sadd(String key, Serializable value); diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java index 4fb90412..2e4540b8 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java @@ -106,7 +106,7 @@ public final Object getSet(final String key, final Serializable value) { return redisTemplate.boundValueOps(key).getAndSet(value); } - public boolean setnx(String key, long value) { + public boolean setnx(String key, Serializable value) { return redisTemplate.boundValueOps(key).setIfAbsent(value); } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedissonHelper.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedissonHelper.java index 4d782acf..09658455 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedissonHelper.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedissonHelper.java @@ -151,9 +151,9 @@ public void unlock(String key) { redissonClient.getLock(key).unlock(); } - public boolean setnx(String key, long value) { + public boolean setnx(String key, Serializable value) { try { - return redissonClient.getLock(key).tryLock(value, TimeUnit.MILLISECONDS); + return redissonClient.getLock(key).tryLock(Long.valueOf(value.toString()), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { return false; } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/scheduler/job/BaseJob.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/scheduler/job/BaseJob.java index f5642724..8febfab8 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/scheduler/job/BaseJob.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/scheduler/job/BaseJob.java @@ -6,6 +6,7 @@ import org.ibase4j.core.base.BaseProvider; import org.ibase4j.core.base.Parameter; import org.ibase4j.core.support.scheduler.TaskScheduled.TaskType; +import org.ibase4j.core.util.CacheUtil; import org.ibase4j.core.util.DubboUtil; import org.quartz.Job; import org.quartz.JobDataMap; @@ -30,21 +31,43 @@ public void execute(JobExecutionContext context) throws JobExecutionException { String taskType = jobDataMap.getString("taskType"); String targetObject = jobDataMap.getString("targetObject"); String targetMethod = jobDataMap.getString("targetMethod"); + String key = targetMethod + "." + targetObject; try { - ApplicationContext applicationContext = (ApplicationContext) context.getScheduler().getContext() - .get("applicationContext"); - if (TaskType.local.equals(taskType)) { - Object refer = applicationContext.getBean(targetObject); - refer.getClass().getDeclaredMethod(targetMethod).invoke(refer); - } else if (TaskType.dubbo.equals(taskType)) { - String system = "org.ibase4j.provider.I" + jobDataMap.getString("targetSystem"); - BaseProvider provider = (BaseProvider) DubboUtil.refer(applicationContext, system); - provider.execute(new Parameter(targetObject, targetMethod)); + logger.info("定时任务[{}.{}]开始", targetObject, targetMethod); + if (CacheUtil.getCache().setnx(key, "1")) { + try { + ApplicationContext applicationContext = (ApplicationContext) context.getScheduler().getContext() + .get("applicationContext"); + if (TaskType.local.equals(taskType)) { + Object refer = applicationContext.getBean(targetObject); + refer.getClass().getDeclaredMethod(targetMethod).invoke(refer); + } else if (TaskType.dubbo.equals(taskType)) { + String system = "org.ibase4j.provider.I" + jobDataMap.getString("targetSystem"); + BaseProvider provider = (BaseProvider) DubboUtil.refer(applicationContext, system); + provider.execute(new Parameter(targetObject, targetMethod)); + } + double time = (System.currentTimeMillis() - start) / 1000.0; + logger.info("定时任务[{}.{}]用时:{}s", targetObject, targetMethod, time); + } finally { + unLock(key); + } } - double time = (System.currentTimeMillis() - start) / 1000.0; - logger.info("定时任务[{}.{}]用时:{}s", targetObject, targetMethod, time); } catch (Exception e) { throw new JobExecutionException(e); } } + + private void unLock(String key) { + try { + CacheUtil.getCache().del(key); + } catch (Exception e) { + logger.error("", e); + try { + Thread.sleep(1000); + } catch (Exception e2) { + logger.error("", e2); + } + unLock(key); + } + } } diff --git a/iBase4J-SYS-Service/pom.xml b/iBase4J-SYS-Service/pom.xml index dc3852e2..f366e227 100644 --- a/iBase4J-SYS-Service/pom.xml +++ b/iBase4J-SYS-Service/pom.xml @@ -115,6 +115,11 @@ spring-jms ${spring.version} + + org.springframework.data + spring-data-redis + ${spring-data-redis.version} + org.aspectj @@ -127,6 +132,11 @@ ${aspectj.version} + + redis.clients + jedis + ${jedis.version} + org.redisson redisson diff --git a/pom.xml b/pom.xml index 2cf8a672..946b697d 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ 3.3.4 1.1.2 - 2.5.3 + 2.5.4 1.2.36 0.3.1 From 1af220d22b77134e8caec8eb4c1b0b9a233e78e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 8 Sep 2017 16:50:59 +0800 Subject: [PATCH 25/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ibase4j/core/support/cache/redisson/Client.java | 6 +----- iBase4J-Common/src/main/resources/spring/redisson.xml | 2 +- iBase4J-SYS-Web/src/main/resources/Spring-config.xml | 1 - 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/Client.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/Client.java index acb2a634..e1cebd52 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/Client.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/redisson/Client.java @@ -10,8 +10,6 @@ import org.redisson.config.Config; import org.redisson.config.MasterSlaveServersConfig; import org.redisson.config.SingleServerConfig; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; /** * Redis连接配置 @@ -19,7 +17,6 @@ * @author ShenHuaJie * @since 2017年8月23日 上午9:36:53 */ -@Configuration public class Client { /** * Redis server address @@ -47,8 +44,7 @@ public class Client { */ private Set slaveAddresses = new HashSet(); - @Bean(name = "redissonClient") - public RedissonClient getRedissonClient() { + public RedissonClient init() { Config config = new Config(); if (StringUtils.isNotBlank(address)) { SingleServerConfig serverConfig = config.useSingleServer().setAddress(address); diff --git a/iBase4J-Common/src/main/resources/spring/redisson.xml b/iBase4J-Common/src/main/resources/spring/redisson.xml index 803a0b4b..8df82828 100644 --- a/iBase4J-Common/src/main/resources/spring/redisson.xml +++ b/iBase4J-Common/src/main/resources/spring/redisson.xml @@ -6,7 +6,7 @@ http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> - + diff --git a/iBase4J-SYS-Web/src/main/resources/Spring-config.xml b/iBase4J-SYS-Web/src/main/resources/Spring-config.xml index d36b0237..d11030ff 100644 --- a/iBase4J-SYS-Web/src/main/resources/Spring-config.xml +++ b/iBase4J-SYS-Web/src/main/resources/Spring-config.xml @@ -27,7 +27,6 @@ - From 7cec4ad20916af5bdc8612ccabaa27ee35debffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 8 Sep 2017 16:53:46 +0800 Subject: [PATCH 26/50] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Common/src/main/resources/spring/redis.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/iBase4J-Common/src/main/resources/spring/redis.xml b/iBase4J-Common/src/main/resources/spring/redis.xml index 14a600f6..41a33bb7 100644 --- a/iBase4J-Common/src/main/resources/spring/redis.xml +++ b/iBase4J-Common/src/main/resources/spring/redis.xml @@ -49,4 +49,9 @@ + + + + + \ No newline at end of file From 82fe2f81c9b970fa1fc1d9d49f185997c407792a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 8 Sep 2017 17:32:32 +0800 Subject: [PATCH 27/50] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=9B=86=E7=BE=A4?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/ibase4j/core/support/cache/RedisHelper.java | 3 +-- .../java/org/ibase4j/core/support/scheduler/job/BaseJob.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java index 2e4540b8..0713d1de 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java @@ -110,9 +110,8 @@ public boolean setnx(String key, Serializable value) { return redisTemplate.boundValueOps(key).setIfAbsent(value); } - @Deprecated public boolean lock(String key) { - throw new RuntimeException("not support."); + return redisTemplate.boundValueOps(key).setIfAbsent("0"); } public void unlock(String key) { diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/scheduler/job/BaseJob.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/scheduler/job/BaseJob.java index 8febfab8..73f67290 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/scheduler/job/BaseJob.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/scheduler/job/BaseJob.java @@ -34,7 +34,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException { String key = targetMethod + "." + targetObject; try { logger.info("定时任务[{}.{}]开始", targetObject, targetMethod); - if (CacheUtil.getCache().setnx(key, "1")) { + if (CacheUtil.getCache().lock(key)) { try { ApplicationContext applicationContext = (ApplicationContext) context.getScheduler().getContext() .get("applicationContext"); @@ -59,7 +59,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException { private void unLock(String key) { try { - CacheUtil.getCache().del(key); + CacheUtil.getCache().unlock(key); } catch (Exception e) { logger.error("", e); try { From b1a50eddcd6adbc30d7be5c14b1eb5b34c033fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 8 Sep 2017 17:38:27 +0800 Subject: [PATCH 28/50] readme --- iBase4J-UI/iBase4J-UI-DataTables/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iBase4J-UI/iBase4J-UI-DataTables/README.md b/iBase4J-UI/iBase4J-UI-DataTables/README.md index 1e2d2c62..b3c4f98d 100644 --- a/iBase4J-UI/iBase4J-UI-DataTables/README.md +++ b/iBase4J-UI/iBase4J-UI-DataTables/README.md @@ -1,4 +1,4 @@ -#iBase4J-UI-DataTables 版本UI,价格面议。有需要请与作者联系!QQ:2296277393 +#iBase4J-UI-DataTables 版本UI,基本功能齐全,价格面议。有需要请与作者联系!QQ:2296277393 主要技术:vue, dataTables, jquery, bootstrap, jquery-treetable, ztree, Select2, switchery, jquery.formautofill 等等 From f0eba505171d8802881ff82198c03ccb271cc998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 8 Sep 2017 17:43:03 +0800 Subject: [PATCH 29/50] readme --- iBase4J-UI/iBase4J-UI-DataTables/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iBase4J-UI/iBase4J-UI-DataTables/README.md b/iBase4J-UI/iBase4J-UI-DataTables/README.md index b3c4f98d..fa577a2f 100644 --- a/iBase4J-UI/iBase4J-UI-DataTables/README.md +++ b/iBase4J-UI/iBase4J-UI-DataTables/README.md @@ -1,5 +1,8 @@ -#iBase4J-UI-DataTables 版本UI,基本功能齐全,价格面议。有需要请与作者联系!QQ:2296277393 -主要技术:vue, dataTables, jquery, bootstrap, jquery-treetable, ztree, Select2, switchery, jquery.formautofill 等等 +#iBase4J-UI-DataTables 版本UI + +#基本功能齐全,价格面议。有需要请与我联系!QQ:2296277393 + +#主要技术:vue, dataTables, jquery, bootstrap, treetable, ztree, Select2, switchery, formautofill 等等 ![新版](http://git.oschina.net/iBase4J/iBase4J/raw/master/img/2D7O7AOE9DS.png "新版") From dacbc91d3a568d7e8e4a214ec21ee472124c6d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Mon, 11 Sep 2017 11:57:43 +0800 Subject: [PATCH 30/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Biz-Service/src/main/resources/log4j2.xml | 1 + .../java/org/ibase4j/core/support/dbcp/ChooseDataSource.java | 4 ++++ iBase4J-SYS-Service/src/main/resources/log4j2.xml | 1 + 3 files changed, 6 insertions(+) diff --git a/iBase4J-Biz-Service/src/main/resources/log4j2.xml b/iBase4J-Biz-Service/src/main/resources/log4j2.xml index eabec600..cb05e5e4 100644 --- a/iBase4J-Biz-Service/src/main/resources/log4j2.xml +++ b/iBase4J-Biz-Service/src/main/resources/log4j2.xml @@ -66,6 +66,7 @@ + diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/ChooseDataSource.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/ChooseDataSource.java index de816c14..4dd09ad0 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/ChooseDataSource.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/ChooseDataSource.java @@ -17,6 +17,10 @@ public class ChooseDataSource extends AbstractRoutingDataSource { public static Map> METHODTYPE = new HashMap>(); + static { + System.setProperty("druid.logType", "log4j2"); + } + // 获取数据源名称 protected Object determineCurrentLookupKey() { return HandleDataSource.getDataSource(); diff --git a/iBase4J-SYS-Service/src/main/resources/log4j2.xml b/iBase4J-SYS-Service/src/main/resources/log4j2.xml index eabec600..cb05e5e4 100644 --- a/iBase4J-SYS-Service/src/main/resources/log4j2.xml +++ b/iBase4J-SYS-Service/src/main/resources/log4j2.xml @@ -66,6 +66,7 @@ + From 23ea458c2bd154c9d68c8f902147b79c29fadffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Mon, 11 Sep 2017 11:57:55 +0800 Subject: [PATCH 31/50] =?UTF-8?q?=E7=AE=80=E5=8C=96tomcat=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 946b697d..d38aa6a2 100644 --- a/pom.xml +++ b/pom.xml @@ -354,10 +354,10 @@ 2.2 - run-war-only + run pre-integration-test - run-war-only + run From 8fbca6941adafbd7dc8a5a9d4a04cfb547aa084c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Mon, 11 Sep 2017 12:18:15 +0800 Subject: [PATCH 32/50] readme --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index f7515145..9cda3d43 100644 --- a/readme.md +++ b/readme.md @@ -36,8 +36,8 @@ * 项目依赖activemq、Redis和ZooKeeper服务。 * 使用nginx代理UI:修改配置里的UI目录后重启nginx。 * 启动命令: - clean package -P build tomcat7:run-war-only -f pom-sys-service-server.xml - clean package -P build tomcat7:run-war-only -f pom-sys-web-server.xml + clean package -P build tomcat7:run -f pom-sys-service-server.xml + clean package -P build tomcat7:run -f pom-sys-web-server.xml * 打包命令: clean package -P build -f pom-sys-service-server.xml clean package -P build -f pom-sys-service-server.xml From 32662683d57f43345f3b8ce66533ef7c72f1d655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Tue, 12 Sep 2017 12:11:24 +0800 Subject: [PATCH 33/50] =?UTF-8?q?=E4=BC=98=E5=8C=96jar=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Biz-Service/pom.xml | 16 ++---- .../src/main/resources/log4j2.xml | 1 + iBase4J-Common/pom.xml | 12 +++-- .../src/main/java/org/ibase4j/Generator.java | 2 +- .../ibase4j/core/base/BaseProviderImpl.java | 18 ------- .../org/ibase4j/core/base/BaseService.java | 10 ++++ .../core/support/dbcp/DataSourceAspect.java | 51 +++++++++++++++++++ .../java/org/ibase4j/core/util/CacheUtil.java | 2 +- iBase4J-Common/src/main/resources/log4j2.xml | 1 + iBase4J-SYS-Service/pom.xml | 17 ++----- .../src/main/resources/log4j2.xml | 1 + iBase4J-SYS-Web/pom.xml | 13 +++-- pom.xml | 29 +++++++---- 13 files changed, 111 insertions(+), 62 deletions(-) create mode 100644 iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/DataSourceAspect.java diff --git a/iBase4J-Biz-Service/pom.xml b/iBase4J-Biz-Service/pom.xml index 3569ee6c..5d7a9d25 100644 --- a/iBase4J-Biz-Service/pom.xml +++ b/iBase4J-Biz-Service/pom.xml @@ -45,22 +45,16 @@ mysql-connector-java ${mysql.version} - - - org.mybatis - mybatis - ${mybatis.version} - - - org.mybatis - mybatis-spring - ${mybatis-spring.version} - com.alibaba druid ${druid.version} + + com.baomidou + mybatis-plus + ${mybatis-plus.version} + org.springframework diff --git a/iBase4J-Biz-Service/src/main/resources/log4j2.xml b/iBase4J-Biz-Service/src/main/resources/log4j2.xml index cb05e5e4..384102b4 100644 --- a/iBase4J-Biz-Service/src/main/resources/log4j2.xml +++ b/iBase4J-Biz-Service/src/main/resources/log4j2.xml @@ -73,6 +73,7 @@ + diff --git a/iBase4J-Common/pom.xml b/iBase4J-Common/pom.xml index ae3a4596..e0257292 100644 --- a/iBase4J-Common/pom.xml +++ b/iBase4J-Common/pom.xml @@ -39,9 +39,9 @@ - org.mybatis - mybatis - ${mybatis.version} + com.baomidou + mybatis-plus + ${mybatis-plus.version} org.apache.velocity @@ -165,6 +165,12 @@ reflectasm 1.11.4-2 + + + org.apache.activemq + activemq-spring + ${activemq.version} + com.google.zxing diff --git a/iBase4J-Common/src/main/java/org/ibase4j/Generator.java b/iBase4J-Common/src/main/java/org/ibase4j/Generator.java index 00172e2e..906ee5e2 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/Generator.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/Generator.java @@ -14,7 +14,7 @@ import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; /** - * 代码生成 注意:不生成service接口 注意:不生成service接口 注意:不生成service接口 + * 代码生成 * * @author ShenHuaJie */ diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java index d400deb1..d0859d0c 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java @@ -6,8 +6,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.ibase4j.core.Constants; -import org.ibase4j.core.support.dbcp.ChooseDataSource; -import org.ibase4j.core.support.dbcp.HandleDataSource; import org.ibase4j.core.util.ExceptionUtil; import org.ibase4j.core.util.InstanceUtil; import org.springframework.beans.BeansException; @@ -35,20 +33,6 @@ public Parameter execute(Parameter parameter) { Map map = parameter.getMap(); String method = parameter.getMethod(); Object[] param = parameter.getParam(); - try { - L: for (String key : ChooseDataSource.METHODTYPE.keySet()) { - for (String type : ChooseDataSource.METHODTYPE.get(key)) { - if (method.startsWith(type)) { - logger.info(key); - HandleDataSource.putDataSource(key); - break L; - } - } - } - } catch (Exception e) { - logger.error(e); - HandleDataSource.putDataSource("write"); - } Object result = null; if (param != null) { result = InstanceUtil.invokeMethod(service, method, param); @@ -74,8 +58,6 @@ public Parameter execute(Parameter parameter) { String msg = ExceptionUtil.getStackTraceAsString(e); logger.error(no + " " + Constants.Exception_Head + msg, e); throw e; - } finally { - HandleDataSource.clear(); } } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java index 6c00e147..1d4061a7 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseService.java @@ -94,6 +94,8 @@ public Page getPage(final Page ids) { public void run() { try { records.set(index, queryById(ids.getRecords().get(index))); + } catch (Exception e) { + logger.error("", e); } finally { thread.put(index, 0); } @@ -129,6 +131,8 @@ public Page> getPageMap(final Page ids) { public void run() { try { records.set(index, InstanceUtil.transBean2Map(queryById(ids.getRecords().get(index)))); + } catch (Exception e) { + logger.error("", e); } finally { thread.put(index, 0); } @@ -166,6 +170,8 @@ public void run() { T t = queryById(ids.getRecords().get(index)); K k = InstanceUtil.to(t, cls); records.set(index, k); + } catch (Exception e) { + logger.error("", e); } finally { thread.put(index, 0); } @@ -199,6 +205,8 @@ public List getList(final List ids) { public void run() { try { list.set(index, queryById(ids.get(index))); + } catch (Exception e) { + logger.error("", e); } finally { thread.put(index, 0); } @@ -232,6 +240,8 @@ public void run() { T t = queryById(ids.get(index)); K k = InstanceUtil.to(t, cls); list.set(index, k); + } catch (Exception e) { + logger.error("", e); } finally { thread.put(index, 0); } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/DataSourceAspect.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/DataSourceAspect.java new file mode 100644 index 00000000..f8f457f4 --- /dev/null +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/dbcp/DataSourceAspect.java @@ -0,0 +1,51 @@ +package org.ibase4j.core.support.dbcp; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.After; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.ibase4j.core.base.Parameter; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.stereotype.Component; + +@Aspect +@Component +@EnableAspectJAutoProxy(proxyTargetClass = true) +public class DataSourceAspect { + private final Logger logger = LogManager.getLogger(); + + @Pointcut("this(org.ibase4j.core.base.BaseProviderImpl)") + public void aspect() { + } + + /** + * 配置前置通知,使用在方法aspect()上注册的切入点 + */ + @Before("aspect()") + public void before(JoinPoint point) { + Parameter parameter = (Parameter) point.getArgs()[0]; + String method = parameter.getMethod(); + try { + L: for (String key : ChooseDataSource.METHODTYPE.keySet()) { + for (String type : ChooseDataSource.METHODTYPE.get(key)) { + if (method.startsWith(type)) { + logger.info(key); + HandleDataSource.putDataSource(key); + break L; + } + } + } + } catch (Exception e) { + logger.error(e); + HandleDataSource.putDataSource("write"); + } + } + + @After("aspect()") + public void after(JoinPoint point) { + HandleDataSource.clear(); + } +} diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java b/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java index f93dd279..b11c326e 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java @@ -40,7 +40,7 @@ public static boolean getLock(String key) { } } int expires = 1000 * 60 * 3; - String currentValue = (String) getCache().get(key); + String currentValue = String.valueOf(getCache().get(key)); if (currentValue != null && Long.parseLong(currentValue) < System.currentTimeMillis() - expires) { unlock(key); return getLock(key); diff --git a/iBase4J-Common/src/main/resources/log4j2.xml b/iBase4J-Common/src/main/resources/log4j2.xml index a88fd8da..9644c7a0 100644 --- a/iBase4J-Common/src/main/resources/log4j2.xml +++ b/iBase4J-Common/src/main/resources/log4j2.xml @@ -61,6 +61,7 @@ + diff --git a/iBase4J-SYS-Service/pom.xml b/iBase4J-SYS-Service/pom.xml index f366e227..72b68af1 100644 --- a/iBase4J-SYS-Service/pom.xml +++ b/iBase4J-SYS-Service/pom.xml @@ -72,16 +72,10 @@ druid ${druid.version} - - org.mybatis - mybatis - ${mybatis.version} - - - org.mybatis - mybatis-spring - ${mybatis-spring.version} + com.baomidou + mybatis-plus + ${mybatis-plus.version} @@ -121,11 +115,6 @@ ${spring-data-redis.version} - - org.aspectj - aspectjrt - ${aspectj.version} - org.aspectj aspectjweaver diff --git a/iBase4J-SYS-Service/src/main/resources/log4j2.xml b/iBase4J-SYS-Service/src/main/resources/log4j2.xml index cb05e5e4..384102b4 100644 --- a/iBase4J-SYS-Service/src/main/resources/log4j2.xml +++ b/iBase4J-SYS-Service/src/main/resources/log4j2.xml @@ -73,6 +73,7 @@ + diff --git a/iBase4J-SYS-Web/pom.xml b/iBase4J-SYS-Web/pom.xml index eb82ceb6..5d3f241a 100644 --- a/iBase4J-SYS-Web/pom.xml +++ b/iBase4J-SYS-Web/pom.xml @@ -56,6 +56,11 @@ spring-data-redis ${spring-data-redis.version} + + org.aspectj + aspectjweaver + ${aspectj.version} + redis.clients @@ -123,11 +128,11 @@ springfox-swagger-ui ${springfox.version} - + - cz.mallat.uasparser - uasparser - 0.6.2 + cz.mallat.uasparser + uasparser + 0.6.2 \ No newline at end of file diff --git a/pom.xml b/pom.xml index d38aa6a2..78717b44 100644 --- a/pom.xml +++ b/pom.xml @@ -29,16 +29,15 @@ UTF-8 - 5.0.0.RC3 - 2.0.0.M2 - 2.0.0.M2 + 4.3.11.RELEASE + 1.3.1.RELEASE + 1.8.7.RELEASE 5.1.39 1.4.1 - 3.4.2 1.3.1 - 2.1-gamma + 2.1.1 1.7.9 2.8.2 @@ -60,7 +59,7 @@ 2.9.0 1.2.4 2.2.3 - 1.8.9 + 1.8.10 2.5.1 5.13.3 0.9.5 @@ -133,6 +132,16 @@ com.baomidou mybatis-plus ${mybatis-plus.version} + + + org.mybatis + mybatis-spring + + + com.github.jsqlparser + jsqlparser + + @@ -283,11 +292,11 @@ 0.10 - + com.fasterxml.jackson.core @@ -354,10 +363,10 @@ 2.2 - run + run-war-only pre-integration-test - run + run-war-only From 59dbd227902003e9e1285415e2292a7435ca11a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Tue, 12 Sep 2017 12:25:20 +0800 Subject: [PATCH 34/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/log4j2.xml | 27 ++++------------ iBase4J-Biz-Web/src/main/resources/log4j2.xml | 29 +++++------------ iBase4J-Common/src/main/resources/log4j2.xml | 31 +++++++++---------- .../src/main/resources/log4j2.xml | 27 ++++------------ iBase4J-SYS-Web/src/main/resources/log4j2.xml | 29 +++++------------ 5 files changed, 42 insertions(+), 101 deletions(-) diff --git a/iBase4J-Biz-Service/src/main/resources/log4j2.xml b/iBase4J-Biz-Service/src/main/resources/log4j2.xml index 384102b4..5d242355 100644 --- a/iBase4J-Biz-Service/src/main/resources/log4j2.xml +++ b/iBase4J-Biz-Service/src/main/resources/log4j2.xml @@ -5,7 +5,6 @@ backup ${project.artifactId} - 5M DEBUG @@ -17,23 +16,15 @@ fileName="${LOG_HOME}/dev_${SERVER_NAME}.log" filePattern="${LOG_HOME}/dev_${BACKUP_HOME}/dev_${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log"> - - - - + - - - - - - - - + + + @@ -42,10 +33,7 @@ fileName="${LOG_HOME}/dev_${SERVER_NAME}_error.log" filePattern="${LOG_HOME}/dev_${BACKUP_HOME}/dev_${SERVER_NAME}_error.%d{yyyy-MM-dd-HH}.log"> - - - - + @@ -55,10 +43,7 @@ fileName="${LOG_HOME}/${SERVER_NAME}.log" filePattern="${LOG_HOME}/${BACKUP_HOME}/${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log"> - - - - + diff --git a/iBase4J-Biz-Web/src/main/resources/log4j2.xml b/iBase4J-Biz-Web/src/main/resources/log4j2.xml index eabec600..5d242355 100644 --- a/iBase4J-Biz-Web/src/main/resources/log4j2.xml +++ b/iBase4J-Biz-Web/src/main/resources/log4j2.xml @@ -5,7 +5,6 @@ backup ${project.artifactId} - 5M DEBUG @@ -17,23 +16,15 @@ fileName="${LOG_HOME}/dev_${SERVER_NAME}.log" filePattern="${LOG_HOME}/dev_${BACKUP_HOME}/dev_${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log"> - - - - + - - - - - - - - + + + @@ -42,10 +33,7 @@ fileName="${LOG_HOME}/dev_${SERVER_NAME}_error.log" filePattern="${LOG_HOME}/dev_${BACKUP_HOME}/dev_${SERVER_NAME}_error.%d{yyyy-MM-dd-HH}.log"> - - - - + @@ -55,10 +43,7 @@ fileName="${LOG_HOME}/${SERVER_NAME}.log" filePattern="${LOG_HOME}/${BACKUP_HOME}/${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log"> - - - - + @@ -66,12 +51,14 @@ + + diff --git a/iBase4J-Common/src/main/resources/log4j2.xml b/iBase4J-Common/src/main/resources/log4j2.xml index 9644c7a0..5d242355 100644 --- a/iBase4J-Common/src/main/resources/log4j2.xml +++ b/iBase4J-Common/src/main/resources/log4j2.xml @@ -5,7 +5,6 @@ backup ${project.artifactId} - 5M DEBUG @@ -17,24 +16,24 @@ fileName="${LOG_HOME}/dev_${SERVER_NAME}.log" filePattern="${LOG_HOME}/dev_${BACKUP_HOME}/dev_${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log"> - - - - + + + + + + + - - - - + @@ -44,10 +43,7 @@ fileName="${LOG_HOME}/${SERVER_NAME}.log" filePattern="${LOG_HOME}/${BACKUP_HOME}/${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log"> - - - - + @@ -55,18 +51,19 @@ + + - - - + + - + diff --git a/iBase4J-SYS-Service/src/main/resources/log4j2.xml b/iBase4J-SYS-Service/src/main/resources/log4j2.xml index 384102b4..5d242355 100644 --- a/iBase4J-SYS-Service/src/main/resources/log4j2.xml +++ b/iBase4J-SYS-Service/src/main/resources/log4j2.xml @@ -5,7 +5,6 @@ backup ${project.artifactId} - 5M DEBUG @@ -17,23 +16,15 @@ fileName="${LOG_HOME}/dev_${SERVER_NAME}.log" filePattern="${LOG_HOME}/dev_${BACKUP_HOME}/dev_${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log"> - - - - + - - - - - - - - + + + @@ -42,10 +33,7 @@ fileName="${LOG_HOME}/dev_${SERVER_NAME}_error.log" filePattern="${LOG_HOME}/dev_${BACKUP_HOME}/dev_${SERVER_NAME}_error.%d{yyyy-MM-dd-HH}.log"> - - - - + @@ -55,10 +43,7 @@ fileName="${LOG_HOME}/${SERVER_NAME}.log" filePattern="${LOG_HOME}/${BACKUP_HOME}/${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log"> - - - - + diff --git a/iBase4J-SYS-Web/src/main/resources/log4j2.xml b/iBase4J-SYS-Web/src/main/resources/log4j2.xml index eabec600..5d242355 100644 --- a/iBase4J-SYS-Web/src/main/resources/log4j2.xml +++ b/iBase4J-SYS-Web/src/main/resources/log4j2.xml @@ -5,7 +5,6 @@ backup ${project.artifactId} - 5M DEBUG @@ -17,23 +16,15 @@ fileName="${LOG_HOME}/dev_${SERVER_NAME}.log" filePattern="${LOG_HOME}/dev_${BACKUP_HOME}/dev_${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log"> - - - - + - - - - - - - - + + + @@ -42,10 +33,7 @@ fileName="${LOG_HOME}/dev_${SERVER_NAME}_error.log" filePattern="${LOG_HOME}/dev_${BACKUP_HOME}/dev_${SERVER_NAME}_error.%d{yyyy-MM-dd-HH}.log"> - - - - + @@ -55,10 +43,7 @@ fileName="${LOG_HOME}/${SERVER_NAME}.log" filePattern="${LOG_HOME}/${BACKUP_HOME}/${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log"> - - - - + @@ -66,12 +51,14 @@ + + From 5f0585c80de27fc06e46363fdd687cfbb5c2c8bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Tue, 12 Sep 2017 12:33:03 +0800 Subject: [PATCH 35/50] =?UTF-8?q?fastDFS=E6=96=87=E4=BB=B6=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/config/system.properties | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/iBase4J-Common/src/main/resources/config/system.properties b/iBase4J-Common/src/main/resources/config/system.properties index f107da1a..7d0fadc8 100644 --- a/iBase4J-Common/src/main/resources/config/system.properties +++ b/iBase4J-Common/src/main/resources/config/system.properties @@ -16,17 +16,17 @@ rpc.consumer.retries=2 redis.host=127.0.0.1 redis.port=6379 redis.password= -#最小空闲数 +#\u6700\u5c0f\u7a7a\u95f2\u6570 redis.minIdle=2 -#最大空闲数 +#\u6700\u5927\u7a7a\u95f2\u6570 redis.maxIdle=10 -#最大连接数 +#\u6700\u5927\u8fde\u63a5\u6570 redis.maxTotal=100 -#最大建立连接等待时间 +#\u6700\u5927\u5efa\u7acb\u8fde\u63a5\u7b49\u5f85\u65f6\u95f4 redis.maxWaitMillis=1000 -#客户端超时时间单位是毫秒 +#\u5ba2\u6237\u7aef\u8d85\u65f6\u65f6\u95f4\u5355\u4f4d\u662f\u6beb\u79d2 redis.timeout=120000 -#明是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个 +#\u660e\u662f\u5426\u5728\u4ece\u6c60\u4e2d\u53d6\u51fa\u8fde\u63a5\u524d\u8fdb\u884c\u68c0\u9a8c,\u5982\u679c\u68c0\u9a8c\u5931\u8d25,\u5219\u4ece\u6c60\u4e2d\u53bb\u9664\u8fde\u63a5\u5e76\u5c1d\u8bd5\u53d6\u51fa\u53e6\u4e00\u4e2a redis.testOnBorrow=true redis.expiration=600 #rediscluster @@ -48,23 +48,12 @@ sftp.timeout=5000 sftp.aliveMax=10 sftp.baseDir=/user/iBase4J/ sftp.nginx.path=http://localhost/ +# fastDFS nginx +remote.file.uri.prefix=http://localhost/ # email.smtp.host=smtp.126.com email.send.from=iBase4J,iBase4J@126.com email.user.name=iBase4J email.user.password=a123456 email.authorisation.code=iBase4J -# -fastDFS.connect_timeout=5 -fastDFS.network_timeout=30 -fastDFS.charset=UTF-8 -fastDFS.http.tracker_http_port=8080 -fastDFS.http.anti_steal_token=no -fastDFS.http.secret_key=FastDFS1234567890 -fastDFS.tracker_server=192.168.5.100:22122 - -fastDHT.network_timeout=30 -fastDHT.charset = UTF-8 -fastDHT.keep_alive=1 -fastDHT.group_count=1 -fastDHT.group0=192.168.1.37:11411 \ No newline at end of file +# \ No newline at end of file From 740ebe59b0f8f2d859fee48916492aeff3254567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Tue, 12 Sep 2017 15:10:18 +0800 Subject: [PATCH 36/50] =?UTF-8?q?APP=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/ibase4j/web/LoginController.java | 2 +- .../main/java/org/ibase4j/core/filter/TokenFilter.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java b/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java index 9efea753..e5c34fdf 100644 --- a/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java +++ b/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java @@ -83,7 +83,7 @@ public Object login(Login user, ModelMap modelMap, HttpServletRequest request) { if (success) { request.setAttribute("msg", "[" + user.getAccount() + "]登录成功."); String token = SecurityUtil.encryptPassword(user.getAccount() + DateUtil.getDateTime("yyyyMMddHHmmss")); - TokenUtil.setTokenInfo(token, user.getAccount()); + TokenUtil.setTokenInfo(uuid, user.getAccount()); modelMap.put("token", token); return setSuccessModelMap(modelMap); } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/filter/TokenFilter.java b/iBase4J-Common/src/main/java/org/ibase4j/core/filter/TokenFilter.java index 4b8591d9..92cd4b46 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/filter/TokenFilter.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/filter/TokenFilter.java @@ -55,15 +55,15 @@ public void doFilter(ServletRequest servletRequest, ServletResponse response, Fi if (isWhiteReq(request.getRequestURI())) { chain.doFilter(request, response); } else { - String token = request.getHeader("UUID"); - if (StringUtils.isNotBlank(token)) { + String uuid = request.getHeader("UUID"); + if (StringUtils.isNotBlank(uuid)) { try { - Token tokenInfo = TokenUtil.getTokenInfo(token); + Token tokenInfo = TokenUtil.getTokenInfo(uuid); if (tokenInfo != null) { Long now = System.currentTimeMillis(); if (now - tokenInfo.getTime() < 1000 * 60 * 30) { String value = tokenInfo.getValue(); - TokenUtil.setTokenInfo(token, value); + TokenUtil.setTokenInfo(uuid, value); WebUtil.saveCurrentUser(request, value); } } From 069f3ef0894b6ccf47a3d5ed0f0d061a89686ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Tue, 12 Sep 2017 15:19:17 +0800 Subject: [PATCH 37/50] =?UTF-8?q?APP=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/ibase4j/web/LoginController.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java b/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java index e5c34fdf..3fde68b5 100644 --- a/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java +++ b/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java @@ -82,9 +82,7 @@ public Object login(Login user, ModelMap modelMap, HttpServletRequest request) { if (success) { request.setAttribute("msg", "[" + user.getAccount() + "]登录成功."); - String token = SecurityUtil.encryptPassword(user.getAccount() + DateUtil.getDateTime("yyyyMMddHHmmss")); TokenUtil.setTokenInfo(uuid, user.getAccount()); - modelMap.put("token", token); return setSuccessModelMap(modelMap); } request.setAttribute("msg", "[" + user.getAccount() + "]登录失败."); @@ -95,9 +93,9 @@ public Object login(Login user, ModelMap modelMap, HttpServletRequest request) { @ApiOperation(value = "用户登出") @PostMapping("app/logout") public Object logout(HttpServletRequest request, ModelMap modelMap) { - String token = request.getHeader("token"); - if (StringUtils.isNotBlank(token)) { - TokenUtil.delToken(token); + String uuid = request.getHeader("UUID"); + if (StringUtils.isNotBlank(uuid)) { + TokenUtil.delToken(uuid); } return setSuccessModelMap(modelMap); } From 29179afb247e70713eddc5dff6ecab32d149d622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Tue, 12 Sep 2017 18:55:29 +0800 Subject: [PATCH 38/50] =?UTF-8?q?dubbo=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 78717b44..cbd9bcdd 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ 3.3.4 1.1.2 - 2.5.4 + 2.5.5 1.2.36 0.3.1 From 535f23527cf4c7f5e65d9b673aef15b4747db4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Wed, 13 Sep 2017 20:01:53 +0800 Subject: [PATCH 39/50] =?UTF-8?q?DUBBO=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Common/pom.xml | 4 ++-- iBase4J-Common/src/main/java/org/ibase4j/Generator.java | 1 + .../src/main/resources/config/system.properties | 8 ++++---- iBase4J-Common/src/main/resources/log4j2.xml | 1 - readme.md | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/iBase4J-Common/pom.xml b/iBase4J-Common/pom.xml index e0257292..9f3e90cb 100644 --- a/iBase4J-Common/pom.xml +++ b/iBase4J-Common/pom.xml @@ -45,8 +45,8 @@ org.apache.velocity - velocity - 1.7 + velocity-engine-core + 2.0 diff --git a/iBase4J-Common/src/main/java/org/ibase4j/Generator.java b/iBase4J-Common/src/main/java/org/ibase4j/Generator.java index 906ee5e2..7eab6257 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/Generator.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/Generator.java @@ -57,6 +57,7 @@ public static void main(String[] args) { // strategy.setTablePrefix("sys_");// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 strategy.setInclude(new String[] { "sys_user" }); // 需要生成的表 + strategy.setTablePrefix(new String[] { "sys_" });// 此处可以修改为您的表前缀 // strategy.setExclude(new String[]{"test"}); // 排除生成的表 // 自定义实体父类 strategy.setSuperEntityClass("org.ibase4j.core.base.BaseModel"); diff --git a/iBase4J-Common/src/main/resources/config/system.properties b/iBase4J-Common/src/main/resources/config/system.properties index 7d0fadc8..a1e09139 100644 --- a/iBase4J-Common/src/main/resources/config/system.properties +++ b/iBase4J-Common/src/main/resources/config/system.properties @@ -21,10 +21,10 @@ redis.minIdle=2 #\u6700\u5927\u7a7a\u95f2\u6570 redis.maxIdle=10 #\u6700\u5927\u8fde\u63a5\u6570 -redis.maxTotal=100 -#\u6700\u5927\u5efa\u7acb\u8fde\u63a5\u7b49\u5f85\u65f6\u95f4 -redis.maxWaitMillis=1000 -#\u5ba2\u6237\u7aef\u8d85\u65f6\u65f6\u95f4\u5355\u4f4d\u662f\u6beb\u79d2 +redis.maxTotal=1000 +#\u6700\u5927\u5efa\u7acb\u8fde\u63a5\u7b49\u5f85\u65f6\u95f4 +redis.maxWaitMillis=3000 +#\u5ba2\u6237\u7aef\u8d85\u65f6\u65f6\u95f4\u5355\u4f4d\u662f\u6beb\u79d2 redis.timeout=120000 #\u660e\u662f\u5426\u5728\u4ece\u6c60\u4e2d\u53d6\u51fa\u8fde\u63a5\u524d\u8fdb\u884c\u68c0\u9a8c,\u5982\u679c\u68c0\u9a8c\u5931\u8d25,\u5219\u4ece\u6c60\u4e2d\u53bb\u9664\u8fde\u63a5\u5e76\u5c1d\u8bd5\u53d6\u51fa\u53e6\u4e00\u4e2a redis.testOnBorrow=true diff --git a/iBase4J-Common/src/main/resources/log4j2.xml b/iBase4J-Common/src/main/resources/log4j2.xml index 5d242355..8b46f40c 100644 --- a/iBase4J-Common/src/main/resources/log4j2.xml +++ b/iBase4J-Common/src/main/resources/log4j2.xml @@ -58,7 +58,6 @@ - diff --git a/readme.md b/readme.md index 9cda3d43..f7515145 100644 --- a/readme.md +++ b/readme.md @@ -36,8 +36,8 @@ * 项目依赖activemq、Redis和ZooKeeper服务。 * 使用nginx代理UI:修改配置里的UI目录后重启nginx。 * 启动命令: - clean package -P build tomcat7:run -f pom-sys-service-server.xml - clean package -P build tomcat7:run -f pom-sys-web-server.xml + clean package -P build tomcat7:run-war-only -f pom-sys-service-server.xml + clean package -P build tomcat7:run-war-only -f pom-sys-web-server.xml * 打包命令: clean package -P build -f pom-sys-service-server.xml clean package -P build -f pom-sys-service-server.xml From 0450d9992ff77f94a9d4c317b1cec0065ca893ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 15 Sep 2017 17:21:36 +0800 Subject: [PATCH 40/50] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbiz=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/Spring-config.xml | 4 ++-- iBase4J-Biz-Web/pom.xml | 6 ++++++ .../src/main/resources/Spring-config.xml | 15 +++++++-------- iBase4J-SYS-Service/pom.xml | 8 +++----- iBase4J-SYS-Web/pom.xml | 8 +++----- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/iBase4J-Biz-Service/src/main/resources/Spring-config.xml b/iBase4J-Biz-Service/src/main/resources/Spring-config.xml index def38d68..7ea4e56b 100644 --- a/iBase4J-Biz-Service/src/main/resources/Spring-config.xml +++ b/iBase4J-Biz-Service/src/main/resources/Spring-config.xml @@ -34,8 +34,8 @@ - - + + diff --git a/iBase4J-Biz-Web/pom.xml b/iBase4J-Biz-Web/pom.xml index 0f726253..12481da8 100644 --- a/iBase4J-Biz-Web/pom.xml +++ b/iBase4J-Biz-Web/pom.xml @@ -7,6 +7,7 @@ 1.1.0 iBase4J-Biz-Web + iBase4J-Biz-Web war @@ -63,6 +64,11 @@ spring-data-redis ${spring-data-redis.version} + + org.aspectj + aspectjweaver + ${aspectj.version} + redis.clients diff --git a/iBase4J-Biz-Web/src/main/resources/Spring-config.xml b/iBase4J-Biz-Web/src/main/resources/Spring-config.xml index dd893a74..3ecd5dd0 100644 --- a/iBase4J-Biz-Web/src/main/resources/Spring-config.xml +++ b/iBase4J-Biz-Web/src/main/resources/Spring-config.xml @@ -20,26 +20,25 @@ - ${project.artifactId} + ${project.artifactId} 1${server.port} - - - - + + + - - + + diff --git a/iBase4J-SYS-Service/pom.xml b/iBase4J-SYS-Service/pom.xml index 72b68af1..a54cf76f 100644 --- a/iBase4J-SYS-Service/pom.xml +++ b/iBase4J-SYS-Service/pom.xml @@ -2,16 +2,14 @@ 4.0.0 - iBase4J-SYS-Service - iBase4J-SYS-Service - http://maven.apache.org - war - org.ibase4j iBase4J 1.1.0 + iBase4J-SYS-Service + iBase4J-SYS-Service + war 8085 diff --git a/iBase4J-SYS-Web/pom.xml b/iBase4J-SYS-Web/pom.xml index 5d3f241a..11825ac3 100644 --- a/iBase4J-SYS-Web/pom.xml +++ b/iBase4J-SYS-Web/pom.xml @@ -2,16 +2,14 @@ 4.0.0 - iBase4J-SYS-Web - iBase4J-SYS-Web - war - http://maven.apache.org - org.ibase4j iBase4J 1.1.0 + iBase4J-SYS-Web + iBase4J-SYS-Web + war 8088 From e9ade981421af374b9d42dfe4cac3c83d4fb7007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Sat, 16 Sep 2017 21:47:23 +0800 Subject: [PATCH 41/50] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AF=86=E7=A0=81bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/ibase4j/web/SysUserController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java index 0094b163..55fa3123 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java @@ -165,8 +165,7 @@ public Object updatePassword(ModelMap modelMap, @RequestBody SysUser param) { if (!sysUser.getPassword().equals(encryptPassword)) { throw new UnauthorizedException("原密码错误."); } - param.setPassword(encryptPassword); - param.setUpdateBy(getCurrUser()); + param.setPassword(SecurityUtil.encryptPassword(param.getPassword())); return super.update(modelMap, param); } } From 4f3ee56acc89234a73303e89df217b77edc3f07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Sat, 16 Sep 2017 21:52:43 +0800 Subject: [PATCH 42/50] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-SYS-Facade/src/main/java/org/ibase4j/model/SysMenu.java | 1 + 1 file changed, 1 insertion(+) diff --git a/iBase4J-SYS-Facade/src/main/java/org/ibase4j/model/SysMenu.java b/iBase4J-SYS-Facade/src/main/java/org/ibase4j/model/SysMenu.java index 6c891bd3..c3d142f7 100644 --- a/iBase4J-SYS-Facade/src/main/java/org/ibase4j/model/SysMenu.java +++ b/iBase4J-SYS-Facade/src/main/java/org/ibase4j/model/SysMenu.java @@ -32,6 +32,7 @@ public SysMenu(String request, String menuName) { private Boolean expand; private Integer sortNo; + @TableField("is_show") private Boolean isShow; @TableField("permission_") From 8827dbc1a7390d0242f28be633c846fa23270371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Sun, 17 Sep 2017 08:15:42 +0800 Subject: [PATCH 43/50] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/ibase4j/web/SysUserController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java index 55fa3123..d9011503 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java @@ -165,7 +165,7 @@ public Object updatePassword(ModelMap modelMap, @RequestBody SysUser param) { if (!sysUser.getPassword().equals(encryptPassword)) { throw new UnauthorizedException("原密码错误."); } - param.setPassword(SecurityUtil.encryptPassword(param.getPassword())); - return super.update(modelMap, param); + sysUser.setPassword(SecurityUtil.encryptPassword(param.getPassword())); + return super.update(modelMap, sysUser); } } From cb82d51ab5d6bd2c7a372c19b2d8bf9bd418b5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Sun, 17 Sep 2017 10:59:09 +0800 Subject: [PATCH 44/50] =?UTF-8?q?=E4=BC=98=E5=8C=96redis=E7=BC=93=E5=AD=98?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=90=AF=E7=94=A8=E4=BA=8B=E5=8A=A1?= =?UTF-8?q?=E6=97=B6=E8=8E=B7=E5=8F=96=E9=94=81=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/support/cache/RedisHelper.java | 264 +++++++++--------- 1 file changed, 137 insertions(+), 127 deletions(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java index 0713d1de..2d3915ee 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java @@ -8,7 +8,10 @@ import org.ibase4j.core.util.CacheUtil; import org.ibase4j.core.util.InstanceUtil; import org.ibase4j.core.util.PropertiesUtil; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.core.RedisConnectionUtils; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.RedisSerializer; /** * Redis缓存辅助类 @@ -17,130 +20,137 @@ * @version 2016年4月2日 下午4:17:22 */ public final class RedisHelper implements CacheManager { - private RedisTemplate redisTemplate; - private final Integer EXPIRE = PropertiesUtil.getInt("redis.expiration"); - - public void setRedisTemplate(RedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - CacheUtil.setCacheManager(this); - } - - public final Object get(final String key) { - expire(key, EXPIRE); - return redisTemplate.boundValueOps(key).get(); - } - - public final Set getAll(final String pattern) { - Set values = InstanceUtil.newHashSet(); - Set keys = redisTemplate.keys(pattern); - for (Serializable key : keys) { - expire(key.toString(), EXPIRE); - values.add(redisTemplate.opsForValue().get(key)); - } - return values; - } - - public final void set(final String key, final Serializable value, int seconds) { - redisTemplate.boundValueOps(key).set(value); - expire(key, seconds); - } - - public final void set(final String key, final Serializable value) { - redisTemplate.boundValueOps(key).set(value); - expire(key, EXPIRE); - } - - public final Boolean exists(final String key) { - return redisTemplate.hasKey(key); - } - - public final void del(final String key) { - redisTemplate.delete(key); - } - - public final void delAll(final String pattern) { - redisTemplate.delete(redisTemplate.keys(pattern)); - } - - public final String type(final String key) { - expire(key, EXPIRE); - return redisTemplate.type(key).getClass().getName(); - } - - /** - * 在某段时间后失效 - * - * @return - */ - public final Boolean expire(final String key, final int seconds) { - return redisTemplate.expire(key, seconds, TimeUnit.SECONDS); - } - - /** - * 在某个时间点失效 - * - * @param key - * @param unixTime - * @return - */ - public final Boolean expireAt(final String key, final long unixTime) { - return redisTemplate.expireAt(key, new Date(unixTime)); - } - - public final Long ttl(final String key) { - return redisTemplate.getExpire(key, TimeUnit.SECONDS); - } - - public final void setrange(final String key, final long offset, final String value) { - redisTemplate.boundValueOps(key).set(value, offset); - expire(key, EXPIRE); - } - - public final String getrange(final String key, final long startOffset, final long endOffset) { - expire(key, EXPIRE); - return redisTemplate.boundValueOps(key).get(startOffset, endOffset); - } - - public final Object getSet(final String key, final Serializable value) { - expire(key, EXPIRE); - return redisTemplate.boundValueOps(key).getAndSet(value); - } - - public boolean setnx(String key, Serializable value) { - return redisTemplate.boundValueOps(key).setIfAbsent(value); - } - - public boolean lock(String key) { - return redisTemplate.boundValueOps(key).setIfAbsent("0"); - } - - public void unlock(String key) { - del(key); - } - - public void hset(String key, Serializable field, Serializable value) { - redisTemplate.boundHashOps(key).put(field, value); - } - - public Object hget(String key, Serializable field) { - return redisTemplate.boundHashOps(key).get(field); - } - - public void hdel(String key, Serializable field) { - redisTemplate.boundHashOps(key).delete(field); - } - - public void sadd(String key, Serializable value) { - redisTemplate.boundSetOps(key).add(value); - } - - public Set sall(String key) { - return redisTemplate.boundSetOps(key).members(); - } - - public boolean sdel(String key, Serializable value) { - return redisTemplate.boundSetOps(key).remove(value) == 1; - } - - // 未完,待续... -} \ No newline at end of file + private RedisTemplate redisTemplate; + private RedisConnection redisConnection; + private RedisSerializer keySerializer; + private RedisSerializer valueSerializer; + private final Integer EXPIRE = PropertiesUtil.getInt("redis.expiration"); + + @SuppressWarnings("unchecked") + public void setRedisTemplate(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + this.redisConnection = RedisConnectionUtils.getConnection(redisTemplate.getConnectionFactory()); + this.keySerializer = (RedisSerializer)redisTemplate.getKeySerializer(); + this.valueSerializer = (RedisSerializer)redisTemplate.getValueSerializer(); + CacheUtil.setCacheManager(this); + } + + public final Object get(final String key) { + expire(key, EXPIRE); + return redisTemplate.boundValueOps(key).get(); + } + + public final Set getAll(final String pattern) { + Set values = InstanceUtil.newHashSet(); + Set keys = redisTemplate.keys(pattern); + for (Serializable key : keys) { + expire(key.toString(), EXPIRE); + values.add(redisTemplate.opsForValue().get(key)); + } + return values; + } + + public final void set(final String key, final Serializable value, int seconds) { + redisTemplate.boundValueOps(key).set(value); + expire(key, seconds); + } + + public final void set(final String key, final Serializable value) { + redisTemplate.boundValueOps(key).set(value); + expire(key, EXPIRE); + } + + public final Boolean exists(final String key) { + return redisTemplate.hasKey(key); + } + + public final void del(final String key) { + redisTemplate.delete(key); + } + + public final void delAll(final String pattern) { + redisTemplate.delete(redisTemplate.keys(pattern)); + } + + public final String type(final String key) { + expire(key, EXPIRE); + return redisTemplate.type(key).getClass().getName(); + } + + /** + * 在某段时间后失效 + * + * @return + */ + public final Boolean expire(final String key, final int seconds) { + return redisTemplate.expire(key, seconds, TimeUnit.SECONDS); + } + + /** + * 在某个时间点失效 + * + * @param key + * @param unixTime + * @return + */ + public final Boolean expireAt(final String key, final long unixTime) { + return redisTemplate.expireAt(key, new Date(unixTime)); + } + + public final Long ttl(final String key) { + return redisTemplate.getExpire(key, TimeUnit.SECONDS); + } + + public final void setrange(final String key, final long offset, final String value) { + redisTemplate.boundValueOps(key).set(value, offset); + expire(key, EXPIRE); + } + + public final String getrange(final String key, final long startOffset, final long endOffset) { + expire(key, EXPIRE); + return redisTemplate.boundValueOps(key).get(startOffset, endOffset); + } + + public final Object getSet(final String key, final Serializable value) { + expire(key, EXPIRE); + return redisTemplate.boundValueOps(key).getAndSet(value); + } + + public boolean setnx(String key, Serializable value) { + return redisConnection.setNX(keySerializer.serialize(key), valueSerializer.serialize(value)); + } + + public boolean lock(String key) { + return redisConnection.setNX(keySerializer.serialize(key), valueSerializer.serialize("0")); + } + + public void unlock(String key) { + del(key); + } + + public void hset(String key, Serializable field, Serializable value) { + redisTemplate.boundHashOps(key).put(field, value); + } + + public Object hget(String key, Serializable field) { + return redisTemplate.boundHashOps(key).get(field); + } + + public void hdel(String key, Serializable field) { + redisTemplate.boundHashOps(key).delete(field); + } + + public void sadd(String key, Serializable value) { + redisTemplate.boundSetOps(key).add(value); + } + + public Set sall(String key) { + return redisTemplate.boundSetOps(key).members(); + } + + public boolean sdel(String key, Serializable value) { + return redisTemplate.boundSetOps(key).remove(value) == 1; + } + + // 未完,待续... +} From 7cedbba92964b5c8ee780d2707a0d16eb234ffbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Sun, 17 Sep 2017 21:31:01 +0800 Subject: [PATCH 45/50] =?UTF-8?q?mybatis-plus=E7=A8=B3=E5=AE=9A=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cbd9bcdd..b585ea09 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ 1.4.1 1.3.1 - 2.1.1 + 2.1-gamma 1.7.9 2.8.2 From 4d87bbf5c7d24938c688769edc7b8b4b1bfbb407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Mon, 18 Sep 2017 11:08:25 +0800 Subject: [PATCH 46/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ibase4j/core/util/InstanceUtil.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/util/InstanceUtil.java b/iBase4J-Common/src/main/java/org/ibase4j/core/util/InstanceUtil.java index b83a403a..c76a5a72 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/util/InstanceUtil.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/util/InstanceUtil.java @@ -27,6 +27,8 @@ import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.ibase4j.core.exception.DataParseException; import org.ibase4j.core.exception.InstanceException; @@ -39,6 +41,8 @@ * @since 2012-07-18 */ public final class InstanceUtil { + protected static Logger logger = LogManager.getLogger(InstanceUtil.class); + private InstanceUtil() { } @@ -53,6 +57,17 @@ public static final T to(Object orig, Class clazz) { return bean; } + public static T transMap2Bean(Map map, Class clazz) { + T bean = null; + try { + bean = clazz.newInstance(); + transMap2Bean(map, bean); + } catch (Exception e) { + logger.error("transMap2Bean Error ", e); + } + return bean; + } + // Map --> Bean 1: 利用Introspector,PropertyDescriptor实现 Map --> Bean public static void transMap2Bean(Map map, Object obj) { try { @@ -64,11 +79,11 @@ public static void transMap2Bean(Map map, Object obj) { Object value = map.get(key); // 得到property对应的setter方法 Method setter = property.getWriteMethod(); - setter.invoke(obj, value); + setter.invoke(obj, TypeParseUtil.convert(value, property.getPropertyType(), null)); } } } catch (Exception e) { - System.out.println("transMap2Bean Error " + e); + logger.error("transMap2Bean Error ", e); } return; } @@ -93,7 +108,7 @@ public static Map transBean2Map(Object obj) { } } } catch (Exception e) { - System.out.println("transBean2Map Error " + e); + logger.error("transMap2Bean Error ", e); } return map; } From cb3ed11f584ea6f2c8c602dd580fd65ca81702d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Tue, 19 Sep 2017 11:31:59 +0800 Subject: [PATCH 47/50] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BC=A0=E5=8F=82?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1Parameter,=E4=BF=9D=E7=95=99=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=85=A5=E5=8F=82=E4=B8=80=E4=B8=AA=E5=87=BA=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/ibase4j/core/shiro/Realm.java | 16 +- .../java/org/ibase4j/web/LoginController.java | 6 +- .../ibase4j/core/base/AbstractController.java | 92 ++-- .../ibase4j/core/base/BaseProviderImpl.java | 32 +- .../java/org/ibase4j/core/base/Parameter.java | 208 ++++----- .../core/interceptor/EventInterceptor.java | 2 +- .../core/support/cache/RedisHelper.java | 39 +- .../java/org/ibase4j/core/util/CacheUtil.java | 2 +- .../java/org/ibase4j/core/shiro/Realm.java | 18 +- .../java/org/ibase4j/web/LoginController.java | 2 +- .../org/ibase4j/web/ScheduledController.java | 16 +- .../org/ibase4j/web/SearchController.java | 4 +- .../ibase4j/web/SysAuthorizeController.java | 399 +++++++++--------- .../ibase4j/web/SysEmailConfigController.java | 4 +- .../org/ibase4j/web/SysMenuController.java | 8 +- .../org/ibase4j/web/SysUserController.java | 16 +- .../web/ThirdPartyLoginController.java | 12 +- 17 files changed, 420 insertions(+), 456 deletions(-) diff --git a/iBase4J-Biz-Web/src/main/java/org/ibase4j/core/shiro/Realm.java b/iBase4J-Biz-Web/src/main/java/org/ibase4j/core/shiro/Realm.java index 0a2fd951..89f9813f 100644 --- a/iBase4J-Biz-Web/src/main/java/org/ibase4j/core/shiro/Realm.java +++ b/iBase4J-Biz-Web/src/main/java/org/ibase4j/core/shiro/Realm.java @@ -46,9 +46,9 @@ public class Realm extends AuthorizingRealm { protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); Long userId = (Long) WebUtil.getCurrentUser(); - Parameter parameter = new Parameter("sysAuthorizeService", "queryPermissionByUserId").setId(userId); + Parameter parameter = new Parameter("sysAuthorizeService", "queryPermissionByUserId", userId); logger.info("{} execute queryPermissionByUserId start...", parameter.getNo()); - List list = provider.execute(parameter).getList(); + List list = provider.execute(parameter).getResultList(); logger.info("{} execute queryPermissionByUserId end.", parameter.getNo()); for (Object permission : list) { if (StringUtils.isNotBlank((String) permission)) { @@ -68,9 +68,9 @@ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcTo Map params = new HashMap(); params.put("enable", 1); params.put("account", token.getUsername()); - Parameter parameter = new Parameter("sysUserService", "queryList").setMap(params); + Parameter parameter = new Parameter("sysUserService", "queryList", params); logger.info("{} execute sysUserService.queryList start...", parameter.getNo()); - List list = provider.execute(parameter).getList(); + List list = provider.execute(parameter).getResultList(); logger.info("{} execute sysUserService.queryList end.", parameter.getNo()); if (list.size() == 1) { SysUser user = (SysUser) list.get(0); @@ -98,9 +98,9 @@ private void saveSession(String account, String host) { // 踢出用户 SysSession record = new SysSession(); record.setAccount(account); - Parameter parameter = new Parameter("sysSessionService", "querySessionIdByAccount").setModel(record); + Parameter parameter = new Parameter("sysSessionService", "querySessionIdByAccount", record); logger.info("{} execute querySessionIdByAccount start...", parameter.getNo()); - List sessionIds = provider.execute(parameter).getList(); + List sessionIds = provider.execute(parameter).getResultList(); logger.info("{} execute querySessionIdByAccount end.", parameter.getNo()); Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); @@ -108,7 +108,7 @@ private void saveSession(String account, String host) { if (sessionIds != null) { for (Object sessionId : sessionIds) { record.setSessionId((String) sessionId); - parameter = new Parameter("sysSessionService", "deleteBySessionId").setModel(record); + parameter = new Parameter("sysSessionService", "deleteBySessionId", record); logger.info("{} execute deleteBySessionId start...", parameter.getNo()); provider.execute(parameter); logger.info("{} execute deleteBySessionId end.", parameter.getNo()); @@ -122,7 +122,7 @@ private void saveSession(String account, String host) { record.setSessionId(currentSessionId); record.setIp(StringUtils.isBlank(host) ? session.getHost() : host); record.setStartTime(session.getStartTimestamp()); - parameter = new Parameter("sysSessionService", "update").setModel(record); + parameter = new Parameter("sysSessionService", "update", record); logger.info("{} execute sysSessionService.update start...", parameter.getNo()); provider.execute(parameter); logger.info("{} execute sysSessionService.update end.", parameter.getNo()); diff --git a/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java b/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java index 3fde68b5..1a28a7cf 100644 --- a/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java +++ b/iBase4J-Biz-Web/src/main/java/org/ibase4j/web/LoginController.java @@ -69,8 +69,8 @@ public Object login(Login user, ModelMap modelMap, HttpServletRequest request) { params.put("countSql", 0); params.put("enable", 1); params.put("loginKey", user.getAccount()); // 登录帐号/手机号/邮箱 - Parameter parameter = new Parameter(getService(), "query").setMap(params); - Page pageInfo = provider.execute(parameter).getPage(); + Parameter parameter = new Parameter(getService(), "query", params); + Page pageInfo = provider.execute(parameter).getResultPage(); if (pageInfo.getTotal() == 1) { SysUser sysUser = (SysUser) pageInfo.getRecords().get(0); if (user.getPassword().equals(SecurityUtil.encryptPassword(user.getPassword()))) { @@ -107,7 +107,7 @@ public Object regin(ModelMap modelMap, @RequestBody SysUser sysUser) { Assert.notNull(sysUser.getAccount(), "ACCOUNT"); Assert.notNull(sysUser.getPassword(), "PASSWORD"); sysUser.setPassword(SecurityUtil.encryptPassword(sysUser.getPassword())); - provider.execute(new Parameter("sysUserService", "update").setModel(sysUser)); + provider.execute(new Parameter("sysUserService", "update", sysUser)); try { String token = SecurityUtil.encryptPassword(sysUser.getAccount() + DateUtil.getDateTime("yyyyMMddHHmmss")); TokenUtil.setTokenInfo(token, sysUser.getAccount()); diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/AbstractController.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/AbstractController.java index cc2ed260..2a8e32b4 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/AbstractController.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/AbstractController.java @@ -21,56 +21,56 @@ * @version 2016年5月20日 下午3:47:58 */ public abstract class AbstractController extends BaseController { - protected final Logger logger = LogManager.getLogger(this.getClass()); - @Autowired - protected T provider; + protected final Logger logger = LogManager.getLogger(this.getClass()); + @Autowired + protected T provider; - public abstract String getService(); + public abstract String getService(); - public Object query(ModelMap modelMap, Map param) { - Parameter parameter = new Parameter(getService(), "query").setMap(param); - logger.info("{} execute query start...", parameter.getNo()); - Page list = provider.execute(parameter).getPage(); - logger.info("{} execute query end.", parameter.getNo()); - return setSuccessModelMap(modelMap, list); - } + public Object query(ModelMap modelMap, Map param) { + Parameter parameter = new Parameter(getService(), "query", param); + logger.info("{} execute query start...", parameter.getNo()); + Page list = (Page) provider.execute(parameter).getResult(); + logger.info("{} execute query end.", parameter.getNo()); + return setSuccessModelMap(modelMap, list); + } - public Object queryList(ModelMap modelMap, Map param) { - Parameter parameter = new Parameter(getService(), "queryList").setMap(param); - logger.info("{} execute queryList start...", parameter.getNo()); - List list = provider.execute(parameter).getList(); - logger.info("{} execute queryList end.", parameter.getNo()); - return setSuccessModelMap(modelMap, list); - } + public Object queryList(ModelMap modelMap, Map param) { + Parameter parameter = new Parameter(getService(), "queryList", param); + logger.info("{} execute queryList start...", parameter.getNo()); + List list = (List) provider.execute(parameter).getResult(); + logger.info("{} execute queryList end.", parameter.getNo()); + return setSuccessModelMap(modelMap, list); + } - public Object get(ModelMap modelMap, BaseModel param) { - Parameter parameter = new Parameter(getService(), "queryById").setId(param.getId()); - logger.info("{} execute queryById start...", parameter.getNo()); - BaseModel result = provider.execute(parameter).getModel(); - logger.info("{} execute queryById end.", parameter.getNo()); - return setSuccessModelMap(modelMap, result); - } + public Object get(ModelMap modelMap, BaseModel param) { + Parameter parameter = new Parameter(getService(), "queryById", param.getId()); + logger.info("{} execute queryById start...", parameter.getNo()); + BaseModel result = (BaseModel) provider.execute(parameter).getResult(); + logger.info("{} execute queryById end.", parameter.getNo()); + return setSuccessModelMap(modelMap, result); + } - public Object update(ModelMap modelMap, BaseModel param) { - Long userId = getCurrUser(); - if (param.getId() == null) { - param.setCreateBy(userId); - param.setCreateTime(new Date()); - } - param.setUpdateBy(userId); - param.setUpdateTime(new Date()); - Parameter parameter = new Parameter(getService(), "update").setModel(param); - logger.info("{} execute update start...", parameter.getNo()); - provider.execute(parameter); - logger.info("{} execute update end.", parameter.getNo()); - return setSuccessModelMap(modelMap); - } + public Object update(ModelMap modelMap, BaseModel param) { + Long userId = getCurrUser(); + if (param.getId() == null) { + param.setCreateBy(userId); + param.setCreateTime(new Date()); + } + param.setUpdateBy(userId); + param.setUpdateTime(new Date()); + Parameter parameter = new Parameter(getService(), "update", param); + logger.info("{} execute update start...", parameter.getNo()); + provider.execute(parameter); + logger.info("{} execute update end.", parameter.getNo()); + return setSuccessModelMap(modelMap); + } - public Object delete(ModelMap modelMap, BaseModel param) { - Parameter parameter = new Parameter(getService(), "delete").setId(param.getId()); - logger.info("{} execute delete start...", parameter.getNo()); - provider.execute(parameter); - logger.info("{} execute delete end.", parameter.getNo()); - return setSuccessModelMap(modelMap); - } + public Object delete(ModelMap modelMap, BaseModel param) { + Parameter parameter = new Parameter(getService(), "delete", param.getId()); + logger.info("{} execute delete start...", parameter.getNo()); + provider.execute(parameter); + logger.info("{} execute delete end.", parameter.getNo()); + return setSuccessModelMap(modelMap); + } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java index d0859d0c..1ae781ee 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseProviderImpl.java @@ -1,8 +1,5 @@ package org.ibase4j.core.base; -import java.util.List; -import java.util.Map; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.ibase4j.core.Constants; @@ -27,33 +24,12 @@ public Parameter execute(Parameter parameter) { logger.info("{} request:{}", no, JSON.toJSONString(parameter)); Object service = applicationContext.getBean(parameter.getService()); try { - Long id = parameter.getId(); - BaseModel model = parameter.getModel(); - List list = parameter.getList(); - Map map = parameter.getMap(); String method = parameter.getMethod(); Object[] param = parameter.getParam(); - Object result = null; - if (param != null) { - result = InstanceUtil.invokeMethod(service, method, param); - } else if (id != null) { - result = InstanceUtil.invokeMethod(service, method, id); - } else if (model != null) { - result = InstanceUtil.invokeMethod(service, method, model); - } else if (list != null) { - result = InstanceUtil.invokeMethod(service, method, list); - } else if (map != null) { - result = InstanceUtil.invokeMethod(service, method, map); - } else { - result = InstanceUtil.invokeMethod(service, method); - } - if (result != null) { - Parameter response = new Parameter(result); - logger.info("{} response:{}", no, JSON.toJSONString(response)); - return response; - } - logger.info("{} response empty.", no); - return new Parameter(); + Object result = InstanceUtil.invokeMethod(service, method, param); + Parameter response = new Parameter(result); + logger.info("{} response:{}", no, JSON.toJSONString(response)); + return response; } catch (Exception e) { String msg = ExceptionUtil.getStackTraceAsString(e); logger.error(no + " " + Constants.Exception_Head + msg, e); diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/Parameter.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/Parameter.java index a43e8647..fc1bbd60 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/Parameter.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/Parameter.java @@ -2,7 +2,6 @@ import java.io.Serializable; import java.util.List; -import java.util.Map; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.toolkit.IdWorker; @@ -13,126 +12,89 @@ */ @SuppressWarnings("serial") public class Parameter implements Serializable { - public Parameter() { - } - - public Parameter(String service, String method) { - this.service = service; - this.method = method; - } - - public Parameter(Object result) { - if (result instanceof Long) { - this.id = (Long) result; - } else if (result instanceof BaseModel) { - this.model = (BaseModel) result; - } else if (result instanceof Page) { - this.page = (Page) result; - } else if (result instanceof Map) { - this.map = (Map) result; - } else if (result instanceof List) { - this.list = (List) result; - } else if (result instanceof Object[]) { - this.param = (Object[]) result; - } else { - this.result = result; - } - } - - private String service; - private String method; - - private Object[] param; - private Long id; - private BaseModel model; - private Map map; - private Page page; - private List list; - private Object result; - - private final String no = "[" + IdWorker.getId() + "]"; - - public String getService() { - return service; - } - - public void setService(String service) { - this.service = service; - } - - public String getMethod() { - return method; - } - - public Parameter setMethod(String method) { - this.method = method; - return this; - } - - public Object[] getParam() { - return param; - } - - public Parameter setParam(Object[] param) { - this.param = param; - return this; - } - - public Long getId() { - return id; - } - - public Parameter setId(Long id) { - this.id = id; - return this; - } - - public BaseModel getModel() { - return model; - } - - public Parameter setModel(BaseModel model) { - this.model = model; - return this; - } - - public Map getMap() { - return map; - } - - public Parameter setMap(Map map) { - this.map = map; - return this; - } - - public Page getPage() { - return page; - } - - public Parameter setPage(Page page) { - this.page = page; - return this; - } - - public List getList() { - return list; - } - - public Parameter setList(List list) { - this.list = list; - return this; - } - - public String getNo() { - return no; - } - - public Object getResult() { - return result; - } - - public Parameter setResult(Object result) { - this.result = result; - return this; - } + public Parameter() { + } + + public Parameter(String service, String method) { + this.service = service; + this.method = method; + } + + public Parameter(String service, String method, Object... param) { + this.service = service; + this.method = method; + this.param = param; + } + + public Parameter(Object result) { + this.result = result; + } + + private String service; + private String method; + + private Object[] param; + private Object result; + + private final String no = "[" + IdWorker.getId() + "]"; + + public String getService() { + return service; + } + + public void setService(String service) { + this.service = service; + } + + public String getMethod() { + return method; + } + + public Parameter setMethod(String method) { + this.method = method; + return this; + } + + public Object[] getParam() { + return param; + } + + public Parameter setParam(Object... param) { + this.param = param; + return this; + } + + public String getNo() { + return no; + } + + public Parameter setResult(Object result) { + this.result = result; + return this; + } + + public Object getResult() { + return result; + } + + public List getResultList() { + if (result instanceof List) { + return (List)result; + } + return null; + } + + public Page getResultPage() { + if (result instanceof Page) { + return (Page)result; + } + return null; + } + + public Long getResultLong() { + if (result instanceof Long) { + return (Long)result; + } + return null; + } } diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/EventInterceptor.java b/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/EventInterceptor.java index 860524f1..e390d491 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/EventInterceptor.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/interceptor/EventInterceptor.java @@ -94,7 +94,7 @@ public void run() { record.setRemark(ExceptionUtil.getStackTraceAsString(ex)); } - Parameter parameter = new Parameter("sysEventService", "update").setModel(record); + Parameter parameter = new Parameter("sysEventService", "update", record); sysProvider.execute(parameter); } catch (Exception e) { logger.error("Save event log cause error :", e); diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java index 2d3915ee..2b58709f 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/support/cache/RedisHelper.java @@ -9,6 +9,7 @@ import org.ibase4j.core.util.InstanceUtil; import org.ibase4j.core.util.PropertiesUtil; import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisConnectionUtils; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer; @@ -21,7 +22,6 @@ */ public final class RedisHelper implements CacheManager { private RedisTemplate redisTemplate; - private RedisConnection redisConnection; private RedisSerializer keySerializer; private RedisSerializer valueSerializer; private final Integer EXPIRE = PropertiesUtil.getInt("redis.expiration"); @@ -29,7 +29,6 @@ public final class RedisHelper implements CacheManager { @SuppressWarnings("unchecked") public void setRedisTemplate(RedisTemplate redisTemplate) { this.redisTemplate = redisTemplate; - this.redisConnection = RedisConnectionUtils.getConnection(redisTemplate.getConnectionFactory()); this.keySerializer = (RedisSerializer)redisTemplate.getKeySerializer(); this.valueSerializer = (RedisSerializer)redisTemplate.getValueSerializer(); CacheUtil.setCacheManager(this); @@ -61,7 +60,14 @@ public final void set(final String key, final Serializable value) { } public final Boolean exists(final String key) { - return redisTemplate.hasKey(key); + RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); + RedisConnection redisConnection = null; + try { + redisConnection = RedisConnectionUtils.getConnection(factory); + return redisConnection.exists(keySerializer.serialize(key)); + } finally { + RedisConnectionUtils.releaseConnection(redisConnection, factory); + } } public final void del(final String key) { @@ -117,15 +123,36 @@ public final Object getSet(final String key, final Serializable value) { } public boolean setnx(String key, Serializable value) { - return redisConnection.setNX(keySerializer.serialize(key), valueSerializer.serialize(value)); + RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); + RedisConnection redisConnection = null; + try { + redisConnection = RedisConnectionUtils.getConnection(factory); + return redisConnection.setNX(keySerializer.serialize(key), valueSerializer.serialize(value)); + } finally { + RedisConnectionUtils.releaseConnection(redisConnection, factory); + } } public boolean lock(String key) { - return redisConnection.setNX(keySerializer.serialize(key), valueSerializer.serialize("0")); + RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); + RedisConnection redisConnection = null; + try { + redisConnection = RedisConnectionUtils.getConnection(factory); + return redisConnection.setNX(keySerializer.serialize(key), valueSerializer.serialize("0")); + } finally { + RedisConnectionUtils.releaseConnection(redisConnection, factory); + } } public void unlock(String key) { - del(key); + RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); + RedisConnection redisConnection = null; + try { + redisConnection = RedisConnectionUtils.getConnection(factory); + redisConnection.del(keySerializer.serialize(key)); + } finally { + RedisConnectionUtils.releaseConnection(redisConnection, factory); + } } public void hset(String key, Serializable field, Serializable value) { diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java b/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java index b11c326e..1754e7d6 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/util/CacheUtil.java @@ -53,6 +53,6 @@ public static boolean getLock(String key) { } public static void unlock(String key) { - getCache().del(key); + getCache().unlock(key); } } diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/core/shiro/Realm.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/core/shiro/Realm.java index 830958e2..f55285ca 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/core/shiro/Realm.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/core/shiro/Realm.java @@ -46,9 +46,9 @@ public class Realm extends AuthorizingRealm { protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); Long userId = (Long) WebUtil.getCurrentUser(); - Parameter parameter = new Parameter("sysAuthorizeService", "queryPermissionByUserId").setId(userId); + Parameter parameter = new Parameter("sysAuthorizeService", "queryPermissionByUserId", userId); logger.info("{} execute queryPermissionByUserId start...", parameter.getNo()); - List list = provider.execute(parameter).getList(); + List list = provider.execute(parameter).getResultList(); logger.info("{} execute queryPermissionByUserId end.", parameter.getNo()); for (Object permission : list) { if (StringUtils.isNotBlank((String) permission)) { @@ -68,9 +68,9 @@ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcTo Map params = new HashMap(); params.put("enable", 1); params.put("account", token.getUsername()); - Parameter parameter = new Parameter("sysUserService", "queryList").setMap(params); + Parameter parameter = new Parameter("sysUserService", "queryList", params); logger.info("{} execute sysUserService.queryList start...", parameter.getNo()); - List list = provider.execute(parameter).getList(); + List list = provider.execute(parameter).getResultList(); logger.info("{} execute sysUserService.queryList end.", parameter.getNo()); if (list.size() == 1) { SysUser user = (SysUser) list.get(0); @@ -98,17 +98,17 @@ private void saveSession(String account, String host) { // 踢出用户 SysSession record = new SysSession(); record.setAccount(account); - Parameter parameter = new Parameter("sysSessionService", "querySessionIdByAccount").setModel(record); + Parameter parameter = new Parameter("sysSessionService", "querySessionIdByAccount", record); logger.info("{} execute querySessionIdByAccount start...", parameter.getNo()); - List sessionIds = provider.execute(parameter).getList(); + List sessionIds = provider.execute(parameter).getResultList(); logger.info("{} execute querySessionIdByAccount end.", parameter.getNo()); Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); - String currentSessionId= session.getId().toString(); + String currentSessionId = session.getId().toString(); if (sessionIds != null) { for (Object sessionId : sessionIds) { record.setSessionId((String) sessionId); - parameter = new Parameter("sysSessionService", "deleteBySessionId").setModel(record); + parameter = new Parameter("sysSessionService", "deleteBySessionId", record); logger.info("{} execute deleteBySessionId start...", parameter.getNo()); provider.execute(parameter); logger.info("{} execute deleteBySessionId end.", parameter.getNo()); @@ -122,7 +122,7 @@ private void saveSession(String account, String host) { record.setSessionId(currentSessionId); record.setIp(StringUtils.isBlank(host) ? session.getHost() : host); record.setStartTime(session.getStartTimestamp()); - parameter = new Parameter("sysSessionService", "update").setModel(record); + parameter = new Parameter("sysSessionService", "update", record); logger.info("{} execute sysSessionService.update start...", parameter.getNo()); provider.execute(parameter); logger.info("{} execute sysSessionService.update end.", parameter.getNo()); diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/LoginController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/LoginController.java index 686b182d..6907b9bc 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/LoginController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/LoginController.java @@ -72,7 +72,7 @@ public Object regin(HttpServletRequest request, ModelMap modelMap, @RequestBody Assert.notNull(sysUser.getAccount(), "ACCOUNT"); Assert.notNull(sysUser.getPassword(), "PASSWORD"); sysUser.setPassword(SecurityUtil.encryptPassword(sysUser.getPassword())); - provider.execute(new Parameter("sysUserService", "update").setModel(sysUser)); + provider.execute(new Parameter("sysUserService", "update", sysUser)); String clientIp = (String) request.getSession().getAttribute(Constants.USER_IP); if (LoginHelper.login(sysUser.getAccount(), sysUser.getPassword(), clientIp)) { return setSuccessModelMap(modelMap); diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/ScheduledController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/ScheduledController.java index 27d65848..337cc5cc 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/ScheduledController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/ScheduledController.java @@ -53,7 +53,7 @@ public Object updateTask(@RequestBody TaskScheduled scheduled, ModelMap modelMap if (TaskType.dubbo.equals(scheduled.getTaskType())) { Assert.notNull(scheduled.getTargetSystem(), "TARGETSYSTEM"); } - Parameter parameter = new Parameter(getService(), "updateTask").setModel(scheduled); + Parameter parameter = new Parameter(getService(), "updateTask", scheduled); provider.execute(parameter); return setSuccessModelMap(modelMap); } @@ -64,7 +64,7 @@ public Object updateTask(@RequestBody TaskScheduled scheduled, ModelMap modelMap public Object delete(@RequestBody TaskScheduled scheduled, ModelMap modelMap) { Assert.notNull(scheduled.getTaskGroup(), "TASKGROUP"); Assert.notNull(scheduled.getTaskName(), "TASKNAME"); - Parameter parameter = new Parameter(getService(), "delTask").setModel(scheduled); + Parameter parameter = new Parameter(getService(), "delTask", scheduled); provider.execute(parameter); return setSuccessModelMap(modelMap); } @@ -75,7 +75,7 @@ public Object delete(@RequestBody TaskScheduled scheduled, ModelMap modelMap) { public Object exec(@RequestBody TaskScheduled scheduled, ModelMap modelMap) { Assert.notNull(scheduled.getTaskGroup(), "TASKGROUP"); Assert.notNull(scheduled.getTaskName(), "TASKNAME"); - Parameter parameter = new Parameter(getService(), "execTask").setModel(scheduled); + Parameter parameter = new Parameter(getService(), "execTask", scheduled); provider.execute(parameter); return setSuccessModelMap(modelMap); } @@ -86,7 +86,7 @@ public Object exec(@RequestBody TaskScheduled scheduled, ModelMap modelMap) { public Object open(@RequestBody TaskScheduled scheduled, ModelMap modelMap) { Assert.notNull(scheduled.getTaskGroup(), "TASKGROUP"); Assert.notNull(scheduled.getTaskName(), "TASKNAME"); - Parameter parameter = new Parameter(getService(), "openTask").setModel(scheduled); + Parameter parameter = new Parameter(getService(), "openTask", scheduled); provider.execute(parameter); return setSuccessModelMap(modelMap); } @@ -97,7 +97,7 @@ public Object open(@RequestBody TaskScheduled scheduled, ModelMap modelMap) { public Object close(@RequestBody TaskScheduled scheduled, ModelMap modelMap) { Assert.notNull(scheduled.getTaskGroup(), "TASKGROUP"); Assert.notNull(scheduled.getTaskName(), "TASKNAME"); - Parameter parameter = new Parameter(getService(), "closeTask").setModel(scheduled); + Parameter parameter = new Parameter(getService(), "closeTask", scheduled); provider.execute(parameter); return setSuccessModelMap(modelMap); } @@ -107,7 +107,7 @@ public Object close(@RequestBody TaskScheduled scheduled, ModelMap modelMap) { @RequiresPermissions("sys.task.scheduled.read") public Object list(ModelMap modelMap) { Parameter parameter = new Parameter(getService(), "getAllTaskDetail"); - List records = provider.execute(parameter).getList(); + List records = provider.execute(parameter).getResultList(); modelMap.put("recordsTotal", records.size()); modelMap.put("total", records.size()); modelMap.put("current", 1); @@ -119,8 +119,8 @@ public Object list(ModelMap modelMap) { @ApiOperation(value = "任务执行记录") @RequiresPermissions("sys.task.log.read") public Object getFireLog(ModelMap modelMap, @RequestBody Map log) { - Parameter parameter = new Parameter(getService(), "queryLog").setMap(log); - Page list = provider.execute(parameter).getPage(); + Parameter parameter = new Parameter(getService(), "queryLog", log); + Page list = provider.execute(parameter).getResultPage(); return setSuccessModelMap(modelMap, list); } } \ No newline at end of file diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SearchController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SearchController.java index c250cbde..b5b8fda0 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SearchController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SearchController.java @@ -25,8 +25,8 @@ public String getService() { @PutMapping("query") @ApiOperation(value = "全库搜索") public Object query(ModelMap modelMap, @RequestBody Map param) { - Parameter parameter = new Parameter(getService(), "query").setMap(param); - List list = provider.execute(parameter).getList(); + Parameter parameter = new Parameter(getService(), "query", param); + List list = provider.execute(parameter).getResultList(); return setSuccessModelMap(modelMap, list); } } diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysAuthorizeController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysAuthorizeController.java index 4f30c815..3d6aef38 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysAuthorizeController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysAuthorizeController.java @@ -33,204 +33,203 @@ @Api(value = "权限管理", description = "权限管理") public class SysAuthorizeController extends AbstractController { - public String getService() { - return "sysAuthorizeService"; - } - - @ApiOperation(value = "获取用户菜单编号") - @PutMapping(value = "user/read/menu") - @RequiresPermissions("sys.permisson.userMenu.read") - public Object getUserMenu(ModelMap modelMap, @RequestBody SysUserMenu param) { - Parameter parameter = new Parameter(getService(), "queryMenuIdsByUserId").setId(param.getUserId()); - logger.info("{} execute queryMenuIdsByUserId start...", parameter.getNo()); - List menus = provider.execute(parameter).getList(); - logger.info("{} execute queryMenuIdsByUserId end.", parameter.getNo()); - return setSuccessModelMap(modelMap, menus); - } - - @ApiOperation(value = "修改用户菜单") - @PostMapping(value = "/user/update/menu") - @RequiresPermissions("sys.permisson.userMenu.update") - public Object userMenu(ModelMap modelMap, @RequestBody List list) { - Long userId = null; - Long currentUserId = getCurrUser(); - for (SysUserMenu sysUserMenu : list) { - if (sysUserMenu.getUserId() != null) { - if (userId != null && sysUserMenu.getUserId() != null - && userId.longValue() != sysUserMenu.getUserId()) { - throw new IllegalParameterException("参数错误."); - } - userId = sysUserMenu.getUserId(); - } - sysUserMenu.setCreateBy(currentUserId); - sysUserMenu.setUpdateBy(currentUserId); - sysUserMenu.setCreateTime(new Date()); - sysUserMenu.setUpdateTime(new Date()); - } - Parameter parameter = new Parameter(getService(), "updateUserMenu").setList(list); - logger.info("{} execute updateUserMenu start...", parameter.getNo()); - provider.execute(parameter); - logger.info("{} execute updateUserMenu end.", parameter.getNo()); - return setSuccessModelMap(modelMap); - } - - @ApiOperation(value = "获取用户角色") - @PutMapping(value = "user/read/role") - @RequiresPermissions("sys.permisson.userRole.read") - public Object getUserRole(ModelMap modelMap, @RequestBody SysUserRole param) { - Parameter parameter = new Parameter(getService(), "getRolesByUserId").setId(param.getUserId()); - logger.info("{} execute getRolesByUserId start...", parameter.getNo()); - List menus = provider.execute(parameter).getList(); - logger.info("{} execute getRolesByUserId end.", parameter.getNo()); - return setSuccessModelMap(modelMap, menus); - } - - @ApiOperation(value = "修改用户角色") - @PostMapping(value = "/user/update/role") - @RequiresPermissions("sys.permisson.userRole.update") - public Object userRole(ModelMap modelMap, @RequestBody List list) { - Long userId = null; - Long currentUserId = getCurrUser(); - for (SysUserRole sysUserRole : list) { - if (sysUserRole.getUserId() != null) { - if (userId != null && sysUserRole.getUserId() != null - && userId.longValue() != sysUserRole.getUserId()) { - throw new IllegalParameterException("参数错误."); - } - userId = sysUserRole.getUserId(); - } - sysUserRole.setCreateBy(currentUserId); - sysUserRole.setUpdateBy(currentUserId); - sysUserRole.setCreateTime(new Date()); - sysUserRole.setUpdateTime(new Date()); - } - Parameter parameter = new Parameter(getService(), "updateUserRole").setList(list); - logger.info("{} execute updateUserRole start...", parameter.getNo()); - provider.execute(parameter); - logger.info("{} execute updateUserRole end.", parameter.getNo()); - return setSuccessModelMap(modelMap); - } - - @ApiOperation(value = "获取角色菜单编号") - @PutMapping(value = "role/read/menu") - @RequiresPermissions("sys.permisson.roleMenu.read") - public Object getRoleMenu(ModelMap modelMap, @RequestBody SysRoleMenu param) { - Parameter parameter = new Parameter(getService(), "queryMenuIdsByRoleId").setId(param.getRoleId()); - logger.info("{} execute queryMenuIdsByRoleId start...", parameter.getNo()); - List menus = provider.execute(parameter).getList(); - logger.info("{} execute queryMenuIdsByRoleId end.", parameter.getNo()); - return setSuccessModelMap(modelMap, menus); - } - - @ApiOperation(value = "修改角色菜单") - @PostMapping(value = "/role/update/menu") - @RequiresPermissions("sys.permisson.roleMenu.update") - public Object roleMenu(ModelMap modelMap, @RequestBody List list) { - Long roleId = null; - Long userId = getCurrUser(); - for (SysRoleMenu sysRoleMenu : list) { - if (sysRoleMenu.getRoleId() != null) { - if (roleId != null && sysRoleMenu.getRoleId() != null - && roleId.longValue() != sysRoleMenu.getRoleId()) { - throw new IllegalParameterException("参数错误."); - } - roleId = sysRoleMenu.getRoleId(); - } - sysRoleMenu.setCreateBy(userId); - sysRoleMenu.setUpdateBy(userId); - sysRoleMenu.setCreateTime(new Date()); - sysRoleMenu.setUpdateTime(new Date()); - } - Parameter parameter = new Parameter(getService(), "updateRoleMenu"); - parameter.setList(list); - logger.info("{} execute updateRoleMenu start...", parameter.getNo()); - provider.execute(parameter); - logger.info("{} execute updateRoleMenu end.", parameter.getNo()); - return setSuccessModelMap(modelMap); - } - - @ApiOperation(value = "获取人员操作权限") - @PutMapping(value = "user/read/permission") - @RequiresPermissions("sys.permisson.user.read") - public Object queryUserPermissions(ModelMap modelMap, @RequestBody SysUserMenu record) { - Parameter parameter = new Parameter(getService(), "queryUserPermissions").setModel(record); - logger.info("{} execute queryUserPermissions start...", parameter.getNo()); - List menuIds = provider.execute(parameter).getList(); - logger.info("{} execute queryUserPermissions end.", parameter.getNo()); - return setSuccessModelMap(modelMap, menuIds); - } - - @ApiOperation(value = "修改用户操作权限") - @PostMapping(value = "/user/update/permission") - @RequiresPermissions("sys.permisson.user.update") - public Object updateUserPermission(ModelMap modelMap, @RequestBody List list) { - Long userId = null; - Long currentUserId = getCurrUser(); - for (SysUserMenu sysUserMenu : list) { - if (sysUserMenu.getUserId() != null) { - if (userId != null && sysUserMenu.getUserId() != null - && userId.longValue() != sysUserMenu.getUserId()) { - throw new IllegalParameterException("参数错误."); - } - userId = sysUserMenu.getUserId(); - } - sysUserMenu.setCreateBy(currentUserId); - sysUserMenu.setUpdateBy(currentUserId); - sysUserMenu.setCreateTime(new Date()); - sysUserMenu.setUpdateTime(new Date()); - } - Parameter parameter = new Parameter(getService(), "updateUserPermission").setList(list); - logger.info("{} execute updateUserPermission start...", parameter.getNo()); - provider.execute(parameter); - logger.info("{} execute updateUserPermission end.", parameter.getNo()); - return setSuccessModelMap(modelMap); - } - - @ApiOperation(value = "获取角色操作权限") - @PutMapping(value = "role/read/permission") - @RequiresPermissions("sys.permisson.role.read") - public Object queryRolePermissions(ModelMap modelMap, @RequestBody SysRoleMenu record) { - Parameter parameter = new Parameter(getService(), "queryRolePermissions").setModel(record); - logger.info("{} execute queryRolePermissions start...", parameter.getNo()); - List menuIds = provider.execute(parameter).getList(); - logger.info("{} execute queryRolePermissions end.", parameter.getNo()); - return setSuccessModelMap(modelMap, menuIds); - } - - @ApiOperation(value = "修改角色操作权限") - @PostMapping(value = "/role/update/permission") - @RequiresPermissions("sys.permisson.role.update") - public Object updateRolePermission(ModelMap modelMap, @RequestBody List list) { - Long roleId = null; - Long userId = getCurrUser(); - for (SysRoleMenu sysRoleMenu : list) { - if (sysRoleMenu.getRoleId() != null) { - if (roleId != null && sysRoleMenu.getRoleId() != null - && roleId.longValue() != sysRoleMenu.getRoleId()) { - throw new IllegalParameterException("参数错误."); - } - roleId = sysRoleMenu.getRoleId(); - } - sysRoleMenu.setCreateBy(userId); - sysRoleMenu.setUpdateBy(userId); - sysRoleMenu.setCreateTime(new Date()); - sysRoleMenu.setUpdateTime(new Date()); - } - Parameter parameter = new Parameter(getService(), "updateRolePermission").setList(list); - logger.info("{} execute updateRolePermission start...", parameter.getNo()); - provider.execute(parameter); - logger.info("{} execute updateRolePermission end.", parameter.getNo()); - return setSuccessModelMap(modelMap); - } - - @ApiOperation(value = "清理缓存") - @RequiresPermissions("sys.cache.update") - @RequestMapping(value = "/cache/update", method = RequestMethod.POST) - public Object flush(ModelMap modelMap, @RequestBody Map param) { - Parameter parameter = new Parameter("sysCacheService", "flush").setMap(param); - logger.info("{} execute sysCacheService.flush start...", parameter.getNo()); - provider.execute(parameter); - logger.info("{} execute sysCacheService.flush end.", parameter.getNo()); - return setSuccessModelMap(modelMap); - } + public String getService() { + return "sysAuthorizeService"; + } + + @ApiOperation(value = "获取用户菜单编号") + @PutMapping(value = "user/read/menu") + @RequiresPermissions("sys.permisson.userMenu.read") + public Object getUserMenu(ModelMap modelMap, @RequestBody SysUserMenu param) { + Parameter parameter = new Parameter(getService(), "queryMenuIdsByUserId", param.getUserId()); + logger.info("{} execute queryMenuIdsByUserId start...", parameter.getNo()); + List menus = provider.execute(parameter).getResultList(); + logger.info("{} execute queryMenuIdsByUserId end.", parameter.getNo()); + return setSuccessModelMap(modelMap, menus); + } + + @ApiOperation(value = "修改用户菜单") + @PostMapping(value = "/user/update/menu") + @RequiresPermissions("sys.permisson.userMenu.update") + public Object userMenu(ModelMap modelMap, @RequestBody List list) { + Long userId = null; + Long currentUserId = getCurrUser(); + for (SysUserMenu sysUserMenu : list) { + if (sysUserMenu.getUserId() != null) { + if (userId != null && sysUserMenu.getUserId() != null + && userId.longValue() != sysUserMenu.getUserId()) { + throw new IllegalParameterException("参数错误."); + } + userId = sysUserMenu.getUserId(); + } + sysUserMenu.setCreateBy(currentUserId); + sysUserMenu.setUpdateBy(currentUserId); + sysUserMenu.setCreateTime(new Date()); + sysUserMenu.setUpdateTime(new Date()); + } + Parameter parameter = new Parameter(getService(), "updateUserMenu", list); + logger.info("{} execute updateUserMenu start...", parameter.getNo()); + provider.execute(parameter); + logger.info("{} execute updateUserMenu end.", parameter.getNo()); + return setSuccessModelMap(modelMap); + } + + @ApiOperation(value = "获取用户角色") + @PutMapping(value = "user/read/role") + @RequiresPermissions("sys.permisson.userRole.read") + public Object getUserRole(ModelMap modelMap, @RequestBody SysUserRole param) { + Parameter parameter = new Parameter(getService(), "getRolesByUserId", param.getUserId()); + logger.info("{} execute getRolesByUserId start...", parameter.getNo()); + List menus = provider.execute(parameter).getResultList(); + logger.info("{} execute getRolesByUserId end.", parameter.getNo()); + return setSuccessModelMap(modelMap, menus); + } + + @ApiOperation(value = "修改用户角色") + @PostMapping(value = "/user/update/role") + @RequiresPermissions("sys.permisson.userRole.update") + public Object userRole(ModelMap modelMap, @RequestBody List list) { + Long userId = null; + Long currentUserId = getCurrUser(); + for (SysUserRole sysUserRole : list) { + if (sysUserRole.getUserId() != null) { + if (userId != null && sysUserRole.getUserId() != null + && userId.longValue() != sysUserRole.getUserId()) { + throw new IllegalParameterException("参数错误."); + } + userId = sysUserRole.getUserId(); + } + sysUserRole.setCreateBy(currentUserId); + sysUserRole.setUpdateBy(currentUserId); + sysUserRole.setCreateTime(new Date()); + sysUserRole.setUpdateTime(new Date()); + } + Parameter parameter = new Parameter(getService(), "updateUserRole", list); + logger.info("{} execute updateUserRole start...", parameter.getNo()); + provider.execute(parameter); + logger.info("{} execute updateUserRole end.", parameter.getNo()); + return setSuccessModelMap(modelMap); + } + + @ApiOperation(value = "获取角色菜单编号") + @PutMapping(value = "role/read/menu") + @RequiresPermissions("sys.permisson.roleMenu.read") + public Object getRoleMenu(ModelMap modelMap, @RequestBody SysRoleMenu param) { + Parameter parameter = new Parameter(getService(), "queryMenuIdsByRoleId", param.getRoleId()); + logger.info("{} execute queryMenuIdsByRoleId start...", parameter.getNo()); + List menus = provider.execute(parameter).getResultList(); + logger.info("{} execute queryMenuIdsByRoleId end.", parameter.getNo()); + return setSuccessModelMap(modelMap, menus); + } + + @ApiOperation(value = "修改角色菜单") + @PostMapping(value = "/role/update/menu") + @RequiresPermissions("sys.permisson.roleMenu.update") + public Object roleMenu(ModelMap modelMap, @RequestBody List list) { + Long roleId = null; + Long userId = getCurrUser(); + for (SysRoleMenu sysRoleMenu : list) { + if (sysRoleMenu.getRoleId() != null) { + if (roleId != null && sysRoleMenu.getRoleId() != null + && roleId.longValue() != sysRoleMenu.getRoleId()) { + throw new IllegalParameterException("参数错误."); + } + roleId = sysRoleMenu.getRoleId(); + } + sysRoleMenu.setCreateBy(userId); + sysRoleMenu.setUpdateBy(userId); + sysRoleMenu.setCreateTime(new Date()); + sysRoleMenu.setUpdateTime(new Date()); + } + Parameter parameter = new Parameter(getService(), "updateRoleMenu", list); + logger.info("{} execute updateRoleMenu start...", parameter.getNo()); + provider.execute(parameter); + logger.info("{} execute updateRoleMenu end.", parameter.getNo()); + return setSuccessModelMap(modelMap); + } + + @ApiOperation(value = "获取人员操作权限") + @PutMapping(value = "user/read/permission") + @RequiresPermissions("sys.permisson.user.read") + public Object queryUserPermissions(ModelMap modelMap, @RequestBody SysUserMenu record) { + Parameter parameter = new Parameter(getService(), "queryUserPermissions", record); + logger.info("{} execute queryUserPermissions start...", parameter.getNo()); + List menuIds = provider.execute(parameter).getResultList(); + logger.info("{} execute queryUserPermissions end.", parameter.getNo()); + return setSuccessModelMap(modelMap, menuIds); + } + + @ApiOperation(value = "修改用户操作权限") + @PostMapping(value = "/user/update/permission") + @RequiresPermissions("sys.permisson.user.update") + public Object updateUserPermission(ModelMap modelMap, @RequestBody List list) { + Long userId = null; + Long currentUserId = getCurrUser(); + for (SysUserMenu sysUserMenu : list) { + if (sysUserMenu.getUserId() != null) { + if (userId != null && sysUserMenu.getUserId() != null + && userId.longValue() != sysUserMenu.getUserId()) { + throw new IllegalParameterException("参数错误."); + } + userId = sysUserMenu.getUserId(); + } + sysUserMenu.setCreateBy(currentUserId); + sysUserMenu.setUpdateBy(currentUserId); + sysUserMenu.setCreateTime(new Date()); + sysUserMenu.setUpdateTime(new Date()); + } + Parameter parameter = new Parameter(getService(), "updateUserPermission", list); + logger.info("{} execute updateUserPermission start...", parameter.getNo()); + provider.execute(parameter); + logger.info("{} execute updateUserPermission end.", parameter.getNo()); + return setSuccessModelMap(modelMap); + } + + @ApiOperation(value = "获取角色操作权限") + @PutMapping(value = "role/read/permission") + @RequiresPermissions("sys.permisson.role.read") + public Object queryRolePermissions(ModelMap modelMap, @RequestBody SysRoleMenu record) { + Parameter parameter = new Parameter(getService(), "queryRolePermissions", record); + logger.info("{} execute queryRolePermissions start...", parameter.getNo()); + List menuIds = provider.execute(parameter).getResultList(); + logger.info("{} execute queryRolePermissions end.", parameter.getNo()); + return setSuccessModelMap(modelMap, menuIds); + } + + @ApiOperation(value = "修改角色操作权限") + @PostMapping(value = "/role/update/permission") + @RequiresPermissions("sys.permisson.role.update") + public Object updateRolePermission(ModelMap modelMap, @RequestBody List list) { + Long roleId = null; + Long userId = getCurrUser(); + for (SysRoleMenu sysRoleMenu : list) { + if (sysRoleMenu.getRoleId() != null) { + if (roleId != null && sysRoleMenu.getRoleId() != null + && roleId.longValue() != sysRoleMenu.getRoleId()) { + throw new IllegalParameterException("参数错误."); + } + roleId = sysRoleMenu.getRoleId(); + } + sysRoleMenu.setCreateBy(userId); + sysRoleMenu.setUpdateBy(userId); + sysRoleMenu.setCreateTime(new Date()); + sysRoleMenu.setUpdateTime(new Date()); + } + Parameter parameter = new Parameter(getService(), "updateRolePermission", list); + logger.info("{} execute updateRolePermission start...", parameter.getNo()); + provider.execute(parameter); + logger.info("{} execute updateRolePermission end.", parameter.getNo()); + return setSuccessModelMap(modelMap); + } + + @ApiOperation(value = "清理缓存") + @RequiresPermissions("sys.cache.update") + @RequestMapping(value = "/cache/update", method = RequestMethod.POST) + public Object flush(ModelMap modelMap, @RequestBody Map param) { + Parameter parameter = new Parameter("sysCacheService", "flush", param); + logger.info("{} execute sysCacheService.flush start...", parameter.getNo()); + provider.execute(parameter); + logger.info("{} execute sysCacheService.flush end.", parameter.getNo()); + return setSuccessModelMap(modelMap); + } } diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysEmailConfigController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysEmailConfigController.java index 7d8784ed..6c48b91a 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysEmailConfigController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysEmailConfigController.java @@ -52,8 +52,8 @@ public Object get(ModelMap modelMap, @RequestBody SysEmailConfig param) { @RequestMapping(method = RequestMethod.POST) public Object update(ModelMap modelMap, @RequestBody SysEmailConfig param) { if (param.getId() != null) { - Parameter parameter = new Parameter("sysEmailConfigService", "queryById").setId(param.getId()); - SysEmailConfig result = (SysEmailConfig) provider.execute(parameter).getModel(); + Parameter parameter = new Parameter("sysEmailConfigService", "queryById", param.getId()); + SysEmailConfig result = (SysEmailConfig) provider.execute(parameter).getResult(); if (param.getSenderPassword() != null && !param.getSenderPassword().equals(result.getSenderPassword())) { param.setSenderPassword(SecurityUtil.encryptMd5(param.getSenderPassword())); } diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysMenuController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysMenuController.java index d337f432..5d448780 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysMenuController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysMenuController.java @@ -51,8 +51,8 @@ public Object get(ModelMap modelMap, @RequestBody Map param) { @PutMapping(value = "/read/tree") @RequiresPermissions("sys.base.menu.read") public Object getTree(ModelMap modelMap, @RequestBody Map param) { - Parameter parameter = new Parameter(getService(), "queryTreeList").setMap(param); - List list = provider.execute(parameter).getList(); + Parameter parameter = new Parameter(getService(), "queryTreeList", param); + List list = provider.execute(parameter).getResultList(); return setSuccessModelMap(modelMap, list); } @@ -84,8 +84,8 @@ public Object delete(ModelMap modelMap, @RequestBody SysMenu param) { @RequiresPermissions("sys.base.menu.read") @RequestMapping(value = "/read/permission") public Object getPermissions(ModelMap modelMap) { - Parameter parameter = new Parameter(getService(), "getPermissions").setModel(new SysMenu()); - List list = provider.execute(parameter).getList(); + Parameter parameter = new Parameter(getService(), "getPermissions", new SysMenu()); + List list = provider.execute(parameter).getResultList(); return setSuccessModelMap(modelMap, list); } } diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java index d9011503..81911074 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/SysUserController.java @@ -55,8 +55,8 @@ public Object update(ModelMap modelMap, @RequestBody SysUser param) { if (param.getEnable() == null) { param.setEnable(1); } - Parameter parameter = new Parameter(getService(), "queryById").setId(param.getId()); - SysUser user = (SysUser) provider.execute(parameter).getModel(); + Parameter parameter = new Parameter(getService(), "queryById", param.getId()); + SysUser user = (SysUser) provider.execute(parameter).getResult(); Assert.notNull(user, "USER", param.getId()); if (StringUtils.isNotBlank(param.getPassword())) { if (!param.getPassword().equals(user.getPassword())) { @@ -98,12 +98,12 @@ public Object delete(ModelMap modelMap, @RequestBody SysUser param) { @GetMapping(value = "/read/promission") public Object promission(ModelMap modelMap) { Long id = getCurrUser(); - Parameter parameter = new Parameter(getService(), "queryById").setId(id); - SysUser sysUser = (SysUser) provider.execute(parameter).getModel(); + Parameter parameter = new Parameter(getService(), "queryById", id); + SysUser sysUser = (SysUser) provider.execute(parameter).getResult(); modelMap.put("user", sysUser); - parameter = new Parameter("sysAuthorizeService", "queryAuthorizeByUserId").setId(id); + parameter = new Parameter("sysAuthorizeService", "queryAuthorizeByUserId", id); logger.info("{} execute queryAuthorizeByUserId start...", parameter.getNo()); - List menus = provider.execute(parameter).getList(); + List menus = provider.execute(parameter).getResultList(); logger.info("{} execute queryAuthorizeByUserId end.", parameter.getNo()); modelMap.put("menus", menus); return setSuccessModelMap(modelMap); @@ -157,9 +157,9 @@ public Object updatePassword(ModelMap modelMap, @RequestBody SysUser param) { Assert.isNotBlank(param.getPassword(), "PASSWORD"); Long userId = getCurrUser(); String encryptPassword = SecurityUtil.encryptPassword(param.getOldPassword()); - Parameter parameter = new Parameter(getService(), "queryById").setId(userId); + Parameter parameter = new Parameter(getService(), "queryById", userId); logger.info("{} execute queryById start...", parameter.getNo()); - SysUser sysUser = (SysUser) provider.execute(parameter).getModel(); + SysUser sysUser = (SysUser) provider.execute(parameter).getResult(); logger.info("{} execute queryById end.", parameter.getNo()); Assert.notNull(sysUser, "USER", param.getId()); if (!sysUser.getPassword().equals(encryptPassword)) { diff --git a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/ThirdPartyLoginController.java b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/ThirdPartyLoginController.java index 3656ccb4..c8432bf5 100644 --- a/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/ThirdPartyLoginController.java +++ b/iBase4J-SYS-Web/src/main/java/org/ibase4j/web/ThirdPartyLoginController.java @@ -168,15 +168,15 @@ public String sinaCallback(HttpServletRequest request, ModelMap modelMap) { private void thirdPartyLogin(HttpServletRequest request, ThirdPartyUser param) { SysUser sysUser = null; // 查询是否已经绑定过 - Parameter parameter = new Parameter(getService(), "queryUserIdByThirdParty").setModel(param); - Long userId = provider.execute(parameter).getId(); + Parameter parameter = new Parameter(getService(), "queryUserIdByThirdParty", param); + Long userId = provider.execute(parameter).getResultLong(); if (userId == null) { - parameter = new Parameter(getService(), "insertThirdPartyUser").setModel(param); - sysUser = (SysUser) provider.execute(parameter).getModel(); + parameter = new Parameter(getService(), "insertThirdPartyUser", param); + sysUser = (SysUser) provider.execute(parameter).getResult(); } else { - parameter = new Parameter(getService(), "queryById").setId(param.getId()); - sysUser = (SysUser) provider.execute(parameter).getModel(); + parameter = new Parameter(getService(), "queryById", param.getId()); + sysUser = (SysUser) provider.execute(parameter).getResult(); } String clientIp = (String) request.getSession().getAttribute(Constants.USER_IP); LoginHelper.login(sysUser.getAccount(), sysUser.getPassword(), clientIp); From 85e8622400ecef8d2125d7675aff75a62066713b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Tue, 26 Sep 2017 10:14:20 +0800 Subject: [PATCH 48/50] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBase4J-Biz-Service/pom.xml | 6 ++++++ iBase4J-Common/src/main/resources/spring/motan.xml | 2 +- pom.xml | 3 +-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/iBase4J-Biz-Service/pom.xml b/iBase4J-Biz-Service/pom.xml index 5d7a9d25..dd6b098b 100644 --- a/iBase4J-Biz-Service/pom.xml +++ b/iBase4J-Biz-Service/pom.xml @@ -114,5 +114,11 @@ pinyin4j ${pinyin4j.version} + + + org.db4j + reflectasm + 1.11.4-2 + \ No newline at end of file diff --git a/iBase4J-Common/src/main/resources/spring/motan.xml b/iBase4J-Common/src/main/resources/spring/motan.xml index bc37a0e4..d62c32e0 100644 --- a/iBase4J-Common/src/main/resources/spring/motan.xml +++ b/iBase4J-Common/src/main/resources/spring/motan.xml @@ -16,7 +16,7 @@ maxServerConnection="80000" maxContentLength="1048576" maxWorkerThread="${rpc.protocol.maxThread}" minWorkerThread="${rpc.protocol.minThread}" /> - diff --git a/pom.xml b/pom.xml index b585ea09..98d12dd3 100644 --- a/pom.xml +++ b/pom.xml @@ -415,8 +415,7 @@ src/main/resources - * - */* + ** true From fd2c1ce6ab6c5d9490351b087c22b1e8bfaa4da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Fri, 29 Sep 2017 17:06:21 +0800 Subject: [PATCH 49/50] =?UTF-8?q?spring=E5=8D=87=E7=BA=A75.0.0.RELEASE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 98d12dd3..6eb19fd0 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ UTF-8 - 4.3.11.RELEASE + 5.0.0.RELEASE 1.3.1.RELEASE 1.8.7.RELEASE From 953c8cda8ed0acd246839bef5fcd6ac80e3e08c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E6=97=AD?= Date: Thu, 12 Oct 2017 15:07:45 +0800 Subject: [PATCH 50/50] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ibase4j/core/base/BaseController.java | 260 +++++++++--------- .../main/resources/config/system.properties | 5 +- .../src/main/resources/spring/dubbo.xml | 5 +- .../src/main/resources/spring/motan.xml | 53 ++-- .../src/main/resources/spring/redis.xml | 113 ++++---- 5 files changed, 220 insertions(+), 216 deletions(-) diff --git a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseController.java b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseController.java index 38f80524..0cb9afa9 100644 --- a/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseController.java +++ b/iBase4J-Common/src/main/java/org/ibase4j/core/base/BaseController.java @@ -1,130 +1,130 @@ -/** - * - */ -package org.ibase4j.core.base; - -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.shiro.authz.UnauthorizedException; -import org.ibase4j.core.Constants; -import org.ibase4j.core.exception.BaseException; -import org.ibase4j.core.exception.IllegalParameterException; -import org.ibase4j.core.support.DateFormat; -import org.ibase4j.core.support.HttpCode; -import org.ibase4j.core.util.InstanceUtil; -import org.ibase4j.core.util.WebUtil; -import org.springframework.beans.propertyeditors.CustomDateEditor; -import org.springframework.http.ResponseEntity; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.InitBinder; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.serializer.SerializerFeature; -import com.baomidou.mybatisplus.plugins.Page; - -/** - * 控制器基类 - * - * @author ShenHuaJie - * @version 2016年5月20日 下午3:47:58 - */ -public abstract class BaseController { - protected final Logger logger = LogManager.getLogger(this.getClass()); - - /** 获取当前用户Id */ - protected Long getCurrUser() { - return WebUtil.getCurrentUser(); - } - - @InitBinder - protected void initBinder(WebDataBinder binder) { - binder.registerCustomEditor(Date.class, new CustomDateEditor(new DateFormat(), true)); - } - - /** 设置成功响应代码 */ - protected ResponseEntity setSuccessModelMap(ModelMap modelMap) { - return setSuccessModelMap(modelMap, null); - } - - /** 设置成功响应代码 */ - protected ResponseEntity setSuccessModelMap(ModelMap modelMap, Object data) { - return setModelMap(modelMap, HttpCode.OK, data); - } - - /** 设置响应代码 */ - protected ResponseEntity setModelMap(ModelMap modelMap, HttpCode code) { - return setModelMap(modelMap, code, null); - } - - /** 设置响应代码 */ - protected ResponseEntity setModelMap(ModelMap modelMap, HttpCode code, Object data) { - Map map = InstanceUtil.newLinkedHashMap(); - map.putAll(modelMap); - modelMap.clear(); - for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) { - String key = iterator.next(); - if (!key.startsWith("org.springframework.validation.BindingResult") && !key.equals("void")) { - modelMap.put(key, map.get(key)); - } - } - if (data != null) { - if (data instanceof Page) { - Page page = (Page) data; - modelMap.put("data", page.getRecords()); - modelMap.put("current", page.getCurrent()); - modelMap.put("size", page.getSize()); - modelMap.put("pages", page.getPages()); - modelMap.put("total", page.getTotal()); - modelMap.put("iTotalRecords", page.getTotal()); - modelMap.put("iTotalDisplayRecords", page.getTotal()); - } else if (data instanceof List) { - modelMap.put("data", data); - modelMap.put("iTotalRecords", ((List) data).size()); - modelMap.put("iTotalDisplayRecords", ((List) data).size()); - } else { - modelMap.put("data", data); - } - } - modelMap.put("httpCode", code.value()); - modelMap.put("msg", code.msg()); - modelMap.put("timestamp", System.currentTimeMillis()); - logger.info("RESPONSE : " + JSON.toJSONString(modelMap)); - return ResponseEntity.ok(modelMap); - } - - /** 异常处理 */ - @ExceptionHandler(Exception.class) - public void exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception ex) - throws Exception { - logger.error(Constants.Exception_Head, ex); - ModelMap modelMap = new ModelMap(); - if (ex instanceof BaseException) { - ((BaseException) ex).handler(modelMap); - } else if (ex instanceof IllegalArgumentException) { - new IllegalParameterException(ex.getMessage()).handler(modelMap); - } else if (ex instanceof UnauthorizedException) { - modelMap.put("httpCode", HttpCode.FORBIDDEN.value()); - modelMap.put("msg", StringUtils.defaultIfBlank(ex.getMessage(), HttpCode.FORBIDDEN.msg())); - } else { - modelMap.put("httpCode", HttpCode.INTERNAL_SERVER_ERROR.value()); - String msg = StringUtils.defaultIfBlank(ex.getMessage(), HttpCode.INTERNAL_SERVER_ERROR.msg()); - modelMap.put("msg", msg.length() > 100 ? "系统走神了,请稍候再试." : msg); - } - response.setContentType("application/json;charset=UTF-8"); - modelMap.put("timestamp", System.currentTimeMillis()); - logger.info("RESPONSE : " + JSON.toJSON(modelMap)); - byte[] bytes = JSON.toJSONBytes(modelMap, SerializerFeature.DisableCircularReferenceDetect); - response.getOutputStream().write(bytes); - } -} +/** + * + */ +package org.ibase4j.core.base; + +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.shiro.authz.UnauthorizedException; +import org.ibase4j.core.Constants; +import org.ibase4j.core.exception.BaseException; +import org.ibase4j.core.exception.IllegalParameterException; +import org.ibase4j.core.support.DateFormat; +import org.ibase4j.core.support.HttpCode; +import org.ibase4j.core.util.InstanceUtil; +import org.ibase4j.core.util.WebUtil; +import org.springframework.beans.propertyeditors.CustomDateEditor; +import org.springframework.http.ResponseEntity; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.InitBinder; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.baomidou.mybatisplus.plugins.Page; + +/** + * 控制器基类 + * + * @author ShenHuaJie + * @version 2016年5月20日 下午3:47:58 + */ +public abstract class BaseController { + protected final Logger logger = LogManager.getLogger(this.getClass()); + + /** 获取当前用户Id */ + protected Long getCurrUser() { + return WebUtil.getCurrentUser(); + } + + @InitBinder + protected void initBinder(WebDataBinder binder) { + binder.registerCustomEditor(Date.class, new CustomDateEditor(new DateFormat(), true)); + } + + /** 设置成功响应代码 */ + protected ResponseEntity setSuccessModelMap(ModelMap modelMap) { + return setSuccessModelMap(modelMap, null); + } + + /** 设置成功响应代码 */ + protected ResponseEntity setSuccessModelMap(ModelMap modelMap, Object data) { + return setModelMap(modelMap, HttpCode.OK, data); + } + + /** 设置响应代码 */ + protected ResponseEntity setModelMap(ModelMap modelMap, HttpCode code) { + return setModelMap(modelMap, code, null); + } + + /** 设置响应代码 */ + protected ResponseEntity setModelMap(ModelMap modelMap, HttpCode code, Object data) { + Map map = InstanceUtil.newLinkedHashMap(); + map.putAll(modelMap); + modelMap.clear(); + for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) { + String key = iterator.next(); + if (!key.startsWith("org.springframework.validation.BindingResult") && !key.equals("void")) { + modelMap.put(key, map.get(key)); + } + } + if (data != null) { + if (data instanceof Page) { + Page page = (Page) data; + modelMap.put("data", page.getRecords()); + modelMap.put("current", page.getCurrent()); + modelMap.put("size", page.getSize()); + modelMap.put("pages", page.getPages()); + modelMap.put("total", page.getTotal()); + modelMap.put("iTotalRecords", page.getTotal()); + modelMap.put("iTotalDisplayRecords", page.getTotal()); + } else if (data instanceof List) { + modelMap.put("data", data); + modelMap.put("iTotalRecords", ((List) data).size()); + modelMap.put("iTotalDisplayRecords", ((List) data).size()); + } else { + modelMap.put("data", data); + } + } + modelMap.put("httpCode", code.value()); + modelMap.put("msg", code.msg()); + modelMap.put("timestamp", System.currentTimeMillis()); + logger.info("RESPONSE : " + JSON.toJSONString(modelMap)); + return ResponseEntity.ok(modelMap); + } + + /** 异常处理 */ + @ExceptionHandler(Exception.class) + public void exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception ex) + throws Exception { + logger.error(Constants.Exception_Head, ex); + ModelMap modelMap = new ModelMap(); + if (ex instanceof BaseException) { + ((BaseException) ex).handler(modelMap); + } else if (ex instanceof IllegalArgumentException) { + new IllegalParameterException(ex.getMessage()).handler(modelMap); + } else if (ex instanceof UnauthorizedException) { + modelMap.put("httpCode", HttpCode.FORBIDDEN.value().toString()); + modelMap.put("msg", StringUtils.defaultIfBlank(ex.getMessage(), HttpCode.FORBIDDEN.msg())); + } else { + modelMap.put("httpCode", HttpCode.INTERNAL_SERVER_ERROR.value().toString()); + String msg = StringUtils.defaultIfBlank(ex.getMessage(), HttpCode.INTERNAL_SERVER_ERROR.msg()); + modelMap.put("msg", msg.length() > 100 ? "系统走神了,请稍候再试." : msg); + } + response.setContentType("application/json;charset=UTF-8"); + modelMap.put("timestamp", System.currentTimeMillis()); + logger.info("RESPONSE : " + JSON.toJSON(modelMap)); + byte[] bytes = JSON.toJSONBytes(modelMap, SerializerFeature.DisableCircularReferenceDetect); + response.getOutputStream().write(bytes); + } +} diff --git a/iBase4J-Common/src/main/resources/config/system.properties b/iBase4J-Common/src/main/resources/config/system.properties index a1e09139..04412ff3 100644 --- a/iBase4J-Common/src/main/resources/config/system.properties +++ b/iBase4J-Common/src/main/resources/config/system.properties @@ -9,9 +9,10 @@ rpc.protocol.threads=100 rpc.protocol.maxThread=500 rpc.protocol.minThread=20 rpc.cache.dir=/output/cache/ -rpc.timeout=20000 +rpc.connect.timeout=20000 +rpc.request.timeout=20000 #\u5931\u8d25\u91cd\u8bd5\u6b21\u6570 -rpc.consumer.retries=2 +rpc.consumer.retries=0 # redis.host=127.0.0.1 redis.port=6379 diff --git a/iBase4J-Common/src/main/resources/spring/dubbo.xml b/iBase4J-Common/src/main/resources/spring/dubbo.xml index 4adb9ae5..8062da19 100644 --- a/iBase4J-Common/src/main/resources/spring/dubbo.xml +++ b/iBase4J-Common/src/main/resources/spring/dubbo.xml @@ -14,12 +14,13 @@ - - + \ No newline at end of file diff --git a/iBase4J-Common/src/main/resources/spring/motan.xml b/iBase4J-Common/src/main/resources/spring/motan.xml index d62c32e0..95d38883 100644 --- a/iBase4J-Common/src/main/resources/spring/motan.xml +++ b/iBase4J-Common/src/main/resources/spring/motan.xml @@ -1,27 +1,28 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/iBase4J-Common/src/main/resources/spring/redis.xml b/iBase4J-Common/src/main/resources/spring/redis.xml index 41a33bb7..c07b1654 100644 --- a/iBase4J-Common/src/main/resources/spring/redis.xml +++ b/iBase4J-Common/src/main/resources/spring/redis.xml @@ -1,57 +1,58 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file