刘磊
7 天以前 2de09bec5cc05bf875543fa8956167ca7db73021
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -4,6 +4,7 @@
using Newtonsoft.Json;
using SqlSugar;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common;
@@ -18,9 +19,12 @@
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.DTO;
namespace WIDESEAWCS_TaskInfoService
{
@@ -95,6 +99,7 @@
                    task.wheels_mttype = item.wheels_mttype;
                    task.WheelsNewOrOld = item.WheelsNewOrOld;
                    task.WheelsLX = item.WheelsLX;
                    // åˆ¤æ–­ä»»åŠ¡ç±»åž‹æ˜¯å¦ä¸ºå‡ºåº“ä»»åŠ¡
                    if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
@@ -103,12 +108,23 @@
                        List<Dt_Router> routers = _routerService.QueryNextRoutes(item.RoadWay, item.TargetAddress);
                        if (routers.Count > 0)
                        {
                            // è®¾ç½®ä»»åŠ¡çŠ¶æ€ä¸ºå‡ºåº“æ–°å»º
                            task.TaskState = (int)TaskOutStatusEnum.OutNew;
                            task.TaskState =(int)TaskOutStatusEnum.OutNew;
                            // è®¾ç½®å½“前地址为源地址
                            task.CurrentAddress = item.SourceAddress;
                            // è®¾ç½®ä¸‹ä¸€ä¸ªåœ°å€ä¸ºç¬¬ä¸€ä¸ªå­ä½ç½®
                            task.NextAddress = routers.FirstOrDefault().ChildPosi;
                            if (item.SourceAddress == "2009")
                            {
                                task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish;
                                // è®¾ç½®ä¸‹ä¸€ä¸ªåœ°å€ä¸ºç¬¬ä¸€ä¸ªå­ä½ç½®
                                task.NextAddress = "2015";
                            }
                        }
                        else
                        {
@@ -825,5 +841,156 @@
        }
        #endregion é‡å†™æ–¹æ³•
        //===========================车轴上料=====================
        public WebResponseContent GetFeedbackAxleloading()
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                var completeTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestAxleloading)?.ConfigValue;
                if (wmsBase == null || completeTask == null)
                {
                    throw new InvalidOperationException("WMS IP æœªé…ç½®");
                }
                var wmsIpAddress = wmsBase + completeTask;
                var taskDto = new RequestTaskDto()
                {
                    PalletCode = "1",
                };
                var result = HttpHelper.PostAsync(wmsIpAddress,taskDto.ToJsonString()).Result;
                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                return content;
            }
            catch (Exception ex)
            {
                return content.Error($"{ex.Message}");
            }
        }
        public WebResponseContent UpdateAxleCurrentStatue(string CZTM)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                var completeTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.UpdateAxleCurrentStatue)?.ConfigValue;
                if (wmsBase == null || completeTask == null)
                {
                    throw new InvalidOperationException("WMS IP æœªé…ç½®");
                }
                var wmsIpAddress = wmsBase + completeTask;
                var keys = new Dictionary<string, object>()
                {
                    {"CZTM", CZTM}
                };
                var taskDto = new RequestTaskDto()
                {
                    PalletCode = CZTM,
                };
                var result = HttpHelper.PostAsync(wmsIpAddress, taskDto.ToJsonString()).Result;
                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                return content;
            }
            catch (Exception ex)
            {
                return content.Error($"{ex.Message}");
            }
        }
        public WebResponseContent GetAGVTaskdistribution(string TargetAddress)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                var completeTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.genAgvSchedulingTask)?.ConfigValue;
                if (wmsBase == null || completeTask == null)
                {
                    throw new InvalidOperationException("WMS IP æœªé…ç½®");
                }
                var wmsIpAddress = wmsBase + completeTask;
                var taskDto = new RequestTaskDto()
                {
                    Position = TargetAddress,
                };
                var result = HttpHelper.PostAsync(wmsIpAddress, taskDto.ToJsonString()).Result;
                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                return content;
            }
            catch (Exception ex)
            {
                return content.Error($"{ex.Message}");
            }
        }
        public WebResponseContent SetPlcResponState(string TargetAddress)
        {
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1000");
                CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                DeviceProDTO? deviceProDTOt = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == TargetAddress && x.DeviceProParamName == "ResponState");
                if (conveyorLine.Communicator.Write(deviceProDTOt.DeviceProAddress, (short)2))
                {
                    Console.Out.WriteLine("成功!写出车轴线末端agv取货完成信号:2");
                    return WebResponseContent.Instance.OK();
                }
                else
                {
                    bool st= conveyorLine.Communicator.Write(deviceProDTOt.DeviceProAddress, (short)3);
                    Console.Out.WriteLine($"写出车轴线末端agv取货完成信号失败信息,写入:3,是否成功:{st}");
                    return WebResponseContent.Instance.Error();
                }
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine($"写出车轴线末端agv取货完成信号失败信息,故障信息:{ex.Message}");
                return WebResponseContent.Instance.Error();
            }
        }
        public WebResponseContent GetPlcState(string TargetAddress)
        {
            Dt_StationManager dt_Station=_stationManagerRepository.QueryFirst(x => x.stationLocation == TargetAddress);
            if(dt_Station == null)
                return WebResponseContent.Instance.Error("未找到压装位信息!");
            if(dt_Station.stationStatus=="0")
                return WebResponseContent.Instance.Error("该压装位已被禁用!不可生成agv任务");
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1000");
            CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
            DeviceProDTO? deviceProDTOt = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == TargetAddress && x.DeviceProParamName == "ConveyorLineSingal");
            DeviceProDTO? deviceProDTOt2 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == TargetAddress && x.DeviceProParamName == "ResponState");
            if (conveyorLine.Communicator.Read<short>(deviceProDTOt.DeviceProAddress)==1)
            {
                conveyorLine.Communicator.Write(deviceProDTOt2.DeviceProAddress,(short)1);
                return WebResponseContent.Instance.OK();
            }
            else
            {
                conveyorLine.Communicator.Write(deviceProDTOt2.DeviceProAddress, (short)2);
                return WebResponseContent.Instance.Error("读取到压装位信号反馈不可放货!不可生成agv任务");
            }
        }
    }
}