dengjunjie
2026-03-13 ee1a08f59b6c532be931dae4d0d485cf77ae01af
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskMethods.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Reflection.Metadata;
using System.Text;
using System.Text.Json;
@@ -59,7 +60,8 @@
                            break;
                        default:
                            task.TaskState = ReturnTaskStatus(gALAXIS.taskStatus, deviceTypeEnum);
                            BaseDal.UpdateData(task);
                            if (gALAXIS.taskStatus == 10) TaskFeedback(task, 1);
                            else BaseDal.UpdateData(task);
                            break;
                    }
                }
@@ -71,11 +73,15 @@
                    if (task == null) throw new Exception($"未找到任务,任务编号【{hIKROBOT.robotTaskCode}】");
                    switch (hIKROBOT.extra.values.method)
                    {
                        case "start":
                        case "end":
                            TaskCompleted(task, deviceTypeEnum);
                            break;
                        case "end":
                        case "outbin":
                            TaskFromCompleted(task, deviceTypeEnum);
                            break;
                        case "start":
                            task.TaskState = (int)TaskStatusEnum.Takeing;
                            TaskFeedback(task, 1);
                            break;
                        default:
                            task.TaskState = ReturnTaskStatus(hIKROBOT.extra.values.method, deviceTypeEnum);
@@ -90,31 +96,65 @@
                    //var task = BaseDal.QueryFirst(x => x.RGVTaskId == Rgv.content.taskID);
                    var task = BaseDal.QueryFirst(x => x.PalletCode == Rgv.content.podID);
                    if (task == null) throw new Exception($"未找到任务,任务编号【{Rgv.content.taskID}】");
                    if (Rgv.messageType == 72)//小车顶起货物
                    if (task.TaskType == TaskTypeEnum.CPMoveInventory.ObjToInt())
                    {
                        TaskFromCompleted(task, deviceTypeEnum);
                        //给质检门写入启动信号
                        var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "F1") as OtherDevice ?? throw new Exception("未找到1楼质检门设备信息");
                        device.SetValue(QualityInspectionCommandEnum.StartqualityInspection, true, task.SourceAddress);
                    }
                    else if (Rgv.messageType == 10)
                    else
                    {
                        if (task.TaskState == (int)TaskStatusEnum.TakeFinish && Rgv.content.status == 4)
                        if (Rgv.messageType == 72)//小车顶起货物
                        {
                            task.TaskState = (int)TaskStatusEnum.CheckShapeing;
                            BaseDal.UpdateData(task);
                            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 (device.IsConnected)
                                        device.SetValue(QualityInspectionCommandEnum.StartqualityInspection, true, task.SourceAddress);
                                    else
                                        task.ExceptionMessage = "1楼质检门设备连接失败";
                                }
                                TaskFeedback(task, 4);
                            }
                            else
                            {
                                TaskFromCompleted(task, deviceTypeEnum);
                            }
                        }
                        else if (task.TaskState == (int)TaskStatusEnum.Puting && Rgv.content.status == 4)
                        else if (Rgv.messageType == 10)
                        {
                            TaskCompleted(task, deviceTypeEnum);
                            if (Rgv.content.status == 2) TaskFeedback(task, 1);
                            if (Rgv.content.status == 4)
                            {
                                if (task.TaskType == (int)TaskTypeEnum.CPInbound && task.TaskState == (int)TaskStatusEnum.TakeFinish)
                                {
                                    if (!string.IsNullOrEmpty(task.ExceptionMessage)) task.TaskState = TaskStatusEnum.CheckShapeingNG.ObjToInt();
                                    else task.TaskState = (int)TaskStatusEnum.CheckShapeing;
                                    BaseDal.UpdateData(task);
                                }
                                else if (task.TaskType == (int)TaskTypeEnum.CPInbound && task.TaskState == (int)TaskStatusEnum.Puting)
                                {
                                    if (!string.IsNullOrEmpty(task.ExceptionMessage))
                                        ErrorTaskFeedback(task, true/*!task.ExceptionMessage.Contains("外检失败")*/);
                                    else
                                        TaskCompleted(task, deviceTypeEnum);
                                }
                                else if (task.TaskType == (int)TaskTypeEnum.CPOutbound || task.TaskType == (int)TaskTypeEnum.CPMoveInventory)//出库、移库完成
                                {
                                    TaskCompleted(task, deviceTypeEnum);
                                }
                            }
                        }
                    }
                }
                return content.OK();
                content.OK();
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
                content.Error(ex.Message);
            }
            finally
            {
@@ -143,6 +183,7 @@
                    _trackloginfoService.AddTrackLog(logObject, content, $"下发{deviceName}任务", "", "");
                }
            }
            return content;
        }
        #endregion
@@ -200,10 +241,11 @@
            try
            {
                dt_Task.TaskState = TaskStatusEnum.TakeFinish.ObjToInt();
                Db.Ado.BeginTran();
                TaskFeedback(dt_Task, 4);
                //Db.Ado.BeginTran();
                UpdateLocationStatus(dt_Task.SourceAddress, dt_Task.PalletCode, deviceTypeEnum, LocationStatusEnum.Free);
                BaseDal.UpdateData(dt_Task);
                Db.Ado.CommitTran();
                //BaseDal.UpdateData(dt_Task);
                //Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
@@ -225,45 +267,17 @@
        {
            try
            {
                WMSInOutBoundCompleteFeedback boundCompleteFeedback = new WMSInOutBoundCompleteFeedback();
                WMSReturn agvContent = null;
                dt_Task.TaskState = TaskStatusEnum.Finish.ObjToInt();
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(WMSInOutBoundCompleteFeedback));
                if (apiInfo == null) dt_Task.ExceptionMessage = "未找到出入库完成反馈WMS接口配置信息!请检查接口配置";
                else
                {
                    boundCompleteFeedback.taskCode = dt_Task.WMSTaskNum;
                    boundCompleteFeedback.containerCode = dt_Task.PalletCode;
                    boundCompleteFeedback.fromStationCode = dt_Task.SourceAddress;
                    boundCompleteFeedback.toLocationCode = dt_Task.TargetAddress;
                    switch (deviceTypeEnum)
                    {
                        case DeviceTypeEnum.GALAXIS:
                            boundCompleteFeedback.businessType = 1;
                            break;
                        case DeviceTypeEnum.YuanLiJuHe:
                            boundCompleteFeedback.businessType = 2;
                            break;
                    }
                    boundCompleteFeedback.completeType = 1;
                    string response = HttpHelper.Post(apiInfo.ApiAddress, boundCompleteFeedback.Serialize());
                    agvContent = response.DeserializeObject<WMSReturn>();
                    if (agvContent.code != 0) dt_Task.ExceptionMessage = agvContent.msg;
                }
                Db.Ado.BeginTran();
                TaskFeedback(dt_Task, 2);
                //Db.Ado.BeginTran();
                UpdateLocationStatus(dt_Task.TargetAddress, dt_Task.PalletCode, deviceTypeEnum, LocationStatusEnum.InStock);
                if (agvContent != null && agvContent.code == 0)
                    BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动完成);
                else
                    BaseDal.UpdateData(dt_Task);
                Db.Ado.CommitTran();
                //Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                //Db.Ado.RollbackTran();
                throw new Exception(ex.Message);
            }
        }
@@ -346,5 +360,92 @@
            }
        }
        #endregion
        #region ä¸ŠæŠ¥WMS
        public WebResponseContent TaskFeedback(Dt_Task dt_Task, int Status)
        {
            WebResponseContent content = new WebResponseContent();
            WMSInOutBoundCompleteFeedback boundCompleteFeedback = new WMSInOutBoundCompleteFeedback();
            WMSReturn agvContent = null;
            try
            {
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(WMSInOutBoundCompleteFeedback));
                if (apiInfo == null) dt_Task.ExceptionMessage = "未找到出入库完成反馈WMS接口配置信息!请检查接口配置";
                else
                {
                    boundCompleteFeedback.taskCode = dt_Task.WMSTaskNum;
                    boundCompleteFeedback.containerCode = dt_Task.PalletCode;
                    boundCompleteFeedback.fromStationCode = dt_Task.SourceAddress;
                    boundCompleteFeedback.toLocationCode = dt_Task.TargetAddress;
                    boundCompleteFeedback.status = Status;
                    boundCompleteFeedback.custStatus = "";
                    string response = HttpHelper.Post(apiInfo.ApiAddress, boundCompleteFeedback.Serialize());
                    agvContent = response.DeserializeObject<WMSReturn>();
                    content.OK(data: agvContent);
                    if (agvContent.code != 200)
                    {
                        dt_Task.ExceptionMessage = agvContent.message;
                        content.Error(agvContent.message);
                    }
                }
            }
            catch (Exception ex)
            {
                dt_Task.ExceptionMessage = ex.Message;
            }
            finally
            {
                _trackloginfoService.AddTrackLog(boundCompleteFeedback, content, "出入库任务状态反馈WMS", "", "");
                if (agvContent != null && agvContent.code == 200 && Status == 2)
                    BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动完成);
                else
                    BaseDal.UpdateData(dt_Task);
            }
            return WebResponseContent.Instance.OK();
        }
        #endregion
        #region å¤±è´¥ä»»åŠ¡ä¸ŠæŠ¥WMS并删除任务
        public WebResponseContent ErrorTaskFeedback(Dt_Task dt_Task, bool Del)
        {
            WebResponseContent content = new WebResponseContent();
            WMSInOutBoundCompleteFeedback boundCompleteFeedback = new WMSInOutBoundCompleteFeedback();
            WMSReturn agvContent = null;
            try
            {
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(WMSInOutBoundCompleteFeedback));
                if (apiInfo == null) dt_Task.ExceptionMessage = "未找到出入库完成反馈WMS接口配置信息!请检查接口配置";
                else
                {
                    boundCompleteFeedback.taskCode = dt_Task.WMSTaskNum;
                    boundCompleteFeedback.containerCode = dt_Task.PalletCode;
                    boundCompleteFeedback.fromStationCode = dt_Task.SourceAddress;
                    boundCompleteFeedback.toLocationCode = dt_Task.TargetAddress;
                    boundCompleteFeedback.status = 3;
                    boundCompleteFeedback.custStatus = "";
                    boundCompleteFeedback.memo = dt_Task.ExceptionMessage;
                    string response = HttpHelper.Post(apiInfo.ApiAddress, boundCompleteFeedback.Serialize());
                    agvContent = response.DeserializeObject<WMSReturn>();
                    content.OK(data: agvContent);
                    if (agvContent.code != 200)
                    {
                        dt_Task.ExceptionMessage = agvContent.message;
                        content.Error(agvContent.message);
                    }
                }
            }
            catch (Exception ex)
            {
                dt_Task.ExceptionMessage = ex.Message;
                content.Error(ex.Message);
            }
            finally
            {
                _trackloginfoService.AddTrackLog(boundCompleteFeedback, content, "出入库任务状态反馈WMS", "", "");
                if (agvContent != null && agvContent.code == 200 && Del) BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动删除);
                else BaseDal.UpdateData(dt_Task);
            }
            return content;
        }
        #endregion
    }
}