1
This commit is contained in:
@@ -212,11 +212,11 @@ public class JDUtils {
|
|||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
int[] parm = {-1};
|
int[] parm = {-1};
|
||||||
List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(parm);
|
List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(parm);
|
||||||
if (!orderRows.isEmpty()) {
|
|
||||||
for (OrderRow orderRow : orderRows) {
|
for (OrderRow orderRow : orderRows) {
|
||||||
orderToWx(orderRow, true);
|
orderToWx(orderRow, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("扫描订单发送到微信耗时:{} ms, 订单数:{} ", System.currentTimeMillis() - start, orderRows.size());
|
logger.info("扫描订单发送到微信耗时:{} ms, 订单数:{} ", System.currentTimeMillis() - start, orderRows.size());
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -274,25 +274,23 @@ public class JDUtils {
|
|||||||
* 手动调用 将订单发送到微信
|
* 手动调用 将订单发送到微信
|
||||||
*/
|
*/
|
||||||
private void orderToWx(OrderRow orderRow, Boolean isAutoFlush) {
|
private void orderToWx(OrderRow orderRow, Boolean isAutoFlush) {
|
||||||
// 查询订单状态
|
// 获取订单当前状态
|
||||||
Integer newValidCode = orderRow.getValidCode();
|
Integer newValidCode = orderRow.getValidCode();
|
||||||
String oldValidCode = redisTemplate.opsForValue().get(ORDER_ROW_KEY + orderRow.getId());
|
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)) {
|
// 检查Redis中是否有旧的状态码,没有的话赋予默认值
|
||||||
lastValidCode = Integer.valueOf(oldValidCode);
|
Integer lastValidCode = oldValidCode != null ? Integer.parseInt(oldValidCode) : -100;
|
||||||
}
|
|
||||||
// 如果订单状态没变化,就不发送
|
// 这里使用了逻辑非(!)操作符来简化条件判断
|
||||||
if (isAutoFlush && lastValidCode.equals(newValidCode)) {
|
if (!isAutoFlush || !lastValidCode.equals(newValidCode)) {
|
||||||
} else {
|
// 当 isAutoFlush 为 false 或状态确实有变化时,进行消息发送
|
||||||
String content;
|
String content = getFormattedOrderInfo(orderRow, lastValidCode);
|
||||||
content = getFormattedOrderInfo(orderRow, Util.isEmpty(oldValidCode) ? -100 : Integer.parseInt(oldValidCode));
|
|
||||||
// 推送
|
|
||||||
wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content, 1, WXUtil.super_admin_wxid);
|
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()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -144,14 +144,8 @@ public class WXUtil {
|
|||||||
JSONObject response = JSON.parseObject(responseStr);
|
JSONObject response = JSON.parseObject(responseStr);
|
||||||
logger.info("消息响应:{}", response.toString());
|
logger.info("消息响应:{}", response.toString());
|
||||||
//return response;
|
//return response;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
Thread.sleep(100);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user