diff --git a/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSaveRequest.cs index f8199a86..ffec74b3 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSaveRequest.cs @@ -1,10 +1,9 @@ using System.ComponentModel.DataAnnotations; using Dlhis.Entity.Device.Enums; -using Dlhis.Entity.Device.Models; namespace Dlhis.Basic.Device.Request; -public class DeviceTimePeriodSaveRequest +public class DeviceTimePeriodSaveRequest : IValidatableObject { public long? Id { get; set; } @@ -31,5 +30,14 @@ public class DeviceTimePeriodSaveRequest /// [MinLength(7, ErrorMessage = "配置有误")] [MaxLength(7, ErrorMessage = "配置有误")] - public List Sections { get; set; } + public List Sections { get; set; } + + + public IEnumerable Validate(ValidationContext validationContext) + { + if (Sections.DistinctBy(x => x.DayOfWeek).Count() != Sections.Count) + { + yield return new ValidationResult("星期配置重复", new[] { nameof(Sections) }); + } + } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSectionRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSectionRequest.cs new file mode 100644 index 00000000..da758d03 --- /dev/null +++ b/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSectionRequest.cs @@ -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 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) }); + } + } + } +} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Device/Response/DeviceTimePeriodResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceTimePeriodResponse.cs index 70f919e9..dd3091be 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceTimePeriodResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceTimePeriodResponse.cs @@ -5,6 +5,8 @@ namespace Dlhis.Basic.Device.Response; public class DeviceTimePeriodResponse { + public long Id { get; set; } + /// /// 名称 /// diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceTimePeriodService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceTimePeriodService.cs index 442a30d0..1ab79451 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceTimePeriodService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceTimePeriodService.cs @@ -143,23 +143,27 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService var c = currentDtos.First(x => x.CardType == cardType); - if (b.ToJson() != c.ToJson()) + if (b.ToJson() == c.ToJson()) { - tasks.Add(new DeviceTaskEntity - { - Type = DeviceTaskEnumType.TimePeriodAdd, - DeviceType = device.Type, - UserId = null, - UserNo = null, - DeviceUniqueNo = deviceUniqueNo, - Status = DeviceTaskStatusEnumType.Wait, - Version = 0, - CancellationId = 0, - Source = null, - Priority = 90, - TenantId = device.TenantId - }); + continue; } + + tasks.Add(new DeviceTaskEntity + { + Type = DeviceTaskEnumType.TimePeriodAdd, + DeviceType = device.Type, + UserId = null, + UserNo = null, + DeviceUniqueNo = deviceUniqueNo, + Status = DeviceTaskStatusEnumType.Wait, + Version = 0, + CancellationId = 0, + Source = null, + Priority = 90, + TenantId = device.TenantId + }); + + break; } } diff --git a/Src/Dlhis.Entity/Device/Models/DeviceWeekDayTimePeriod.cs b/Src/Dlhis.Entity/Device/Models/DeviceWeekDayTimePeriod.cs index 62e818e6..c9397b83 100644 --- a/Src/Dlhis.Entity/Device/Models/DeviceWeekDayTimePeriod.cs +++ b/Src/Dlhis.Entity/Device/Models/DeviceWeekDayTimePeriod.cs @@ -10,5 +10,5 @@ public class DeviceWeekDayTimePeriod /// /// 时段 /// - public List TimePeriods { get; set; } + public List TimePeriods { get; set; } = new(); } \ No newline at end of file