From 952eae1b6b85a1bba4ffd0cb53269321931c7350 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Fri, 11 Aug 2023 13:34:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=8D=E5=8A=A1=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=8B=89=E5=8F=96=E3=80=82=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=AE=A2=E8=88=B1=E5=8F=B0=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookingOrder/BookingOrderService.cs | 110 ++++--- .../Service/BookingOrder/Dto/GoodsStatus.cs | 5 +- .../Dto/QueryServiceProjectWithStatus.cs | 23 ++ .../Dtos/ServiceProjectWithStatusDto.cs | 10 + .../Dtos/ServiceWorkFlowRunDto.cs | 10 + .../Dtos/TrackingQueryMessageInfo.cs | 61 ++++ .../IServiceWorkFlowManageService.cs | 8 + .../ServiceWorkFlowManageService.cs | 288 +++++++++++++++++- 8 files changed, 466 insertions(+), 49 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 4ca2eca1..070cd8e5 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -449,7 +449,19 @@ namespace Myshipping.Application } var bookingidlist = list.Items.Select(x => x.Id).ToList(); - var itgoodsStatus = _goodsStatus.AsQueryable().LeftJoin(_goodsStatusConfig.AsQueryable(), + + if (App.Configuration["ServiceStatusOpenAuto"] == "1") + { + QueryServiceProjectWithStatusBatch batchQuery = new QueryServiceProjectWithStatusBatch { + BookingIds = bookingidlist.ToArray(), + QueryType = TrackingQueryTypeEnum.QUERY_SERVICE_ALL + }; + var queryList = _serviceWorkFlowManageService.GetEnableStatusListByBusinessBatch(batchQuery) + .GetAwaiter().GetResult(); + } + + var itgoodsStatus = + _goodsStatus.AsQueryable().LeftJoin(_goodsStatusConfig.AsQueryable(), (goods, config) => config.Id == goods.ConfigId && bookingidlist.Contains((long)goods.bookingId)). OrderBy((goods, config) => config.Sort). Select((goods, config) => new @@ -464,20 +476,23 @@ namespace Myshipping.Application CreatedUserId = config.CreatedUserId, Sort = config.Sort }).ToList(); - var configID = itgoodsStatus.Select(x => x.ConfigId).Distinct().ToList(); + var configID = itgoodsStatus.Select(x => x.ConfigId) + .Distinct().ToList(); + + var itconfigs = _goodsStatusConfig.AsQueryable() + .Where(x => configID.Contains(x.Id)).Select(config => new + { + bookingid = "", + ConfigId = config.Id, + SystemCode = config.SystemCode, + StatusName = config.StatusName, + FinishTime = "", + ExtData = "", + Remark = "", + CreatedUserId = config.CreatedUserId, + Sort = config.Sort + }).ToList(); - var itconfigs = _goodsStatusConfig.AsQueryable().Where(x => configID.Contains(x.Id)).Select(config => new - { - bookingid = "", - ConfigId = config.Id, - SystemCode = config.SystemCode, - StatusName = config.StatusName, - FinishTime = "", - ExtData = "", - Remark = "", - CreatedUserId = config.CreatedUserId, - Sort = config.Sort - }).ToList(); if (traceTime) { @@ -558,38 +573,41 @@ namespace Myshipping.Application { item.ATA = Convert.ToDateTime(item.ATA).ToString("yyyy-MM-dd"); } - var itgoods = itgoodsStatus.Where(x => x.CreatedUserId == item.CreatedUserId && x.bookingid == item.Id).OrderBy(x => x.Sort). - Select(x => new GoodsStatusList - { - ConfigId = x.ConfigId, - StatusName = x.StatusName, - SystemCode = x.SystemCode, - FinishTime = x.FinishTime, - ExtData = x.ExtData, - Remark = x.Remark, - Sort = x.Sort - }).ToList(); - - var itconfig = itconfigs.Where(x => x.CreatedUserId == item.CreatedUserId).OrderBy(x => x.Sort). - Select(x => new GoodsStatusList - { - ConfigId = x.ConfigId, - StatusName = x.StatusName, - SystemCode = x.SystemCode, - FinishTime = null, - ExtData = x.ExtData, - Remark = x.Remark, - Sort = x.Sort - }).ToList(); - - foreach (var ii in itgoods) - { - itconfig.RemoveAll(x => x.ConfigId == ii.ConfigId); - } - item.IsVGM = itgoods.Where(x => x.SystemCode == "YFVGM").FirstOrDefault() == null ? null : itgoods.Where(x => x.SystemCode == "YFVGM").Select(x => x.FinishTime).FirstOrDefault(); - item.IsCanDan = itgoods.Where(x => x.SystemCode == "YFCD").FirstOrDefault() == null ? null : itgoods.Where(x => x.SystemCode == "YFCD").Select(x => x.FinishTime).FirstOrDefault(); - item.IsZZFX = itgoods.Where(x => x.SystemCode == "ZZFX").FirstOrDefault() == null ? null : itgoods.Where(x => x.SystemCode == "ZZFX").Select(x => x.FinishTime).FirstOrDefault(); - item.GoodsStatusList = itgoods.Union(itconfig).OrderBy(x => x.Sort).ToList(); + + + var itgoods = itgoodsStatus.Where(x => x.CreatedUserId == item.CreatedUserId && x.bookingid == item.Id).OrderBy(x => x.Sort). + Select(x => new GoodsStatusList + { + ConfigId = x.ConfigId, + StatusName = x.StatusName, + SystemCode = x.SystemCode, + FinishTime = x.FinishTime, + ExtData = x.ExtData, + Remark = x.Remark, + Sort = x.Sort + }).ToList(); + + var itconfig = itconfigs.Where(x => x.CreatedUserId == item.CreatedUserId).OrderBy(x => x.Sort). + Select(x => new GoodsStatusList + { + ConfigId = x.ConfigId, + StatusName = x.StatusName, + SystemCode = x.SystemCode, + FinishTime = null, + ExtData = x.ExtData, + Remark = x.Remark, + Sort = x.Sort + }).ToList(); + + foreach (var ii in itgoods) + { + itconfig.RemoveAll(x => x.ConfigId == ii.ConfigId); + } + item.IsVGM = itgoods.Where(x => x.SystemCode == "YFVGM").FirstOrDefault() == null ? null : itgoods.Where(x => x.SystemCode == "YFVGM").Select(x => x.FinishTime).FirstOrDefault(); + item.IsCanDan = itgoods.Where(x => x.SystemCode == "YFCD").FirstOrDefault() == null ? null : itgoods.Where(x => x.SystemCode == "YFCD").Select(x => x.FinishTime).FirstOrDefault(); + item.IsZZFX = itgoods.Where(x => x.SystemCode == "ZZFX").FirstOrDefault() == null ? null : itgoods.Where(x => x.SystemCode == "ZZFX").Select(x => x.FinishTime).FirstOrDefault(); + item.GoodsStatusList = itgoods.Union(itconfig).OrderBy(x => x.Sort).ToList(); + //获取提箱返场状态 //var statuslog = statusloglist.Where(x => x.BookingId == item.Id).OrderByDescending(x => x.CreatedTime).ToList(); //var dto = statuslog.Adapt>(); diff --git a/Myshipping.Application/Service/BookingOrder/Dto/GoodsStatus.cs b/Myshipping.Application/Service/BookingOrder/Dto/GoodsStatus.cs index 6848b3cf..b2ae30e0 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/GoodsStatus.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/GoodsStatus.cs @@ -138,6 +138,9 @@ namespace Myshipping.Application.Service.BookingOrder.Dto /// public long? Sort { get; set; } - + /// + /// 是否最新记录 + /// + public bool IsLast { get; set; } = false; } } diff --git a/Myshipping.Application/Service/BookingOrder/Dto/QueryServiceProjectWithStatus.cs b/Myshipping.Application/Service/BookingOrder/Dto/QueryServiceProjectWithStatus.cs index 06028d61..a1ea384d 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/QueryServiceProjectWithStatus.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/QueryServiceProjectWithStatus.cs @@ -31,4 +31,27 @@ namespace Myshipping.Application /// public long TenantId { get; set; } } + + public class QueryServiceProjectWithStatusBatch + { + /// + /// 订舱ID数组 + /// + public long[] BookingIds { get; set; } + + /// + /// 0-查服务项目 1-查服务项目下的状态 + /// + public TrackingQueryTypeEnum QueryType { get; set; } + + /// + /// 服务项目代码组 + /// + 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 160b59d7..db49f1c3 100644 --- a/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceProjectWithStatusDto.cs +++ b/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceProjectWithStatusDto.cs @@ -183,5 +183,15 @@ namespace Myshipping.Application /// 是否结束 /// public bool IsEnd { get; set; } + + /// + /// 业务系统代码 + /// + public string BusiSystemCode { get; set; } + + /// + /// 业务主键 + /// + public string BusiId { get; set; } } } diff --git a/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceWorkFlowRunDto.cs b/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceWorkFlowRunDto.cs index a6216aa4..26cfbf84 100644 --- a/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceWorkFlowRunDto.cs +++ b/Myshipping.Application/Service/TrackingSystem/Dtos/ServiceWorkFlowRunDto.cs @@ -46,6 +46,16 @@ namespace Myshipping.Application /// public string WFPKId { get; set; } + /// + /// 业务系统代码 + /// + public string BusiSystemCode { get; set; } + + /// + /// 业务主键 + /// + public string BusiId { get; set; } + /// /// 状态列表 /// diff --git a/Myshipping.Application/Service/TrackingSystem/Dtos/TrackingQueryMessageInfo.cs b/Myshipping.Application/Service/TrackingSystem/Dtos/TrackingQueryMessageInfo.cs index 7836633e..e65c0024 100644 --- a/Myshipping.Application/Service/TrackingSystem/Dtos/TrackingQueryMessageInfo.cs +++ b/Myshipping.Application/Service/TrackingSystem/Dtos/TrackingQueryMessageInfo.cs @@ -79,4 +79,65 @@ namespace Myshipping.Application public bool IsReloadCache { get; set; } = false; } + + public class TrackingQueryBatchMessageInfo + { + /// + /// 表头 + /// + public TrackingMessageHeadInfo Head { get; set; } + + /// + /// 表体 + /// + public TrackingMessageQueryBatchMainInfo Main { get; set; } + } + + /// + /// 表体 + /// + public class TrackingMessageQueryBatchMainInfo + { + /// + /// 服务项目代码 + /// + public List ServiceProjectCodeList { get; set; } + + /// + /// 业务系统代码 + /// + [Required(ErrorMessage = "必填")] + public string BusiSystemCode { get; set; } + + /// + /// 业务主键 + /// + public List BusiIds { get; set; } + + /// + /// 查询类型 + /// + public TrackingQueryTypeEnum QueryType { get; set; } + + /// + /// 查询服务项目代码 + /// + public string[] QueryServiceProjectCode { get; set; } + + /// + /// 租户ID + /// + public string TenantId { get; set; } + + /// + /// 租户名称 + /// + public string TenantName { get; set; } + + /// + /// 强制刷新缓存 + /// + public bool IsReloadCache { get; set; } = false; + + } } diff --git a/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowManageService.cs b/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowManageService.cs index eeae98b2..77d09994 100644 --- a/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowManageService.cs +++ b/Myshipping.Application/Service/TrackingSystem/Interface/IServiceWorkFlowManageService.cs @@ -91,5 +91,13 @@ namespace Myshipping.Application /// 修改服务状态详情 /// 返回回执 Task CancelServiceStatus(ModifyServiceProjectStatusDto model); + + + /// + /// 批量检索服务项目下的状态列表 + /// + /// 批量查询服务项目和状态详情 + /// 返回回执 + Task GetEnableStatusListByBusinessBatch(QueryServiceProjectWithStatusBatch model); } } diff --git a/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowManageService.cs b/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowManageService.cs index 027085f2..ddc88f83 100644 --- a/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowManageService.cs +++ b/Myshipping.Application/Service/TrackingSystem/ServiceWorkFlowManageService.cs @@ -1875,8 +1875,8 @@ namespace Myshipping.Application ActSortNo = c.ActSortNo, ShowName = c.ShowName, IsYield = false, - StatusSKUCode = b.StatusSKUCode, - ActRemark = b.ActRemark, + StatusSKUCode = c.StatusSKUCode, + ActRemark = c.ActRemark, WFSortNo = l.SortNo, CalcSortNo = (decimal)b.ActSortNo + (c.ActSortNo * 0.001m) }).ToList()); @@ -2143,5 +2143,289 @@ namespace Myshipping.Application return result; } + + /// + /// 批量检索服务项目下的状态列表 + /// + /// 批量查询服务项目和状态详情 + /// 返回回执 + public async Task GetEnableStatusListByBusinessBatch(QueryServiceProjectWithStatusBatch model) + { + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + try + { + var statuList = await _serviceWorkFlowBaseService.GetEnableProjectWithStatusList(model.TenantId.ToString()); + + TrackingQueryBatchMessageInfo messageInfo = new TrackingQueryBatchMessageInfo + { + 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 TrackingMessageQueryBatchMainInfo + { + BusiIds = model.BookingIds.Select(a=>a.ToString()).ToList(), + BusiSystemCode = "BOOKING_ORDER", + TenantId = model.TenantId.ToString(), + } + }; + + DateTime bDate = DateTime.Now; + //在获取运行表已有的记录 + var runList = InnerGetRunListBySingleBusinessBatch(messageInfo); + + DateTime eDate = DateTime.Now; + TimeSpan ts = eDate.Subtract(bDate); + var timeDiff = ts.TotalMilliseconds; + + _logger.LogInformation("测试读取服务状态-读取数据库记录 耗时:{timeDiff}ms. ", timeDiff); + + int lastWFSortNo = 0; + int calcNum = 1; + + var resultList = statuList.Join(runList, l => l.WFPKId, r => r.WFPKId, + (l, r) => { + + var runInfo = r; + + var rltList = new List(); + + if (runInfo.IsYield == 1) + { + if (runInfo.ActivitiesList == null || (runInfo.ActivitiesList != null && runInfo.ActivitiesList.Count == 0)) + { + l.StatusList.ForEach(b => { + rltList.Add(new ServiceProjectStatusDto + { + ActPKId = b.ActPKId, + ActSortNo = b.ActSortNo, + ShowName = b.ShowName, + IsYield = false, + StatusSKUCode = b.StatusSKUCode, + ActRemark = b.ActRemark, + WFSortNo = l.SortNo, + CalcSortNo = (decimal)b.ActSortNo, + BusiSystemCode = runInfo.BusiSystemCode, + BusiId = runInfo.BusiId, + }); + + if (b.SubStatusList != null && b.SubStatusList.Count > 0) + { + rltList.AddRange(b.SubStatusList.Select(c => new ServiceProjectStatusDto + { + ActPKId = c.ActPKId, + ActSortNo = c.ActSortNo, + ShowName = c.ShowName, + IsYield = false, + StatusSKUCode = b.StatusSKUCode, + ActRemark = b.ActRemark, + WFSortNo = l.SortNo, + CalcSortNo = (decimal)b.ActSortNo + (c.ActSortNo * 0.001m), + BusiSystemCode = runInfo.BusiSystemCode, + BusiId = runInfo.BusiId, + }).ToList()); + } + }); + } + else + { + runInfo.ActivitiesList.ForEach(b => { + rltList.Add(new ServiceProjectStatusDto + { + ActPKId = b.ActId, + ActSortNo = b.ExecSortNo, + ShowName = b.ShowName, + IsYield = b.IsYield == 1 ? true : false, + ActDate = b.ActDate, + ActVal = b.ActVal, + StatusSKUCode = b.StatusSKUCode, + ActRemark = b.ActRemark, + WFSortNo = l.SortNo, + CalcSortNo = (decimal)b.ExecSortNo, + BusiSystemCode = runInfo.BusiSystemCode, + BusiId = runInfo.BusiId, + }); + + if (b.SubList != null && b.SubList.Count > 0) + { + rltList.AddRange(b.SubList.Select(c => new ServiceProjectStatusDto + { + ActPKId = c.ActId, + ActSortNo = c.ExecSortNo, + ShowName = c.ShowName, + IsYield = c.IsYield == 1 ? true : false, + ActDate = c.ActDate, + ActVal = c.ActVal, + StatusSKUCode = c.StatusSKUCode, + ActRemark = c.ActRemark, + WFSortNo = l.SortNo, + CalcSortNo = (decimal)b.ExecSortNo + (c.ExecSortNo * 0.001m), + BusiSystemCode = runInfo.BusiSystemCode, + BusiId = runInfo.BusiId, + }).ToList()); + } + }); + } + } + + if (rltList != null && rltList.Count > 0) + { + var maxSort = rltList.Max(t => t.CalcSortNo); + rltList.FirstOrDefault(t => t.CalcSortNo == maxSort).IsEnd = true; + } + return rltList; + }).SelectMany(b => b).OrderBy(b => b.WFSortNo).Select(b => { + if (lastWFSortNo == 0) + { + b.GroupName = calcNum.ToString(); + lastWFSortNo = b.WFSortNo; + } + else if (b.WFSortNo == lastWFSortNo) + { + b.GroupName = calcNum.ToString(); + } + else + { + ++calcNum; + lastWFSortNo = b.WFSortNo; + b.GroupName = calcNum.ToString(); + } + + return b; + }).OrderBy(b => b.WFSortNo).ThenBy(b => b.CalcSortNo).ToList(); + + + result.succ = true; + result.ext = resultList; + } + catch (Exception ex) + { + result.succ = false; + result.msg = $"检索服务项目下的状态列表失败,原因:{ex.Message}"; + } + + return result; + } + + + #region 获取单票业务相关的服务项目运行列表 + /// + /// 获取单票业务相关的服务项目运行列表 + /// + /// 查询服务流程详情 + /// 返回查询列表 + private List InnerGetRunListBySingleBusinessBatch(TrackingQueryBatchMessageInfo 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) + .InnerJoin((m, s, rela, p) => + rela.SERVICE_PROJECT_ID == p.PK_ID) + .Where((m, s, rela, p) + => m.BUSI_SYSTEM_CODE == info.Main.BusiSystemCode && info.Main.BusiIds.Contains(m.BUSI_ID) && + (info.Main.ServiceProjectCodeList == null || info.Main.ServiceProjectCodeList.Contains(p.SERVICE_PROJECT_CODE))) + .Select((m, s, rela, p) => + new { Run = m, Sub = s }).ToList(); + + var resultList = runList.GroupBy(a => $"{a.Run.BUSI_ID}_{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.WFPKId = runInfo.SERVICE_WF_ID; + showModel.BusiId = runInfo.BUSI_ID; + showModel.BusiSystemCode = runInfo.BUSI_SYSTEM_CODE; + + showModel.ActivitiesList = currList.Where(t => + !string.IsNullOrWhiteSpace(t.Sub.PK_ID) && t.Sub.IS_SUB == 0) + .Select(t => + { + 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, + ActRemark = t.Sub.ACT_REMARK, + }; + + return runModel; + }).ToList(); + + var subList = + currList.Where(t => + !string.IsNullOrWhiteSpace(t.Sub.PK_ID) && 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) => + { + var currList = r.ToList(); + + if (currList.Count > 0) + { + l.SubList = currList.Select(x => { + + var subModel = new ServiceWorkFlowActivitiesRunSubDto + { + PKId = x.PK_ID, + ActDate = x.ACT_DATE, + ActId = x.ACT_ID, + ExecSortNo = x.EXEC_SORT_NO, + ActVal = x.ACT_VAL, + IsStart = x.IS_START, + IsEnd = x.IS_END, + IsYield = x.IS_YIELD, + RunId = x.RUN_ID, + ShowName = x.SHOW_NAME, + SourceType = x.SOURCE_TYPE, + StatusSKUCode = x.STATUS_SKU_CODE, + StatusSKUId = x.STATUS_SKU_ID, + ActRemark = x.ACT_REMARK + }; + + return subModel; + }).OrderBy(x => x.ExecSortNo).ToList(); + } + + return l; + }).OrderBy(t => t.ExecSortNo).ToList(); + + return showModel; + }).ToList(); + + return resultList; + } + #endregion } }