Beispiel #1
0
        protected ICMOSchedule GetOrCreateSchedule(Entities.VW_MOBillList icmo)
        {
            var schedule = SRepository.GetAll().Include(p => p.Dailies).SingleOrDefault(p => p.FMOBillNo == icmo.任务单号);

            if (schedule == null)
            {
                schedule = new ICMOSchedule
                {
                    FID             = Guid.NewGuid().ToString(),
                    FBillTime       = DateTime.Now,
                    FBillNo         = "SC-" + icmo.任务单号,
                    FBiller         = AbpSession.UserId.ToString(),
                    FPlanAuxQty     = icmo.计划生产数量,
                    FItemNumber     = icmo.产品编码,
                    FItemID         = icmo.FItemID,
                    FItemModel      = icmo.规格型号,
                    FItemName       = icmo.产品名称,
                    FPlanBeginDate  = icmo.计划开工日期,
                    FPlanFinishDate = icmo.计划完工日期
                    ,
                    Dailies    = new List <Entities.ICMODaily>(),
                    FMOBillNo  = icmo.任务单号,
                    FMOInterID = icmo.FMOInterID
                };
                //插入新的计划单
                schedule = SRepository.Insert(schedule);
                UnitOfWorkManager.Current.SaveChanges();
            }

            return(schedule);
        }
        protected async Task InsertOrUpdateICMOSchedul(ICMODailyCreatedtEventData eventData)
        {
            var entity = await SRepository.GetAll().SingleOrDefaultAsync(p =>
                                                                         p.FID == eventData.FSrcID);

            if (entity == null)
            {
                entity = new ICMOSchedule()
                {
                    FID         = eventData.FSrcID,
                    FBillTime   = DateTime.Now,
                    FBillNo     = "SC-" + eventData.FMOBillNo,
                    FBiller     = eventData.FBiller,
                    FPlanAuxQty = eventData.FPlanAuxQty
                };
                SRepository.Insert(entity);
            }
            else
            {
                entity.FPlanAuxQty = eventData.FPlanAuxQty;

                SRepository.Update(entity);
            }
        }
        public List <ICMOSchedule> ImportDaily(List <ICMODailyCreatDto> input)
        {
            string              fmobillno  = "";
            int                 fmointerid = -1;
            ICMOSchedule        schedule   = null;
            List <ICMOSchedule> result     = new List <ICMOSchedule>();

            //遍历导入数据
            foreach (var inputItem in input)
            {
                if (inputItem != null && fmobillno != inputItem.FMOBillNo)
                {
                    fmobillno = inputItem.FMOBillNo;
                    var icmo = MRepository.GetAll().SingleOrDefault(p => p.FBillNo == fmobillno);
                    if (icmo != null)
                    {
                        schedule = SRepository.GetAll().SingleOrDefault(p => p.FMOBillNo == fmobillno);

                        if (schedule == null)
                        {
                            schedule = new ICMOSchedule()
                            {
                                FID         = Guid.NewGuid().ToString(),
                                FBillTime   = DateTime.Now,
                                FBillNo     = "SC-" + fmobillno,
                                FBiller     = AbpSession.UserId.ToString(),
                                FPlanAuxQty = 0
                            };
                            //插入新的计划单
                            schedule = SRepository.Insert(schedule);
                        }

                        foreach (var dailyItem in inputItem.Dailies)
                        {
                            #region 暂时注掉不用



                            //var entity = dailyList.SingleOrDefault(p => p.FDate == dailyItem.FDate && p.FMachineID == dailyItem.FMachineID &&
                            //                                            p.FShift == dailyItem.FShift && p.FOperID == dailyItem.FOperID);

                            //var index = (inputItem.Dailies.IndexOf(dailyItem) + dailyList.Count + 1).ToString("000");

                            //if (entity == null)
                            //{
                            //    entity = new Entities.ICMODaily()
                            //    {
                            //        FMachineID = dailyItem.FMachineID,
                            //        FWorkCenterID = dailyItem.FWorkCenterID,
                            //        FShift = dailyItem.FShift,
                            //        FID = Guid.NewGuid().ToString(),
                            //        FBillNo = "DA" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + index,//任务计划单号
                            //        FMOInterID = icmo.FInterID,//任务单号
                            //        FMOBillNo = icmo.FBillNo,//任务单号
                            //        FBiller = this.AbpSession.UserId.ToString(),//当前登录用户
                            //        FSrcID = schedule.FID,
                            //        FPlanAuxQty = dailyItem.FPlanAuxQty,
                            //        FBillTime = DateTime.Now,
                            //        FDate = dailyItem.FDate.Date
                            //    };

                            //}
                            //else
                            //{
                            //    entity.FPlanAuxQty = dailyItem.FPlanAuxQty;
                            //}
                            #endregion

                            var entity = schedule.Dailies.SingleOrDefault(p =>
                                                                          p.FDate == dailyItem.FDate && p.FMachineID == dailyItem.FMachineID &&
                                                                          p.FShift == dailyItem.FShift && p.FOperID == dailyItem.FOperID);

                            var index = (schedule.Dailies.Count + 1).ToString("000");

                            if (entity == null)
                            {
                                entity = new Entities.ICMODaily()
                                {
                                    FMachineID    = dailyItem.FMachineID,
                                    FWorkCenterID = dailyItem.FWorkCenterID,
                                    FShift        = dailyItem.FShift,
                                    FID           = Guid.NewGuid().ToString(),
                                    FBillNo       = "DA" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + index, //任务计划单号
                                    FMOInterID    = icmo.FInterID,                                                //任务单号
                                    FMOBillNo     = icmo.FBillNo,                                                 //任务单号
                                    FBiller       = this.AbpSession.UserId.ToString(),                            //当前登录用户
                                    FSrcID        = schedule.FID,
                                    FPlanAuxQty   = dailyItem.FPlanAuxQty,
                                    FBillTime     = DateTime.Parse(DateTime.Now.ToString("yyyy-M-d dd HH:mm:ss")),
                                    FDate         = dailyItem.FDate.Date
                                };
                                //插入新的日计划单
                                schedule.Dailies.Add(entity);
                            }
                            else
                            {
                                schedule.FPlanAuxQty -= entity.FPlanAuxQty;
                                entity.FPlanAuxQty    = dailyItem.FPlanAuxQty;
                                schedule.FPlanAuxQty += entity.FPlanAuxQty;
                            }
                        }
                        //更新计划单
                        SRepository.Update(schedule);
                    }
                    else
                    {
                        throw new AbpException($"任务单号:{0} 不存在" + fmobillno);
                    }
                }
            }

            return(null);
        }
Beispiel #4
0
        public ICMODailyDto Create(ICMODailyCreatDto input)
        {
            var tran = context.Database.BeginTransaction();

            try
            {
                // 检查是否已存在任务计划单
                var schedule = context.ICMOSchedule.SingleOrDefault(p =>
                                                                    p.FMOBillNo == input.FMOBillNo && p.FMOInterID == input.FMOInterID);
                //不存在则新建
                if (schedule == null)
                {
                    schedule = new ICMOSchedule()
                    {
                        FID        = Guid.NewGuid().ToString(),
                        FBillNo    = "SC" + DateTime.Now.ToString("yyyyMMddHHmmss"), //计划单号
                        FMOInterID = input.FMOInterID,                               //任务单ID
                        FMOBillNo  = input.FMOBillNo
                    };                                                               //任务单号

                    context.ICMOSchedule.Add(schedule);                              //插入任务计划单
                }
                else
                {
                    context.ICMOSchedule.Attach(schedule);
                    context.Entry(schedule).State = EntityState.Modified;
                }


                //已存在的排程日计划单
                var dailyEntityList = context.ICMODaily.Where(p => p.FSrcID == schedule.FID).ToList();

                foreach (var daily in input.Dailies)
                {
                    //比较传入数据是否已存在,如果存在则更新数据,否则插入新记录
                    var dailyEntity = dailyEntityList.SingleOrDefault(p =>
                                                                      p.FMachineID == daily.FMachineID && p.FWorkCenterID == daily.FWorkCenterID &&
                                                                      p.FShift == daily.FShift);

                    JITEF.DIME2Barcode.ICMODaily item = null;

                    if (dailyEntity != null)
                    {
                        item = dailyEntity;
                        context.ICMODaily.Attach(item);
                        context.Entry(item).State = EntityState.Modified;
                    }
                    else
                    {
                        var index = (Array.IndexOf(input.Dailies, daily) + dailyEntityList.Count + 1).ToString("000");

                        item = new JITEF.DIME2Barcode.ICMODaily();


                        item.FMachineID    = daily.FMachineID;
                        item.FWorkCenterID = daily.FWorkCenterID;
                        item.FShift        = daily.FShift;
                        item.FID           = Guid.NewGuid().ToString();
                        item.FBillNo       = "DA" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + index; //任务计划单号
                        item.FMOInterID    = input.FMOInterID;                                             //任务单号
                        item.FMOBillNo     = input.FMOBillNo;                                              //任务单号
                        item.FBiller       = this.AbpSession.UserId.ToString();                            //当前登录用户
                        item.FSrcID        = schedule.FID;

                        context.ICMODaily.Attach(item);
                        context.Entry(item).State = EntityState.Added;
                    }

                    item.FPlanAuxQty = daily.FPlanAuxQty;
                    item.FDate       = daily.FDate;
                }

                //更新任务计划单派工数
                //schedule.FPlanAuxQty = planTotalQty;



                context.SaveChanges();
                tran.Commit();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                tran.Rollback();
                throw;
            }


            return(new ICMODailyDto());
        }