From a9a0d7d6bb94e16ae1150f323cef68cf340fafb4 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Thu, 3 Aug 2023 16:21:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=8D=E5=8A=A1=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=BF=9D=E5=AD=98=E3=80=81=E8=8E=B7=E5=8F=96=E8=AF=A6?= =?UTF-8?q?=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrackingSystem/ServiceWorkFlowRunInfo.cs | 12 +- .../BookingOrder/BookingValueAddedService.cs | 18 +- .../Dto/QueryServiceProjectWithStatus.cs | 5 + .../Dtos/ServiceProjectWithStatusDto.cs | 12 +- .../Dtos/ServiceWorkFlowRunDto.cs | 15 + .../Interface/IServiceWorkFlowBaseService.cs | 3 + .../IServiceWorkFlowManageService.cs | 6 + .../ServiceWorkFlowBaseService.cs | 2 + .../ServiceWorkFlowManageService.cs | 290 ++++++++++++++---- 9 files changed, 293 insertions(+), 70 deletions(-) diff --git a/Myshipping.Application/Entity/TrackingSystem/ServiceWorkFlowRunInfo.cs b/Myshipping.Application/Entity/TrackingSystem/ServiceWorkFlowRunInfo.cs index 74f932e2..243d62c6 100644 --- a/Myshipping.Application/Entity/TrackingSystem/ServiceWorkFlowRunInfo.cs +++ b/Myshipping.Application/Entity/TrackingSystem/ServiceWorkFlowRunInfo.cs @@ -87,6 +87,16 @@ namespace Myshipping.Application.Entity /// /// 最后活动名称 /// - public int LST_ACT_NAME { get; set; } + public string LST_ACT_NAME { get; set; } + + /// + /// 是否已产生 1-已产生 0-未产生 + /// + public int IS_YIELD { get; set; } + + /// + /// 项目发生时间 + /// + public Nullable ACT_DATE { get; set; } } } diff --git a/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs b/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs index 78f808ea..39c154f3 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingValueAddedService.cs @@ -2225,13 +2225,14 @@ namespace Myshipping.Application } #endregion - + #region 获取服务项目列表 /// /// 获取服务项目列表 /// /// 查询服务项目和状态详情 /// 返回回执 - public async Task GetServiceProjectList(QueryServiceProjectWithStatus model) + [HttpPost("/BookingValueAdded/GetServiceProjectList")] + public async Task GetServiceProjectList([FromBody] QueryServiceProjectWithStatus model) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); @@ -2239,7 +2240,19 @@ namespace Myshipping.Application try { + var bookingOrder = _bookingOrderRepository.AsQueryable().Filter(null, true) + .First(a => a.Id == model.BookingId); + if (bookingOrder == null) + throw Oops.Oh($"订舱信息获取失败,订舱信息不存在或已作废"); + + QueryServiceProjectWithStatus queryInfo = new QueryServiceProjectWithStatus { + BookingId = model.BookingId, + QueryType = TrackingQueryTypeEnum.QUERY_SERVICE_PROJECT, + TenantId = bookingOrder.TenantId.Value + }; + + result = await _serviceWorkFlowManageService.GetEnableProjectList(queryInfo); } catch(Exception ex) { @@ -2249,6 +2262,7 @@ namespace Myshipping.Application return result; } + #endregion /// diff --git a/Myshipping.Application/Service/BookingOrder/Dto/QueryServiceProjectWithStatus.cs b/Myshipping.Application/Service/BookingOrder/Dto/QueryServiceProjectWithStatus.cs index cc503c86..06028d61 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/QueryServiceProjectWithStatus.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/QueryServiceProjectWithStatus.cs @@ -25,5 +25,10 @@ namespace Myshipping.Application /// 服务项目代码组 /// public string[] ProjectCodes { get; set; } + + /// + /// 租户ID + /// + public long TenantId { get; set; } } } diff --git a/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceProjectWithStatusDto.cs b/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceProjectWithStatusDto.cs index b630f64c..14b16b1e 100644 --- a/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceProjectWithStatusDto.cs +++ b/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceProjectWithStatusDto.cs @@ -49,13 +49,23 @@ namespace Myshipping.Application /// /// 发布日期 /// - public DateTime ReleaseDate { get; set; } + public Nullable ReleaseDate { get; set; } /// /// 状态代码列表(方便检索) /// public string[] StatusSKUCodeArgs { get; set; } + /// + /// 是否已完成 + /// + public bool IsYield { get; set; } + + /// + /// 完成时间 + /// + public Nullable ActDate { get; set; } + /// /// 状态列表 /// diff --git a/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceWorkFlowRunDto.cs b/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceWorkFlowRunDto.cs index d287ad7f..99158850 100644 --- a/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceWorkFlowRunDto.cs +++ b/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceWorkFlowRunDto.cs @@ -16,6 +16,11 @@ namespace Myshipping.Application /// public string PKId { get; set; } + /// + /// 服务项目主键 + /// + public string ServiceProjectId { get; set; } + /// /// 服务项目代码 /// @@ -26,6 +31,16 @@ namespace Myshipping.Application /// public string ServiceProjectName { get; set; } + /// + /// 是否已产生 1-已产生 0-未产生 + /// + public int IsYield { get; set; } + + /// + /// 项目发生时间 + /// + public Nullable ActDate { get; set; } + /// /// 状态列表 /// diff --git a/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowBaseService.cs b/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowBaseService.cs index a589c6ca..518ef0e6 100644 --- a/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowBaseService.cs +++ b/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowBaseService.cs @@ -129,5 +129,8 @@ namespace Myshipping.Application /// 是否不从缓存取值 /// 返回回执 Task> GetEnableProjectWithStatusList(string tenantId, bool isAvoidCache = false); + + + } } diff --git a/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowManageService.cs b/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowManageService.cs index a6c8ff41..d6d1e498 100644 --- a/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowManageService.cs +++ b/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowManageService.cs @@ -64,5 +64,11 @@ namespace Myshipping.Application /// 返回回执 Task ValidateCancelProject(TrackingMessageInfo info); + /// + /// 检索已选中并且可用的服务项目列表 + /// + /// 查询服务项目和状态详情 + /// 返回回执 + Task GetEnableProjectList(QueryServiceProjectWithStatus model); } } diff --git a/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowBaseService.cs b/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowBaseService.cs index 44de7433..3efa89d7 100644 --- a/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowBaseService.cs +++ b/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowBaseService.cs @@ -2014,5 +2014,7 @@ namespace Myshipping.Application return statusList; } #endregion + + } } diff --git a/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowManageService.cs b/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowManageService.cs index 1f3503cd..db9a58c6 100644 --- a/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowManageService.cs +++ b/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowManageService.cs @@ -131,6 +131,8 @@ namespace Myshipping.Application throw Oops.Oh($"报文Main的业务主键不能为空", typeof(InvalidOperationException)); } + var statusList = _serviceWorkFlowBaseService.GetEnableProjectWithStatusList(info.Main.OperTenantId.ToString()).GetAwaiter().GetResult(); + var projectList = _cache.Get>($"{CONST_CACHE_ENABLE_PROJECT}_{info.Main.OperTenantId}"); if (info.Main.PushType == TrackingPushTypeEnum.Project) @@ -142,13 +144,84 @@ namespace Myshipping.Application throw Oops.Oh($"推送类型是【服务项目】,服务项目列表不能为空", typeof(InvalidOperationException)); } - //提取 + //提取所有已经有run记录的 var runBaseList = _serviceWorkFlowRunInfoRepository.AsQueryable().Filter(null, true) .Where(a => a.BUSI_ID == info.Main.BusiId && a.BUSI_SYSTEM_CODE.Equals(info.Main.BusiSystemCode) && !a.IsDeleted && a.TenantId == info.Main.OperTenantId).ToList(); + + var needProjectArg = info.Main.ProjectList.Select(a=>a.ServiceProjectCode).ToArray(); + + var needProjectList = statusList.Where(a => needProjectArg.Contains(a.ProjectCode)).ToList(); + + var tskList = needProjectList.GroupJoin(runBaseList, l => l.WFPKId, + r => r.SERVICE_WF_ID, + (l, r) => + { + var currList = r.ToList(); + + if (currList.Count == 0) + { + //标识当前服务项目写入运行主表 + return new { OperType = "Insert", Info = l, Run = new ServiceWorkFlowRunInfo() }; + } + + return new { OperType = "Update", Info = l, Run = currList.FirstOrDefault() }; + }).ToList(); + + DateTime nowDate = DateTime.Now; + + tskList.ForEach(async tsk => { + if(tsk.OperType == "Insert") + { + ServiceWorkFlowRunInfo serviceWorkFlowRunInfo = new ServiceWorkFlowRunInfo + { + PK_ID = IDGen.NextID().ToString(), + SERVICE_WF_ID = tsk.Info.WFPKId, + BUSI_SYSTEM_CODE = info.Main.BusiSystemCode.ToUpper(), + BUSI_ID = info.Main.BusiId.ToUpper(), + MBL_NO = info.Main?.MBlNo.ToUpper(), + VESSEL_VOYNO = info.Main?.VesselVoyno.ToUpper(), + ORDER_NO = info.Main?.OrderNo, + STATUS = TaskStatusEnum.Create.ToString(), + RELEASE_VERSION = tsk.Info.ReleaseVersion, + ACTIVITIES_NUM = 0, + CreatedTime = nowDate, + UpdatedTime = nowDate, + CreatedUserId = long.Parse(info.Main.OperUserId), + CreatedUserName = info.Main.OperUserName, + TenantId = info.Main.OperTenantId, + TenantName = info.Main.OperTenantName, + SERVICE_PROJECT_CODE = tsk.Info.ProjectCode, + SERVICE_PROJECT_NAME = tsk.Info.ProjectName, + SERVICE_PROJECT_ID = tsk.Info.ProjectPKId, + IS_YIELD = 1, + ACT_DATE = nowDate, + }; + + await _serviceWorkFlowRunInfoRepository.InsertAsync(serviceWorkFlowRunInfo); + } + else if(tsk.OperType == "Update") + { + var runInfo = _serviceWorkFlowRunInfoRepository.AsQueryable() + .First(a => a.PK_ID == tsk.Run.PK_ID); + + runInfo.IS_YIELD = 1; + runInfo.ACT_DATE = nowDate; + + await _serviceWorkFlowRunInfoRepository.AsUpdateable(runInfo).UpdateColumns(it => new + { + it.ACT_DATE, + it.IS_YIELD, + }).ExecuteCommandAsync(); + } + }); + + result.succ = true; + result.msg = "推送成功"; + + return result; } - //校验状态代码是否一致,不一致直接返回错误不允许推送 var statusArg = info.Main.StatusList.Select(a => a?.StatusCode.ToUpper()) .Where(a => !string.IsNullOrWhiteSpace(a)).Distinct().ToArray(); @@ -432,62 +505,84 @@ namespace Myshipping.Application try { - - - var runList = _serviceWorkFlowRunInfoRepository.AsQueryable().Filter(null, true) - .LeftJoin((m, s) => m.PK_ID == s.RUN_ID) - .LeftJoin((m, s, rela) => - m.SERVICE_WF_ID == rela.SERVICE_WORKFLOW_ID && m.RELEASE_VERSION == rela.WF_VERSION) - .LeftJoin((m, s, rela, p) => - rela.SERVICE_PROJECT_ID == p.PK_ID) - .Where((m, s, rela, p) - => m.BUSI_SYSTEM_CODE == info.Main.BusiSystemCode && m.BUSI_ID == info.Main.BusiId && - info.Main.ServiceProjectCodeList.Contains(p.SERVICE_PROJECT_CODE)) - .Select((m, s) => new { Run = m, Sub = s }).ToList(); - - - var resultList = runList.GroupBy(a=>a.Run.PK_ID) - .Select(a => { - var currList = a.ToList(); - - var runInfo = currList.FirstOrDefault().Run; - - var showModel = new ServiceWorkFlowRunDto(); + result.succ = true; + result.ext = InnerGetRunListBySigleBusiness(info); + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"单票单服务项目查询失败,原因:{ex.Message}"; + } - showModel.PKId = runInfo.PK_ID; - showModel.ServiceProjectCode = runInfo.SERVICE_PROJECT_CODE; - showModel.ServiceProjectName = runInfo.SERVICE_PROJECT_NAME; + return result; + } + #endregion - showModel.ActivitiesList = currList.Where(t => t.Sub.IS_SUB == 0) - .Select(t => + #region 获取单票业务相关的服务项目运行列表 + /// + /// 获取单票业务相关的服务项目运行列表 + /// + /// 查询服务流程详情 + /// 返回查询列表 + private List InnerGetRunListBySigleBusiness(TrackingQueryMessageInfo info) + { + var runList = _serviceWorkFlowRunInfoRepository.AsQueryable() + .Filter(null, true) + .LeftJoin((m, s) => m.PK_ID == s.RUN_ID) + .LeftJoin((m, s, rela) => + m.SERVICE_WF_ID == rela.SERVICE_WORKFLOW_ID && m.RELEASE_VERSION == rela.WF_VERSION) + .LeftJoin((m, s, rela, p) => + rela.SERVICE_PROJECT_ID == p.PK_ID) + .Where((m, s, rela, p) + => m.BUSI_SYSTEM_CODE == info.Main.BusiSystemCode && m.BUSI_ID == info.Main.BusiId && + (info.Main.ServiceProjectCodeList == null || info.Main.ServiceProjectCodeList.Contains(p.SERVICE_PROJECT_CODE))) + .Select((m, s) => new { Run = m, Sub = s }).ToList(); + + var resultList = runList.GroupBy(a => a.Run.PK_ID) + .Select(a => { + var currList = a.ToList(); + + var runInfo = currList.FirstOrDefault().Run; + + var showModel = new ServiceWorkFlowRunDto(); + + showModel.PKId = runInfo.PK_ID; + showModel.ServiceProjectId = runInfo.SERVICE_PROJECT_ID; + showModel.ServiceProjectCode = runInfo.SERVICE_PROJECT_CODE; + showModel.ServiceProjectName = runInfo.SERVICE_PROJECT_NAME; + showModel.IsYield = runInfo.IS_YIELD; + showModel.ActDate = runInfo.ACT_DATE; + + showModel.ActivitiesList = currList.Where(t => t.Sub.IS_SUB == 0) + .Select(t => + { + var runModel = new ServiceWorkFlowActivitiesRunDto { - var runModel = new ServiceWorkFlowActivitiesRunDto - { - PKId = t.Sub.PK_ID, - ActDate = t.Sub.ACT_DATE, - ActId = t.Sub.ACT_ID, - ExecSortNo = t.Sub.EXEC_SORT_NO, - ActVal = t.Sub.ACT_VAL, - IsStart = t.Sub.IS_START, - IsEnd = t.Sub.IS_END, - IsYield = t.Sub.IS_YIELD, - RunId = t.Sub.RUN_ID, - ShowName = t.Sub.SHOW_NAME, - SourceType = t.Sub.SOURCE_TYPE, - StatusSKUCode = t.Sub.STATUS_SKU_CODE, - StatusSKUId = t.Sub.STATUS_SKU_ID - }; + PKId = t.Sub.PK_ID, + ActDate = t.Sub.ACT_DATE, + ActId = t.Sub.ACT_ID, + ExecSortNo = t.Sub.EXEC_SORT_NO, + ActVal = t.Sub.ACT_VAL, + IsStart = t.Sub.IS_START, + IsEnd = t.Sub.IS_END, + IsYield = t.Sub.IS_YIELD, + RunId = t.Sub.RUN_ID, + ShowName = t.Sub.SHOW_NAME, + SourceType = t.Sub.SOURCE_TYPE, + StatusSKUCode = t.Sub.STATUS_SKU_CODE, + StatusSKUId = t.Sub.STATUS_SKU_ID + }; - return runModel; - }).ToList(); + return runModel; + }).ToList(); - var subList = - currList.Where(t => t.Sub.IS_SUB == 1) - .Select(t => t.Sub).ToList(); + var subList = + currList.Where(t => t.Sub.IS_SUB == 1) + .Select(t => t.Sub).ToList(); - showModel.ActivitiesList = showModel.ActivitiesList.GroupJoin(subList, - l => l.PKId, r => r.PARENT_ID, - (l, r) => + showModel.ActivitiesList = showModel.ActivitiesList.GroupJoin(subList, + l => l.PKId, r => r.PARENT_ID, + (l, r) => { var currList = r.ToList(); @@ -513,25 +608,16 @@ namespace Myshipping.Application }; return subModel; - }).OrderBy(x=>x.ExecSortNo).ToList(); + }).OrderBy(x => x.ExecSortNo).ToList(); } return l; }).OrderBy(t => t.ExecSortNo).ToList(); - return showModel; - }).ToList(); - - result.succ = true; - result.ext = resultList; - } - catch (Exception ex) - { - result.succ = false; - result.msg = $"单票单服务项目查询失败,原因:{ex.Message}"; - } + return showModel; + }).ToList(); - return result; + return resultList; } #endregion @@ -558,7 +644,6 @@ namespace Myshipping.Application => m.BUSI_SYSTEM_CODE == info.Main.BusiSystemCode && m.BUSI_ID == info.Main.BusiId) .Select((m, s) => new { Run = m, Sub = s }).ToList(); - var resultList = runList.GroupBy(a => a.Run.PK_ID) .Select(a => { var currList = a.ToList(); @@ -1120,6 +1205,79 @@ namespace Myshipping.Application return result; } #endregion + + + #region 检索已选中并且可用的服务项目列表 + /// + /// 检索已选中并且可用的服务项目列表 + /// + /// 查询服务项目和状态详情 + /// 返回回执 + public async Task GetEnableProjectList(QueryServiceProjectWithStatus model) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + try + { + //先获取可用的服务项目 + var projectList = await _serviceWorkFlowBaseService.GetEnableProjectList(model.TenantId.ToString()); + + TrackingQueryMessageInfo messageInfo = new TrackingQueryMessageInfo { + Head = new TrackingMessageHeadInfo + { + GID = IDGen.NextID().ToString(), + MessageType = "PROJECT", + ReceiverId = "ServiceProjectStatus", + ReceiverName = "服务项目和状态", + SenderId = "BookingOrder", + SenderName = "海运订舱", + RequestDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), + Version = "2.0", + RequestAction = "AddOrModify", + },Main = new TrackingMessageQueryMainInfo { + BusiId = model.BookingId.ToString(), + BusiSystemCode = "BOOKING_ORDER", + TenantId = model.TenantId.ToString(), + } + }; + //在获取运行表已有的记录 + var runList = InnerGetRunListBySigleBusiness(messageInfo); + + var resultList = projectList.GroupJoin(runList, l => l.PKId, r => r.ServiceProjectId, (l, r) => { + var currList = r.ToList(); + + var runInfo = currList.FirstOrDefault(); + + var dto = new ServiceProjectWithStatusDto + { + ProjectPKId = l.PKId, + ProjectCode = l.ServiceProjectCode, + ProjectName = l.ServiceProjectName, + SortNo = l.SortNo + + }; + + if(runInfo != null) + { + dto.IsYield = runInfo.IsYield == 1 ? true : false; + dto.ActDate = runInfo.ActDate; + } + + return dto; + }).ToList(); + + result.succ = true; + result.ext = resultList; + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"检索已选中并且可用的服务项目列表失败,原因:{ex.Message}"; + } + + return result; + } + #endregion } }