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

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

View File

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

View File

@ -23,71 +23,71 @@ import redis.clients.jedis.JedisPoolConfig;
@Configuration @Configuration
@RequiredArgsConstructor @RequiredArgsConstructor
public class WxOpenStorageAutoConfiguration { public class WxOpenStorageAutoConfiguration {
private final WxOpenProperties properties; private final WxOpenProperties properties;
@Autowired(required = false) @Autowired(required = false)
private JedisPool jedisPool; private JedisPool jedisPool;
@Value("${wx.open.config-storage.redis.host:}") @Value("${wx.open.config-storage.redis.host:}")
private String redisHost; private String redisHost;
@Bean @Bean
@ConditionalOnMissingBean(WxOpenConfigStorage.class) @ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() { public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenProperties.ConfigStorage storage = properties.getConfigStorage(); WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
WxOpenProperties.StorageType type = storage.getType(); WxOpenProperties.StorageType type = storage.getType();
if (type == WxOpenProperties.StorageType.redis) { if (type == WxOpenProperties.StorageType.redis) {
return getWxOpenInRedisConfigStorage(); return getWxOpenInRedisConfigStorage();
}
return getWxOpenInMemoryConfigStorage();
} }
return getWxOpenInMemoryConfigStorage();
}
private WxOpenInMemoryConfigStorage getWxOpenInMemoryConfigStorage() { private WxOpenInMemoryConfigStorage getWxOpenInMemoryConfigStorage() {
WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage(); WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage();
setWxOpenInfo(config); setWxOpenInfo(config);
return 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() { private void setWxOpenInfo(WxOpenConfigStorage config) {
JedisPool poolToUse = jedisPool; config.setComponentAppId(properties.getAppId());
if (jedisPool == null || StringUtils.isNotEmpty(redisHost)) { config.setComponentAppSecret(properties.getSecret());
poolToUse = getJedisPool(); config.setComponentToken(properties.getToken());
} config.setComponentAesKey(properties.getAesKey());
WxOpenInRedisConfigStorage config = new WxOpenInRedisConfigStorage(poolToUse); }
setWxOpenInfo(config);
return config; 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) {
private void setWxOpenInfo(WxOpenConfigStorage config) { config.setMaxIdle(redis.getMaxIdle());
config.setComponentAppId(properties.getAppId());
config.setComponentAppSecret(properties.getSecret());
config.setComponentToken(properties.getToken());
config.setComponentAesKey(properties.getAesKey());
} }
if (redis.getMaxWaitMillis() != null) {
private JedisPool getJedisPool() { config.setMaxWaitMillis(redis.getMaxWaitMillis());
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.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 @Data
public class RedisProperties implements Serializable { 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 maxActive;
private Integer maxIdle; private Integer maxIdle;
private Integer maxWaitMillis; private Integer maxWaitMillis;
private Integer minIdle; private Integer minIdle;
} }

View File

@ -17,52 +17,52 @@ import static com.binarywang.spring.starter.wxjava.open.properties.WxOpenPropert
@Data @Data
@ConfigurationProperties(PREFIX) @ConfigurationProperties(PREFIX)
public class WxOpenProperties { 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; redis
}
/**
* 设置微信开放平台的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
}
} }