forked from luyan/epmet-cloud-lingshan
				
			
				 17 changed files with 241 additions and 47 deletions
			
			
		| @ -0,0 +1,56 @@ | |||
| package com.epmet.commons.tools.config; | |||
| 
 | |||
| import com.epmet.commons.tools.constant.NumConstant; | |||
| import com.epmet.commons.tools.constant.StrConstant; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.redisson.Redisson; | |||
| import org.redisson.api.RedissonClient; | |||
| import org.redisson.codec.JsonJacksonCodec; | |||
| import org.redisson.config.Config; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| 
 | |||
| /** | |||
|  * redisson 配置类 | |||
|  */ | |||
| @Slf4j | |||
| @Configuration | |||
| public class RedissonConfig { | |||
| 
 | |||
|     @Value("${spring.redis.host}") | |||
|     private String host; | |||
|     @Value("${spring.redis.port}") | |||
|     private String port; | |||
|     @Value("${spring.redis.password}") | |||
|     private String password; | |||
| 
 | |||
| 
 | |||
|     @Bean | |||
|     public RedissonClient getRedisson() { | |||
|         if (StringUtils.isBlank(host)) { | |||
|             log.warn("getRedisson redis param is null,don't need to init redissonClient"); | |||
|             return null; | |||
|         } | |||
| 
 | |||
|         try { | |||
|             Config config = new Config(); | |||
|             config.setCodec(new JsonJacksonCodec()); | |||
|             config.setThreads(NumConstant.FOUR); | |||
|             config.setNettyThreads(NumConstant.FOUR); | |||
|             //redis://ip:port
 | |||
|             //redis的部署方式有单节点部署、主从方式部署、哨兵方式部署、集群方式部署
 | |||
|             config.useSingleServer().setAddress("redis://".concat(host).concat(StrConstant.COLON).concat(port)); | |||
|             config.useSingleServer().setPassword(password); | |||
|             config.useSingleServer().setConnectTimeout(NumConstant.ONE_THOUSAND * NumConstant.FIVE); | |||
|             config.useSingleServer().setDatabase(NumConstant.TEN); | |||
|             return Redisson.create(config); | |||
|         } catch (Exception e) { | |||
|             log.error("初始化redisson失败", e); | |||
|             return null; | |||
|         } | |||
| 
 | |||
|     } | |||
| 
 | |||
| } | |||
| @ -0,0 +1,61 @@ | |||
| package com.epmet.stats.test; | |||
| 
 | |||
| import com.epmet.DataStatsApplication; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.junit.Test; | |||
| import org.junit.runner.RunWith; | |||
| import org.redisson.api.RLock; | |||
| import org.redisson.api.RedissonClient; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.boot.test.context.SpringBootTest; | |||
| import org.springframework.test.context.junit4.SpringRunner; | |||
| 
 | |||
| import java.util.concurrent.TimeUnit; | |||
| 
 | |||
| /** | |||
|  * desc:redisson测试类 | |||
|  */ | |||
| @Slf4j | |||
| @RunWith(value = SpringRunner.class) | |||
| @SpringBootTest(classes = {DataStatsApplication.class}) | |||
| public class RedissonTest { | |||
| 
 | |||
|     @Autowired | |||
|     private RedissonClient redissonClient; | |||
| 
 | |||
|     @Test | |||
|     public void lockTest() { | |||
|         //获取一个名为 lockName 的锁实例
 | |||
|         RLock lock = redissonClient.getLock("lockName"); | |||
|         try { | |||
|             // 尝试加锁(推荐使用)
 | |||
|             // 参数1 等待时长 waitTime:5 等待时长是5秒 如果5秒内还获取不到锁 则返回false,
 | |||
|             // 参数2 持有时长 leaseTime:5 持有锁时长超过5秒 就释放锁 此时如果继续lock.unlock()会抛出异常
 | |||
|             // 参数3 时间单位
 | |||
|             boolean bs = lock.tryLock(5, 6, TimeUnit.SECONDS); | |||
| 
 | |||
|             //如果获取不到锁 会一直阻塞到着 直至获取到锁 不推荐使用
 | |||
|             //lock.lock();
 | |||
| 
 | |||
|             //异步方式
 | |||
|         /*    RFuture<Void> future = lock.lockAsync(); | |||
|             if (future.isSuccess()){ | |||
|                 //todo something
 | |||
|             }*/ | |||
|             if (bs) { | |||
|                 // 业务代码
 | |||
|                 System.out.println("进入业务代码: " + 123); | |||
|             } else { | |||
|                 Thread.sleep(300); | |||
|             } | |||
|         } catch (Exception e) { | |||
|             log.error("lockTest exception", e); | |||
|         } finally { | |||
|             //判断是否是当前线程 持有锁
 | |||
|             if (lock.isHeldByCurrentThread()) { | |||
|                 lock.unlock(); | |||
|             } | |||
|         } | |||
|     } | |||
| 
 | |||
| } | |||
| @ -0,0 +1,7 @@ | |||
| 1. 当数据偏小时,可能社区下没有网格,例如 网格发文数量得分就为0; | |||
| 2. screen_index_data_monthly中的 数据条数 与客户下(组织数 + 直属部门数 + 网格数)的和不统一, | |||
|    原因:数据插入的时候,只算到了区县级,区县级以上的没有计算,少了 市级和省级agency | |||
| 
 | |||
| 文档地址: | |||
|     1. 大屏指标项文档说明:https://www.kdocs.cn/view/l/svtSfaUyzNYZ?f=130 | |||
|     2. 大屏或手机端:https://www.kdocs.cn/view/l/suilmk0Ziss1?f=130 | |||
					Loading…
					
					
				
		Reference in new issue