/// <summary>
        /// 日计划单生成或更新派工单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <ICMODispBillListDto> Create(ICMODispBillCreateInput input)
        {
            decimal?totalCommitQty = 0;

            try
            {
                foreach (var dispBillI in input.Details)
                {
                    var dailyFid = dispBillI.FSrcID;
                    var entity   = await Repository.GetAll().SingleOrDefaultAsync(p => p.FSrcID == dailyFid);

                    if (entity == null)
                    {
                        /*
                         *派工单不存在,插入新派工单
                         */
                        entity = new ICMODispBill()
                        {
                            FID           = Guid.NewGuid().ToString(),
                            FSrcID        = dailyFid,
                            FWorkCenterID = dispBillI.FWorkCenterID,
                            FMachineID    = dispBillI.FMachineID,
                            FMOBillNo     = dispBillI.FMOBillNo,
                            FMOInterID    = dispBillI.FMOInterID,
                            FCommitAuxQty = dispBillI.FCommitAuxQty,
                            FBiller       = AbpSession.UserId.ToString(),
                            FDate         = DateTime.Now,
                            FBillNo       = "DI" + DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(1, 10).ToString()
                        };

                        totalCommitQty += dispBillI.FCommitAuxQty;

                        await Repository.InsertAsync(entity);
                    }
                    else
                    {
                        /*
                         *派工单已存在,更新派工单信息
                         */
                        entity.FWorkCenterID = dispBillI.FWorkCenterID;
                        entity.FWorker       = dispBillI.FWorker;
                        entity.FCommitAuxQty = dispBillI.FCommitAuxQty;
                        entity.FMachineID    = dispBillI.FMachineID;
                        entity.FDate         = DateTime.Now;

                        await Repository.UpdateAsync(entity);

                        totalCommitQty += entity.FCommitAuxQty;
                    }
                }

                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
示例#2
0
        public async Task <ICMODispBillListDto> Create(ICMODispBillCreateInput input)
        {
            try
            {
                // 循环生成修改派工单
                foreach (var itemDetail in input.Details)
                {
                    // 日计划单
                    ICMODaily mDaily = await JIT_ICMODaily.GetAll().SingleOrDefaultAsync(p => p.FID == itemDetail.FID);

                    // 判断是否存在
                    if (mDaily == null)
                    {
                        throw new UserFriendlyException("日计划单不存在");
                    }

                    // 查看是否已经存在
                    var entity =
                        JIT_ICMODispBill.GetAll().Where(p =>
                                                        p.FSrcID == itemDetail.FID && p.FID == itemDetail.ICMODispBillId)
                        .SingleOrDefault(p => true) ?? new ICMODispBill();
                    // 判断是增加还是修改
                    if (string.IsNullOrWhiteSpace(entity.FID))
                    {
                        /*
                         * 派工单不存在,插入新派工单
                         */
                        entity.FID       = Guid.NewGuid().ToString();
                        entity.FSrcID    = itemDetail.FID;
                        entity.FBiller   = AbpSession.UserId.ToString();
                        entity.FDate     = DateTime.Now.Date;
                        entity.FBillNo   = "DI" + DateTime.Now.ToString("yyyyMMddHHmmss") + entity.FID.Right(4);
                        entity.FBillTime = DateTime.Now;
                    }
                    else
                    {
                        /*
                         * 派工单已存在,更新派工单信息
                         */
                        mDaily.FCommitAuxQty -= entity.FCommitAuxQty;


                        entity.FDate = DateTime.Now;
                    }

                    // 修改派工
                    entity.FCommitAuxQty = itemDetail.FCommitAuxQty;
                    entity.FWorker       = itemDetail.FWorker;
                    entity.FShift        = itemDetail.FShift;
                    entity.FMachineID    = itemDetail.FMachineID;
                    entity.FMOBillNo     = itemDetail.FMOBillNo;
                    entity.FMOInterID    = itemDetail.FMOInterID;
                    entity.FWorkCenterID = mDaily.FWorkCenterID;

                    entity.FPackQty = itemDetail.FPackQty;
                    //
                    itemDetail.ICMODispBillId = string.IsNullOrWhiteSpace(itemDetail.ICMODispBillId)
                        ? "0"
                        : itemDetail.ICMODispBillId;
                    // 判断是增加还是修改
                    if (itemDetail.ICMODispBillId.Equals("0"))
                    {
                        await JIT_ICMODispBill.InsertAsync(entity);
                    }
                    else
                    {
                        await JIT_ICMODispBill.UpdateAsync(entity);
                    }

                    // 修改日计划
                    mDaily.FCommitAuxQty += entity.FCommitAuxQty;
                    mDaily.FWorker        = itemDetail.FWorker;
                    await JIT_ICMODaily.UpdateAsync(mDaily);
                }

                return(null);
            }
            catch (Exception e)
            {
                EX(-1, e.Message);
                throw;
            }
        }