diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs index e1373729..6399e0b9 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs @@ -2140,8 +2140,6 @@ namespace DS.WMS.Core.TaskPlat.Method var userId = long.Parse(user.UserId); DataResult> result = new(); - List taskIdList = []; // 查询结果中的任务主键列表 - List<(long taskId, int count)?> childTaskData = []; // 查询结果中任务的子任务列表 try { @@ -2780,7 +2778,7 @@ namespace DS.WMS.Core.TaskPlat.Method .LeftJoin((t, a, s) => t.OUT_BS_NO == s.Id); await SetCondition(queryable, whereList, taskType, taskStatLevel, querySearch.OtherQueryCondition, user); - + ISugarQueryable queryableTemp = queryable.Select((t, a, s) => new { PK_ID = t.Id.SelectAll(), @@ -2814,24 +2812,6 @@ namespace DS.WMS.Core.TaskPlat.Method #endif result = await queryableTemp.ToQueryPageAsync(querySearch.PageCondition); - if (result.Data?.Count > 0) - { - taskIdList = result.Data.Select(x => (long)x.Id).ToList(); - - // 查询子任务 - var childTaskTotalQueryable = tenantDb.Queryable().Where(x => taskIdList.Contains(x.ParentTaskId) && x.IsChild == true) - .GroupBy(x => new { x.ParentTaskId }) - .Select(x => new - { - ParentTaskId = x.ParentTaskId, - Count = SqlFunc.AggregateCount(x.ParentTaskId) - }); -#if DEBUG - var sql1 = childTaskTotalQueryable.ToSqlString(); -#endif - var childTaskTotal = await childTaskTotalQueryable.ToListAsync(); - childTaskData = childTaskTotal.Select(x => new ValueTuple?((x.ParentTaskId, x.Count))).ToList(); - } return result; } @@ -2841,6 +2821,8 @@ namespace DS.WMS.Core.TaskPlat.Method { if (result.Data?.Count > 0) { + List taskIdList = result.Data.Select(x => (long)x.Id).ToList(); // 查询结果中的任务主键列表 + // 查询任务接收人列表 var allRecvUserList = await tenantDb.Queryable() .Where(x => taskIdList.Contains(x.TaskId)) @@ -2854,6 +2836,19 @@ namespace DS.WMS.Core.TaskPlat.Method RecvUserStatusTime = x.StatusTime }).ToListAsync(); + // 查询子任务 + var childTaskTotalQueryable = tenantDb.Queryable().Where(x => taskIdList.Contains(x.ParentTaskId) && x.IsChild == true) + .GroupBy(x => new { x.ParentTaskId }) + .Select(x => new + { + ParentTaskId = x.ParentTaskId, + Count = SqlFunc.AggregateCount(x.ParentTaskId) + }); +#if DEBUG + var sql1 = childTaskTotalQueryable.ToSqlString(); +#endif + var childTaskTotal = await childTaskTotalQueryable.ToListAsync(); + // 一些特殊处理 foreach (var item in result.Data) { @@ -2915,7 +2910,7 @@ namespace DS.WMS.Core.TaskPlat.Method } // 4.赋值子任务数量 - item.ChildTaskCount = childTaskData.FirstOrDefault(x => x.Value.taskId == taskId)?.count ?? 0; + item.ChildTaskCount = childTaskTotal.FirstOrDefault(x => x.ParentTaskId == taskId)?.Count ?? 0; } } }