+25
@@ -34,10 +34,12 @@ public class ZiniaoAuthService {
|
||||
private static final String CACHE_TYPE_COMPANY_ID = "COMPANY_ID";
|
||||
private static final String CACHE_TYPE_STAFF_LIST = "STAFF_LIST";
|
||||
private static final String CACHE_TYPE_USER_STORES = "USER_STORES";
|
||||
private static final String CACHE_TYPE_INVALID_USER_STORES = "INVALID_USER_STORES";
|
||||
private static final String CACHE_TYPE_SHOP_MATCH = "SHOP_MATCH";
|
||||
private static final Duration COMPANY_ID_CACHE_TTL = Duration.ofHours(12);
|
||||
private static final Duration STAFF_LIST_CACHE_TTL = Duration.ofMinutes(30);
|
||||
private static final Duration USER_STORES_CACHE_TTL = Duration.ofMinutes(30);
|
||||
private static final Duration INVALID_USER_STORES_CACHE_TTL = Duration.ofMinutes(30);
|
||||
private static final Duration SHOP_MATCH_CACHE_TTL = Duration.ofMinutes(30);
|
||||
|
||||
public StoreMatchResult matchStoreByNameAcrossStaff(String targetShopName, Long preferUserId) {
|
||||
@@ -139,6 +141,9 @@ public class ZiniaoAuthService {
|
||||
}
|
||||
|
||||
public List<ZiniaoShopCacheDto> getOrLoadUserStoresForIndex(String apiKey, Long companyId, Long userId) {
|
||||
if (isInvalidUserCachedForIndex(apiKey, companyId, userId)) {
|
||||
return List.of();
|
||||
}
|
||||
return getOrLoadUserStores(apiKey, companyId, userId);
|
||||
}
|
||||
|
||||
@@ -182,6 +187,11 @@ public boolean isIpWhitelistError(BusinessException ex) {
|
||||
if (apiKey == null || apiKey.isBlank() || companyId == null || companyId <= 0 || userId == null || userId <= 0) {
|
||||
return;
|
||||
}
|
||||
ziniaoTransientCacheService.put(
|
||||
CACHE_TYPE_INVALID_USER_STORES,
|
||||
buildUserScopeCacheKey(apiKey, companyId, userId),
|
||||
Boolean.TRUE,
|
||||
INVALID_USER_STORES_CACHE_TTL);
|
||||
String staffCacheKey = buildApiKeyHash(apiKey) + ":" + companyId;
|
||||
ziniaoTransientCacheService.getList(CACHE_TYPE_STAFF_LIST, staffCacheKey, ZiniaoStaffItemVo.class)
|
||||
.ifPresent(staff -> {
|
||||
@@ -197,6 +207,21 @@ public boolean isIpWhitelistError(BusinessException ex) {
|
||||
ziniaoTransientCacheService.delete(CACHE_TYPE_USER_STORES, buildApiKeyHash(apiKey) + ":" + companyId + ":" + userId);
|
||||
}
|
||||
|
||||
private boolean isInvalidUserCachedForIndex(String apiKey, Long companyId, Long userId) {
|
||||
if (apiKey == null || apiKey.isBlank() || companyId == null || companyId <= 0 || userId == null || userId <= 0) {
|
||||
return false;
|
||||
}
|
||||
return ziniaoTransientCacheService.get(
|
||||
CACHE_TYPE_INVALID_USER_STORES,
|
||||
buildUserScopeCacheKey(apiKey, companyId, userId),
|
||||
Boolean.class)
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
private String buildUserScopeCacheKey(String apiKey, Long companyId, Long userId) {
|
||||
return buildApiKeyHash(apiKey) + ":" + companyId + ":" + userId;
|
||||
}
|
||||
|
||||
private boolean isSkippableUserStoresError(BusinessException ex) {
|
||||
String message = ex == null ? null : ex.getMessage();
|
||||
if (message == null || message.isBlank()) {
|
||||
|
||||
Reference in New Issue
Block a user