兴安访客小程序访客改造

This commit is contained in:
zc
2025-06-10 09:33:07 +08:00
parent 2d23219a0f
commit ccc1f08366
13 changed files with 603 additions and 95 deletions

View File

@@ -72,4 +72,6 @@ public class CacheConstants
public static final String WEIXIN_URL_LINK = "weixin_url_link";
public static final String WE_COM_TOKEN = "we_com_token:";
public static final String VISITOR_SMS_CODE = "visitor_sms_code:";
}

View File

@@ -1,11 +1,7 @@
package com.dcsoft.common.redis.service;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.HashOperations;
@@ -13,18 +9,24 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* spring redis 工具类
*
*
* @author dcsoft
**/
@SuppressWarnings(value = { "unchecked", "rawtypes" })
@Component
@Slf4j
public class RedisService
{
@Autowired
public RedisTemplate redisTemplate;
private static final long DEFAULT_TIMEOUT = 60 * 60 * 24 * 7;
/**
* 缓存基本的对象Integer、String、实体类等
*
@@ -36,6 +38,43 @@ public class RedisService
redisTemplate.opsForValue().set(key, value);
}
/**
* 缓存是否存在,存在返回false不存在返回true并存储缓存值
*
* @param key
* @param value
*/
public Boolean setIfAbsent(final String key, final String value, long timeout, TimeUnit timeUnit)
{
try {
return redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit);
} catch (Exception e) {
log.error("redis error:{}", e.getMessage());
return false;
}
}
/**
* 分布式加锁
*
* @param key
* @param value
*/
public Boolean lock(final String key, final String value, long timeout, TimeUnit timeUnit)
{
try {
if (timeout <= 0) {
timeout = DEFAULT_TIMEOUT;
timeUnit = TimeUnit.SECONDS;
}
return redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit);
} catch (Exception e) {
log.error("redis error:{}", e.getMessage());
return false;
}
}
/**
* 缓存基本的对象Integer、String、实体类等
*