using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Op.Entity;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
namespace DS.WMS.Core.Application.Dtos
{
///
/// 业务ID与类型
///
public class BizItem
{
public static readonly BizItemComparer DefaultComparer = new();
///
/// 业务ID
///
public long Id { get; set; }
///
/// 业务类型
///
public BusinessType BusinessType { get; set; }
public class BizItemComparer : IEqualityComparer
{
public bool Equals(BizItem? x, BizItem? y)
{
if (x == null || y == null)
return false;
return x.Id == y.Id && x.BusinessType == y.BusinessType;
}
public int GetHashCode([DisallowNull] BizItem obj)
{
return obj.Id.GetHashCode() ^ (int)obj.BusinessType;
}
}
}
///
/// 费用对象/单位
///
public class FeeClient : BizItem
{
///
/// 费用对象ID
///
public long CustomerId { get; set; }
///
/// 汇率信息
///
public CurrencyExchangeRate[]? ExchangeRates { get; set; }
}
public class BizOperation : IValidatableObject
{
///
/// 请求值(object类型,根据业务按需传值)
///
public object Value { get; set; }
///
/// 业务ID与类型
///
public List? Items { get; set; }
///
/// 业务ID
///
[IgnoreDataMember]
public IEnumerable? Ids => Items?.Select(x => x.Id).Distinct();
///
/// 业务类型
///
[IgnoreDataMember]
public IEnumerable? Types => Items?.Select(x => x.BusinessType).Distinct();
public IEnumerable Validate(ValidationContext validationContext)
{
if (Items == null || Items.Count == 0)
{
yield return new ValidationResult($"缺少请求参数:{nameof(Items)}");
}
}
}
public class BizOperation : BizOperation
{
///
/// 请求值(根据业务按需传值)
///
public new T Value { get; set; }
}
}