Commit 9550623c authored by wanghao's avatar wanghao

1 老化柜界面调整及 五分钟巡检任务调整。

parent 389633da
...@@ -41,11 +41,7 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP ...@@ -41,11 +41,7 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
// 日期格式器,用于生成文件名和日志时间 // 日期格式器,用于生成文件名和日志时间
private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyyMMdd"); private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyyMMdd");
private static final SimpleDateFormat TIME_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static final SimpleDateFormat TIME_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 添加状态跟踪变量
private volatile boolean isProcessingCommand = false;
private volatile long lastActivityTime = System.currentTimeMillis(); private volatile long lastActivityTime = System.currentTimeMillis();
private volatile long lastIdleTime = System.currentTimeMillis();
/** /**
* 当前正在处理的指令信息 * 当前正在处理的指令信息
...@@ -140,20 +136,21 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP ...@@ -140,20 +136,21 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
// 处理指令完成 // 处理指令完成
if (status.isFullyIdle()) { if (status.isFullyIdle()) {
// 记录详细状态
log.debug("机械臂状态: code={}, text={}, position=({},{},{},{})",
status.getCode(), status.getText(),
status.getX(), status.getY(), status.getZ(), status.getR());
CommandExecution execution = currentCommands.get("127.0.0.1"); CommandExecution execution = currentCommands.get("127.0.0.1");
if (execution != null) { if (execution != null) {
robotArmCommandService.completeCommand(execution.commandId); robotArmCommandService.completeCommand(execution.commandId);
currentCommands.remove(sender); currentCommands.remove("127.0.0.1");
log.info("指令完成: {}", execution.commandId); log.info("指令完成: {}", execution.commandId);
} }
} else { } else {
log.info("status.isFullyIdle() = false"); log.info("status.isFullyIdle() = false");
} }
// 记录详细状态
log.debug("机械臂状态: code={}, text={}, position=({},{},{},{})",
status.getCode(), status.getText(),
status.getX(), status.getY(), status.getZ(), status.getR());
} }
/** /**
* 记录当前执行的指令 * 记录当前执行的指令
...@@ -168,9 +165,6 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP ...@@ -168,9 +165,6 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
private void handleFullyIdleState() { private void handleFullyIdleState() {
// 重置空闲计时
lastIdleTime = System.currentTimeMillis();
// 处理待执行指令 // 处理待执行指令
robotArmCommandService.processPendingCommands(); robotArmCommandService.processPendingCommands();
} }
...@@ -213,8 +207,6 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP ...@@ -213,8 +207,6 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long idleDuration = now - lastActivityTime; long idleDuration = now - lastActivityTime;
log.info("UDP通道空闲: {}ms", idleDuration);
// 如果长时间空闲(>2秒) // 如果长时间空闲(>2秒)
if (idleDuration > 20000) { if (idleDuration > 20000) {
handleLongIdleState(); handleLongIdleState();
......
...@@ -6,6 +6,10 @@ import java.net.SocketAddress; ...@@ -6,6 +6,10 @@ import java.net.SocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.zehong.common.utils.DateUtils; import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.StringUtils; import com.zehong.common.utils.StringUtils;
import com.zehong.system.domain.TEquipmentInfo; import com.zehong.system.domain.TEquipmentInfo;
...@@ -106,7 +110,7 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService ...@@ -106,7 +110,7 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
// boolean[] roboticArmExitConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData(); // boolean[] roboticArmExitConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData();
// if(roboticArmExitConveyorData[1]) { // if(roboticArmExitConveyorData[1]) {
log.info("开始处理上料指令: {}", loadingCommands.get(0)); log.info("开始处理下料指令: {}", unloadingCommands.get(0));
sendCommand(unloadingCommands.get(0), "UNLOAD"); sendCommand(unloadingCommands.get(0), "UNLOAD");
// } // }
} }
...@@ -119,6 +123,26 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService ...@@ -119,6 +123,26 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
command.setStartExecutionTime(new Date()); command.setStartExecutionTime(new Date());
robotArmCommandMapper.updateRobotArmCommand(command); robotArmCommandMapper.updateRobotArmCommand(command);
// 如果是下料,则 先断电再去下料
if("UNLOAD".equals(commandType)) {
String trayCode = command.getTrayCode();
String[] split = trayCode.split("-");
TEquipmentInfo tEquipmentInfo = equipmentInfoMapper.selectTEquipmentInfoByCode(split[0]);
int layer = Integer.parseInt(split[0]);
try {
ModbusMaster master = Modbus4jUtils.getMaster(tEquipmentInfo.getfPowerOutageIp(), tEquipmentInfo.getfPowerOutagePort());
Modbus4jUtils.writeCoil(master, 1, layer, false);
log.info("已发送断电指令 - 设备:{} 层:{}", tEquipmentInfo.getfEquipmentCode(), layer);
master.destroy();
} catch (ModbusTransportException | ModbusInitException e) {
log.info("下料发送断电指令失败 - 设备:{} 层:{}", tEquipmentInfo.getfEquipmentCode(), layer);
throw new RuntimeException(e);
}
}
// 通过WebSocket广播更新 // 通过WebSocket广播更新
robotArmWebSocketHandler.broadcastCommandUpdate(); robotArmWebSocketHandler.broadcastCommandUpdate();
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<!-- 每行渲染6个卡片 --> <!-- 每行渲染6个卡片 -->
<el-col <el-col
:span="4" :span="4"
v-for="item in row" v-for="(item, colIndex) in row"
:key="item.fEquipmentId" :key="item.fEquipmentId"
style="margin-bottom: 20px; text-align: center;" style="margin-bottom: 20px; text-align: center;"
> >
...@@ -56,7 +56,9 @@ ...@@ -56,7 +56,9 @@
font-weight: bold;" font-weight: bold;"
@click.native="handleCardClick(item)" @click.native="handleCardClick(item)"
> >
{{ item.fEquipmentCode + "号柜" }} <!-- {{ item.fEquipmentCode + "号柜" }}-->
<!-- 核心:调用方法生成编号,传入总索引 = 行索引*6 + 列索引 -->
{{ getCabinetNumber(rowIndex * 6 + colIndex) }}
</el-card> </el-card>
</el-tooltip> </el-tooltip>
</el-col> </el-col>
...@@ -103,7 +105,19 @@ export default { ...@@ -103,7 +105,19 @@ export default {
this.initWebSocket(); // 初始化WebSocket连接 this.initWebSocket(); // 初始化WebSocket连接
}, },
methods: { methods: {
// 新增:计算柜子编号(北-XX / 南-XX)
getCabinetNumber(totalIndex) {
if (totalIndex < 15) {
// 前15个(索引0-14):北-1 ~ 北-15
return `北-${totalIndex + 1}`;
} else if (totalIndex < 30) {
// 16-30个(索引15-29):南-1 ~ 南-15
return `南-${totalIndex - 15 + 1}`; // 15对应南-1,29对应南-15
} else {
// 超过30个的情况(可选扩展)
return `其他-${totalIndex + 1}`;
}
},
// 初始化WebSocket连接 // 初始化WebSocket连接
initWebSocket() { initWebSocket() {
// 从环境变量获取基础URL,默认使用Nginx代理地址 // 从环境变量获取基础URL,默认使用Nginx代理地址
...@@ -128,7 +142,10 @@ export default { ...@@ -128,7 +142,10 @@ export default {
const message = JSON.parse(event.data); const message = JSON.parse(event.data);
// 只处理老化柜数据类型的消息 // 只处理老化柜数据类型的消息
if (message.type === 'aging_cabinet_data') { if (message.type === 'aging_cabinet_data') {
this.cabinets = message.data; // 更新数据,自动触发cabinetRows重新计算 // 按fEquipmentCode升序排序(假设fEquipmentCode是1~30的数字字符串)
this.cabinets = message.data.sort((a, b) => {
return Number(a.fEquipmentCode) - Number(b.fEquipmentCode);
});
console.log('收到老化柜更新数据,共', message.data.length, '条'); console.log('收到老化柜更新数据,共', message.data.length, '条');
} }
} catch (e) { } catch (e) {
...@@ -168,7 +185,10 @@ export default { ...@@ -168,7 +185,10 @@ export default {
// 开始加载:显示全局loading // 开始加载:显示全局loading
this.pageLoading = true; this.pageLoading = true;
getAllEquipmentList().then(response => { getAllEquipmentList().then(response => {
this.cabinets = response; // 按fEquipmentCode升序排序(假设fEquipmentCode是1~30的数字字符串)
this.cabinets = response.sort((a, b) => {
return Number(a.fEquipmentCode) - Number(b.fEquipmentCode);
});
this.pageLoading = false; this.pageLoading = false;
}) })
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment