´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/TSJJob.cs
@@ -14,6 +14,7 @@
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.LocationEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core.Helper;
@@ -33,10 +34,13 @@
    {
        private readonly ITaskService _taskService;
        private readonly IStationMangerService _stationMangerService;
        public TSJJob(ITaskService taskService, IStationMangerService stationMangerService)
        private readonly IStationInfoService _stationInfoService;
        public TSJJob(ITaskService taskService, IStationMangerService stationMangerService, IStationInfoService stationInfoService)
        {
            _taskService = taskService;//注入
            _stationMangerService = stationMangerService;
            _stationInfoService = stationInfoService;
        }
        public Task Execute(IJobExecutionContext context)
@@ -69,12 +73,12 @@
                            continue;
                            //throw new Exception("设备故障");
                        }
                        if (task.TaskType == TaskTypeEnum.RK3F.ObjToInt()|| task.TaskType == TaskTypeEnum.CHUKU1.ObjToInt())
                        if (task.TaskType == TaskTypeEnum.RK3F.ObjToInt() || task.TaskType == TaskTypeEnum.CHUKU1.ObjToInt() || task.TaskType == TaskTypeEnum.F04.ObjToInt())
                        {
                            if (task.TaskType == TaskTypeEnum.RK3F.ObjToInt())
                            {
                                //判断3楼入库箱号有无
                                if (device.GetValue<HoistEnum, short>(HoistEnum.OutboundInplace, task.SourceAddress) != 2)
                                if (device.GetValue<HoistEnum, short>(HoistEnum.OutboundInplace, task.TargetAddress) != 2)
                                {
                                    if (task.ExceptionMessage == "3楼入库箱号有货,请先处理")
                                    {
@@ -87,27 +91,15 @@
                            }
                            else
                            {
                                //回空箱的时候要读一个吗
                                if (device.GetValue<HoistEnum, string>(HoistEnum.Emptycontainernumber, task.SourceAddress) == null)
                                if (device.GetValue<HoistEnum, short>(HoistEnum.ReturnbinAvailable, task.TargetAddress) != 2)
                                {
                                    if (task.ExceptionMessage != "4楼空箱,读码器没有读到值")
                                    if (task.ExceptionMessage != "4F提升机入口有货")
                                    {
                                        task.ExceptionMessage = "4楼空箱,读码器没有读到值";
                                        task.ExceptionMessage = "4F提升机入口有货";
                                        Uptasks.Add(task);
                                    }
                                    continue;
                                }
                                //判断4楼空箱到位
                                if (device.GetValue<HoistEnum, short>(HoistEnum.ReturnbinAvailable, task.SourceAddress) == 2)
                                {
                                    if (task.ExceptionMessage != "TSJ4楼回料箱为空")
                                    {
                                        task.ExceptionMessage = "TSJ4楼回料箱为空";
                                        Uptasks.Add(task);
                                    }
                                    continue;
                                }
                            }
@@ -115,7 +107,7 @@
                            var result = _taskService.Hikvisiontaskscontinue(task.WMSTaskNum);
                            if (result.Status == false)
                            {
                                if (task.ExceptionMessage!= result.Message)
                                if (task.ExceptionMessage != result.Message)
                                {
                                    task.ExceptionMessage = result.Message;
                                    Uptasks.Add(task);
@@ -129,23 +121,49 @@
                            //这里任务变成了CheckPalletCodeing
                        }
                        else if(task.TaskType == TaskTypeEnum.CK3F.ObjToInt()) //出库
                        else if (task.TaskType == TaskTypeEnum.CK3F.ObjToInt() || task.TaskType == TaskTypeEnum.Q1TSJ4.ObjToInt() || task.TaskType == TaskTypeEnum.F03.ObjToInt()) //出库
                        {
                            ////出库料箱缓存数量(这个是库区查询的时候要查一下,返给wms)
                            //if (device.GetValue<HoistEnum, short>(HoistEnum.Outboundmaterialbox, "TSJ") == 0) throw new Exception("没有出库料箱缓存数量为空");
                            //读取3楼出库料箱到位
                            if (device.GetValue<HoistEnum, short>(HoistEnum.SOutboundmaterialbox, task.TargetAddress) != 1)
                            if (task.TaskType == TaskTypeEnum.CK3F.ObjToInt())
                            {
                                if (task.ExceptionMessage != "3楼出库料箱没有到位")
                                //读取3楼出库料箱到位
                                if (device.GetValue<HoistEnum, short>(HoistEnum.SOutboundmaterialbox, task.SourceAddress) != 1)
                                {
                                    task.ExceptionMessage = "3楼出库料箱没有到位";
                                    Uptasks.Add(task);
                                    if (task.ExceptionMessage != "3楼提升机出口光电反馈无货")
                                    {
                                        task.ExceptionMessage = "3楼提升机出口光电反馈无货";
                                        Uptasks.Add(task);
                                    }
                                    continue;
                                }
                                continue;
                            }
                            else
                            {
                                if (device.GetValue<HoistEnum, short>(HoistEnum.FOutboundmaterialbox, task.SourceAddress) != 1)
                                {
                                    if (task.ExceptionMessage != "4楼提升机出口光电反馈无货")
                                    {
                                        task.ExceptionMessage = "4楼提升机出口光电反馈无货";
                                        Uptasks.Add(task);
                                    }
                                    continue;
                                }
                                if (device.GetValue<HoistEnum, short>(HoistEnum.ROutScanningCompletionSignal, task.SourceAddress) != 1)
                                {
                                    if (task.ExceptionMessage != "4楼提升机出口扫码完成信号没有完成")
                                    {
                                        task.ExceptionMessage = "4楼提升机出口扫码完成信号没有完成";
                                        Uptasks.Add(task);
                                    }
                                    continue;
                                }
                            }
                            //然后调用输送线接口,通知输送线有料箱需要入库,任务举行执行
                            var result = _taskService.Hikvisiontaskscontinue(task.WMSTaskNum);
                            if (result.Status == false)
                            if (result.Status == false)
                            {
                                if (task.ExceptionMessage != result.Message)
                                {
@@ -158,72 +176,94 @@
                            task.ExceptionMessage = "";
                            Uptasks.Add(task);
                        }
                        else if (task.TaskType == TaskTypeEnum.Q1TSJ4.ObjToInt())//和3楼出库中一样;
                        {
                            #region 4楼出库
                            //4楼出库料箱到位
                            if (device.GetValue<HoistEnum, short>(HoistEnum.FOutboundmaterialbox, task.TargetAddress) != 2)
                            {
                                if (task.ExceptionMessage != "4楼出库料箱没有到位")
                                {
                                    task.ExceptionMessage = "3楼入库箱号有货,请先处理";
                                    Uptasks.Add(task);
                                }
                                continue;
                            }
                            #endregion
                            task.TaskState = (int)TaskStatusEnum.AGV_ToExecute;
                            task.ExceptionMessage = "";
                            Uptasks.Add(task);
                        }
                        //else if (task.TaskType == TaskTypeEnum.CHUKU1.ObjToInt()) //四楼库内到提升机
                        //{
                        //}
                    }
                    //查找三楼入库任务状态为CheckPalletCodeing的任务托盘号确认中
                    var RK3FTasks = _taskService.Repository.QueryFirst(x => x.TaskType == TaskTypeEnum.RK3F.ObjToInt() && x.TaskState == (int)TaskStatusEnum.CheckPalletCodeing);
                    if (RK3FTasks!=null)
                    {
                        var Barcode = device.SetValue<HoistEnum, short>(HoistEnum.Codereadingtriggered, 1);
                        //检查3楼入库箱号是多少,然后传给wms
                        var BinNumber = device.GetValue<HoistEnum, string>(HoistEnum.Inboxnumber, "TSJ");
                        //根据读到的箱号进行料箱检验,检验通过就触发读码器读取,如果不通过就抛出异常
                        //var Verification = _taskService.MaterialBoxInspection(RK3FTasks.WMSTaskNum, BinNumber.ToString());
                        //if (!Verification.Status)
                        //{
                        //    if (!(RK3FTasks.ExceptionMessage == Verification.Message))
                        //    {
                        //        RK3FTasks.ExceptionMessage = Verification.Message;
                        //        Uptasks.Add(RK3FTasks);
                        //    }
                        //    //料箱验证写好后,需要更改
                        //    RK3FTasks.TargetAddress = Verification.Data.ToString();
                        //}
                        //如果料箱检验成功就写入读码器的值
                        var result = _taskService.Hikvisiontaskscontinue(RK3FTasks.WMSTaskNum, RK3FTasks.TargetAddress);
                        if (result.Status == false)
                        {
                            if (RK3FTasks.ExceptionMessage != result.Message)
                            {
                                RK3FTasks.ExceptionMessage = result.Message;
                                Uptasks.Add(RK3FTasks);
                            }
                        }
                        RK3FTasks.TaskState = (int)TaskStatusEnum.CheckPalletCodeFinish;
                        Uptasks.Add(RK3FTasks);
                    }
                    if (Uptasks.Count > 0)
                    {
                        _taskService.UpdateData(Uptasks);
                    }
                    WriteInfo(device.DeviceName, "infoLog");
                    WriteDebug(device.DeviceName, "debugLog");
                    #region æ‰˜ç›˜å·ç¡®è®¤ä¸­
                    //查找三楼入库任务状态为CheckPalletCodeing的任务托盘号确认中
                    var RK3FTask = _taskService.Repository.QueryFirst(x => x.TaskType == TaskTypeEnum.RK3F.ObjToInt() && x.TaskState == (int)TaskStatusEnum.CheckPalletCodeing);
                    if (RK3FTask != null)
                    {
                        if (device.GetValue<HoistEnum, short>(HoistEnum.RInScanningCompletionSignal, RK3FTask.TargetAddress) != 1)
                        {
                            RK3FTask.ExceptionMessage = "3楼扫码完成信号没有完成";
                            _taskService.UpdateData(RK3FTask);
                        }
                        else //完成就把任务状态改成托盘号确认完成
                        {
                            //检查3楼入库箱号是多少,然后传给wms
                            var BinNumber = device.GetValue<HoistEnum, string>(HoistEnum.Inboxnumber, RK3FTask.TargetAddress);
                            if (!string.IsNullOrEmpty(BinNumber))
                            {
                                BinNumber = BinNumber.TrimEnd('\0').Substring(2);
                                //根据读到的箱号进行料箱检验,检验通过就触发读码器读取,如果不通过就抛出异常
                                var Verification = _taskService.MaterialBoxInspection(RK3FTask.WMSTaskNum, BinNumber);
                                if (!Verification.Status)
                                {
                                    if (RK3FTask.ExceptionMessage != Verification.Message)
                                    {
                                        RK3FTask.ExceptionMessage = Verification.Message;
                                        _taskService.UpdateData(RK3FTask);
                                    }
                                }
                                else
                                {
                                    //如果质检通过就不改变RK3FTask.TargetAddress的值,
                                    if (!string.IsNullOrEmpty(Verification.Message))
                                    {
                                        //寻找平库货位
                                        var Location = _stationInfoService.Repository.QueryFirst(x=>x.StationRegion==Verification.Message.ObjToInt()&&x.StationStatus==(int)LocationStatusEnum.Free&&x.FloorNumber=="CC"&&x.IsOccupied==(int)LocationStatusEnum.Free);
                                        //这里要判断
                                        if (Location==null)
                                        {
                                            RK3FTask.ExceptionMessage = "$未找到{Verification.Message}区域的货位{Location}";
                                        }
                                        RK3FTask.CurrentAddress = RK3FTask.TargetAddress;
                                        RK3FTask.NextAddress = Location.StationCode;
                                        RK3FTask.TargetAddress = Location.StationCode;
                                        _taskService.UpdateData(RK3FTask);
                                    }
                                        //调用海康进行执行完成接口
                                        var result = _taskService.Hikvisiontaskscontinue(RK3FTask.WMSTaskNum, RK3FTask.NextAddress);
                                    if (result.Status)
                                    {
                                        RK3FTask.ExceptionMessage = "";
                                        RK3FTask.TaskState = (int)TaskStatusEnum.CheckPalletCodeFinish;
                                        _taskService.UpdateData(RK3FTask);
                                    }
                                    else
                                    {
                                        if (RK3FTask.ExceptionMessage != result.Message)
                                        {
                                            RK3FTask.ExceptionMessage = result.Message;
                                            _taskService.UpdateData(RK3FTask);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                    #region 4F提升机出口托盘号上报WMS
                    var Address = "TSJC4F";
                    if (device.GetValue<HoistEnum, short>(HoistEnum.ROutScanningCompletionSignal, Address) == 1)
                    {
                        var BinNumber = device.GetValue<HoistEnum, string>(HoistEnum.Emptycontainernumber, Address);
                        if (!string.IsNullOrEmpty(BinNumber))
                        {
                            BinNumber = BinNumber.TrimEnd('\0').Substring(2);
                            _taskService.InboundElevatorExit(Address, BinNumber);
                        }
                    }
                    #endregion
                    //WriteInfo(device.DeviceName, "infoLog");
                    //WriteDebug(device.DeviceName, "debugLog");
                }
                catch (Exception ex)
                {
@@ -232,7 +272,7 @@
            }
            else
            {
                WriteError(nameof(TestJob), "参数错误,未传递设备参数或设备类型错误");
                WriteError(nameof(TSJJob), "参数错误,未传递设备参数或设备类型错误");
            }