liulijun
21 小时以前 5270308151082506e0e6df2c72d278d2976ec860
ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_Tasks/Ô­ÁÏ¿â/ConveyorLineJob_YL1ndFloor.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components.Routing;
using HslCommunication.WebSocket;
using Microsoft.AspNetCore.Components.Routing;
using Newtonsoft.Json;
using Quartz;
using System;
@@ -7,11 +8,13 @@
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using HslCommunication.WebSocket;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
@@ -37,9 +40,10 @@
        private readonly IRouterRepository _routerRepository;
        private readonly IRouterService _routerService;
        private readonly IRouterExtension _routerExtension;
        private readonly WebSocketServer _webSocketServer;
        private readonly List<Dt_WarehouseDevice> warehouseDevices;
        public ConveyorLineJob_YL1ndFloor(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension)
        public ConveyorLineJob_YL1ndFloor(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension, WebSocketServer webSocketServer)
        {
            _cacheService = cacheService;
            _taskService = taskService;
@@ -49,6 +53,7 @@
            _routerRepository = routerRepository;
            _routerService = routerService;
            _routerExtension = routerExtension;
            _webSocketServer = webSocketServer;
            string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice));
            if (!string.IsNullOrEmpty(warehouseDevicesStr))
@@ -70,12 +75,23 @@
                //获取所有协议的输送线站台
                List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).ToList();
                List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
                // åˆ›å»ºè¾“送线数据对象,用于WebSocket发送
                var conveyorLineCPData = new Dictionary<string, object>();
                conveyorLineCPData["设备编号"] = device.DeviceCode;
                conveyorLineCPData["设备名称"] = "原料库一楼输送线";
                conveyorLineCPData["ConveyorLineInfo"] = new Dictionary<string, Dictionary<string, object>>();
                foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
                {
                    DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(WR_CLineYLDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                    DeviceProDTO? deviceErrRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ErrorYLDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                    R_ConveyorLineYLInfo conveyorLineInfoRead = new R_ConveyorLineYLInfo();
                    R_ErrorYLDB errorYLDB = new R_ErrorYLDB();
                    var simplifiedInfo = new Dictionary<string, object>();
                    if (deviceProRead != null)
                    {
                        R_ConveyorLineYLInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineYLInfo>(deviceProRead.DeviceProAddress);
                         conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineYLInfo>(deviceProRead.DeviceProAddress);
                        if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID)) //一楼来料称重站台允许入库申请
                        {
                            WebResponseContent content = _taskService.YLPurchaseBoxing(conveyorLineInfoRead.WR_TMID, weight: conveyorLineInfoRead.WR_Weight, thickness: conveyorLineInfoRead.WR_Height, wide: conveyorLineInfoRead.WR_Width);
@@ -119,23 +135,27 @@
                            {
                                if (string.IsNullOrEmpty(task.Roadway) && string.IsNullOrEmpty(task.NextAddress))
                                {
                                    WebResponseContent content = _taskService.AssignYLRoadwayNo(task.PalletCode);
                                    if (!content.Status)
                                    WebResponseContent content = _taskService.AssignYLRoadwayNo(task.PalletCode,weight: conveyorLineInfoRead.WR_Weight, thickness: conveyorLineInfoRead.WR_Height, wide: conveyorLineInfoRead.WR_Width);
                                    if (content.Status)
                                    {
                                        string roadWay = content.Data.ToString();
                                        //获取路由配置
                                        List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.CurrentAddress == x.StartPosi && x.ChildPosiDeviceCode == roadWay);
                                        Dt_Router router = routers.FirstOrDefault();
                                        if (router == null)
                                        {
                                            WriteError(item.StationName, $"任务号:{task.TaskNum}未找到路由配置信息");
                                            return Task.CompletedTask;
                                        }
                                        task.Roadway = roadWay;
                                        task.NextAddress = router.NextPosi;
                                        _taskService.UpdateTask(task, TaskStatusEnum.AGV_Finish);
                                    }
                                    else
                                    {
                                        WriteError(item.StationCode, $"请求入库失败:{content.Message}");
                                    }
                                    string roadWay = content.Data.ToString();
                                    //获取路由配置
                                    List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.CurrentAddress == x.StartPosi && x.ChildPosiDeviceCode== roadWay);
                                    Dt_Router router = routers.FirstOrDefault();
                                    if (router == null)
                                    {
                                        WriteError(item.StationName, $"任务号:{task.TaskNum}未找到路由配置信息");
                                        return Task.CompletedTask;
                                    }
                                    task.Roadway = roadWay;
                                    task.NextAddress = router.NextPosi;
                                    _taskService.UpdateTask(task,TaskStatusEnum.AGV_Finish);
                                }
                                else
                                {
@@ -216,12 +236,58 @@
                                WriteInfo(item.StationCode, $"任务号:{task.TaskNum},RIFD{task.RfidCode}一楼出库至老厂房完成");
                            }
                        }
                        // å°†å½“前站台的输送线信息添加到数据对象,只包含需要的字段
                        if (conveyorLineInfoRead != null)
                        {
                            simplifiedInfo["LineCode"] = device.DeviceCode;
                            simplifiedInfo["TaskNum"] = conveyorLineInfoRead.WR_Task; // ä»»åŠ¡å·
                            simplifiedInfo["RFID"] = conveyorLineInfoRead.WR_TMID;//RFID
                            simplifiedInfo["Width"] = conveyorLineInfoRead.WR_Width;//纸卷幅宽
                            simplifiedInfo["Request"] = conveyorLineInfoRead.WR_Request;//申请
                            simplifiedInfo["Reresult"] = conveyorLineInfoRead.WR_Reresult;//申请反馈
                            simplifiedInfo["HasGoods"] = conveyorLineInfoRead.WR_ToHode > 0; // æ˜¯å¦æœ‰è´§
                            ((Dictionary<string, Dictionary<string, object>>)conveyorLineCPData["ConveyorLineInfo"])[item.StationCode] = simplifiedInfo;
                        }
                    }
                    else if (deviceErrRead!=null)
                    {
                        errorYLDB = device.Communicator.ReadCustomer<R_ErrorYLDB>(deviceErrRead.DeviceProAddress);
                        if (errorYLDB != null && errorYLDB.R_Error==2)
                        {
                            ErrorDeviceInfo? errorDeviceInfo = RoadwayError.Roadways.FirstOrDefault(x=>x.Code==item.StationCode);
                            if (errorDeviceInfo==null)
                            {
                                RoadwayError.Roadways.Add(new ErrorDeviceInfo() { Code = item.StationCode, Roadway = item.StackerCraneCode });
                            }
                        }
                        else if(errorYLDB != null && errorYLDB.R_Error == 1)
                        {
                            ErrorDeviceInfo? deviceInfo = RoadwayError.Roadways.FirstOrDefault(x => x.Code == item.StationCode);
                            if (deviceInfo != null)
                            {
                                RoadwayError.Roadways.Remove(deviceInfo);
                            }
                        }
                        if (errorYLDB != null)
                        {
                            simplifiedInfo["Error"] = errorYLDB.R_Error;
                            ((Dictionary<string, Dictionary<string, object>>)conveyorLineCPData["ConveyorLineInfo"])[item.StationCode] = simplifiedInfo;
                        }
                    }
                    else
                    {
                        WriteError(item.StationName, $"未找到设备子编号{item.StationCode}的协议信息");
                    }
                }
                // é€šè¿‡WebSocket发送输送线数据到前端
                // åºåˆ—化数据
                string jsonData = JsonConvert.SerializeObject(conveyorLineCPData);
                // å‘送数据到所有客户端
                _webSocketServer.PublishAllClientPayload(jsonData);
                // è®°å½•发送日志
                WriteInfo(device.DeviceCode, $"WebSocket发送输送线数据:{jsonData}");
            }
            return Task.CompletedTask;
        }