From 3d3598eea1b93ed7f977d077355ebbcc1270ba38 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期日, 02 十一月 2025 12:17:33 +0800
Subject: [PATCH] 优化
---
新建文件夹/WIDESEA_WMSServer/ClassLibrary2/EquipmentAlarmInforService.cs | 182 --------------------------------------------
1 files changed, 3 insertions(+), 179 deletions(-)
diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/EquipmentAlarmInforService.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/EquipmentAlarmInforService.cs"
index 7d61267..397a3bc 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/EquipmentAlarmInforService.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/ClassLibrary2/EquipmentAlarmInforService.cs"
@@ -76,7 +76,7 @@
}
if (string.Equals(item.status, nameof(DeviceStatus.Error), StringComparison.OrdinalIgnoreCase))
{
- _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, item.robotName, item.status);
+ _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm,"灏忚溅缂栧彿"+ item.robotCode, item.status);
}
}
foreach (var item in response.data.sorters)
@@ -103,7 +103,7 @@
}
if (string.Equals(item.status, nameof(DeviceStatus.Error), StringComparison.OrdinalIgnoreCase))
{
- _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, item.sorterCode, item.status);
+ _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, "鍒嗘嫞鍙板悕瀛�"+ item.sorterCode, item.status);
}
}
if (equipmentAlarmInforsAdd.Count > 0) BaseDal.AddData(equipmentAlarmInforsAdd);
@@ -116,182 +116,6 @@
return content;
}
- /// <summary>
- /// 鏌ョ湅绔嬪簱灏忚溅鎶ヨ淇℃伅
- /// </summary>
- /// <returns></returns>
- public WebResponseContent getDeviceStatus1()
- {
- try
- {
- var url = "http://172.16.1.2:8080/cube/taskInfo/getDeviceStatus?token=wH5zdAUCv2BEHJIinmowyki8cdc5ge8fAwFDcYZs0bVldNgmORt0O0l4GJTDv1dglRdMxb9xDK5Qb3NJAqL1Li2GkfdVa3KnIkfrQZtsP7UXhMmUz6xEuztG6d5svAJO9HENLb8JWVqCfpO2EWV6ebo/g5tJ9x7kbwwAxvCBrWdiEJv09FvaRQ== ";
- var result = HttpHelper.Get(url);
- var response = JsonConvert.DeserializeObject<AGVResponse<DeviceStatusData>>(result);
-
- // 妫�鏌ユ帴鍙e搷搴旀槸鍚︽垚鍔�
- if (response == null || response.code != "0")
- {
- return new WebResponseContent { Status = false, Message = $"WCS鎺ュ彛璋冪敤澶辫触: {response?.msg}" };
- }
-
- var syncTime = DateTime.Now;
- var AddEquipList = new List<Dt_EquipmentAlarmInfor>();
- var UpdateEquipList = new List<Dt_EquipmentAlarmInfor>();
- var alarmList = new List<(string deviceType, string deviceName, string deviceCode)>();
-
- // 鏀堕泦鎵�鏈夎澶囩紪鐮侊紝涓�娆℃�ф煡璇�
- var allDeviceCodes = new List<string>();
- if (response.data?.robot != null && response.data.robot.Count > 0)
- {
- allDeviceCodes.AddRange(response.data.robot.Select(x => x.robotCode));
- }
- if (response.data?.sorters != null && response.data.sorters.Count > 0)
- {
- allDeviceCodes.AddRange(response.data.sorters.Select(x => x.sorterCode));
- }
-
- // 涓�娆℃�ф煡璇㈡墍鏈夊凡瀛樺湪鐨勮澶囪褰�
- var existingRecords = allDeviceCodes.Any()
- ? BaseDal.QueryData(x => allDeviceCodes.Contains(x.RobotCode))
- .ToDictionary(x => x.RobotCode, x => x)
- : new Dictionary<string, Dt_EquipmentAlarmInfor>();
-
- // 澶勭悊鏈哄櫒浜鸿澶囨暟鎹�
- if (response.data?.robot != null && response.data.robot.Count > 0)
- {
- foreach (var robot in response.data.robot)
- {
- ProcessDevice(robot.robotCode, robot.robotName, robot.status, "鏈哄櫒浜�",
- existingRecords, AddEquipList, UpdateEquipList, alarmList, syncTime);
- }
- }
-
- // 澶勭悊鍒嗘嫞鍙拌澶囨暟鎹�
- if (response.data?.sorters != null && response.data.sorters.Count > 0)
- {
- foreach (var sorter in response.data.sorters)
- {
- ProcessDevice(sorter.sorterCode, sorter.sorterName, sorter.status, "鍒嗘嫞鍙�",
- existingRecords, AddEquipList, UpdateEquipList, alarmList, syncTime);
- }
- }
-
- // 寮�鍚簨鍔�
- //_unitOfWorkManage.BeginTran();
- try
- {
- // 鎵归噺鎿嶄綔
- if (AddEquipList.Count > 0)
- {
- BaseDal.AddData(AddEquipList);
- }
- if (UpdateEquipList.Count > 0)
- {
- BaseDal.UpdateData(UpdateEquipList);
- }
-
- // 鎻愪氦浜嬪姟
- //_unitOfWorkManage.CommitTran();
-
- // 澶勭悊鎶ヨ淇℃伅
- ProcessAlarmMessages(alarmList);
-
- var totalCount = AddEquipList.Count + UpdateEquipList.Count;
- return new WebResponseContent
- {
- Status = true,
- Message = $"鍚屾鎴愬姛锛屾柊澧� {AddEquipList.Count} 鏉★紝鏇存柊 {UpdateEquipList.Count} 鏉★紝鍏卞鐞� {totalCount} 鏉¤澶囪褰曘��"
- };
- }
- catch (Exception ex)
- {
- //_unitOfWorkManage.RollbackTran();
- return new WebResponseContent
- {
- Status = false,
- Message = $"鏁版嵁淇濆瓨澶辫触: {ex.Message}"
- };
- }
- }
- catch (Exception ex)
- {
- return new WebResponseContent
- {
- Status = false,
- Message = $"鑾峰彇璁惧鐘舵�佸け璐�: {ex.Message}"
- };
- }
- }
-
- /// <summary>
- /// 澶勭悊鍗曚釜璁惧璁板綍
- /// </summary>
- private void ProcessDevice(string deviceCode, string deviceName, string status, string deviceType,
- Dictionary<string, Dt_EquipmentAlarmInfor> existingRecords,
- List<Dt_EquipmentAlarmInfor> addList,
- List<Dt_EquipmentAlarmInfor> updateList,
- List<(string deviceType, string deviceName, string deviceCode)> alarmList,
- DateTime syncTime)
- {
- if (existingRecords.TryGetValue(deviceCode, out var existingRecord))
- {
- // 妫�鏌ョ姸鎬佹槸鍚﹀彂鐢熷彉鍖栵紝閬垮厤涓嶅繀瑕佺殑鏇存柊鍜岄噸澶嶆姤璀�
- bool statusChanged = existingRecord.Status != status;
-
- // 鏇存柊鐜版湁璁板綍
- existingRecord.RobotName = deviceName;
- existingRecord.Status = status;
- existingRecord.SyncTime = syncTime;
- existingRecord.ModifyDate = syncTime;
- existingRecord.Modifier = "System";
-
- updateList.Add(existingRecord);
-
- // 鍙湁鐘舵�佸彉涓篹rror鏃舵墠鎶ヨ
- if (statusChanged && status == "error")
- {
- alarmList.Add((deviceType, deviceName, deviceCode));
- }
- }
- else
- {
- // 鍒涘缓鏂拌褰�
- var newRecord = new Dt_EquipmentAlarmInfor
- {
- RobotName = deviceName,
- RobotCode = deviceCode,
- Status = status,
- SyncTime = syncTime,
- CreateDate = syncTime,
- Creater = "System"
- };
- addList.Add(newRecord);
-
- // 鏂拌澶囩姸鎬佷负error鏃舵姤璀�
- if (status == "error")
- {
- alarmList.Add((deviceType, deviceName, deviceCode));
- }
- }
- }
-
- /// <summary>
- /// 澶勭悊鎶ヨ淇℃伅
- /// </summary>
- private void ProcessAlarmMessages(List<(string deviceType, string deviceName, string deviceCode)> alarmList)
- {
- foreach (var alarm in alarmList)
- {
- string alarmTitle = alarm.deviceType == "鏈哄櫒浜�"
- ? "灏忚溅鍚嶇О:" + alarm.deviceName
- : "鍒嗘嫞鍙板悕绉�:" + alarm.deviceName;
-
- string alarmMessage = alarm.deviceType == "鏈哄櫒浜�"
- ? $"灏忚溅缂栧彿銆恵alarm.deviceCode}銆戝彂鐢熼敊璇�"
- : $"缂栧彿銆恵alarm.deviceCode}銆戝彂鐢熼敊璇�";
-
- _messageInfoService.AddMessageInfo(MessageGroupByEnum.EquipmentAlarm, alarmTitle, alarmMessage, MessageStatusEnum.Emergency);
- }
- }
+
}
}
\ No newline at end of file
--
Gitblit v1.9.3