This commit is contained in:
雷欧(林平凡)
2024-11-29 11:24:46 +08:00
parent 213cf32012
commit 74e5d34c9f
2 changed files with 15 additions and 23 deletions

View File

@@ -212,11 +212,11 @@ public class JDUtils {
long start = System.currentTimeMillis();
int[] parm = {-1};
List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(parm);
if (!orderRows.isEmpty()) {
for (OrderRow orderRow : orderRows) {
orderToWx(orderRow, true);
}
}
logger.info("扫描订单发送到微信耗时:{} ms, 订单数:{} ", System.currentTimeMillis() - start, orderRows.size());
}
@@ -274,25 +274,23 @@ public class JDUtils {
* 手动调用 将订单发送到微信
*/
private void orderToWx(OrderRow orderRow, Boolean isAutoFlush) {
// 查询订单状态
// 获取订单当前状态
Integer newValidCode = orderRow.getValidCode();
String oldValidCode = redisTemplate.opsForValue().get(ORDER_ROW_KEY + orderRow.getId());
Integer lastValidCode = 0;
// 更新 Redis 状态
redisTemplate.opsForValue().set(ORDER_ROW_KEY + orderRow.getId(), String.valueOf(orderRow.getValidCode()));
if (Util.isNotEmpty(oldValidCode)) {
lastValidCode = Integer.valueOf(oldValidCode);
}
// 如果订单状态没变化,就不发送
if (isAutoFlush && lastValidCode.equals(newValidCode)) {
} else {
String content;
content = getFormattedOrderInfo(orderRow, Util.isEmpty(oldValidCode) ? -100 : Integer.parseInt(oldValidCode));
// 推送
// 检查Redis中是否有旧的状态码没有的话赋予默认值
Integer lastValidCode = oldValidCode != null ? Integer.parseInt(oldValidCode) : -100;
// 这里使用了逻辑非(!)操作符来简化条件判断
if (!isAutoFlush || !lastValidCode.equals(newValidCode)) {
// 当 isAutoFlush 为 false 或状态确实有变化时,进行消息发送
String content = getFormattedOrderInfo(orderRow, lastValidCode);
wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content, 1, WXUtil.super_admin_wxid);
}
// 更新 Redis 状态值
redisTemplate.opsForValue().set(ORDER_ROW_KEY + orderRow.getId(), String.valueOf(orderRow.getValidCode()));
}
/**

View File

@@ -144,14 +144,8 @@ public class WXUtil {
JSONObject response = JSON.parseObject(responseStr);
logger.info("消息响应:{}", response.toString());
//return response;
continue;
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}