fix 离线显示,优化enable获取设备,优化设备查询营业日期
This commit is contained in:
@@ -94,7 +94,7 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
|
||||
var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||
|
||||
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||
var deivces = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
var waitTasks = new List<DeviceTaskEntity>();
|
||||
|
||||
foreach (var userNo in userNos)
|
||||
@@ -187,7 +187,7 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
|
||||
var current = await GetAssignDeviceCodesInternalAsync(userNos);
|
||||
|
||||
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||
var deivces = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
var waitTasks = new List<DeviceTaskEntity>();
|
||||
|
||||
foreach (var userNo in userNos)
|
||||
@@ -262,7 +262,10 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
return;
|
||||
}
|
||||
|
||||
var deivces = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceCodes.Contains(x.Code)).ToListAsync();
|
||||
var deivces = await _dbContext.Queryable<DeviceEntity>()
|
||||
.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<DeviceEntity>().Where(x => x.Type == DeviceTypeEnumType.Meal)
|
||||
return await _dbContext.Queryable<DeviceEntity>()
|
||||
.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
|
||||
/// <returns></returns>
|
||||
public async Task<List<Guid>> GetAssignDeviceCodesAsync(string userNo)
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
var deviceRegistries = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => !SqlFunc.IsNullOrEmpty(x.BusinessPlaceCode)).ToListAsync();
|
||||
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().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<DeviceEntity>().ToListAsync();
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
var regiss = await _dbContext.Queryable<DeviceRegistryEntity>().ToListAsync();
|
||||
|
||||
if (ggs != null && ggs.Count > 0)
|
||||
@@ -466,8 +471,12 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
|
||||
private async Task<Dictionary<string, List<UserTenantDeviceCodeDto>>> GetAssignDeviceCodesInternalAsync(List<string> userNos)
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||
var regiss = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => !SqlFunc.IsNullOrEmpty(x.BusinessPlaceCode)).ToListAsync();
|
||||
var deivces = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
var deviceUniqueNos = deivces.Select(x => x.UniqueNo).ToList();
|
||||
var registries = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Where(x => !SqlFunc.IsNullOrEmpty(x.BusinessPlaceCode))
|
||||
.ToListAsync();
|
||||
|
||||
var gainfos = await _dbContext.Queryable<GainfoEntity>().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);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@ public class BalanceRecordResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否离线
|
||||
/// </summary>
|
||||
public bool IsOffline { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 流水号
|
||||
/// </summary>
|
||||
|
||||
@@ -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<GainfoEntity>((record, ga) => record.UserNo == ga.No)
|
||||
.LeftJoin<DepartmentEntity>((record, ga, department) => ga.DepartmentNo == department.No)
|
||||
.LeftJoin<BusinessPlaceEntity>((record, ga, department, bplace) => record.BusinessPlaceCode == bplace.Code)
|
||||
.LeftJoin<CanteenOrderEntity>((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<Pagination<BalanceRecordDeviceResponse>> 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<DeviceEntity>()
|
||||
.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<BalanceRecordEntity>()
|
||||
.LeftJoin<GainfoEntity>((record, ga) => record.UserNo == ga.No)
|
||||
.LeftJoin<DepartmentEntity>((record, ga, department) => ga.DepartmentNo == department.No)
|
||||
.LeftJoin<BusinessPlaceEntity>((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<BalanceRecordEntity>()
|
||||
.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)));
|
||||
|
||||
@@ -404,8 +404,6 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
})
|
||||
.ToPageListAsync(page);
|
||||
|
||||
//.LeftJoin<CanteenOrderDetailEntity>((x, bplace, detail) => x.No == detail.OrderNo)
|
||||
|
||||
var nos = pageResult.Data.Select(x => x.No).ToList();
|
||||
var dtos = await DbContext.Queryable<CanteenOrderDetailEntity>()
|
||||
.LeftJoin<DishesEntity>((x, d) => x.DishesCode == d.CustomCode)
|
||||
|
||||
@@ -21,5 +21,7 @@ public interface ICanteenSettingService : IScopeDependency
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<CanteenSettingItemEnumType, string>> GetUserSettingAsync(string userNo, string tenantId);
|
||||
|
||||
|
||||
Task<TimeOnly?> GetBusinessSwitchTimeAsync(string tenantId);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,6 +109,25 @@ public class CanteenSettingService : ICanteenSettingService
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public async Task<TimeOnly?> GetBusinessSwitchTimeAsync(string tenantId)
|
||||
{
|
||||
var setting = await _context.Queryable<CanteenSettingEntity>()
|
||||
.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)
|
||||
|
||||
Reference in New Issue
Block a user