簡單C#遞迴(向前查詢上工序)

胖头孙發表於2024-09-19

///
<summary> /// 遞迴查詢前工序,直到找到沒有跳序的前工序 /// </summary> /// <param name="process"></param> /// <returns></returns> private async Task<List<string>> HasReportedWorkAsync(List<WorkOrderProcedureEntity> proceduList) { if (proceduList.Count <= 0) return new List<string>(); //前工序ID var pId = proceduList.Select(x => x.PreNid).ToList(); //查詢前工序任務 var preWOProList = await BaseDal.Db.Queryable<WorkOrderProcedureEntity>().Where(p => p.WorkorderId == proceduList[0].WorkorderId && p.IsDelete == 0 && pId.Contains(p.OperationNo)).ToListAsync(); if (preWOProList.Count <= 0) return new List<string>(); //查詢未跳序的工序 var isFlagSkip = preWOProList.Where(x => x.SkipOperation == 0).ToList(); //沒有未跳序並且有前序時 if (isFlagSkip.Count <= 0 && preWOProList.Count > 0) { //沒有未跳序的工序,則繼續往上工序找 return await HasReportedWorkAsync(preWOProList); } else { //存在沒有跳序的工序,則直接返回 return preWOProList.Select(x => x.Nid).ToList(); } }

相關文章