fix CanteenSettingItemEnumType参数校验

This commit is contained in:
cheche
2024-01-11 18:08:14 +08:00
parent 353844f348
commit 3f91c6109b
3 changed files with 49 additions and 3 deletions

View File

@@ -298,7 +298,7 @@ public class OrderService : IOrderService
var balanceRecords = await _dbContext.Queryable<BalanceRecordEntity>()
.Where(x => x.UserNo == order.UserNo)
.Where(x => x.CreateTime <= beginOfDay && x.CreateTime <= endOfDay) //今天消费记录
.Where(x => x.CreateTime >= beginOfDay && x.CreateTime <= endOfDay) //今天消费记录
.ToListAsync();
var dayMarketCostMax = GetSetting<decimal>(settings, CanteenSettingItemEnumType.DayMarketCostMax);

View File

@@ -2,11 +2,15 @@
using Dlhis.Canteen.Setting.Response;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Canteen.Enums;
using Kurisu.AspNetCore.UnifyResultAndValidation;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
using Mapster;
using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
namespace Dlhis.Canteen.Setting.Services.Implements;
@@ -46,6 +50,7 @@ public class CanteenSettingService : ICanteenSettingService
public async Task SaveSettingAsync(CanteenSettingSaveRequest request)
{
Inspection(request);//校验参数
await CheckDuplicateSettingAsync(request);
if (!request.Id.HasValue)
@@ -62,6 +67,48 @@ public class CanteenSettingService : ICanteenSettingService
}
}
private void Inspection(CanteenSettingSaveRequest request)
{
switch (request.Item)
{
case CanteenSettingItemEnumType.BusinessSwitchTime:
ValidateBusinessSwitchTime(request);
break;
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))
{
throw new UserFriendlyException("BusinessSwitchTime 参数无效。它应该是 HH:00:00 格式");
}
}
// 用于验证时间格式
private bool IsValidTimeFormat(string time)
{
return DateTime.TryParseExact(time, "HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out _);
}
private void ValidateDecimal(CanteenSettingSaveRequest request)
{
// 对 InitBalance 进行 decimal 转换验证
if (!decimal.TryParse(request.Value, out _))
{
throw new UserFriendlyException("InitBalance 参数无效。它应该是 decimal 类型");
}
}
public async Task SetEnableAsync(CanteenSettingSetEnableRequest request)
{
var entity = await _context.Queryable<CanteenSettingEntity>().FirstAsync(x => x.Id == request.Id);

View File

@@ -152,7 +152,6 @@ namespace Dlhis.ScheduledTask.Job
gainfo.Code = item.ename;
gainfo.CountryNo = item.country;
gainfo.IdClass = item.idcls;
gainfo.IdNo = item.idno;
gainfo.Native = item.native;
gainfo.Gender = item.sex == "F" ? GenderEnumType.Female : GenderEnumType.Male;
gainfo.Birthday = (DateTime)item.birthday;
@@ -164,7 +163,7 @@ namespace Dlhis.ScheduledTask.Job
gainfo.Position = item.web;
gainfo.Remark = item.remark;
gainfo.Werks = item.WERKS;
gainfo.Employed = item.isowner;
gainfo.Employed = item.isowner; //int.Parse(person.ZSTATUS) < 4 ? "T" : "F", 是否离职
await _dbContext.UpdateAsync(gainfo);
}
else