public object GetLatestProductionOrder(int offsetday = 30)
        {
            int orderStatus = (int)ProductionOrderStatus.Release;

            DateTime dt = BaseEntityFac.GetServerTime().AddDays(0 - offsetday);

            object itemList = BaseEntityFac.GetEntityByField <ProductionOrder>(x => x.ProductionOrderStatus == orderStatus && x.ProductionOrderEndDate >= dt);

            return(itemList);
        }
Пример #2
0
        /// <summary>
        /// 获取工厂的年生产日历
        /// </summary>
        /// <returns></returns>
        public static List <APSCalendar> GetAPSCalendarWorkDate(string ResourceCode)
        {
            #region 获取作业时间
            List <APSCalendar> workDate = new List <APSCalendar>();
            DateTime           current  = BaseEntityFac.GetServerTime();
            int CalendarYear            = current.Year;
            //string ResourceCode = ;//*

            string mode = "";//工厂的出勤模式
            //今年
            string WorkWeekValue = string.Empty;
            List <ProductionResourceCalendar> prcItemList = BaseEntityFac.GetEntityByField <ProductionResourceCalendar>
                                                                (x => x.CalendarYear == CalendarYear && x.ResourceCode == ResourceCode);
            if (prcItemList != null && prcItemList.Count > 0)
            {
                ProductionResourceCalendar prc = prcItemList.FirstOrDefault();
                WorkWeekValue = prc.WorkWeekValue;
                mode          = prc.Mode;
                List <APSCalendar> tempworkDate = CalendarHelper.CalendarTransformWorkDate(current.Year, prc.WorkWeekValue, prc.Mode, prc.NotWorkDates, prc.Overtime);

                if (tempworkDate != null)
                {
                    workDate.AddRange(tempworkDate);
                }
            }
            //明年
            CalendarYear += 1;
            List <ProductionResourceCalendar> prcNextItemList = BaseEntityFac.GetEntityByField <ProductionResourceCalendar>
                                                                    (x => x.CalendarYear == CalendarYear && x.ResourceCode == ResourceCode);
            if (prcNextItemList != null && prcNextItemList.Count > 0)
            {
                ProductionResourceCalendar prc          = prcNextItemList.FirstOrDefault();
                List <APSCalendar>         tempworkDate = CalendarHelper.CalendarTransformWorkDate(CalendarYear, prc.WorkWeekValue, prc.Mode, prc.NotWorkDates, prc.Overtime);

                if (tempworkDate != null)
                {
                    workDate.AddRange(tempworkDate);
                }
            }
            else
            {
                //未定义明年生产日历,参照今年的生产日历(无法估计节假日和加班日期)
                List <APSCalendar> tempworkDate = CalendarHelper.CalendarTransformWorkDate(CalendarYear, WorkWeekValue, mode);

                if (tempworkDate != null)
                {
                    workDate.AddRange(tempworkDate);
                }
            }

            // CalendarHelper.CalendarTransformWorkDate
            #endregion

            return(workDate);
        }
        public object CalculationWorkPlan(OPEntityCmdBase cmd)
        {
            int apsType = int.Parse(cmd.Tag);

            List <ProductionOrderVersion> itemList = JsonUtil.fromJson <List <ProductionOrderVersion> >(cmd.EntityJson);

            DateTime dt = BaseEntityFac.GetServerTime();

            if (!string.IsNullOrWhiteSpace(cmd.timestamp))
            {
                dt = DateTime.Parse(cmd.timestamp);
            }
            return(FPA.Business.ProductionOrder.ProductionOrderBusiness.CalculationWorkPlan(itemList, dt, apsType));
        }
Пример #4
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);
        }
Пример #5
0
        private static ClassWorkPlan CopyDayWorkPlan(DayClassWorkPlan item, DateTime PlanWorkDate, decimal ClassPlanQty, string CEmployeeNum, string CEmployeeName)
        {
            #region  检查日计划是否存在
            string   ProductionMakeWorkOrderId = item.ProductionMakeWorkOrderId;
            string   ProductionVersionName     = item.ProductionVersionName;
            string   MaterialNum = item.MaterialNum;
            DateTime dt          = PlanWorkDate;
            int      tst         = (int)TaskSheetType.DS;//工序日生产计划

            List <ClassWorkPlan> cwpLatest = BaseEntityFac.GetEntityByField <ClassWorkPlan>(x =>
                                                                                            x.PlanWorkDate == dt && x.TaskSheetType == tst &&
                                                                                            x.ProductionMakeWorkOrderId == ProductionMakeWorkOrderId &&
                                                                                            x.ProductionVersionName == ProductionVersionName
                                                                                            );

            if (cwpLatest != null && cwpLatest.Count > 0)
            {
                List <ClassWorkPlan> cwptempLatest = cwpLatest.OrderByDescending(x => x.CreateTime).ToList();

                ClassWorkPlan cwpItem = cwptempLatest.FirstOrDefault();

                cwpItem.ClassPlanQty = ClassPlanQty;//日作业量

                return(cwpItem);
            }

            #endregion
            ClassWorkPlan cwp = ObjectHelper.ObjectMap <DayClassWorkPlan, ClassWorkPlan>(item);
            cwp.PlanWorkDate          = PlanWorkDate;
            cwp.ClassWorkPlanId       = Guid.NewGuid().ToString();       //作业日期
            cwp.TaskSheetType         = (int)TaskSheetType.DS;           //工序日生产计划
            cwp.TaskSheetOPStatus     = (int)TaskSheetOPStatus.NotStart; //未开始作业
            cwp.ClassPlanQty          = ClassPlanQty;                    //日作业量
            cwp.ClassRealQty          = 0;                               //实际日报工量
            cwp.ClassNoSubmitScrapQty = 0;                               //未报工报废
            cwp.ClassSubmitScrapQty   = 0;                               //已报工报废
            cwp.CEmployeeName         = CEmployeeName;                   //创建人姓名
            cwp.CEmployeeNum          = CEmployeeNum;                    //创建人工号
            cwp.CreateTime            = BaseEntityFac.GetServerTime();
            cwp.FatherWorkPlanNo      = item.WorkPlanNo;
            cwp.WorkPlanNo            = item.WorkPlanNo + BaseEntityFac.GetNewSerialNumber("SubWorkPlanNo"); //父工单号+流水号
            cwp.QCProcessFlag         = (int)QCProcessFlag.Untested;
            cwp.QCProcessType         = item.QCProcessType;                                                  //复用父级工单
            cwp.QCEmployeeName        = string.Empty;                                                        //质检员姓名
            cwp.QCEmployeeNum         = string.Empty;                                                        //质检员工号
            return(cwp);
        }
Пример #6
0
        /// <summary>
        /// 返回可以排日计划的工序工单(大计划)
        /// </summary>
        /// <returns></returns>
        public static List <DayClassWorkPlan> GetNotFinishedWorkPlan()
        {
            List <ClassWorkPlan> cwpList = new List <ClassWorkPlan>();
            int tst    = (int)TaskSheetType.PS;//只获取工序工单
            int stop   = (int)TaskSheetOPStatus.Stop;
            int finish = (int)TaskSheetOPStatus.Finish;

            cwpList = BaseEntityFac.GetEntityByField <ClassWorkPlan>
                          (x => x.TaskSheetOPStatus != finish && x.TaskSheetOPStatus != stop && x.TaskSheetType == tst && (x.ClassPlanQty - x.ClassRealQty) > 0);

            List <DayClassWorkPlan> dayList = new List <DayClassWorkPlan>();

            dayList = ObjectHelper.ObjectListMap <ClassWorkPlan, DayClassWorkPlan>(cwpList);

            DateTime dt          = BaseEntityFac.GetServerTime();
            DateTime dtFirtDay   = dt.Date;
            DateTime dtSecondDay = dt.Date.AddDays(1);
            DateTime dtThirdDay  = dt.Date.AddDays(2);

            foreach (var item in dayList)
            {
                //计算大计划的欠数
                item.OweQty = item.ClassPlanQty - item.ClassRealQty;
                if (item.OweQty < 0)
                {
                    item.OweQty = 0;//订单超量报工
                }
                //计算日合计量
                item.FirstDay  = dtFirtDay;
                item.FirstQty  = GetTotalDayPlanQty(item.WorkPlanNo, dtFirtDay);
                item.SecondDay = dtSecondDay;
                item.SecondQty = GetTotalDayPlanQty(item.WorkPlanNo, dtSecondDay);
                item.ThirdDay  = dtThirdDay;
                item.ThirdQty  = GetTotalDayPlanQty(item.WorkPlanNo, dtThirdDay);
            }
            return(dayList);
        }
Пример #7
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);
        }
Пример #8
0
 public string GetServerTime()
 {
     return(BaseEntityFac.GetServerTime().ToString());
 }