1
This commit is contained in:
@@ -23,6 +23,7 @@ import java.util.stream.Collectors;
|
|||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 jd 项目中 JDUtil 的指令能力,抽取为无微信依赖的本地执行版。
|
* 将 jd 项目中 JDUtil 的指令能力,抽取为无微信依赖的本地执行版。
|
||||||
@@ -609,27 +610,33 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
// 产品京东配置已迁移到Redis,通过productJdConfigService获取
|
// 产品京东配置已迁移到Redis,通过productJdConfigService获取
|
||||||
|
|
||||||
private static final List<String> phoneWithTF = new ArrayList<>();
|
private static final List<String> phoneWithTF = new ArrayList<>();
|
||||||
|
private static final AtomicInteger tfPhoneIndex = new AtomicInteger(0);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
/*
|
/*
|
||||||
|
|
||||||
13103996539
|
13723151190
|
||||||
15514755615
|
18839187854
|
||||||
17746927935
|
15639125541
|
||||||
13140433517
|
13243039070
|
||||||
17746921532
|
|
||||||
15514786055
|
|
||||||
*/
|
*/
|
||||||
phoneWithTF.add("13103996539");
|
phoneWithTF.add("13723151190");
|
||||||
phoneWithTF.add("15514755615");
|
phoneWithTF.add("18839187854");
|
||||||
phoneWithTF.add("17746927935");
|
phoneWithTF.add("15639125541");
|
||||||
phoneWithTF.add("13140433517");
|
phoneWithTF.add("13243039070");
|
||||||
phoneWithTF.add("17746921532");
|
|
||||||
phoneWithTF.add("15514786055");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String handleTF(String input) {
|
private String nextTfPhone(String defaultPhone) {
|
||||||
|
if (phoneWithTF.isEmpty()) {
|
||||||
|
return defaultPhone;
|
||||||
|
}
|
||||||
|
final int size = phoneWithTF.size();
|
||||||
|
int currentIndex = tfPhoneIndex.getAndUpdate(value -> (value + 1) % size);
|
||||||
|
return phoneWithTF.get(currentIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String handleTF(String input) {
|
||||||
String body = input.replaceFirst("^TF\\s*", "");
|
String body = input.replaceFirst("^TF\\s*", "");
|
||||||
body = body.replaceAll("[啊阿]", "");
|
body = body.replaceAll("[啊阿]", "");
|
||||||
String[] lines = body.split("\\r?\\n+");
|
String[] lines = body.split("\\r?\\n+");
|
||||||
@@ -663,65 +670,29 @@ 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)) && !phoneWithTF.isEmpty()) {
|
||||||
// String today = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
String originalPhone = phone;
|
||||||
// String usedPhonesKey = "phone_used_today:" + today;
|
if (stringRedisTemplate != null) {
|
||||||
|
try {
|
||||||
// if (stringRedisTemplate != null) {
|
String sequenceKey = "phone_tf_cycle_index";
|
||||||
// try {
|
Long index = stringRedisTemplate.opsForValue().increment(sequenceKey);
|
||||||
// // 获取今天已经使用过的号码集合
|
if (index == null) {
|
||||||
// Set<String> usedPhonesToday = stringRedisTemplate.opsForSet().members(usedPhonesKey);
|
phone = nextTfPhone(originalPhone);
|
||||||
|
} else {
|
||||||
// // 找出今天还没使用过的号码
|
int phoneIndex = (int) ((index - 1) % phoneWithTF.size());
|
||||||
// List<String> availablePhones = new ArrayList<>();
|
phone = phoneWithTF.get(phoneIndex);
|
||||||
// for (String p : phoneWithTF) {
|
if (index % phoneWithTF.size() == 0) {
|
||||||
// if (usedPhonesToday == null || !usedPhonesToday.contains(p)) {
|
stringRedisTemplate.opsForValue().set(sequenceKey, "0");
|
||||||
// availablePhones.add(p);
|
}
|
||||||
// }
|
}
|
||||||
// }
|
} catch (Exception e) {
|
||||||
|
phone = nextTfPhone(originalPhone);
|
||||||
// if (!availablePhones.isEmpty()) {
|
}
|
||||||
// // 随机选择一个今天还没用过的号码
|
} else {
|
||||||
// phone = availablePhones.get(new Random().nextInt(availablePhones.size()));
|
phone = nextTfPhone(originalPhone);
|
||||||
// // 记录今天使用的号码(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";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 记录今天使用的备用号码
|
|
||||||
// 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();
|
StringBuilder address = new StringBuilder();
|
||||||
|
|||||||
Reference in New Issue
Block a user