From 5315632977242293be0f16307bead5e7c6b0d4ba Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Fri, 8 Mar 2024 11:36:36 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=89=B9=E9=87=8F=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/Controllers/DevicesController.cs | 2 +- .../Device/Request/ImportDeviceSaveRequest.cs | 3 - .../Device/Request/ImportListRequest.cs | 7 + .../Device/Services/IDeviceService.cs | 2 +- .../Services/Implements/DeviceService.cs | 70 +--------- Src/Dlhis.Basic/Dlhis.Basic.csproj | 1 - .../Services/Implements/BalanceService.cs | 125 +++++++----------- 7 files changed, 59 insertions(+), 151 deletions(-) create mode 100644 Src/Dlhis.Basic/Device/Request/ImportListRequest.cs diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index 400cff09..9c7d25b0 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -224,7 +224,7 @@ public class DevicesController : ControllerBase /// /// [HttpPost("bulkUploads")] - public async Task BulkUploadsAsync([FromForm] BulkUploadsRequest request) + public async Task BulkUploadsAsync(ImportListRequest request) { await _deviceService.BulkUploadsAsync(request); } diff --git a/Src/Dlhis.Basic/Device/Request/ImportDeviceSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/ImportDeviceSaveRequest.cs index eddbcaed..83a4fca9 100644 --- a/Src/Dlhis.Basic/Device/Request/ImportDeviceSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/ImportDeviceSaveRequest.cs @@ -5,9 +5,6 @@ namespace Dlhis.Basic.Device.Request { public class ImportDeviceSaveRequest { - - public long? Id { get; set; } - /// /// 设备唯一号 /// diff --git a/Src/Dlhis.Basic/Device/Request/ImportListRequest.cs b/Src/Dlhis.Basic/Device/Request/ImportListRequest.cs new file mode 100644 index 00000000..e942004c --- /dev/null +++ b/Src/Dlhis.Basic/Device/Request/ImportListRequest.cs @@ -0,0 +1,7 @@ +namespace Dlhis.Basic.Device.Request +{ + public class ImportListRequest + { + public List Imports { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs index a5549121..2f8bcd2a 100644 --- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs @@ -27,7 +27,7 @@ public interface IDeviceService : IScopeDependency Task> GetRecentNumbersAsync(); - Task BulkUploadsAsync(BulkUploadsRequest request); + Task BulkUploadsAsync(ImportListRequest request); } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs index 05184d1b..da116ef3 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs @@ -11,13 +11,8 @@ using Kurisu.Core.DataAccess.Dto; using Kurisu.SqlSugar.Extensions; using Kurisu.SqlSugar.Services; using Mapster; -using Microsoft.AspNetCore.Mvc; -using MySqlX.XDevAPI.Relational; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using NPOI.OpenXmlFormats; -using NPOI.SS.UserModel; -using NPOI.XSSF.UserModel; using SqlSugar; namespace Dlhis.Basic.Device.Services.Implements; @@ -132,9 +127,9 @@ public class DeviceService : IDeviceService /// /// /// - public async Task BulkUploadsAsync(BulkUploadsRequest request) + public async Task BulkUploadsAsync(ImportListRequest request) { - var lst = ImportFromExcel(request.FormFile); + var lst = request.Imports; var places = await _dbContext.Queryable().ToListAsync(); foreach (var form in lst) @@ -500,67 +495,6 @@ public class DeviceService : IDeviceService return list; } - private List ImportFromExcel(IFormFile formFile) - { - var requests = new List(); - - using (var stream = formFile.OpenReadStream()) - { - XSSFWorkbook workbook = new XSSFWorkbook(stream); - ISheet sheet = workbook.GetSheetAt(0); - - for (int rowIdx = 1; rowIdx <= sheet.LastRowNum; rowIdx++) - { - IRow row = sheet.GetRow(rowIdx); - if (row == null) continue; - - var request = new ImportDeviceSaveRequest(); - - request.UniqueNo = row.GetCell(0).ToString(); - request.TemplateCode = Guid.Parse(row.GetCell(1).ToString()); - request.Supplier = row.GetCell(2).ToString(); - - var funs = new List(); - var fs = row.GetCell(3).ToString().Split(','); - foreach (string str in fs) - { - switch (str) - { - case "1": - funs.Add(DeviceFuncEnumType.Face); - break; - case "2": - funs.Add(DeviceFuncEnumType.Card); - break; - case "3": - funs.Add(DeviceFuncEnumType.QrCode); - break; - case "4": - funs.Add(DeviceFuncEnumType.Control); - break; - default: - break; - } - } - request.Funcs = funs; - request.Type = (DeviceTypeEnumType)Enum.Parse(typeof(DeviceTypeEnumType), row.GetCell(4).ToString()); - request.HeartbeatInterval = int.Parse(row.GetCell(5).ToString()); - request.DeployPlace = row.GetCell(6).ToString(); - request.DeployPosition = row.GetCell(7).ToString(); - request.DeployDirection = row.GetCell(8).ToString(); - request.ConnectionInfo = row.GetCell(9).ToString(); - request.Enable = Convert.ToBoolean(Convert.ToInt32(row.GetCell(10).ToString())); - request.AsAttendance = Convert.ToBoolean(Convert.ToInt32(row.GetCell(11).ToString())); - if (row.GetCell(12) != null) - { - request.PlaceeCode = Guid.Parse(row.GetCell(12)?.ToString()); - } - requests.Add(request); - } - } - - return requests; - } } diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index d0e8b356..ffe86e4d 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -18,7 +18,6 @@ - diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 9cddd2da..9acab61d 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -127,24 +127,24 @@ public class BalanceService : IBalanceService }; // 所有人次 - var BreakfastNumberOfPeople = costIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]); + var BreakfastNumberOfPeople = costIdGroup.Count(x => x.ShiftType == shiftCodeDict["Breakfast"]); - var LunchNumberOfPeople = costIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]); + var LunchNumberOfPeople = costIdGroup.Count(x => x.ShiftType == shiftCodeDict["Lunch"]); - var DinnerNumberOfPeople = costIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]); + var DinnerNumberOfPeople = costIdGroup.Count(x => x.ShiftType == shiftCodeDict["Dinner"]); - var LateNightNumberOfPeople = costIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]); + var LateNightNumberOfPeople = costIdGroup.Count(x => x.ShiftType == shiftCodeDict["LateNight"]); // 每个餐次人数 - obj.BreakfastNumberOfPeople = costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Select(x => x.UserNo).Distinct().Count(); - obj.LunchNumberOfPeople = costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Select(x => x.UserNo).Distinct().Count(); - obj.DinnerNumberOfPeople = costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Select(x => x.UserNo).Distinct().Count(); - obj.LateNightNumberOfPeople = costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Select(x => x.UserNo).Distinct().Count(); + obj.BreakfastNumberOfPeople = costIdGroup.Where(x => x.ShiftType == shiftCodeDict["Breakfast"]).Select(x => x.UserNo).Distinct().Count(); + obj.LunchNumberOfPeople = costIdGroup.Where(x => x.ShiftType == shiftCodeDict["Lunch"]).Select(x => x.UserNo).Distinct().Count(); + obj.DinnerNumberOfPeople = costIdGroup.Where(x => x.ShiftType == shiftCodeDict["Dinner"]).Select(x => x.UserNo).Distinct().Count(); + obj.LateNightNumberOfPeople = costIdGroup.Where(x => x.ShiftType == shiftCodeDict["LateNight"]).Select(x => x.UserNo).Distinct().Count(); //餐次金额 - obj.BreakfastAmount = Math.Abs(costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Sum(x => x.Amount)); - obj.LunchAmount = Math.Abs(costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Sum(x => x.Amount)); - obj.DinnerAmount = Math.Abs(costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Sum(x => x.Amount)); - obj.LateNightAmount = Math.Abs(costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Sum(x => x.Amount)); + obj.BreakfastAmount = Math.Abs(costIdGroup.Where(x => x.ShiftType == shiftCodeDict["Breakfast"]).Sum(x => x.Amount)); + obj.LunchAmount = Math.Abs(costIdGroup.Where(x => x.ShiftType == shiftCodeDict["Lunch"]).Sum(x => x.Amount)); + obj.DinnerAmount = Math.Abs(costIdGroup.Where(x => x.ShiftType == shiftCodeDict["Dinner"]).Sum(x => x.Amount)); + obj.LateNightAmount = Math.Abs(costIdGroup.Where(x => x.ShiftType == shiftCodeDict["LateNight"]).Sum(x => x.Amount)); // 每个餐次单价 @@ -258,24 +258,24 @@ public class BalanceService : IBalanceService OriginTenantId = "" }; // 所有人次 - var BreakfastNumberOfPeople = departmentGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]); + var BreakfastNumberOfPeople = departmentGroup.Count(x => x.ShiftType == shiftCodeDict["Breakfast"]); - var LunchNumberOfPeople = departmentGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]); + var LunchNumberOfPeople = departmentGroup.Count(x => x.ShiftType == shiftCodeDict["Lunch"]); - var DinnerNumberOfPeople = departmentGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]); + var DinnerNumberOfPeople = departmentGroup.Count(x => x.ShiftType == shiftCodeDict["Dinner"]); - var LateNightNumberOfPeople = departmentGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]); + var LateNightNumberOfPeople = departmentGroup.Count(x => x.ShiftType == shiftCodeDict["LateNight"]); //每个餐次人数 - obj.BreakfastNumberOfPeople = departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Select(x => x.UserNo).Distinct().Count(); - obj.LunchNumberOfPeople = departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Select(x => x.UserNo).Distinct().Count(); - obj.DinnerNumberOfPeople = departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Select(x => x.UserNo).Distinct().Count(); - obj.LateNightNumberOfPeople = departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Select(x => x.UserNo).Distinct().Count(); + obj.BreakfastNumberOfPeople = departmentGroup.Where(x => x.ShiftType == shiftCodeDict["Breakfast"]).Select(x => x.UserNo).Distinct().Count(); + obj.LunchNumberOfPeople = departmentGroup.Where(x => x.ShiftType == shiftCodeDict["Lunch"]).Select(x => x.UserNo).Distinct().Count(); + obj.DinnerNumberOfPeople = departmentGroup.Where(x => x.ShiftType == shiftCodeDict["Dinner"]).Select(x => x.UserNo).Distinct().Count(); + obj.LateNightNumberOfPeople = departmentGroup.Where(x => x.ShiftType == shiftCodeDict["LateNight"]).Select(x => x.UserNo).Distinct().Count(); //餐次金额 - obj.BreakfastAmount = Math.Abs(departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Sum(x => x.Amount)); - obj.LunchAmount = Math.Abs(departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Sum(x => x.Amount)); - obj.DinnerAmount = Math.Abs(departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Sum(x => x.Amount)); - obj.LateNightAmount = Math.Abs(departmentGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Sum(x => x.Amount)); + obj.BreakfastAmount = Math.Abs(departmentGroup.Where(x => x.ShiftType == shiftCodeDict["Breakfast"]).Sum(x => x.Amount)); + obj.LunchAmount = Math.Abs(departmentGroup.Where(x => x.ShiftType == shiftCodeDict["Lunch"]).Sum(x => x.Amount)); + obj.DinnerAmount = Math.Abs(departmentGroup.Where(x => x.ShiftType == shiftCodeDict["Dinner"]).Sum(x => x.Amount)); + obj.LateNightAmount = Math.Abs(departmentGroup.Where(x => x.ShiftType == shiftCodeDict["LateNight"]).Sum(x => x.Amount)); // 每个餐次单价 obj.BreakfastPrice = BreakfastNumberOfPeople == 0 ? 0 : Math.Round(obj.BreakfastAmount / BreakfastNumberOfPeople, 2); @@ -337,24 +337,24 @@ public class BalanceService : IBalanceService }; // 所有人次 - var BreakfastNumberOfPeople = originTenantIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]); + var BreakfastNumberOfPeople = originTenantIdGroup.Count(x => x.ShiftType == shiftCodeDict["Breakfast"]); - var LunchNumberOfPeople = originTenantIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]); + var LunchNumberOfPeople = originTenantIdGroup.Count(x => x.ShiftType == shiftCodeDict["Lunch"]); - var DinnerNumberOfPeople = originTenantIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]); + var DinnerNumberOfPeople = originTenantIdGroup.Count(x => x.ShiftType == shiftCodeDict["Dinner"]); - var LateNightNumberOfPeople = originTenantIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]); + var LateNightNumberOfPeople = originTenantIdGroup.Count(x => x.ShiftType == shiftCodeDict["LateNight"]); //每个餐次人数 - obj.BreakfastNumberOfPeople = originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Select(x => x.UserNo).Distinct().Count(); - obj.LunchNumberOfPeople = originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Select(x => x.UserNo).Distinct().Count(); - obj.DinnerNumberOfPeople = originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Select(x => x.UserNo).Distinct().Count(); - obj.LateNightNumberOfPeople = originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Select(x => x.UserNo).Distinct().Count(); + obj.BreakfastNumberOfPeople = originTenantIdGroup.Where(x => x.ShiftType == shiftCodeDict["Breakfast"]).Select(x => x.UserNo).Distinct().Count(); + obj.LunchNumberOfPeople = originTenantIdGroup.Where(x => x.ShiftType == shiftCodeDict["Lunch"]).Select(x => x.UserNo).Distinct().Count(); + obj.DinnerNumberOfPeople = originTenantIdGroup.Where(x => x.ShiftType == shiftCodeDict["Dinner"]).Select(x => x.UserNo).Distinct().Count(); + obj.LateNightNumberOfPeople = originTenantIdGroup.Where(x => x.ShiftType == shiftCodeDict["LateNight"]).Select(x => x.UserNo).Distinct().Count(); //餐次金额 - obj.BreakfastAmount = Math.Abs(originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Sum(x => x.Amount)); - obj.LunchAmount = Math.Abs(originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Sum(x => x.Amount)); - obj.DinnerAmount = Math.Abs(originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Sum(x => x.Amount)); - obj.LateNightAmount = Math.Abs(originTenantIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Sum(x => x.Amount)); + obj.BreakfastAmount = Math.Abs(originTenantIdGroup.Where(x => x.ShiftType == shiftCodeDict["Breakfast"]).Sum(x => x.Amount)); + obj.LunchAmount = Math.Abs(originTenantIdGroup.Where(x => x.ShiftType == shiftCodeDict["Lunch"]).Sum(x => x.Amount)); + obj.DinnerAmount = Math.Abs(originTenantIdGroup.Where(x => x.ShiftType == shiftCodeDict["Dinner"]).Sum(x => x.Amount)); + obj.LateNightAmount = Math.Abs(originTenantIdGroup.Where(x => x.ShiftType == shiftCodeDict["LateNight"]).Sum(x => x.Amount)); // 每个餐次单价 @@ -409,10 +409,10 @@ public class BalanceService : IBalanceService }; //每个餐次人数 - obj.BreakfastNumberOfPeople = first.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Select(x => x.UserNo).Distinct().Count(); - obj.LunchNumberOfPeople = first.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Select(x => x.UserNo).Distinct().Count(); - obj.DinnerNumberOfPeople = first.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Select(x => x.UserNo).Distinct().Count(); - obj.LateNightNumberOfPeople = first.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Select(x => x.UserNo).Distinct().Count(); + obj.BreakfastNumberOfPeople = first.Where(x => x.ShiftType == shiftCodeDict["Breakfast"]).Select(x => x.UserNo).Distinct().Count(); + obj.LunchNumberOfPeople = first.Where(x => x.ShiftType == shiftCodeDict["Lunch"]).Select(x => x.UserNo).Distinct().Count(); + obj.DinnerNumberOfPeople = first.Where(x => x.ShiftType == shiftCodeDict["Dinner"]).Select(x => x.UserNo).Distinct().Count(); + obj.LateNightNumberOfPeople = first.Where(x => x.ShiftType == shiftCodeDict["LateNight"]).Select(x => x.UserNo).Distinct().Count(); obj.TotalNumberOfPeople = obj.BreakfastNumberOfPeople + obj.LunchNumberOfPeople + obj.DinnerNumberOfPeople + obj.LateNightNumberOfPeople; lst.Add(obj); } @@ -963,44 +963,15 @@ public class BalanceService : IBalanceService { var shiftCodeDict = new Dictionary(); - var shifts = await _dbContext.Queryable().ToListAsync(); - //guid - //早餐 - var breakfast = shifts.Where(x => x.CustomCode == "shift-breakfast").FirstOrDefault(); - var codeBreakfast = "Breakfast"; - if (breakfast != null) - { - codeBreakfast = breakfast.Code.ToString(); - } - //午餐 - var lunch = shifts.Where(x => x.CustomCode == "shift-lunch").FirstOrDefault(); - var codeLunch = "Lunch"; - if (lunch != null) - { - codeLunch = lunch.Code.ToString(); - } - //晚餐 - var dinner = shifts.Where(x => x.CustomCode == "shift-dinner").FirstOrDefault(); - var codeDinner = "Dinner"; - if (dinner != null) - { - codeDinner = dinner.Code.ToString(); - } - //宵夜 - var nightsnack = shifts.Where(x => x.CustomCode == "shift-nightsnack").FirstOrDefault(); - var codeNightsnack = "Nightsnack"; - if (nightsnack != null) - { - codeNightsnack = nightsnack.Code.ToString(); - } - //凌晨 - var midnightsnack = shifts.Where(x => x.CustomCode == "shift-midnightsnack").FirstOrDefault(); - var codeMidnightsnack = "Midnightsnack"; - if (midnightsnack != null) - { - codeMidnightsnack = midnightsnack.Code.ToString(); - } + var typs = await _dbContext.Queryable() + .Where(x => x.Type == "mealshift") + .ToListAsync(); + var codeBreakfast = typs.Where(x => x.Display == "早餐").Select(x => x.Code).First(); + var codeLunch = typs.Where(x => x.Display == "午餐").Select(x => x.Code).First(); + var codeDinner = typs.Where(x => x.Display == "晚餐").Select(x => x.Code).First(); + var codeNightsnack = typs.Where(x => x.Display == "宵夜").Select(x => x.Code).First(); + var codeMidnightsnack = typs.Where(x => x.Display == "凌晨餐").Select(x => x.Code).First(); shiftCodeDict.Add("Breakfast", codeBreakfast); shiftCodeDict.Add("Lunch", codeLunch);