Skip to content

Commit 3a1fae6

Browse files
committed
🔨 规范代码
1 parent 44b3680 commit 3a1fae6

File tree

5 files changed

+148
-126
lines changed

5 files changed

+148
-126
lines changed

starters/wx-java-mp-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpAutoConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.context.annotation.Import;
77

8+
/**
9+
* .
10+
*
11+
* @author someone
12+
*/
813
@Configuration
914
@EnableConfigurationProperties(WxMpProperties.class)
1015
@Import({WxMpStorageAutoConfiguration.class, WxMpServiceAutoConfiguration.class})

starters/wx-java-mp-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpServiceAutoConfiguration.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,44 @@
1212
import org.springframework.context.annotation.Configuration;
1313

1414
/**
15-
* 微信公众号相关服务自动注册
15+
* 微信公众号相关服务自动注册.
16+
*
17+
* @author someone
1618
*/
1719
@Configuration
1820
public class WxMpServiceAutoConfiguration {
19-
@Autowired
20-
private ApplicationContext ctx;
21+
@Autowired
22+
private ApplicationContext ctx;
2123

22-
@Bean
23-
@ConditionalOnMissingBean
24-
public WxMpService wxMpService(WxMpConfigStorage configStorage) {
25-
WxMpService wxMpService = new WxMpServiceImpl();
26-
wxMpService.setWxMpConfigStorage(configStorage);
27-
registerWxMpSubService(wxMpService);
28-
return wxMpService;
29-
}
24+
@Bean
25+
@ConditionalOnMissingBean
26+
public WxMpService wxMpService(WxMpConfigStorage configStorage) {
27+
WxMpService wxMpService = new WxMpServiceImpl();
28+
wxMpService.setWxMpConfigStorage(configStorage);
29+
registerWxMpSubService(wxMpService);
30+
return wxMpService;
31+
}
3032

31-
@ConditionalOnBean(WxMpService.class)
32-
public Object registerWxMpSubService(WxMpService wxMpService) {
33-
ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory) ctx.getAutowireCapableBeanFactory();
34-
factory.registerSingleton("wxMpKefuService", wxMpService.getKefuService());
35-
factory.registerSingleton("wxMpMaterialService", wxMpService.getMaterialService());
36-
factory.registerSingleton("wxMpMenuService", wxMpService.getMenuService());
37-
factory.registerSingleton("wxMpUserService", wxMpService.getUserService());
38-
factory.registerSingleton("wxMpUserTagService", wxMpService.getUserTagService());
39-
factory.registerSingleton("wxMpQrcodeService", wxMpService.getQrcodeService());
40-
factory.registerSingleton("wxMpCardService", wxMpService.getCardService());
41-
factory.registerSingleton("wxMpDataCubeService", wxMpService.getDataCubeService());
42-
factory.registerSingleton("wxMpUserBlacklistService", wxMpService.getBlackListService());
43-
factory.registerSingleton("wxMpStoreService", wxMpService.getStoreService());
44-
factory.registerSingleton("wxMpTemplateMsgService", wxMpService.getTemplateMsgService());
45-
factory.registerSingleton("wxMpSubscribeMsgService", wxMpService.getSubscribeMsgService());
46-
factory.registerSingleton("wxMpDeviceService", wxMpService.getDeviceService());
47-
factory.registerSingleton("wxMpShakeService", wxMpService.getShakeService());
48-
factory.registerSingleton("wxMpMemberCardService", wxMpService.getMemberCardService());
49-
factory.registerSingleton("wxMpMassMessageService", wxMpService.getMassMessageService());
50-
return Boolean.TRUE;
51-
}
33+
@ConditionalOnBean(WxMpService.class)
34+
public Object registerWxMpSubService(WxMpService wxMpService) {
35+
ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory) ctx.getAutowireCapableBeanFactory();
36+
factory.registerSingleton("wxMpKefuService", wxMpService.getKefuService());
37+
factory.registerSingleton("wxMpMaterialService", wxMpService.getMaterialService());
38+
factory.registerSingleton("wxMpMenuService", wxMpService.getMenuService());
39+
factory.registerSingleton("wxMpUserService", wxMpService.getUserService());
40+
factory.registerSingleton("wxMpUserTagService", wxMpService.getUserTagService());
41+
factory.registerSingleton("wxMpQrcodeService", wxMpService.getQrcodeService());
42+
factory.registerSingleton("wxMpCardService", wxMpService.getCardService());
43+
factory.registerSingleton("wxMpDataCubeService", wxMpService.getDataCubeService());
44+
factory.registerSingleton("wxMpUserBlacklistService", wxMpService.getBlackListService());
45+
factory.registerSingleton("wxMpStoreService", wxMpService.getStoreService());
46+
factory.registerSingleton("wxMpTemplateMsgService", wxMpService.getTemplateMsgService());
47+
factory.registerSingleton("wxMpSubscribeMsgService", wxMpService.getSubscribeMsgService());
48+
factory.registerSingleton("wxMpDeviceService", wxMpService.getDeviceService());
49+
factory.registerSingleton("wxMpShakeService", wxMpService.getShakeService());
50+
factory.registerSingleton("wxMpMemberCardService", wxMpService.getMemberCardService());
51+
factory.registerSingleton("wxMpMassMessageService", wxMpService.getMassMessageService());
52+
return Boolean.TRUE;
53+
}
5254

5355
}

starters/wx-java-mp-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.binarywang.spring.starter.wxjava.mp.properties.RedisProperties;
44
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
5+
import lombok.RequiredArgsConstructor;
56
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
67
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
78
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
@@ -13,74 +14,75 @@
1314
import redis.clients.jedis.JedisPoolConfig;
1415

1516
/**
16-
* 微信公众号存储策略自动配置
17+
* 微信公众号存储策略自动配置.
18+
*
19+
* @author someone
1720
*/
1821
@Configuration
22+
@RequiredArgsConstructor
1923
public class WxMpStorageAutoConfiguration {
24+
private final WxMpProperties properties;
2025

21-
@Autowired
22-
private WxMpProperties properties;
26+
@Autowired(required = false)
27+
private JedisPool jedisPool;
2328

24-
@Autowired(required = false)
25-
private JedisPool jedisPool;
29+
@Bean
30+
@ConditionalOnMissingBean(WxMpConfigStorage.class)
31+
public WxMpConfigStorage wxMpInMemoryConfigStorage() {
32+
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
33+
WxMpProperties.StorageType type = storage.getType();
2634

27-
@Bean
28-
@ConditionalOnMissingBean(WxMpConfigStorage.class)
29-
public WxMpConfigStorage wxMpInMemoryConfigStorage() {
30-
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
31-
WxMpProperties.StorageType type = storage.getType();
32-
33-
if (type == WxMpProperties.StorageType.redis) {
34-
return getWxMpInRedisConfigStorage();
35-
}
36-
return getWxMpInMemoryConfigStorage();
37-
}
38-
39-
private WxMpDefaultConfigImpl getWxMpInMemoryConfigStorage() {
40-
WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
41-
setWxMpInfo(config);
42-
return config;
35+
if (type == WxMpProperties.StorageType.redis) {
36+
return getWxMpInRedisConfigStorage();
4337
}
38+
return getWxMpInMemoryConfigStorage();
39+
}
4440

45-
private WxMpRedisConfigImpl getWxMpInRedisConfigStorage() {
46-
JedisPool poolToUse = jedisPool;
47-
if (poolToUse == null) {
48-
poolToUse = getJedisPool();
49-
}
50-
WxMpRedisConfigImpl config = new WxMpRedisConfigImpl(poolToUse);
51-
setWxMpInfo(config);
52-
return config;
53-
}
41+
private WxMpDefaultConfigImpl getWxMpInMemoryConfigStorage() {
42+
WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
43+
setWxMpInfo(config);
44+
return config;
45+
}
5446

55-
private void setWxMpInfo(WxMpDefaultConfigImpl config) {
56-
config.setAppId(properties.getAppId());
57-
config.setSecret(properties.getSecret());
58-
config.setToken(properties.getToken());
59-
config.setAesKey(properties.getAesKey());
47+
private WxMpRedisConfigImpl getWxMpInRedisConfigStorage() {
48+
JedisPool poolToUse = jedisPool;
49+
if (poolToUse == null) {
50+
poolToUse = getJedisPool();
6051
}
52+
WxMpRedisConfigImpl config = new WxMpRedisConfigImpl(poolToUse);
53+
setWxMpInfo(config);
54+
return config;
55+
}
6156

62-
private JedisPool getJedisPool() {
63-
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
64-
RedisProperties redis = storage.getRedis();
57+
private void setWxMpInfo(WxMpDefaultConfigImpl config) {
58+
config.setAppId(properties.getAppId());
59+
config.setSecret(properties.getSecret());
60+
config.setToken(properties.getToken());
61+
config.setAesKey(properties.getAesKey());
62+
}
6563

66-
JedisPoolConfig config = new JedisPoolConfig();
67-
if (redis.getMaxActive() != null) {
68-
config.setMaxTotal(redis.getMaxActive());
69-
}
70-
if (redis.getMaxIdle() != null) {
71-
config.setMaxIdle(redis.getMaxIdle());
72-
}
73-
if (redis.getMaxWaitMillis() != null) {
74-
config.setMaxWaitMillis(redis.getMaxWaitMillis());
75-
}
76-
if (redis.getMinIdle() != null) {
77-
config.setMinIdle(redis.getMinIdle());
78-
}
79-
config.setTestOnBorrow(true);
80-
config.setTestWhileIdle(true);
64+
private JedisPool getJedisPool() {
65+
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
66+
RedisProperties redis = storage.getRedis();
8167

82-
JedisPool pool = new JedisPool(config, redis.getHost(), redis.getPort(),
83-
redis.getTimeout(), redis.getPassword(), redis.getDatabase());
84-
return pool;
68+
JedisPoolConfig config = new JedisPoolConfig();
69+
if (redis.getMaxActive() != null) {
70+
config.setMaxTotal(redis.getMaxActive());
8571
}
72+
if (redis.getMaxIdle() != null) {
73+
config.setMaxIdle(redis.getMaxIdle());
74+
}
75+
if (redis.getMaxWaitMillis() != null) {
76+
config.setMaxWaitMillis(redis.getMaxWaitMillis());
77+
}
78+
if (redis.getMinIdle() != null) {
79+
config.setMinIdle(redis.getMinIdle());
80+
}
81+
config.setTestOnBorrow(true);
82+
config.setTestWhileIdle(true);
83+
84+
JedisPool pool = new JedisPool(config, redis.getHost(), redis.getPort(),
85+
redis.getTimeout(), redis.getPassword(), redis.getDatabase());
86+
return pool;
87+
}
8688
}

starters/wx-java-mp-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,41 @@
55
import java.io.Serializable;
66

77
/**
8-
* Redis配置
8+
* Redis配置.
9+
*
10+
* @author someone
911
*/
1012
@Data
1113
public class RedisProperties implements Serializable {
12-
13-
/**
14-
* 主机地址
15-
*/
16-
private String host = "127.0.0.1";
17-
18-
/**
19-
* 端口号
20-
*/
21-
private int port = 6379;
22-
23-
/**
24-
* 密码
25-
*/
26-
private String password;
27-
28-
/**
29-
* 超时
30-
*/
31-
private int timeout = 2000;
32-
33-
/**
34-
* 数据库
35-
*/
36-
private int database = 0;
37-
38-
private Integer maxActive;
39-
private Integer maxIdle;
40-
private Integer maxWaitMillis;
41-
private Integer minIdle;
14+
private static final long serialVersionUID = -5924815351660074401L;
15+
16+
/**
17+
* 主机地址.
18+
*/
19+
private String host = "127.0.0.1";
20+
21+
/**
22+
* 端口号.
23+
*/
24+
private int port = 6379;
25+
26+
/**
27+
* 密码.
28+
*/
29+
private String password;
30+
31+
/**
32+
* 超时.
33+
*/
34+
private int timeout = 2000;
35+
36+
/**
37+
* 数据库.
38+
*/
39+
private int database = 0;
40+
41+
private Integer maxActive;
42+
private Integer maxIdle;
43+
private Integer maxWaitMillis;
44+
private Integer minIdle;
4245
}

starters/wx-java-mp-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,44 @@
1010

1111

1212
/**
13-
* 微信接入相关配置属性
13+
* 微信接入相关配置属性.
14+
*
15+
* @author someone
1416
*/
1517
@Data
1618
@ConfigurationProperties(PREFIX)
1719
public class WxMpProperties {
1820
public static final String PREFIX = "wx.mp";
1921

2022
/**
21-
* 设置微信公众号的appid
23+
* 设置微信公众号的appid.
2224
*/
2325
private String appId;
2426

2527
/**
26-
* 设置微信公众号的app secret
28+
* 设置微信公众号的app secret.
2729
*/
2830
private String secret;
2931

3032
/**
31-
* 设置微信公众号的token
33+
* 设置微信公众号的token.
3234
*/
3335
private String token;
3436

3537
/**
36-
* 设置微信公众号的EncodingAESKey
38+
* 设置微信公众号的EncodingAESKey.
3739
*/
3840
private String aesKey;
3941

4042
/**
41-
* 存储策略, memory, redis
43+
* 存储策略, memory, redis.
4244
*/
4345
private ConfigStorage configStorage = new ConfigStorage();
4446

4547

4648
@Data
4749
public static class ConfigStorage implements Serializable {
50+
private static final long serialVersionUID = 4815731027000065434L;
4851

4952
private StorageType type = memory;
5053

@@ -53,6 +56,13 @@ public static class ConfigStorage implements Serializable {
5356
}
5457

5558
public enum StorageType {
56-
memory, redis
59+
/**
60+
* 内存.
61+
*/
62+
memory,
63+
/**
64+
* redis.
65+
*/
66+
redis
5767
}
5868
}

0 commit comments

Comments
 (0)