Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development
This commit is contained in:
@@ -50,7 +50,8 @@ public class CanteenSettingService : ICanteenSettingService
|
||||
|
||||
public async Task SaveSettingAsync(CanteenSettingSaveRequest request)
|
||||
{
|
||||
Inspection(request);//校验参数
|
||||
//校验参数
|
||||
Inspection(request);
|
||||
await CheckDuplicateSettingAsync(request);
|
||||
|
||||
if (!request.Id.HasValue)
|
||||
@@ -69,42 +70,31 @@ public class CanteenSettingService : ICanteenSettingService
|
||||
|
||||
private void Inspection(CanteenSettingSaveRequest request)
|
||||
{
|
||||
switch (request.Item)
|
||||
{
|
||||
case CanteenSettingItemEnumType.BusinessSwitchTime:
|
||||
ValidateBusinessSwitchTime(request);
|
||||
break;
|
||||
var value = request.Value;
|
||||
|
||||
case CanteenSettingItemEnumType.InitBalance:
|
||||
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))
|
||||
var result = request.Item switch
|
||||
{
|
||||
throw new UserFriendlyException("BusinessSwitchTime 参数无效。它应该是 HH:00:00 格式");
|
||||
}
|
||||
}
|
||||
// 用于验证时间格式
|
||||
private bool IsValidTimeFormat(string time)
|
||||
{
|
||||
return DateTime.TryParseExact(time, "HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out _);
|
||||
}
|
||||
//TimeOnly
|
||||
CanteenSettingItemEnumType.BusinessSwitchTime => IsValidFormat<TimeOnly>(value),
|
||||
|
||||
private void ValidateDecimal(CanteenSettingSaveRequest request)
|
||||
{
|
||||
// 对 InitBalance 进行 decimal 转换验证
|
||||
if (!decimal.TryParse(request.Value, out _))
|
||||
{
|
||||
throw new UserFriendlyException($"{request.Item} 参数无效。它应该是 decimal 类型");
|
||||
}
|
||||
//int
|
||||
CanteenSettingItemEnumType.DayEVoucherUseCountMax => IsValidFormat<int>(value),
|
||||
|
||||
//decimal
|
||||
CanteenSettingItemEnumType.OnceCostMax => IsValidFormat<decimal>(value),
|
||||
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)
|
||||
@@ -158,4 +148,28 @@ public class CanteenSettingService : ICanteenSettingService
|
||||
|
||||
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>
|
||||
[SugarColumn(ColumnDescription = "餐次")]
|
||||
[SugarColumn(ColumnDescription = "餐次", IsNullable = true)]
|
||||
public Guid? BusinessShiftCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -82,7 +82,7 @@ public class BalanceRecordEntity : SugarBaseEntity, ITenantId
|
||||
/// <summary>
|
||||
/// 消费机器唯一信息
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "消费机器唯一信息")]
|
||||
[SugarColumn(ColumnDescription = "消费机器唯一信息", IsNullable = true)]
|
||||
public string DeviceInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -40,7 +40,7 @@ public enum CanteenSettingItemEnumType
|
||||
/// <summary>
|
||||
/// 允许就餐下发
|
||||
/// </summary>
|
||||
[Description("允许就餐下发(T/F)")]
|
||||
[Description("允许就餐下发(0/1)")]
|
||||
AllowSendAtMeal,
|
||||
|
||||
/// <summary>
|
||||
@@ -58,7 +58,7 @@ public enum CanteenSettingItemEnumType
|
||||
/// <summary>
|
||||
/// 允许一餐次多次消费
|
||||
/// </summary>
|
||||
[Description("允许一餐次多次消费(1/0)")]
|
||||
[Description("允许一餐次多次消费(0/1)")]
|
||||
AllowRepeatInOneShift,
|
||||
|
||||
/// <summary>
|
||||
@@ -71,7 +71,7 @@ public enum CanteenSettingItemEnumType
|
||||
/// <summary>
|
||||
/// 允许跨基地消费
|
||||
/// </summary>
|
||||
[Description("允许跨基地消费(1/0)")]
|
||||
[Description("允许跨基地消费(0/1)")]
|
||||
AllowCrossTenant,
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user