fix 餐饮订单参数控制,设备组参数返回
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
namespace Dlhis.Basic.Device.Response;
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Response;
|
||||||
|
|
||||||
public class DeviceGroupPageResponse
|
public class DeviceGroupPageResponse
|
||||||
{
|
{
|
||||||
|
public Guid Code { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备组名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,5 @@ public class Startup : DefaultStartup
|
|||||||
public Startup(IConfiguration configuration) : base(configuration)
|
public Startup(IConfiguration configuration) : base(configuration)
|
||||||
{
|
{
|
||||||
IdentityModelEventSource.ShowPII = true;
|
IdentityModelEventSource.ShowPII = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
using Kurisu.Core.DataAccess.Dto;
|
|
||||||
|
|
||||||
namespace Dlhis.Canteen.BalanceRecord.Request;
|
|
||||||
|
|
||||||
public class BalanceRecordRequest : PageDto
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace Dlhis.Canteen.BalanceRecord.Response;
|
|
||||||
|
|
||||||
public class BalanceRecordResponse
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
using Dlhis.Canteen.BalanceRecord.Request;
|
|
||||||
using Dlhis.Canteen.BalanceRecord.Response;
|
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
|
||||||
|
|
||||||
namespace Dlhis.Canteen.BalanceRecord.Services;
|
|
||||||
|
|
||||||
public interface IBalanceRecordService : IScopeDependency
|
|
||||||
{
|
|
||||||
Task<Pagination<BalanceRecordResponse>> GetPageAsync(BalanceRecordRequest request);
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using Dlhis.Canteen.BalanceRecord.Request;
|
|
||||||
using Dlhis.Canteen.BalanceRecord.Response;
|
|
||||||
using Dlhis.Entity.Canteen.Entities;
|
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
|
||||||
using Kurisu.SqlSugar.Extensions;
|
|
||||||
using Kurisu.SqlSugar.Services;
|
|
||||||
|
|
||||||
namespace Dlhis.Canteen.BalanceRecord.Services.Implements;
|
|
||||||
|
|
||||||
public class BalanceRecordService : IBalanceRecordService
|
|
||||||
{
|
|
||||||
private readonly IDbContext _dbContext;
|
|
||||||
|
|
||||||
public BalanceRecordService(IDbContext dbContext)
|
|
||||||
{
|
|
||||||
_dbContext = dbContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Pagination<BalanceRecordResponse>> GetPageAsync(BalanceRecordRequest request)
|
|
||||||
{
|
|
||||||
return await _dbContext.Queryable<BalanceRecordEntity>()
|
|
||||||
.Select<BalanceRecordResponse>()
|
|
||||||
.ToPageListAsync(request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="BalanceRecord\Controllers\" />
|
|
||||||
<Folder Include="OaEMealVoucher\Controllers\" />
|
<Folder Include="OaEMealVoucher\Controllers\" />
|
||||||
<Folder Include="OaEMealVoucher\Request\" />
|
<Folder Include="OaEMealVoucher\Request\" />
|
||||||
<Folder Include="OaEMealVoucher\Response\" />
|
<Folder Include="OaEMealVoucher\Response\" />
|
||||||
|
|||||||
32
Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs
Normal file
32
Src/Dlhis.Canteen/Order/Controllers/BalancesController.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Dlhis.Canteen.Order.Request;
|
||||||
|
using Dlhis.Canteen.Order.Response;
|
||||||
|
using Dlhis.Canteen.Order.Services;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Dlhis.Canteen.Order.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class BalancesController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IBalanceService _balanceService;
|
||||||
|
|
||||||
|
public BalancesController(IBalanceService balanceService)
|
||||||
|
{
|
||||||
|
_balanceService = balanceService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取消费记录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<Pagination<BalanceRecordResponse>> GetPageAsync([FromQuery] BalanceRecordPageRequest request)
|
||||||
|
{
|
||||||
|
return await _balanceService.GetPageAsync(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
63
Src/Dlhis.Canteen/Order/Request/BalanceRecordPageRequest.cs
Normal file
63
Src/Dlhis.Canteen/Order/Request/BalanceRecordPageRequest.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
using Dlhis.Entity.Canteen.Enums;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
using Kurisu.Core.CustomClass;
|
||||||
|
|
||||||
|
namespace Dlhis.Canteen.Order.Request;
|
||||||
|
|
||||||
|
public class BalanceRecordPageRequest : PageDto, IValidatableObject
|
||||||
|
{
|
||||||
|
[EnumDataType(typeof(DateTimeSearchEnumType))]
|
||||||
|
public DateTimeSearchEnumType? SearchDateTimeDimension { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 日期范围查询
|
||||||
|
/// </summary>
|
||||||
|
public DateTimePeriod SearchDateTimePeriod { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
var now = DateTime.Now;
|
||||||
|
if (SearchDateTimeDimension.HasValue)
|
||||||
|
{
|
||||||
|
//重新赋值
|
||||||
|
SearchDateTimePeriod = new DateTimePeriod();
|
||||||
|
|
||||||
|
if (SearchDateTimeDimension == DateTimeSearchEnumType.Day)
|
||||||
|
{
|
||||||
|
SearchDateTimePeriod.Start = new DateTime(now.Year, now.Month, now.Day, 0, 0, 1);
|
||||||
|
SearchDateTimePeriod.End = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);
|
||||||
|
}
|
||||||
|
else if (SearchDateTimeDimension == DateTimeSearchEnumType.Week)
|
||||||
|
{
|
||||||
|
SearchDateTimePeriod.Start = now.AddDays(1 - (int)now.DayOfWeek);
|
||||||
|
SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddDays(6);
|
||||||
|
}
|
||||||
|
else if (SearchDateTimeDimension == DateTimeSearchEnumType.Month)
|
||||||
|
{
|
||||||
|
SearchDateTimePeriod.Start = new DateTime(now.Year, now.Month, 1);
|
||||||
|
SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddMonths(1).AddDays(-1);
|
||||||
|
}
|
||||||
|
else if (SearchDateTimeDimension == DateTimeSearchEnumType.Season)
|
||||||
|
{
|
||||||
|
SearchDateTimePeriod.Start = now.AddMonths(0 - ((now.Month - 1) % 3));
|
||||||
|
SearchDateTimePeriod.End = now.AddMonths(3 - ((now.Month - 1) % 3)).AddMonths(1).AddDays(-1);
|
||||||
|
}
|
||||||
|
else if (SearchDateTimeDimension == DateTimeSearchEnumType.HalfOfYear)
|
||||||
|
{
|
||||||
|
SearchDateTimePeriod.Start = now.AddDays(-180);
|
||||||
|
SearchDateTimePeriod.End = now;
|
||||||
|
}
|
||||||
|
else if (SearchDateTimeDimension == DateTimeSearchEnumType.Year)
|
||||||
|
{
|
||||||
|
SearchDateTimePeriod.Start = new DateTime(now.Year, 1, 1);
|
||||||
|
SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddYears(1).AddDays(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchDateTimePeriod.Start = SearchDateTimePeriod.Start.Value.Date;
|
||||||
|
SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,20 +5,25 @@ namespace Dlhis.Canteen.Order.Request;
|
|||||||
|
|
||||||
public class OrderAddRequest
|
public class OrderAddRequest
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 是否离线数据
|
||||||
|
/// </summary>
|
||||||
|
public bool IsOffline { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 消费机器唯一信息
|
/// 消费机器唯一信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UniqueNo { get; set; }
|
public string DeviceUniqueNo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 档案号/QrCode
|
/// 第三方订单号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserId { get; set; }
|
public string ThirdNo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 学工号
|
/// 档案号/QrCode/学工号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserCode { get; set; }
|
public string UserUniqueNo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 来源
|
/// 来源
|
||||||
@@ -30,15 +35,16 @@ public class OrderAddRequest
|
|||||||
/// 收入/支出
|
/// 收入/支出
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[EnumDataType(typeof(BalanceRecordTypeEnumType))]
|
[EnumDataType(typeof(BalanceRecordTypeEnumType))]
|
||||||
public BalanceRecordTypeEnumType Type { get; set; }
|
public BalanceRecordTypeEnumType? Type { get; set; } = BalanceRecordTypeEnumType.Out;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 金额 + - 表示
|
/// 金额
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Range(0.01, double.MaxValue)]
|
||||||
public decimal Amount { get; set; }
|
public decimal Amount { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 餐补月份
|
/// 消费时间,由机器提供
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SubsidiesFromMonth { get; set; }
|
public DateTime CostDateTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
109
Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs
Normal file
109
Src/Dlhis.Canteen/Order/Response/BalanceRecordResponse.cs
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
using Dlhis.Entity.Canteen.Enums;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
|
||||||
|
namespace Dlhis.Canteen.Order.Response;
|
||||||
|
|
||||||
|
public class BalanceRecordResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 流水号
|
||||||
|
/// </summary>
|
||||||
|
public string No { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 档案号/QRCode
|
||||||
|
/// </summary>
|
||||||
|
public string UserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 姓名
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 学工号
|
||||||
|
/// </summary>
|
||||||
|
public string UserCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 部门号
|
||||||
|
/// </summary>
|
||||||
|
public string DepartmentNo { get; set; }
|
||||||
|
|
||||||
|
public string DepartmentName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 来源
|
||||||
|
/// </summary>
|
||||||
|
public BalanceRecordSourceEnumType Source { get; set; }
|
||||||
|
public string SourceDesc => Source.GetDescription();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 收入/支出
|
||||||
|
/// </summary>
|
||||||
|
public BalanceRecordTypeEnumType Type { get; set; }
|
||||||
|
public string TypeDesc => Type.GetDescription();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 金额
|
||||||
|
/// </summary>
|
||||||
|
public decimal Amount { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 营业点
|
||||||
|
/// </summary>
|
||||||
|
public Guid BusinessPlaceCode { get; set; }
|
||||||
|
public string BusinessPlaceName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 餐次
|
||||||
|
/// </summary>
|
||||||
|
public Guid? BusinessShiftCode { get; set; }
|
||||||
|
public string BusinessShiftName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 所属成本日期
|
||||||
|
/// </summary>
|
||||||
|
public DateTime CostDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 消费机器唯一信息
|
||||||
|
/// </summary>
|
||||||
|
public string DeviceInfo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 餐补月份
|
||||||
|
/// </summary>
|
||||||
|
public string SubsidiesFromMonth { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ip
|
||||||
|
/// </summary>
|
||||||
|
public string IP { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 成本中心
|
||||||
|
/// </summary>
|
||||||
|
public string CostId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 消费者所在基地
|
||||||
|
/// </summary>
|
||||||
|
public string OriginTenantId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 成本计算是否允许跨基地范围
|
||||||
|
/// </summary>
|
||||||
|
public bool IsCostCrossTenant { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据状态
|
||||||
|
/// </summary>
|
||||||
|
public BalanceRecordStatusEnumType Status { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据状态描述
|
||||||
|
/// </summary>
|
||||||
|
public string StatusDesc => Status.GetDescription();
|
||||||
|
}
|
||||||
10
Src/Dlhis.Canteen/Order/Services/IBalanceService.cs
Normal file
10
Src/Dlhis.Canteen/Order/Services/IBalanceService.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using Dlhis.Canteen.Order.Request;
|
||||||
|
using Dlhis.Canteen.Order.Response;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
|
||||||
|
namespace Dlhis.Canteen.Order.Services;
|
||||||
|
|
||||||
|
public interface IBalanceService : IScopeDependency
|
||||||
|
{
|
||||||
|
Task<Pagination<BalanceRecordResponse>> GetPageAsync(BalanceRecordPageRequest request);
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ using Kurisu.Core.DataAccess.Dto;
|
|||||||
|
|
||||||
namespace Dlhis.Canteen.Order.Services;
|
namespace Dlhis.Canteen.Order.Services;
|
||||||
|
|
||||||
public interface IOrderService
|
public interface IOrderService : IScopeDependency
|
||||||
{
|
{
|
||||||
Task<Pagination<OrderResponse>> GetPageAsync(OrderPageRequest request);
|
Task<Pagination<OrderResponse>> GetPageAsync(OrderPageRequest request);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using Dlhis.Canteen.Order.Request;
|
||||||
|
using Dlhis.Canteen.Order.Response;
|
||||||
|
using Dlhis.Entity.Canteen.Entities;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
using Kurisu.SqlSugar.Extensions;
|
||||||
|
using Kurisu.SqlSugar.Services;
|
||||||
|
|
||||||
|
namespace Dlhis.Canteen.Order.Services.Implements;
|
||||||
|
|
||||||
|
public class BalanceService : IBalanceService
|
||||||
|
{
|
||||||
|
private readonly IDbContext _dbContext;
|
||||||
|
|
||||||
|
public BalanceService(IDbContext dbContext)
|
||||||
|
{
|
||||||
|
_dbContext = dbContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Pagination<BalanceRecordResponse>> GetPageAsync(BalanceRecordPageRequest request)
|
||||||
|
{
|
||||||
|
var page = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||||
|
.WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, record => record.CreateTime >= request.SearchDateTimePeriod.Start)
|
||||||
|
.WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CreateTime <= request.SearchDateTimePeriod.End)
|
||||||
|
.OrderBy(record => record.CreateTime)
|
||||||
|
.Select<BalanceRecordResponse>()
|
||||||
|
.ToPageListAsync(request);
|
||||||
|
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,33 @@
|
|||||||
using Dlhis.Canteen.Order.Request;
|
using Dlhis.Canteen.Order.Request;
|
||||||
using Dlhis.Canteen.Order.Response;
|
using Dlhis.Canteen.Order.Response;
|
||||||
|
using Dlhis.Canteen.Setting.Services;
|
||||||
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Canteen.Entities;
|
using Dlhis.Entity.Canteen.Entities;
|
||||||
|
using Dlhis.Entity.Canteen.Enums;
|
||||||
|
using Dlhis.Entity.Device.Entities;
|
||||||
|
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||||
|
using Kurisu.AspNetCore.Utils;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Kurisu.Core.CustomClass;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
|
using Mapster;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace Dlhis.Canteen.Order.Services.Implements;
|
namespace Dlhis.Canteen.Order.Services.Implements;
|
||||||
|
|
||||||
public class OrderService : IOrderService
|
public class OrderService : IOrderService
|
||||||
{
|
{
|
||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
|
private readonly ICanteenSettingService _canteenSettingService;
|
||||||
|
private readonly ILogger<OrderService> _logger;
|
||||||
|
|
||||||
public OrderService(IDbContext dbContext)
|
public OrderService(IDbContext dbContext, ICanteenSettingService canteenSettingService, ILogger<OrderService> logger)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
|
_canteenSettingService = canteenSettingService;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Pagination<OrderResponse>> GetPageAsync(OrderPageRequest request)
|
public async Task<Pagination<OrderResponse>> GetPageAsync(OrderPageRequest request)
|
||||||
@@ -27,6 +41,208 @@ public class OrderService : IOrderService
|
|||||||
|
|
||||||
public async Task AddAsync(OrderAddRequest request)
|
public async Task AddAsync(OrderAddRequest request)
|
||||||
{
|
{
|
||||||
|
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo == request.DeviceUniqueNo).Where(x => x.Enable).FirstAsync();
|
||||||
|
device.ThrowIfNull("设备不存在或者尚未启用");
|
||||||
|
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.DeviceUniqueNo).FirstAsync();
|
||||||
|
registry.ThrowIfNull("设备尚未注册");
|
||||||
|
|
||||||
|
var businessPlace = await _dbContext.Queryable<CanteenBusinessPlaceEntity>().Where(x => x.Code == registry.BusinessPlaceCode).FirstAsync();
|
||||||
|
businessPlace.ThrowIfNull("营业点尚未设置");
|
||||||
|
var shifts = await _dbContext.Queryable<CanteenBusinessShiftEntity>().Where(x => x.BusinessPlaceCode == registry.BusinessPlaceCode).ToListAsync();
|
||||||
|
|
||||||
|
var shift = shifts.FirstOrDefault(x => new TimePeriod()
|
||||||
|
{
|
||||||
|
Start = x.Start,
|
||||||
|
End = x.End,
|
||||||
|
|
||||||
|
}.IsPresent(request.CostDateTime));
|
||||||
|
|
||||||
|
//根据档案号
|
||||||
|
var canteenUser = await _dbContext.Queryable<CanteenUserEntity>()
|
||||||
|
.Where(x => x.UserId == request.UserUniqueNo || x.UserCode == request.UserUniqueNo)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
var gafinfo = await _dbContext.Queryable<GainfoEntity>()
|
||||||
|
.Where(x => x.Guestno == canteenUser.UserId)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
var settings = await _canteenSettingService.GetUserSettingAsync(gafinfo.Guestno);
|
||||||
|
var switchTime = GetSetting<TimeOnly>(settings, CanteenSettingItemEnumType.BusinessSwitchTime);
|
||||||
|
//金额处理
|
||||||
|
request.Amount = request.Type == BalanceRecordTypeEnumType.In ? Math.Abs(request.Amount) : -Math.Abs(request.Amount);
|
||||||
|
|
||||||
|
var shiftTimePeriod = new TimePeriod()
|
||||||
|
{
|
||||||
|
Start = shift.Start,
|
||||||
|
End = shift.End
|
||||||
|
};
|
||||||
|
|
||||||
|
//成本日期 todo 优化
|
||||||
|
var costDate = DateTime.Now;
|
||||||
|
if (shift == null)
|
||||||
|
{
|
||||||
|
costDate = DateTime.Now;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (shiftTimePeriod.IsCrossDay())
|
||||||
|
costDate = DateTime.Now.AddDays(-1);
|
||||||
|
|
||||||
|
var beginOfDay = DateTime.Today;
|
||||||
|
var setTime = beginOfDay.Add(switchTime.ToTimeSpan());
|
||||||
|
if (DateTime.Now < setTime)
|
||||||
|
costDate = DateTime.Now.AddDays(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var order = new CanteenOrderEntity
|
||||||
|
{
|
||||||
|
RequestJson = request.ToJson(),
|
||||||
|
ThirdNo = request.ThirdNo,
|
||||||
|
Type = request.Type.Value,
|
||||||
|
OrderStatus = CanteenOrderStatusEnumType.Wait,
|
||||||
|
Name = gafinfo.Gname,
|
||||||
|
Source = request.Source,
|
||||||
|
UserId = canteenUser.UserId,
|
||||||
|
UserCode = canteenUser.UserCode,
|
||||||
|
Amount = request.Amount,
|
||||||
|
BusinessPlaceCode = businessPlace.Code,
|
||||||
|
BusinessShiftCode = shift?.Code,
|
||||||
|
CostDate = costDate.Date,
|
||||||
|
CostId = canteenUser.CostId,
|
||||||
|
DepartmentNo = gafinfo.Appellation,
|
||||||
|
DeviceInfo = device.Code.ToString(),
|
||||||
|
|
||||||
|
No = "O" + SnowFlakeHelper.Instance.NextId(),
|
||||||
|
SubsidiesFromMonth = DateTime.Now.ToString("yyyyMM"),
|
||||||
|
IsOffline = request.IsOffline,
|
||||||
|
IsCostCrossTenant = GetSetting<bool>(settings, CanteenSettingItemEnumType.AllowCrossTenant),
|
||||||
|
|
||||||
|
OriginTenantId = canteenUser.TenantId,
|
||||||
|
|
||||||
|
Status = BalanceRecordStatusEnumType.Doubtful,
|
||||||
|
};
|
||||||
|
|
||||||
|
var id = await _dbContext.InsertReturnIdentityAsync(order);
|
||||||
|
await GenerateChargeRecordAsync(id, settings, shifts, request.CostDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static T GetSetting<T>(Dictionary<CanteenSettingItemEnumType, string> settings, CanteenSettingItemEnumType item, T defaultValue = default)
|
||||||
|
{
|
||||||
|
if (settings.TryGetValue(item, out var v))
|
||||||
|
{
|
||||||
|
return v.Adapt<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task GenerateChargeRecordAsync(long orderId,
|
||||||
|
Dictionary<CanteenSettingItemEnumType, string> settings,
|
||||||
|
List<CanteenBusinessShiftEntity> shifts,
|
||||||
|
DateTime costDateTime)
|
||||||
|
{
|
||||||
|
var order = await _dbContext.Queryable<CanteenOrderEntity>().Where(x => x.Id == orderId).FirstAsync();
|
||||||
|
//在线
|
||||||
|
if (!order.IsOffline)
|
||||||
|
{
|
||||||
|
shifts.FirstOrDefault(x => new TimePeriod()
|
||||||
|
{
|
||||||
|
Start = x.Start,
|
||||||
|
End = x.End,
|
||||||
|
|
||||||
|
}.IsPresent(costDateTime)).ThrowIfNull("当前非就餐时间,无法消费");
|
||||||
|
}
|
||||||
|
|
||||||
|
var beginOfDay = DateTime.Today;
|
||||||
|
var endOfDay = beginOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);
|
||||||
|
|
||||||
|
var balanceRecords = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||||
|
.Where(x => x.UserId == order.UserId)
|
||||||
|
.Where(x => x.CreateTime <= beginOfDay && x.CreateTime <= endOfDay) //今天消费记录
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var dayMarketCostMax = GetSetting<decimal>(settings, CanteenSettingItemEnumType.DayMarketCostMax);
|
||||||
|
if (dayMarketCostMax != default)
|
||||||
|
{
|
||||||
|
var businessPlaceCodes = await _dbContext.Queryable<CanteenBusinessPlaceEntity>().Where(x => x.Catalog == CanteenBusinessPlaceCatalogEnumType.Supermarket).Select(x => x.Code).ToListAsync();
|
||||||
|
var cost = balanceRecords.Where(x => businessPlaceCodes.Contains(x.BusinessPlaceCode)).Sum(x => x.Amount);
|
||||||
|
if (cost + Math.Abs(order.Amount) > dayMarketCostMax)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"超出当天超市消费限制({dayMarketCostMax}),无法消费");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var allowRepeatInOneShift = GetSetting(settings, CanteenSettingItemEnumType.AllowRepeatInOneShift, true);
|
||||||
|
if (!allowRepeatInOneShift)
|
||||||
|
{
|
||||||
|
//todo 餐次问题
|
||||||
|
var costCount = balanceRecords.Where(x => x.BusinessShiftCode == order.BusinessShiftCode).Count();
|
||||||
|
if (costCount > 1)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"当前餐次不允许多次消费");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var onceCostMax = GetSetting<decimal>(settings, CanteenSettingItemEnumType.OnceCostMax);
|
||||||
|
if (onceCostMax != default)
|
||||||
|
{
|
||||||
|
if (Math.Abs(order.Amount) > onceCostMax)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"一次消费金额不能超出{onceCostMax}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var dayCostMax = GetSetting<decimal>(settings, CanteenSettingItemEnumType.DayCostMax);
|
||||||
|
if (dayCostMax != default)
|
||||||
|
{
|
||||||
|
var cost = balanceRecords.Where(x => x.Type == BalanceRecordTypeEnumType.Out).Sum(x => Math.Abs(x.Amount));
|
||||||
|
if (cost + Math.Abs(order.Amount) > dayCostMax)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"超出当天消费限制({dayCostMax}),无法消费");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var canteenUser = await _dbContext.Queryable<CanteenUserEntity>().Where(x => x.UserId == order.UserId).FirstAsync();
|
||||||
|
//金额+-
|
||||||
|
canteenUser.Balance += order.Amount;
|
||||||
|
|
||||||
|
if (order.Type == BalanceRecordTypeEnumType.Out)
|
||||||
|
{
|
||||||
|
if (canteenUser.Balance < 0)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("余额不足,无法消费");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var effect = await _dbContext.Updateable<CanteenUserEntity>()
|
||||||
|
.SetColumns(x => x.Balance == canteenUser.Balance + order.Amount)
|
||||||
|
.SetColumns(x => x.Version == x.Version + 1)
|
||||||
|
.Where(x => x.UserId == order.UserId && x.Version == canteenUser.Version)//必须与查询时的version一致
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
|
||||||
|
if (effect <= 0)
|
||||||
|
{
|
||||||
|
throw new VersionExceptions("更新版本冲突");
|
||||||
|
}
|
||||||
|
|
||||||
|
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||||
|
await _dbContext.InsertAsync(balanceRecord);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex is VersionExceptions)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
58
Src/Dlhis.Canteen/Order/TimePeriodExtensions.cs
Normal file
58
Src/Dlhis.Canteen/Order/TimePeriodExtensions.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using Kurisu.Core.CustomClass;
|
||||||
|
|
||||||
|
namespace Dlhis.Canteen.Order;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 临时的扩展类 todo: 嵌入框架
|
||||||
|
/// </summary>
|
||||||
|
public static class TimePeriodExtensions
|
||||||
|
{
|
||||||
|
public static bool IsPresent(this TimePeriod period, DateTime dateTime)
|
||||||
|
{
|
||||||
|
int hour = dateTime.Hour;
|
||||||
|
int minute = dateTime.Minute;
|
||||||
|
IReadOnlyList<int> hourPeriod = GetHourPeriod();
|
||||||
|
if (hourPeriod.Contains(hour))
|
||||||
|
{
|
||||||
|
if (hour == period.Start.Value.Hour)
|
||||||
|
{
|
||||||
|
return minute > period.Start.Value.Minute;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hour == period.End.Value.Hour)
|
||||||
|
{
|
||||||
|
return minute < period.End.Value.Minute;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
IReadOnlyList<int> GetHourPeriod()
|
||||||
|
{
|
||||||
|
List<int> list = new List<int>();
|
||||||
|
if (period.IsCrossDay())
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 25 - period.Start.Value.Hour; i++)
|
||||||
|
{
|
||||||
|
list.Add(period.Start.Value.Hour + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < period.End.Value.Hour; j++)
|
||||||
|
{
|
||||||
|
list.Add(j + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int k = period.Start.Value.Hour; k < period.End.Value.Hour + 1; k++)
|
||||||
|
{
|
||||||
|
list.Add(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using Kurisu.AspNetCore.Startup;
|
using Kurisu.AspNetCore.Startup;
|
||||||
using Kurisu.Startup;
|
using Kurisu.Startup;
|
||||||
|
|
||||||
namespace Dlhis.Canteen
|
namespace Dlhis.Canteen;
|
||||||
{
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -17,4 +17,3 @@ namespace Dlhis.Canteen
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,15 +6,7 @@
|
|||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
},
|
},
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"applicationUrl": "http://localhost:5002"
|
"applicationUrl": "http://localhost:5008"
|
||||||
},
|
|
||||||
"Docker": {
|
|
||||||
"commandName": "Docker",
|
|
||||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_URLS": "http://+:80"
|
|
||||||
},
|
|
||||||
"publishAllPorts": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"$schema": "https://json.schemastore.org/launchsettings.json"
|
"$schema": "https://json.schemastore.org/launchsettings.json"
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using Kurisu.AspNetCore;
|
using Kurisu.AspNetCore.Startup;
|
||||||
using Kurisu.AspNetCore.Startup;
|
|
||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using SqlSugar;
|
|
||||||
|
|
||||||
namespace Dlhis.Canteen;
|
namespace Dlhis.Canteen;
|
||||||
|
|
||||||
@@ -13,4 +11,9 @@ public class SqlSugarPack : BaseAppPack
|
|||||||
{
|
{
|
||||||
services.AddSqlSugar();
|
services.AddSqlSugar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user