fix 处理时段星期优化

This commit is contained in:
2024-07-19 17:17:32 +08:00
parent 4af6cda8cb
commit 0cc5c538f1
5 changed files with 69 additions and 19 deletions

View File

@@ -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
/// </summary>
[MinLength(7, ErrorMessage = "配置有误")]
[MaxLength(7, ErrorMessage = "配置有误")]
public List<DeviceWeekDayTimePeriod> Sections { get; set; }
public List<DeviceTimePeriodSectionRequest> Sections { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (Sections.DistinctBy(x => x.DayOfWeek).Count() != Sections.Count)
{
yield return new ValidationResult("星期配置重复", new[] { nameof(Sections) });
}
}
}

View File

@@ -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) });
}
}
}
}

View File

@@ -5,6 +5,8 @@ namespace Dlhis.Basic.Device.Response;
public class DeviceTimePeriodResponse
{
public long Id { get; set; }
/// <summary>
/// 名称
/// </summary>

View File

@@ -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;
}
}

View File

@@ -10,5 +10,5 @@ public class DeviceWeekDayTimePeriod
/// <summary>
/// 时段
/// </summary>
public List<DeviceTimePeriod> TimePeriods { get; set; }
public List<DeviceTimePeriod> TimePeriods { get; set; } = new();
}