From ac93c4092a21dbf0fa9cf8b9b1302f2d5d183f61 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期一, 09 六月 2025 20:48:20 +0800
Subject: [PATCH] 修改提示字段

---
 project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs |  428 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 398 insertions(+), 30 deletions(-)

diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
index 45cd188..4382f87 100644
--- a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
+++ b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
@@ -5,14 +5,17 @@
 using System.Text;
 using System.Threading.Tasks;
 using AutoMapper;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using SqlSugar;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseRepository;
 using WIDESEAWCS_Core.BaseServices;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.Telescopic;
 using WIDESEAWCS_ITelescopicService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using static WIDESEAWCS_Common.Face.TH_Faces;
 
 
 namespace WIDESEAWCS_TelescopicService
@@ -35,6 +38,7 @@
         /// <returns></returns>
         public WebResponseContent automation(string ExtendedState)
         {
+            
             try
             {
 
@@ -46,35 +50,128 @@
                 var devices = GetDevicesByDeptId(deid);
 
                 //鎵惧埌Dt_Parameters涓殑鏈�鏂颁竴鏉℃暟鎹�
-                var para = BaseDal.QueryData().Where(x=>x.Deptid== deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
+                var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                 if (para == null)
                     return new WebResponseContent { Status = false, Message = "鏈壘鍒板弬鏁伴厤缃�" };
 
-                int ext = (int)para.ExtendSpeed;
-                int ret = (int)para.RetractionSpeed;
+                int ext = (int)para.ExtendSpeed;//宸LC鑷姩浼稿嚭缂╁洖閫熷害
+                int ret = (int)para.RetractionSpeed;//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害
+                int liftPosition = (int)para.LeftPosition;//宸︿几鍑轰綅缃�
+                int rigtpostition = (int)para.RightPosition;//鍙充几鍑轰綅缃�
+                string message = "";
+
+                try
+                {
+                    if (devices.Value.left.Communicator.Read<bool>("M117"))
+                    {
+                        
+                        return new WebResponseContent { Status = true, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
+                    }
+                    
+                }
+                catch (Exception)
+                {
+                }
+                try
+                {
+                    if (devices.Value.right.Communicator.Read<bool>("M117"))
+                    {
+                        return new WebResponseContent { Status = true, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
+                    }
+                    
+                }
+                catch (Exception)
+                {
+                }
 
                 if (ExtendedState == "浼稿嚭")
                 {
-                    devices.Value.left.Communicator.Write<int>("D500", ext);//浼稿嚭閫熷害
-                    devices.Value.left.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳
-                    devices.Value.right.Communicator.Write<int>("D500", ext);//浼稿嚭閫熷害
-                    devices.Value.right.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳
-                    Console.WriteLine($"鑷姩浼哥缉鏉嗕几鍑� {ext}");
+                   
+                        try
+                        {
+                        if (devices.Value.left.Communicator.Read<float>("D80")>= liftPosition-5)//鍒拌揪鏈�澶т綅缃�)
+                        {
+                            message += "宸︿几缂╂潌鍒拌揪鐩爣浣嶇疆锛�";
+                        }
+                        else
+                        {
+                            devices.Value.left.Communicator.Write<int>("D1022", liftPosition);//浼稿嚭浣嶇疆
+                            devices.Value.left.Communicator.Write<int>("D1002", ext);//宸LC鑷姩鍔ㄤ几鍑虹缉鍥為�熷害
+                            devices.Value.left.Communicator.Write<bool>("M102", true);//浼稿嚭鎸夐挳
+                            
+                        } 
+                        }
+                        catch { }
+                
+                        try
+                        {
+                        if (devices.Value.right.Communicator.Read<float>("D80") >= rigtpostition-5)
+                        {
+                            message += "鍙充几缂╂潌鍒拌揪鐩爣浣嶇疆锛�";
+                        }
+                        else
+                        {
+                            devices.Value.right.Communicator.Write<int>("D1022", rigtpostition);
+                            devices.Value.right.Communicator.Write<int>("D1002", ret);
+                            devices.Value.right.Communicator.Write<bool>("M102", true);
+                            
+                        }                        }
+                        catch { }
+                    
                 }
                 else if (ExtendedState == "缂╁洖")
                 {
-                    devices.Value.left.Communicator.Write<int>("D501", ext);//浼稿嚭閫熷害
-                    devices.Value.left.Communicator.Write<bool>("M101", true);//浼稿嚭鎸夐挳
-                    devices.Value.right.Communicator.Write<int>("D501", ext);//浼稿嚭閫熷害
-                    devices.Value.right.Communicator.Write<bool>("M101", true);//浼稿嚭鎸夐挳
-                    Console.WriteLine($"鑷姩浼哥缉鏉嗙缉鍥� {ret}");
+                    
+                        try
+                        {
+                        if (devices.Value.left.Communicator.Read<bool>("M115")) //鍒拌揪鍘熺偣浣�
+                        {
+                            message += "宸︿几缂╂潌宸插埌鍘熺偣锛�";
+                        }
+                        else
+                        {
+                            devices.Value.left.Communicator.Write<int>("D1022", liftPosition);
+                            devices.Value.left.Communicator.Write<int>("D1002", ext);//宸LC鑷姩浼�=缂╁洖鍑虹缉鍥為�熷害
+                            devices.Value.left.Communicator.Write<bool>("M103", true);//宸lc缂╁洖鎸夐挳
+                            
+                            
+                        }                           
+                    }
+                        catch { }
+
+                   
+                        try
+                        {
+                        if (devices.Value.right.Communicator.Read<bool>("M115"))
+                        {
+                            message += "鍙充几缂╂潌宸插埌鍘熺偣锛�";
+                        }
+                        else
+                        {
+                            devices.Value.right.Communicator.Write<int>("D1022", rigtpostition);
+                            devices.Value.right.Communicator.Write<int>("D1002", ret);
+                            devices.Value.right.Communicator.Write<bool>("M103", true);
+                            
+
+                        }
+                          
+                          
+                        }
+                        catch { }
+                    
                 }
                 else
                 {
                     return new WebResponseContent { Status = false, Message = "鏈煡鐨勬搷浣滃懡浠�" };
                 }
 
-                return new WebResponseContent { Status = true, Message = "鎴愬姛" };
+                return new WebResponseContent
+                {
+                    Status = true,
+                    Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"{message}",
+                    Data = new { ExtendSpeed = ext, RetractionSpeed = ret,liftweiz= liftPosition,rightweiz= rigtpostition }
+                };
+
             }
             catch (Exception ex)
             {
@@ -106,40 +203,304 @@
                 //淇╀釜plc宸﹀彸鍚勪竴涓�
                 //OtherDevice liftotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG001");
                 //OtherDevice rightotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG002");
+
                 //鎵惧埌Dt_Parameters涓殑鏈�鏂颁竴鏉℃暟鎹牴鎹綋鍓嶇殑deid
                 var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
-                int ext = (int)para.ManualExtend;//鎵嬪姩浼稿嚭閫熷害
-                int ret = (int)para.ManualRetraction;//鎵嬪姩缂╁洖閫熷害
+                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
+                {
+                    if (devices.Value.left.Communicator.Read<bool>("M117")) //榛樿鏄痜lase 
+                    {
+
+                        return new WebResponseContent { Status = true, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
+                    }
+
+                }
+                catch (Exception)
+                {
+                }
+                try
+                {
+                    if (devices.Value.right.Communicator.Read<bool>("M117"))
+                    {
+                        return new WebResponseContent { Status = true, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
+                    }
+
+                }
+                catch (Exception)
+                {
+                }
                 if (position == "宸�" && ExtendedState == "浼稿嚭")
                 {
-                    devices.Value.left.Communicator.Write<int>("D500", ext);//浼稿嚭閫熷害
-                    devices.Value.left.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳
-                    Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ext}");
+                    if (devices.Value.left.Communicator.Read<float>("D80") >= liftPosition - 5) //鍒拌揪鐩爣浣嶇疆
+                    {
+                        message += "宸︿几缂╂潌鍒拌揪鐩爣浣嶇疆锛�";
+                    }
+                    else
+                    {
+                        devices.Value.left.Communicator.Write<int>("D1004", liftPosition);//宸︿几鍑轰綅缃�
+                        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); // 閲婃斁鎸夐挳
+                        
+
+                        Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ext}");
+                    }
+
                 }
                 else if (position == "宸�" && ExtendedState == "缂╁洖")
                 {
-                    devices.Value.left.Communicator.Write<int>("D501", ret);//缂╁洖閫熷害
-                    devices.Value.left.Communicator.Write<bool>("M101", true);
-                    Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄧ缉鍥瀧ret}");
+                    if (devices.Value.left.Communicator.Read<bool>("M115"))//缂╁洖鐨勬椂鍊欏垽鏂�) 
+                    {
+                        message += "宸︿几缂╂潌宸插埌鍘熺偣锛�";
+                    }
+                    else
+                    {
+                        devices.Value.left.Communicator.Write<int>("D1004", liftPosition);//浼稿嚭浣嶇疆
+                        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 (position == "鍙�" && ExtendedState == "浼稿嚭")
                 {
-                    devices.Value.right.Communicator.Write<int>("D500", ext);
-                    devices.Value.right.Communicator.Write<bool>("M100", true);
-                    Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ext}");
+                    if (devices.Value.right.Communicator.Read<float>("D80") >= rigtpostition - 5)
+                    {
+                        message += "鍙充几缂╂潌鍒拌揪鐩爣浣嶇疆锛�";
+                    }
+                    else
+                    {
+                        devices.Value.right.Communicator.Write<int>("D1004", rigtpostition);//鍙充几鍑轰綅缃�
+                        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); // 閲婃斁鎸夐挳
+                        Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ret}");
+                    }
+
+
                 }
                 else if (position == "鍙�" && ExtendedState == "缂╁洖")
                 {
-                    devices.Value.right.Communicator.Write<int>("D501", ret);
-                    devices.Value.right.Communicator.Write<bool>("M101", true);
-                    Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄧ缉鍥瀧ret}");
+                    if (devices.Value.right.Communicator.Read<bool>("M115"))
+                    {
+                        message += "鍙充几缂╂潌宸插埌鍘熺偣锛�";
+                    }
+                    else
+                    {
+                        devices.Value.right.Communicator.Write<int>("D1004", rigtpostition);//浼稿嚭浣嶇疆
+                        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}");
+                    }
+
                 }
-                return new WebResponseContent { Status = true, Message = "鎴愬姛" };
+               
+
+
+                return new WebResponseContent
+                {
+                    Status = true,
+                    Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"{message}",
+                    Data = new
+                    {
+                        ManualExtend = ext,
+                        ManualRetraction = ret,
+                        message
+                    }
+                };
             }
+
+
             catch (Exception ex)
             {
                 return new WebResponseContent { Status = false, Message = ex.Message };
 
+            }
+
+        }
+
+
+        /// <summary>
+        /// 鏍规嵁鐢ㄦ埛娣诲姞閫熷害
+        /// </summary>
+        /// <param name="entity"></param>
+        /// <returns></returns>
+        public  WebResponseContent AddSpeed(SpeedDTO entity)
+        {
+            try
+            {
+                // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛
+                var user = _user.QueryData(x => x.UserName == entity.account).FirstOrDefault();
+               // 鍒ゆ柇锛氬鏋滀笉鏄鐞嗗憳 && Dept_Id 涓虹┖锛屽垯鎻愮ず閿欒
+                if (user.UserName != "admin" && user.Dept_Id == null)
+                {
+                    return new WebResponseContent { Status = false, Message = "浣犵殑璐﹀彿娌℃湁璁剧疆杞ㄩ亾绔欏彿锛屾棤娉曟坊鍔狅紝璇疯仈绯荤鐞嗗憳" };
+                }
+               
+                var dept = user.Dept_Id;
+
+                //  鑾峰彇閰嶇疆鏂囦欢涓殑 DepartmentID锛堢鐞嗗憳涓撶敤锛�
+                if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+                {
+                    return new WebResponseContent
+                    {
+                        Status = false,
+                        Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�"
+                    };
+                }
+
+
+                // 鍒ゆ柇鏄惁涓虹鐞嗗憳璐﹀彿
+                bool isAdmin = user?.UserName?.Equals("admin") == true; //濡傛灉褰撳墠鐢ㄦ埛涓嶄负绌猴紝涓旂敤鎴峰悕鏄� "admin"锛屽氨璁や负杩欎釜鐢ㄦ埛鏄鐞嗗憳
+
+                // 鏍规嵁鏄惁鏄鐞嗗憳鍐冲畾浣跨敤鍝釜 Deptid
+                var parmet = new Dt_Parameters
+                {
+                    ExtendSpeed = entity.ExtendSpeed,
+                    RetractionSpeed = entity.RetractionSpeed,
+                    ManualExtend = entity.ManualExtend,
+                    ManualRetraction = entity.ManualRetraction,
+                    LeftPosition = entity.LeftPosition,
+                    RightPosition = entity.RightPosition,   
+                    Deptid = isAdmin ? deid : dept.GetValueOrDefault()//濡傛灉褰撳墠鐢ㄦ埛鏄鐞嗗憳锛屽氨鐢ㄩ厤缃枃浠朵腑鐨� DepartmentID锛屽惁鍒欑敤浼犲叆鐨� entity 鍙傛暟涓殑 Deptid
+                };
+                // 娣诲姞鏁版嵁
+                AddData(parmet);
+
+
+                return new WebResponseContent
+                {
+                    Status = true,
+                    Message = "娣诲姞鎴愬姛",
+                    Data = parmet
+                };
+            }
+            catch (Exception ex)
+            {
+
+                return new WebResponseContent { Status = false, Message = ex.Message };
+            }
+        }
+
+
+        /// <summary>
+        ///褰撹嚜鍔ㄤ几鍑洪渶瑕佹殏鍋滄椂锛屾殏鍋滄寜閽�
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent PauseButton()
+        {
+            try
+            {
+                //鏍规嵁int.TryParse(AppSettings.Get("DepartmentID")璇诲彇鍒板綋鍓嶆槸杞ㄩ亾鍑狅紝鎵�鏈変汉閮藉彧鑳芥搷浣滃綋鍓�
+                if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+                {
+                    return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+                };
+                var devices = GetDevicesByDeptId(deid);
+                try
+                {
+                    devices.Value.left.Communicator.Write<bool>("M104", true);
+                }
+                catch (Exception)
+                {
+
+                  
+                }
+                try
+                {
+                    devices.Value.right.Communicator.Write<bool>("M104", true);
+                }
+                catch (Exception)
+                {
+
+                   
+                }
+               
+                
+                return new WebResponseContent { Status =true,Message="鏆傚仠鎴愬姛",Data = devices};
+            }
+            catch (Exception ex)
+            {
+
+                return new WebResponseContent { Status = false, Message = ex.Message };
+            }
+        }
+
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠绋嬪簭鏈�鏂扮殑浼哥缉鏉嗛�熷害
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent BackfillSpeed()
+        {
+            try
+            {
+                if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+                {
+                    return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+
+                }
+                var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
+                if (para == null)
+                {
+                    return new WebResponseContent { Message = "浣犺繕娌℃湁閰嶇疆閫熷害" };
+                }
+                return new WebResponseContent { Status = true, Data = para };
+            }
+            catch (Exception ex)
+            {
+
+                return new WebResponseContent { Status = false, Message = ex.Message };
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠浼哥缉鏉嗙殑浣嶇疆(鑷姩)
+        /// </summary>
+        /// <param name="ExtendedState"></param>
+        /// <returns></returns>
+        public WebResponseContent CurrentLocation()
+        {
+            try
+            {
+                if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+                {
+                    return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+
+                }
+                var devices = GetDevicesByDeptId(deid);
+                
+            
+                    var deviceslift = devices.Value.left.Communicator.Read<float>("D80");
+                    var devicesright = devices.Value.right.Communicator.Read<float>("D80");
+                    Console.WriteLine($"褰撳墠宸﹀彸浼哥缉鏉嗚繑鍥為�熷害鍒嗗埆涓轰负{deviceslift}");
+             
+
+                return new WebResponseContent
+                {
+                    Status = true,
+                    Data = new { lift = deviceslift, Right = devicesright }
+                };
+                }
+            catch (Exception ex)
+            {
+
+                return new WebResponseContent { Status = false, Message = ex.Message };
             }
         }
 
@@ -165,6 +526,13 @@
             return (left, right);
         }
 
+
+
+
+
+
+
+
     }
 
 }

--
Gitblit v1.9.3