refactor(device):重构物联网设备数据处理逻辑

- 修改设备数据查询方法,使用listMQTarget替代listTargetByEquId
- 优化数据处理流程,通过循环遍历设备配置替代硬编码条件判断- 增加空值检查,确保数据列表不为空时才执行保存操作- 移除冗余的批量插入和更新方法
- 添加设备类型过滤条件,精确匹配一氧化碳设备数据
- 简化代码结构,提高可维护性和扩展性
dev
wangyan 2025-11-02 16:07:46 +08:00
parent 4912547478
commit 7a0c4a8082
3 changed files with 61 additions and 75 deletions

View File

@ -152,75 +152,39 @@ public class AppPosiDeviceController {
String processingBatchId = UuidUtil.get32UUID();
// 批处理时间
String processingTime = DateUtil.date2Str(new Date());
// td1 和 t2td1 的值是一氧化碳浓度 每次数据至多两条(安装在一起的设备)
String location = parma.get("location");
// 根据设备的地点和td1或者是t2td1判断出设备对应系统中的哪个
// 查出所有一氧化碳设备的阈值配置
List<PageData> targetAllList = tbIronPlcMapper.listTargetByEquId();
// 查出所有一氧化碳设备的配置
List<PageData> targetAllList = tbIronPlcMapper.listMQTarget();
// 定义一个存储集合用于存储要入库的数据
List<Map<String, Object>> 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));
}
}
// 存储集合中处理好的数据
mesDeviceMonitoringMapper.saveBatchFromMes(dataList);
// 循环遍历所有设备配置
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));
}
}
}
// 存储集合中处理好的数据
if (!dataList.isEmpty()) {
mesDeviceMonitoringMapper.saveBatchFromMes(dataList);
// 将物联网数据存入Redis缓存
redisUtil.set("WMK_DATA_LIST", JSONObject.toJSONString(dataList));
XxlJobHelper.log("成功保存{}条物联网模块数据到本地数据库", dataList.size());
}
}
// 定义一个通用的保存数据的方法
HashMap<String, Object> saveData(String CURRENT_VALUE, String EQUIPMENT_ID, List<PageData> targetAllList, String processingBatchId, String processingTime) {

View File

@ -12,6 +12,8 @@ public interface TbIronPlcMapper {
ArrayList<HashMap<String,String>> listAll ();
List<PageData> listMQTarget();
List<PageData> listTargetByEquId();
List<PageData> listDustDeviceAll();
@ -23,24 +25,12 @@ public interface TbIronPlcMapper {
*/
List<PageData> listRealtimeDataByEquipmentId(String equipmentId);
/**
*
* @param dataList
*/
void insertBatchToRealtime(List<Map<String, Object>> dataList);
/**
*
* @param data
*/
void insertToRealtime(Map<String, Object> data);
/**
* MES
* @param dataList
*/
void updateBatchToRealtime(List<Map<String, Object>> dataList);
/**
* MES
* @param data

View File

@ -32,6 +32,38 @@
p.CORPINFO_ID = '499d43c24fab49f59391ce49fb401837' and p.ISDELETE = 0 and mt.ISDELETE = 0
</select>
<select id="listMQTarget" resultType="com.zcloud.entity.PageData">
SELECT
p.PLC_ID,
p.PLC_NAME,
p.IPCDEVICE_ID,
p.EQUIPMENT_ID,
e.DEVICE_TYPE,
mt.TARGET_NAME,
mt.TARGET_TYPE,
mt.TARGET_PLACE,
mt.TARGET_UNIT,
mt.THRESHOLD_UP_LIMIT,
mt.THRESHOLD_UP_UP_LIMIT,
mt.THRESHOLD_DOWN_LIMIT,
mt.THRESHOLD_DOWN_DOWN_LIMIT,
mt.RANGE_UP,
mt.RANGE_DOWN,
mt.TARGET_DESCRIPTION,
mt.BIT_NO,
mt.SIGNAL_TYPE,
mt.ALARM_VALUE,
mt.TARGET_STATUS,
p.CORPINFO_ID,
mt.REPORT_ID
FROM
tb_iron_plc p
LEFT JOIN tb_iron_equipment_info e on p.EQUIPMENT_ID = e.EQUIPMENT_ID
LEFT JOIN tb_iron_monitoring_target mt on mt.PLC_ID = p.PLC_ID
WHERE
p.CORPINFO_ID = '499d43c24fab49f59391ce49fb401837' and p.ISDELETE = 0 and mt.ISDELETE = 0 and e.DEVICE_TYPE = 'gdsyyhtbjq01'
</select>
<select id="listDustDeviceAll" resultType="com.zcloud.entity.PageData">
SELECT
dds.DEVICE_SENSOR_ID as PLC_ID,
@ -64,7 +96,7 @@
<!-- 查询填报的数据上下限高低值范围 -->
<!-- 查询全部设备填报的数据上下限高低值范围 -->
<select id="listTargetByEquId" resultType="com.zcloud.entity.PageData">
SELECT
p.PLC_ID,