refactor(user): update user information retrieval to use UserDTO and improve method documentation

This commit is contained in:
PIG AI committed 2025-07-04 11:58:50 +08:00
1 parent 3a53fb5677
commit d3770993ce
54 files changed
+810 -813

No files matched your search

@@ -16,11 +16,9 @@
package com.pig4cloud.pigx.mp.config;
import com.pig4cloud.pigx.common.data.cache.RedisUtils;
import me.chanjar.weixin.common.enums.TicketType;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.data.redis.core.RedisTemplate;
import java.util.concurrent.TimeUnit;
/**
* @author lengleng
@@ -36,16 +34,13 @@ public class WxMpInRedisConfigStorage extends WxMpDefaultConfigImpl {
private final static String CARDAPI_TICKET_KEY = "wechat:cardapi_ticket_";
private final RedisTemplate<String, String> redisTemplate;
private String accessTokenKey;
private String jsapiTicketKey;
private String cardapiTicketKey;
public WxMpInRedisConfigStorage(RedisTemplate redisTemplate) {
this.redisTemplate = redisTemplate;
public WxMpInRedisConfigStorage() {
}
/**
@@ -62,52 +57,52 @@ public class WxMpInRedisConfigStorage extends WxMpDefaultConfigImpl {
@Override
public String getAccessToken() {
return redisTemplate.opsForValue().get(this.accessTokenKey);
return RedisUtils.get(this.accessTokenKey);
}
@Override
public boolean isAccessTokenExpired() {
return redisTemplate.getExpire(accessTokenKey) < 2L;
return RedisUtils.getExpire(accessTokenKey) < 2L;
}
@Override
public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) {
redisTemplate.opsForValue().set(accessTokenKey, accessToken, expiresInSeconds - 200, TimeUnit.SECONDS);
RedisUtils.set(accessTokenKey, accessToken, expiresInSeconds - 200);
}
@Override
public void expireAccessToken() {
redisTemplate.expire(this.accessTokenKey, 0, TimeUnit.SECONDS);
RedisUtils.expire(this.accessTokenKey, 0);
}
@Override
public String getJsapiTicket() {
return redisTemplate.opsForValue().get(this.jsapiTicketKey);
return RedisUtils.get(this.jsapiTicketKey);
}
@Override
public String getCardApiTicket() {
return redisTemplate.opsForValue().get(cardapiTicketKey);
return RedisUtils.get(cardapiTicketKey);
}
@Override
public String getTicket(TicketType type) {
return redisTemplate.opsForValue().get(getTicketRedisKey(type));
return RedisUtils.get(getTicketRedisKey(type));
}
@Override
public boolean isTicketExpired(TicketType type) {
return redisTemplate.getExpire(this.getTicketRedisKey(type)) < 2;
return RedisUtils.getExpire(this.getTicketRedisKey(type)) < 2;
}
@Override
public synchronized void updateTicket(TicketType type, String jsapiTicket, int expiresInSeconds) {
redisTemplate.opsForValue().set(getTicketRedisKey(type), jsapiTicket, expiresInSeconds - 200, TimeUnit.SECONDS);
RedisUtils.set(getTicketRedisKey(type), jsapiTicket, expiresInSeconds - 200);
}
@Override
public void expireTicket(TicketType type) {
redisTemplate.expire(getTicketRedisKey(type), 0, TimeUnit.SECONDS);
RedisUtils.expire(getTicketRedisKey(type), 0);
}
private String getTicketRedisKey(TicketType type) {
@@ -20,7 +20,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.scheduling.annotation.Async;
@@ -83,8 +82,6 @@ public class WxMpInitConfigRunner {
private final ScanHandler scanHandler;
private final RedisTemplate redisTemplate;
@Async
@Order
@EventListener({ ApplicationReadyEvent.class })
@@ -105,7 +102,7 @@ public class WxMpInitConfigRunner {
// @formatter:on
mpServices = accountList.stream().map(a -> {
WxMpInRedisConfigStorage configStorage = new WxMpInRedisConfigStorage(redisTemplate);
WxMpInRedisConfigStorage configStorage = new WxMpInRedisConfigStorage();
configStorage.setAppId(a.getAppid());
configStorage.setSecret(a.getAppsecret());
configStorage.setToken(a.getToken());
@@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.data.cache.RedisUtils;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.security.annotation.HasPermission;
import com.pig4cloud.pigx.mp.config.WxMpInitConfigRunner;
@@ -30,7 +31,7 @@ import com.pig4cloud.pigx.mp.service.WxAccountService;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.web.bind.annotation.*;
/**
@@ -46,8 +47,6 @@ public class WxAccountController {
private final WxAccountService wxAccountService;
private final RedisTemplate redisTemplate;
/**
* 分页查询
* @param page 分页对象
@@ -82,7 +81,8 @@ public class WxAccountController {
@HasPermission("mp_wxaccount_add")
public R save(@RequestBody WxAccount wxAccount) {
wxAccountService.save(wxAccount);
redisTemplate.convertAndSend(CacheConstants.MP_REDIS_RELOAD_TOPIC, "重新加载公众号配置");
RedisUtils.execute((RedisCallback<Long>) connection ->
connection.publish(CacheConstants.MP_REDIS_RELOAD_TOPIC.getBytes(), "重新加载公众号配置".getBytes()));
return R.ok();
}
@@ -96,7 +96,8 @@ public class WxAccountController {
@HasPermission("mp_wxaccount_edit")
public R updateById(@RequestBody WxAccount wxAccount) {
wxAccountService.updateById(wxAccount);
redisTemplate.convertAndSend(CacheConstants.MP_REDIS_RELOAD_TOPIC, "重新加载公众号配置");
RedisUtils.execute((RedisCallback<Long>) connection ->
connection.publish(CacheConstants.MP_REDIS_RELOAD_TOPIC.getBytes(), "重新加载公众号配置".getBytes()));
return R.ok();
}
@@ -110,7 +111,8 @@ public class WxAccountController {
@HasPermission("mp_wxaccount_del")
public R removeById(@PathVariable Long id) {
wxAccountService.removeById(id);
redisTemplate.convertAndSend(CacheConstants.MP_REDIS_RELOAD_TOPIC, "重新加载公众号配置");
RedisUtils.execute((RedisCallback<Long>) connection ->
connection.publish(CacheConstants.MP_REDIS_RELOAD_TOPIC.getBytes(), "重新加载公众号配置".getBytes()));
return R.ok();
}