项目初始化

This commit is contained in:
liuhanqing
2025-12-03 16:05:57 +08:00
commit 4b66b5bc44
871 changed files with 130415 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.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.schedule.plcRead.ddj.PlcDdjRead;
import com.ruoyi.schedule.plcRead.srgv.PlcSrgvRead;
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
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<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;
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);
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);
// 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);
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;
case 3:
PlcSrgvRead plcSrgvRead3=new PlcSrgvRead(srgv,new PlcConnectInfo(srgv.getIp(),srgv.getPort()));
Thread plcSrgvReadThread3 = new Thread((plcSrgvRead3));
plcSrgvReadCustomThread3=new CustomThread<PlcSrgvRead>(plcSrgvReadThread3,plcSrgvRead3);
break;
}
}
PlcSrgvRead.deviceSrgvMap=srgvList;
}
/**
* 开始线程
*/
public void startAllThread() {
plcSsjReadCustomThread.getThread().start();
plcSrgvReadCustomThread1.getThread().start();
//plcSrgvReadCustomThread2.getThread().start();
//plcSrgvReadCustomThread3.getThread().start();
isRun = true;
}
/**
* 开启线程2
*/
public void startAllThread2() {
monitoringCustomThread.thread.start();
ssjThreadCustomThread.thread.start();
//tsjThreadCustomThread.thread.start();
sRgvThreadCustomThread.thread.start();
//cdzThreadCustomThread.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;
}
}