From b2e04d15e8284aa23af89200075b6fd52a77477e Mon Sep 17 00:00:00 2001 From: z8018 <1282578289@qq.com> Date: 星期四, 08 五月 2025 14:50:36 +0800 Subject: [PATCH] 1 --- project/后台管理/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs | 197 ++++++++++++++++++++++++++----------------------- 1 files changed, 104 insertions(+), 93 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 fb818db..a10f1af 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" @@ -9,6 +9,7 @@ using WIDESEAWCS_Core; using WIDESEAWCS_Core.BaseRepository; using WIDESEAWCS_Core.BaseServices; +using WIDESEAWCS_Core.Helper; using WIDESEAWCS_ITelescopicService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; @@ -28,72 +29,73 @@ /// <summary> - /// 鑷姩鎺у埗浼哥缉鏉嗙殑浼稿嚭鍜岀缉鍥為�熷害 + /// 鑷姩鎺у埗浼哥缉鏉嗙殑浼稿嚭鍜岀缉鍥為�熷害锛堜竴娆℃�ф帶鍒舵墍鏈夌殑锛� /// </summary> /// <param name="ExtendedState">浼�/鍑虹姸鎬�</param> - /// <param name="account">鐢ㄦ埛璐﹀彿</param> /// <returns></returns> - public WebResponseContent automation(string ExtendedState, string account) + public WebResponseContent automation(string extendedState) { try { - var loginer = _user.QueryData(x => x.UserName == account).FirstOrDefault(); - if (loginer == null) - return new WebResponseContent { Status = false, Message = "鐧诲綍鐢ㄦ埛涓嶅瓨鍦�" }; - - // 璁惧缂栧彿瑙勫垯鏄寜閮ㄩ棬缂栧彿渚濇涓� SSG001~SSG010 - string liftDeviceCode = $"SSG{(loginer.Dept_Id * 2 - 1):D3}"; - string rightDeviceCode = $"SSG{(loginer.Dept_Id * 2):D3}"; - - OtherDevice liftDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == liftDeviceCode); - OtherDevice rightDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == rightDeviceCode); - - if (liftDevice == null || rightDevice == null) + for (int deptId = 1; deptId <= 5; deptId++) { - return new WebResponseContent { Status = false, Message = $"璁惧 {liftDeviceCode} 鎴� {rightDeviceCode} 鏈壘鍒�" }; + 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; + int ret = (int)para.RetractionSpeed; + + 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($"DeptId={deptId} 浼稿嚭鎿嶄綔锛岄�熷害={ext}"); + } + else if (extendedState == "缂╁洖") + { + devices.Value.left.Communicator.Write<int>("D501", ret);//浼稿嚭閫熷害 + devices.Value.left.Communicator.Write<bool>("M101", true);//浼稿嚭鎸夐挳 + + devices.Value.right.Communicator.Write<int>("D501", ret); + devices.Value.right.Communicator.Write<bool>("M101", true); + + Console.WriteLine($"DeptId={deptId} 缂╁洖鎿嶄綔锛岄�熷害={ret}"); + } + else + { + return new WebResponseContent { Status = false, Message = "鏈煡鐨勬搷浣滃懡浠�" }; + } } - if (liftDevice.Communicator == null || rightDevice.Communicator == null) - { - return new WebResponseContent { Status = false, Message = "璁惧閫氳鏈垵濮嬪寲" }; - } - - //鎵惧埌Dt_Parameters涓殑鏈�鏂颁竴鏉℃暟鎹� - var para = BaseDal.QueryData().OrderByDescending(x => x.CreateDate).FirstOrDefault(); - if (para == null) - return new WebResponseContent { Status = false, Message = "鏈壘鍒板弬鏁伴厤缃�" }; - - int ext = (int)para.ExtendSpeed; - int ret = (int)para.RetractionSpeed; - - if (ExtendedState == "浼稿嚭") - { - liftDevice.Communicator.Write<int>("D500", ext); - liftDevice.Communicator.Write<bool>("M100", true); - rightDevice.Communicator.Write<int>("D500", ext); - rightDevice.Communicator.Write<bool>("M100", true); - Console.WriteLine($"浼哥缉鏉嗕几鍑� {ext}"); - } - else if (ExtendedState == "缂╁洖") - { - liftDevice.Communicator.Write<int>("D501", ret); - liftDevice.Communicator.Write<bool>("M101", true); - rightDevice.Communicator.Write<int>("D501", ret); - rightDevice.Communicator.Write<bool>("M101", true); - Console.WriteLine($"浼哥缉鏉嗙缉鍥� {ret}"); - } - else - { - return new WebResponseContent { Status = false, Message = "鏈煡鐨勬搷浣滃懡浠�" }; - } - - return new WebResponseContent { Status = true, Message = "鎴愬姛" }; + return new WebResponseContent { Status = true, Message = "鍏ㄩ儴璁惧鎿嶄綔瀹屾垚" }; } catch (Exception ex) { - return new WebResponseContent { Status = false, Message = ex.Message }; + return new WebResponseContent { Status = false, Message = $"鎿嶄綔寮傚父锛歿ex.Message}" }; } } + + + @@ -116,53 +118,58 @@ // var para = BaseDal.QueryData().OrderBy(x => x.CreateDate).FirstOrDefault(); // int ext = (int)para.ManualExtend;//鑷姩浼稿嚭閫熷害 // int ret = (int)para.ManualRetraction;//鑷姩缂╁洖閫熷害 - // if (position == "宸�" && ExtendedState == "浼稿嚭") - // { - // var values = liftotherDevice.Communicator.Write<int>("D500", ext);//閫熷害 - // var button = liftotherDevice.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳 - // Console.WriteLine($"{position}浼哥缉鏉嗕几鍑簕ext}"); - // } - // if (position == "宸�" && ExtendedState == "缂╁洖") - // { - // var values = liftotherDevice.Communicator.Write<int>("D501", ret); - //var button = liftotherDevice.Communicator.Write<bool>("M101", true);//缂╁洖鎸夐挳 - //Console.WriteLine($"{position}浼哥缉鏉嗙缉鍥瀧ret}"); - // } -// if (position == "鍙�" && ExtendedState == "浼稿嚭") -// { -// var values = rightotherDevice.Communicator.Write<int>("D500", ext);//閫熷害 -// var button = rightotherDevice.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳 -// Console.WriteLine($"{position}浼哥缉鏉嗕几鍑簕ext}"); -// } -// if (position == "鍙�" && ExtendedState == "缂╁洖") -// { -// var values = rightotherDevice.Communicator.Write<int>("D501", ret); -// var button = rightotherDevice.Communicator.Write<bool>("M101", true);//缂╁洖鎸夐挳 -// Console.WriteLine($"{position}浼哥缉鏉嗙缉鍥瀧ret}"); -// } -// return new WebResponseContent { Status = true, Message = "鎴愬姛" }; -// } -// catch (Exception ex) -// { -// return new WebResponseContent { Status = false, Message = ex.Message }; + // if (position == "宸�" && ExtendedState == "浼稿嚭") + // { + // var values = liftotherDevice.Communicator.Write<int>("D500", ext);//閫熷害 + // var button = liftotherDevice.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳 + // Console.WriteLine($"{position}浼哥缉鏉嗕几鍑簕ext}"); + // } + // if (position == "宸�" && ExtendedState == "缂╁洖") + // { + // var values = liftotherDevice.Communicator.Write<int>("D501", ret); + //var button = liftotherDevice.Communicator.Write<bool>("M101", true);//缂╁洖鎸夐挳 + //Console.WriteLine($"{position}浼哥缉鏉嗙缉鍥瀧ret}"); + // } + // if (position == "鍙�" && ExtendedState == "浼稿嚭") + // { + // var values = rightotherDevice.Communicator.Write<int>("D500", ext);//閫熷害 + // var button = rightotherDevice.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳 + // Console.WriteLine($"{position}浼哥缉鏉嗕几鍑簕ext}"); + // } + // if (position == "鍙�" && ExtendedState == "缂╁洖") + // { + // var values = rightotherDevice.Communicator.Write<int>("D501", ret); + // var button = rightotherDevice.Communicator.Write<bool>("M101", true);//缂╁洖鎸夐挳 + // Console.WriteLine($"{position}浼哥缉鏉嗙缉鍥瀧ret}"); + // } + // return new WebResponseContent { Status = true, Message = "鎴愬姛" }; + // } + // catch (Exception ex) + // { + // return new WebResponseContent { Status = false, Message = ex.Message }; -// } -//} + // } + //} - public WebResponseContent ManualOperation(string position, string ExtendedState,string account) + + /// <summary> + /// 鎵嬪姩鎺у埗锛屼几缂╂潌鐨勭缉鍥炲拰浼稿嚭閫熷害 + /// </summary> + /// <param name="position">浼哥缉鏉嗙殑浣嶇疆锛堝乏鍙筹級</param> + /// <param name="ExtendedState">浼�/缂╃姸鎬�</param> + /// <param name="DeptId">鑲¢亾鍙�</param> + /// <returns></returns> + public WebResponseContent ManualOperation(string position, string ExtendedState,int DeptId) { try { - var loginer = _user.QueryData(x => x.UserName == account).FirstOrDefault(); - if (loginer == null) - return new WebResponseContent { Status = false, Message = "鐢ㄦ埛涓嶅瓨鍦�" }; - var devices = GetDevicesByDeptId((int)loginer.Dept_Id); + var devices = GetDevicesByDeptId(DeptId); if (devices == null) return new WebResponseContent { Status = false, Message = "璁惧鏈壘鍒�" }; - var para = BaseDal.QueryData().OrderByDescending(x => x.CreateDate).FirstOrDefault(); + var para = BaseDal.QueryData(x=>x.Deptid== DeptId).OrderByDescending(x => x.CreateDate).FirstOrDefault(); if (para == null) return new WebResponseContent { Status = false, Message = "鍙傛暟鏈厤缃�" }; @@ -171,23 +178,27 @@ if (position == "宸�" && ExtendedState == "浼稿嚭") { - devices.Value.left.Communicator.Write<int>("D500", ext); - devices.Value.left.Communicator.Write<bool>("M100", true); + devices.Value.left.Communicator.Write<int>("D500", ext);//浼稿嚭閫熷害 + devices.Value.left.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳 + Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ext}"); } else if (position == "宸�" && ExtendedState == "缂╁洖") { - devices.Value.left.Communicator.Write<int>("D501", ret); + devices.Value.left.Communicator.Write<int>("D501", ret);//缂╁洖閫熷害 devices.Value.left.Communicator.Write<bool>("M101", true); + Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄧ缉鍥瀧ret}"); } else if (position == "鍙�" && ExtendedState == "浼稿嚭") { devices.Value.right.Communicator.Write<int>("D500", ext); devices.Value.right.Communicator.Write<bool>("M100", true); + Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ext}"); } else if (position == "鍙�" && ExtendedState == "缂╁洖") { devices.Value.right.Communicator.Write<int>("D501", ret); devices.Value.right.Communicator.Write<bool>("M101", true); + Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄧ缉鍥瀧ret}"); } else @@ -216,8 +227,8 @@ // 宸﹁澶囧彿锛�1 -> 001锛�2 -> 003锛�3 -> 005... int baseCode = 1 + (deptId - 1) * 2; string leftCode = $"SSG{baseCode.ToString("D3")}"; + //鍙宠澶囷細1->002 ,2->004 string rightCode = $"SSG{(baseCode + 1).ToString("D3")}"; - var left = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == leftCode); var right = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == rightCode); -- Gitblit v1.9.3