dengjunjie
2025-05-20 be484c84a25d1f6c769e7b5e958048d745942e55
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/ConveyorLineExtend/ConveyorLineExtend.cs
@@ -7,9 +7,12 @@
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_DTO.WMSInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_Tasks.ConveyorLineJob;
namespace WIDESEAWCS_Tasks
@@ -24,32 +27,52 @@
        public List<Task> ConveyorLineExtend(CommonConveyorLine conveyorLine)
        {
            List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
            List<string> strings = new List<string>() { "1003", "1006", "1007" };
            childDeviceCodes.AddRange(strings);
            List<Task> tasks = new List<Task>();
            foreach (string childDeviceCode in childDeviceCodes)
            {
                try
                {
                    ConveyorLineTaskCommandR command = conveyorLine.ReadCustomer<ConveyorLineTaskCommandR>(childDeviceCode);
                    if (command != null && command.Status == (ushort)ConveyorStatus.Stored)//添加输送线状态ConveyorLineStatus enum
                    _cacheService.AddOrUpdate(childDeviceCode, command);
                    if (command != null)
                    {
                        switch (childDeviceCode)
                        if (childDeviceCode == "1002" && command.Status == (ushort)ConveyorStatus.Wait)
                        {
                            case "102":
                                RequestInbound(conveyorLine, command, childDeviceCode);
                                break;
                            case "104":
                                ConveyorLineInFinish(conveyorLine, command, childDeviceCode);
                                break;
                            //case "105":
                            //    RequestOutbound(conveyorLine, command, childDeviceCode);
                            //    break;
                            case "108":
                                ConveyorLineOutFinish(conveyorLine, command, childDeviceCode);
                                break;
                                //default:
                                //    RequestInNextAddress(conveyorLine, command, childDeviceCode);
                                //    RequestOutNextAddress(conveyorLine, command, childDeviceCode);
                                //    break;
                            RequestInbound(conveyorLine, command, childDeviceCode);
                        }
                        else if (childDeviceCode == "1004" && command.Status == (ushort)ConveyorStatus.Stored)
                        {
                            ConveyorLineInFinish(conveyorLine, command, childDeviceCode);
                        }
                        else if (childDeviceCode == "1008" && command.Status == (ushort)ConveyorStatus.Stored)
                        {
                            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
                            if (task != null)
                            {
                                #region MyRegion
                                //List<Dt_Router> routers = _routerRepository.QueryData(x => x.StartPosi == task.TargetAddress && x.ChildPosiDeviceCode == "AGV" && x.Remark == "未占用");
                                //if (routers != null && routers.Count > 0)
                                //{
                                //    var router = routers.FirstOrDefault();
                                //    if (router != null)
                                //    {
                                //        task.TaskState = TaskOutStatusEnum.Line_OutFinish.ObjToInt();
                                //        task.CurrentAddress = childDeviceCode;
                                //        task.NextAddress = router.NextPosi;
                                //        task.TargetAddress = task.NextAddress;
                                //        router.Remark = "占用";
                                //        _routerRepository.UpdateData(router);
                                //        _taskService.UpdateData(task);
                                //    }
                                //}
                                #endregion
                                task.TaskState = TaskOutStatusEnum.OutFinish.ObjToInt();
                                WMSTaskDTO WMStask = _mapper.Map<WMSTaskDTO>(task);
                                _taskService.AddTask_Hty(task, TaskOperateTypeEnum.AutoComplete);
                                HttpHelper.PostAsync(WMSInterfaceAddress.UpdateTaskStatus, WMStask.ToJson(), headers: new Dictionary<string, string>());
                            }
                        }
                    }
                }
@@ -71,8 +94,20 @@
        public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
        {
            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode, command.Barcode);
            //Dt_Task task = _taskService.QueryConveyorLineTaskNum(conveyorLine.DeviceCode, childDeviceCode, command.TaskNum);
            if (task != null)
            {
                if (command.Spec > 0)
                {
                    DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == command.Spec.ToString() && x.DeviceProParamName == nameof(ConveyorLineTaskCommandR.Spec));
                    string? Des = deviceProtocolDetail?.ProtocolDetailDes;
                    if (Des != task.ExceptionMessage)
                    {
                        task.ExceptionMessage = deviceProtocolDetail?.ProtocolDetailDes;
                        _taskService.UpdateData(task);
                    }
                    return;
                }
                ConveyorLineDTO lineDTO = new ConveyorLineDTO()
                {
                    TaskNum = task.TaskNum,
@@ -82,31 +117,50 @@
                    Weight = command.Weight,
                };
                var content = _taskService.RequestWMSTask(lineDTO);
                if (content.Status)
                if (!content.Status)
                {
                    task.CurrentAddress = childDeviceCode;
                    task.NextAddress = AppSettings.Configuration["OKAddress"];
                    task.ExceptionMessage = null;
                    ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
                    taskCommand.WriterTrue = 1;
                    if (conveyorLine.SendCommand(taskCommand, childDeviceCode))
                        _taskService.UpdateTaskStatusToNext(task);
                    task.ExceptionMessage = content?.Message;
                    _taskService.UpdateData(task);
                    return;
                }
                else
                //if (content.Status)
                //{
                task.CurrentAddress = childDeviceCode;
                List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.TargetAddress);
                if (routers.Count > 0)
                {
                    //if (content.Code == 404)//修改终点地址
                    //{
                    task.CurrentAddress = childDeviceCode;
                    task.NextAddress = AppSettings.Configuration["NGAddress"];
                    task.ExceptionMessage = content.Message;
                    task.TaskState = (int)TaskInStatusEnum.InException;
                    ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
                    taskCommand.WriterTrue = 1;
                    if (conveyorLine.SendCommand(taskCommand, childDeviceCode)) _taskService.UpdateData(task);
                    //}
                    task.NextAddress = routers.FirstOrDefault().ChildPosi;
                }
                //task.NextAddress = AppSettings.Configuration["OKAddress"];
                task.ExceptionMessage = null;
                ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
                taskCommand.WriterTrue = (short)command.inRead;
                if (conveyorLine.SendCommand(taskCommand, childDeviceCode))
                    _taskService.UpdateTaskStatusToNext(task);
                //}
                //else
                //{
                //    //if (content.Code == 404)//修改终点地址
                //    //{
                //    task.CurrentAddress = childDeviceCode;
                //    task.NextAddress = AppSettings.Configuration["NGAddress"];
                //    task.ExceptionMessage = content.Message;
                //    task.TaskState = (int)TaskInStatusEnum.InException;
                //    ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
                //    taskCommand.WriterTrue = 1;
                //    if (conveyorLine.SendCommand(taskCommand, childDeviceCode)) _taskService.UpdateData(task);
                //    //}
                //}
            }
            else
            {
                Dt_Task _Task = new Dt_Task();
                _Task.TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss"));
                _Task.CurrentAddress = childDeviceCode;
                _Task.NextAddress = "1001";
                ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(_Task);
                taskCommand.WriterTrue = (short)command.inRead;
            }
        }
@@ -142,7 +196,7 @@
            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.Barcode, childDeviceCode);
            if (task != null) _taskService.UpdateTaskStatusToNext(task);
            task = _taskService.QueryCompletedConveyorLineTask(command.TaskNum, childDeviceCode);
            task = _taskService.QueryCompletedConveyorLineTask(command.Barcode, childDeviceCode);
            if (task != null && string.IsNullOrEmpty(task.TargetAddress))
            {
                _taskService.StackerCraneRequestInbound(task);