fix 处理时段星期优化
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Dlhis.Entity.Device.Enums;
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Dlhis.Entity.Device.Models;
|
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Request;
|
namespace Dlhis.Basic.Device.Request;
|
||||||
|
|
||||||
public class DeviceTimePeriodSaveRequest
|
public class DeviceTimePeriodSaveRequest : IValidatableObject
|
||||||
{
|
{
|
||||||
public long? Id { get; set; }
|
public long? Id { get; set; }
|
||||||
|
|
||||||
@@ -31,5 +30,14 @@ public class DeviceTimePeriodSaveRequest
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[MinLength(7, ErrorMessage = "配置有误")]
|
[MinLength(7, ErrorMessage = "配置有误")]
|
||||||
[MaxLength(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) });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ namespace Dlhis.Basic.Device.Response;
|
|||||||
|
|
||||||
public class DeviceTimePeriodResponse
|
public class DeviceTimePeriodResponse
|
||||||
{
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 名称
|
/// 名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -143,23 +143,27 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService
|
|||||||
|
|
||||||
var c = currentDtos.First(x => x.CardType == cardType);
|
var c = currentDtos.First(x => x.CardType == cardType);
|
||||||
|
|
||||||
if (b.ToJson() != c.ToJson())
|
if (b.ToJson() == c.ToJson())
|
||||||
{
|
{
|
||||||
tasks.Add(new DeviceTaskEntity
|
continue;
|
||||||
{
|
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ public class DeviceWeekDayTimePeriod
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 时段
|
/// 时段
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<DeviceTimePeriod> TimePeriods { get; set; }
|
public List<DeviceTimePeriod> TimePeriods { get; set; } = new();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user