| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.manager.core.domain.AgvTaskDto; |
| | | import com.zy.acs.manager.core.service.MainLockWrapService; |
| | | import com.zy.acs.manager.core.service.MainLxtService; |
| | | import com.zy.acs.manager.core.service.TrafficService; |
| | | import com.zy.acs.manager.core.service.*; |
| | | import com.zy.acs.manager.manager.entity.Bus; |
| | | import com.zy.acs.manager.manager.entity.Segment; |
| | | import com.zy.acs.manager.manager.entity.Task; |
| | |
| | | import com.zy.acs.manager.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.context.event.ApplicationReadyEvent; |
| | | import org.springframework.context.event.EventListener; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | @Autowired |
| | | private MainLxtService mainService; |
| | | @Autowired |
| | | private MainZkdService mainZkdService; |
| | | @Autowired |
| | | private MainLockWrapService mainLockWrapService; |
| | | @Autowired |
| | | private ActionService actionService; |
| | | @Autowired |
| | | private SegmentService segmentService; |
| | | @Autowired |
| | | private TrafficService trafficService; |
| | | private TrafficZkdService trafficZkdService; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private AgvModelService agvModelService; |
| | | |
| | | //@Scheduled(cron = "0/1 * * * * ? ") |
| | | @Scheduled(cron = "0/1 * * * * ? ") |
| | | private void startupBus() throws InterruptedException { |
| | | // if (!configService.getVal("TaskAssignMode", Boolean.class)) { return; } |
| | | if (!this.lock.tryLock(LOCK_TIMEOUT, TimeUnit.SECONDS)) { return; } |
| | | if (!this.lock.tryLock(LOCK_TIMEOUT, TimeUnit.SECONDS)) { |
| | | return; |
| | | } |
| | | List<Bus> busList = busService.selectBySts(BusStsType.RECEIVE); |
| | | for (Bus bus : busList) { |
| | | mainService.allocateTask(bus); |
| | | mainZkdService.allocateTask(bus); |
| | | } |
| | | this.lock.unlock(); |
| | | } |
| | | |
| | | //@Scheduled(cron = "0/1 * * * * ? ") |
| | | private void calculateSeg() throws InterruptedException { |
| | | if (!this.lock.tryLock(LOCK_TIMEOUT, TimeUnit.SECONDS)) { return; } |
| | | if (!this.lock.tryLock(LOCK_TIMEOUT, TimeUnit.SECONDS)) { |
| | | return; |
| | | } |
| | | List<Task> taskList = taskService.selectBySts(TaskStsType.WAITING); |
| | | |
| | | List<AgvTaskDto> taskDtoList = new ArrayList<>(); |
| | |
| | | this.lock.unlock(); |
| | | } |
| | | |
| | | //@EventListener(ApplicationReadyEvent.class) |
| | | @EventListener(ApplicationReadyEvent.class) |
| | | public void init() { |
| | | try { Thread.sleep(1200); } catch (InterruptedException ignore) {} |
| | | try { |
| | | Thread.sleep(1200); |
| | | } catch (InterruptedException ignore) { |
| | | } |
| | | // traffic calculate |
| | | this.trafficCalcThread = new Thread(() -> { |
| | | while (!Thread.currentThread().isInterrupted()) { |
| | |
| | | ); |
| | | for (Segment segment : segments) { |
| | | long startTime = System.currentTimeMillis(); |
| | | trafficService.trigger(segment); |
| | | trafficZkdService.trigger(segment); |
| | | // log.info("traffic calculation spend {} ms", System.currentTimeMillis() - startTime); |
| | | } |
| | | |
| | |
| | | // patch ---------------------------------------------------------------------------------------------- |
| | | |
| | | @Scheduled(cron = "0/3 * * * * ? ") |
| | | private void busFinishPatch(){ |
| | | private void busFinishPatch() { |
| | | List<Bus> busList = busService.selectBySts(BusStsType.PROGRESS); |
| | | for (Bus bus : busList) { |
| | | boolean finish = true; |
| | |
| | | |
| | | |
| | | @PreDestroy |
| | | public void shutDown(){ |
| | | public void shutDown() { |
| | | if (this.trafficCalcThread != null) { |
| | | this.trafficCalcThread .interrupt(); |
| | | this.trafficCalcThread.interrupt(); |
| | | } |
| | | if (this.actionPublicThread != null) { |
| | | this.actionPublicThread .interrupt(); |
| | | this.actionPublicThread.interrupt(); |
| | | } |
| | | } |
| | | |