|
|
@@ -428,6 +428,38 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
return desc.length() > 0 ? desc.toString() : "全企业";
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成唯一的页面参数(针对2000条数据的优化版本)
|
|
|
+ */
|
|
|
+ private String generateUniquePageParam() {
|
|
|
+ // 获取所有已存在的pageParam(只取需要的字段)
|
|
|
+ List<String> existingParams = qwAcquisitionAssistantMapper.selectAllPageParams();
|
|
|
+ //使用Set,提高查找效率 O(1)
|
|
|
+ Set<String> paramSet = new HashSet<>(existingParams);
|
|
|
+
|
|
|
+ int maxAttempts = 10; // 设置最大尝试次数
|
|
|
+ int attempt = 0;
|
|
|
+
|
|
|
+ while (attempt < maxAttempts) {
|
|
|
+ // 生成6位随机码
|
|
|
+ String candidate = UniqueStringUtil.generateTimeBasedUnique(6);
|
|
|
+
|
|
|
+ // 使用Set的contains方法,O(1)复杂度
|
|
|
+ if (!paramSet.contains(candidate)) {
|
|
|
+ log.debug("生成页面参数成功: {}, 尝试次数: {}", candidate, attempt + 1);
|
|
|
+ return candidate;
|
|
|
+ }
|
|
|
+
|
|
|
+ attempt++;
|
|
|
+ log.debug("页面参数 {} 已存在,重新生成,第{}次尝试", candidate, attempt);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果多次尝试都失败,使用+1随机数方案
|
|
|
+ String finalParam = UniqueStringUtil.generateTimeBasedUnique(7);
|
|
|
+ log.warn("多次尝试后使用7位参数: {}", finalParam);
|
|
|
+ return finalParam;
|
|
|
+ }
|
|
|
+
|
|
|
// ==================== 获取详情方法 ====================
|
|
|
|
|
|
@Override
|
|
|
@@ -549,8 +581,10 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
assistant.setQwCreateTime(new Date(response.getLink().getCreateTime() * 1000));
|
|
|
}
|
|
|
|
|
|
- //生成随机网页参数编码(字母+数字)
|
|
|
- String randomParam = UniqueStringUtil.generateShortUnique();
|
|
|
+
|
|
|
+ //如果这个随机参数已存在,则重新生成
|
|
|
+ String randomParam =generateUniquePageParam();
|
|
|
+
|
|
|
assistant.setPageParam(randomParam);
|
|
|
|
|
|
// 生成scheme
|
|
|
@@ -608,11 +642,11 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
|
|
|
// 更新本地字段
|
|
|
setLocalFields(assistant, false);
|
|
|
- //TODO重新生成页面参数,需要修改对应redis缓存
|
|
|
+ //重新生成页面参数,需要修改对应redis缓存
|
|
|
String oldPageParam = existAssistant.getPageParam();
|
|
|
String oldKey = QW_ACQUISITION_URL_KEY_PREFIX + oldPageParam;
|
|
|
redisCache.deleteObject(oldKey);
|
|
|
- String newPageParam = UniqueStringUtil.generateShortUnique();
|
|
|
+ String newPageParam =generateUniquePageParam();
|
|
|
String newKey = QW_ACQUISITION_URL_KEY_PREFIX + newPageParam;
|
|
|
Integer cacheExpire = 10;//默认缓存10天
|
|
|
redisCache.setCacheObject(newKey, existAssistant.getUrl(), cacheExpire, TimeUnit.DAYS);
|