|
|
|
|
@@ -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)));
|
|
|
|
|
|