This commit is contained in:
Leo
2025-11-08 15:46:40 +08:00
parent 654a496478
commit a8c948e958

View File

@@ -653,64 +653,64 @@ private String handleTF(String input) {
// 提取电话第7个字段
String phone = parts[6];
//每天可以使用 phoneWithTF 中的多个不同号码,每个号码只用一次
if ("13243039070".equals(phone) || "17530176250".equals(phone)) {
String today = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date());
String usedPhonesKey = "phone_used_today:" + today;
// if ("13243039070".equals(phone) || "17530176250".equals(phone)) {
// String today = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date());
// String usedPhonesKey = "phone_used_today:" + today;
if (stringRedisTemplate != null) {
try {
// 获取今天已经使用过的号码集合
Set<String> usedPhonesToday = stringRedisTemplate.opsForSet().members(usedPhonesKey);
// if (stringRedisTemplate != null) {
// try {
// // 获取今天已经使用过的号码集合
// Set<String> usedPhonesToday = stringRedisTemplate.opsForSet().members(usedPhonesKey);
// 找出今天还没使用过的号码
List<String> availablePhones = new ArrayList<>();
for (String p : phoneWithTF) {
if (usedPhonesToday == null || !usedPhonesToday.contains(p)) {
availablePhones.add(p);
}
}
// // 找出今天还没使用过的号码
// List<String> availablePhones = new ArrayList<>();
// for (String p : phoneWithTF) {
// if (usedPhonesToday == null || !usedPhonesToday.contains(p)) {
// availablePhones.add(p);
// }
// }
if (!availablePhones.isEmpty()) {
// 随机选择一个今天还没用过的号码
phone = availablePhones.get(new Random().nextInt(availablePhones.size()));
// 记录今天使用的号码24小时后自动过期
stringRedisTemplate.opsForSet().add(usedPhonesKey, phone);
stringRedisTemplate.expire(usedPhonesKey, 1, TimeUnit.DAYS);
} else {
// phoneWithTF 中的号码今天都用完了,使用备用号码(轮换使用)
String backupUsedKey = "backup_phone_used_today:" + today;
Set<String> backupUsedToday = stringRedisTemplate.opsForSet().members(backupUsedKey);
// if (!availablePhones.isEmpty()) {
// // 随机选择一个今天还没用过的号码
// phone = availablePhones.get(new Random().nextInt(availablePhones.size()));
// // 记录今天使用的号码24小时后自动过期
// stringRedisTemplate.opsForSet().add(usedPhonesKey, phone);
// stringRedisTemplate.expire(usedPhonesKey, 1, TimeUnit.DAYS);
// } else {
// // phoneWithTF 中的号码今天都用完了,使用备用号码(轮换使用)
// String backupUsedKey = "backup_phone_used_today:" + today;
// Set<String> backupUsedToday = stringRedisTemplate.opsForSet().members(backupUsedKey);
// 检查两个备用号码哪个还没用过
if (backupUsedToday == null || !backupUsedToday.contains("15639125541")) {
phone = "15639125541";
} else if (!backupUsedToday.contains("13243039070")) {
phone = "13243039070";
} else {
// 两个备用号码今天都用过了,继续轮换使用
String lastBackupKey = "last_backup_phone:" + today;
String lastBackup = stringRedisTemplate.opsForValue().get(lastBackupKey);
if ("15639125541".equals(lastBackup)) {
phone = "13243039070";
} else {
phone = "15639125541";
}
}
// // 检查两个备用号码哪个还没用过
// if (backupUsedToday == null || !backupUsedToday.contains("15639125541")) {
// phone = "15639125541";
// } else if (!backupUsedToday.contains("13243039070")) {
// phone = "13243039070";
// } else {
// // 两个备用号码今天都用过了,继续轮换使用
// String lastBackupKey = "last_backup_phone:" + today;
// String lastBackup = stringRedisTemplate.opsForValue().get(lastBackupKey);
// if ("15639125541".equals(lastBackup)) {
// phone = "13243039070";
// } else {
// phone = "15639125541";
// }
// }
// 记录今天使用的备用号码
stringRedisTemplate.opsForSet().add(backupUsedKey, phone);
stringRedisTemplate.expire(backupUsedKey, 1, TimeUnit.DAYS);
stringRedisTemplate.opsForValue().set("last_backup_phone:" + today, phone, 1, TimeUnit.DAYS);
}
} catch (Exception e) {
// Redis操作失败使用随机号码作为降级方案
phone = phoneWithTF.get(new Random().nextInt(phoneWithTF.size()));
}
} else {
// Redis不可用使用随机号码
phone = phoneWithTF.get(new Random().nextInt(phoneWithTF.size()));
}
}
// // 记录今天使用的备用号码
// stringRedisTemplate.opsForSet().add(backupUsedKey, phone);
// stringRedisTemplate.expire(backupUsedKey, 1, TimeUnit.DAYS);
// stringRedisTemplate.opsForValue().set("last_backup_phone:" + today, phone, 1, TimeUnit.DAYS);
// }
// } catch (Exception e) {
// // Redis操作失败使用随机号码作为降级方案
// phone = phoneWithTF.get(new Random().nextInt(phoneWithTF.size()));
// }
// } else {
// // Redis不可用使用随机号码
// phone = phoneWithTF.get(new Random().nextInt(phoneWithTF.size()));
// }
// }
// 构建地址:姓名+电话+地址信息
StringBuilder address = new StringBuilder();