This commit is contained in:
雷欧(林平凡)
2024-11-29 11:38:13 +08:00
parent 34c2e8638e
commit f3a9536685
2 changed files with 9 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package cn.van;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
/** /**
@@ -12,6 +13,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
*/ */
@SpringBootApplication @SpringBootApplication
@EnableScheduling @EnableScheduling
@EnableAsync
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -22,6 +22,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.SetOperations; import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -73,8 +75,6 @@ public class JDUtils {
private OrderRowRepository orderRowRepository; private OrderRowRepository orderRowRepository;
@Resource @Resource
private WXUtil wxUtil; private WXUtil wxUtil;
// 创建一个固定大小的线程池
private ExecutorService jdExecutorService = Executors.newFixedThreadPool(128); // 线程池大小根据需求调整
/** /**
* 将 响应参数转化为 OrderRow并返回 * 将 响应参数转化为 OrderRow并返回
@@ -218,9 +218,9 @@ public class JDUtils {
List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(parm); List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(parm);
for (OrderRow orderRow : orderRows) { for (OrderRow orderRow : orderRows) {
jdExecutorService.submit(() -> {
orderToWx(orderRow, true); orderToWx(orderRow, true);
});
} }
logger.info("扫描订单发送到微信耗时:{} ms, 订单数:{} ", System.currentTimeMillis() - start, orderRows.size()); logger.info("扫描订单发送到微信耗时:{} ms, 订单数:{} ", System.currentTimeMillis() - start, orderRows.size());
@@ -279,7 +279,8 @@ public class JDUtils {
/** /**
* 手动调用 将订单发送到微信 * 手动调用 将订单发送到微信
*/ */
private void orderToWx(OrderRow orderRow, Boolean isAutoFlush) { @Async
public 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());