refactor(schedule): 重构调度线程任务初始化逻辑
- 移除BeanUtil等无关注入工具类 - 使用SpringUtils手动获取依赖服务实例 - 调整设备读取逻辑,从连接判断改为直接加载列表 - 注释掉部分冗余或暂时不用的启动线程代码 - 新增对TSJ、CDZ等设备的支持与初始化配置 - 更新XML映射文件中的SQL查询条件及格式化内容 - 优化SRGV任务中断处理逻辑,增加break语句防止空循环 - 暂时注释实际下发指令方法以避免执行真实操作
This commit is contained in:
@@ -41,6 +41,11 @@ public class RoadCacheServiceImpl implements RoadCacheService {
|
||||
for (WcsSrgvMap wcsSrgvMap : wcsSrgvMaps) {
|
||||
maps.put(wcsSrgvMap.getSiteId(), wcsSrgvMap);
|
||||
}
|
||||
param.setAxy("7,7");
|
||||
List<WcsSrgvMap> tsjMap = wcsSrgvMapMapper.selectWcsSrgvMapList(param);
|
||||
for (WcsSrgvMap wcsSrgvMap : tsjMap) {
|
||||
maps.put("tsj",wcsSrgvMap);
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,12 @@ 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;
|
||||
@@ -34,6 +37,9 @@ public class ScheduleThread {
|
||||
|
||||
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;
|
||||
@@ -43,8 +49,6 @@ public class ScheduleThread {
|
||||
@Autowired
|
||||
private IDeviceSsjService deviceSsjService;
|
||||
@Autowired
|
||||
private IMsgDdjService msgDdjService;
|
||||
@Autowired
|
||||
private IDeviceSrgvService deviceSrgvService;
|
||||
|
||||
private boolean isRun = false;
|
||||
@@ -71,6 +75,12 @@ public class ScheduleThread {
|
||||
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();
|
||||
@@ -135,8 +145,9 @@ public class ScheduleThread {
|
||||
public void startAllThread() {
|
||||
plcSsjReadCustomThread.getThread().start();
|
||||
plcSrgvReadCustomThread1.getThread().start();
|
||||
plcSrgvReadCustomThread2.getThread().start();
|
||||
plcSrgvReadCustomThread3.getThread().start();
|
||||
//plcSrgvReadCustomThread2.getThread().start();
|
||||
//plcSrgvReadCustomThread3.getThread().start();
|
||||
|
||||
|
||||
isRun = true;
|
||||
}
|
||||
@@ -147,6 +158,9 @@ public class ScheduleThread {
|
||||
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();
|
||||
|
||||
@@ -9,9 +9,12 @@ import HslCommunication.ModBus.ModbusTcpNet;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.ruoyi.common.domain.HslRead;
|
||||
import com.ruoyi.common.domain.PlcConnectInfo;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.srgv.domain.DeviceSrgv;
|
||||
import com.ruoyi.device.srgv.service.IDeviceSrgvService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
@@ -55,17 +58,25 @@ public class PlcSrgvRead implements Runnable {
|
||||
public void run() {
|
||||
while (isRun) {
|
||||
try {
|
||||
if (IsConnect()) {
|
||||
/*if (IsConnect()) {
|
||||
|
||||
if (deviceSrgv != null) {
|
||||
readSrgvPlc(deviceSrgv);
|
||||
*//*if (deviceSrgv != null) {
|
||||
//readSrgvPlc(deviceSrgv);
|
||||
|
||||
}
|
||||
}*//*
|
||||
|
||||
Thread.sleep(1000);
|
||||
} else {
|
||||
reConnect();
|
||||
}*/
|
||||
IDeviceSrgvService deviceSrgvService = SpringUtils.getBean(IDeviceSrgvService.class);
|
||||
List<DeviceSrgv> srgvs=deviceSrgvService.selectDeviceSrgvList(new DeviceSrgv());
|
||||
ConcurrentHashMap<String, DeviceSrgv> srgvList = new ConcurrentHashMap<>();
|
||||
for(DeviceSrgv srgv:srgvs){
|
||||
srgvList.put(srgv.getDeviceId().toString(),srgv);
|
||||
}
|
||||
PlcSrgvRead.deviceSrgvMap=srgvList;
|
||||
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// 捕获中断异常,退出循环
|
||||
Thread.currentThread().interrupt(); // 重新设置中断标志
|
||||
|
||||
@@ -7,15 +7,18 @@ import HslCommunication.Core.Types.OperateResultExOne;
|
||||
import HslCommunication.Profinet.Siemens.SiemensPLCS;
|
||||
import HslCommunication.Profinet.Siemens.SiemensS7Net;
|
||||
import com.ruoyi.common.domain.SendData;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.common.domain.HslRead;
|
||||
import com.ruoyi.common.domain.PlcConnectInfo;
|
||||
import com.ruoyi.device.ssj.service.impl.DeviceSsjServiceImpl;
|
||||
import com.ruoyi.schedule.plcRead.util.ParseUtil;
|
||||
import com.ruoyi.schedule.plcRead.util.Tools;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
@@ -48,10 +51,10 @@ public class PlcSsjRead implements Runnable {
|
||||
public void run() {
|
||||
while (isRun) {
|
||||
try {
|
||||
if (IsConnect()) {
|
||||
/*if (IsConnect()) {
|
||||
int step = 20;
|
||||
int baseOffset = 0;
|
||||
for (String ssjCode : deviceSsjMap.keySet()) {
|
||||
*//*for (String ssjCode : deviceSsjMap.keySet()) {
|
||||
DeviceSsj ssjDevice = deviceSsjMap.get(ssjCode);
|
||||
switch (ssjDevice.getType()) {
|
||||
case "1":
|
||||
@@ -64,11 +67,19 @@ public class PlcSsjRead implements Runnable {
|
||||
readPlcOtherSsj(ssjDevice);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}*//*
|
||||
|
||||
} else {
|
||||
reConnect();
|
||||
}*/
|
||||
DeviceSsjServiceImpl deviceSsjService = SpringUtils.getBean(DeviceSsjServiceImpl.class);
|
||||
List<DeviceSsj> deviceSsjs = deviceSsjService.selectDeviceSsjList(new DeviceSsj());
|
||||
ConcurrentHashMap<String, DeviceSsj> ssjList = new ConcurrentHashMap<>();
|
||||
for (DeviceSsj deviceSsj : deviceSsjs) {
|
||||
ssjList.put(deviceSsj.getDeviceCode(), deviceSsj);
|
||||
}
|
||||
PlcSsjRead.deviceSsjMap = ssjList;
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// 捕获中断异常,退出循环
|
||||
Thread.currentThread().interrupt(); // 重新设置中断标志
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.cdz.domain.DeviceCdz;
|
||||
import com.ruoyi.device.cdz.service.IDeviceCdzService;
|
||||
import com.ruoyi.device.srgv.domain.DeviceSrgv;
|
||||
@@ -36,7 +37,10 @@ public class CdzThread implements Runnable {
|
||||
private IWcsSrgvQueueService wcsSrgvQueueService;
|
||||
|
||||
public void init() {
|
||||
|
||||
chargingJobService = SpringUtils.getBean(ISrgvChargingJobService.class);
|
||||
deviceCdzService = SpringUtils.getBean(IDeviceCdzService.class);
|
||||
deviceSrgvService = SpringUtils.getBean(IDeviceSrgvService.class);
|
||||
wcsSrgvQueueService = SpringUtils.getBean(IWcsSrgvQueueService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.ruoyi.schedule.scheduleTask.srgv;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
@@ -10,13 +9,13 @@ import com.ruoyi.bas.srgvmap.domain.WcsSrgvMap;
|
||||
import com.ruoyi.bas.srgvmap.service.IWcsSrgvMapService;
|
||||
import com.ruoyi.bas.srgvmap.service.RoadCacheService;
|
||||
import com.ruoyi.common.domain.SendData2;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.srgv.domain.DeviceSrgv;
|
||||
import com.ruoyi.job.charg.domain.SrgvChargingJob;
|
||||
import com.ruoyi.job.charg.service.ISrgvChargingJobService;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.srgv.domain.WcsSrgvQueue;
|
||||
import com.ruoyi.queue.srgv.domain.WcsSrgvQueueFinish;
|
||||
import com.ruoyi.queue.srgv.service.IWcsSrgvQueueFinishService;
|
||||
import com.ruoyi.queue.srgv.service.IWcsSrgvQueueService;
|
||||
import com.ruoyi.schedule.plcRead.srgv.PlcSrgvRead;
|
||||
@@ -59,6 +58,14 @@ public class BaseSRgvThread implements Runnable, SRgvThreadInterface {
|
||||
sRgvCodes.add("2");
|
||||
sRgvCodes.add("3");
|
||||
sRgvCodeList.put("srgv", sRgvCodes);
|
||||
|
||||
wcsSagvQueueMapper = SpringUtils.getBean(IWcsSrgvQueueService.class);
|
||||
wcsSagvQueueFinishMapper = SpringUtils.getBean(IWcsSrgvQueueFinishService.class);
|
||||
wcsPortService = SpringUtils.getBean(IWcsPortService.class);
|
||||
srgvChargingJobMapper = SpringUtils.getBean(ISrgvChargingJobService.class);
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
wcsSrgvMapService = SpringUtils.getBean(IWcsSrgvMapService.class);
|
||||
roadCacheService = SpringUtils.getBean(RoadCacheService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,6 +216,7 @@ public class BaseSRgvThread implements Runnable, SRgvThreadInterface {
|
||||
WcsSrgvQueue wcsSrgvQueue2 = wcsSagvQueueMapper.selectWcsSrgvQueueByAgvId(deviceSrgv1.getDeviceId().toString());
|
||||
if (deviceSrgv1.getStatus() == 1 && wcsSrgvQueue2 == null) {
|
||||
deviceSrgv = deviceSrgv1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,8 +388,8 @@ public class BaseSRgvThread implements Runnable, SRgvThreadInterface {
|
||||
//筛选出deviceSrgvMap中deviceSrgv.getWorkMode() == 4并且deviceSrgv.getStatus() == 1并且deviceSrgv.getCurrSite() == cargoPickSite得对象,并排除掉其中deviceId与deviceSrgv.getDeviceId()相同的对象
|
||||
|
||||
List<DeviceSrgv> sameSiteDevices = deviceSrgvMap.values().stream()
|
||||
.filter(d -> d.getWorkMode() == 4
|
||||
&& d.getStatus() == 1
|
||||
.filter(d -> d.getWorkMode() == 4
|
||||
&& d.getStatus() == 1
|
||||
&& d.getCurrSite().equals(cargoPickSite))
|
||||
.collect(Collectors.toList());
|
||||
if(!sameSiteDevices.isEmpty() && !Objects.equals(sameSiteDevices.get(0).getDeviceId(), deviceSrgv.getDeviceId())){
|
||||
@@ -642,7 +650,7 @@ public class BaseSRgvThread implements Runnable, SRgvThreadInterface {
|
||||
sendDataList.add(flag);
|
||||
|
||||
//下发数据
|
||||
boolean b = sendCarTask(sendDataList, deviceSrgv);
|
||||
boolean b = true;// sendCarTask(sendDataList, deviceSrgv);
|
||||
if (b) {
|
||||
wcsSrgvQueue.setPathInfo(pathBuilder.toString());
|
||||
wcsSrgvQueue.setTrunPath(turnBuilder.toString());
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.ruoyi.bas.cargospace.service.IBasCargoSpaceService;
|
||||
import com.ruoyi.bas.port.domain.WcsPort;
|
||||
import com.ruoyi.bas.port.service.IWcsPortService;
|
||||
import com.ruoyi.common.domain.SendData;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.srgv.domain.DeviceSrgv;
|
||||
import com.ruoyi.device.tsj.domain.DeviceTsj;
|
||||
import com.ruoyi.device.tsj.service.IDeviceTsjService;
|
||||
@@ -35,17 +36,15 @@ public class TsjThread implements Runnable {
|
||||
|
||||
private ITsjDeviceExecutionQueueService tsjDeviceExecutionQueueService;
|
||||
private ITsjDeviceExecutionQueueFinishService tsjDeviceExecutionQueueFinishService;
|
||||
private IDeviceTsjService deviceTsjService;
|
||||
|
||||
private IMydoJobService mydoJobService;
|
||||
|
||||
private IWcsPortService wcsPortService;
|
||||
private IBasCargoSpaceService basCargoSpaceService;
|
||||
|
||||
private IWcsSrgvQueueService wcsSrgvQueueService;
|
||||
|
||||
|
||||
public void init() {
|
||||
tsjDeviceExecutionQueueService = SpringUtils.getBean(ITsjDeviceExecutionQueueService.class);
|
||||
tsjDeviceExecutionQueueFinishService = SpringUtils.getBean(ITsjDeviceExecutionQueueFinishService.class);
|
||||
wcsPortService = SpringUtils.getBean(IWcsPortService.class);
|
||||
wcsSrgvQueueService = SpringUtils.getBean(IWcsSrgvQueueService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.bas.srgvmap.mapper.WcsSrgvMapMapper">
|
||||
|
||||
|
||||
<resultMap type="WcsSrgvMap" id="WcsSrgvMapResult">
|
||||
<result property="guid" column="guid" />
|
||||
<result property="x" column="x" />
|
||||
@@ -35,7 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectWcsSrgvMapList" parameterType="WcsSrgvMap" resultMap="WcsSrgvMapResult">
|
||||
<include refid="selectWcsSrgvMapVo"/>
|
||||
<where>
|
||||
<where>
|
||||
<if test="guid != null and guid != ''"> and guid = #{guid}</if>
|
||||
<if test="x != null "> and x = #{x}</if>
|
||||
<if test="y != null "> and y = #{y}</if>
|
||||
@@ -57,9 +57,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="plcLayer != null "> and plc_layer = #{plcLayer}</if>
|
||||
<if test="warehouse != null and warehouse != ''"> and warehouse = #{warehouse}</if>
|
||||
<if test="spaceArea != null and spaceArea != ''"> and space_area = #{spaceArea}</if>
|
||||
<if test="remark != null and remark != ''"> and remark = #{remark}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectWcsSrgvMapByGuid" parameterType="String" resultMap="WcsSrgvMapResult">
|
||||
<include refid="selectWcsSrgvMapVo"/>
|
||||
where guid = #{guid}
|
||||
@@ -155,9 +156,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</delete>
|
||||
|
||||
<delete id="deleteWcsSrgvMapByGuids" parameterType="String">
|
||||
delete from wcs_srgv_map where guid in
|
||||
delete from wcs_srgv_map where guid in
|
||||
<foreach item="guid" collection="array" open="(" separator="," close=")">
|
||||
#{guid}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user