初始化

This commit is contained in:
liuhanqing
2025-11-17 16:53:33 +08:00
commit cb2c0c032d
794 changed files with 119071 additions and 0 deletions

View File

@@ -0,0 +1,212 @@
package com.ruoyi.schedule;
import com.ruoyi.common.domain.CustomThread;
import com.ruoyi.common.domain.PlcConnectInfo;
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.schedule.plcRead.ddj.PlcDdjRead;
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
import com.ruoyi.schedule.scheduleTask.ddj.impl.Ddj1Thread;
import com.ruoyi.schedule.scheduleTask.monit.MonitoringThread;
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> plcDdj1ReadCustomThread;
public CustomThread<PlcDdjRead> plcDdj2ReadCustomThread;
public CustomThread<PlcDdjRead> plcDdj3ReadCustomThread;
public CustomThread<PlcDdjRead> plcDdj4ReadCustomThread;
public CustomThread<PlcDdjRead> plcDdj5ReadCustomThread;
public CustomThread<PlcDdjRead> plcDdj6ReadCustomThread;
public CustomThread<MonitoringThread> monitoringCustomThread;
public CustomThread<Ddj1Thread> ddj1CustomThread;
/*public CustomThread<Ddj2Thread> ddj2CustomThread;
public CustomThread<Ddj3Thread> ddj3CustomThread;
public CustomThread<Ddj4Thread> ddj4CustomThread;
public CustomThread<Ddj5Thread> ddj5CustomThread;
public CustomThread<Ddj6Thread> ddj6CustomThread;*/
@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);
Ddj1Thread ddj1Thread = new Ddj1Thread();
ddj1CustomThread = new CustomThread<>(new Thread(ddj1Thread), ddj1Thread);
/*Ddj2Thread ddj2Thread = new Ddj2Thread();
ddj2CustomThread = new CustomThread<>(new Thread(ddj2Thread), ddj2Thread);
Ddj3Thread ddj3Thread = new Ddj3Thread();
ddj3CustomThread = new CustomThread<>(new Thread(ddj3Thread), ddj3Thread);
Ddj4Thread ddj4Thread = new Ddj4Thread();
ddj4CustomThread = new CustomThread<>(new Thread(ddj4Thread), ddj4Thread);
Ddj5Thread ddj5Thread = new Ddj5Thread();
ddj5CustomThread = new CustomThread<>(new Thread(ddj5Thread), ddj5Thread);
Ddj6Thread ddj6Thread = new Ddj6Thread();
ddj6CustomThread = new CustomThread<>(new Thread(ddj6Thread), ddj6Thread);*/
}
/**
* 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) {
switch (msgDdj.getId()){
case 1:
msgDdj.setPlcDbReadAddress("DB41.0");
PlcDdjRead plcDdjRead1 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
Thread plcDdjReadThread1 = new Thread(plcDdjRead1);
plcDdj1ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread1, plcDdjRead1);
break;
case 2:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead2 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.2", 102));
Thread plcDdjReadThread2 = new Thread(plcDdjRead2);
plcDdj2ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread2, plcDdjRead2);
break;
case 3:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead3 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.3", 102));
Thread plcDdjReadThread3 = new Thread(plcDdjRead3);
plcDdj3ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread3, plcDdjRead3);
break;
case 4:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead4 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.4", 102));
Thread plcDdjReadThread4 = new Thread(plcDdjRead4);
plcDdj4ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread4, plcDdjRead4);
break;
case 5:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead5 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.5", 102));
Thread plcDdjReadThread5 = new Thread(plcDdjRead5);
plcDdj5ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread5, plcDdjRead5);
break;
case 6:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead6 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.6", 102));
Thread plcDdjReadThread6 = new Thread(plcDdjRead6);
plcDdj6ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread6, plcDdjRead6);
break;
}
ddjList.put("ddj" + msgDdj.getId(), msgDdj);
}
}
/**
* 开始线程
*/
public void startAllThread() {
plcSsjReadCustomThread.getThread().start();
plcDdj1ReadCustomThread.getThread().start();
plcDdj2ReadCustomThread.getThread().start();
plcDdj3ReadCustomThread.getThread().start();
plcDdj4ReadCustomThread.getThread().start();
plcDdj5ReadCustomThread.getThread().start();
plcDdj6ReadCustomThread.getThread().start();
isRun = true;
}
/**
* 开启线程2
*/
public void startAllThread2() {
monitoringCustomThread.thread.start();
ddj1CustomThread.thread.start();
/*ddj2CustomThread.thread.start();
ddj3CustomThread.thread.start();
ddj4CustomThread.thread.start();
ddj5CustomThread.thread.start();
ddj6CustomThread.thread.start();*/
isRun2 = true;
}
/**
* 停止线程
*/
public void stopAllThread() {
plcSsjReadCustomThread.runnable.isRun = false;
plcDdj1ReadCustomThread.runnable.isRun = false;
/* plcDdj2ReadCustomThread.runnable.isRun = false;
plcDdj3ReadCustomThread.runnable.isRun = false;
plcDdj4ReadCustomThread.runnable.isRun = false;
plcDdj5ReadCustomThread.runnable.isRun = false;
plcDdj6ReadCustomThread.runnable.isRun = false;*/
plcReadInit();
isRun = false;
}
/**
* 停止线程2
*/
public void stopAllThread2() {
monitoringCustomThread.runnable.isRun = false;
ddj1CustomThread.runnable.isRun = false;
/*ddj2CustomThread.runnable.isRun = false;
ddj3CustomThread.runnable.isRun = false;
ddj4CustomThread.runnable.isRun = false;
ddj5CustomThread.runnable.isRun = false;
ddj6CustomThread.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;
}
}