/// <summary>
        /// 添加SAP交接单行
        /// </summary>
        public async Task AddSapHandOverBillLine(AddSapHandOverBillLineInput input)
        {
            var bill = await this._handOverBillRepository.GetAll()
                       .FirstAsync(b => b.Id == input.BillId);

            if (bill.BillState > HandOverBillState.Draft)
            {
                throw new UserFriendlyException($"交接单[{input.BillId}]状态为[{bill.BillState.GetDescription()}],不可修改!");
            }

            if (input.HandOverQuantity <= 0)
            {
                throw new UserFriendlyException($"交接数量必须大于0!");
            }

            SapMOrder sapOrder = await this._sapMOrderRepository.FirstOrDefaultAsync(input.SapMOrderId);

            if (sapOrder == null)
            {
                throw new DomainException($"订单[{input.SapMOrderId}]不存在!");
            }

            //取得SAP道序(含外协信息)
            SapMOrderProcess          sapProcess              = null; //本道序
            SapMOrderProcessCooperate sapProcessCooperate     = null;
            SapMOrderProcess          sapNextProcess          = null; //下道序
            SapMOrderProcessCooperate sapNextProcessCooperate = null;

            if (input.SapMOrderProcessId == null)
            {
                //首道序交接
                var sapFirstProcessWithCooperate = await this._sapMOrderManager.GetFirstSapMOrderProcess(sapOrder.Id);

                sapNextProcess          = sapFirstProcessWithCooperate?.ProcessLine;
                sapNextProcessCooperate = sapFirstProcessWithCooperate?.CooperateLine;
            }
            else
            {
                //非首道序交接
                var sapProcessWithCooperate = await this._sapMOrderManager.GetSapMOrderProcessListWithCooperateQuery()
                                              .Where(p => p.ProcessLine.Id == input.SapMOrderProcessId)
                                              .FirstOrDefaultAsync();

                if (sapProcessWithCooperate == null)
                {
                    throw new DomainException($"SAP道序[{input.SapMOrderProcessId}]不存在!");
                }

                sapProcess          = sapProcessWithCooperate.ProcessLine;
                sapProcessCooperate = sapProcessWithCooperate.CooperateLine;    //外协信息(只有东厂往西厂还的时候才有)

                var next = await this._sapMOrderManager.GetNextSapMOrderProcess(sapProcess.Id);

                sapNextProcess          = next?.ProcessLine;
                sapNextProcessCooperate = next?.CooperateLine;
            }

            //验证是否重复添加该SAP订单
            bool exists = await this._handOverBillLineRepository.GetAll()
                          .AnyAsync(bl => bl.HandOverBillId == input.BillId &&
                                    bl.OrderInfo.OrderNumber == sapOrder.OrderNumber);

            if (exists)
            {
                throw new UserFriendlyException($"SAP订单[{sapOrder.OrderNumber}]已添加交接,请勿重复添加!");
            }

            //TODO:验证道序是否可交接(根据转入转出部门)

            //构建交接行
            HandOverBillLine billLine = new HandOverBillLine
            {
                HandOverBillId   = bill.Id,
                HandOverBill     = bill,
                OrderInfo        = OrderInfo.CreateFromSap(sapOrder),
                ItemNumber       = sapOrder.MaterialNumber,
                DrawingNumber    = string.Empty,
                ItemDescription  = sapOrder.MaterialDescription,
                HandOverQuantity = input.HandOverQuantity,
                CurrentProcess   = OrderProcess.Empty(),
                NextProcess      = OrderProcess.Empty(),
                Remark           = input.Remark ?? "",
                LineState        = HandOverBillLineState.Pending
            };

            if (sapProcess != null)
            {
                billLine.CurrentProcess = OrderProcess.CreateFromSap(sapProcess, sapProcessCooperate);
            }
            if (sapNextProcess != null)
            {
                billLine.NextProcess = OrderProcess.CreateFromSap(sapNextProcess, sapNextProcessCooperate);
            }
            await this._handOverBillLineRepository.InsertAndGetIdAsync(billLine);
        }