71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using Dlhis.Entity.Device.Enums;
|
|
using Dlhis.Entity.Sys.Enums;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
|
|
namespace Dlhis.Basic.Device.Request;
|
|
|
|
public class DevicePermissionSaveRequest : IValidatableObject
|
|
{
|
|
/// <summary>
|
|
/// 分配类型 AssignTypeEnumType
|
|
/// </summary>
|
|
[EnumDataType(typeof(AssignTypeEnumType), ErrorMessage = "枚举类型错误")]
|
|
public AssignTypeEnumType AssignType { get; set; }
|
|
|
|
/// <summary>
|
|
/// 分配值
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// 如果<see cref="AssignTypeEnumType"/>为用户,那么AssignValue=UserNo
|
|
/// </remarks>
|
|
[Required(ErrorMessage = "分配值不能为空")]
|
|
public string AssignValue { get; set; }
|
|
|
|
/// <summary>
|
|
/// 来源分配权限类型 DevicePermissionTypeEnumType
|
|
/// </summary>
|
|
[EnumDataType(typeof(DeviceAssignmentTypeEnumType), ErrorMessage = "枚举类型错误")]
|
|
public DeviceAssignmentTypeEnumType UniqueType { get; set; }
|
|
|
|
/// <summary>
|
|
/// 分配权限值
|
|
/// </summary>
|
|
public List<Guid> Codes { get; set; }
|
|
|
|
/// <summary>
|
|
/// AssignType == AssignTypeEnumType.Department 需要传入
|
|
/// </summary>
|
|
public string TenantId { get; set; }
|
|
|
|
/// <summary>
|
|
/// 设备类型
|
|
/// </summary>
|
|
[EnumDataType(typeof(DeviceTypeEnumType))]
|
|
public DeviceTypeEnumType Type { get; set; }
|
|
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
{
|
|
if (AssignType == AssignTypeEnumType.Department)
|
|
{
|
|
if (TenantId.IsEmpty())
|
|
{
|
|
yield return new ValidationResult("请明确具体的厂区", new[] { nameof(TenantId) });
|
|
}
|
|
}
|
|
|
|
if (AssignType == AssignTypeEnumType.Role)
|
|
{
|
|
yield return new ValidationResult("暂不支持角色分配", new[] { nameof(AssignType) });
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取实际分配的权限值
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetActualAssignValue()
|
|
{
|
|
return AssignType == AssignTypeEnumType.Department ? TenantId + ":" + AssignValue : AssignValue;
|
|
}
|
|
} |