Ejemplo n.º 1
0
        private RouteData StockCountCore(
            string StockInventoryId, DateTime StockCountDate, string WarehouseID, OutsideStockCountMaterial[] materials)
        {
            if (materials.Length == 0)
            {
                return(YL.Core.Dto.RouteData.From(PubMessages.E2204_STOCKCOUNT_MATERIAL_ZERO));
            }

            string        warehouseNo = string.IsNullOrWhiteSpace(WarehouseID) ? "A00" : WarehouseID;
            Wms_warehouse warehouse   = WMSApiManager.GetWarehouse(warehouseNo);

            if (warehouse == null)
            {
                return(YL.Core.Dto.RouteData.From(PubMessages.E1026_SUPPLIES_WAREHOUSEID_NOTFOUND, $"warehouseId = {warehouseNo}"));
            }
            long warehouseId          = warehouse.WarehouseId;
            IWMSBaseApiAccessor proxy = WMSApiManager.GetBaseApiAccessor(warehouseId.ToString(), _sqlClient);

            Wms_mestask mesTask = new Wms_mestask()
            {
                MesTaskId        = PubId.SnowflakeId,
                MesTaskType      = MESTaskTypes.StockCount,
                WarehousingId    = StockInventoryId,              //入库单编号
                WarehousingType  = String.Empty,                  //入库类型
                WarehousingTime  = StockCountDate,                //入库时间
                ProductionPlanId = String.Empty,                  //生产令号
                BatchPlanId      = String.Empty,                  //批次号
                WorkAreaName     = String.Empty,                  //作业区
                SuppliesKinds    = materials.Length,              //物料种类
                SuppliesInfoJson = "",                            // jsonSuppliesInfoStr, //物料信息
                WorkStatus       = MESTaskWorkStatus.WaitPlan,    //等待计划
                NotifyStatus     = MESTaskNotifyStatus.Requested, //已接收
                CreateDate       = DateTime.Now
            };
            RouteData result = null;

            try
            {
                result = proxy.StockCount(new OutsideStockCountRequestDto()
                {
                    MesTaskId    = mesTask.MesTaskId,
                    StockCountNo = StockInventoryId,
                    PlanDate     = StockCountDate.ToString(PubConst.Format_Date),
                    MaterialList = materials
                }).GetAwaiter().GetResult();
                if (result == null || !result.IsSccuess)
                {
                    mesTask.WorkStatus = MESTaskWorkStatus.Failed;
                    mesTask.Remark     = result.Message;
                }
            }
            catch (Exception ex)
            {
                mesTask.WorkStatus = MESTaskWorkStatus.Failed;
                mesTask.Remark     = ex.Message;
            }

            _mastaskServices.Insert(mesTask);
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <string> NofityStockIn(long mesTaskId)
        {
            Wms_mestask mesTask = await _sqlClient.Queryable <Wms_mestask>().FirstAsync(x => x.MesTaskId == mesTaskId);

            RouteData result = await _sqlClient.NofityStockIn(mesTask);

            return(JsonConvert.SerializeObject(result));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Detail(string id)
        {
            long searchId = id.ToInt64();

            if (id.IsEmptyZero())
            {
                return(Content(""));
            }
            else
            {
                Wms_mestask mesTask = await _client.Queryable <Wms_mestask>().FirstAsync(x => x.MesTaskId == SqlFunc.ToInt64(id));

                return(View(mesTask));
            }
        }
Ejemplo n.º 4
0
        public async Task <RouteData> StockInReport(long stockInId, [FromBody] OutsideStockInReportDto result)
        {
            try
            {
                _logger.LogInformation($"[入库任务状态变化通知]收到通知,StockInId={stockInId},data={JsonConvert.SerializeObject(result)}");
                result.StockInId = stockInId;
                Wms_stockin stockIn = await _client.Queryable <Wms_stockin>()
                                      .FirstAsync(x => x.StockInId == result.StockInId);

                if (stockIn == null)
                {
                    _logger.LogError($"[入库任务状态变化通知]E2013-没有找到入库单,StockInId={stockInId}");
                    return(YL.Core.Dto.RouteData.From(PubMessages.E2013_STOCKIN_NOTFOUND));
                }
                if (stockIn.StockInStatus == StockInStatus.task_finish.ToInt32())
                {
                    _logger.LogError($"[入库任务状态变化通知]E2014-入库单状态已标记为完成,本次操作中断,StockInId={stockInId}, StockInNo={stockIn.StockInNo}");
                    //return YL.Core.Dto.RouteData.From(PubMessages.E2014_STOCKIN_ALLOW_FINISHED);
                    return(new RouteData());
                }

                Wms_mestask mesTask = await _client.Queryable <Wms_mestask>()
                                      .FirstAsync(x => x.MesTaskId == stockIn.MesTaskId);

                if (mesTask == null)
                {
                    _logger.LogError($"[入库任务状态变化通知]E3000-没有找到相应的Mes任务,StockInId={stockInId}, StockInNo={stockIn.StockInNo}, MesTaskId={stockIn.MesTaskId}");
                    return(YL.Core.Dto.RouteData.From(PubMessages.E3000_MES_STOCKINTASK_NOTFOUND));
                }

                Wms_stockindetail[] details = _client.Queryable <Wms_stockindetail>()
                                              .Where(x => x.StockInId == result.StockInId).ToArray();

                _client.BeginTran();
                foreach (OutsideStockInReportDetail detail in result.Details)
                {
                    Wms_stockindetail localDetail = details.FirstOrDefault(
                        x => x.UniqueIndex == detail.UniqueIndex);
                    if (localDetail == null)
                    {
                        _client.RollbackTran();
                        _logger.LogError($"[入库任务状态变化通知]E2015-没有找到相应的物料,StockInId={stockInId}, StockInNo={stockIn.StockInNo} ,UniqueIndex ={ detail.UniqueIndex}");
                        return(YL.Core.Dto.RouteData.From(PubMessages.E2015_STOCKIN_HASNOT_MATERIAL, $"MaterialId={detail.MaterialId}"));
                    }
                    localDetail.PlanInQty    = detail.PlanInQty;
                    localDetail.ActInQty     = detail.ActInQty;
                    localDetail.Status       = detail.Status.ToInt32();
                    localDetail.ModifiedBy   = PubConst.InterfaceUserId;
                    localDetail.ModifiedUser = detail.ModifiedBy;
                    localDetail.ModifiedDate = Convert.ToDateTime(detail.ModifiedDate);
                    localDetail.Remark       = detail.Remark;
                    localDetail.ErrorId      = detail.ErrorId;
                    localDetail.ErrorInfo    = detail.ErrorInfo;
                }

                if (_client.Updateable(details).ExecuteCommand() == 0)
                {
                    _client.RollbackTran();
                    _logger.LogError($"[入库任务状态变化通知]E0002-任务明细更新失败,StockInId={stockInId}, StockInNo={stockIn.StockInNo}");
                    return(YL.Core.Dto.RouteData.From(PubMessages.E0002_UPDATE_COUNT_FAIL));
                }

                stockIn.StockInStatus = result.StockInStatus.ToInt32();
                stockIn.ModifiedBy    = PubConst.InterfaceUserId;
                stockIn.ModifiedUser  = PubConst.InterfaceUserName;

                if (_client.Updateable(stockIn).ExecuteCommand() == 0)
                {
                    _client.RollbackTran();
                    _logger.LogError($"[入库任务状态变化通知]E0002-任务更新失败,StockInId={stockInId}, StockInNo={stockIn.StockInNo}");
                    return(YL.Core.Dto.RouteData.From(PubMessages.E0002_UPDATE_COUNT_FAIL));
                }

                var anyWorking = await _client.Queryable <Wms_stockin>()
                                 .AnyAsync(x => x.MesTaskId == stockIn.MesTaskId &&
                                           x.StockInStatus != (int)StockInStatus.task_finish &&
                                           x.StockInStatus != (int)StockInStatus.task_canceled);

                if (!anyWorking)
                {
                    _logger.LogInformation($"[入库任务状态变化通知]所有相关任务已完成,尝试通知MES MesTaskId={stockIn.MesTaskId}");
                    await _client.NofityStockIn(mesTask);
                }
                else
                {
                    _logger.LogInformation($"[入库任务状态变化通知]尚有未完成任务,等待其余任务完成通知 MesTaskId={stockIn.MesTaskId}");
                }

                _logger.LogInformation($"[入库任务状态变化通知]通知处理正常完成,StockInId={stockInId}");
                _client.CommitTran();
                return(new RouteData());
            }
            catch (Exception ex)
            {
                _client.RollbackTran();
                _logger.LogError($"[入库任务状态变化通知]E-1-发生异常,处理结束 ex={ex.ToString()}");
                return(new RouteData()
                {
                    Code = -1, Message = ex.Message
                });
            }
        }
Ejemplo n.º 5
0
        //public OutsideWarehouseEntryStatusEnquiryResult WarehouseEntryStatusEnquiry(OutsideWarehouseEntryStatusEnquiryArg arg)
        public string WarehouseEntryStatusEnquiry(string WarehouseEntryId, string WarehouseEntryType)
        {
            var    request   = new { WarehouseEntryId, WarehouseEntryType };
            string resultStr = null;

            Wms_mestask mesTask = _sqlClient.Queryable <Wms_mestask>().First(x => x.WarehousingId == WarehouseEntryId && x.WarehousingType == WarehouseEntryType);

            if (mesTask == null)
            {
                OutsideWarehouseEntryStatusEnquiryResult error = new OutsideWarehouseEntryStatusEnquiryResult()
                {
                    Success   = "false",
                    ErrorId   = PubMessages.E3000_MES_STOCKINTASK_NOTFOUND.Code.ToString(),
                    ErrorInfo = PubMessages.E3000_MES_STOCKINTASK_NOTFOUND.Message
                };
                return(JsonConvert.SerializeObject(error));
            }

            var stockoutList = _sqlClient.Queryable <Wms_stockout, Wms_warehouse>(
                (s, w) => new object[] {
                JoinType.Left, s.WarehouseId == w.WarehouseId
            })
                               .Where((s, w) => s.MesTaskId == mesTask.MesTaskId)
                               .Select((s, w) => new
            {
                s.WarehouseId,
                w.WarehouseName,
                s.StockOutId,
                s.StockOutNo,
                s.StockOutStatus,
                s.StockOutType
            })
                               .ToList();
            List <WarehouseEntryStatusInfo> statusInfoList = new List <WarehouseEntryStatusInfo>();

            foreach (var stockin in stockoutList)
            {
                var stockoutDetailList = _sqlClient.Queryable <Wms_stockoutdetail, Wms_stockoutdetail_box, Wms_inventorybox, Wms_material>(
                    (sod, sodb, ib, m) => new object[] {
                    JoinType.Left, sod.StockOutDetailId == sodb.StockOutDetailId,
                    JoinType.Left, sodb.InventoryBoxId == ib.InventoryBoxId,
                    JoinType.Left, sod.MaterialId == m.MaterialId,
                }
                    )
                                         .Where((sod, sodb, ib, m) => sod.StockOutId == stockin.StockOutId)
                                         .Select((sod, sodb, ib, m) => new
                {
                    sod.WarehouseId,
                    sod.SubWarehouseEntryId,
                    sod.UniqueIndex,
                    sod.MaterialId,
                    m.MaterialNo,
                    m.MaterialOnlyId,
                    sod.StockOutDetailId,
                    InventoryBoxId = (int?)sodb.InventoryBoxId,
                    ib.InventoryBoxNo,
                    Position = (int?)sodb.Position,
                    Qty      = (int?)sodb.Qty,
                    sod.Status,
                    sod.CreateBy,
                    sod.CreateDate,
                    sod.ModifiedBy,
                    sod.ModifiedDate
                }).MergeTable().ToList();
                foreach (var detail in stockoutDetailList)
                {
                    statusInfoList.Add(new WarehouseEntryStatusInfo()
                    {
                        IsNormalWarehouseEntry   = detail.Status == StockInStatus.task_finish.ToByte(),
                        SubWarehouseEntryId      = detail.SubWarehouseEntryId,
                        UniqueIndex              = detail.UniqueIndex,
                        SuppliesId               = string.IsNullOrWhiteSpace(detail.MaterialOnlyId) ? detail.MaterialNo.ToString() : detail.MaterialOnlyId.ToString(),
                        RefreshStock             = 0,  //TODO
                        WorkAreaName             = "", //TODO
                        WarehouseEntryStep       = ((StockInStatus)detail.Status).ToString(),
                        WarehouseEntryFinishTime = detail.Status == StockInStatus.task_finish.ToByte() ? detail.ModifiedDate?.ToString("yyyy-MM-dd HH:mm:ss") : ""
                    });
                }
            }

            OutsideWarehouseEntryStatusEnquiryResult result = new OutsideWarehouseEntryStatusEnquiryResult()
            {
                Success   = "true",
                ErrorId   = null,
                ErrorInfo = null,
                //WarehouseEntryId = arg.WarehouseEntryId,
                //WarehouseEntryType = arg.WarehouseEntryType,
                WarehouseEntryStatusInfoList = statusInfoList.ToArray(),
                IsNormalWarehouseEntry       = mesTask.WorkStatus == MESTaskWorkStatus.WorkComplated,
            };

            resultStr = JsonConvert.SerializeObject(result);
            LogRequest("WarehouseEntryStatusEnquiry", request, resultStr);
            return(resultStr);
        }
Ejemplo n.º 6
0
        //public OutsideStockInResult Warehousing([FromBody]OutsideStockInDto data)
        public string Warehousing(string WarehousingId, string WarehousingType, string WarehousingTime, string ProductionPlanId, string BatchPlanId, string WorkAreaName, string SuppliesKinds, string SuppliesInfoList)
        {
            OutsideStockInDto data      = null;
            string            resultStr = null;

            try
            {
                data = OutsideStockInDto.Create(
                    Guard.GuardEmpty(() => WarehousingId),
                    Guard.GuardEmpty(() => WarehousingType),
                    Guard.GuardEmpty(() => WarehousingTime),
                    Guard.GuardEmpty(() => ProductionPlanId),
                    Guard.GuardEmpty(() => BatchPlanId),
                    Guard.GuardEmpty(() => WorkAreaName),
                    Guard.GuardInteger(() => SuppliesKinds),
                    Guard.GuardEmpty(() => SuppliesInfoList)
                    );

                _sqlClient.BeginTran();
                string jsonSuppliesInfoStr = data.SuppliesInfoList;
                OutsideWarehousingMaterialDto[] suppliesInfos = JsonConvert.DeserializeObject <OutsideWarehousingMaterialDto[]>(jsonSuppliesInfoStr);
                Wms_mestask mesTask = new Wms_mestask()
                {
                    MesTaskId        = PubId.SnowflakeId,
                    MesTaskType      = MESTaskTypes.StockIn,
                    WarehousingId    = data.WarehousingId,                       //入库单编号
                    WarehousingType  = data.WarehousingType,                     //入库类型
                    WarehousingTime  = Convert.ToDateTime(data.WarehousingTime), //入库时间
                    ProductionPlanId = data.ProductionPlanId,                    //生产令号
                    BatchPlanId      = data.BatchPlanId,                         //批次号
                    WorkAreaName     = data.WorkAreaName,                        //作业区
                    SuppliesKinds    = data.SuppliesKinds,                       //物料种类
                    SuppliesInfoJson = "",                                       // jsonSuppliesInfoStr, //物料信息
                    WorkStatus       = MESTaskWorkStatus.WaitPlan,               //等待计划
                    NotifyStatus     = MESTaskNotifyStatus.Requested,            //已接收
                    CreateDate       = DateTime.Now
                };
                _mastaskServices.Insert(mesTask);

                RouteData routeData = CreateWMSStockin(mesTask, suppliesInfos);
                if (!routeData.IsSccuess)
                {
                    _sqlClient.RollbackTran();
                    OutsideStockInResult result = new OutsideStockInResult()
                    {
                        ErrorId         = routeData.CodeString,
                        ErrorInfo       = routeData.Message,
                        Success         = false,
                        WarehousingId   = data.WarehousingId,
                        WarehousingTime = data.WarehousingTime
                    };
                    resultStr = JsonConvert.SerializeObject(result);
                    return(resultStr);
                }
                else
                {
                    _sqlClient.CommitTran();
                    OutsideStockInResult result = new OutsideStockInResult()
                    {
                        Success         = true,
                        ErrorId         = string.Empty,
                        ErrorInfo       = string.Empty,
                        WarehousingId   = data.WarehousingId,
                        WarehousingTime = data.WarehousingTime
                    };
                    resultStr = JsonConvert.SerializeObject(result);
                    return(resultStr);
                }
            }
            catch (Exception ex)
            {
                _sqlClient.RollbackTran();
                OutsideStockInResult result = new OutsideStockInResult()
                {
                    Success   = false,
                    ErrorId   = "-1",
                    ErrorInfo = ex.ToString()
                                //  WarehousingId = Warehousingid,
                                //  WarehousingTime = Warehousingtime
                };
                resultStr = JsonConvert.SerializeObject(result);
                return(resultStr);
            }
            finally {
                LogRequest("Warehousing", data, resultStr);
            }
        }
Ejemplo n.º 7
0
        private RouteData CreateWMSStockout(Wms_mestask mesTask, OutsideWarehouseEntryMaterialDto[] suppliesInfoList)
        {
            Dictionary <long, List <Wms_WarehouseEntryMaterialInventoryDto> > map =
                new Dictionary <long, List <Wms_WarehouseEntryMaterialInventoryDto> >();

            foreach (OutsideWarehouseEntryMaterialDto materialDto in suppliesInfoList)
            {
                //Sys_dict typeDict = _sqlClient.Queryable<Sys_dict>()
                //       .First(x => x.DictType == PubDictType.material.ToByte().ToString() && x.DictName == materialDto.SuppliesType);
                //if (typeDict == null)
                //{
                //    return RouteData<Wms_material>.From(PubMessages.E1001_SUPPLIESTYPE_NOTFOUND, $"SuppliesType = {materialDto.SuppliesType}");
                //}
                //else if (typeDict.WarehouseId == null)
                //{
                //    return RouteData<Wms_material>.From(PubMessages.E1002_SUPPLIESTYPE_WAREHOUSEID_NOTSET, $"SuppliesType = {materialDto.SuppliesType}");
                //}
                //long warehouseId = typeDict.WarehouseId.Value;


                string warehouseNo = string.IsNullOrWhiteSpace(materialDto.WarehouseId) ? "A00" : materialDto.WarehouseId;
                //MES的WarehouseID对应WMS的WarehouseNo
                Wms_warehouse warehouse = WMSApiManager.GetWarehouse(warehouseNo);
                if (warehouse == null)
                {
                    return(RouteData <Wms_material> .From(PubMessages.E1026_SUPPLIES_WAREHOUSEID_NOTFOUND, $"warehouseId = {warehouseNo}"));
                }
                long warehouseId = warehouse.WarehouseId;
                List <Wms_WarehouseEntryMaterialInventoryDto> warehouseMaterialList = null;
                if (map.ContainsKey(warehouseId))
                {
                    warehouseMaterialList = map[warehouseId];
                }
                else
                {
                    warehouseMaterialList = new List <Wms_WarehouseEntryMaterialInventoryDto>();
                    map.Add(warehouseId, warehouseMaterialList);
                }
                warehouseMaterialList.Add(new Wms_WarehouseEntryMaterialInventoryDto()
                {
                    MaterialId          = "-1",
                    SubWarehouseEntryId = materialDto.SubWarehouseEntryId,
                    UniqueIndex         = materialDto.UniqueIndex,
                    MaterialOnlyId      = materialDto.SuppliesOnlyId,
                    MaterialNo          = materialDto.SuppliesId,
                    MaterialName        = materialDto.SuppliesName,
                    MaterialType        = materialDto.SuppliesType,
                    Qty  = materialDto.SuppliesNumber,
                    Unit = materialDto.Unit
                });
            }

            List <RouteData> result = new List <RouteData>();

            foreach (KeyValuePair <long, List <Wms_WarehouseEntryMaterialInventoryDto> > keyValue in map)
            {
                try
                {
                    IWMSBaseApiAccessor       proxy   = WMSApiManager.GetBaseApiAccessor(keyValue.Key.ToString(), _sqlClient);
                    OutsideStockOutRequestDto request = new OutsideStockOutRequestDto()
                    {
                        MesTaskId          = mesTask.MesTaskId,
                        WarehouseEntryId   = mesTask.WarehousingId,
                        WarehouseEntryTime = mesTask.WarehousingTime.ToString(PubConst.Format_DateTime),
                        WarehouseEntryType = mesTask.WarehousingType,
                        WarehouseId        = keyValue.Key,
                        OrderNo            = mesTask.ProductionPlanId,
                        WorkNo             = mesTask.TotalWorkOrder,
                        BatchNumber        = mesTask.BatchNumber,
                        WorkAreaName       = mesTask.WorkAreaName,
                        WorkStationId      = mesTask.WorkStationId,
                        BatchPlanId        = mesTask.BatchPlanId,
                        MaterialList       = keyValue.Value.ToArray(),
                    };
                    _logger.LogInformation("小WMS的StockOut开始", "");
                    RouteData data = proxy.StockOut(request).GetAwaiter().GetResult();
                    _logger.LogInformation("小WMS的StockOut结束", "");
                    if (!data.IsSccuess)
                    {
                        string message = $"仓库{keyValue.Key}下发出库任务失败,Code={data.Code},Message={data.Message}";
                        _logger.LogError(message);
                        result.Add(data);
                        return(new RouteData()
                        {
                            Code = -1,
                            Message = message
                        });
                    }
                    else
                    {
                        _logger.LogInformation($"仓库{keyValue.Key}下发出库任务成功");
                    }
                }
                catch (Exception ex)
                {
                    string message = $"仓库{keyValue.Key}下发出库任务发生异常";
                    _logger.LogError(ex, message);
                    return(new RouteData()
                    {
                        Code = -1,
                        Message = message
                    });
                }
            }


            return(new RouteData());
        }
Ejemplo n.º 8
0
        //public OutsideStockOutResult WarehouseEntry([FromBody]OutsideStockOutDto data)
        public string WarehouseEntry(
            string WarehouseEntryId,
            string WarehouseEntryType,
            string WarehouseEntryTime,
            string ProductionPlanId,
            string TotalWorkOrder,
            string BatchNumber,
            string BatchPlanId,
            string WorkAreaName,
            string WorkStationId,
            string SuppliesKinds,
            string SuppliesInfoList)
        {
            string             resultStr = null;
            OutsideStockOutDto data      = null;

            try
            {
                data = OutsideStockOutDto.Create(
                    Guard.GuardEmpty(() => WarehouseEntryId),
                    Guard.GuardEmpty(() => WarehouseEntryType),
                    Guard.GuardEmpty(() => WarehouseEntryTime),
                    Guard.GuardEmpty(() => ProductionPlanId),
                    Guard.GuardEmpty(() => TotalWorkOrder),
                    Guard.GuardEmpty(() => BatchNumber),
                    Guard.GuardEmpty(() => BatchPlanId),
                    Guard.GuardEmpty(() => WorkAreaName),
                    Guard.GuardEmpty(() => WorkStationId),
                    Guard.GuardInteger(() => SuppliesKinds),
                    Guard.GuardEmpty(() => SuppliesInfoList)
                    );


                _sqlClient.BeginTran();
                string jsonSuppliesInfoStr = data.SuppliesInfoList;
                OutsideWarehouseEntryMaterialDto[] suppliesInfos = JsonConvert.DeserializeObject <OutsideWarehouseEntryMaterialDto[]>(jsonSuppliesInfoStr);
                Wms_mestask mesTask = new Wms_mestask()
                {
                    MesTaskId        = PubId.SnowflakeId,
                    MesTaskType      = MESTaskTypes.StockOut,
                    WarehousingId    = data.WarehouseEntryId,                       //入库单编号
                    WarehousingType  = data.WarehouseEntryType,                     //入库类型
                    WarehousingTime  = Convert.ToDateTime(data.WarehouseEntryTime), //入库时间
                    ProductionPlanId = data.ProductionPlanId,                       //生产令号
                    TotalWorkOrder   = data.TotalWorkOrder,
                    BatchNumber      = data.BatchNumber,
                    BatchPlanId      = data.BatchPlanId,              //批次号
                    WorkAreaName     = data.WorkAreaName,             //作业区
                    WorkStationId    = data.WorkStationId,            //工位号
                    SuppliesKinds    = data.SuppliesKinds,            //物料种类
                    SuppliesInfoJson = "",                            //jsonSuppliesInfoStr, //物料信息
                    WorkStatus       = MESTaskWorkStatus.WaitPlan,    //等待计划
                    NotifyStatus     = MESTaskNotifyStatus.Requested, //已接收
                    CreateDate       = DateTime.Now
                };
                if (_sqlClient.Insertable(mesTask).ExecuteCommand() == 0)
                {
                    throw new Exception("mesTask更新异常");
                }

                RouteData routeData = CreateWMSStockout(mesTask, suppliesInfos);
                if (!routeData.IsSccuess)
                {
                    _sqlClient.RollbackTran();
                    OutsideStockOutResult result = new OutsideStockOutResult()
                    {
                        ErrorId          = routeData.CodeString,
                        ErrorInfo        = routeData.Message,
                        Success          = false,
                        WarehouseEntryId = data.WarehouseEntryId,
                        //WarehouseEntryTime = data.WarehouseEntryTime
                    };
                    return(JsonConvert.SerializeObject(result));
                }
                else
                {
                    _sqlClient.CommitTran();
                    OutsideStockOutResult result = new OutsideStockOutResult()
                    {
                        Success          = true,
                        ErrorId          = string.Empty,
                        ErrorInfo        = string.Empty,
                        WarehouseEntryId = data.WarehouseEntryId,
                        //WarehouseEntryTime = data.WarehouseEntryTime
                    };
                    resultStr = JsonConvert.SerializeObject(result);
                    return(resultStr);
                }
            }
            catch (Exception ex)
            {
                _sqlClient.RollbackTran();
                OutsideStockOutResult result = new OutsideStockOutResult()
                {
                    Success   = false,
                    ErrorId   = "-1",
                    ErrorInfo = ex.ToString(),
                    //WarehouseEntryId = warehouseEntryid,
                    //WarehouseEntryTime = data.WarehouseEntryTime
                };
                resultStr = JsonConvert.SerializeObject(result);
                return(resultStr);
            }
            finally {
                this.LogRequest("WarehouseEntry", data, resultStr);
            }
        }
        /// <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));
            }
        }
        public static async Task <RouteData> ConfirmRelationStockOut(
            this ISqlSugarClient client, long inventoryBoxTaskId, SysUserDto user)
        {
            List <Wms_stockoutdetail_box> stockOutDeltailBoxs =
                await client.Queryable <Wms_stockoutdetail_box>().Where(x => x.InventoryBoxTaskId == inventoryBoxTaskId).ToListAsync();

            if (stockOutDeltailBoxs.Count == 0)
            {
                return(new RouteData()); //如果没有相关任务则不做处理
            }
            List <long> confiredStockOutIds = new List <long>();

            foreach (Wms_stockoutdetail_box detailbox in stockOutDeltailBoxs)
            {
                Wms_stockoutdetail stockOutDetail =
                    await client.Queryable <Wms_stockoutdetail>().Where(x => x.StockOutDetailId == detailbox.StockOutDetailId).FirstAsync();

                if (stockOutDetail == null)
                {
                    continue;
                }
                if (stockOutDetail.Status == (int)StockOutStatus.task_finish)
                {
                    continue;
                }
                if (stockOutDetail.ActOutQty < stockOutDetail.PlanOutQty)
                {
                    continue;
                }
                stockOutDetail.Status       = (int)StockOutStatus.task_finish;
                stockOutDetail.ModifiedBy   = user.UserId;
                stockOutDetail.ModifiedUser = user.UserName;
                stockOutDetail.ModifiedDate = DateTime.Now;
                if (client.Updateable(stockOutDetail).ExecuteCommand() == 0)
                {
                    continue;
                }

                if (!confiredStockOutIds.Contains(stockOutDetail.StockOutId.Value))
                {
                    confiredStockOutIds.Add(stockOutDetail.StockOutId.Value);
                }
            }

            foreach (long stockOutId in confiredStockOutIds)
            {
                bool hasWorking = await client.Queryable <Wms_stockoutdetail>().AnyAsync(x => x.StockOutId == stockOutId && x.Status != (int)StockInStatus.task_finish);

                if (!hasWorking)
                {
                    Wms_stockout stockout = await client.Queryable <Wms_stockout>().FirstAsync(x => x.StockOutId == stockOutId);

                    if (stockout == null)
                    {
                        continue;
                    }
                    stockout.StockOutStatus = (int)StockOutStatus.task_finish;
                    stockout.ModifiedBy     = user.UserId;
                    stockout.ModifiedUser   = user.UserName;
                    stockout.ModifiedDate   = DateTime.Now;
                    if (client.Updateable(stockout).ExecuteCommand() == 0)
                    {
                        //LOG
                    }

                    bool anyWorking = await client.Queryable <Wms_stockout>()
                                      .AnyAsync(x => x.MesTaskId == stockout.MesTaskId &&
                                                x.StockOutStatus != (int)StockOutStatus.task_finish &&
                                                x.StockOutStatus != (int)StockOutStatus.task_canceled);

                    if (!anyWorking)
                    {
                        Wms_mestask mesTask = await client.Queryable <Wms_mestask>()
                                              .FirstAsync(x => x.MesTaskId == stockout.MesTaskId);

                        if (mesTask == null)
                        {
                            //正常不可能
                            return(YL.Core.Dto.RouteData.From(PubMessages.E3100_MES_STOCKOUTTASK_NOTFOUND));
                        }
                        try
                        {
                            //通知处理无论成功失败不影响后续处理
                            await client.NofityStockOut(mesTask);
                        }
                        catch { }
                    }
                }
            }
            return(new RouteData());
        }