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