Esempio 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);
        }
Esempio n. 2
0
        //public OutsideWarehousingStatusEnquiryResult WarehousingStatusEnquiry(OutsideWarehousingStatusEnquiryArg arg)
        public string WarehousingStatusEnquiry(string WarehousingId, string WarehousingType)
        {
            var         request   = new { WarehousingId, WarehousingType };
            string      resultStr = null;
            Wms_mestask mesTask   = _sqlClient.Queryable <Wms_mestask>().First(x => x.WarehousingId == WarehousingId && x.WarehousingType == WarehousingType);

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

            var stockinList = _sqlClient.Queryable <Wms_stockin, 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.StockInId,
                s.StockInNo,
                s.StockInStatus,
                s.StockInType
            })
                              .ToList();

            List <WarehousingStatusInfo> statusInfoList = new List <WarehousingStatusInfo>();

            foreach (var stockin in stockinList)
            {
                var stockinDetailList = _sqlClient.Queryable <Wms_stockindetail, Wms_stockindetail_box, Wms_inventorybox, Wms_material>(
                    (sid, sidb, ib, m) => new object[] {
                    JoinType.Left, sid.StockInDetailId == sidb.StockinDetailId,
                    JoinType.Left, sidb.InventoryBoxId == ib.InventoryBoxId,
                    JoinType.Left, sid.MaterialId == m.MaterialId,
                }
                    )
                                        .Where((sid, sidb, ib, m) => sid.StockInId == stockin.StockInId)
                                        .Select((sid, sidb, ib, m) => new
                {
                    sid.WarehouseId,
                    sid.SubWarehousingId,
                    sid.UniqueIndex,
                    sid.MaterialId,
                    m.MaterialNo,
                    m.MaterialOnlyId,
                    sid.StockInDetailId,
                    InventoryBoxId = (int?)sidb.InventoryBoxId,
                    ib.InventoryBoxNo,
                    Position = (int?)sidb.Position,
                    Qty      = (int?)sidb.Qty,
                    sid.Status,
                    sid.CreateBy,
                    sid.CreateDate,
                    sid.ModifiedBy,
                    sid.ModifiedDate
                }).MergeTable().ToList();
                foreach (var detail in stockinDetailList)
                {
                    statusInfoList.Add(new WarehousingStatusInfo()
                    {
                        IsNormalWarehousing = detail.Status == StockInStatus.task_finish.ToByte(),
                        //WarehouseId = detail.WarehouseId.ToString(),
                        WarehouseId           = WMSApiManager.GetWarehouse(detail.WarehouseId).WarehouseNo,
                        WarehousePosition     = null,
                        WarehouseName         = stockin.WarehouseName,
                        InventoryBoxNo        = detail.InventoryBoxNo,
                        Position              = Convert.ToString(detail.Position),//TODO
                        StorageRackPosition   = "",
                        SubWarehousingId      = detail.SubWarehousingId,
                        UniqueIndex           = detail.UniqueIndex,
                        SuppliesId            = string.IsNullOrWhiteSpace(detail.MaterialOnlyId) ? detail.MaterialNo.ToString() : detail.MaterialOnlyId.ToString(),
                        RefreshStock          = 0, //TODO
                        WarehousingStep       = ((StockInStatus)detail.Status).ToString(),
                        WarehousingFinishTime = detail.Status == StockInStatus.task_finish.ToByte() ? detail.ModifiedDate?.ToString("yyyy-MM-dd HH:mm:ss") : ""
                    });
                }
            }

            OutsideWarehousingStatusEnquiryResult result = new OutsideWarehousingStatusEnquiryResult()
            {
                Success   = "true",
                ErrorId   = null,
                ErrorInfo = null,
                //WarehousingId = WarehousingId,
                //WarehousingType = warehousingType,
                WarehousingStatusInfoList = statusInfoList.ToArray(),
                IsNormalWarehousing       = mesTask.WorkStatus == MESTaskWorkStatus.WorkComplated,
            };

            resultStr = JsonConvert.SerializeObject(result);
            this.LogRequest("WarehousingStatusEnquiry", request, result);
            return(resultStr);
        }
Esempio n. 3
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());
        }