feat 内部余额写入
This commit is contained in:
@@ -156,7 +156,7 @@ public class MealSupplementRecordService : IMealSupplementRecordService
|
||||
await _dbContext.InsertAsync(new BalanceRecordEntity
|
||||
{
|
||||
Amount = request.Balance,
|
||||
ApplicationType = CanteenApplicaitonTypeEnumType.MealSupplement,
|
||||
ApplicationType = CanteenApplicationTypeEnumType.MealSupplement,
|
||||
Type = BalanceRecordTypeEnumType.In,
|
||||
BusinessPlaceCode = null,
|
||||
BusinessShiftCode = null,
|
||||
|
||||
@@ -137,4 +137,16 @@ public class BalancesController : ControllerBase
|
||||
{
|
||||
return await _balanceService.GetConsumeDeviceAsync(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 海宁餐补数据写入
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
[Transactional]
|
||||
[HttpPost("haining/import")]
|
||||
public async Task Import(BalanceHainingImportRequest request)
|
||||
{
|
||||
await _balanceService.Import(request);
|
||||
}
|
||||
}
|
||||
115
Src/Dlhis.Canteen/Order/Request/BalanceHainingImportRequest.cs
Normal file
115
Src/Dlhis.Canteen/Order/Request/BalanceHainingImportRequest.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Request;
|
||||
|
||||
public class BalanceHainingImportRequest : IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 工号
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "工号不可为空")]
|
||||
public string UserCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 流水号
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "流水号不可为空")]
|
||||
public string No { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备号
|
||||
/// </summary>
|
||||
public string DeviceUniqueNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 金额
|
||||
/// </summary>
|
||||
[Required]
|
||||
public decimal Amount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消费数据类型
|
||||
/// </summary>
|
||||
[Required]
|
||||
[EnumDataType(typeof(CanteenApplicationTypeEnumType), ErrorMessage = "消费数据类型有误")]
|
||||
public CanteenApplicationTypeEnumType ApplicationType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 餐次
|
||||
/// </summary>
|
||||
[Required]
|
||||
[EnumDataType(typeof(ShiftEnumType), ErrorMessage = "餐次类型有误")]
|
||||
public ShiftEnumType ShiftType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 营业点
|
||||
/// </summary>
|
||||
public Guid? BusinessPlaceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消费类型 0:消费, 1:充值
|
||||
/// </summary>
|
||||
[Required]
|
||||
[EnumDataType(typeof(BalanceRecordTypeEnumType), ErrorMessage = "消费类型有误")]
|
||||
public BalanceRecordTypeEnumType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消费来源
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(BalanceRecordSourceEnumType), ErrorMessage = "消费来源有误")]
|
||||
public BalanceRecordSourceEnumType Source { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 成本日期
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime CostDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消费时间
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime CostDateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 厂区
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "厂区不可为空")]
|
||||
public string Factory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "备注不可为空")]
|
||||
public string Remark { get; set; }
|
||||
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (Type == BalanceRecordTypeEnumType.Out)
|
||||
{
|
||||
Amount = -Math.Abs(Amount);
|
||||
|
||||
if (DeviceUniqueNo.IsEmpty())
|
||||
{
|
||||
yield return new ValidationResult("消费设备号不能为空", new[] { nameof(DeviceUniqueNo) });
|
||||
}
|
||||
|
||||
if (ApplicationType != CanteenApplicationTypeEnumType.Device)
|
||||
{
|
||||
yield return new ValidationResult("仅支持设备消费", new[] { nameof(ApplicationType) });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Amount = Math.Abs(Amount);
|
||||
|
||||
if (ApplicationType != CanteenApplicationTypeEnumType.MealSupplement)
|
||||
{
|
||||
yield return new ValidationResult("只支持餐补充值", new[] { nameof(ApplicationType) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public class BalanceRecordUserPageRequest : PageDto, IValidatableObject
|
||||
/// <summary>
|
||||
/// 消费应用类型
|
||||
/// </summary>
|
||||
public CanteenApplicaitonTypeEnumType? ApplicationType { get; set; }
|
||||
public CanteenApplicationTypeEnumType? ApplicationType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 日期范围查询
|
||||
|
||||
@@ -55,7 +55,7 @@ public class BalanceRecordUserPageResponse
|
||||
/// <summary>
|
||||
/// 消费应用类型
|
||||
/// </summary>
|
||||
public CanteenApplicaitonTypeEnumType ApplicationType { get; set; }
|
||||
public CanteenApplicationTypeEnumType ApplicationType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消费应用类型
|
||||
|
||||
@@ -29,4 +29,7 @@ public interface IBalanceService : IScopeDependency
|
||||
Task<Pagination<AverageDailyResponse>> AverageDailyAsync(AverageDailyRequest request);
|
||||
|
||||
Task<Pagination<DevicePageResponse>> GetConsumeDeviceAsync(GetConsumeDeviceRequest request);
|
||||
|
||||
|
||||
Task Import(BalanceHainingImportRequest request);
|
||||
}
|
||||
|
||||
@@ -494,6 +494,58 @@ public class BalanceService : IBalanceService
|
||||
return page;
|
||||
}
|
||||
|
||||
public async Task Import(BalanceHainingImportRequest request)
|
||||
{
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == request.UserCode).SingleAsync();
|
||||
gainfo.ThrowIfNull($"工号{request.UserCode}不存在");
|
||||
var gainfoMeal = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == request.UserCode).SingleAsync();
|
||||
|
||||
|
||||
await _dbContext.InsertAsync(new BalanceRecordEntity
|
||||
{
|
||||
Amount = request.Amount,
|
||||
ApplicationType = request.ApplicationType,
|
||||
Type = request.Type,
|
||||
BusinessPlaceCode = request.BusinessPlaceCode,
|
||||
BusinessShiftCode = null,
|
||||
ShiftType = request.ShiftType,
|
||||
CostDate = request.CostDate,
|
||||
CostDateTime = request.CostDateTime,
|
||||
UserNo = gainfo.No,
|
||||
No = request.No,
|
||||
UserCode = gainfo.Code,
|
||||
TenantId = request.Factory,
|
||||
Status = BalanceRecordStatusEnumType.Valid,
|
||||
Source = request.Source,
|
||||
Remark = request.Remark,
|
||||
CostId = gainfo.CostId,
|
||||
SubsidiesFromMonth = request.CostDate.ToString("yyyyMM"),
|
||||
OriginTenantId = gainfo.Factory,
|
||||
Werks = gainfo.Werks,
|
||||
Name = gainfo.Name,
|
||||
IsCostCrossTenant = false,
|
||||
DepartmentNo = gainfo.DepartmentNo,
|
||||
DeviceUniqueNo = request.DeviceUniqueNo,
|
||||
|
||||
IsDeleted = false,
|
||||
|
||||
CreatedBy = 1,
|
||||
CreateTime = DateTime.Now,
|
||||
ModifiedBy = 1,
|
||||
ModifiedTime = DateTime.Now,
|
||||
});
|
||||
|
||||
var newBalance = gainfoMeal.Balance += request.Amount;
|
||||
|
||||
await _dbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == newBalance)
|
||||
.SetColumns(x => x.ModifiedBy == 1)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.Where(x => x.UserCode == request.UserCode && x.Version == gainfoMeal.Version)
|
||||
.ExecuteCommandThrowVersionAsync("写入失败,正在消费中");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取离线设备
|
||||
|
||||
@@ -55,7 +55,7 @@ public class BookingOrderService : BaseOrderService, IBookingOrderService
|
||||
RequestJson = request.ToJson(),
|
||||
ThirdNo = string.Empty,
|
||||
Type = BalanceRecordTypeEnumType.Out,
|
||||
ApplicationType = CanteenApplicaitonTypeEnumType.Booking,
|
||||
ApplicationType = CanteenApplicationTypeEnumType.Booking,
|
||||
Name = gainfo.Name,
|
||||
Source = request.Source,
|
||||
UserNo = gainfo.No,
|
||||
@@ -287,7 +287,7 @@ public class BookingOrderService : BaseOrderService, IBookingOrderService
|
||||
var end = start.AddDays(1).AddSeconds(-1);
|
||||
|
||||
var exists = await DbContext.Queryable<CanteenOrderEntity>()
|
||||
.Where(x => x.ApplicationType == CanteenApplicaitonTypeEnumType.Booking)
|
||||
.Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.Booking)
|
||||
.Where(x => x.OrderStatus == CanteenOrderStatusEnumType.Success)
|
||||
.Where(x => x.ShiftType == shiftType)
|
||||
.Where(x => x.UserNo == gainfo.No)
|
||||
|
||||
@@ -182,7 +182,7 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
RequestJson = request.ToJson(),
|
||||
ThirdNo = request.ThirdNo,
|
||||
Type = BalanceRecordTypeEnumType.Out,
|
||||
ApplicationType = CanteenApplicaitonTypeEnumType.Device,
|
||||
ApplicationType = CanteenApplicationTypeEnumType.Device,
|
||||
Name = gainfo.Name,
|
||||
Source = request.Source,
|
||||
UserNo = gainfo.No,
|
||||
@@ -314,7 +314,7 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
RequestJson = request.ToJson(),
|
||||
ThirdNo = request.ThirdNo,
|
||||
Type = BalanceRecordTypeEnumType.Out,
|
||||
ApplicationType = CanteenApplicaitonTypeEnumType.Device,
|
||||
ApplicationType = CanteenApplicationTypeEnumType.Device,
|
||||
Name = gainfo.Name,
|
||||
Source = request.Source,
|
||||
UserNo = gainfo.No,
|
||||
@@ -383,7 +383,7 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
|
||||
var pageResult = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.UserNo == gainfo.No)
|
||||
.LeftJoin<BusinessPlaceEntity>((x, bplace) => x.BusinessPlaceCode == bplace.Code)
|
||||
.Where(x => x.ApplicationType == CanteenApplicaitonTypeEnumType.Booking)
|
||||
.Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.Booking)
|
||||
.OrderBy(x => x.CreateTime, OrderByType.Desc)
|
||||
.Select((x, bplace) => new OrderAggregationResponse
|
||||
{
|
||||
@@ -422,7 +422,7 @@ public class OrderService : BaseOrderService, IOrderService
|
||||
var orders = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.IsOffline)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.Where(x => x.OrderStatus == CanteenOrderStatusEnumType.Success)
|
||||
.Where(x => x.ApplicationType == CanteenApplicaitonTypeEnumType.Device)
|
||||
.Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.Device)
|
||||
.Where(x => SqlFunc.IsNullOrEmpty(x.BusinessShiftCode))
|
||||
.WhereIF(outRequest.No.IsPresent(), x => x.No == outRequest.No)
|
||||
.ToListAsync();
|
||||
|
||||
Reference in New Issue
Block a user