Commit 754d5d57 authored by wanghao's avatar wanghao

1 解绑是否上传MES 调整

2 设备报警记录调整
3 写自检 读设备时间 间隔调整。避免出现写成功,后立马读 读失败的问题。
parent 23f64090
......@@ -22,7 +22,7 @@ import com.zehong.common.core.page.TableDataInfo;
/**
* 托盘绑定的设备列Controller
*
*
* @author zehong
* @date 2025-06-29
*/
......@@ -153,6 +153,16 @@ public class PalletDeviceBindingController extends BaseController
return palletDeviceBindingService.unbindAllDevice(trayId);
}
/**
* 解绑所有设备(不上传MES数据)
* @param trayId t
* @return l
*/
@GetMapping("/unbindAllDeviceNoUploadMes/{trayId}")
public AjaxResult unbindAllDeviceNoUploadMes(@PathVariable("trayId") Long trayId) {
return palletDeviceBindingService.unbindAllDeviceNoUploadMes(trayId);
}
/**
* 删除托盘绑定的设备列
*/
......
......@@ -1050,7 +1050,7 @@ public class Modbus4jUtils {
if (retry < CUSTOM_RETRY_TIMES) {
log.info("设备{}第{}次读取未满足条件,准备重试: ip={}, port={}",
deviceId, retry + 1, ip, port);
Thread.sleep(200);
Thread.sleep(500);
}
} catch (Exception e) {
// 本次读取发生异常,记录日志但不中断重试(继续下一次)
......@@ -1084,7 +1084,7 @@ public class Modbus4jUtils {
// 20251206 写完时间写自检,写自检就在时间后边写就行,不管时间写不写成功
try {
Modbus4jUtils.writeRegister(master, deviceId, 15, (short) 1);
Thread.sleep(1000);
Thread.sleep(1500);
int[] ints = Modbus4jUtils.readDeviceRegisters(master, deviceId);
if (ints[15] == 1) {
return 1;
......
......@@ -7,15 +7,15 @@ import com.zehong.system.domain.PalletDeviceBinding;
/**
* 托盘绑定的设备列Service接口
*
*
* @author zehong
* @date 2025-06-29
*/
public interface IPalletDeviceBindingService
public interface IPalletDeviceBindingService
{
/**
* 查询托盘绑定的设备列
*
*
* @param palletDeviceBindingId 托盘绑定的设备列ID
* @return 托盘绑定的设备列
*/
......@@ -23,7 +23,7 @@ public interface IPalletDeviceBindingService
/**
* 查询托盘绑定的设备列列表
*
*
* @param palletDeviceBinding 托盘绑定的设备列
* @return 托盘绑定的设备列集合
*/
......@@ -37,7 +37,7 @@ public interface IPalletDeviceBindingService
/**
* 新增托盘绑定的设备列
*
*
* @param palletDeviceBinding 托盘绑定的设备列
* @return 结果
*/
......@@ -53,7 +53,7 @@ public interface IPalletDeviceBindingService
/**
* 修改托盘绑定的设备列
*
*
* @param palletDeviceBinding 托盘绑定的设备列
* @return 结果
*/
......@@ -63,9 +63,11 @@ public interface IPalletDeviceBindingService
public AjaxResult unbindAllDevice(Long trayId);
public AjaxResult unbindAllDeviceNoUploadMes(Long trayId);
/**
* 批量删除托盘绑定的设备列
*
*
* @param palletDeviceBindingIds 需要删除的托盘绑定的设备列ID
* @return 结果
*/
......@@ -73,7 +75,7 @@ public interface IPalletDeviceBindingService
/**
* 删除托盘绑定的设备列信息
*
*
* @param palletDeviceBindingId 托盘绑定的设备列ID
* @return 结果
*/
......
......@@ -251,6 +251,36 @@ public class PalletDeviceBindingServiceImpl implements IPalletDeviceBindingServi
return palletDeviceBindingMapper.deletePalletDeviceBindingById(palletDeviceBindingId);
}
/**
* 批量解绑所有设备(不处理上传数据)
*
* @param trayId 托盘ID
* @return 删除结果
*/
@Override
public AjaxResult unbindAllDeviceNoUploadMes(Long trayId) {
if(trayId == null) {
return AjaxResult.error("参数错误");
}
List<PalletDeviceBinding> palletDeviceBindings = palletDeviceBindingMapper.listByTrayId(trayId);
if(palletDeviceBindings.size() != 0) {
List<PalletDeviceBinding> mesDeviceDomains = palletDeviceBindings.stream().filter(item -> item.getMotherboardCode() != null).collect(Collectors.toList());
if(mesDeviceDomains.size() != 0) {
// 20251210 领导说 先 保存所有历史数据
palletDeviceUploadHistoryService.batchInsertRealTimeData(mesDeviceDomains);
}
}
// 解绑设备
palletDeviceBindingMapper.unbindAllDevice(trayId);
// 初始托盘状态
tTrayInfoMapper.initStatusByTrayId(trayId);
return AjaxResult.success();
}
/**
* 批量解绑所有设备
*
......
......@@ -4,16 +4,12 @@ import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ErrorResponseException;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.zehong.system.domain.TEquipmentAlarmData;
import com.zehong.system.domain.TEquipmentInfo;
import com.zehong.system.domain.modbus.ModbusDeviceData;
import com.zehong.system.modbus.util.Modbus4jUtils;
import com.zehong.system.service.ITEquipmentAlarmDataService;
import com.zehong.system.service.ITEquipmentInfoService;
import com.zehong.system.service.websocket.AgingCabinetWebSocketHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
......@@ -36,12 +32,6 @@ public class AgingCabinetInspectionAndPowerCheckTask {
@Resource
private ITEquipmentInfoService tEquipmentInfoService;
@Resource
private ApplicationEventPublisher eventPublisher; // 新增事件发布器
@Resource
private ITEquipmentAlarmDataService tEquipmentAlarmDataService;
@Resource
private AgingCabinetWebSocketHandler agingCabinetWebSocketHandler;
......@@ -72,8 +62,6 @@ public class AgingCabinetInspectionAndPowerCheckTask {
type.add("2");
List<TEquipmentInfo> equipmentInfos = tEquipmentInfoService.selectTEquipmentList(type);
TEquipmentAlarmData alarmData = new TEquipmentAlarmData();
try {
if (equipmentInfos.size() == 0) {
log.error("设备列表查询结果为空");
......@@ -91,10 +79,6 @@ public class AgingCabinetInspectionAndPowerCheckTask {
} catch (ModbusInitException e) {
// 记录异常数据
alarmData.setfAlarmType("01"); //01.老化柜 02.机械臂 03.老化层 04.点位
alarmData.setfEquipmentCode(equipmentInfo.getfEquipmentCode());
alarmData.setfAlarmData("定时任务巡检:Modbus初始化失败");
tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData);
// 更新老化柜状态(“0”空闲,“1”运行,“2”故障)
equipmentInfo.setfStatus("2");
equipmentInfo.setErrorReason("定时任务巡检:Modbus初始化失败");
......@@ -106,19 +90,12 @@ public class AgingCabinetInspectionAndPowerCheckTask {
// 网线没插好通讯不上
if (e.getMessage().equals("java.net.SocketTimeoutException: connect timed out")) {
// 记录异常数据
alarmData.setfAlarmType("01"); //01.老化柜 02.机械臂 03.老化层 04.点位
alarmData.setfEquipmentCode(equipmentInfo.getfEquipmentCode());
alarmData.setfAlarmData("定时任务巡检:老化柜网线没插好");
equipmentInfo.setErrorReason("定时任务巡检:老化柜网线没插好");
// 线接错误
} else {
// 记录异常数据
alarmData.setfAlarmType("01"); //01.老化柜 02.机械臂 03.老化层 04.点位
alarmData.setfEquipmentCode(equipmentInfo.getfEquipmentCode());
alarmData.setfAlarmData("定时任务巡检:老化柜通信线路没接好");
equipmentInfo.setErrorReason("定时任务巡检:老化柜通信线路没接好");
}
tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData);
// 更新老化柜状态(“0”空闲,“1”运行,“2”故障)
equipmentInfo.setRegisterValues(new HashMap<>());
equipmentInfo.setfStatus("2");
......@@ -168,30 +145,9 @@ public class AgingCabinetInspectionAndPowerCheckTask {
if (registerValues.size() > 0) {
boolean isRun = false;
for (Map.Entry<Integer, Object> entry : registerValues.entrySet()) {
Integer registerOffset = entry.getKey();
Object registerValue = entry.getValue();
log.info("registerValue = " + registerValue);
log.info("true equals registerValue" + Boolean.TRUE.equals(registerValue));
if (Boolean.TRUE.equals(registerValue)) {
// eventPublisher.publishEvent(new CheckPowerOnCommandEvent(
// this,
// modbusDeviceData.getfEquipmentCode(),
// modbusDeviceData.getfPowerOutageIp(),
// modbusDeviceData.getfPowerOutagePort(),
// registerOffset + 1,
// registerOffset
// ));
isRun = true;
// 要给这个 层 发断电的 指令
} else {
// 发布断电指令事件(不再直接执行)
// eventPublisher.publishEvent(new PowerOffCommandEvent(
// this,
// modbusDeviceData.getfEquipmentCode(),
// modbusDeviceData.getfPowerOutageIp(),
// modbusDeviceData.getfPowerOutagePort(),
// registerOffset + 1
// ));
}
}
if (isRun) {
......@@ -205,11 +161,4 @@ public class AgingCabinetInspectionAndPowerCheckTask {
}
return deviceDataList;
}
private ModbusDeviceData createErrorData(Throwable ex) {
ModbusDeviceData errorData = new ModbusDeviceData();
errorData.setDeviceCode("error");
errorData.setRegisterValues(Collections.singletonMap(0, "系统错误:" + ex.getMessage()));
return errorData;
}
}
......@@ -3,7 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zehong.system.mapper.TEquipmentAlarmDataMapper">
<resultMap type="TEquipmentAlarmData" id="TEquipmentAlarmDataResult">
<result property="fEquipmentAlarmDataId" column="f_equipment_alarm_data_id" />
<result property="fEquipmentCode" column="f_equipment_code" />
......@@ -18,17 +18,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectTEquipmentAlarmDataList" parameterType="TEquipmentAlarmData" resultMap="TEquipmentAlarmDataResult">
<include refid="selectTEquipmentAlarmDataVo"/>
<where>
<where>
<if test="fEquipmentCode != null and fEquipmentCode != ''"> and f_equipment_code like concat ('%',#{fEquipmentCode},'%')</if>
<if test="fAlarmData != null and fAlarmData != ''"> and f_alarm_data like concat ('%', #{fAlarmData},'%')</if>
</where>
order by f_create_time desc
</select>
<select id="selectTEquipmentAlarmDataById" parameterType="Long" resultMap="TEquipmentAlarmDataResult">
<include refid="selectTEquipmentAlarmDataVo"/>
where f_equipment_alarm_data_id = #{fEquipmentAlarmDataId}
</select>
<insert id="insertTEquipmentAlarmData" parameterType="TEquipmentAlarmData">
insert into t_equipment_alarm_data
<trim prefix="(" suffix=")" suffixOverrides=",">
......@@ -63,9 +64,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<delete id="deleteTEquipmentAlarmDataByIds" parameterType="String">
delete from t_equipment_alarm_data where f_equipment_alarm_data_id in
delete from t_equipment_alarm_data where f_equipment_alarm_data_id in
<foreach item="fEquipmentAlarmDataId" collection="array" open="(" separator="," close=")">
#{fEquipmentAlarmDataId}
</foreach>
</delete>
</mapper>
\ No newline at end of file
</mapper>
......@@ -66,6 +66,13 @@ export function unbindAllDevice(trayId){
})
}
export function unbindAllDeviceNoUploadMes(trayId){
return request({
url: '/palletDevice/binding/unbindAllDeviceNoUploadMes/' + trayId,
method: 'get'
})
}
// 修改托盘绑定的设备列
export function updateBinding(data) {
return request({
......
......@@ -139,7 +139,7 @@
import {
batchAdd,
unbindSingleDevice,
getAllExcludeUnbindingTimeByTrayId, unbindAllDevice, batchUpdateDeviceCodeAndUnbindingTime
getAllExcludeUnbindingTimeByTrayId, unbindAllDevice, batchUpdateDeviceCodeAndUnbindingTime,unbindAllDeviceNoUploadMes
} from "@/api/palletDeviceBinding/binding"
import {resetAll} from "@/api/palletDeviceBinding/binding"
export default {
......@@ -640,51 +640,158 @@ export default {
// 一键解绑所有设备
// 一键解绑所有设备
unbindAll() {
this.$confirm('确定要解绑当前托盘下所有设备吗?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'error'
// 原有代码位置:调用解绑的地方
this.showFirstConfirm();
// this.$confirm('确定要解绑当前托盘下所有设备吗?', '警告', {
// confirmButtonText: '确定',
// cancelButtonText: '取消',
// type: 'error'
// }).then(() => {
// // 创建loading实例
// const loadingInstance = this.$loading({
// lock: true,
// text: '正在解绑所有设备...',
// spinner: 'el-icon-loading',
// background: 'rgba(0, 0, 0, 0.7)'
// });
//
// unbindAllDevice(this.fTrayId).then(res => {
// // 关闭loading
// loadingInstance.close();
//
// if (res.code === 200) {
// // 解绑成功后重置设备矩阵
// this.devices = this.devices.map(d => ({
// ...d,
// motherboardCode: '',
// deviceStatus: '1',
// isDuplicate: false
// }));
// this.abnormalCount = this.devices.length; // 重置异常计数为总设备数
// this.initialAbnormalCount = this.abnormalCount;
// this.deviceInput = '';
// this.activeCell = 0;
// this.trayStatus = '0';
// this.$message.success("一键解绑成功");
// } else {
// this.$message.error("解绑失败");
// }
// }).catch(error => {
// // 关闭loading
// loadingInstance.close();
// this.$message.error("解绑请求失败: " + error.message);
// console.error("一键解绑失败:", error);
// });
// }).catch(() => {
// // 用户点击取消,不做任何操作
// });
},
// 第一级确认:是否上传MES?
showFirstConfirm() {
this.$confirm('解绑后是否上传MES?', '提示', {
confirmButtonText: '是',
cancelButtonText: '否',
type: 'warning'
}).then(() => {
// 创建loading实例
const loadingInstance = this.$loading({
lock: true,
text: '正在解绑所有设备...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
unbindAllDevice(this.fTrayId).then(res => {
// 关闭loading
loadingInstance.close();
// 点击“是” → 调用原接口(上传MES)
this.executeUnbindIsUploadMes(true);
}).catch(() => {
// 点击“否” → 显示第二级确认
this.showSecondConfirm();
});
// this.$confirm({
// title: '提示',
// message: '解绑后是否上传MES?',
// confirmButtonText: '是',
// cancelButtonText: '否',
// type: 'warning',
// distinguishCancelAndClose: true // 区分取消按钮和关闭按钮
// // confirmButtonText: '确定',
// // cancelButtonText: '取消',
// // type: 'error'
// }).then(() => {
// // 点击“是” → 调用原接口(上传MES)
// this.executeUnbindIsUploadMes(true);
// }).catch(action => {
// if (action === 'cancel') {
// // 点击“否” → 显示第二级确认
// this.showSecondConfirm();
// }
// // 若为 'close'(点击右上角关闭或ESC),则不做任何操作
// });
},
if (res.code === 200) {
// 解绑成功后重置设备矩阵
this.devices = this.devices.map(d => ({
...d,
motherboardCode: '',
deviceStatus: '1',
isDuplicate: false
}));
this.abnormalCount = this.devices.length; // 重置异常计数为总设备数
this.initialAbnormalCount = this.abnormalCount;
this.deviceInput = '';
this.activeCell = 0;
this.trayStatus = '0';
this.$message.success("一键解绑成功");
} else {
this.$message.error("解绑失败");
}
}).catch(error => {
// 关闭loading
loadingInstance.close();
this.$message.error("解绑请求失败: " + error.message);
console.error("一键解绑失败:", error);
});
// 第二级确认:确实不上传MES?
showSecondConfirm() {
this.$confirm('确实解绑后不上传MES?', '提示', {
confirmButtonText: '是',
cancelButtonText: '否',
type: 'warning'
}).then(() => {
// 点击“是” → 调用新接口(不上传MES)
this.executeUnbindIsUploadMes(false);
}).catch(() => {
// 用户点击取消,不做任何操作
// 点击“否” → 返回第一级确认
this.showFirstConfirm();
});
// this.$msgbox({
// title: '提示',
// message: '确实解绑后不上传MES?',
// confirmButtonText: '是',
// cancelButtonText: '否',
// type: 'warning',
// distinguishCancelAndClose: true
// }).then(() => {
// // 点击“是” → 调用新接口(不上传MES)
// this.executeUnbindIsUploadMes(false);
// }).catch(action => {
// if (action === 'cancel') {
// // 点击“否” → 返回第一级确认
// this.showFirstConfirm();
// }
// // 若为 'close' 则退出
// });
},
// 执行解绑的通用方法
executeUnbindIsUploadMes(uploadMes) {
// 创建loading实例
const loadingInstance = this.$loading({
lock: true,
text: '正在解绑所有设备...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
// 根据 uploadMes 决定调用哪个接口
const unbindApi = uploadMes ? unbindAllDevice : unbindAllDeviceNoUploadMes;
unbindApi(this.fTrayId).then(res => {
loadingInstance.close();
if (res.code === 200) {
// 解绑成功后重置设备矩阵
this.devices = this.devices.map(d => ({
...d,
motherboardCode: '',
deviceStatus: '1',
isDuplicate: false
}));
this.abnormalCount = this.devices.length; // 重置异常计数为总设备数
this.initialAbnormalCount = this.abnormalCount;
this.deviceInput = '';
this.activeCell = 0;
this.trayStatus = '0';
this.$message.success("一键解绑成功");
} else {
this.$message.error("解绑失败");
}
}).catch(error => {
loadingInstance.close();
this.$message.error("解绑请求失败: " + error.message);
console.error("一键解绑失败:", error);
});
},
// 绑定托盘
bindTray: function () {
if (this.trayStatus === '0' || this.trayStatus === '4') {
......
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