Merge remote-tracking branch 'origin/master'

master
wj 2 years ago
commit 467fa984a0

@ -23,6 +23,6 @@ public class ThirdSysInterfaceExecuteVo {
/** /**
* *
*/ */
private boolean isFinished; private boolean finished;
} }

@ -20,10 +20,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -35,13 +32,13 @@ import java.util.concurrent.ExecutorService;
@Component @Component
public class ThirdSysInterfaceTask { public class ThirdSysInterfaceTask {
private ExecutorService executor;
/** /**
* redis key * redis key
*/ */
private static final Map<String, Map<String, String>> keyMap = new ConcurrentHashMap<>(5); private static final Map<String, Map<String, String>> keyMap = new ConcurrentHashMap<>(5);
private volatile ExecutorService executor;
/** /**
* 线 * 线
* *
@ -49,8 +46,10 @@ public class ThirdSysInterfaceTask {
*/ */
private ExecutorService getExecutor() { private ExecutorService getExecutor() {
if (null == executor) { if (null == executor) {
log.info("初始化第三方系统接口执行线程池"); synchronized (this) {
executor = ThreadUtil.newExecutor(10, 100, Integer.MAX_VALUE); log.info("初始化第三方系统接口执行线程池");
executor = ThreadUtil.newExecutor(10, 100, Integer.MAX_VALUE);
}
} }
return executor; return executor;
} }
@ -70,7 +69,7 @@ public class ThirdSysInterfaceTask {
@Resource @Resource
private IoOrderService orderService; private IoOrderService orderService;
@Scheduled(fixedRate = 60 * 1000, initialDelay = 60 * 1000) @Scheduled(fixedRate = 20 * 1000, initialDelay = 60 * 1000)
public void scanInterface() { public void scanInterface() {
log.info("开始扫描自动执行的第三方接口列表"); log.info("开始扫描自动执行的第三方接口列表");
List<ThrSystemDetailEntity> list = thrSystemDetailDao.selectAutoExecuteList(); List<ThrSystemDetailEntity> list = thrSystemDetailDao.selectAutoExecuteList();
@ -118,8 +117,13 @@ public class ThirdSysInterfaceTask {
if (verifyTask(thrSystemDetailEntity)) { if (verifyTask(thrSystemDetailEntity)) {
getExecutor().submit(() -> { getExecutor().submit(() -> {
log.info("开始提交单据到第三方系统"); log.info("开始提交单据到第三方系统");
orderService.submitOrderToThrSys(thrSystemDetailEntity); try {
updateTask(getTaskKey(thrSystemDetailEntity)); orderService.submitOrderToThrSys(thrSystemDetailEntity);
} catch (Exception e) {
log.error("提交单据到第三方系统异常", e);
} finally {
updateTask(getTaskKey(thrSystemDetailEntity));
}
log.info("提交单据到第三方系统完成"); log.info("提交单据到第三方系统完成");
}); });
} }
@ -135,8 +139,13 @@ public class ThirdSysInterfaceTask {
if (verifyTask(thrSystemDetailEntity)) { if (verifyTask(thrSystemDetailEntity)) {
getExecutor().submit(() -> { getExecutor().submit(() -> {
log.info("开始下载第三方单据类型"); log.info("开始下载第三方单据类型");
thrBusTypeOriginService.downloadThrBusType(thrSystemDetailEntity); try {
updateTask(getTaskKey(thrSystemDetailEntity)); thrBusTypeOriginService.downloadThrBusType(thrSystemDetailEntity);
} catch (Exception e) {
log.error("下载第三方单据类型异常", e);
} finally {
updateTask(getTaskKey(thrSystemDetailEntity));
}
log.info("第三方单据类型下载完成"); log.info("第三方单据类型下载完成");
}); });
} }
@ -152,8 +161,13 @@ public class ThirdSysInterfaceTask {
if (verifyTask(thrSystemDetailEntity)) { if (verifyTask(thrSystemDetailEntity)) {
getExecutor().submit(() -> { getExecutor().submit(() -> {
log.info("开始下载第三方产品信息"); log.info("开始下载第三方产品信息");
thrProductsService.downloadThrPi(thrSystemDetailEntity); try {
updateTask(getTaskKey(thrSystemDetailEntity)); thrProductsService.downloadThrPi(thrSystemDetailEntity);
} catch (Exception e) {
log.error("下载第三方产品信息异常", e);
} finally {
updateTask(getTaskKey(thrSystemDetailEntity));
}
log.info("第三方产品信息下载完成"); log.info("第三方产品信息下载完成");
}); });
} }
@ -169,8 +183,13 @@ public class ThirdSysInterfaceTask {
if (verifyTask(thrSystemDetailEntity)) { if (verifyTask(thrSystemDetailEntity)) {
getExecutor().submit(() -> { getExecutor().submit(() -> {
log.info("开始下载第三方往来单位信息"); log.info("开始下载第三方往来单位信息");
thrCorpService.downloadThrCorp(thrSystemDetailEntity); try {
updateTask(getTaskKey(thrSystemDetailEntity)); thrCorpService.downloadThrCorp(thrSystemDetailEntity);
} catch (Exception e) {
log.error("下载第三方往来单位异常", e);
} finally {
updateTask(getTaskKey(thrSystemDetailEntity));
}
log.info("第三方往来单位信息下载完成"); log.info("第三方往来单位信息下载完成");
}); });
} }
@ -186,8 +205,14 @@ public class ThirdSysInterfaceTask {
if (verifyTask(thrSystemDetailEntity)) { if (verifyTask(thrSystemDetailEntity)) {
getExecutor().submit(() -> { getExecutor().submit(() -> {
log.info("开始下载第三方仓库信息"); log.info("开始下载第三方仓库信息");
thrInvWarehouseService.downloadThrInv(thrSystemDetailEntity); try {
updateTask(getTaskKey(thrSystemDetailEntity)); thrInvWarehouseService.downloadThrInv(thrSystemDetailEntity);
} catch (Exception e) {
log.error("下载第三方仓库信息异常", e);
} finally {
//保证任务标识一定会被修改回去
updateTask(getTaskKey(thrSystemDetailEntity));
}
log.info("第三方仓库信息下载完成"); log.info("第三方仓库信息下载完成");
}); });
} }
@ -216,17 +241,14 @@ public class ThirdSysInterfaceTask {
if (null != vo && !vo.isFinished()) { if (null != vo && !vo.isFinished()) {
log.info("有任务尚未执行完成当前任务key{}", taskKey); log.info("有任务尚未执行完成当前任务key{}", taskKey);
return false; return false;
} else {
if (vo == null) {
vo = new ThirdSysInterfaceExecuteVo();
vo.setKey(taskKey);
}
vo.setNextTime(DateUtil.offsetMonth(new Date(), thrSystemDetailEntity.getTime()).getTime());
vo.setFinished(false);
redisUtil.set(taskKey, vo);
return true;
} }
long nextTime = DateUtil.offsetMonth(new Date(), thrSystemDetailEntity.getTime()).getTime();
vo = Optional.ofNullable(vo).orElse(new ThirdSysInterfaceExecuteVo());
vo.setKey(taskKey);
vo.setNextTime(nextTime);
vo.setFinished(false);
redisUtil.set(taskKey, vo);
return true;
} }
/** /**

Loading…
Cancel
Save