From 04914a9997afbbead6f8adbb9d9c40e05b2edbd1 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期三, 17 十二月 2025 17:04:34 +0800
Subject: [PATCH] 修复调用导入工程失败 重复保存;修复分批出片逻辑
---
mes-processes/mes-plcSend/src/main/java/com/mes/device/mapper/DeviceGroupRelationMapper.java | 43 ++++++++++++++++++++++++++++++++++++++++---
1 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/device/mapper/DeviceGroupRelationMapper.java b/mes-processes/mes-plcSend/src/main/java/com/mes/device/mapper/DeviceGroupRelationMapper.java
index 6ae3625..0da6396 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/device/mapper/DeviceGroupRelationMapper.java
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/device/mapper/DeviceGroupRelationMapper.java
@@ -1,6 +1,7 @@
package com.mes.device.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.mes.device.entity.DeviceConfig;
import com.mes.device.entity.DeviceGroupRelation;
import com.mes.device.vo.DeviceGroupVO;
import org.apache.ibatis.annotations.Mapper;
@@ -56,11 +57,15 @@
* @return 璁惧淇℃伅鍒楄〃
*/
@Select("SELECT d.id, d.device_name as deviceName, d.device_code as deviceCode, " +
- "d.device_type as deviceType, dgr.role, d.status, " +
- "d.last_heartbeat as lastHeartbeat, d.is_online as isOnline " +
+ "d.device_type as deviceType, d.plc_ip as plcIp, dgr.role, d.status, " +
+ "ds.last_heartbeat as lastHeartbeat, d.enabled, " +
+ "CASE WHEN ds.status = 'ONLINE' THEN TRUE ELSE FALSE END as isOnline " +
"FROM device_config d " +
"INNER JOIN device_group_relation dgr ON d.id = dgr.device_id " +
- "WHERE dgr.group_id = #{groupId} AND dgr.is_deleted = 0 AND d.is_deleted = 0")
+ "LEFT JOIN device_status ds ON d.device_id = ds.device_id " +
+ " AND ds.id = (SELECT MAX(id) FROM device_status WHERE device_id = d.device_id) " +
+ "WHERE dgr.group_id = #{groupId} AND dgr.is_deleted = 0 AND d.is_deleted = 0 " +
+ "ORDER BY dgr.connection_order ASC")
List<DeviceGroupVO.DeviceInfo> getGroupDevices(@Param("groupId") Long groupId);
/**
@@ -77,4 +82,36 @@
"INNER JOIN device_group_relation dgr ON dgc.id = dgr.group_id " +
"WHERE dgr.device_id = #{deviceId} AND dgr.is_deleted = 0 AND dgc.is_deleted = 0")
List<DeviceGroupVO.GroupInfo> getDeviceGroups(@Param("deviceId") Long deviceId);
+
+ /**
+ * 鑾峰彇鎸夎繛鎺ラ『搴忔帓搴忕殑璁惧閰嶇疆鍒楄〃
+ *
+ * @param groupId 璁惧缁処D
+ * @return 璁惧閰嶇疆闆嗗悎
+ */
+ @Select("SELECT d.* " +
+ "FROM device_group_relation dgr " +
+ "INNER JOIN device_config d ON dgr.device_id = d.id " +
+ "WHERE dgr.group_id = #{groupId} " +
+ " AND dgr.is_deleted = 0 " +
+ " AND d.is_deleted = 0 " +
+ "ORDER BY IFNULL(dgr.connection_order, 0) ASC, dgr.id ASC")
+ List<DeviceConfig> getOrderedDeviceConfigs(@Param("groupId") Long groupId);
+
+ /**
+ * 鑾峰彇璁惧缁勪笅鐨勫湪绾胯澶囨暟閲�
+ *
+ * @param groupId 璁惧缁処D
+ * @return 鍦ㄧ嚎璁惧鏁伴噺
+ */
+ @Select("SELECT COUNT(DISTINCT d.id) " +
+ "FROM device_config d " +
+ "INNER JOIN device_group_relation dgr ON d.id = dgr.device_id " +
+ "LEFT JOIN device_status ds ON d.device_id = ds.device_id " +
+ " AND ds.id = (SELECT MAX(id) FROM device_status WHERE device_id = d.device_id) " +
+ "WHERE dgr.group_id = #{groupId} " +
+ " AND dgr.is_deleted = 0 " +
+ " AND d.is_deleted = 0 " +
+ " AND ds.status = 'ONLINE'")
+ Integer getOnlineDeviceCountByGroupId(@Param("groupId") Long groupId);
}
\ No newline at end of file
--
Gitblit v1.8.0