fix 处理时段星期优化
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Device.Models;
|
||||
|
||||
namespace Dlhis.Basic.Device.Request;
|
||||
|
||||
public class DeviceTimePeriodSectionRequest : DeviceWeekDayTimePeriod, IValidatableObject
|
||||
{
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (TimePeriods.Count == 0)
|
||||
{
|
||||
yield return new ValidationResult("时段码设置不能为空", new[] { nameof(TimePeriods) });
|
||||
}
|
||||
|
||||
for (int i = 0; i < TimePeriods.Count; i++)
|
||||
{
|
||||
var tp = TimePeriods[i];
|
||||
|
||||
if (tp.Enable && tp.Start >= tp.End)
|
||||
{
|
||||
yield return new ValidationResult($"第{i + 1}个时段设置有误", new[] { nameof(tp.Start) });
|
||||
}
|
||||
|
||||
if (i == TimePeriods.Count - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var tpn = TimePeriods[i + 1];
|
||||
if (tpn.Enable && tp.Enable && tp.End >= tpn.Start)
|
||||
{
|
||||
yield return new ValidationResult($"第{i + 1}个时段设置有误", new[] { nameof(tp.End) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user