From bfc11f87e2b64420c9917c0b9881b3e327d6f796 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期二, 04 十一月 2025 22:19:59 +0800
Subject: [PATCH] 优化调拨出入库

---
 新建文件夹/WIDESEA_WMSServer/ClassLibrary2/EquipmentAlarmInforService.cs |  181 --------------------------------------------
 1 files changed, 3 insertions(+), 178 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..7949385 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"
@@ -50,6 +50,7 @@
 
                 if (codes.Count < 1) return content;
                 List<Dt_EquipmentAlarmInfor> equipmentAlarmInfors = BaseDal.QueryData(x => codes.Contains(x.RobotCode));
+                if (equipmentAlarmInfors.Count < 1) return content;
                 List<Dt_EquipmentAlarmInfor> equipmentAlarmInforsAdd = new List<Dt_EquipmentAlarmInfor>();
                 List<Dt_EquipmentAlarmInfor> equipmentAlarmInforsUp = new List<Dt_EquipmentAlarmInfor>();
                 foreach (var item in response.data.robot)
@@ -76,7 +77,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 +104,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 +117,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