Exemple #1
0
        public OutsideStockOutResponseResult ConfirmOutStockMES(OutsideStockOutResponse obj)
        {
            OutsideStockOutResponseResult retModel = new OutsideStockOutResponseResult();

            retModel.WarehouseEntryId  = obj.WarehouseEntryId;
            retModel.IsNormalExecution = true;
            _eventBus.Post(new KeyValuePair <OutsideStockOutResponse, OutsideStockOutResponseResult>(obj, retModel), TimeSpan.Zero);
            return(retModel);
        }
        /// <summary>
        /// 通知MES出库完成
        /// </summary>
        /// <param name="stockOutId"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static async Task <RouteData> NofityStockOut(this ISqlSugarClient client, Wms_mestask mesTask)
        {
            mesTask.ModifiedDate = DateTime.Now;
            mesTask.WorkStatus   = MESTaskWorkStatus.WorkComplated;
            mesTask.NotifyStatus = MESTaskNotifyStatus.WaitResponse;

            try
            {
                List <Wms_stockout> stockOuts = await client.Queryable <Wms_stockout>().Where(x => x.MesTaskId == mesTask.MesTaskId).ToListAsync();

                List <OutsideStockOutResponseWarehouse> warehouseList = new List <OutsideStockOutResponseWarehouse>();
                foreach (Wms_stockout stockOut in stockOuts)
                {
                    OutsideStockOutResponseWarehouse warehouse = warehouseList.FirstOrDefault(x => x.WarehouseId == stockOut.WarehouseId.ToString());
                    if (warehouse == null)
                    {
                        warehouse = new OutsideStockOutResponseWarehouse()
                        {
                            //WarehouseId = stockOut.WarehouseId.ToString(),
                            WarehouseId              = WMSApiManager.GetWarehouse(stockOut.WarehouseId).WarehouseNo,
                            WarehouseName            = "", //TODO
                            WarehousePosition        = "", //TODO
                            WorkAreaName             = mesTask.WorkAreaName,
                            WarehouseEntryFinishTime = stockOut.ModifiedDate.Value.ToString("yyyy-MM-dd HH:mm:ss"),
                        };
                        warehouseList.Add(warehouse);
                    }
                    List <Wms_stockoutdetail> stockOutDetails = await client.Queryable <Wms_stockoutdetail>().Where(x => x.StockOutId == stockOut.StockOutId).ToListAsync();

                    foreach (Wms_stockoutdetail stockOutDetail in stockOutDetails)
                    {
                        OutsideMaterialResult material = new OutsideMaterialResult()
                        {
                            UniqueIndex    = stockOutDetail.UniqueIndex,
                            SuppliesId     = stockOutDetail.MaterialNo.ToString(),
                            SuppliesName   = stockOutDetail.MaterialName,
                            SuppliesNumber = stockOutDetail.ActOutQty.ToString(),
                            RefreshStock   = stockOutDetail.ActOutQty.ToString(),
                            ErrorId        = stockOutDetail.ErrorId,
                            ErrorInfo      = stockOutDetail.ErrorInfo
                        };
                        warehouse.SuppliesInfoList.Add(material);
                        warehouse.SuppliesKinds = warehouse.SuppliesInfoList.Count;
                    }
                }

                OutsideStockOutResponse response = new OutsideStockOutResponse()
                {
                    WarehouseEntryId          = mesTask.WarehousingId,
                    WarehouseEntryFinishCount = warehouseList.Count,
                    WarehouseEntryFinishList  = JsonConvert.SerializeObject(warehouseList)
                };

                SelfReservoirAreaManager._logger.Info($"[通知MES出库完成]开始通知MES,param={JsonConvert.SerializeObject(response)}");
                OutsideStockOutResponseResult result = await MESApiAccessor.Instance.WarehouseEntryFinish(response);

                SelfReservoirAreaManager._logger.Info($"[通知MES出库完成]通知MES成功,result={JsonConvert.SerializeObject(result)}");
                if (String.IsNullOrWhiteSpace(result.IsNormalExecution))
                {
                    mesTask.NotifyStatus = MESTaskNotifyStatus.Responsed;
                    mesTask.Remark       = $"";
                }
                else
                {
                    mesTask.NotifyStatus = MESTaskNotifyStatus.Failed;
                    mesTask.Remark       = $"Error={result.IsNormalExecution}";
                }
            }
            catch (Exception ex)
            {
                //_logger.LogError(ex, "出库完成通知时发生异常");
                //逻辑继续,寻找其它时机重新通知
                mesTask.NotifyStatus = MESTaskNotifyStatus.Failed;
                mesTask.Remark       = $"Error={ex.Message}";
                SelfReservoirAreaManager._logger.Error($"[通知MES出库完成]通知MES时发生异常,{ex.ToString()}");
            }

            if (client.Updateable(mesTask).ExecuteCommand() == 0)
            {
                SelfReservoirAreaManager._logger.Error($"[通知MES入库完成]E-0002-更新状态失败");
                return(YL.Core.Dto.RouteData.From(PubMessages.E0002_UPDATE_COUNT_FAIL));
            }

            SelfReservoirAreaManager._logger.Info($"[通知MES入库完成]更新状态成功,NotifyStatus={mesTask.NotifyStatus}");
            if (mesTask.NotifyStatus == MESTaskNotifyStatus.Responsed)
            {
                return(new RouteData());
            }
            else
            {
                return(YL.Core.Dto.RouteData.From(PubMessages.E3101_MES_STOCKOUT_NOFITY_FAIL));
            }
        }