diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 95a790ca..b373fa60 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -195,26 +195,23 @@ public class BalanceService : IBalanceService CostId = request.CostId }; - // 在部门内部再次按照餐次分组 - foreach (var businessShiftGroup in departmentGroup.GroupBy(x => x.BusinessShiftCode)) - { // 每个餐次人数 - obj.BreakfastNumberOfPeople = businessShiftGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]); + obj.BreakfastNumberOfPeople = departmentGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]); - obj.LunchNumberOfPeople = businessShiftGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]); + obj.LunchNumberOfPeople = departmentGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]); - obj.DinnerNumberOfPeople = businessShiftGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]); + obj.DinnerNumberOfPeople = departmentGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]); - obj.LateNightNumberOfPeople = businessShiftGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]); + obj.LateNightNumberOfPeople = departmentGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]); //餐次金额 - obj.BreakfastAmount = businessShiftGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Sum(x => x.Amount); + obj.BreakfastAmount = departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Sum(x => x.Amount); - obj.LunchAmount = businessShiftGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Sum(x => x.Amount); + obj.LunchAmount = departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Sum(x => x.Amount); - obj.DinnerAmount = businessShiftGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Sum(x => x.Amount); + obj.DinnerAmount = departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Sum(x => x.Amount); - obj.LateNightAmount = businessShiftGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Sum(x => x.Amount); + obj.LateNightAmount = departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Sum(x => x.Amount); // 每个餐次单价 obj.BreakfastPrice = obj.BreakfastAmount / obj.BreakfastNumberOfPeople; @@ -223,8 +220,8 @@ public class BalanceService : IBalanceService obj.LateNightPrice = obj.LateNightAmount / obj.LateNightNumberOfPeople; // 每个部门餐次中的 OriginTenantId - obj.OriginTenantId = businessShiftGroup.FirstOrDefault()?.OriginTenantId; - } + obj.OriginTenantId = departmentGroup.FirstOrDefault()?.OriginTenantId; + // 总人数 总金额 obj.TotalNumberOfPeople = obj.BreakfastNumberOfPeople + obj.LunchNumberOfPeople + obj.DinnerNumberOfPeople + obj.LateNightNumberOfPeople; @@ -266,26 +263,23 @@ public class BalanceService : IBalanceService DepartmentNo = originTenantIdGroup.First().DepartmentNo }; - // 在人事范围内部再次按照餐次分组 - foreach (var businessShiftGroup in originTenantIdGroup.GroupBy(x => x.BusinessShiftCode)) - { // 每个餐次人数 - obj.BreakfastNumberOfPeople = businessShiftGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]); + obj.BreakfastNumberOfPeople = originTenantIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]); - obj.LunchNumberOfPeople = businessShiftGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]); + obj.LunchNumberOfPeople = originTenantIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]); - obj.DinnerNumberOfPeople = businessShiftGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]); + obj.DinnerNumberOfPeople = originTenantIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]); - obj.LateNightNumberOfPeople = businessShiftGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]); + obj.LateNightNumberOfPeople = originTenantIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]); //餐次金额 - obj.BreakfastAmount = businessShiftGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Sum(x => x.Amount); + obj.BreakfastAmount = originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Sum(x => x.Amount); - obj.LunchAmount = businessShiftGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Sum(x => x.Amount); + obj.LunchAmount = originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Sum(x => x.Amount); - obj.DinnerAmount = businessShiftGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Sum(x => x.Amount); + obj.DinnerAmount = originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Sum(x => x.Amount); - obj.LateNightAmount = businessShiftGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Sum(x => x.Amount); + obj.LateNightAmount = originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Sum(x => x.Amount); // 每个餐次单价 obj.BreakfastPrice = obj.BreakfastAmount / obj.BreakfastNumberOfPeople; @@ -293,14 +287,11 @@ public class BalanceService : IBalanceService obj.DinnerPrice = obj.DinnerAmount / obj.DinnerNumberOfPeople; obj.LateNightPrice = obj.LateNightAmount / obj.LateNightNumberOfPeople; - } - // 总人数 总金额 obj.TotalNumberOfPeople = obj.BreakfastNumberOfPeople + obj.LunchNumberOfPeople + obj.DinnerNumberOfPeople + obj.LateNightNumberOfPeople; obj.TotalAmount = obj.BreakfastAmount + obj.LunchAmount + obj.DinnerAmount + obj.LateNightAmount; lst.Add(obj); } - return lst; } @@ -346,18 +337,15 @@ public class BalanceService : IBalanceService { CostDate = DateOnly.FromDateTime(Convert.ToDateTime(first.Key)), }; - foreach (var second in first.GroupBy(x=>x.BusinessShiftCode)) - { - - obj.BreakfastNumberOfPeople=second.Count(x=>second.Key.ToString() == shiftCodeDict["Breakfast"]); + + obj.BreakfastNumberOfPeople= first.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]); + + obj.LunchNumberOfPeople = first.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]); + + obj.DinnerNumberOfPeople = first.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]); + + obj.LateNightNumberOfPeople = first.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]); - obj.LunchNumberOfPeople = second.Count(x => second.Key.ToString() == shiftCodeDict["Lunch"]); - - obj.DinnerNumberOfPeople = second.Count(x => second.Key.ToString() == shiftCodeDict["Dinner"]); - - obj.LateNightNumberOfPeople = second.Count(x => second.Key.ToString() == shiftCodeDict["LateNight"]); - - } obj.TotalNumberOfPeople = obj.BreakfastNumberOfPeople + obj.LunchNumberOfPeople + obj.DinnerNumberOfPeople + obj.LateNightNumberOfPeople; lst.Add(obj); }