private void ConvertRequest(int requestId) { #region Создание заявки var request = Executor.GetQuery <WorkflowBusinessLogic.Requests.GetRequestByIdQuery>().Process(q => q.Execute(requestId)); var protectionDocTypeCode = request.ProtectionDocType.Code; DicProtectionDocType newProtectionDocType = null; DicProtectionDocSubType newProtectionDocSubType = null; string initialStageCode = null; switch (protectionDocTypeCode) { case DicProtectionDocTypeCodes.RequestTypeUsefulModelCode: newProtectionDocType = Executor.GetQuery <GetDicProtectionDocTypebyCodeQuery>().Process(q => q.Execute(DicProtectionDocTypeCodes.RequestTypeInventionCode)); initialStageCode = RouteStageCodes.I_02_1; break; case DicProtectionDocTypeCodes.RequestTypeInventionCode: newProtectionDocType = Executor.GetQuery <GetDicProtectionDocTypebyCodeQuery>().Process(q => q.Execute(DicProtectionDocTypeCodes.RequestTypeUsefulModelCode)); initialStageCode = RouteStageCodes.UM_02_1; break; case DicProtectionDocTypeCodes.RequestTypeTrademarkCode: initialStageCode = request.CurrentWorkflow.FromStage.Code; newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.CollectiveTrademark)); break; } if (initialStageCode == null) { return; } var newRequest = _mapper.Map <Request>(request); newRequest.ProtectionDocTypeId = newProtectionDocType?.Id ?? request.ProtectionDocTypeId; newRequest.RequestTypeId = newProtectionDocSubType?.Id ?? request.RequestTypeId; newRequest.DateCreate = DateTimeOffset.Now; Executor.GetHandler <GenerateRequestNumberHandler>().Process(h => h.Execute(newRequest)); var newRequestId = Executor.GetCommand <CreateRequestCommand>().Process(c => c.Execute(newRequest)); var initialStage = Executor.GetQuery <GetDicRouteStageByCodeQuery>() .Process(q => q.Execute(initialStageCode)); var initialWorkflow = new RequestWorkflow { CurrentUserId = request.CurrentWorkflow.FromUserId, OwnerId = newRequestId, CurrentStageId = initialStage.Id, RouteId = initialStage.RouteId, IsComplete = initialStage.IsLast, IsSystem = initialStage.IsSystem, IsMain = initialStage.IsMain, }; Executor.GetCommand <CreateRequestWorkflowCommand>() .Process(c => c.Execute(initialWorkflow)); newRequest.CurrentWorkflowId = initialWorkflow.Id; Executor.GetCommand <UpdateRequestCommand>().Process(c => c.Execute(newRequest)); #endregion #region Биб. данные var newConventionInfos = _mapper.Map <RequestConventionInfo[]>(request.RequestConventionInfos); foreach (var conventionInfo in newConventionInfos) { conventionInfo.RequestId = newRequestId; Executor.GetCommand <CreateConventionInfoCommand>().Process(c => c.Execute(conventionInfo)); } var newEarlyRegs = _mapper.Map <RequestEarlyReg[]>(request.EarlyRegs); foreach (var earlyReg in newEarlyRegs) { earlyReg.RequestId = newRequestId; Executor.GetCommand <CreateRequestEarlyRegCommand>().Process(c => c.Execute(earlyReg)); } var newIcgsRequests = _mapper.Map <ICGSRequest[]>(request.ICGSRequests); foreach (var icgsRequest in newIcgsRequests) { icgsRequest.RequestId = newRequestId; Executor.GetCommand <CreateRequestIcgsCommand>().Process(c => c.Execute(icgsRequest)); } var newIpcRequests = _mapper.Map <IPCRequest[]>(request.IPCRequests); foreach (var ipcRequest in newIpcRequests) { ipcRequest.RequestId = newRequestId; Executor.GetCommand <CreateIpcRequestCommand>().Process(c => c.Execute(ipcRequest)); } var newIcisRequests = _mapper.Map <ICISRequest[]>(request.ICISRequests); foreach (var icisRequest in newIcisRequests) { icisRequest.RequestId = newRequestId; Executor.GetCommand <CreateRequestIcisCommand>().Process(c => c.Execute(icisRequest)); } foreach (var colorTz in request.ColorTzs) { var newColorTz = new DicColorTZRequestRelation { ColorTzId = colorTz.ColorTzId, RequestId = newRequestId }; Executor.GetCommand <CreateRequestColorTzCommand>().Process(c => c.Execute(newColorTz)); } foreach (var icfem in request.Icfems) { var newIcfem = new DicIcfemRequestRelation { DicIcfemId = icfem.DicIcfemId, RequestId = newRequestId }; Executor.GetCommand <CreateRequestIcfemCommand>().Process(c => c.Execute(newIcfem)); } #endregion #region Контрагенты var newCustomers = _mapper.Map <RequestCustomer[]>(request.RequestCustomers); foreach (var customer in newCustomers) { customer.RequestId = newRequestId; Executor.GetCommand <CreateRequestCustomerCommand>().Process(c => c.Execute(customer)); } #endregion }
/// <summary> /// Преобразование заявки /// </summary> /// <param name="requestId">Идентификатор преобразуемой заявки</param> private void ConvertRequest(int requestId) { var request = Executor.GetQuery <GetRequestByIdQuery>().Process(q => q.Execute(requestId)); var workflows = Executor.GetQuery <GetRequestWorkflowsByRequestIdQuery>().Process(q => q.Execute(requestId)); #region Генерация уведомления var notificationCode = string.Empty; var hasBeenOnFullExam = workflows.Any(w => w.CurrentStage.Code == RouteStageCodes.TZFirstFullExpertizePerformerChoosing); var trademarkTypeCode = request.SpeciesTradeMark.Code; //Смерджили два справочника, получилось так, не стал трогать, мало ли прийдется вернуть if (hasBeenOnFullExam) { if (trademarkTypeCode == DicProtectionDocSubtypeCodes.CollectiveTrademark) { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } else { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } } else { if (trademarkTypeCode == DicProtectionDocSubtypeCodes.CollectiveTrademark) { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } else { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } } var userInputDto = new UserInputDto { Code = notificationCode, Fields = new List <KeyValuePair <string, string> >(), OwnerId = requestId, OwnerType = Owner.Type.Request }; Executor.GetHandler <CreateDocumentHandler>().Process(h => h.Execute(requestId, Owner.Type.Request, notificationCode, DocumentType.Outgoing, userInputDto)); #endregion #region Создание заявки var protectionDocTypeCode = request.ProtectionDocType.Code; var protectionDocSubtypeCode = request.RequestType.Code; DicProtectionDocType newProtectionDocType = null; DicProtectionDocSubType newProtectionDocSubType = null; string initialStageCode = null; switch (protectionDocTypeCode) { //todo перенести коды в классы case DicProtectionDocTypeCodes.RequestTypeUsefulModelCode: newProtectionDocType = Executor.GetQuery <GetDicProtectionDocTypebyCodeQuery>().Process(q => q.Execute(DicProtectionDocTypeCodes.RequestTypeInventionCode)); initialStageCode = RouteStageCodes.I_02_1; switch (protectionDocSubtypeCode) { case DicProtectionDocSubtypeCodes.NationalUsefulModel: newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.NationalInvention)); break; case "03_UsefulModel": newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute("03")); break; case "04_UsefulModel": newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute("04")); break; } break; case DicProtectionDocTypeCodes.RequestTypeInventionCode: newProtectionDocType = Executor.GetQuery <GetDicProtectionDocTypebyCodeQuery>().Process(q => q.Execute(DicProtectionDocTypeCodes.RequestTypeUsefulModelCode)); initialStageCode = RouteStageCodes.UM_02_1; switch (protectionDocSubtypeCode) { case DicProtectionDocSubtypeCodes.NationalInvention: newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.NationalUsefulModel)); break; case "03": newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute("03_UsefulModel")); break; case "04": newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute("04_UsefulModel")); break; } break; case DicProtectionDocTypeCodes.RequestTypeTrademarkCode: if (request.SpeciesTradeMark.Code == DicProtectionDocSubtypeCodes.CollectiveTrademark) { newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.RegularTradeMark)); } else { newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.CollectiveTrademark)); } request.SpeciesTradeMark = newProtectionDocSubType; request.SpeciesTradeMarkId = newProtectionDocSubType.Id; Executor.GetCommand <UpdateRequestCommand>().Process(c => c.Execute(request)); return; } if (initialStageCode == null) { return; } var newRequest = _mapper.Map <Request>(request); newRequest.ProtectionDocTypeId = newProtectionDocType?.Id ?? request.ProtectionDocTypeId; newRequest.RequestTypeId = newProtectionDocSubType?.Id ?? request.RequestTypeId; newRequest.DateCreate = DateTimeOffset.Now; Executor.GetHandler <GenerateRequestNumberHandler>().Process(h => h.Execute(newRequest)); var newRequestId = Executor.GetCommand <CreateRequestCommand>().Process(c => c.Execute(newRequest)); var initialStage = Executor.GetQuery <GetDicRouteStageByCodeQuery>() .Process(q => q.Execute(initialStageCode)); var initialWorkflow = new RequestWorkflow { CurrentUserId = WorkflowRequest.NextStageUserId, OwnerId = newRequestId, CurrentStageId = initialStage.Id, RouteId = initialStage.RouteId, IsComplete = initialStage.IsLast, IsSystem = initialStage.IsSystem, IsMain = initialStage.IsMain, }; Executor.GetCommand <CreateRequestWorkflowCommand>() .Process(c => c.Execute(initialWorkflow)); newRequest.CurrentWorkflowId = initialWorkflow.Id; newRequest.StatusId = initialStage.RequestStatusId; Executor.GetCommand <UpdateRequestCommand>().Process(c => c.Execute(newRequest)); #endregion #region Биб. данные var newConventionInfos = _mapper.Map <RequestConventionInfo[]>(request.RequestConventionInfos); foreach (var conventionInfo in newConventionInfos) { conventionInfo.RequestId = newRequestId; Executor.GetCommand <CreateConventionInfoCommand>().Process(c => c.Execute(conventionInfo)); } var newEarlyRegs = _mapper.Map <RequestEarlyReg[]>(request.EarlyRegs); foreach (var earlyReg in newEarlyRegs) { earlyReg.RequestId = newRequestId; Executor.GetCommand <CreateRequestEarlyRegCommand>().Process(c => c.Execute(earlyReg)); } var newIcgsRequests = _mapper.Map <ICGSRequest[]>(request.ICGSRequests); foreach (var icgsRequest in newIcgsRequests) { icgsRequest.RequestId = newRequestId; Executor.GetCommand <CreateRequestIcgsCommand>().Process(c => c.Execute(icgsRequest)); } var newIpcRequests = _mapper.Map <IPCRequest[]>(request.IPCRequests); foreach (var ipcRequest in newIpcRequests) { ipcRequest.RequestId = newRequestId; Executor.GetCommand <CreateIpcRequestCommand>().Process(c => c.Execute(ipcRequest)); } var newIcisRequests = _mapper.Map <ICISRequest[]>(request.ICISRequests); foreach (var icisRequest in newIcisRequests) { icisRequest.RequestId = newRequestId; Executor.GetCommand <CreateRequestIcisCommand>().Process(c => c.Execute(icisRequest)); } foreach (var colorTz in request.ColorTzs) { var newColorTz = new DicColorTZRequestRelation { ColorTzId = colorTz.ColorTzId, RequestId = newRequestId }; Executor.GetCommand <CreateRequestColorTzCommand>().Process(c => c.Execute(newColorTz)); } foreach (var icfem in request.Icfems) { var newIcfem = new DicIcfemRequestRelation { DicIcfemId = icfem.DicIcfemId, RequestId = newRequestId }; Executor.GetCommand <CreateRequestIcfemCommand>().Process(c => c.Execute(newIcfem)); } #endregion #region Контрагенты var newCustomers = _mapper.Map <RequestCustomer[]>(request.RequestCustomers); foreach (var customer in newCustomers) { customer.RequestId = newRequestId; Executor.GetCommand <CreateRequestCustomerCommand>().Process(c => c.Execute(customer)); } #endregion }
public async Task <ConvertResponseDto> ExecuteAsync(ConvertDto convertDto) { int requestId = convertDto.OwnerId; var request = await Executor.GetQuery <GetRequestByIdQuery>().Process(q => q.ExecuteAsync(requestId)); var workflows = Executor.GetQuery <GetRequestWorkflowsByRequestIdQuery>().Process(q => q.Execute(requestId)); var result = new ConvertResponseDto(); var fullExamCodes = new[] { RouteStageCodes.TZFirstFullExpertizePerformerChoosing, RouteStageCodes.TZFirstFullExpertize, RouteStageCodes.TZSecondFullExpertizePerformerChoosing, RouteStageCodes.TZSecondFullExpertize }; #region Генерация уведомления string notificationCode; var hasBeenOnFullExam = workflows.Any(w => fullExamCodes.Contains(w.CurrentStage.Code)); var trademarkTypeCode = request.SpeciesTradeMark.Code; //Смерджили два справочника, получилось так, не стал трогать, мало ли прийдется вернуть if (hasBeenOnFullExam) { if (trademarkTypeCode == DicProtectionDocSubtypeCodes.CollectiveTrademark) { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } else { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } } else { if (trademarkTypeCode == DicProtectionDocSubtypeCodes.CollectiveTrademark) { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } else { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } } var userInputDto = new UserInputDto { Code = notificationCode, Fields = new List <KeyValuePair <string, string> >(), OwnerId = requestId, OwnerType = Owner.Type.Request }; Executor.GetHandler <WorkflowBusinessLogic.Document.CreateDocumentHandler>().Process(h => h.Execute(requestId, Owner.Type.Request, notificationCode, DocumentType.Outgoing, userInputDto)); #endregion #region Преобразование заявки var protectionDocTypeCode = request.ProtectionDocType.Code; request = await Executor.GetQuery <GetRequestByIdQuery>().Process(q => q.ExecuteAsync(requestId)); switch (protectionDocTypeCode) { case DicProtectionDocTypeCodes.RequestTypeTrademarkCode: if (!string.IsNullOrEmpty(convertDto.ColectiveTrademarkParticipantsInfo)) { request.ColectiveTrademarkParticipantsInfo = convertDto.ColectiveTrademarkParticipantsInfo; } DicProtectionDocSubType newProtectionDocSubType = null; if (request.SpeciesTradeMark.Code == DicProtectionDocSubtypeCodes.CollectiveTrademark) { newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.RegularTradeMark)); } else { newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.CollectiveTrademark)); } request.SpeciesTradeMark = newProtectionDocSubType; request.SpeciesTradeMarkId = newProtectionDocSubType.Id; Executor.GetCommand <WorkflowBusinessLogic.Requests.UpdateRequestCommand>().Process(c => c.Execute(request)); result.SpeciesTradeMarkId = request.SpeciesTradeMarkId; result.ColectiveTrademarkParticipantsInfo = request.ColectiveTrademarkParticipantsInfo; result.SpeciesTrademarkCode = request.SpeciesTradeMark?.Code; break; } #endregion return(result); }