1
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -8,7 +8,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
@@ -24,7 +24,7 @@ public class AsyncConfig implements AsyncConfigurer {
|
||||
@Bean(name = "threadPoolTaskExecutor")
|
||||
public Executor getAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(10); // 核心线程数
|
||||
executor.setCorePoolSize(16); // 核心线程数
|
||||
executor.setMaxPoolSize(128); // 最大线程数
|
||||
executor.setQueueCapacity(500); // 队列容量
|
||||
executor.setThreadNamePrefix("Async-Executor-");
|
||||
|
||||
@@ -6,8 +6,8 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.annotation.PreDestroy; // 使用 jakarta.annotation 包
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@@ -15,20 +15,33 @@ import java.util.concurrent.*;
|
||||
public class SchedulerConfig implements SchedulingConfigurer {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SchedulerConfig.class);
|
||||
private ScheduledExecutorService scheduledExecutorService;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
|
||||
// 动态配置线程池大小
|
||||
int poolSize = Integer.parseInt(System.getenv().getOrDefault("SCHEDULED_THREAD_POOL_SIZE", "10"));
|
||||
scheduledExecutorService = Executors.newScheduledThreadPool(poolSize);
|
||||
|
||||
taskRegistrar.setScheduler(new CustomScheduledExecutorService(scheduledExecutorService));
|
||||
}
|
||||
|
||||
private static class CustomScheduledExecutorService implements ScheduledExecutorService {
|
||||
private final ScheduledExecutorService delegate;
|
||||
|
||||
public CustomScheduledExecutorService(ScheduledExecutorService delegate) {
|
||||
this.delegate = delegate;
|
||||
@PreDestroy
|
||||
public void shutdown() {
|
||||
if (scheduledExecutorService != null && !scheduledExecutorService.isShutdown()) {
|
||||
scheduledExecutorService.shutdown();
|
||||
try {
|
||||
if (!scheduledExecutorService.awaitTermination(60, TimeUnit.SECONDS)) {
|
||||
scheduledExecutorService.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
scheduledExecutorService.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private record CustomScheduledExecutorService(
|
||||
ScheduledExecutorService delegate) implements ScheduledExecutorService {
|
||||
|
||||
@Override
|
||||
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
|
||||
@@ -49,8 +62,8 @@ public class SchedulerConfig implements SchedulingConfigurer {
|
||||
return () -> {
|
||||
try {
|
||||
command.run();
|
||||
} catch (Exception e) {
|
||||
logger.error("Scheduled task error", e);
|
||||
} catch (Throwable t) { // 捕获所有类型的异常
|
||||
logger.error("Scheduled task error", t);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -83,37 +96,37 @@ public class SchedulerConfig implements SchedulingConfigurer {
|
||||
|
||||
@Override
|
||||
public <T> Future<T> submit(Callable<T> task) {
|
||||
return null;
|
||||
return delegate.submit(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> submit(Runnable task, T result) {
|
||||
return null;
|
||||
return delegate.submit(task, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<?> submit(Runnable task) {
|
||||
return null;
|
||||
return delegate.submit(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
|
||||
return Collections.emptyList();
|
||||
return delegate.invokeAll(tasks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException {
|
||||
return Collections.emptyList();
|
||||
return delegate.invokeAll(tasks, timeout, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
|
||||
return null;
|
||||
return delegate.invokeAny(tasks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
return null;
|
||||
return delegate.invokeAny(tasks, timeout, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -303,16 +303,21 @@ public class JDUtil {
|
||||
@Scheduled(cron = "0 0 */4 * * ?")
|
||||
public void fetchHistoricalOrders3090() {
|
||||
|
||||
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
|
||||
//String wxid = entry.getKey();
|
||||
WXUtil.SuperAdmin admin = entry.getValue();
|
||||
String appKey = admin.getAppKey();
|
||||
String secretKey = admin.getSecretKey();
|
||||
if (Util.isAnyEmpty(appKey, secretKey)) {
|
||||
continue;
|
||||
try {
|
||||
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
|
||||
//String wxid = entry.getKey();
|
||||
WXUtil.SuperAdmin admin = entry.getValue();
|
||||
String appKey = admin.getAppKey();
|
||||
String secretKey = admin.getSecretKey();
|
||||
if (Util.isAnyEmpty(appKey, secretKey)) {
|
||||
continue;
|
||||
}
|
||||
fetchHistoricalOrders3090Do(appKey, secretKey);
|
||||
}
|
||||
fetchHistoricalOrders3090Do(appKey, secretKey);
|
||||
} catch (Exception e) {
|
||||
logger.error("拉取历史订单3090异常", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int fetchHistoricalOrders3090Do(String appKey, String secretKey) {
|
||||
@@ -369,16 +374,21 @@ public class JDUtil {
|
||||
*/
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void fetchHistoricalOrders1430() {
|
||||
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
|
||||
//String wxid = entry.getKey();
|
||||
WXUtil.SuperAdmin admin = entry.getValue();
|
||||
String appKey = admin.getAppKey();
|
||||
String secretKey = admin.getSecretKey();
|
||||
if (Util.isAnyEmpty(appKey, secretKey)) {
|
||||
continue;
|
||||
try {
|
||||
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
|
||||
//String wxid = entry.getKey();
|
||||
WXUtil.SuperAdmin admin = entry.getValue();
|
||||
String appKey = admin.getAppKey();
|
||||
String secretKey = admin.getSecretKey();
|
||||
if (Util.isAnyEmpty(appKey, secretKey)) {
|
||||
continue;
|
||||
}
|
||||
fetchHistoricalOrders1430Do(appKey, secretKey);
|
||||
}
|
||||
fetchHistoricalOrders1430Do(appKey, secretKey);
|
||||
}catch (Exception e){
|
||||
logger.error("拉取历史订单1430异常", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int fetchHistoricalOrders1430Do(String appKey, String secretKey) {
|
||||
@@ -433,16 +443,21 @@ public class JDUtil {
|
||||
*/
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void fetchHistoricalOrders0714() {
|
||||
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
|
||||
//String wxid = entry.getKey();
|
||||
WXUtil.SuperAdmin admin = entry.getValue();
|
||||
String appKey = admin.getAppKey();
|
||||
String secretKey = admin.getSecretKey();
|
||||
if (Util.isAnyEmpty(appKey, secretKey)) {
|
||||
continue;
|
||||
try {
|
||||
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
|
||||
//String wxid = entry.getKey();
|
||||
WXUtil.SuperAdmin admin = entry.getValue();
|
||||
String appKey = admin.getAppKey();
|
||||
String secretKey = admin.getSecretKey();
|
||||
if (Util.isAnyEmpty(appKey, secretKey)) {
|
||||
continue;
|
||||
}
|
||||
fetchHistoricalOrders0714Do(appKey, secretKey);
|
||||
}
|
||||
fetchHistoricalOrders0714Do(appKey, secretKey);
|
||||
}catch (Exception e){
|
||||
logger.error("拉取历史订单0714异常", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int fetchHistoricalOrders0714Do(String appKey, String secretKey) {
|
||||
@@ -493,16 +508,21 @@ public class JDUtil {
|
||||
|
||||
@Scheduled(cron = "0 */5 * * * ?")
|
||||
public void fetchHistoricalOrders0007() {
|
||||
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
|
||||
//String wxid = entry.getKey();
|
||||
WXUtil.SuperAdmin admin = entry.getValue();
|
||||
String appKey = admin.getAppKey();
|
||||
String secretKey = admin.getSecretKey();
|
||||
if (Util.isAnyEmpty(appKey, secretKey)) {
|
||||
continue;
|
||||
try {
|
||||
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
|
||||
//String wxid = entry.getKey();
|
||||
WXUtil.SuperAdmin admin = entry.getValue();
|
||||
String appKey = admin.getAppKey();
|
||||
String secretKey = admin.getSecretKey();
|
||||
if (Util.isAnyEmpty(appKey, secretKey)) {
|
||||
continue;
|
||||
}
|
||||
fetchHistoricalOrders0007Do(appKey, secretKey);
|
||||
}
|
||||
fetchHistoricalOrders0007Do(appKey, secretKey);
|
||||
}catch (Exception e){
|
||||
logger.error("拉取历史订单0007异常", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int fetchHistoricalOrders0007Do(String appKey, String secretKey) {
|
||||
@@ -1197,11 +1217,11 @@ public void sendOrderToWxByOrderDefault(String order, String fromWxid) {
|
||||
|
||||
switch (state.getCurrentState()) {
|
||||
case "INIT":
|
||||
if ("消毒柜".equals(message)) {
|
||||
if ("订单".equals(message)) {
|
||||
//1,查询消毒柜订单;2,输入新的订单;3,修改订单
|
||||
String sb = """
|
||||
请选择您要执行的操作:
|
||||
1,查询消毒柜订单
|
||||
1,查询订单
|
||||
2,输入新的订单
|
||||
3,修改订单""";
|
||||
wxUtil.sendTextMessage(fromWxid, sb, 1, fromWxid);
|
||||
@@ -1216,6 +1236,7 @@ public void sendOrderToWxByOrderDefault(String order, String fromWxid) {
|
||||
String sb = "";
|
||||
|
||||
|
||||
|
||||
wxUtil.sendTextMessage(fromWxid, sb, 1, fromWxid);
|
||||
state.setCurrentState("INIT");
|
||||
logger.debug("User {} queried disinfectant cabinet orders", fromWxid);
|
||||
|
||||
@@ -255,7 +255,7 @@ private void handlePrivateMessage(WxMessage wxMessage) throws Exception {
|
||||
logger.info("消息内容为空,不处理");
|
||||
return;
|
||||
} else {
|
||||
logger.info("消息内容:" + innerData.getMsg());
|
||||
logger.info("消息内容:{}", innerData.getMsg());
|
||||
}
|
||||
|
||||
String fromWxid = innerData.getFromWxid();
|
||||
|
||||
Reference in New Issue
Block a user