1
This commit is contained in:
@@ -477,56 +477,55 @@ private String handleTF(String input) {
|
|||||||
|
|
||||||
// 提取电话(第7个字段)
|
// 提取电话(第7个字段)
|
||||||
String phone = parts[6];
|
String phone = parts[6];
|
||||||
//每天至多从phoneWithTF中进行一次替换
|
//每天可以使用 phoneWithTF 中的多个不同号码,每个号码只用一次
|
||||||
if ("13243039070".equals(phone) || "17530176250".equals(phone)) {
|
if ("13243039070".equals(phone) || "17530176250".equals(phone)) {
|
||||||
String today = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
String today = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||||
String phoneUsageKey = "phone_usage:" + today;
|
String usedPhonesKey = "phone_used_today:" + today;
|
||||||
|
|
||||||
if (stringRedisTemplate != null) {
|
if (stringRedisTemplate != null) {
|
||||||
try {
|
try {
|
||||||
// 获取今天已经使用过的号码
|
// 获取今天已经使用过的号码集合
|
||||||
String usedPhone = stringRedisTemplate.opsForValue().get(phoneUsageKey);
|
Set<String> usedPhonesToday = stringRedisTemplate.opsForSet().members(usedPhonesKey);
|
||||||
|
|
||||||
if (usedPhone != null) {
|
// 找出今天还没使用过的号码
|
||||||
// 今天已经替换过了,使用已记录的号码
|
List<String> availablePhones = new ArrayList<>();
|
||||||
phone = usedPhone;
|
for (String p : phoneWithTF) {
|
||||||
} else {
|
if (usedPhonesToday == null || !usedPhonesToday.contains(p)) {
|
||||||
// 今天还没有替换过,从列表中选择一个可用的号码
|
availablePhones.add(p);
|
||||||
// 获取最近使用过的所有号码(保留7天)
|
|
||||||
String usedPhonesKey = "used_phones_history";
|
|
||||||
Set<String> usedPhones = stringRedisTemplate.opsForSet().members(usedPhonesKey);
|
|
||||||
|
|
||||||
// 找出还没使用过的号码
|
|
||||||
List<String> availablePhones = new ArrayList<>();
|
|
||||||
for (String p : phoneWithTF) {
|
|
||||||
if (usedPhones == null || !usedPhones.contains(p)) {
|
|
||||||
availablePhones.add(p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!availablePhones.isEmpty()) {
|
if (!availablePhones.isEmpty()) {
|
||||||
// 随机选择一个可用的号码
|
// 随机选择一个今天还没用过的号码
|
||||||
phone = availablePhones.get(new Random().nextInt(availablePhones.size()));
|
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 {
|
} else {
|
||||||
// 所有号码都用过了,使用备用号码(轮换使用)
|
// 两个备用号码今天都用过了,继续轮换使用
|
||||||
String lastBackupKey = "last_backup_phone";
|
String lastBackupKey = "last_backup_phone:" + today;
|
||||||
String lastBackup = stringRedisTemplate.opsForValue().get(lastBackupKey);
|
String lastBackup = stringRedisTemplate.opsForValue().get(lastBackupKey);
|
||||||
if ("15639125541".equals(lastBackup)) {
|
if ("15639125541".equals(lastBackup)) {
|
||||||
phone = "13243039070";
|
phone = "13243039070";
|
||||||
} else {
|
} else {
|
||||||
phone = "15639125541";
|
phone = "15639125541";
|
||||||
}
|
}
|
||||||
stringRedisTemplate.opsForValue().set(lastBackupKey, phone);
|
|
||||||
// 清空历史记录,重新开始
|
|
||||||
stringRedisTemplate.delete(usedPhonesKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 记录今天使用的号码(24小时过期)
|
// 记录今天使用的备用号码
|
||||||
stringRedisTemplate.opsForValue().set(phoneUsageKey, phone, 1, TimeUnit.DAYS);
|
stringRedisTemplate.opsForSet().add(backupUsedKey, phone);
|
||||||
// 添加到历史记录(不过期,手动管理)
|
stringRedisTemplate.expire(backupUsedKey, 1, TimeUnit.DAYS);
|
||||||
if (availablePhones.contains(phone)) {
|
stringRedisTemplate.opsForValue().set("last_backup_phone:" + today, phone, 1, TimeUnit.DAYS);
|
||||||
stringRedisTemplate.opsForSet().add(usedPhonesKey, phone);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Redis操作失败,使用随机号码作为降级方案
|
// Redis操作失败,使用随机号码作为降级方案
|
||||||
|
|||||||
Reference in New Issue
Block a user