重构第一版,没有明显bug

This commit is contained in:
Leo
2025-03-11 14:11:51 +08:00
parent 9aa02430fd
commit 2316951e7f
4 changed files with 101 additions and 70 deletions

View File

@@ -22,6 +22,7 @@ import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
@@ -85,6 +86,12 @@ public class JDUtil {
// 添加ObjectMapper来序列化和反序列化UserInteractionState
private final ObjectMapper objectMapper = new ObjectMapper();
@Value("${isRunning.wx")
private boolean isRunning_wx = false;
@Value("isRunning.jd")
private boolean isRunning_jd = false;
// 构造函数中注入StringRedisTemplate
@Autowired
public JDUtil(StringRedisTemplate redisTemplate, ProductOrderRepository productOrderRepository, OrderRowRepository orderRowRepository, WXUtil wxUtil, OrderUtil orderUtil) {
@@ -237,6 +244,8 @@ public class JDUtil {
*/
@Scheduled(cron = "0 * * * * ?")
public void fetchLatestOrder() {
if (isRunning_jd) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = now.minusMinutes(10).withSecond(0).withNano(0);
@@ -256,6 +265,7 @@ public class JDUtil {
}
});
}
}
// 响应校验方法
private boolean isValidResponse(UnionOpenOrderRowQueryResponse response) {
@@ -271,8 +281,9 @@ public class JDUtil {
* 扫描订单发送到微信
* 每分钟的30秒执行一次
*/
@Scheduled(cron = "10 * * * * ?")
@Scheduled(cron = "3 * * * * ?")
public void sendOrderToWx() {
if (isRunning_wx) {
//long start = System.currentTimeMillis();
int[] validCodes = {-1};
// 只要三个月的,更多的也刷新不出来的
@@ -289,11 +300,14 @@ public class JDUtil {
}
}
/**
* 一天拉取三次 30天到60天前的订单
*/
@Scheduled(cron = "0 0 */4 * * ?")
public void fetchHistoricalOrders3090() {
if (isRunning_jd) {
try {
OrderFetchStrategy strategy = new Days3090Strategy();
for (WXUtil.SuperAdmin admin : super_admins.values()) {
@@ -308,11 +322,15 @@ public class JDUtil {
}
}
}
/**
* 一天拉取6次 14天到30天前的订单
*/
@Scheduled(cron = "0 0 * * * ?")
public void fetchHistoricalOrders1430() {
if (isRunning_jd) {
try {
OrderFetchStrategy strategy = new Days1430Strategy(); // 需补充Days1430Strategy实现
for (WXUtil.SuperAdmin admin : super_admins.values()) {
@@ -326,12 +344,15 @@ public class JDUtil {
logger.error("1430策略执行异常", ex);
}
}
}
/**
* 每10分钟拉取07-14天的订单
*/
@Scheduled(cron = "0 0 * * * ?")
public void fetchHistoricalOrders0714() {
if (isRunning_jd) {
try {
OrderFetchStrategy strategy = new Days0714Strategy();
super_admins.values().parallelStream().forEach(admin -> {
@@ -345,11 +366,14 @@ public class JDUtil {
} catch (Exception ex) {
logger.error("0714策略执行异常", ex);
}
}
}
@Scheduled(cron = "0 */5 * * * ?")
public void fetchHistoricalOrders0007() {
if (isRunning_jd) {
try {
OrderFetchStrategy strategy = new Days0007Strategy();
super_admins.values().parallelStream().forEach(admin -> {
@@ -368,6 +392,7 @@ public class JDUtil {
} catch (Exception ex) {
logger.error("0007策略执行异常", ex);
}
}
}

View File

@@ -74,7 +74,7 @@ public class OrderUtil {
"状态:" + (converter.getCodeDescription(orderRow.getValidCode())) + "\r"
+ "名称:" + orderRow.getSkuName().substring(0, 64) + "\r\n"
+ "名称:" + orderRow.getSkuName() + "\r\n"
//+ "商品单价:" + orderRow.getPrice() + "\r"
//+ "商品数量:" + orderRow.getSkuNum() + "\r"
//+ "商品总价:" + (orderRow.getPrice() * orderRow.getSkuNum()) + "\r"

View File

@@ -60,3 +60,6 @@ rocketmq:
consume-thread-min: 20 # 消费线程池最小线程数
consume-thread-max: 64 # 消费线程池最大线程数
consume-message-batch-max-size: 64 # 批量消费最大消息数
isRunning:
wx: false
jd: false

View File

@@ -60,3 +60,6 @@ rocketmq:
consume-thread-min: 20 # 消费线程池最小线程数
consume-thread-max: 64 # 消费线程池最大线程数
consume-message-batch-max-size: 64 # 批量消费最大消息数
isRunning:
wx: true
jd: true