|
@@ -62,23 +62,26 @@ public class ScheduledTask extends BaseServiceImpl {
|
|
|
//查出task表id最小的一条status= 0 1 的数据
|
|
|
//查这条数据任务,按照子任务顺序id最小开始依次执行
|
|
|
//如果任务状态是 未开始 或 异常,则调C#接口
|
|
|
- Object jobLock = redisTemplate.opsForValue().get("JOB_LOCK");
|
|
|
- if (!Objects.isNull(jobLock)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- WInventoryTransactionTask wInventoryTransactionTask = taskDao.selectOne();
|
|
|
+
|
|
|
+ List<WInventoryTransactionTask> wInventoryTransactionTask = taskDao.selectOne();
|
|
|
Assert.notNull(wInventoryTransactionTask);
|
|
|
- List<WInventoryTransactionChildTask> wInventoryTransactionTaskDetails = childTaskDao.selectListByTaskId(wInventoryTransactionTask);
|
|
|
- if (CollectionUtils.isNotEmpty(wInventoryTransactionTaskDetails)) {
|
|
|
- WInventoryTransactionChildTask wInventoryTransactionChildTask = wInventoryTransactionTaskDetails.get(0);
|
|
|
- if (wInventoryTransactionChildTask.getStatus() == Status.NOT_STARTED.getCode() || wInventoryTransactionChildTask.getStatus() == Status.EXCEPTION.getCode()) {
|
|
|
- redisTemplate.opsForValue().set("JOB_LOCK", true);
|
|
|
- httpHandler(wInventoryTransactionChildTask);
|
|
|
+ wInventoryTransactionTask.stream().parallel().forEach(vo->{
|
|
|
+ Object jobLock = redisTemplate.opsForValue().get("JOB_LOCK_"+vo.getDeviceId());
|
|
|
+ if (!Objects.isNull(jobLock)) {
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
+ List<WInventoryTransactionChildTask> wInventoryTransactionTaskDetails = childTaskDao.selectListByTaskId(vo);
|
|
|
+ if (CollectionUtils.isNotEmpty(wInventoryTransactionTaskDetails)) {
|
|
|
+ WInventoryTransactionChildTask wInventoryTransactionChildTask = wInventoryTransactionTaskDetails.get(0);
|
|
|
+ if (wInventoryTransactionChildTask.getStatus() == Status.NOT_STARTED.getCode() || wInventoryTransactionChildTask.getStatus() == Status.EXCEPTION.getCode()) {
|
|
|
+ redisTemplate.opsForValue().set("JOB_LOCK_"+vo.getDeviceId(), true);
|
|
|
+ httpHandler(wInventoryTransactionChildTask,vo.getDeviceId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- private void httpHandler(WInventoryTransactionChildTask item) {
|
|
|
+ private void httpHandler(WInventoryTransactionChildTask item,Long deviceId) {
|
|
|
String responseBody = null;
|
|
|
Date responseTime = null;
|
|
|
String url = "http://127.0.0.1:8081";
|
|
@@ -140,7 +143,7 @@ public class ScheduledTask extends BaseServiceImpl {
|
|
|
e.printStackTrace(pw);
|
|
|
responseBody = sw.toString();
|
|
|
} finally {
|
|
|
- redisTemplate.opsForValue().getAndDelete("JOB_LOCK");
|
|
|
+ redisTemplate.opsForValue().getAndDelete("JOB_LOCK_"+deviceId);
|
|
|
log.error("释放定时任务调度锁");
|
|
|
insertApiLog(json, responseBody, url, requestTime, responseTime, item);
|
|
|
}
|