From cc273a4693b9dd30e8e6ee886168a9ddec7fd284 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 23 Apr 2024 11:35:35 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=A6=BB=E7=BA=BF=E6=98=BE=E7=A4=BA,?= =?UTF-8?q?=E4=BC=98=E5=8C=96enable=E8=8E=B7=E5=8F=96=E8=AE=BE=E5=A4=87,?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=BE=E5=A4=87=E6=9F=A5=E8=AF=A2=E8=90=A5?= =?UTF-8?q?=E4=B8=9A=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/DevicePermissionService.cs | 27 ++++++++++++------- .../Order/Response/BalanceRecordResponse.cs | 5 ++++ .../Services/Implements/BalanceService.cs | 27 +++++++++++++------ .../Order/Services/Implements/OrderService.cs | 2 -- .../Services/ICanteenSettingService.cs | 2 ++ .../Implements/CanteenSettingService.cs | 19 +++++++++++++ 6 files changed, 63 insertions(+), 19 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index bb026dec..808eb322 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -94,7 +94,7 @@ public class DevicePermissionService : IDevicePermissionService var current = await GetAssignDeviceCodesInternalAsync(userNos); - var deivces = await _dbContext.Queryable().ToListAsync(); + var deivces = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); var waitTasks = new List(); foreach (var userNo in userNos) @@ -187,7 +187,7 @@ public class DevicePermissionService : IDevicePermissionService var current = await GetAssignDeviceCodesInternalAsync(userNos); - var deivces = await _dbContext.Queryable().ToListAsync(); + var deivces = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); var waitTasks = new List(); foreach (var userNo in userNos) @@ -262,7 +262,10 @@ public class DevicePermissionService : IDevicePermissionService return; } - var deivces = await _dbContext.Queryable().Where(x => deviceCodes.Contains(x.Code)).ToListAsync(); + var deivces = await _dbContext.Queryable() + .Where(x => x.Enable) + .Where(x => deviceCodes.Contains(x.Code)) + .ToListAsync(); var tasks = deivces.Select(x => new DeviceTaskEntity { @@ -284,7 +287,9 @@ public class DevicePermissionService : IDevicePermissionService { var all = await GetAssignDeviceCodesAsync(userNo); - return await _dbContext.Queryable().Where(x => x.Type == DeviceTypeEnumType.Meal) + return await _dbContext.Queryable() + .Where(x => x.Enable) + .Where(x => x.Type == DeviceTypeEnumType.Meal) .Where(x => all.Contains(x.Code)) .Select(x => x.UniqueNo) .ToListAsync(); @@ -298,7 +303,7 @@ public class DevicePermissionService : IDevicePermissionService /// public async Task> GetAssignDeviceCodesAsync(string userNo) { - var devices = await _dbContext.Queryable().ToListAsync(); + var devices = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); var deviceRegistries = await _dbContext.Queryable().Where(x => !SqlFunc.IsNullOrEmpty(x.BusinessPlaceCode)).ToListAsync(); var gainfo = await _dbContext.Queryable().Where(x => x.No == userNo).SingleAsync() @@ -335,7 +340,7 @@ public class DevicePermissionService : IDevicePermissionService //所有营业点guid var gps = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.BusinessPlace, AssignTypeEnumType.User, request.No); - var devices = await _dbContext.Queryable().ToListAsync(); + var devices = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); var regiss = await _dbContext.Queryable().ToListAsync(); if (ggs != null && ggs.Count > 0) @@ -466,8 +471,12 @@ public class DevicePermissionService : IDevicePermissionService private async Task>> GetAssignDeviceCodesInternalAsync(List userNos) { - var devices = await _dbContext.Queryable().ToListAsync(); - var regiss = await _dbContext.Queryable().Where(x => !SqlFunc.IsNullOrEmpty(x.BusinessPlaceCode)).ToListAsync(); + var deivces = await _dbContext.Queryable().Where(x => x.Enable).ToListAsync(); + var deviceUniqueNos = deivces.Select(x => x.UniqueNo).ToList(); + var registries = await _dbContext.Queryable() + .Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo)) + .Where(x => !SqlFunc.IsNullOrEmpty(x.BusinessPlaceCode)) + .ToListAsync(); var gainfos = await _dbContext.Queryable().Where(x => userNos.Contains(x.No)).ToListAsync(); if (!gainfos.Any()) @@ -484,7 +493,7 @@ public class DevicePermissionService : IDevicePermissionService foreach (var gainfo in gainfos) { - var codes = GetAssignDeviceCodesInternal(gainfo, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, regiss, devices); + var codes = GetAssignDeviceCodesInternal(gainfo, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, registries, deivces); result.Add(gainfo.No, codes); } diff --git a/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs b/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs index 7b086dac..fef548a8 100644 --- a/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs +++ b/Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs @@ -7,6 +7,11 @@ public class BalanceRecordResponse { public long Id { get; set; } + /// + /// 是否离线 + /// + public bool IsOffline { get; set; } + /// /// 流水号 /// diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index 47268f89..279e5e6f 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -2,6 +2,7 @@ using Dlhis.Canteen.Dishes.Request; using Dlhis.Canteen.Order.Request; using Dlhis.Canteen.Order.Response; +using Dlhis.Canteen.Setting.Services; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; @@ -24,16 +25,19 @@ public class BalanceService : IBalanceService private readonly IDbContext _dbContext; private readonly ICurrentUser _currentUser; private readonly ITenantApi _tenantApi; + private readonly ICanteenSettingService _canteenSettingService; private readonly IBusinessPlacePermissionsApi _businessPlacePermissionsApi; public BalanceService(IDbContext dbContext, ICurrentUser currentUser, ITenantApi tenantApi, + ICanteenSettingService canteenSettingService, IBusinessPlacePermissionsApi businessPlacePermissionsApi) { _dbContext = dbContext; _currentUser = currentUser; _tenantApi = tenantApi; + _canteenSettingService = canteenSettingService; _businessPlacePermissionsApi = businessPlacePermissionsApi; } @@ -43,6 +47,7 @@ public class BalanceService : IBalanceService .LeftJoin((record, ga) => record.UserNo == ga.No) .LeftJoin((record, ga, department) => ga.DepartmentNo == department.No) .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) + .LeftJoin((record, ga, department, bplace, order) => record.No == order.No) .WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, record => record.CostDate >= request.SearchDateTimePeriod.Start) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End) .WhereIF(request.ShiftTypes.IsPresent(), record => request.ShiftTypes.Contains(record.ShiftType)) @@ -53,10 +58,11 @@ public class BalanceService : IBalanceService || ga.Code == request.Search ) .OrderBy(record => record.CreateTime, OrderByType.Desc) - .Select((record, ga, department, bplace) => new BalanceRecordResponse + .Select((record, ga, department, bplace, order) => new BalanceRecordResponse { Id = record.Id, No = record.No, + IsOffline = order.IsOffline, Amount = SqlFunc.Abs(record.Amount), CostDate = record.CostDate, CostId = record.CostId, @@ -101,10 +107,6 @@ public class BalanceService : IBalanceService public async Task> GetPageByDeviceUniqueNoAsync(BalanceRecordPageByDeviceUniqueNoRequest request) { - var now = request.SearchDate ?? DateTime.Now; - var start = request.SearchDate.HasValue ? request.SearchDate.Value.Date : DateTime.Today; - var end = start.AddDays(1).AddSeconds(-1); - var device = await _dbContext.Queryable() .Where(x => x.UniqueNo == request.DeviceUniqueNo || x.Code == Guid.Parse(request.DeviceUniqueNo)) .FirstAsync(); @@ -117,11 +119,21 @@ public class BalanceService : IBalanceService }; } + var date = request.SearchDate.HasValue ? request.SearchDate.Value.Date : DateTime.Today; + + var switchTime = await _canteenSettingService.GetBusinessSwitchTimeAsync(device.TenantId); + if (switchTime.HasValue) + { + var setTime = date.Add(switchTime.Value.ToTimeSpan()); + if (DateTime.Now < setTime) + date = date.AddDays(-1); + } + var page = await _dbContext.Queryable() .LeftJoin((record, ga) => record.UserNo == ga.No) .LeftJoin((record, ga, department) => ga.DepartmentNo == department.No) .LeftJoin((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code) - .Where(record => record.CostDate >= start && record.CostDate <= end) + .Where(record => SqlFunc.DateIsSame(record.CostDate, date, DateType.Day)) .Where(record => record.DeviceUniqueNo == device.UniqueNo || record.DeviceUniqueNo == device.Code.ToString()) .Where(record => record.Type == BalanceRecordTypeEnumType.Out && record.Status == BalanceRecordStatusEnumType.Valid) .OrderBy(record => record.CreateTime, OrderByType.Desc) @@ -148,8 +160,7 @@ public class BalanceService : IBalanceService //消费总金额 var sum = await _dbContext.Queryable() - .Where(record => record.CostDate >= start) - .Where(record => record.CostDate <= end) + .Where(record => SqlFunc.DateIsSame(record.CostDate, date, DateType.Day)) .Where(record => record.DeviceUniqueNo == device.UniqueNo || record.DeviceUniqueNo == device.Code.ToString()) .Where(record => record.Type == BalanceRecordTypeEnumType.Out && record.Status == BalanceRecordStatusEnumType.Valid) .SumAsync(record => SqlFunc.Abs(SqlFunc.IsNull(record.Amount, 0))); diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs index fae9e5a3..751c2f35 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/OrderService.cs @@ -404,8 +404,6 @@ public class OrderService : BaseOrderService, IOrderService }) .ToPageListAsync(page); - //.LeftJoin((x, bplace, detail) => x.No == detail.OrderNo) - var nos = pageResult.Data.Select(x => x.No).ToList(); var dtos = await DbContext.Queryable() .LeftJoin((x, d) => x.DishesCode == d.CustomCode) diff --git a/Src/Dlhis.Canteen/Setting/Services/ICanteenSettingService.cs b/Src/Dlhis.Canteen/Setting/Services/ICanteenSettingService.cs index 218ea68e..355d681c 100644 --- a/Src/Dlhis.Canteen/Setting/Services/ICanteenSettingService.cs +++ b/Src/Dlhis.Canteen/Setting/Services/ICanteenSettingService.cs @@ -21,5 +21,7 @@ public interface ICanteenSettingService : IScopeDependency /// Task> GetUserSettingAsync(string userNo, string tenantId); + + Task GetBusinessSwitchTimeAsync(string tenantId); } diff --git a/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs b/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs index 81eb9088..cc08f7df 100644 --- a/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs +++ b/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs @@ -109,6 +109,25 @@ public class CanteenSettingService : ICanteenSettingService return result; } + + public async Task GetBusinessSwitchTimeAsync(string tenantId) + { + var setting = await _context.Queryable() + .Where(x => x.Enable) + .Where(x => x.TenantId == tenantId) + .Where(x => x.Item == CanteenSettingItemEnumType.BusinessSwitchTime) + .FirstAsync(); + + try + { + return TimeOnly.Parse(setting.Value); + } + catch (Exception) + { + return null; + } + } + //*********************************************** help methods ***************************************************// private async Task CheckDuplicateSettingAsync(CanteenSettingSaveRequest request)