182 lines
7.0 KiB
Java
182 lines
7.0 KiB
Java
package com.ruoyi.schedule;
|
|
|
|
import com.ruoyi.device.ddj.domain.MsgDdj;
|
|
import com.ruoyi.device.ddj.service.IMsgDdjService;
|
|
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
|
import com.ruoyi.device.ssj.service.IDeviceSsjService;
|
|
import com.ruoyi.common.domain.PlcConnectInfo;
|
|
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
|
|
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
|
import com.ruoyi.common.domain.CustomThread;
|
|
import com.ruoyi.schedule.scheduleTask.ddj.Ddj1Thread;
|
|
import com.ruoyi.schedule.scheduleTask.monit.MonitoringThread;
|
|
import com.ruoyi.schedule.scheduleTask.ssj.floor1.Floor1BothWayInSsjThread;
|
|
import com.ruoyi.schedule.scheduleTask.ssj.floor1.Floor1BothWayOutSsjThread;
|
|
import com.ruoyi.schedule.scheduleTask.ssj.floor1.Floor1SingleSsjThread;
|
|
import com.ruoyi.schedule.scheduleTask.ssj.floor2.Floor2InSsjThread;
|
|
import com.ruoyi.schedule.scheduleTask.ssj.floor2.Floor2OutSsjThread;
|
|
import com.ruoyi.schedule.scheduleTask.ssj.floor2.LineSsjThread;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
@Component
|
|
@Slf4j
|
|
public class ScheduleThread {
|
|
|
|
public CustomThread<PlcSsjRead> plcSsjReadCustomThread;
|
|
public CustomThread<PlcDdjRead> plcDdjReadCustomThread;
|
|
|
|
public CustomThread<Floor1BothWayInSsjThread> floor1BothWayInSsjCustomThread;
|
|
public CustomThread<Floor1BothWayOutSsjThread> floor1BothWayOutSsjCustomThread;
|
|
public CustomThread<Floor1SingleSsjThread> floor1SingleSsjCustomThread;
|
|
public CustomThread<Floor2InSsjThread> floor2InSsjCustomThread;
|
|
public CustomThread<Floor2OutSsjThread> floor2OutSsjCustomThread;
|
|
public CustomThread<LineSsjThread> lineSsjCustomThread;
|
|
public CustomThread<MonitoringThread> monitoringCustomThread;
|
|
public CustomThread<Ddj1Thread> ddj1CustomThread;
|
|
@Autowired
|
|
private IDeviceSsjService deviceSsjService;
|
|
@Autowired
|
|
private IMsgDdjService msgDdjService;
|
|
|
|
private boolean isRun = false;
|
|
private boolean isRun2 = false;
|
|
|
|
/**
|
|
* 项目初始化启动
|
|
*/
|
|
@PostConstruct
|
|
public void init() {
|
|
log.info("初始化调度服务");
|
|
//读取信息初始化
|
|
plcReadInit();
|
|
//调度初始化
|
|
scheduleInit();
|
|
log.info("调度服务执行成功");
|
|
}
|
|
|
|
/**
|
|
* 调度初始化
|
|
*/
|
|
private void scheduleInit() {
|
|
MonitoringThread monitoringThread = new MonitoringThread();
|
|
monitoringCustomThread = new CustomThread<MonitoringThread>(new Thread(monitoringThread), monitoringThread);
|
|
|
|
Floor1BothWayInSsjThread floor1BothWayInSsjThread = new Floor1BothWayInSsjThread();
|
|
floor1BothWayInSsjCustomThread = new CustomThread<Floor1BothWayInSsjThread>(new Thread(floor1BothWayInSsjThread), floor1BothWayInSsjThread);
|
|
|
|
Floor1BothWayOutSsjThread floor1BothWayOutSsjThread = new Floor1BothWayOutSsjThread();
|
|
floor1BothWayOutSsjCustomThread = new CustomThread<Floor1BothWayOutSsjThread>(new Thread(floor1BothWayOutSsjThread), floor1BothWayOutSsjThread);
|
|
|
|
Floor1SingleSsjThread floor1SingleSsjThread = new Floor1SingleSsjThread();
|
|
floor1SingleSsjCustomThread = new CustomThread<Floor1SingleSsjThread>(new Thread(floor1SingleSsjThread), floor1SingleSsjThread);
|
|
|
|
Floor2InSsjThread floor2InSsjThread = new Floor2InSsjThread();
|
|
floor2InSsjCustomThread = new CustomThread<Floor2InSsjThread>(new Thread(floor2InSsjThread), floor2InSsjThread);
|
|
|
|
LineSsjThread lineSsjThread = new LineSsjThread();
|
|
lineSsjCustomThread = new CustomThread<LineSsjThread>(new Thread(lineSsjThread), lineSsjThread);
|
|
|
|
Floor2OutSsjThread floor2OutSsjThread = new Floor2OutSsjThread();
|
|
floor2OutSsjCustomThread = new CustomThread<Floor2OutSsjThread>(new Thread(floor2OutSsjThread), floor2OutSsjThread);
|
|
|
|
Ddj1Thread ddj1Thread = new Ddj1Thread();
|
|
ddj1CustomThread = new CustomThread<Ddj1Thread>(new Thread(ddj1Thread), ddj1Thread);
|
|
}
|
|
|
|
/**
|
|
* plc读取初始化
|
|
*/
|
|
private void plcReadInit() {
|
|
ConcurrentHashMap<String, DeviceSsj> ssjList = new ConcurrentHashMap<>();
|
|
//获取要去取的输送机
|
|
List<DeviceSsj> deviceSsjs = deviceSsjService.selectDeviceSsjList(new DeviceSsj());
|
|
for (DeviceSsj deviceSsj : deviceSsjs) {
|
|
ssjList.put(deviceSsj.getDeviceCode(), deviceSsj);
|
|
}
|
|
|
|
|
|
//plc输送机读取线程
|
|
PlcSsjRead plcSsjRead = new PlcSsjRead(ssjList, new PlcConnectInfo("127.0.0.1", 102));
|
|
Thread plcSsjReadThread = new Thread(plcSsjRead);
|
|
plcSsjReadCustomThread = new CustomThread<PlcSsjRead>(plcSsjReadThread, plcSsjRead);
|
|
|
|
//plc堆垛机读取现场
|
|
ConcurrentHashMap<String, MsgDdj> ddjList = new ConcurrentHashMap<>();
|
|
List<MsgDdj> msgDdjs = msgDdjService.selectMsgDdjList(new MsgDdj());
|
|
for (MsgDdj msgDdj : msgDdjs) {
|
|
ddjList.put("ddj"+msgDdj.getId(), msgDdj);
|
|
}
|
|
PlcDdjRead plcDdjRead = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
|
|
Thread plcDdjReadThread = new Thread(plcDdjRead);
|
|
plcDdjReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread, plcDdjRead);
|
|
|
|
}
|
|
|
|
/**
|
|
* 开始线程
|
|
*/
|
|
public void startAllThread() {
|
|
plcSsjReadCustomThread.getThread().start();
|
|
plcDdjReadCustomThread.getThread().start();
|
|
isRun = true;
|
|
}
|
|
|
|
/**
|
|
* 开启线程2
|
|
*/
|
|
public void startAllThread2() {
|
|
monitoringCustomThread.thread.start();
|
|
floor1BothWayInSsjCustomThread.thread.start();
|
|
floor1BothWayOutSsjCustomThread.thread.start();
|
|
floor1SingleSsjCustomThread.thread.start();
|
|
floor2InSsjCustomThread.thread.start();
|
|
lineSsjCustomThread.thread.start();
|
|
floor2OutSsjCustomThread.thread.start();
|
|
ddj1CustomThread.thread.start();
|
|
isRun2 = true;
|
|
}
|
|
|
|
/**
|
|
* 停止线程
|
|
*/
|
|
public void stopAllThread() {
|
|
plcSsjReadCustomThread.runnable.isRun = false;
|
|
plcDdjReadCustomThread.runnable.isRun = false;
|
|
plcReadInit();
|
|
isRun = false;
|
|
}
|
|
|
|
/**
|
|
* 停止线程2
|
|
*/
|
|
public void stopAllThread2() {
|
|
monitoringCustomThread.runnable.isRun = false;
|
|
floor1BothWayInSsjCustomThread.runnable.isRun = false;
|
|
floor1BothWayOutSsjCustomThread.runnable.isRun = false;
|
|
floor1SingleSsjCustomThread.runnable.isRun = false;
|
|
floor2InSsjCustomThread.runnable.isRun = false;
|
|
lineSsjCustomThread.runnable.isRun = false;
|
|
floor2OutSsjCustomThread.runnable.isRun = false;
|
|
ddj1CustomThread.runnable.isRun = false;
|
|
scheduleInit();
|
|
isRun2 = false;
|
|
}
|
|
|
|
/**
|
|
* 获取调度状态
|
|
*/
|
|
public HashMap<String,Boolean> getScheduleStatus() {
|
|
HashMap<String,Boolean> map = new HashMap<>();
|
|
map.put("isRun",isRun);
|
|
map.put("isRun2",isRun2);
|
|
return map;
|
|
}
|
|
}
|