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);
        }
Exemplo n.º 2
0
        public async Task <int> Create(ICMODailyCreatDto input)
        {
            var icmo = MRepository.GetAll().SingleOrDefault(p => p.任务单号 == input.FMOBillNo);

            if (icmo == null)
            {
                this.EX(-1, $"{input.FMOBillNo} 任务单不存在,请检查");
            }

            var oplist = await SUbRepository.GetAll().ToListAsync();

            var equipmentList = await ERepository.GetAll().Where(p => p.FType == PublicEnum.EquipmentType.设备).ToListAsync();

            var orgs = await ORepository.GetAll().Where(p => p.FWorkshopType).ToListAsync();

            var eqShifts = await EsRepository.GetAll().ToListAsync();

            if (icmo != null)
            {
                var schedule = GetOrCreateSchedule(icmo);

                var org = orgs.SingleOrDefault(o => o.DisplayName == icmo.车间);

                if (org == null)
                {
                    this.EX(-1, $"找不到此车间:{icmo.车间},请检查组织架构信息");
                }

                foreach (var dailyItem in input.Dailies)
                {
                    var equipments = equipmentList.Where(e => e.FName == dailyItem.FMachineName && e.FWorkCenterID == org.Id);

                    if (equipments.Count() > 1)
                    {
                        this.EX(-1, $"【{org.DisplayName}】车间存在多个【{dailyItem.FMachineName}】设备");
                    }

                    var equipment = equipments.SingleOrDefault();

                    if (equipment == null)
                    {
                        this.EX(-1, $"在【{icmo.车间}】车间找不到设备:{dailyItem.FMachineName} ,请检查设备档案");
                    }

                    var shift = eqShifts.SingleOrDefault(p =>
                                                         p.FEqiupmentID == equipment.FInterID && p.FShift == dailyItem.FShift);

                    if (shift == null)
                    {
                        this.EX(-1, $"设备:{dailyItem.FMachineName} 的班次信息中不存在 【{dailyItem.FShift}】,请检查设备的班次信息");
                    }

                    var entity = schedule.Dailies.SingleOrDefault(p =>
                                                                  p.FDate == dailyItem.FDate && p.FMachineID == equipment.FInterID &&
                                                                  p.FShift == shift.Id);

                    var op = oplist.SingleOrDefault(p => p.FName == dailyItem.FOperID);

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

                    if (entity == null && dailyItem.FPlanAuxQty > 0)
                    {
                        entity = new Entities.ICMODaily
                        {
                            FMachineID      = equipment.FInterID,
                            FWorkCenterID   = org.Id,
                            FShift          = shift.Id,
                            FID             = Guid.NewGuid().ToString(),
                            FBillNo         = "DA" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + index, //任务计划单号
                            FMOInterID      = icmo.FMOInterID,                                              //任务单ID
                            FMOBillNo       = icmo.任务单号,                                                    //任务单号
                            FBiller         = AbpSession.UserId.ToString(),                                 //当前登录用户
                            FSrcID          = schedule.FID,
                            FPlanAuxQty     = dailyItem.FPlanAuxQty,
                            FBillTime       = DateTime.Now,
                            FDate           = dailyItem.FDate.Date,
                            FOperID         = op != null?op.FInterID:0,
                            FWorkCenterName = icmo.车间,
                            FWorker         = shift.FEmployeeID,
                            FPackQty        = dailyItem.PackQty
                        };
                        //插入新的日计划单
                        schedule.Dailies.Add(entity);
                    }
                    else if (dailyItem.FPlanAuxQty > 0)
                    {
                        schedule.FPlanAuxQty -= entity.FPlanAuxQty;
                        entity.FPlanAuxQty    = dailyItem.FPlanAuxQty;
                        schedule.FPlanAuxQty += entity.FPlanAuxQty;
                    }
                }

                //更新计划单
                SRepository.Update(schedule);
                return(schedule.Dailies.Count);
            }
            else
            {
                throw new UserFriendlyException(string.Format("任务单:{0}不存在", input.FMOBillNo));
            }
        }