From 0aac30d1c6f1ca0c2bf7662fb9ca4f0d98b3bca7 Mon Sep 17 00:00:00 2001
From: z8018 <1282578289@qq.com>
Date: 星期一, 09 六月 2025 14:29:25 +0800
Subject: [PATCH] Merge branch 'qy0427' of http://115.159.85.185:8098/r/MeiXinLaiRui/ShenSuoGanKongZhi into qy0427

---
 project/后台管理/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs |  354 ++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 229 insertions(+), 125 deletions(-)

diff --git "a/project/\345\220\216\345\217\260\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs" "b/project/\345\220\216\345\217\260\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs"
index e9327e6..d40bdc8 100644
--- "a/project/\345\220\216\345\217\260\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs"
+++ "b/project/\345\220\216\345\217\260\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs"
@@ -36,133 +36,189 @@
         /// <returns></returns>
         public WebResponseContent automation(string extendedState)
         {
+            var messages = new List<string>();
+            //string   message = "";
             try
             {
                 for (int deptId = 1; deptId <= 5; deptId++)
                 {
-                    var devices = GetDevicesByDeptId(deptId);
-                    if (devices == null)
-                    {
-                        Console.WriteLine($"DeptId={deptId} 鏈壘鍒拌澶囷紝璺宠繃");
-                        continue;
-                    }
-
-                    var para = BaseDal.QueryData()
-                        .Where(x => x.Deptid == deptId)
-                        .OrderByDescending(x => x.CreateDate)
-                        .FirstOrDefault();
-
-                    if (para == null)
-                    {
-                        Console.WriteLine($"DeptId={deptId} 鏈壘鍒板弬鏁伴厤缃紝璺宠繃");
-                        continue;
-                    }
-
-                    int ext = (int)para.ExtendSpeed;//宸LC鑷姩浼稿嚭缂╁洖閫熷害
-                    int ret = (int)para.RetractionSpeed;//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害
-                    int liftPosition = (int)para.LeftPosition;//宸︿几鍑轰綅缃�
-                    int rigtpostition = (int)para.RightPosition;//鍙充几鍑轰綅缃�
-
                     try
                     {
-                        var leftorigin = devices.Value.left.Communicator.Read<bool>("M115");//宸lc鍒板師鐐逛綅缃俊鍙�
-                        var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");//鍙硃lc鍒拌揪鍘熺偣浣嶇疆淇″彿
-                        if (leftorigin == true || rightorigin == true)
+                        var devices = GetDevicesByDeptId(deptId);
+                        if (devices == null)
                         {
-                            return new WebResponseContent { Status = false, Message = "宸插埌鍘熷鐐�" };
-                        }
-                    }
-                    catch (Exception)
-                    {
-
-
-                    }
-                    try
-                    {
-                        var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//宸lc鍒拌揪鐩爣浣嶇疆
-                        var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//鍙硃lc鍒拌揪鐩爣浣嶇疆
-                        if (lefttarget == true || righttarget == true)
-                        {
-                            return new WebResponseContent { Status = false, Message = "宸插埌鏈�澶у��" };
+                            messages.Add($"DeptId={deptId} 鏈壘鍒拌澶囷紝璺宠繃");
+                            continue;
                         }
 
-                    }
-                    catch (Exception)
-                    {
+                        var para = BaseDal.QueryData()
+                            .Where(x => x.Deptid == deptId)
+                            .OrderByDescending(x => x.CreateDate)
+                            .FirstOrDefault();
 
-
-                    }
-
-
-                    if (extendedState == "浼稿嚭")
-                    {
-                        try
+                        if (para == null)
                         {
-                            devices.Value.left.Communicator.Write<int>("D1001", ext);//宸LC鑷姩浼稿嚭缂╁洖閫熷害
-                            devices.Value.left.Communicator.Write<bool>("M102", true);//浼稿嚭鎸夐挳
-                            devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//宸︿几鍑轰綅缃�
+                            messages.Add($"DeptId={deptId} 鏈壘鍒板弬鏁伴厤缃紝璺宠繃");
+                            continue;
                         }
-                        catch (Exception)
-                        {
 
-                            
-                        }
+                        int ext = (int)para.ExtendSpeed;
+                        int ret = (int)para.RetractionSpeed;
+                        int liftPos = (int)para.LeftPosition;
+                        int rightPos = (int)para.RightPosition;
+
+                        // 鐙珛鍒ゆ柇宸�/鍙虫槸鍚﹀彲鎵ц
+                        bool canLeft = true, canRight = true;
 
                         try
                         {
-                            devices.Value.right.Communicator.Write<int>("D1001", ret); //鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害
-                            devices.Value.right.Communicator.Write<bool>("M102", true);
-                            devices.Value.right.Communicator.Write<int>("D1002", rigtpostition);//鍙充几鍑轰綅缃�
+                            var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115");//鍒拌揪鍘熺偣
+                            if (leftOrigin)
+                            {
+                                messages.Add($"{deptId}杞ㄩ亾宸LC宸插埌鍘熺偣");
+                                canLeft = false;
+                            }
+
                         }
                         catch (Exception)
-                        {
-
-                            throw;
-                        }
-
-                      
-
-                        Console.WriteLine($"DeptId={deptId} 锛屽乏閫熷害={ext}锛屽彸閫熷害={ret}");
-                    }
-                    else if (extendedState == "缂╁洖")
-                    {
+                        { }
                         try
                         {
-                            devices.Value.left.Communicator.Write<int>("D1001", ext);//缂╁洖閫熷害
-                            devices.Value.left.Communicator.Write<bool>("M103", true);//缂╁洖鎸夐挳
+                            var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115");
+                            if (rightOrigin)
+                            {
+                                messages.Add($"{deptId}杞ㄩ亾鍙砅LC宸插埌鍘熺偣");
+                                canRight = false;
+                            }
                         }
                         catch (Exception)
                         {
-
-                            throw;
                         }
+
 
                         try
                         {
-                            devices.Value.right.Communicator.Write<int>("D1001", ret);
-                            devices.Value.right.Communicator.Write<bool>("M103", true);
+                            var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//宸lc鍒拌揪鐩爣浣嶇疆
+                            if (lefttarget)
+                            {
+                                messages.Add($"{deptId}杞ㄩ亾宸lc鍒拌揪鐩爣浣嶇疆");
+                                canLeft = false;
+                            }
                         }
                         catch (Exception)
                         {
-
-                            throw;
                         }
-                        Console.WriteLine($"DeptId={deptId} 缂╁洖鎿嶄綔锛屽乏閫熷害={ext}锛屽彸閫熷害={ret}");
+                        try
+                        {
+                            var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//鍙硃lc鍒拌揪鐩爣浣嶇疆
+                            if (righttarget)
+                            {
+                                messages.Add($"{deptId}杞ㄩ亾鍙硃lc鍒拌揪鐩爣浣嶇疆");
+                                canRight = false;
+                            }
+
+                        }
+                        catch (Exception)
+                        {
+                        }
+
+                        if (extendedState == "浼稿嚭")
+                        {
+                            if (canLeft)
+                            {
+                                try
+                                {
+                                    devices.Value.left.Communicator.Write<int>("D1001", ext);
+                                    devices.Value.left.Communicator.Write<bool>("M102", true);
+                                    devices.Value.left.Communicator.Write<int>("D1002", liftPos);
+                                }
+                                catch (Exception)
+                                {
+
+                                    
+                                }
+
+                               
+                            }
+
+                            if (canRight)
+                            {
+                                try
+                                {
+
+                                    devices.Value.right.Communicator.Write<int>("D1001", ret);
+                                    devices.Value.right.Communicator.Write<bool>("M102", true);
+                                    devices.Value.right.Communicator.Write<int>("D1002", rightPos);
+                                }
+                                catch (Exception)
+                                {
+
+                                }
+                              
+                            }
+                        }
+                        else if (extendedState == "缂╁洖")
+                        {
+                            if (canLeft)
+                            {
+                                try
+                                {
+                                        devices.Value.left.Communicator.Write<int>("D1001", ext);
+                                        devices.Value.left.Communicator.Write<bool>("M103", true);
+                                    }
+                                catch (Exception)
+                                {
+
+
+                                }
+                               
+                               
+                            }
+
+                            if (canRight)
+                            {
+                                try
+                                {
+                                        devices.Value.right.Communicator.Write<int>("D1001", ret);
+                                        devices.Value.right.Communicator.Write<bool>("M103", true);
+                                    }
+                                catch (Exception)
+                                {
+
+
+                                }
+                            }
+                        }
+                        else
+                        {
+                            return new WebResponseContent { Status = false, Message = "鏈煡鎿嶄綔鍛戒护" };
+                        }
+
+                        
                     }
-                    else
+                    catch (Exception exDept)
                     {
-                        return new WebResponseContent { Status = false, Message = "鏈煡鐨勬搷浣滃懡浠�" };
+                        messages.Add($"DeptId={deptId} 寮傚父锛歿exDept.Message}");
                     }
                 }
 
-                return new WebResponseContent { Status = true, Message = "鍏ㄩ儴璁惧鎿嶄綔瀹屾垚",
+                return new WebResponseContent
+                {
+                    Status = true,
+                    Message = messages.Count == 0 ? "鎵ц鎴愬姛" : "閮ㄥ垎鎵ц澶辫触锛�" + string.Join("锛�", messages),
+                    Data = messages
                 };
             }
             catch (Exception ex)
             {
-                return new WebResponseContent { Status = false, Message = $"鎿嶄綔寮傚父锛歿ex.Message}" };
+                return new WebResponseContent
+                {
+                    Status = false,
+                    Message = $"鑷姩鎺у埗寮傚父锛歿ex.Message}"
+                };
             }
         }
+
 
 
 
@@ -190,60 +246,106 @@
 
                 int ext = (int)para.ManualExtend;//宸LC鎵嬪姩浼稿嚭缂╁洖閫熷害
                 int ret = (int)para.ManualRetraction;//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害
+                int liftPosition = (int)para.LeftPosition;//宸︿几鍑轰綅缃�
+                int rigtpostition = (int)para.RightPosition;//鍙充几鍑轰綅缃�
+                bool canLeft = true,
+                   canRight = true;
+                string message = "";
+
                 try
                 {
-                    var leftorigin = devices.Value.left.Communicator.Read<bool>("M115");//宸lc鍒板師鐐逛綅缃俊鍙�
-                    var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");//鍙硃lc鍒拌揪鍘熺偣浣嶇疆淇″彿
-                    if (leftorigin == true || rightorigin == true)
-                    {
-                        return new WebResponseContent { Status = false, Message = "宸插埌鍘熷鐐�" };
-                    }
-                }
-                catch (Exception)
-                {
+                    var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115");
 
 
-                }
-                try
-                {
-                    var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//宸lc鍒拌揪鐩爣浣嶇疆
-                    var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//鍙硃lc鍒拌揪鐩爣浣嶇疆
-                    if (lefttarget == true || righttarget == true)
+                    if (leftOrigin)
                     {
-                        return new WebResponseContent { Status = false, Message = "宸插埌鏈�澶у��" };
+                        message += "宸LC宸插埌鍘熺偣锛�";
+                        canLeft = false;
                     }
 
                 }
                 catch (Exception)
+                { }
+                try
                 {
-
-
+                    var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115");
+                    if (rightOrigin)
+                    {
+                        message += "鍙砅LC宸插埌鍘熺偣锛�";
+                        canRight = false;
+                    }
+                }
+                catch (Exception)
+                {
                 }
 
+               
+                    try
+                    {
+                        var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//宸lc鍒拌揪鐩爣浣嶇疆
+                        if (lefttarget)
+                        {
+                            message += "宸lc鍒拌揪鐩爣浣嶇疆锛�";
+                            canLeft = false;
+                        }
+                    }
+                    catch (Exception)
+                    {
+                    }
+                    try
+                    {
+                        var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//鍙硃lc鍒拌揪鐩爣浣嶇疆
+                        if (righttarget)
+                        {
+                            message += "鍙硃lc鍒拌揪鐩爣浣嶇疆锛�";
+                            canRight = false;
+                        }
 
-                if (position == "宸�" && ExtendedState == "浼稿嚭")
+                    }
+                    catch (Exception)
+                    {
+                    }
+
+
+                if (canLeft)
                 {
-                    devices.Value.left.Communicator.Write<int>("D1000", ext);//宸LC鎵嬪姩浼稿嚭缂╁洖閫熷害
-                    devices.Value.left.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳
-                    Console.WriteLine($"{position}宸LC鑷姩浼稿嚭缂╁洖閫熷害{ext}");
+                    if (position == "宸�" && ExtendedState == "浼稿嚭")
+                    {
+                        devices.Value.left.Communicator.Write<int>("D1000", ext);//宸LC鎵嬪姩浼稿嚭缂╁洖閫熷害
+                        devices.Value.left.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳
+                        Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級
+                        devices.Value.left.Communicator.Write<bool>("M100", false); // 閲婃斁鎸夐挳
+                        devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//宸︿几鍑轰綅缃�
+                        Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ext}");
+                    }
+                    else if (position == "宸�" && ExtendedState == "缂╁洖")
+                    {
+                        devices.Value.left.Communicator.Write<int>("D1000", ext);//宸LC鎵嬪姩浼稿嚭缂╁洖閫熷害
+                        devices.Value.left.Communicator.Write<bool>("M101", true);
+                        Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級
+                        devices.Value.left.Communicator.Write<bool>("M101", false); // 閲婃斁鎸夐挳
+                        Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄧ缉鍥瀧ext}");
+                    }
                 }
-                else if (position == "宸�" && ExtendedState == "缂╁洖")
+                if (canRight)
                 {
-                    devices.Value.left.Communicator.Write<int>("D1000", ext);//宸LC鎵嬪姩浼稿嚭缂╁洖閫熷害
-                    devices.Value.left.Communicator.Write<bool>("M101", true);
-                    Console.WriteLine($"{position}宸LC鑷姩浼稿嚭缂╁洖閫熷害{ext}");
-                }
-                else if (position == "鍙�" && ExtendedState == "浼稿嚭")
-                {
-                    devices.Value.right.Communicator.Write<int>("D1000", ret);//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害
-                    devices.Value.right.Communicator.Write<bool>("M100", true);
-                    Console.WriteLine($"{position}鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害{ext}");
-                }
-                else if (position == "鍙�" && ExtendedState == "缂╁洖")
-                {
-                    devices.Value.right.Communicator.Write<int>("D1000", ret);//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害
-                    devices.Value.right.Communicator.Write<bool>("M101", true);
-                    Console.WriteLine($"{position}鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害{ret}");
+                    if (position == "鍙�" && ExtendedState == "浼稿嚭")
+                    {
+                        devices.Value.right.Communicator.Write<int>("D1000", ret);//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害
+                        devices.Value.right.Communicator.Write<bool>("M100", true);
+                        Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級
+                        devices.Value.right.Communicator.Write<bool>("M100", false); // 閲婃斁鎸夐挳
+                        devices.Value.right.Communicator.Write<int>("D1002", liftPosition);//宸︿几鍑轰綅缃�
+                        Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ret}");
+                    }
+                    else if (position == "鍙�" && ExtendedState == "缂╁洖")
+                    {
+                        devices.Value.right.Communicator.Write<int>("D1000", ret);//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害
+                        devices.Value.right.Communicator.Write<bool>("M101", true);
+                        Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級
+                        devices.Value.right.Communicator.Write<bool>("M101", false); // 閲婃斁鎸夐挳
+                        Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄧ缉鍥瀧ret}");
+                    }
                 }
 
                 else
@@ -251,11 +353,13 @@
                     return new WebResponseContent { Status = false, Message = "鐘舵�佸弬鏁伴敊璇�" };
                 }
 
-                return new WebResponseContent { Status = true, Message = "鎴愬姛",
+                return new WebResponseContent { Status = true,
+                    Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"鎵ц澶辫触锛歿message}",
                     Data = new
                     {
                         ManualExtend = ext,
-                        ManualRetraction = ret
+                        ManualRetraction = ret,
+                        message
                     }
 
                 };

--
Gitblit v1.9.3