Beispiel #1
0
        /// <summary>
        /// 插入新工序计划到数据库
        /// </summary>
        /// <param name="itemList"></param>
        /// <param name="CEmployeeNum"></param>
        /// <param name="CEmployeeName"></param>
        /// <returns></returns>
        public static bool InsertProcessWorkPlan(List <ClassWorkPlan> itemList, string CEmployeeNum, string CEmployeeName)
        {
            bool result = false;

            if (itemList != null && itemList.Count > 0)
            {
                List <ProductionOrderVersion> povList = new List <ProductionOrderVersion>();
                //遍历更新
                itemList.ForEach(x =>
                {
                    x.CEmployeeName = CEmployeeName;
                    x.CEmployeeNum  = CEmployeeNum;
                    x.CreateTime    = BaseEntityFac.GetServerTime();

                    ProductionOrderVersion pov = povList.Find(y => y.ProductionOrderVersionNumber == x.ProductionOrderVersionNumber);

                    if (pov == null)
                    {
                        string ProductionOrderVersionNumber    = x.ProductionOrderVersionNumber;
                        List <ProductionOrderVersion> tempList = BaseEntityFac.GetEntityByField <ProductionOrderVersion>
                                                                     (m => m.ProductionOrderVersionNumber == ProductionOrderVersionNumber);

                        if (tempList != null && tempList.Count > 0)
                        {
                            povList.AddRange(tempList);
                        }
                    }
                });

                povList.ForEach(x =>
                {
                    x.IsAPS = (int)WhetherValue.Yes;
                });

                return(BaseEntityFac.TransactionOPEntitys <ClassWorkPlan>((cn, transaction) =>
                {
                    bool res = false;
                    res = BaseEntityFac.TransactionOPEntitysAdd <ClassWorkPlan>(cn, transaction, EOPType.Insert, itemList);

                    res = BaseEntityFac.TransactionOPEntitysAdd <ProductionOrderVersion>(cn, transaction, EOPType.Update, povList);

                    return res;
                }));
            }

            return(result);
        }
Beispiel #2
0
        public static List <ClassWorkPlan> CreateClassWorkPlans(ProductionOrderVersion item, List <ProductionMakeWorkOrderView> workList)
        {
            List <ClassWorkPlan> cwpList = new List <ClassWorkPlan>();

            string ProductionVersionId = item.ProductionVersionId;

            DateTime dt = BaseEntityFac.GetServerTime();
            //工序时间缓存
            List <ProductionMakeWorkOrderTime> procesTimeList = new List <ProductionMakeWorkOrderTime>();

            //获取该生产版本中工序在制品清单
            List <WorkOrderOutProduct> woopList = BaseEntityFac.GetEntityByField <WorkOrderOutProduct>(x => x.ProductionVersionId == ProductionVersionId);

            //跟工序作业顺序计算  升序
            List <ProductionMakeWorkOrderView> newworkList = workList.OrderBy(x => x.ProcessOrder).ToList();

            //公式 (订单量/产能)* (时间值)*(时间单位换算成的秒数)
            decimal totalWorkTime = (item.MakeQty / item.ProductMakeValue) * item.ProductMakeTimeValue * item.ProductMakeUnit;//作业时间 单位秒

            //最晚作业开始时间


            List <APSCalendar> ascList = GetAPSCalendarWorkDate(CalendarHelper.ALLResourceCode.ToString());

            DateTime LatestStartTime = CalendarHelper.GetAPSWorkTime(item.ProductionOrderEndDate, totalWorkTime, ascList);

            //获取工序时间(去掉非作业时间)
            List <ProductionMakeWorkOrderTime> tempprocesTimeList = CalculationProcessTime(item, newworkList,
                                                                                           woopList, LatestStartTime, dt, ascList);

            if (tempprocesTimeList == null)
            {
                return(null);
            }

            foreach (var pmw in newworkList)
            {
                //获取工序产出品 可能存在一个工序多个产出品的情况
                List <WorkOrderOutProduct> newwoopList = woopList.FindAll(x => x.WorkOrderNum == pmw.WorkOrderNum &&
                                                                          x.ProductionVersionId == pmw.ProductionVersionId);

                if (newwoopList != null && newwoopList.Count > 0)
                {
                    ProductionMakeWorkOrderTime processTime = tempprocesTimeList.Find(x =>
                                                                                      x.ProductionMakeWorkOrderId == pmw.ProductionMakeWorkOrderId);
                    foreach (var woopItem in newwoopList)
                    {
                        ClassWorkPlan cwp = new ClassWorkPlan();
                        cwp.ClassWorkPlanId              = Guid.NewGuid().ToString();
                        cwp.ProductionOrderNumbe         = item.ProductionOrderNumbe;         //生产订单编号
                        cwp.ProductionOrderVersionNumber = item.ProductionOrderVersionNumber; //订单工艺编号
                        cwp.CustomerNum               = item.CustomerNum;
                        cwp.CustomerName              = item.CustomerName;
                        cwp.WorkPlanNo                = dt.Year.ToString() + BaseEntityFac.GetNewSerialNumber(EE.Name <ClassWorkPlan>(x => x.WorkPlanNo)); //工单流水号
                        cwp.TaskSheetType             = (int)TaskSheetType.PS;                                                                             //工单大分类
                        cwp.FatherWorkPlanNo          = string.Empty;                                                                                      //父级工单流水号
                        cwp.ProductionVersionId       = pmw.ProductionVersionId;                                                                           //生产版本ID
                        cwp.ProductionVersionName     = pmw.ProductionVersionName;                                                                         //生产版本名称
                        cwp.ProductionMakeWorkOrderId = pmw.ProductionMakeWorkOrderId;                                                                     //生产版本中工序ID
                        cwp.WorkOrderOutProductId     = woopItem.WorkOrderOutProductId;                                                                    //工序在制品ID
                        cwp.WorkOrderPositionId       = string.Empty;                                                                                      //工序中工位ID
                        cwp.WorkOrderNum              = pmw.WorkOrderNum;                                                                                  //工序编码
                        cwp.WorkOrderName             = pmw.WorkOrderName;                                                                                 //工序名称
                        cwp.MaterialNum               = woopItem.MaterialNum;                                                                              //在制品编码
                        cwp.MaterialName              = woopItem.MaterialName;                                                                             //在制品名称
                        cwp.BatchNumber               = item.BatchNumber;                                                                                  //生产批次

                        cwp.MainProductionResourceCode = string.Empty;                                                                                     //主资源编码
                        cwp.MainProductionResourceName = string.Empty;                                                                                     //主资源名称
                        cwp.SubProductionResourceCode  = string.Empty;                                                                                     //副资源编码
                        cwp.SubProductionResourceName  = string.Empty;                                                                                     //副资源名称

                        cwp.WorkPositionNum       = string.Empty;                                                                                          //工位编码
                        cwp.WorkPositionName      = string.Empty;                                                                                          //工位名称
                        cwp.EmployeeNum           = string.Empty;                                                                                          //员工工号
                        cwp.PlanWorkDate          = dt;                                                                                                    //计划日期
                        cwp.ClassNoName           = string.Empty;                                                                                          //班次
                        cwp.EarliestStartTime     = processTime.EarliestStartTime;
                        cwp.LatestEndTime         = processTime.LatestEndTime;
                        cwp.PlanWorkStartTime     = cwp.EarliestStartTime;
                        cwp.PlanWorkEndTime       = cwp.LatestEndTime;
                        cwp.ClassPlanQty          = item.MakeQty * woopItem.Qty - InspectRegisterQty(item.ProductionOrderNumbe, woopItem.WorkOrderOutProductId); //工单计划作业量 去掉库存抵消量
                        cwp.ClassRealQty          = 0;                                                                                                           //工单实际作业量
                        cwp.ClassSubmitScrapQty   = 0;                                                                                                           //报工后出现的废品
                        cwp.ClassNoSubmitScrapQty = 0;                                                                                                           //调试出现的废品
                        cwp.UnitCode = item.UnitCode;                                                                                                            //物料单位

                        cwp.TaskSheetSmallType = (int)TaskSheetSmallType.Normal;                                                                                 //工单小分类
                        cwp.IsPublish          = (int)WhetherValue.No;
                        cwp.CustomFlag         = 0;                                                                                                              //1-表示插单
                        cwp.TaskSheetOPStatus  = (int)TaskSheetOPStatus.NotStart;                                                                                //工单操作
                        cwp.HandoverState      = (int)WhetherValue.No;                                                                                           //交接班

                        cwp.QCProcessType  = woopItem.QCProcessType;                                                                                             //质检类型 例如全检 抽检 免检
                        cwp.QCProcessFlag  = (int)QCProcessFlag.Untested;                                                                                        //质检状态
                        cwp.QCEmployeeName = string.Empty;                                                                                                       //质检员姓名
                        cwp.QCEmployeeNum  = string.Empty;                                                                                                       //质检员工号

                        cwp.Comments = string.Empty;                                                                                                             //工单备注

                        cwpList.Add(cwp);
                    }
                }
            }


            return(cwpList);
        }
Beispiel #3
0
        /// <summary>
        /// 计算工序时间
        /// </summary>
        /// <param name="item">生产订单&生产版本</param>
        /// <param name="newworkList">版本工序清单</param>
        /// <param name="woopList">版本工序产出品清单</param>
        /// <param name="LatestStartTime"></param>
        /// <param name="EarliestStartTime"></param>
        /// <returns></returns>
        public static List <ProductionMakeWorkOrderTime> CalculationProcessTime(ProductionOrderVersion item, List <ProductionMakeWorkOrderView> newworkList,
                                                                                List <WorkOrderOutProduct> woopList, DateTime LatestStartTime, DateTime EarliestStartTime, List <APSCalendar> ascList)
        {
            int min = newworkList.FirstOrDefault().ProcessOrder; //开始工序顺序号
            int max = newworkList.Max(x => x.ProcessOrder);      //末尾工序顺序号

            List <ProductionMakeWorkOrderTime> procesTimeList = new List <ProductionMakeWorkOrderTime>();

            //生产版本的工序产出品清单

            foreach (var pmw in newworkList)
            {
                string ProductionMakeWorkOrderId       = pmw.ProductionMakeWorkOrderId;
                ProductionMakeWorkOrderTime procesTime = new ProductionMakeWorkOrderTime();

                procesTime.ProductionMakeWorkOrderId = pmw.ProductionMakeWorkOrderId;

                if (pmw.ProcessOrder == min)
                {
                    //首工序
                    procesTime.LatestStartTime   = LatestStartTime;
                    procesTime.EarliestStartTime = EarliestStartTime;
                }
                else
                {
                    //检查当前工序是否有依赖工序
                    List <ProductionMakeWorkOrderRelation> relationList = BaseEntityFac.GetEntityByField <ProductionMakeWorkOrderRelation>(x => x.ProductionMakeWorkOrderId == ProductionMakeWorkOrderId);

                    if (relationList != null && relationList.Count > 0)
                    {
                        //获取依赖工序的开始时间
                        DateTime tempLatestStartTime   = DateTime.Now.AddYears(-1);
                        DateTime tempEarliestStartTime = DateTime.Now.AddYears(-1);
                        foreach (var relation in relationList)
                        {
                            ProductionMakeWorkOrderTime relationTime = procesTimeList.Find(x => x.ProductionMakeWorkOrderId == relation.RProductionMakeWorkOrderId);

                            if (relation.WTR == (int)WorkOrderSequenceType.ES)
                            {
                                decimal spanRelation = relation.ETime * relation.TimeUnit;//秒

                                DateTime tempDt = CalendarHelper.GetAPSWorkTime(relationTime.EarliestEndTime, spanRelation, ascList, false);

                                if (tempEarliestStartTime < tempDt)
                                {
                                    tempEarliestStartTime = tempDt;
                                }
                                tempDt = CalendarHelper.GetAPSWorkTime(relationTime.LatestEndTime, spanRelation, ascList, false);
                                if (tempLatestStartTime < tempDt)
                                {
                                    tempLatestStartTime = tempDt;
                                }
                            }
                            else if (relation.WTR == (int)WorkOrderSequenceType.SS || relation.WTR == (int)WorkOrderSequenceType.SSEE)
                            {
                                decimal  spanRelation = relation.STime * relation.TimeUnit;//秒
                                DateTime tempDt       = CalendarHelper.GetAPSWorkTime(relationTime.EarliestStartTime, spanRelation, ascList, false);
                                if (tempEarliestStartTime < tempDt)
                                {
                                    tempEarliestStartTime = tempDt;
                                }
                                tempDt = CalendarHelper.GetAPSWorkTime(relationTime.LatestStartTime, spanRelation, ascList, false);
                                if (tempLatestStartTime < tempDt)
                                {
                                    tempLatestStartTime = tempDt;
                                }
                            }
                            //whw 2019年8月9号  暂不支持SSEE的接序方式

                            procesTime.LatestStartTime   = tempLatestStartTime;
                            procesTime.EarliestStartTime = tempEarliestStartTime;
                        }
                    }
                }

                #region 计算工序产出品最终BOM构成数量
                List <WorkOrderOutProduct> tempwoopList = woopList.FindAll(x => x.ProductionMakeWorkOrderId == ProductionMakeWorkOrderId);
                if (tempwoopList == null)
                {
                    continue;
                }
                decimal maxBomQty = 0;
                decimal Qty       = 0;
                foreach (var tempItem in tempwoopList)
                {
                    //去掉库存现有货物抵消值
                    Qty = item.MakeQty * tempItem.Qty - InspectRegisterQty(item.ProductionOrderNumbe, tempItem.WorkOrderOutProductId);//工序需要生产的数量(工序多个产出品时,该值为最大值)

                    if (maxBomQty < Qty)
                    {
                        maxBomQty = Qty;
                    }
                }


                #endregion

                decimal spanTime = (pmw.FrontTimeValue * pmw.FrontTimeUnit                                                 //前设置时间
                                    + (Qty / pmw.StandardMakeValue) * pmw.StandardMakeTimeValue * pmw.StandardMakeTimeUnit //制造时间
                                    + pmw.BackTimeValue * pmw.BackTimeUnit);                                               //后设置时间

                procesTime.spanTime = (Double)spanTime;

                procesTime.LatestEndTime   = CalendarHelper.GetAPSWorkTime(procesTime.LatestStartTime, spanTime, ascList, false);
                procesTime.EarliestEndTime = CalendarHelper.GetAPSWorkTime(procesTime.EarliestStartTime, spanTime, ascList, false);


                #region 去掉非作业时间  时间会变长



                #endregion


                procesTimeList.Add(procesTime);
                //计算结束时间
            }

            return(procesTimeList);
        }