Skip to content

Commit

Permalink
修改结构.添加了微信公众号授权认证模块

Browse files Browse the repository at this point in the history
  • Loading branch information
叶云轩.MacBookPro committed Dec 27, 2019
1 parent 5a877a4 commit 9a7cae3
Show file tree
Hide file tree
Showing 31 changed files with 1,331 additions and 149 deletions.
14 changes: 14 additions & 0 deletions cjwy-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.cjwy.projects.commons.cache.condition;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.stereotype.Component;

/**
* 判断是否有Map使用的Condition
* <p>
*
* @author 叶云轩 at [email protected]
* @date 2018/9/8-11:16
*/
@Slf4j
@Component
public class MapCondition implements Condition {

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
Environment environment = context.getEnvironment();
String host = environment.getProperty("spring.redis.host");
String port = environment.getProperty("spring.redis.port");
// 如果端口号和主机名都为空,认为没有配置redis
boolean allEmpty = StrUtil.isAllEmpty(host, port);
log.info("MapCondition [是否配置了Redis] {}", allEmpty ? "没有配置" : "配置了");
return allEmpty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.cjwy.projects.commons.cache.condition;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.stereotype.Component;

/**
* 判断是否有Redis使用的Condition
* <p>
*
* @author 叶云轩 at [email protected]
* @date 2018/9/8-11:16
*/
@Slf4j
@Component
public class RedisCondition implements Condition {

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
Environment environment = context.getEnvironment();
String host = environment.getProperty("spring.redis.host");
String port = environment.getProperty("spring.redis.port");
// 如果端口号和主机名都为空,认为没有配置redis
boolean allEmpty = StrUtil.isAllEmpty(host, port);
log.info("RedisCondition [是否配置了Redis] {}", allEmpty ? "没有配置" : "配置了");
return !allEmpty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.cjwy.projects.commons.cache.config;

import com.cjwy.projects.commons.cache.condition.MapCondition;
import com.cjwy.projects.commons.cache.condition.RedisCondition;
import com.cjwy.projects.commons.cache.service.CacheService;
import com.cjwy.projects.commons.cache.service.achieve.MapCacheServiceImpl;
import com.cjwy.projects.commons.cache.service.achieve.RedisCacheServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
* 缓存配置类
* <p>
*
* @author 叶云轩 at [email protected]
* @date 2018/9/8-11:19
*/
@Configuration
public class CacheConfig {

/**
* CacheConfig日志输出
*/
private static final Logger LOGGER = LoggerFactory.getLogger(CacheConfig.class);

/**
* 缓存工具
*
* @param <K> key
* @param <V> value
* @return 缓存工具对象
*/
@Bean("cacheService")
@Conditional(MapCondition.class)
public <K, V> CacheService<K, V> mapCacheService() {
LOGGER.info("[使用Map实现缓存] ");
return new MapCacheServiceImpl<>();
}

/**
* 缓存工具
*
* @param <K> key
* @param <V> value
* @return 缓存工具对象
*/
@Bean("cacheService")
@Conditional(RedisCondition.class)
public <K, V> CacheService<K, V> redisCacheService() {
LOGGER.info("[使用Redis实现缓存] ");
return new RedisCacheServiceImpl<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package com.cjwy.projects.commons.cache.service;

import java.util.List;
import java.util.Set;

/**
* 缓存接口
* <p>
*
* @author 叶云轩 at [email protected]
* @date 2018/9/8-14:09
*/
public interface CacheService<K, V> {

/**
* 缓存list
*
* @param key 储存的数据的键
* @param value 储存的数据的值
* @return 缓存一个集合
*/
boolean cacheList(K key, V value);

/**
* 向一个list集合中添加新项
*
* @param key 储存的数据的键
* @param value 储存的数据的值
* @param time 缓存的时间
* @return 缓存的状态
*/
boolean cacheList(K key, V value, long time);

/**
* 缓存set
*
* @param key 储存的数据的键
* @param value 储存的数据的值
* @return 缓存的结果
*/
boolean cacheSet(K key, V value);

/**
* 缓存set操作
*
* @param key 储存的数据的键
* @param value 储存的数据的值
* @param time 数据的生命时长
* @return set状态
*/
boolean cacheSet(K key, V value, long time);

/**
* 存储单个K/V
*
* @param key 储存的数据的键
* @param value 储存的数据的值
* @return 数据存储状态
*/
boolean cacheValue(K key, V value);

/**
* 存储单个K/V
*
* @param key 储存的数据的键 redis缓存的键
* @param value 储存的数据的值 redis缓存的值
* @param time 记录的生命持续时间
* @return 存储状态
*/
boolean cacheValue(K key, V value, long time);

/**
* 判断key是否存在
*
* @param key 储存的数据的键
* @return 是否包含这个key
*/
boolean containsKey(K key);

/**
* 判断key是否存在
*
* @param key 储存的数据的键
* @return 是否包含这个key
*/
boolean containsListKey(K key);

/**
* 判断key是否存在
*
* @param key 储存的数据的键
* @return 是否包含这个key
*/
boolean containsSetKey(K key);

/**
* 判断key是否存在
*
* @param key 储存的数据的键
* @return 是否包含这个key
*/
boolean containsValueKey(K key);

/**
* 获取list缓存
*
* @param key 储存的数据的键
* @param start 开始获取的位置
* @param end 结束获取的位置
* @return 集合
*/
List<V> getList(K key, long start, long end);

/**
* 获取总条数, 可用于分页
*
* @param key 储存的数据的键
* @return 集合的长度
*/
long getListSize(K key);

/**
* 获取缓存set数据
*
* @param key 储存的数据的键
* @return 缓存的值
*/
Set<V> getSet(K key);

/**
* 获取单个KEY缓存
*
* @param key 储存的数据的键
* @return 获取缓存的value
*/
V getValue(K key);

/**
* 根据 Key 模糊查询
*
* @param key key
* @return key 集合
*/
Set<K> likeKeys(K key);

void print();

/**
* 移除某个KEY
*
* @param key 移除的数据的键
* @return 是否移除成功
*/
boolean remove(K key);

/**
* 移除并list中的首项
*
* @param key 储存的数据的键
* @return 移除结果
*/
boolean removeOneOfList(K key);

/**
* 移除某个KEY
*
* @param key 移除的数据的键
* @return 是否移除成功
*/
boolean removeValue(K key);
}
Loading

0 comments on commit 9a7cae3

Please sign in to comment.