Files
FT542-WCS/ruoyi-admin/src/main/java/com/ruoyi/schedule/ScheduleThread.java
2025-12-25 13:56:28 +08:00

231 lines
9.0 KiB
Java

package com.ruoyi.schedule;
import HslCommunication.Core.Types.OperateResultExOne;
import com.ruoyi.common.domain.CustomThread;
import com.ruoyi.common.domain.PlcConnectInfo;
import com.ruoyi.device.cdz.domain.DeviceCdz;
import com.ruoyi.device.cdz.service.IDeviceCdzService;
import com.ruoyi.device.ddj.domain.MsgDdj;
import com.ruoyi.device.ddj.service.IMsgDdjService;
import com.ruoyi.device.srgv.domain.DeviceSrgv;
import com.ruoyi.device.srgv.service.IDeviceSrgvService;
import com.ruoyi.device.ssj.domain.DeviceSsj;
import com.ruoyi.device.ssj.service.IDeviceSsjService;
import com.ruoyi.device.tsj.domain.DeviceTsj;
import com.ruoyi.device.tsj.service.impl.DeviceTsjServiceImpl;
import com.ruoyi.schedule.plcRead.cdz.PlcCdzRead;
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
import com.ruoyi.schedule.plcRead.srgv.PlcSrgvRead;
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
import com.ruoyi.schedule.plcRead.tsj.PlcTsjRead;
import com.ruoyi.schedule.scheduleTask.cdz.CdzThread;
import com.ruoyi.schedule.scheduleTask.ddj.impl.Ddj1Thread;
import com.ruoyi.schedule.scheduleTask.monit.MonitoringThread;
import com.ruoyi.schedule.scheduleTask.srgv.impl.SRgv1Thread;
import com.ruoyi.schedule.scheduleTask.ssj.SsjThread;
import com.ruoyi.schedule.scheduleTask.tsj.TsjThread;
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<PlcCdzRead> plcCdzjReadCustomThread;
public CustomThread<PlcTsjRead> plcTsjReadCustomThread;
public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread1;
public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread2;
public CustomThread<PlcSrgvRead> plcSrgvReadCustomThread3;
public CustomThread<MonitoringThread> monitoringCustomThread;
public CustomThread<SsjThread> ssjThreadCustomThread;
public CustomThread<SRgv1Thread> sRgvThreadCustomThread;
public CustomThread<TsjThread> tsjThreadCustomThread;
public CustomThread<CdzThread> cdzThreadCustomThread;
// 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 IDeviceSrgvService deviceSrgvService;
@Autowired
private IDeviceCdzService deviceCdzService;
private boolean isRun = false;
private boolean isRun2 = false;
@Autowired
private DeviceTsjServiceImpl deviceTsjServiceImpl;
/**
* 项目初始化启动
*/
@PostConstruct
public void init() {
log.info("初始化调度服务");
//读取信息初始化
plcReadInit();
//调度初始化
scheduleInit();
startAllThread();
startAllThread2();
log.info("调度服务执行成功");
}
/**
* 调度初始化
*/
private void scheduleInit() {
//输送机线程
SsjThread ssjThread=new SsjThread();
ssjThreadCustomThread=new CustomThread<SsjThread>(new Thread(ssjThread),ssjThread);
// //四向车线程
SRgv1Thread srgvThread=new SRgv1Thread();
sRgvThreadCustomThread=new CustomThread<>(new Thread(srgvThread),srgvThread);
//提升机线程
TsjThread tsjThread=new TsjThread();
tsjThreadCustomThread=new CustomThread<>(new Thread(tsjThread),tsjThread);
//充电线程
CdzThread cdzThread = new CdzThread();
cdzThreadCustomThread=new CustomThread<>(new Thread(cdzThread),cdzThread);
}
/**
* plc读取初始化
*/
private void plcReadInit() {
//plc输送机读取线程
ConcurrentHashMap<String, DeviceSsj> ssjList = new ConcurrentHashMap<>();
//获取要取的输送机
List<DeviceSsj> deviceSsjs = deviceSsjService.selectDeviceSsjList(new DeviceSsj());
for (DeviceSsj deviceSsj : deviceSsjs) {
ssjList.put(deviceSsj.getDeviceCode(), deviceSsj);
}
PlcSsjRead plcSsjRead = new PlcSsjRead(ssjList, new PlcConnectInfo("127.0.0.1", 1502));
Thread plcSsjReadThread = new Thread(plcSsjRead);
plcSsjReadCustomThread = new CustomThread<PlcSsjRead>(plcSsjReadThread, plcSsjRead);
//plc充电桩读取线程
ConcurrentHashMap<String, DeviceCdz> cdzList = new ConcurrentHashMap<>();
List<DeviceCdz> deviceCdzList =deviceCdzService.selectDeviceCdzList(new DeviceCdz());
for (DeviceCdz deviceCdz : deviceCdzList) {
cdzList.put(String.valueOf(deviceCdz.getId()),deviceCdz);
}
PlcCdzRead plcCdzRead = new PlcCdzRead(cdzList, new PlcConnectInfo("127.0.0.1", 1502));
Thread plcCdzReadThread = new Thread(plcCdzRead);
plcCdzjReadCustomThread = new CustomThread<PlcCdzRead>(plcCdzReadThread, plcCdzRead);
ConcurrentHashMap<String, DeviceTsj> tsjList = new ConcurrentHashMap<>();
//获取要取的提升机
List<DeviceTsj> tsjLists = deviceTsjServiceImpl.selectDeviceTsjList(new DeviceTsj());
for (DeviceTsj t : tsjLists) {
tsjList.put(t.getName(), t);
}
//plc提升机读取线程
PlcTsjRead plcTsjRead = new PlcTsjRead(tsjList, new PlcConnectInfo("127.0.0.1", 1502));
Thread plcTsjReadThread = new Thread(plcTsjRead);
plcTsjReadCustomThread = new CustomThread<PlcTsjRead>(plcTsjReadThread, plcTsjRead);
ConcurrentHashMap<String, DeviceSrgv> srgvList = new ConcurrentHashMap<>();
List<DeviceSrgv> srgvs=deviceSrgvService.selectDeviceSrgvList(new DeviceSrgv());
for(DeviceSrgv srgv:srgvs){
srgvList.put(srgv.getDeviceId().toString(),srgv);
switch (srgv.getDeviceId()){
case 1:
PlcSrgvRead plcSrgvRead1=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
Thread plcSrgvReadThread1 = new Thread((plcSrgvRead1));
plcSrgvReadCustomThread1=new CustomThread<PlcSrgvRead>(plcSrgvReadThread1,plcSrgvRead1);
break;
case 2:
PlcSrgvRead plcSrgvRead2=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
Thread plcSrgvReadThread2 = new Thread((plcSrgvRead2));
plcSrgvReadCustomThread2=new CustomThread<PlcSrgvRead>(plcSrgvReadThread2,plcSrgvRead2);
break;
}
}
PlcSrgvRead.deviceSrgvMap=srgvList;
//监控线程
MonitoringThread monitoringThread = new MonitoringThread();
monitoringCustomThread = new CustomThread<MonitoringThread>(new Thread(monitoringThread), monitoringThread);
}
/**
* 开始线程
*/
public void startAllThread() {
plcSsjReadCustomThread.getThread().start();
plcSrgvReadCustomThread1.getThread().start();
// plcSrgvReadCustomThread2.getThread().start();
plcTsjReadCustomThread.getThread().start();
monitoringCustomThread.getThread().start();
//充电桩读取线程
// plcCdzjReadCustomThread.getThread().start();
isRun = true;
}
/**
* 开启线程2
*/
public void startAllThread2() {
ssjThreadCustomThread.thread.start();
tsjThreadCustomThread.thread.start();
sRgvThreadCustomThread.thread.start();
// cdzThreadCustomThread.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;
}
}