1
huangxiaoqiang
2025-12-25 544014da344afc67f1671cdc38f4f732890e10c8
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -591,6 +591,7 @@
            _stockService.StockInfoService.Db.UpdateNav(stock).IncludesAllFirstLayer().ExecuteCommand();
            task.TaskStatus = (int)TaskStatusEnum.Finish;
            var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.自动完成);
            if (!result)
            {
@@ -718,6 +719,9 @@
                {
                    return content.Error("未找到入智仓的物料信息");
                }
                string Operator = allocateMaterialInfos.FirstOrDefault().Creater;
                _unitOfWorkManage.BeginTran();
                var alldelete = _allocateMaterialInfo.DeleteAndMoveIntoHty(allocateMaterialInfos ,OperateTypeEnum.自动删除);
                if (!alldelete)
@@ -744,19 +748,21 @@
                }
                Dt_OutboundOrder outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo).Includes(x=>x.Details).First();
                if(outboundOrder.OrderStatus == OutOrderStatusEnum.出库完成.ObjToInt())
                ///回调MES
                HttpResponseResult<MesResponseDTO> httpResponseResult = new HttpResponseResult<MesResponseDTO>();
                string reqCode = Guid.NewGuid().ToString();
                string reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string requestData = string.Empty;
                List<string> lineNos = new List<string>();
                if (outboundOrder.OrderStatus == OutOrderStatusEnum.出库完成.ObjToInt())
                {
                    HttpResponseResult<MesResponseDTO> httpResponseResult = new HttpResponseResult<MesResponseDTO>();
                    string reqCode = Guid.NewGuid().ToString();
                    string reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    string requestData = string.Empty;
                    List<string> lineNos = new List<string>();
                    Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo);
                    if (allocateOrder == null)
                    {
                        return WebResponseContent.Instance.Error($"未找到对应的调拨单");
                    }
                    AllocationReturnDTO? returnDTO = BuildAllocationFeedbackData(outboundOrder, allocateOrder.FromWarehouse, allocateOrder.ToWarehouse);
                    AllocationReturnDTO? returnDTO = BuildAllocationFeedbackData(outboundOrder, allocateOrder.FromWarehouse, allocateOrder.ToWarehouse, Operator);
                    if (returnDTO == null)
                    {
                        return WebResponseContent.Instance.Error($"构建回调对象失败");
@@ -773,6 +779,72 @@
                    httpResponseResult = _httpClientHelper.Post<MesResponseDTO>(apiUrl, requestData);
                    httpResponseResult.ApiUrl = apiUrl;
                }
                bool isSuccess = httpResponseResult.IsSuccess && httpResponseResult.Data.Code == "200";
                string message = "成功";
                if (!isSuccess)
                {
                    if (!httpResponseResult.IsSuccess)
                    {
                        message = $"MES接口返回错误,HTTP代码:{httpResponseResult.StatusCode},信息:{httpResponseResult.ErrorMessage}";
                    }
                    else if (httpResponseResult?.Data?.Code != "200")
                    {
                        message = $"调用MES接口失败,代码:{httpResponseResult?.Data?.Code},信息:{httpResponseResult?.Data?.Message}";
                    }
                }
                Dt_MesReturnRecord mesReturnRecord = new Dt_MesReturnRecord()
                {
                    ApiUrl = httpResponseResult.ApiUrl,
                    InterfaceType = outboundOrder.OrderType == 0 ? 1 : 3,
                    OrderId = outboundOrder.Id,
                    OrderNo = outboundOrder.OrderNo,
                    RequestCode = reqCode,
                    RequestData = requestData,
                    FailureReason = message,
                    LastReturnTime = DateTime.Now,
                    HttpStatusCode = httpResponseResult.StatusCode.ObjToInt(),
                    ResponseData = httpResponseResult.Content,
                    ReturnType = 0,
                    ReturnCount = 1,
                    ReturnStatus = isSuccess ? 1 : 2,
                    SuccessTime = isSuccess ? DateTime.Now : null
                };
                _unitOfWorkManage.BeginTran();
                _unitOfWorkManage.Db.Insertable(mesReturnRecord).ExecuteCommand();
                List<Dt_OutboundOrderDetail> outboundOrderDetails = outboundOrder.Details.Where(x => lineNos.Contains(x.lineNo)).ToList();
                outboundOrderDetails.ForEach(x =>
                {
                    if (x.OverOutQuantity == x.OrderQuantity - x.MoveQty)
                    {
                        x.ReturnToMESStatus = isSuccess ? 1 : 2;
                    }
                    else
                    {
                        x.ReturnToMESStatus = isSuccess ? 3 : 4;
                    }
                    x.CurrentDeliveryQty = 0;
                    x.ReturnJsonData = "";
                });
                mesReturnRecord.ReturnType = outboundOrder.Details.Count == outboundOrderDetails.Count ? 1 : 2;
                if (outboundOrder.Details.Count == outboundOrderDetails.Count && outboundOrderDetails.All(x => x.ReturnToMESStatus == 1 || x.ReturnToMESStatus == 2))
                {
                    outboundOrder.ReturnToMESStatus = isSuccess ? 1 : 2;
                }
                else
                {
                    outboundOrder.ReturnToMESStatus = isSuccess ? 3 : 4;
                }
                _outboundOrderService.Db.Updateable(outboundOrderDetails).ExecuteCommand();
                _outboundOrderService.UpdateData(outboundOrder);
                _unitOfWorkManage.CommitTran();
                try
                {
                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
@@ -790,7 +862,7 @@
            }
        }
        public AllocationReturnDTO? BuildAllocationFeedbackData(Dt_OutboundOrder outboundOrder, string fromWarehouse, string toWarehouse)
        public AllocationReturnDTO? BuildAllocationFeedbackData(Dt_OutboundOrder outboundOrder, string fromWarehouse, string toWarehouse,string Operator)
        {
            try
            {
@@ -825,10 +897,10 @@
                    Details = returnDetails,
                    FactoryArea = outboundOrder.FactoryArea,
                    OperationType = 1,
                    OrderNo = outboundOrder.OrderNo,
                    OrderNo = outboundOrder.UpperOrderNo,
                    FromWarehouse = fromWarehouse,
                    ToWarehouse = toWarehouse,
                    Operator = App.User.UserName
                    Operator = Operator
                };
                return outboundReturnDTO;
@@ -1773,5 +1845,10 @@
            }
        }
        public Task<WebResponseContent> HandCompleteTask(string TaskNum)
        {
            return TaskCompleted(TaskNum);
        }
    }
}