价保
This commit is contained in:
@@ -73,27 +73,38 @@ public class OrderUtil {
|
|||||||
sendDailyStats(wxId);
|
sendDailyStats(wxId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理价保逻辑
|
// 处理价保逻辑
|
||||||
BigDecimal newProPriceAmount = Optional.ofNullable(orderRow.getProPriceAmount())
|
BigDecimal newProPriceAmount = Optional.ofNullable(orderRow.getProPriceAmount()).map(BigDecimal::new).orElse(BigDecimal.ZERO);
|
||||||
.map(BigDecimal::new)
|
|
||||||
.orElse(BigDecimal.ZERO);
|
|
||||||
|
|
||||||
if (BigDecimal.ZERO.compareTo(newProPriceAmount) < 0) {
|
// 获取Redis中的旧价保金额和通知状态
|
||||||
String oldProPriceAmountStr = getFromRedis(ORDER_ROW_JB_KEY + orderRow.getId());
|
String redisKey = ORDER_ROW_JB_KEY + orderRow.getId();
|
||||||
BigDecimal oldProPriceAmount = oldProPriceAmountStr == null ?
|
String redisValue = getFromRedis(redisKey);
|
||||||
BigDecimal.ZERO : new BigDecimal(oldProPriceAmountStr);
|
|
||||||
|
|
||||||
if (newProPriceAmount.compareTo(oldProPriceAmount) != 0) {
|
// 解析Redis值,格式为 "金额:通知状态",例如 "100.00:true"
|
||||||
String wxId = getWxidFromJdid(orderRow.getUnionId().toString());
|
String[] parts = redisValue != null ? redisValue.split(":") : new String[0];
|
||||||
if (Util.isNotEmpty(wxId)) {
|
BigDecimal oldProPriceAmount = parts.length > 0 ? new BigDecimal(parts[0]) : BigDecimal.ZERO;
|
||||||
String content = getFormattedOrderInfo(orderRow);
|
boolean hasNotified = parts.length > 1 && Boolean.parseBoolean(parts[1]);
|
||||||
String alertMsg = "[Broken][Broken][Broken] 价保提醒 [Broken][Broken][Broken] " + newProPriceAmount + "\n" + content;
|
|
||||||
|
// 判断是否需要发送通知:金额不为零且金额变化了或者未发送过通知
|
||||||
|
boolean shouldNotify = newProPriceAmount.compareTo(BigDecimal.ZERO) > 0 && (newProPriceAmount.compareTo(oldProPriceAmount) != 0 || !hasNotified);
|
||||||
|
|
||||||
|
if (shouldNotify) {
|
||||||
|
String wxId = getWxidFromJdid(orderRow.getUnionId().toString());
|
||||||
|
if (Util.isNotEmpty(wxId)) {
|
||||||
|
String content = getFormattedOrderInfo(orderRow);
|
||||||
|
String alertMsg = "[Broken][Broken][Broken] 价保提醒 [Broken][Broken][Broken] " + newProPriceAmount + "\n" + content;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 先发送通知
|
||||||
wxUtil.sendTextMessage(wxId, alertMsg, 1, wxId, true);
|
wxUtil.sendTextMessage(wxId, alertMsg, 1, wxId, true);
|
||||||
}
|
|
||||||
|
|
||||||
// 只有发生变动后才更新 Redis
|
// 通知成功后更新Redis,格式为 "金额:true"
|
||||||
redisTemplate.opsForValue().set(ORDER_ROW_JB_KEY + orderRow.getId(), newProPriceAmount.toString());
|
String newRedisValue = newProPriceAmount + ":true";
|
||||||
|
redisTemplate.opsForValue().set(redisKey, newRedisValue);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("发送价保通知失败: {}", e.getMessage(), e);
|
||||||
|
// 通知失败,不更新Redis,下次继续尝试
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -217,15 +217,14 @@ public class WXUtil {
|
|||||||
|
|
||||||
String messageContent = "Jarvis 重启完成 [亲亲][亲亲][亲亲] ";
|
String messageContent = "Jarvis 重启完成 [亲亲][亲亲][亲亲] ";
|
||||||
String fromWxid = default_bot_wxid; // 来源为机器人自身
|
String fromWxid = default_bot_wxid; // 来源为机器人自身
|
||||||
|
for (SuperAdmin admin : super_admins.values()) {
|
||||||
super_admins.forEach((wxid, superAdmin) -> {
|
|
||||||
try {
|
try {
|
||||||
// 异步发送,不影响启动流程
|
// 异步发送,不影响启动流程
|
||||||
CompletableFuture.runAsync(() -> sendTextMessage(wxid.substring(0, 19), messageContent, 1, fromWxid, false));
|
CompletableFuture.runAsync(() -> sendTextMessage(admin.getWxid(), messageContent, 1, fromWxid, false));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("发送重启通知失败,目标 wxid: {}", wxid, e);
|
logger.warn("发送重启通知失败,目标 wxid: {}", admin.getWxid(), e);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
restartNoticeSent = true;
|
restartNoticeSent = true;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user