格式化新提交的不规范代码

This commit is contained in:
Binary Wang 2019-10-14 16:49:34 +08:00
parent 2899978dfa
commit e33601ce78
5 changed files with 176 additions and 177 deletions

View File

@ -9,45 +9,44 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>wx-java-open-spring-boot-starter</artifactId>
<name>WxJava - Spring Boot Starter for WxOpen</name>
<description>微信开放平台开发的 Spring Boot Starter</description>
<artifactId>wx-java-open-spring-boot-starter</artifactId>
<name>WxJava - Spring Boot Starter for WxOpen</name>
<description>微信开放平台开发的 Spring Boot Starter</description>
<dependencies>
<dependencies>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-open</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-open</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -17,23 +17,23 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class WxOpenServiceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public WxOpenService wxOpenService(WxOpenConfigStorage configStorage) {
WxOpenService wxOpenService = new WxOpenServiceImpl();
wxOpenService.setWxOpenConfigStorage(configStorage);
return wxOpenService;
}
@Bean
@ConditionalOnMissingBean
public WxOpenService wxOpenService(WxOpenConfigStorage configStorage) {
WxOpenService wxOpenService = new WxOpenServiceImpl();
wxOpenService.setWxOpenConfigStorage(configStorage);
return wxOpenService;
}
@Bean
public WxOpenMessageRouter wxOpenMessageRouter(WxOpenService wxOpenService) {
return new WxOpenMessageRouter(wxOpenService);
}
@Bean
public WxOpenMessageRouter wxOpenMessageRouter(WxOpenService wxOpenService) {
return new WxOpenMessageRouter(wxOpenService);
}
@Bean
public WxOpenComponentService wxOpenComponentService(WxOpenService wxOpenService) {
return wxOpenService.getWxOpenComponentService();
}
@Bean
public WxOpenComponentService wxOpenComponentService(WxOpenService wxOpenService) {
return wxOpenService.getWxOpenComponentService();
}
}

View File

@ -23,71 +23,71 @@ import redis.clients.jedis.JedisPoolConfig;
@Configuration
@RequiredArgsConstructor
public class WxOpenStorageAutoConfiguration {
private final WxOpenProperties properties;
private final WxOpenProperties properties;
@Autowired(required = false)
private JedisPool jedisPool;
@Autowired(required = false)
private JedisPool jedisPool;
@Value("${wx.open.config-storage.redis.host:}")
private String redisHost;
@Value("${wx.open.config-storage.redis.host:}")
private String redisHost;
@Bean
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
WxOpenProperties.StorageType type = storage.getType();
@Bean
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
WxOpenProperties.StorageType type = storage.getType();
if (type == WxOpenProperties.StorageType.redis) {
return getWxOpenInRedisConfigStorage();
}
return getWxOpenInMemoryConfigStorage();
if (type == WxOpenProperties.StorageType.redis) {
return getWxOpenInRedisConfigStorage();
}
return getWxOpenInMemoryConfigStorage();
}
private WxOpenInMemoryConfigStorage getWxOpenInMemoryConfigStorage() {
WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage();
setWxOpenInfo(config);
return config;
private WxOpenInMemoryConfigStorage getWxOpenInMemoryConfigStorage() {
WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage();
setWxOpenInfo(config);
return config;
}
private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() {
JedisPool poolToUse = jedisPool;
if (jedisPool == null || StringUtils.isNotEmpty(redisHost)) {
poolToUse = getJedisPool();
}
WxOpenInRedisConfigStorage config = new WxOpenInRedisConfigStorage(poolToUse);
setWxOpenInfo(config);
return config;
}
private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() {
JedisPool poolToUse = jedisPool;
if (jedisPool == null || StringUtils.isNotEmpty(redisHost)) {
poolToUse = getJedisPool();
}
WxOpenInRedisConfigStorage config = new WxOpenInRedisConfigStorage(poolToUse);
setWxOpenInfo(config);
return config;
private void setWxOpenInfo(WxOpenConfigStorage config) {
config.setComponentAppId(properties.getAppId());
config.setComponentAppSecret(properties.getSecret());
config.setComponentToken(properties.getToken());
config.setComponentAesKey(properties.getAesKey());
}
private JedisPool getJedisPool() {
WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
RedisProperties redis = storage.getRedis();
JedisPoolConfig config = new JedisPoolConfig();
if (redis.getMaxActive() != null) {
config.setMaxTotal(redis.getMaxActive());
}
private void setWxOpenInfo(WxOpenConfigStorage config) {
config.setComponentAppId(properties.getAppId());
config.setComponentAppSecret(properties.getSecret());
config.setComponentToken(properties.getToken());
config.setComponentAesKey(properties.getAesKey());
if (redis.getMaxIdle() != null) {
config.setMaxIdle(redis.getMaxIdle());
}
private JedisPool getJedisPool() {
WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
RedisProperties redis = storage.getRedis();
JedisPoolConfig config = new JedisPoolConfig();
if (redis.getMaxActive() != null) {
config.setMaxTotal(redis.getMaxActive());
}
if (redis.getMaxIdle() != null) {
config.setMaxIdle(redis.getMaxIdle());
}
if (redis.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redis.getMaxWaitMillis());
}
if (redis.getMinIdle() != null) {
config.setMinIdle(redis.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);
JedisPool pool = new JedisPool(config, redis.getHost(), redis.getPort(),
redis.getTimeout(), redis.getPassword(), redis.getDatabase());
return pool;
if (redis.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redis.getMaxWaitMillis());
}
if (redis.getMinIdle() != null) {
config.setMinIdle(redis.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);
JedisPool pool = new JedisPool(config, redis.getHost(), redis.getPort(),
redis.getTimeout(), redis.getPassword(), redis.getDatabase());
return pool;
}
}

View File

@ -11,35 +11,35 @@ import java.io.Serializable;
*/
@Data
public class RedisProperties implements Serializable {
private static final long serialVersionUID = -5924815351660074401L;
private static final long serialVersionUID = -5924815351660074401L;
/**
* 主机地址.
*/
private String host = "127.0.0.1";
/**
* 主机地址.
*/
private String host = "127.0.0.1";
/**
* 端口号.
*/
private int port = 6379;
/**
* 端口号.
*/
private int port = 6379;
/**
* 密码.
*/
private String password;
/**
* 密码.
*/
private String password;
/**
* 超时.
*/
private int timeout = 2000;
/**
* 超时.
*/
private int timeout = 2000;
/**
* 数据库.
*/
private int database = 0;
/**
* 数据库.
*/
private int database = 0;
private Integer maxActive;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer minIdle;
private Integer maxActive;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer minIdle;
}

View File

@ -17,52 +17,52 @@ import static com.binarywang.spring.starter.wxjava.open.properties.WxOpenPropert
@Data
@ConfigurationProperties(PREFIX)
public class WxOpenProperties {
public static final String PREFIX = "wx.open";
public static final String PREFIX = "wx.open";
/**
* 设置微信开放平台的appid.
*/
private String appId;
/**
* 设置微信开放平台的app secret.
*/
private String secret;
/**
* 设置微信开放平台的token.
*/
private String token;
/**
* 设置微信开放平台的EncodingAESKey.
*/
private String aesKey;
/**
* 存储策略, memory, redis.
*/
private ConfigStorage configStorage = new ConfigStorage();
@Data
public static class ConfigStorage implements Serializable {
private static final long serialVersionUID = 4815731027000065434L;
private StorageType type = memory;
private RedisProperties redis = new RedisProperties();
}
public enum StorageType {
/**
* 设置微信开放平台的appid.
* 内存.
*/
private String appId;
memory,
/**
* 设置微信开放平台的app secret.
* redis.
*/
private String secret;
/**
* 设置微信开放平台的token.
*/
private String token;
/**
* 设置微信开放平台的EncodingAESKey.
*/
private String aesKey;
/**
* 存储策略, memory, redis.
*/
private ConfigStorage configStorage = new ConfigStorage();
@Data
public static class ConfigStorage implements Serializable {
private static final long serialVersionUID = 4815731027000065434L;
private StorageType type = memory;
private RedisProperties redis = new RedisProperties();
}
public enum StorageType {
/**
* 内存.
*/
memory,
/**
* redis.
*/
redis
}
redis
}
}