public static AscmWmsMtlRequisitionMainService GetInstance()
 {
     if (ascmWmsMtlRequisitionMainService == null)
     {
         ascmWmsMtlRequisitionMainService = new AscmWmsMtlRequisitionMainService();
     }
     return(ascmWmsMtlRequisitionMainService);
 }
Example #2
0
        /// <summary>发料校验</summary>
        public List <AscmWmsStoreIssueCheck> GetWmsLedStoreIssueCheck()
        {
            List <AscmWmsStoreIssueCheck> listStoreIssueCheck = new List <AscmWmsStoreIssueCheck>();
            //获取当天的领料单
            string whereOther = "";

            whereOther = YnBaseClass2.Helper.StringHelper.SqlWhereAndAdd(whereOther, "createTime>='" + DateTime.Now.ToString("yyyy-MM-dd 00:00:00") + "'");
            whereOther = YnBaseClass2.Helper.StringHelper.SqlWhereAndAdd(whereOther, "createTime<'" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00") + "'");
            whereOther = YnBaseClass2.Helper.StringHelper.SqlWhereAndAdd(whereOther, "checkOutNo>0");

            List <AscmWmsMtlRequisitionMain> listRequisitionMain = AscmWmsMtlRequisitionMainService.GetInstance().GetList(null, "", "", "", whereOther);

            if (listRequisitionMain == null || listRequisitionMain.Count == 0)
            {
                return(listStoreIssueCheck);
            }
            AscmWmsMtlRequisitionMainService.GetInstance().SetWipDiscreteJobs(listRequisitionMain, true, true, false, false);
            //获取当天的领料明细
            List <AscmWmsMtlRequisitionDetail> listRequisitionDetail = AscmWmsMtlRequisitionDetailService.GetInstance().GetList(listRequisitionMain);

            if (listRequisitionDetail == null || listRequisitionDetail.Count == 0)
            {
                return(listStoreIssueCheck);
            }
            //获取领料单与备料单关联
            List <AscmWmsMtlReqMainLink> listReqMainLink = AscmWmsMtlRequisitionMainService.GetInstance().GetReqMainLinkList(listRequisitionMain);
            //获取备料容器
            List <AscmWmsContainerDelivery> listContainerDelivery = AscmWmsContainerDeliveryService.GetInstance().GetList(listReqMainLink.Select(P => P.reqMainLinkPK.preMainId).ToList(), "");

            //按领料员分组
            var result = listRequisitionMain.Where(P => !string.IsNullOrEmpty(P.workerId)).GroupBy(P => P.workerId);

            foreach (IGrouping <string, AscmWmsMtlRequisitionMain> ig in result)
            {
                //按领料次数分组
                var result2 = ig.GroupBy(P => P.checkOutNo);
                foreach (IGrouping <int, AscmWmsMtlRequisitionMain> ig2 in result2)
                {
                    AscmWmsStoreIssueCheck storeIssueCheck = new AscmWmsStoreIssueCheck();
                    storeIssueCheck.workerId    = ig.Key;
                    storeIssueCheck.checkTime   = ig2.First().checkTime;
                    storeIssueCheck.times       = ig2.Key;
                    storeIssueCheck.destination = ig2.First().jobScheduleGroupsName;
                    listStoreIssueCheck.Add(storeIssueCheck);

                    //获取应发容器
                    List <AscmWmsContainerDelivery> listContainerDeliverySub = new List <AscmWmsContainerDelivery>();
                    foreach (AscmWmsMtlRequisitionMain requisitionMain in ig2)
                    {
                        List <AscmWmsMtlRequisitionDetail> listRequisitionDetailSub = listRequisitionDetail.Where(P => P.mainId == requisitionMain.id).ToList();
                        storeIssueCheck.shouldMaterialNum += listRequisitionDetailSub.Sum(P => P.quantity);
                        //考虑相同作业、相同物料、取自不同货位,所以应按物料分组
                        var detailResult = listRequisitionDetailSub.GroupBy(P => P.materialId);
                        foreach (IGrouping <int, AscmWmsMtlRequisitionDetail> detailIg in detailResult)
                        {
                            var findContainerDelivery = listContainerDeliverySub.Where(P => P.wipEntityId == requisitionMain.wipEntityId &&
                                                                                       P.materialId == detailIg.Key &&
                                                                                       listReqMainLink.Where(T => T.reqMainLinkPK.reqMainId == requisitionMain.id).Select(T => T.reqMainLinkPK.preMainId).Contains(P.preparationMainId));
                            if (findContainerDelivery != null)
                            {
                                listContainerDeliverySub.AddRange(findContainerDelivery);
                            }
                        }
                    }
                    if (listContainerDeliverySub.Count > 0)
                    {
                        storeIssueCheck.shouldContainerNum = listContainerDeliverySub.Select(P => P.containerSn).Distinct().Count();

                        var findContainerDelivery = listContainerDeliverySub.Where(P => P.status == AscmWmsContainerDelivery.StatusDefine.outWarehouseDoor);
                        if (findContainerDelivery.Count() > 0)
                        {
                            storeIssueCheck.realMaterialNum  = findContainerDelivery.Sum(P => P.quantity);
                            storeIssueCheck.realContainerNum = findContainerDelivery.Select(P => P.containerSn).Distinct().Count();
                        }
                    }

                    //设置产线
                    storeIssueCheck.productionLine = string.Join("、", ig2.Where(P => !string.IsNullOrEmpty(P.jobProductionLine)).Select(P => P.jobProductionLine).Distinct().OrderBy(P => P));

                    //设置发料状态
                    storeIssueCheck.status = IssueStatus.prepared;
                    //获取校验的最后时间
                    string lastCheckTime = ig2.Where(P => !string.IsNullOrEmpty(P.checkTime)).Max(P => P.checkTime);
                    if (!string.IsNullOrEmpty(lastCheckTime))
                    {
                        //暂定最后校验时间与当前时间间隔30秒以内的设置为“正在出仓”
                        DateTime checkTime;
                        if (DateTime.TryParse(lastCheckTime, out checkTime) && DateTime.Now.Subtract(checkTime).TotalMilliseconds < 30)
                        {
                            storeIssueCheck.status = IssueStatus.outingOfWarehouse;
                        }
                    }
                    if (storeIssueCheck.waitContainerNum == 0 && storeIssueCheck.status != IssueStatus.outingOfWarehouse)
                    {
                        storeIssueCheck.status = IssueStatus.outedOfWarehouse;
                    }
                }
            }
            return(listStoreIssueCheck);
        }
 public static AscmWmsMtlRequisitionMainService GetInstance()
 {
     if (ascmWmsMtlRequisitionMainService == null)
         ascmWmsMtlRequisitionMainService = new AscmWmsMtlRequisitionMainService();
     return ascmWmsMtlRequisitionMainService;
 }