private async Task <HandOverBill> saveHandOverBill(SaveHandOverBillInput input) { if (input == null) { throw new ArgumentNullException("input"); } var currentBill = await this._handOverBillRepository.FirstOrDefaultAsync(input.Id); if (currentBill == null) { throw new DomainException($"交接单[{input.Id}]不存在!"); } if (currentBill.BillState > HandOverBillState.Draft) { throw new UserFriendlyException($"交接单[{input.Id}]状态为[{currentBill.BillState.GetDescription()}],不可修改!"); } input.MapTo(currentBill); if (currentBill.TransferTargetType == HandOverTargetType.Department) { currentBill.TransferTargetSupplier?.Clear(); } else if (currentBill.TransferTargetType == HandOverTargetType.Supplier) { currentBill.TransferTargetDepartment?.Clear(); } return(currentBill); }
/// <summary> /// 发布交接单 /// </summary> public async Task <bool> PublishHandOverBill(SaveHandOverBillInput input) { var bill = await this.saveHandOverBill(input); if (bill.TransferTargetType == HandOverTargetType.Department && bill.TransferTargetDepartment.OrganizationUnitId == null) { throw new UserFriendlyException("部门交接单转入部门不可为空!"); } else if (bill.TransferTargetType == HandOverTargetType.Supplier && bill.TransferTargetSupplier.SupplierCode == null) { throw new UserFriendlyException("供方交接单转入供方代码不可为空!"); } if (!bill.BillLines.Any()) { throw new UserFriendlyException("请添加交接物料!"); } //判断所有道序是否都已经SAP质检 bool isAllInspected = true; foreach (var billLine in bill.BillLines) { if (billLine.CurrentProcess == null || billLine.CurrentProcess.IsEmpty()) { continue; //首个道序交接 } if (billLine.InspectState == HandOverBillLineInspectState.Inspected) { continue; //已检验,不用再调用接口检查 } try { bool isInspected = await this.isHandOverLineInspected(billLine.OrderInfo.OrderNumber, billLine.CurrentProcess.ProcessNumber); billLine.InspectState = isInspected ? HandOverBillLineInspectState.Inspected : HandOverBillLineInspectState.UnInspected; billLine.InspectStateErrorMessage = null; if (!isInspected) { isAllInspected = false; } } catch (Exception ex) { isAllInspected = false; billLine.InspectState = HandOverBillLineInspectState.Error; billLine.InspectStateErrorMessage = ex.Message; } await this._handOverBillLineRepository.UpdateAsync(billLine); //更新检验状态 } //是否所有交接行都已经SAP检验 if (isAllInspected) { bill.HandOverDate = DateTime.Now; bill.BillState = HandOverBillState.Published; await this._handOverBillRepository.UpdateAsync(bill); return(true); //发布成功 } else { throw new UserFriendlyException("存在未SAP质检的交接单行!"); } }
/// <summary> /// 保存交接单信息 /// </summary> public async Task SaveHandOverBill(SaveHandOverBillInput input) { var bill = await this.saveHandOverBill(input); await this._handOverBillRepository.UpdateAsync(bill); }