From 9f3858dd723a69c56dbab909e0c7e6c5ef8b85a8 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期一, 09 六月 2025 20:27:19 +0800
Subject: [PATCH] 修改plc信息,以及进入检修接口

---
 project/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITelescopicService/IMaintenanceService.cs              |    4 
 project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs                |   97 ++++---
 project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/MaintenanceController.cs |    9 
 project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs                 |  241 ++++++++++---------
 project/后台管理/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs                |  314 ++++++++++++-------------
 5 files changed, 331 insertions(+), 334 deletions(-)

diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITelescopicService/IMaintenanceService.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITelescopicService/IMaintenanceService.cs
index eb8ae10..d8acad0 100644
--- a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITelescopicService/IMaintenanceService.cs
+++ b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_ITelescopicService/IMaintenanceService.cs
@@ -29,11 +29,11 @@
         WebResponseContent PersonnelMonitoring(PaginationDTO pagination);
 
         /// <summary>
-        /// 鏇存敼鐘舵�侊紝杩愯杩涘叆妫�淇�
+        /// 鏇存敼鐘舵�侊紝寮哄埗涓嬬嚎
         /// </summary>
         /// <param name="id"></param>
         /// <returns></returns>
-        WebResponseContent RunOperation(int id,string  ispossible);
+        WebResponseContent RunOperation(int id, string LocalIP);
 
         WebResponseContent ChangeTasState(int id);
 
diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/MaintenanceController.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/MaintenanceController.cs
index 1a89567..06a69fe 100644
--- a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/MaintenanceController.cs
+++ b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Telescopic/MaintenanceController.cs
@@ -44,15 +44,16 @@
 
 
         /// <summary>
-        /// 鏇存敼鐘舵�侊紝杩愯杩涘叆妫�淇�
+        /// 鏇存敼鐘舵�侊紝寮哄埗涓嬬嚎
         /// </summary>
         /// <param name="id"></param>
         /// <returns></returns>
         [HttpPost, Route("RunOperation"), AllowAnonymous]
-        public WebResponseContent RunOperation(int id, string ispossible)
+        public WebResponseContent RunOperation(int id, string LocalIP)
         {
-            //
-            return Service.RunOperation(id, ispossible);
+            var userIp = HttpContext.GetUserIp();//鐢ㄦ埛鐢佃剳ip
+            var reslut = userIp.Replace("::ffff:", " ");
+            return Service.RunOperation(id, LocalIP);
         }
 
         /// <summary>
diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs
index 0454faa..a99fa9d 100644
--- a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs
+++ b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs
@@ -148,6 +148,7 @@
                         a.UserTrueName,
                         a.Userteam,//鐝粍
                         a.Unit,//鍗曚綅
+                        b.ID,//id
                         b.MaintenanceStatus,//妫�淇姸鎬�
                         b.CreateDate,//鏃ユ湡
                         b.MaintenancStartTime,//寮�濮嬫椂闂�
@@ -177,43 +178,38 @@
 
 
         /// <summary>
-        /// 鏇存柊鐘舵�佹槸鍚﹀厑璁歌繘鍏ユ淇紙娣诲姞浜嗘淇褰曪級
+        /// 鏇存柊鐘舵�佸己鍒朵笅绾匡紙娣诲姞浜嗘淇褰曪級
         /// </summary>
         /// <param name="id"></param>
         /// <param name="ispossible"></param>
         /// <returns></returns>
-        public WebResponseContent RunOperation(int id, string  ispossible)
+        public WebResponseContent RunOperation(int id,string LocalIP)
         {
             try
             {
-                var mon = BaseDal.QueryFirst(x => x.ID == id);
-                if (mon == null)
+                var user = BaseDal.QueryData();//妫�淇〃
+                
+                var maint = user.Where(x => x.ID == id).FirstOrDefault(); //鍦ㄦ淇〃涓厛鎵惧埌璇ョ敤鎴�
+                var sysuer = _user.QueryData(x => x.UserName == maint.UserAccount).FirstOrDefault();
+                if (maint == null ||sysuer==null)
                 {
-                    return new WebResponseContent { Status = false, Message = "鏃犳硶鏇存敼锛屾病鏈夋壘鍒拌鐢ㄦ埛" };
+                    return new WebResponseContent { Status = false, Message = "娌℃湁鎵惧埌璇ョ敤鎴�" };
                 }
-                var sysuer = _user.QueryData(x => x.UserName == mon.UserAccount).FirstOrDefault();
-                if (ispossible == "true")
+                 maint.MaintenanceStatus = 0;//鏀瑰彉鐘舵�佸己鍒朵笅绾�
+                BaseDal.UpdateData(maint);
+                                            //鎻掑叆璁板綍琛�
+                var recording = new Dt_MaintenanceTeam  //娣诲姞璁板綍
                 {
-                    mon.IsPossible = "true";
-                    mon.MaintenanceDate = DateTime.Now;
-                    BaseDal.UpdateData(mon);
-                    var recording = new Dt_MaintenanceTeam  //娣诲姞璁板綍
-                    {
-                        OperatorName = sysuer.UserTrueName,
-                        TeamName = sysuer.RoleName,
-                        DistributionTime = DateTime.Now,
-                        Creater = "admin",
-                        CreateDate = DateTime.Now,
+                    Account = maint.UserAccount,
+                    MaintenanceStatus = 0,
+                    OperatorName = sysuer.UserTrueName,
+                    TeamName = sysuer.RoleName,
+                    DistributionTime = DateTime.Now,
+                    IPAddress = LocalIP,
+                };
+                _team.AddData(recording);
 
-                    };
-                    _team.AddData(recording);
-                }
-                else
-                {
-                    mon.IsPossible = "false";
-                    BaseDal.UpdateData(mon);
-                }
-                return new WebResponseContent { Status = true, Data = mon };
+                return new WebResponseContent { Status = true,Message="寮哄埗涓嬬嚎鎴愬姛", Data = recording };
             }
             catch (Exception ex)
             {
@@ -606,19 +602,19 @@
             }
         }
 
-
         /// <summary>
         /// 缁撴潫妫�淇�
-        /// </summary>MaintenanceStatus 0浠h〃妫�淇畬鎴�  1浠h〃妫�淇腑
+        /// </summary>
         /// <param name="account"></param>
         /// <returns></returns>
         public WebResponseContent StopMaintenanceTask(string account)
         {
             try
             {
-                var user = BaseDal.QueryData();//妫�淇〃
+                var user = BaseDal.QueryData(); // 妫�淇〃
                 var maint = user.Where(x => x.UserAccount == account).FirstOrDefault();
-                var sysuer = _user.QueryData(x => x.UserName == account).FirstOrDefault();//鐢ㄦ埛琛�
+                var sysuer = _user.QueryData(x => x.UserName == account).FirstOrDefault(); // 鐢ㄦ埛琛�
+
                 if (maint == null || sysuer == null)
                 {
                     return new WebResponseContent { Status = false, Message = "娌℃湁鎵惧埌璇ョ敤鎴�" };
@@ -626,33 +622,46 @@
 
                 // 鏌ユ壘璇ョ敤鎴峰湪 _team 琛ㄤ腑鐨勬渶鏂颁竴鏉¤褰�
                 var lastRecord = _team.QueryData(x => x.Account == account)
-                                      .OrderByDescending(x => x.CreateDate)
-                                      .FirstOrDefault();
+                                    .OrderByDescending(x => x.CreateDate)
+                                    .FirstOrDefault();
 
                 if (lastRecord == null || lastRecord.MaintenanceStatus != 1)
                 {
                     return new WebResponseContent { Status = false, Message = "浣犺繕娌℃湁寮�濮嬫淇紝璇峰厛鐐瑰嚮寮�濮嬫淇�" };
                 }
 
-                if (maint.IsLeader == 1)//濡傛灉璇ョ敤鎴锋槸鐝暱锛岄偅涔堣绛夊叏閮ㄤ汉閮芥淇畬鎴愶紝浠栨墠鍙互缁撴潫妫�淇�
+                // 妫�鏌ユ槸鍚﹁嚦灏戞湁涓�涓粍闀垮湪鍦�
+                var activeLeaders = user.Where(x => x.IsLeader == 1 && x.MaintenanceStatus == 1).ToList();
+
+                // 濡傛灉褰撳墠鐢ㄦ埛鏄粍闀�
+                if (maint.IsLeader == 1)
                 {
-                    //鍏堟煡鎵炬墍鏈夌敤鎴风殑缁勬槸閭d釜缁勭殑锛岀粍鍛樼姸鎬佹湁涓�涓笉鏄�1               
-                    // 鏌ユ壘鍚岀粍鏈畬鎴愮殑缁勫憳锛圛sLeader=0 && MaintenanceStatus=1锛�
-                    var hasUnfinishedMembers = user.Where(x =>x.IsLeader == 0 &&x.MaintenanceStatus == 1).ToList(); //锛欰ny()鏈変竴涓弧瓒冲氨杩斿洖true琛ㄧず瀛樺湪婊¤冻鏉′欢鐨勮褰�
-                    if (hasUnfinishedMembers.Count>0)
+                    // 濡傛灉鏄渶鍚庝竴涓湪鍦虹殑缁勯暱
+                    if (activeLeaders.Count == 1 && activeLeaders[0].UserAccount == account)
                     {
-                        return new WebResponseContent { Status = false, Message = "杩樻湁缁勫憳鏈畬鎴愬綋鍓嶆壒娆℃淇�" };
+                        // 妫�鏌ユ槸鍚﹁繕鏈夋湭瀹屾垚鐨勭粍鍛�
+                        var unfinishedMembers = user.Where(x => x.IsLeader == 0 && x.MaintenanceStatus == 1).Any();
+                        if (unfinishedMembers)
+                        {
+                            return new WebResponseContent
+                            {
+                                Status = false,
+                                Message = "鎮ㄦ槸鏈�鍚庝竴涓湪鍦虹殑缁勯暱锛岃绛夊緟鎵�鏈夌粍鍛樺畬鎴愭淇悗鍐嶇粨鏉�"
+                            };
+                        }
                     }
                 }
-                //濡傛灉婊¤冻涓嬮潰鐨勬潯浠跺氨寮�濮�
-                maint.MaintenancEendTime = DateTime.Now;//璁板綍缁撴潫鏃堕棿
-                maint.MaintenanceStatus = 0;//鏇存敼鐘舵��
+
+                // 鏇存柊褰撳墠鐢ㄦ埛鐨勬淇姸鎬�
+                maint.MaintenancEendTime = DateTime.Now; // 璁板綍缁撴潫鏃堕棿
+                maint.MaintenanceStatus = 0; // 鏇存敼鐘舵��
                 BaseDal.UpdateData(maint);
-                ////鎻掑叆璁板綍琛�
-                var recording = new Dt_MaintenanceTeam  //娣诲姞璁板綍
+
+                // 鎻掑叆璁板綍琛�
+                var recording = new Dt_MaintenanceTeam  // 娣诲姞璁板綍
                 {
                     Account = account,
-                    MaintenanceStatus=0,
+                    MaintenanceStatus = 0,
                     OperatorName = sysuer.UserTrueName,
                     TeamName = sysuer.RoleName,
                     EndTime = DateTime.Now,
diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
index 68f1eda..8704a1d 100644
--- a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
+++ b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
@@ -15,6 +15,7 @@
 using WIDESEAWCS_ITelescopicService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using static WIDESEAWCS_Common.Face.TH_Faces;
 
 
 namespace WIDESEAWCS_TelescopicService
@@ -37,6 +38,7 @@
         /// <returns></returns>
         public WebResponseContent automation(string ExtendedState)
         {
+            
             try
             {
 
@@ -56,54 +58,27 @@
                 int ret = (int)para.RetractionSpeed;//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害
                 int liftPosition = (int)para.LeftPosition;//宸︿几鍑轰綅缃�
                 int rigtpostition = (int)para.RightPosition;//鍙充几鍑轰綅缃�
-                bool canLeftWork = true;
-                bool canRightWork = true;
                 string message = "";
-                    try
-                    {
-                        var leftorigin = devices.Value.left.Communicator.Read<bool>("M115");  //鍒拌揪鍘熺偣浣嶇疆
-                        if (leftorigin)
-                        {
-                            canLeftWork = false;
-                            message += "宸LC宸插埌鍘熺偣锛�";
-                        }
-                    }
-                    catch (Exception)
-                    {  
-                    }
-                    try
-                    {
-                        var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");
-                        if (rightorigin)
-                        {
-                            canRightWork = false;
-                            message += "鍙砅LC宸插埌鍘熺偣锛�";
-                        }
-                    }
-                    catch (Exception)
-                    { 
-                    }
 
                 try
                 {
-                    var lefttarget = devices.Value.left.Communicator.Read<bool>("M116"); //鍒拌揪鏈�澶т綅缃�
-                   
-                    if (lefttarget)
+                    if (devices.Value.left.Communicator.Read<bool>("M117"))
                     {
-                        canLeftWork = false;
-                        message += "宸LC宸插埌鏈�澶у�硷紱";
+                        
+                        return new WebResponseContent { Status = true, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                     }
-                  
+                    
                 }
-                catch { }
+                catch (Exception)
+                {
+                }
                 try
                 {
-                    var righttarget = devices.Value.right.Communicator.Read<bool>("M116");
-                    if (righttarget)
+                    if (devices.Value.right.Communicator.Read<bool>("M117"))
                     {
-                        canRightWork = false;
-                        message += "鍙砅LC宸插埌鏈�澶у�硷紱";
+                        return new WebResponseContent { Status = true, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                     }
+                    
                 }
                 catch (Exception)
                 {
@@ -111,51 +86,79 @@
 
                 if (ExtendedState == "浼稿嚭")
                 {
-                    if (canLeftWork)
-                    {
+                   
                         try
                         {
-                            devices.Value.left.Communicator.Write<int>("D1001", ext);//宸LC鑷姩鍔ㄤ几鍑虹缉鍥為�熷害
+                        if (devices.Value.left.Communicator.Read<float>("D80")>= liftPosition-5)//鍒拌揪鏈�澶т綅缃�)
+                        {
+                            message += "宸LC宸插埌鏈�澶т綅缃紱";
+                        }
+                        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);//浼稿嚭鎸夐挳
-                            devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//浼稿嚭浣嶇疆
+                            
+                        } 
                         }
                         catch { }
-                    }
-
-                    if (canRightWork)
-                    {
+                
                         try
                         {
-                            devices.Value.right.Communicator.Write<int>("D1001", ret);
-                            devices.Value.right.Communicator.Write<bool>("M102", true);
-                            devices.Value.right.Communicator.Write<int>("D1002", rigtpostition);
+                        if (devices.Value.right.Communicator.Read<float>("D80") >= rigtpostition-5)
+                        {
+                            message += "鍙砅LC宸插埌鏈�澶т綅缃紱";
                         }
+                        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 == "缂╁洖")
                 {
-                    if (canLeftWork)
-                    {
+                    
                         try
                         {
-                            devices.Value.left.Communicator.Write<int>("D1001", ext);//宸LC鑷姩浼�=缂╁洖鍑虹缉鍥為�熷害
+                        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 { }
+                            
+                        }                           
                     }
+                        catch { }
 
-                    if (canRightWork)
-                    {
+                   
                         try
                         {
-                            devices.Value.right.Communicator.Write<int>("D1001", ret);
+                        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
                 {
@@ -165,8 +168,8 @@
                 return new WebResponseContent
                 {
                     Status = true,
-                    Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"閮ㄥ垎PLC鏈墽琛岋細{message}",
-                    Data = new { ExtendSpeed = ext, RetractionSpeed = ret }
+                    Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"{message}",
+                    Data = new { ExtendSpeed = ext, RetractionSpeed = ret,liftweiz= liftPosition,rightweiz= rigtpostition }
                 };
 
             }
@@ -207,114 +210,112 @@
                 int ret = (int)para.ManualRetraction;//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害
                 int liftPosition = (int)para.LeftPosition;//宸︿几鍑轰綅缃�
                 int rigtpostition = (int)para.RightPosition;//鍙充几鍑轰綅缃�
-                bool canLeft = true,
-                 canRight = true;
+                //bool canLeft = true,
+                // canRight = true;
                 string message = "";
 
                 try
                 {
-                    var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115");
-                   
+                    if (devices.Value.left.Communicator.Read<bool>("M117")) //榛樿鏄痜lase 
+                    {
 
-                    if (leftOrigin)
-                    {
-                        message += "宸LC宸插埌鍘熺偣锛�";
-                        canLeft=false;
+                        return new WebResponseContent { Status = true, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                     }
-                  
-                }
-                catch (Exception )
-                {     }
-                try
-                {
-                    var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115");
-                    if (rightOrigin)
-                    {
-                        message += "鍙砅LC宸插埌鍘熺偣锛�";
-                        canRight = false;
-                    }
+
                 }
                 catch (Exception)
                 {
                 }
-
                 try
                 {
-                    try
+                    if (devices.Value.right.Communicator.Read<bool>("M117"))
                     {
-                        var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//宸lc鍒拌揪鐩爣浣嶇疆
-                        if (lefttarget)
-                        {
-                            message += "宸lc鍒拌揪鐩爣浣嶇疆锛�";
-                            canLeft = false;
-                        }
+                        return new WebResponseContent { Status = false, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                     }
-                    catch (Exception)
-                    {
-                    }
-                    try
-                    {
-                        var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//鍙硃lc鍒拌揪鐩爣浣嶇疆
-                        if (righttarget)
-                        {
-                            message += "鍙硃lc鍒拌揪鐩爣浣嶇疆锛�";
-                            canRight = false;
-                        }
 
-                    }
-                    catch (Exception)
-                    {
-                    }
                 }
-                catch (Exception )
-                { }
-                if (canLeft) //娌℃湁鍒板師鐐规垨鏈�澶у�肩殑鏃跺�欐墠鎵ц涓嬮潰鐨勮鍙�
+                catch (Exception)
                 {
-                    if (position == "宸�" && ExtendedState == "浼稿嚭")
+                }
+                if (position == "宸�" && ExtendedState == "浼稿嚭")
+                {
+                    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); // 閲婃斁鎸夐挳
-                        devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//宸︿几鍑轰綅缃�
+                        
 
                         Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ext}");
-
                     }
-                    else if (position == "宸�" && ExtendedState == "缂╁洖")
+
+                }
+                else if (position == "宸�" && ExtendedState == "缂╁洖")
+                {
+                    if (devices.Value.left.Communicator.Read<bool>("M115"))//缂╁洖鐨勬椂鍊欏垽鏂�) 
                     {
+                        message += "宸LC宸插埌鍘熺偣锛�";
+                    }
+                    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}");
                     }
+
                 }
 
-                if (canRight)
+                if (position == "鍙�" && ExtendedState == "浼稿嚭")
                 {
-
-                    if (position == "鍙�" && ExtendedState == "浼稿嚭")
+                    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); // 閲婃斁鎸夐挳
-                        devices.Value.right.Communicator.Write<int>("D1002", liftPosition);//宸︿几鍑轰綅缃�
                         Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ret}");
-
                     }
-                    else if (position == "鍙�" && ExtendedState == "缂╁洖")
+
+
+                }
+                else if (position == "鍙�" && ExtendedState == "缂╁洖")
+                {
+                    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 = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"鎵ц澶辫触锛歿message}", 
+
+                }
+               
+
+
+                return new WebResponseContent
+                {
+                    Status = true,
+                    Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"{message}",
                     Data = new
                     {
                         ManualExtend = ext,
@@ -323,6 +324,8 @@
                     }
                 };
             }
+
+
             catch (Exception ex)
             {
                 return new WebResponseContent { Status = false, Message = ex.Message };
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 d40bdc8..566e4f4 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"
@@ -67,54 +67,23 @@
                         int liftPos = (int)para.LeftPosition;
                         int rightPos = (int)para.RightPosition;
 
-                        // 鐙珛鍒ゆ柇宸�/鍙虫槸鍚﹀彲鎵ц
-                        bool canLeft = true, canRight = true;
-
                         try
                         {
-                            var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115");//鍒拌揪鍘熺偣
-                            if (leftOrigin)
+                            if (devices.Value.left.Communicator.Read<bool>("M117"))
                             {
-                                messages.Add($"{deptId}杞ㄩ亾宸LC宸插埌鍘熺偣");
-                                canLeft = false;
+
+                                return new WebResponseContent { Status = false, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                             }
 
                         }
                         catch (Exception)
-                        { }
-                        try
-                        {
-                            var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115");
-                            if (rightOrigin)
-                            {
-                                messages.Add($"{deptId}杞ㄩ亾鍙砅LC宸插埌鍘熺偣");
-                                canRight = false;
-                            }
-                        }
-                        catch (Exception)
-                        {
-                        }
-
-
-                        try
-                        {
-                            var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//宸lc鍒拌揪鐩爣浣嶇疆
-                            if (lefttarget)
-                            {
-                                messages.Add($"{deptId}杞ㄩ亾宸lc鍒拌揪鐩爣浣嶇疆");
-                                canLeft = false;
-                            }
-                        }
-                        catch (Exception)
                         {
                         }
                         try
                         {
-                            var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//鍙硃lc鍒拌揪鐩爣浣嶇疆
-                            if (righttarget)
+                            if (devices.Value.right.Communicator.Read<bool>("M117"))
                             {
-                                messages.Add($"{deptId}杞ㄩ亾鍙硃lc鍒拌揪鐩爣浣嶇疆");
-                                canRight = false;
+                                return new WebResponseContent { Status = false, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                             }
 
                         }
@@ -124,71 +93,83 @@
 
                         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 == "缂╁洖")
+                   
+                        try
                         {
-                            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)
-                                {
-
-
-                                }
-                            }
+                        if (devices.Value.left.Communicator.Read<float>("D80")>= liftPos-5)//鍒拌揪鏈�澶т綅缃�)
+                        {
+                                    messages.Add($"杞ㄩ亾绔檣deptId}宸︿几缂╂潌宸插埌鏈�澶т綅缃�");
+                           
                         }
+                        else
+                        {
+                                    devices.Value.left.Communicator.Write<int>("D1022", liftPos);//浼稿嚭浣嶇疆
+                                    devices.Value.left.Communicator.Write<int>("D1002", ext);//宸LC鑷姩鍔ㄤ几鍑虹缉鍥為�熷害
+                                    devices.Value.left.Communicator.Write<bool>("M102", true);//浼稿嚭鎸夐挳
+                            
+                        } 
+                        }
+                        catch { }
+                
+                        try
+                        {
+                        if (devices.Value.left.Communicator.Read<float>("D80") >=rightPos-5)
+                        {
+                                    messages.Add($"杞ㄩ亾绔檣deptId}鍙充几缂╂潌宸插埌鏈�澶т綅缃�");
+                        
+                        }
+                        else
+                        {
+                                    devices.Value.right.Communicator.Write<int>("D1022", rightPos);
+                                    devices.Value.right.Communicator.Write<int>("D1002", ret);
+                            devices.Value.right.Communicator.Write<bool>("M102", true);
+                            
+                        }                        }
+                        catch { }
+                    
+                }
+                else if (extendedState == "缂╁洖")
+                {
+                    
+                        try
+                        {
+                        if (devices.Value.left.Communicator.Read<bool>("M115")) //鍒拌揪鍘熺偣浣�
+                        {
+                                    messages.Add($"杞ㄩ亾绔檣deptId}宸︿几缂╂潌宸插埌鍘熺偣");
+                           
+                        }
+                        else
+                        {
+                                    devices.Value.left.Communicator.Write<int>("D1022", liftPos);//浼稿嚭浣嶇疆
+                                    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"))
+                        {
+                                    messages.Add($"杞ㄩ亾绔檣deptId}鍙充几缂╂潌宸插埌鍘熺偣");
+                          
+                        }
+                        else
+                        {
+                                    devices.Value.right.Communicator.Write<int>("D1022", rightPos);
+                                    devices.Value.right.Communicator.Write<int>("D1002", ret);
+                            devices.Value.right.Communicator.Write<bool>("M103", true);
+                            
+                         }
+                          
+                          
+                        }
+                        catch { }
+                    
+                }
                         else
                         {
                             return new WebResponseContent { Status = false, Message = "鏈煡鎿嶄綔鍛戒护" };
@@ -232,144 +213,147 @@
         /// <param name="DeptId">鑲¢亾鍙�</param>
         /// <returns></returns>
         public WebResponseContent ManualOperation(string position, string ExtendedState,int DeptId)
-                {
+          {
             try
             {
+                if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+                {
+                    return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+                }
+                var devices = GetDevicesByDeptId(deid);
 
-                var devices = GetDevicesByDeptId(DeptId);
-                if (devices == null)
-                    return new WebResponseContent { Status = false, Message = "璁惧鏈壘鍒�" };
+                //淇╀釜plc宸﹀彸鍚勪竴涓�
+                //OtherDevice liftotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG001");
+                //OtherDevice rightotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG002");
 
-                var para = BaseDal.QueryData(x=>x.Deptid== DeptId).OrderByDescending(x => x.CreateDate).FirstOrDefault();
-                if (para == null)
-                    return new WebResponseContent { Status = false, Message = "鍙傛暟鏈厤缃�" };
-
+                //鎵惧埌Dt_Parameters涓殑鏈�鏂颁竴鏉℃暟鎹牴鎹綋鍓嶇殑deid
+                var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                 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;
+                //bool canLeft = true,
+                // canRight = true;
                 string message = "";
 
                 try
                 {
-                    var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115");
-
-
-                    if (leftOrigin)
+                    if (devices.Value.left.Communicator.Read<bool>("M117")) //榛樿鏄痜lase 
                     {
-                        message += "宸LC宸插埌鍘熺偣锛�";
-                        canLeft = false;
+
+                        return new WebResponseContent { Status = true, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                     }
 
                 }
                 catch (Exception)
-                { }
+                {
+                }
                 try
                 {
-                    var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115");
-                    if (rightOrigin)
+                    if (devices.Value.right.Communicator.Read<bool>("M117"))
                     {
-                        message += "鍙砅LC宸插埌鍘熺偣锛�";
-                        canRight = false;
+                        return new WebResponseContent { Status = false, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                     }
+
                 }
                 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;
-                        }
-
-                    }
-                    catch (Exception)
-                    {
-                    }
-
-
-                if (canLeft)
+                if (position == "宸�" && ExtendedState == "浼稿嚭")
                 {
-                    if (position == "宸�" && ExtendedState == "浼稿嚭")
+                    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); // 閲婃斁鎸夐挳
-                        devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//宸︿几鍑轰綅缃�
+
+
                         Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ext}");
                     }
-                    else if (position == "宸�" && ExtendedState == "缂╁洖")
+
+                }
+                else if (position == "宸�" && ExtendedState == "缂╁洖")
+                {
+                    if (devices.Value.left.Communicator.Read<bool>("M115"))//缂╁洖鐨勬椂鍊欏垽鏂�) 
                     {
+                        message += "宸LC宸插埌鍘熺偣锛�";
+                    }
+                    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}");
                     }
+
                 }
-                if (canRight)
+
+                if (position == "鍙�" && ExtendedState == "浼稿嚭")
                 {
-                    if (position == "鍙�" && ExtendedState == "浼稿嚭")
+                    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); // 閲婃斁鎸夐挳
-                        devices.Value.right.Communicator.Write<int>("D1002", liftPosition);//宸︿几鍑轰綅缃�
                         Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ret}");
                     }
-                    else if (position == "鍙�" && ExtendedState == "缂╁洖")
+
+
+                }
+                else if (position == "鍙�" && ExtendedState == "缂╁洖")
+                {
+                    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}");
                     }
+
                 }
 
-                else
+
+
+                return new WebResponseContent
                 {
-                    return new WebResponseContent { Status = false, Message = "鐘舵�佸弬鏁伴敊璇�" };
-                }
-
-                return new WebResponseContent { Status = true,
-                    Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"鎵ц澶辫触锛歿message}",
+                    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 };
 
             }
+
         }
 
 

--
Gitblit v1.9.3