From 7a0c4a808255657a7c8330985ed1a5e5446156be Mon Sep 17 00:00:00 2001 From: wangyan <405898180@qq.com> Date: Sun, 2 Nov 2025 16:07:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor(device):=E9=87=8D=E6=9E=84=E7=89=A9?= =?UTF-8?q?=E8=81=94=E7=BD=91=E8=AE=BE=E5=A4=87=E6=95=B0=E6=8D=AE=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改设备数据查询方法,使用listMQTarget替代listTargetByEquId - 优化数据处理流程,通过循环遍历设备配置替代硬编码条件判断- 增加空值检查,确保数据列表不为空时才执行保存操作- 移除冗余的批量插入和更新方法 - 添加设备类型过滤条件,精确匹配一氧化碳设备数据 - 简化代码结构,提高可维护性和扩展性 --- .../controller/AppPosiDeviceController.java | 88 ++++++------------- .../datasource/tbIron/TbIronPlcMapper.java | 14 +-- .../datasource/tbIron/TbIronPlcMapper.xml | 34 ++++++- 3 files changed, 61 insertions(+), 75 deletions(-) diff --git a/src/main/java/com/zcloud/controller/AppPosiDeviceController.java b/src/main/java/com/zcloud/controller/AppPosiDeviceController.java index d1127a6..25389be 100644 --- a/src/main/java/com/zcloud/controller/AppPosiDeviceController.java +++ b/src/main/java/com/zcloud/controller/AppPosiDeviceController.java @@ -152,74 +152,38 @@ public class AppPosiDeviceController { String processingBatchId = UuidUtil.get32UUID(); // 批处理时间 String processingTime = DateUtil.date2Str(new Date()); - // td1 和 t2td1 的值是一氧化碳浓度 每次数据至多两条(安装在一起的设备) String location = parma.get("location"); - // 根据设备的地点和td1或者是t2td1判断出设备对应系统中的哪个 - // 查出所有一氧化碳设备的阈值配置 - List targetAllList = tbIronPlcMapper.listTargetByEquId(); + + // 查出所有一氧化碳设备的配置 + List targetAllList = tbIronPlcMapper.listMQTarget(); // 定义一个存储集合用于存储要入库的数据 List> dataList = new ArrayList<>(); - // TODO: 这里要读表作对比然后存入数据库 - if (location.equals("1#高炉中控室")) { - // 如果是1#高炉中控室,td1的值为1#高炉中控室(上)的CO浓度,t2td1的值为1#高炉中控室(下)的CO浓度。 - if (parma.containsKey("td1")) { - // 如果包含td1,证明1#高炉中控室(上)的CO浓度有值 将一氧化碳的浓度值、所属设备编码(EQUIPMENT_ID)、预警阈值传入方法 - dataList.add(saveData(parma.get("td1"), "8eab7aff5585192b028e9592e2a6c6e9", targetAllList, processingBatchId, processingTime)); - } - if (parma.containsKey("t2td1")) { - dataList.add(saveData(parma.get("t2td1"), "cf0c414e21e0413aac3ac53e53c33058", targetAllList, processingBatchId, processingTime)); - } - } else if (location.equals("2#高炉中控室")) { - if (parma.containsKey("td1")) { - dataList.add(saveData(String.valueOf(Double.parseDouble(parma.get("td1")) / 10), "5787b69539465c1221c4eb2b9bf00168", targetAllList, processingBatchId, processingTime)); - } - if (parma.containsKey("t2td1")) { - dataList.add(saveData(parma.get("t2td1"), "90313d5f6a22cefcd2ea44c871481723", targetAllList, processingBatchId, processingTime)); - } - } else if (location.equals("3#高炉中控室")) { - if (parma.containsKey("td24")) { - dataList.add(saveData(parma.get("td24"), "bdd20ccfe7c356a350d4bbc1d0390f97", targetAllList, processingBatchId, processingTime)); - } - if (parma.containsKey("t2td1")) { - dataList.add(saveData(parma.get("t2td1"), "8cf0093ec99a1d09cac2e8bc207c0d8b", targetAllList, processingBatchId, processingTime)); - } - } else if (location.equals("4#高炉中控室")) { - if (parma.containsKey("td1")) { - dataList.add(saveData(parma.get("td1"), "49a8b00f779007f09c0fbd5afeccb75a", targetAllList, processingBatchId, processingTime)); - } - if (parma.containsKey("t2td1")) { - dataList.add(saveData(parma.get("t2td1"), "3737a215ef2f5a774703cd69f2952d3c", targetAllList, processingBatchId, processingTime)); - } - } else if (location.equals("一烧中控室")) { - if (parma.containsKey("td1")) { - dataList.add(saveData(parma.get("td1"), "7c7ab19b8b862e6febac8e72e2bcecaa", targetAllList, processingBatchId, processingTime)); - } - }else if (location.equals("二烧中控室")) { - if (parma.containsKey("td1")) { - dataList.add(saveData(parma.get("td1"), "8e3854150d46d7fa9769cf6d5dc0cfa8", targetAllList, processingBatchId, processingTime)); - } - } else if (location.equals("型钢中控室")) { - if (parma.containsKey("td1")) { - dataList.add(saveData(parma.get("td1"), "da04c8ae4e7b2bacaafae391a3baa0aa", targetAllList, processingBatchId, processingTime)); - } - if (parma.containsKey("t2td1")) { - dataList.add(saveData(parma.get("t2td1"), "60ef896d9f6af5705430cf6aa8d52174", targetAllList, processingBatchId, processingTime)); - } - } else if (location.equals("15万高炉煤气柜中控室")) { - if (parma.containsKey("td1")) { - dataList.add(saveData(parma.get("td1"), "07d5be0f912ae11418772b39d447665b", targetAllList, processingBatchId, processingTime)); - } - } else if (location.equals("新跨大包热修")) { - if (parma.containsKey("td1")) { - dataList.add(saveData(parma.get("td1"), "188624b575d36e4bc2cffd57c78b3314", targetAllList, processingBatchId, processingTime)); + + // 循环遍历所有设备配置 + for (PageData target : targetAllList) { + String displayArea = target.getString("DISPLAY_AREA"); + String bitNo = target.getString("BIT_NO"); + String equipmentId = target.getString("EQUIPMENT_ID"); + + // 检查DISPLAY_AREA是否匹配传入的location + if (location != null && location.equals(displayArea) && bitNo != null) { + // 直接使用BIT_NO作为参数key查找对应的值 + if (parma.containsKey(bitNo)) { + String currentValue = parma.get(bitNo); + + // 添加到数据列表 + dataList.add(saveData(currentValue, equipmentId, targetAllList, processingBatchId, processingTime)); + } } } - // 存储集合中处理好的数据 - mesDeviceMonitoringMapper.saveBatchFromMes(dataList); - // 将物联网数据存入Redis缓存 - redisUtil.set("WMK_DATA_LIST", JSONObject.toJSONString(dataList)); - XxlJobHelper.log("成功保存{}条物联网模块数据到本地数据库", dataList.size()); + // 存储集合中处理好的数据 + if (!dataList.isEmpty()) { + mesDeviceMonitoringMapper.saveBatchFromMes(dataList); + // 将物联网数据存入Redis缓存 + redisUtil.set("WMK_DATA_LIST", JSONObject.toJSONString(dataList)); + XxlJobHelper.log("成功保存{}条物联网模块数据到本地数据库", dataList.size()); + } } // 定义一个通用的保存数据的方法 diff --git a/src/main/java/com/zcloud/mapper/datasource/tbIron/TbIronPlcMapper.java b/src/main/java/com/zcloud/mapper/datasource/tbIron/TbIronPlcMapper.java index de5d660..e227fbc 100644 --- a/src/main/java/com/zcloud/mapper/datasource/tbIron/TbIronPlcMapper.java +++ b/src/main/java/com/zcloud/mapper/datasource/tbIron/TbIronPlcMapper.java @@ -12,6 +12,8 @@ public interface TbIronPlcMapper { ArrayList> listAll (); + List listMQTarget(); + List listTargetByEquId(); List listDustDeviceAll(); @@ -23,23 +25,11 @@ public interface TbIronPlcMapper { */ List listRealtimeDataByEquipmentId(String equipmentId); - /** - * 批量插入数据到实时表 - * @param dataList 数据列表 - */ - void insertBatchToRealtime(List> dataList); - /** * 单条插入数据到实时表 * @param data 数据 */ void insertToRealtime(Map data); - - /** - * 批量更新从MES获取的数据 - * @param dataList 数据列表 - */ - void updateBatchToRealtime(List> dataList); /** * 单条更新从MES获取的数据 diff --git a/src/main/resources/mybatis/datasource/tbIron/TbIronPlcMapper.xml b/src/main/resources/mybatis/datasource/tbIron/TbIronPlcMapper.xml index f563480..0c96f0f 100644 --- a/src/main/resources/mybatis/datasource/tbIron/TbIronPlcMapper.xml +++ b/src/main/resources/mybatis/datasource/tbIron/TbIronPlcMapper.xml @@ -32,6 +32,38 @@ p.CORPINFO_ID = '499d43c24fab49f59391ce49fb401837' and p.ISDELETE = 0 and mt.ISDELETE = 0 + + SELECT p.PLC_ID,