|
@ -12,6 +12,8 @@ import org.nl.modules.wql.core.bean.WQLObject; |
|
|
import org.nl.modules.wql.util.SpringContextHolder; |
|
|
import org.nl.modules.wql.util.SpringContextHolder; |
|
|
import org.nl.wms.sch.AcsUtil; |
|
|
import org.nl.wms.sch.AcsUtil; |
|
|
import org.nl.wms.sch.task.AcsTaskDTO; |
|
|
import org.nl.wms.sch.task.AcsTaskDTO; |
|
|
|
|
|
import org.redisson.api.RLock; |
|
|
|
|
|
import org.redisson.api.RedissonClient; |
|
|
import org.reflections.Reflections; |
|
|
import org.reflections.Reflections; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
@ -19,12 +21,12 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Set; |
|
|
import java.util.Set; |
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Component("autoCreateTask") |
|
|
@Component("autoCreateTask") |
|
|
public class AutoCreateTask { |
|
|
public class AutoCreateTask { |
|
|
// 下发acs的任务集合
|
|
|
// 下发acs的任务集合
|
|
|
private List<AcsTaskDTO> taskList = null; |
|
|
|
|
|
private Set<Class<? extends AbstractAcsTask>> subTypes = null; |
|
|
private Set<Class<? extends AbstractAcsTask>> subTypes = null; |
|
|
|
|
|
|
|
|
WQLObject taskTab = null; |
|
|
WQLObject taskTab = null; |
|
@ -36,13 +38,27 @@ public class AutoCreateTask { |
|
|
subTypes = reflections.getSubTypesOf(AbstractAcsTask.class); |
|
|
subTypes = reflections.getSubTypesOf(AbstractAcsTask.class); |
|
|
} |
|
|
} |
|
|
if (ObjectUtil.isNull(taskTab)) taskTab = WQLObject.getWQLObject("sch_base_task"); |
|
|
if (ObjectUtil.isNull(taskTab)) taskTab = WQLObject.getWQLObject("sch_base_task"); |
|
|
taskList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RLock lock = SpringContextHolder.getBean(RedissonClient.class).getFairLock("autoCreateTask"); |
|
|
|
|
|
boolean try_lock = false; |
|
|
|
|
|
try { |
|
|
|
|
|
try_lock = lock.tryLock(0, TimeUnit.SECONDS); |
|
|
|
|
|
if (try_lock) { |
|
|
this.doExecute(); |
|
|
this.doExecute(); |
|
|
} |
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("auto create task error !", e); |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (try_lock) { |
|
|
|
|
|
lock.unlock(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doExecute() { |
|
|
private void doExecute() { |
|
|
|
|
|
ArrayList<AcsTaskDTO> taskList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
subTypes.forEach(clz -> { |
|
|
subTypes.forEach(clz -> { |
|
|
// 调用AbstractAcsTask类的每个子类的schedule()方法
|
|
|
// 调用AbstractAcsTask类的每个子类的schedule()方法
|
|
|
try { |
|
|
try { |
|
|