fix 就餐参数配置检验调整
This commit is contained in:
@@ -50,7 +50,8 @@ public class CanteenSettingService : ICanteenSettingService
|
|||||||
|
|
||||||
public async Task SaveSettingAsync(CanteenSettingSaveRequest request)
|
public async Task SaveSettingAsync(CanteenSettingSaveRequest request)
|
||||||
{
|
{
|
||||||
Inspection(request);//校验参数
|
//校验参数
|
||||||
|
Inspection(request);
|
||||||
await CheckDuplicateSettingAsync(request);
|
await CheckDuplicateSettingAsync(request);
|
||||||
|
|
||||||
if (!request.Id.HasValue)
|
if (!request.Id.HasValue)
|
||||||
@@ -69,42 +70,31 @@ public class CanteenSettingService : ICanteenSettingService
|
|||||||
|
|
||||||
private void Inspection(CanteenSettingSaveRequest request)
|
private void Inspection(CanteenSettingSaveRequest request)
|
||||||
{
|
{
|
||||||
switch (request.Item)
|
var value = request.Value;
|
||||||
{
|
|
||||||
case CanteenSettingItemEnumType.BusinessSwitchTime:
|
|
||||||
ValidateBusinessSwitchTime(request);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CanteenSettingItemEnumType.InitBalance:
|
var result = request.Item switch
|
||||||
case CanteenSettingItemEnumType.DayCostMax:
|
|
||||||
case CanteenSettingItemEnumType.DayMarketCostMax:
|
|
||||||
case CanteenSettingItemEnumType.OnceCostMax:
|
|
||||||
ValidateDecimal(request);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ValidateBusinessSwitchTime(CanteenSettingSaveRequest request)
|
|
||||||
{
|
|
||||||
// 对 BusinessSwitchTime 进行时间格式验证
|
|
||||||
if (string.IsNullOrEmpty(request.Value) || !IsValidTimeFormat(request.Value))
|
|
||||||
{
|
{
|
||||||
throw new UserFriendlyException("BusinessSwitchTime 参数无效。它应该是 HH:00:00 格式");
|
//TimeOnly
|
||||||
}
|
CanteenSettingItemEnumType.BusinessSwitchTime => IsValidFormat<TimeOnly>(value),
|
||||||
}
|
|
||||||
// 用于验证时间格式
|
|
||||||
private bool IsValidTimeFormat(string time)
|
|
||||||
{
|
|
||||||
return DateTime.TryParseExact(time, "HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ValidateDecimal(CanteenSettingSaveRequest request)
|
//int
|
||||||
{
|
CanteenSettingItemEnumType.DayEVoucherUseCountMax => IsValidFormat<int>(value),
|
||||||
// 对 InitBalance 进行 decimal 转换验证
|
|
||||||
if (!decimal.TryParse(request.Value, out _))
|
//decimal
|
||||||
{
|
CanteenSettingItemEnumType.OnceCostMax => IsValidFormat<decimal>(value),
|
||||||
throw new UserFriendlyException($"{request.Item} 参数无效。它应该是 decimal 类型");
|
CanteenSettingItemEnumType.DayCostMax => IsValidFormat<decimal>(value),
|
||||||
}
|
CanteenSettingItemEnumType.DayMarketCostMax => IsValidFormat<decimal>(value),
|
||||||
|
CanteenSettingItemEnumType.Subsidies => IsValidFormat<decimal>(value),
|
||||||
|
CanteenSettingItemEnumType.InitBalance => IsValidFormat<decimal>(value),
|
||||||
|
|
||||||
|
//bool
|
||||||
|
CanteenSettingItemEnumType.AllowSendAtMeal => IsValidFormat<bool>(value),
|
||||||
|
CanteenSettingItemEnumType.AllowRepeatInOneShift => IsValidFormat<bool>(value),
|
||||||
|
CanteenSettingItemEnumType.AllowCrossTenant => IsValidFormat<bool>(value),
|
||||||
|
_ => throw new NotImplementedException(),
|
||||||
|
};
|
||||||
|
|
||||||
|
result.ThrowIfFalse($"{request.Item.GetDescription()},参数值为[{value}],格式错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetEnableAsync(CanteenSettingSetEnableRequest request)
|
public async Task SetEnableAsync(CanteenSettingSetEnableRequest request)
|
||||||
@@ -158,4 +148,28 @@ public class CanteenSettingService : ICanteenSettingService
|
|||||||
|
|
||||||
exists.ThrowIfTrue("配置项重复,请检查.");
|
exists.ThrowIfTrue("配置项重复,请检查.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检验参数
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static bool IsValidFormat<T>(string value, CanteenSettingItemEnumType? type = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//mapster
|
||||||
|
value.Adapt<T>();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class BalanceRecordEntity : SugarBaseEntity, ITenantId
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 餐次
|
/// 餐次
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "餐次")]
|
[SugarColumn(ColumnDescription = "餐次", IsNullable = true)]
|
||||||
public Guid? BusinessShiftCode { get; set; }
|
public Guid? BusinessShiftCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -82,7 +82,7 @@ public class BalanceRecordEntity : SugarBaseEntity, ITenantId
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 消费机器唯一信息
|
/// 消费机器唯一信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "消费机器唯一信息")]
|
[SugarColumn(ColumnDescription = "消费机器唯一信息", IsNullable = true)]
|
||||||
public string DeviceInfo { get; set; }
|
public string DeviceInfo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public enum CanteenSettingItemEnumType
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 允许就餐下发
|
/// 允许就餐下发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("允许就餐下发(T/F)")]
|
[Description("允许就餐下发(0/1)")]
|
||||||
AllowSendAtMeal,
|
AllowSendAtMeal,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -58,7 +58,7 @@ public enum CanteenSettingItemEnumType
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 允许一餐次多次消费
|
/// 允许一餐次多次消费
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("允许一餐次多次消费(1/0)")]
|
[Description("允许一餐次多次消费(0/1)")]
|
||||||
AllowRepeatInOneShift,
|
AllowRepeatInOneShift,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -71,7 +71,7 @@ public enum CanteenSettingItemEnumType
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 允许跨基地消费
|
/// 允许跨基地消费
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("允许跨基地消费(1/0)")]
|
[Description("允许跨基地消费(0/1)")]
|
||||||
AllowCrossTenant,
|
AllowCrossTenant,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user