Exemple #1
0
        /// <summary>
        /// 获取滚动排期表数据
        /// </summary>
        /// <param name="factoryID">工厂id</param>
        /// <param name="poCode">生产单号</param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="orderType">Eric添加 生产单类型:实单1,非实单0 </param>
        private void InitData(int factoryID, string poCode, DateTime startDate, DateTime endDate, int orderType, string lotNO)
        {
            //客户信息
            this.DicAllCustomers = Customer.GetDictionary(null);
            //产品分类
            this.DicProductType = ProductType.GetDictionary(null);
            this.InitLstReportSetting();

            //返回选中的工厂ID字符串
            /// 多个用逗号隔开,默认全选
            /// 格式:"1,2,3,4,5,6"
            //string FactorySelectIDsStr = "1,2,3,12,14,15,16,17";
            string FactorySelectIDsStr = factoryID.ToString();

            this.DicSimulation.Clear();
            this.DicVirProdEvent.Clear();

            // 目标生产线集合
            Filter filter = new Filter();

            filter.AddSort("FactoryID");
            filter.AddSort("ID");
            //if (!string.IsNullOrEmpty(groupNames))
            //    filter.Add("GroupName", groupNames, RELEATTION_TYPE.IN, LOGIC_TYPE.AND);
            filter.Add("FactoryID", FactorySelectIDsStr, RELEATTION_TYPE.IN, LOGIC_TYPE.AND);

            List <Facility> lstFacility = Facility.GetList(filter);

            this.LstVirtualFacility = new List <VirtualFacility>();
            List <int> ids = new List <int>();

            //
            // 相关的生产计划
            foreach (Facility fa in lstFacility)
            {
                if (!AMOData.Settings.ImpSetting.IsOutsourcedScheduling && fa.IsSubCon)//外发不排产需过滤外发线
                {
                    continue;
                }
                ids.Add(fa.ID);
                LstVirtualFacility.Add(new VirtualFacility(fa));
            }
            string wherein = string.Join(",", (from p in ids.Distinct() select p.ToString()).ToArray());

            if (string.IsNullOrEmpty(wherein))
            {
                return;
            }

            filter = new Filter();
            filter.Add(AMODataHelper.GetStringFromList(ids, 1000, "FacilityID"), LOGIC_TYPE.AND);
            filter.Add("StartTime", endDate.Date.AddDays(1), RELEATTION_TYPE.LESS, LOGIC_TYPE.AND);
            filter.Add("EndTime", startDate.Date, RELEATTION_TYPE.GREATEREQUAL, LOGIC_TYPE.AND);

            /*
             * if (orderType > -1)
             *  filter.Add("ISFIRMORDER", orderType, RELEATTION_TYPE.EQUAL, LOGIC_TYPE.AND);
             */
            if (orderType > -1)
            {
                filter.AddFrom("productioneventdetail", "ProductionEvent.ID=productioneventdetail.ProductionEventID", JOIN_TYPE.LEFT);
                filter.AddFrom("PO", "PO.ID = productioneventdetail.POID", JOIN_TYPE.LEFT);
                filter.Add("PO.ISFIRMORDER", orderType, RELEATTION_TYPE.EQUAL, LOGIC_TYPE.AND);
            }
            if (string.IsNullOrEmpty(lotNO) == false)
            {
                string sql = string.Format("(select id from po where LotNO like '%{0}%')", lotNO);
                filter.Add("ProductionEvent.POID", sql, RELEATTION_TYPE.IN, LOGIC_TYPE.AND);
            }
            filter.AddSort("StartTime");
            this.LstProdEvent   = ProductionEvent.GetList(filter);
            this.DicFaProdEvent = new Dictionary <int, IEnumerable <ProductionEvent> >();
            foreach (var g in this.LstProdEvent.GroupBy(x => x.FacilityID))
            {
                this.DicFaProdEvent[g.Key] = g.ToList();
            }
            //获取计划完成日期
            var peFilter = new Filter();

            peFilter.Add(AMODataHelper.GetStringFromList(ids, 1000, "PRODUCTIONEVENT.FacilityID"), LOGIC_TYPE.AND);
            peFilter.Add("PRODUCTIONEVENT.StartTime", endDate.Date.AddDays(1), RELEATTION_TYPE.LESS, LOGIC_TYPE.AND);
            peFilter.Add("PRODUCTIONEVENT.EndTime", startDate.Date, RELEATTION_TYPE.GREATEREQUAL, LOGIC_TYPE.AND);
            peFilter.Add("PRODUCTIONEVENT.STATUS", 1, RELEATTION_TYPE.EQUAL, LOGIC_TYPE.AND);
            this.DicProdFinishDates = ProductionSchedule.GetProductionFinishedDate(peFilter);

            //动态人数
            Filter fwnFilter = new Filter();
            string idStr     = string.Join(",", (from p in ids.Distinct() select p.ToString()).ToArray());

            fwnFilter.Add("FacilityID", idStr, RELEATTION_TYPE.IN, LOGIC_TYPE.AND);
            var lstFwn = FacilityWorkerNumber.GetList(fwnFilter);

            this.DicFwn = new Dictionary <int, IEnumerable <FacilityWorkerNumber> >();
            foreach (var g in lstFwn.GroupBy(x => x.FacilityID))
            {
                DicFwn[g.Key] = g.ToList();
            }
            //ids = new List<int>();
            //ids = (from item in this.LstProdEvent select item.POID).ToList();
            //this.LstProdEvent = ProductionEvent.GetList(filter);

            if (this.LstProdEvent.Count > 0)
            {
                var mylist = this.LstProdEvent.Where(x => !string.IsNullOrEmpty(x.GroupID));
                if (mylist.Any())
                {
                    var gids = mylist.Select(x => x.GroupID).Distinct();
                    var lst  = gids.ToList();
                    groupIdCodes = AMO.BLL.ProductionEvent.GetAboutGroupIdList(lst); //获取与组ID关联的POCODE列表
                }
            }



            //生产计划细分
            ids    = new List <int>();
            filter = new Filter();
            ids    = (from item in this.LstProdEvent select item.ID).ToList();
            this.DicProdEventDetail = new Dictionary <int, List <ProductionEventDetail> >();
            List <ProductionEventDetail> lstProdEventDetail = new List <ProductionEventDetail>();

            if (ids.Count > 0)
            {
                filter.Add(AMODataHelper.GetStringFromList(ids, 1000, "ProductionEventID"), LOGIC_TYPE.AND);
                if (!string.IsNullOrEmpty(poCode))
                {
                    filter.Add("POID", string.Format("SELECT id FROM dbo.PO WHERE CODE LIKE '%{0}%'", poCode), RELEATTION_TYPE.IN, LOGIC_TYPE.AND);
                }

                lstProdEventDetail = ProductionEventDetail.GetList(filter);
                foreach (var g in lstProdEventDetail.GroupBy(x => x.ProductionEventID))
                {
                    this.DicProdEventDetail[g.Key] = g.ToList();
                }
            }

            //生产单信息
            ids    = new List <int>();
            filter = new Filter();
            ids    = (from item in lstProdEventDetail select item.POID).Distinct().ToList();
            string sokeySql = string.Empty;

            if (ids.Count > 0)
            {
                filter.Add(AMODataHelper.GetStringFromList(ids, 1000, "ID"), LOGIC_TYPE.AND);
                if (!string.IsNullOrEmpty(poCode))
                {
                    filter.Add("Code", poCode, RELEATTION_TYPE.LIKE, LOGIC_TYPE.AND);
                }
                string poidSql = DBHelper.GetDistinctSql("PO", "ID", filter);
                sokeySql   = DBHelper.GetDistinctSql("PO", "SoKeyID", filter);
                this.DicPO = PO.GetDictionary(filter);
                filter     = new Filter();
                filter.Add("POID", poidSql, RELEATTION_TYPE.IN, LOGIC_TYPE.AND);
                this.LstPODetail = PODetail.GetList(filter, false);

                //关键事件(物料ETA)日期,有实际区实际,没实际区预计
                var eventFilter = new Filter();
                eventFilter.AddFrom("EVENTFLOWNODE", "EVENTFLOWNODE.ID=POEVENT.EVENTFLOWNODEID", JOIN_TYPE.INNER);
                eventFilter.Add("EVENTFLOWNODE.CRITICALEVENTID", AMOData.Settings.SysSetting.Rpt_ActualMaterialETA, RELEATTION_TYPE.EQUAL, LOGIC_TYPE.AND);
                eventFilter.Add("POEVENT.POID", poidSql, RELEATTION_TYPE.IN, LOGIC_TYPE.AND);
                List <POEvent> lstPOEvent = POEvent.GetList(eventFilter);
                this.DicPOEvents = new Dictionary <int, POEvent>();
                foreach (POEvent model in lstPOEvent)
                {
                    if (DicPOEvents.ContainsKey(model.POID) == false)
                    {
                        DicPOEvents.Add(model.POID, model);
                    }
                }
            }
            else
            {
                this.DicPO       = new Dictionary <int, PO>();
                this.LstPODetail = new List <PODetail>();
            }



            //
            if (!string.IsNullOrEmpty(sokeySql))
            {
                Filter sokeyFilter = new Filter();
                sokeyFilter.Add("SoKeyID", sokeySql, RELEATTION_TYPE.IN, LOGIC_TYPE.AND);
                sokeyFilter.Add("MaterialStyle", 6, RELEATTION_TYPE.NOTEQUAL, LOGIC_TYPE.AND);
                LstPOMaterialRequest = POMaterialRequest.GetListOnlySample(sokeyFilter);
                LstPOMaterialRequest.Sort(POMaterialRequest.ComparerByDate);
            }

            #region 用于计算 计划的每日计划产量
            List <VirtualProdEvent> lstVirProdEvent = this.CreateVirtualProdEvent(this.LstProdEvent, lstProdEventDetail);
            this.DicVirProdEvent = lstVirProdEvent.ToDictionary(x => x.ID);

            if (this.LstReportSetting.Find(x => x.ColumnName == "AreaPlanQty" || x.ColumnName == "AreaOutput") != null)//AMOHB-3684 增加区间排单数、区间产值
            {
                var gsVpe = lstVirProdEvent.GroupBy(x => x.FacilityID);
                foreach (var g in gsVpe)
                {
                    var virFacility = this.LstVirtualFacility.Find(x => x.ID == g.Key);
                    if (virFacility != null)
                    {
                        foreach (var vpe in g.ToList())
                        {
                            vpe.FactoryID = virFacility.FactoryID;
                        }
                    }
                }

                //按工厂生产simulation对象
                var gsFacility = this.LstVirtualFacility.GroupBy(x => x.FactoryID);
                foreach (var g in gsFacility)
                {
                    if (!DicSimulation.ContainsKey(g.Key))
                    {
                        //Simulation sim = this.CreateSimulation(g.Key, lstVirProdEvent.Where(x => x.FactoryID == g.Key).ToList());
                        var lstVirProdEventFinded = lstVirProdEvent.Where(x => x.FactoryID == g.Key);
                        if (lstVirProdEventFinded != null && lstVirProdEventFinded.Count() > 0)
                        {
                            Simulation sim = this.CreateSimulation(g.Key, lstVirProdEventFinded.ToList());
                            DicSimulation.Add(g.Key, sim);
                        }
                    }
                }
            }
            #endregion
        }