1
z8018
2025-05-08 b2e04d15e8284aa23af89200075b6fd52a77477e
project/ºǫ́¹ÜÀí/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);