dengjunjie
6 小时以前 90ac374a64e47e2bd97ee9245f4cafb50ad5dbbb
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskMethods.cs
@@ -1,7 +1,9 @@
using Autofac.Core;
using Magicodes.IE.Core;
using NetTaste;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
@@ -84,7 +86,7 @@
                                task.TaskState = (int)TaskStatusEnum.HktransportIng;
                                BaseDal.UpdateData(task);
                            }
                            else
                            else if (task.TaskState == (int)TaskStatusEnum.Execut)
                            {
                                task.TaskState = (int)TaskStatusEnum.Takeing;
                                TaskFeedback(task, 1);
@@ -105,19 +107,27 @@
                                    else
                                    {
                                        bool Work = false;
                                        if (device.IsConnected)
                                        try
                                        {
                                            int i = 0;
                                            while (!Work && i <= 3)
                                            if (device.IsConnected)
                                            {
                                                i++;
                                                Work = device.SetValue(HoistEnum.Inboundboxon, 1, task.TargetAddress);
                                                Thread.Sleep(500);
                                                int i = 0;
                                                while (!Work && i <= 3)
                                                {
                                                    i++;
                                                    Work = device.SetValue(HoistEnum.Inboundboxon, 1, task.TargetAddress);
                                                    Thread.Sleep(500);
                                                }
                                            }
                                            if (!Work)
                                            {
                                                task.ExceptionMessage = $"【{task.TargetAddress}】写入3楼入库箱放到位失败";
                                                task.Remark = $"{device.DeviceCode}_Inboundboxon_{1}_{task.TargetAddress}";
                                            }
                                        }
                                        if (!Work)
                                        catch (Exception ex)
                                        {
                                            task.ExceptionMessage = $"【{task.TargetAddress}】写入3楼入库箱放到位失败";
                                            task.ExceptionMessage = $"【{task.TargetAddress}】写入3楼入库箱放到位失败!{ex.Message}";
                                            task.Remark = $"{device.DeviceCode}_Inboundboxon_{1}_{task.TargetAddress}";
                                        }
                                    }
@@ -132,21 +142,30 @@
                                    else
                                    {
                                        bool Work = false;
                                        if (device.IsConnected)
                                        try
                                        {
                                            int i = 0;
                                            while (!Work && i <= 3)
                                            if (device.IsConnected)
                                            {
                                                i++;
                                                Work = device.SetValue(HoistEnum.Outboundboxon, 1, task.SourceAddress);//出库完成
                                                Thread.Sleep(500);
                                                int i = 0;
                                                while (!Work && i <= 3)
                                                {
                                                    i++;
                                                    Work = device.SetValue(HoistEnum.Outboundboxon, 1, task.SourceAddress);//出库完成
                                                    Thread.Sleep(500);
                                                }
                                            }
                                            if (!Work)
                                            {
                                                task.ExceptionMessage = $"【{task.SourceAddress}】写入3楼出库箱放到位失败";
                                                task.Remark = $"{device.DeviceCode}_Outboundboxon_{1}_{task.SourceAddress}";
                                            }
                                        }
                                        if (!Work)
                                        catch (Exception ex)
                                        {
                                            task.ExceptionMessage = $"【{task.SourceAddress}】写入3楼出库箱放到位失败";
                                            task.Remark = $"{device.DeviceCode}_Outboundboxon_{1}_{task.SourceAddress}";
                                            task.Remark = $"{device.DeviceCode}_Outboundboxon_{1}_{task.SourceAddress}"; throw;
                                        }
                                    }
                                    BaseDal.UpdateData(task);
                                }
@@ -158,21 +177,31 @@
                                    else
                                    {
                                        bool Work = false;
                                        if (device.IsConnected)
                                        try
                                        {
                                            int i = 0;
                                            while (!Work && i <= 3)
                                            if (device.IsConnected)
                                            {
                                                i++;
                                                Work = device.SetValue(HoistEnum.Emptyboxplacedinposition, 1, task.TargetAddress);
                                                Thread.Sleep(500);
                                                int i = 0;
                                                while (!Work && i <= 3)
                                                {
                                                    i++;
                                                    Work = device.SetValue(HoistEnum.Emptyboxplacedinposition, 1, task.TargetAddress);
                                                    Thread.Sleep(500);
                                                }
                                            }
                                            if (!Work)
                                            {
                                                task.ExceptionMessage = $"【{task.TargetAddress}】写入4楼空箱放到位失败";
                                                task.Remark = $"{device.DeviceCode}_Emptyboxplacedinposition_{1}_{task.TargetAddress}";
                                            }
                                        }
                                        if (!Work)
                                        catch (Exception ex)
                                        {
                                            task.ExceptionMessage = $"【{task.TargetAddress}】写入4楼空箱放到位失败";
                                            task.Remark = $"{device.DeviceCode}_Emptyboxplacedinposition_{1}_{task.TargetAddress}";
                                        }
                                    }
                                    BaseDal.UpdateData(task);
                                }
@@ -184,21 +213,31 @@
                                    else
                                    {
                                        bool Work = false;
                                        if (device.IsConnected)
                                        try
                                        {
                                            int i = 0;
                                            while (!Work && i <= 3)
                                            if (device.IsConnected)
                                            {
                                                i++;
                                                Work = device.SetValue(HoistEnum.Outboundboxretrievalcompleted, 1, task.SourceAddress);
                                                Thread.Sleep(500);
                                                int i = 0;
                                                while (!Work && i <= 3)
                                                {
                                                    i++;
                                                    Work = device.SetValue(HoistEnum.Outboundboxretrievalcompleted, 1, task.SourceAddress);
                                                    Thread.Sleep(500);
                                                }
                                            }
                                            if (!Work)
                                            {
                                                task.ExceptionMessage = $"【{task.SourceAddress}】写入4楼出库取箱完成失败";
                                                task.Remark = $"{device.DeviceCode}_Outboundboxretrievalcompleted_{1}_{task.SourceAddress}";
                                            }
                                        }
                                        if (!Work)
                                        catch (Exception ex)
                                        {
                                            task.ExceptionMessage = $"【{task.SourceAddress}】写入4楼出库取箱完成失败";
                                            task.Remark = $"{device.DeviceCode}_Outboundboxretrievalcompleted_{1}_{task.SourceAddress}";
                                        }
                                    }
                                    BaseDal.UpdateData(task);
                                }
@@ -211,21 +250,31 @@
                                    {
                                        bool Wok = false;
                                        var Address = task.TaskType == TaskTypeEnum.Q3RK.ObjToInt() ? task.TargetAddress : task.SourceAddress;
                                        if (device.IsConnected)
                                        try
                                        {
                                            int i = 0;
                                            while (!Wok && i <= 3)
                                            if (device.IsConnected)
                                            {
                                                i++;
                                                Wok = device.SetValue(QualityInspectionCommandEnum.RequestToEnter, false, Address);
                                                Thread.Sleep(500);
                                                int i = 0;
                                                while (!Wok && i <= 3)
                                                {
                                                    i++;
                                                    Wok = device.SetValue(QualityInspectionCommandEnum.RequestToEnter, false, Address);
                                                    Thread.Sleep(500);
                                                }
                                            }
                                            if (!Wok)
                                            {
                                                task.ExceptionMessage = $"【{Address}】关闭请求进入失败!";
                                                task.Remark = $"{device.DeviceCode}_RequestToEnter_{false}_{Address}";
                                            }
                                        }
                                        if (!Wok)
                                        catch (Exception ex)
                                        {
                                            task.ExceptionMessage = $"【{Address}】关闭请求进入失败!";
                                            task.Remark = $"{device.DeviceCode}_RequestToEnter_{false}_{Address}";
                                        }
                                    }
                                    BaseDal.UpdateData(task);
                                }
@@ -245,21 +294,31 @@
                                else
                                {
                                    bool Wok = false;
                                    if (device.IsConnected)
                                    try
                                    {
                                        int i = 0;
                                        while (!Wok && i <= 3)
                                        if (device.IsConnected)
                                        {
                                            i++;
                                            Wok = device.SetValue<HoistEnum, short>(HoistEnum.Codereadingtriggered, 1, "TSJR3F");
                                            Thread.Sleep(500);
                                            int i = 0;
                                            while (!Wok && i <= 3)
                                            {
                                                i++;
                                                Wok = device.SetValue<HoistEnum, short>(HoistEnum.Codereadingtriggered, 1, "TSJR3F");
                                                Thread.Sleep(500);
                                            }
                                        }
                                        if (!Wok)
                                        {
                                            task.ExceptionMessage = $"【TSJR3F】3楼读码触发失败!";
                                            task.Remark = $"{device.DeviceCode}_Codereadingtriggered_{1}_TSJR3F";
                                        }
                                    }
                                    if (!Wok)
                                    catch (Exception ex)
                                    {
                                        task.ExceptionMessage = $"【TSJR3F】3楼读码触发失败!";
                                        task.Remark = $"{device.DeviceCode}_Codereadingtriggered_{1}_TSJR3F";
                                    }
                                }
                                task.TaskState = (int)TaskStatusEnum.CheckPalletCodeing;
                                BaseDal.UpdateData(task);
@@ -293,7 +352,7 @@
                            break;
                        case "leavelift": //离开电梯
                            {
                                if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.MOVE || task.TaskType == (int)TaskTypeEnum.F01|| task.TaskType == (int)TaskTypeEnum.Q3CK)
                                if (task.TaskType == (int)TaskTypeEnum.Q3RK || task.TaskType == (int)TaskTypeEnum.MOVE || task.TaskType == (int)TaskTypeEnum.F01 || task.TaskType == (int)TaskTypeEnum.Q3CK)
                                {
                                    task.TaskState = TaskStatusEnum.HKleavelift.ObjToInt();
                                    BaseDal.UpdateData(task);
@@ -316,31 +375,40 @@
                    var task = BaseDal.QueryFirst(x => x.PalletCode == Rgv.content.podID);
                    if (task == null) throw new Exception($"未找到任务,任务编号【{Rgv.content.taskID}】");
                    //移库
                    if (task.TaskType == TaskTypeEnum.CPMoveInventory.ObjToInt() && Rgv.messageType == 10 && Rgv.content.status == 4)
                    if (task.TaskType == TaskTypeEnum.CPMoveInventory.ObjToInt() && string.IsNullOrEmpty(task.WMSTaskNum))
                    {
                        deviceName += "移库";
                        WMSMoveLocationFeedback wMSMoveLocationFeedback = new WMSMoveLocationFeedback()
                        if (Rgv.messageType == 72)
                        {
                            containerCode = task.PalletCode,
                            fromStationCode = task.SourceAddress,
                            toLocationCode = task.TargetAddress
                        };
                        Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(WMSMoveLocationFeedback));
                        WMSReturn agvContent = null;
                        if (apiInfo == null) task.ExceptionMessage = "未找到移库完成反馈WMS接口配置信息!请检查接口配置";
                        else
                            task.TaskState = TaskStatusEnum.TakeFinish.ObjToInt();
                            BaseDal.UpdateData(task);
                            UpdateLocationStatus(task.SourceAddress, task.PalletCode, deviceTypeEnum, LocationStatusEnum.Free);
                        }
                        if (Rgv.messageType == 10 && Rgv.content.status == 4)
                        {
                            task.TaskState = TaskStatusEnum.Finish.ObjToInt();
                            string response = HttpHelper.Post(apiInfo.ApiAddress, wMSMoveLocationFeedback.Serialize());
                            agvContent = response.DeserializeObject<WMSReturn>();
                            content.OK(data: agvContent);
                            if (agvContent.code != 200)
                            deviceName += "移库";
                            WMSMoveLocationFeedback wMSMoveLocationFeedback = new WMSMoveLocationFeedback()
                            {
                                task.ExceptionMessage = agvContent.message;
                                content.Error(agvContent.message);
                                containerCode = task.PalletCode,
                                fromStationCode = task.SourceAddress,
                                toLocationCode = task.TargetAddress
                            };
                            Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(WMSMoveLocationFeedback));
                            WMSReturn agvContent = null;
                            if (apiInfo == null) task.ExceptionMessage = "未找到移库完成反馈WMS接口配置信息!请检查接口配置";
                            else
                            {
                                task.TaskState = TaskStatusEnum.Finish.ObjToInt();
                                string response = HttpHelper.Post(apiInfo.ApiAddress, wMSMoveLocationFeedback.Serialize());
                                agvContent = response.DeserializeObject<WMSReturn>();
                                content.OK(data: agvContent);
                                if (agvContent.code != 200)
                                {
                                    task.ExceptionMessage = agvContent.message;
                                    content.Error(agvContent.message);
                                }
                                UpdateLocationStatus(task.TargetAddress, task.PalletCode, deviceTypeEnum, LocationStatusEnum.InStock);
                                BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.自动完成);
                            }
                            UpdateLocationStatus(task.TargetAddress, task.PalletCode, deviceTypeEnum, LocationStatusEnum.InStock);
                            BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.自动完成);
                        }
                    }
                    else
@@ -351,15 +419,18 @@
                            if (task.TaskType == (int)TaskTypeEnum.CPInbound && task.TaskState == (int)TaskStatusEnum.Execut)
                            {
                                task.TaskState = (int)TaskStatusEnum.WaiCheckShape;
                                //BaseDal.UpdateData(task);//给质检门写入启动信号
                                var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "F1") as OtherDevice;
                                if (device == null) task.ExceptionMessage = "未找到1楼质检门设备信息";
                                else
                                if (task.SourceAddress != "OUT-01")
                                {
                                    if (device.IsConnected)
                                        device.SetValue(QualityInspectionCommandEnum.StartqualityInspection, true, task.SourceAddress);
                                    //BaseDal.UpdateData(task);//给质检门写入启动信号
                                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "F1") as OtherDevice;
                                    if (device == null) task.ExceptionMessage = "未找到1楼质检门设备信息";
                                    else
                                        task.ExceptionMessage = "1楼质检门设备连接失败";
                                    {
                                        if (device.IsConnected)
                                            device.SetValue(QualityInspectionCommandEnum.StartqualityInspection, true, task.SourceAddress);
                                        else
                                            task.ExceptionMessage = "1楼质检门设备连接失败";
                                    }
                                }
                                TaskFeedback(task, 4);
                            }
@@ -396,16 +467,24 @@
                            {
                                task.ExceptionMessage = Rgv.content.errorReason;
                                var Error = _taskErrorMessageService.Repository.QueryFirst(x => x.ErrorCode == Rgv.content.errorCode && x.DeviceType == (int)deviceTypeEnum);
                                if (Error != null)
                                if (task.TaskType == (int)TaskTypeEnum.CPOutbound && task.TaskState == (int)TaskStatusEnum.Execut && Rgv.content.errorCode == 1330003)//成品出库任务下发后反馈有阻碍托,修改任务状态为新建重新查询阻碍托关系
                                {
                                    task.ExceptionMessage = Error.ExceptionMessage;
                                    MatchCollection matches = Regex.Matches(Rgv.content.errorReason, @"\(([^)]+)\)");
                                    if (matches.Count > 0)
                                        task.ExceptionMessage = ReplacePlaceholders(Rgv.content.errorReason, Error.ExceptionMessage);
                                    ErrorTaskFeedback(task, true, Error.ErrorCode.ToString());
                                    task.TaskState = (int)TaskStatusEnum.New;
                                    BaseDal.UpdateData(task);
                                }
                                else
                                    ErrorTaskFeedback(task, true);
                                {
                                    if (Error != null)
                                    {
                                        task.ExceptionMessage = Error.ExceptionMessage;
                                        MatchCollection matches = Regex.Matches(Rgv.content.errorReason, @"\(([^)]+)\)");
                                        if (matches.Count > 0)
                                            task.ExceptionMessage = ReplacePlaceholders(Rgv.content.errorReason, Error.ExceptionMessage);
                                        ErrorTaskFeedback(task, true, Error.ErrorCode.ToString());
                                    }
                                    else
                                        ErrorTaskFeedback(task, true);
                                }
                            }
                        }
                    }
@@ -637,38 +716,22 @@
                        dt_RGVLocationInfo.LocationStatus = locationStatusEnum.ObjToInt();
                        _rGVLocationInfoService.Repository.UpdateData(dt_RGVLocationInfo);
                    }
                }
                else//平库库位
                {
                }
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
        #region æ›´æ–°ä¸€æ¥¼ç«™å°çŠ¶æ€
        public WebResponseContent UpdateStandStatus(Dt_Task task, string stationCode, LocationStatusEnum locationStatusEnum)
        {
            try
            {
                Dt_StationManger? stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == task.TargetAddress);
                //stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
                if (stationManger != null)
                {
                    if (locationStatusEnum == LocationStatusEnum.Free) //如果起点完成就给货位赋值托盘号
                    Dt_StationManger stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == locationCode);
                    if (stationManger != null)
                    {
                        stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
                        if (locationStatusEnum == LocationStatusEnum.Free) //如果起点完成就给货位赋值托盘号
                        {
                            stationManger.Remark = "";
                            stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
                        }
                        else
                        {
                            stationManger.Remark = palletCode;
                            stationManger.IsOccupied = LocationStatusEnum.Lock.ObjToInt();
                        }
                        _stationMangerService.UpdateData(stationManger);
                    }
                    else
                    {
                        stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
                    }
                    _stationMangerService.UpdateData(stationManger);
                }
                return WebResponseContent.Instance.OK();
            }