using System.Reflection; using JNPF; using JNPF.Common.Extension; using Tnb.WarehouseMgr.Entities.Attributes; using Tnb.WarehouseMgr.Entities.Dto; using Tnb.WarehouseMgr.Interfaces; namespace Tnb.WarehouseMgr { [Caller("app")] public class PdaStroageService : IWHStorageService { private static readonly Dictionary _serviceMap = new(StringComparer.OrdinalIgnoreCase); static PdaStroageService() { List serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IPdaStroage).IsAssignableFrom(u) && u.IsSubclassOf(typeof(BaseWareHouseService))).ToList(); foreach (Type? serviceType in serviceTypes) { string? bizTypeId = serviceType.GetCustomAttribute()?.BizTypeId; if (!bizTypeId.IsNullOrEmpty()) { _serviceMap[bizTypeId!] = (BaseWareHouseService)App.GetService(serviceType)!; } } } public async Task Do(WareHouseUpInput input) { if (_serviceMap.ContainsKey(input.bizTypeId)) { await _serviceMap[input.bizTypeId].ModifyAsync(input); } else { foreach (var key in _serviceMap.Keys) { if (key.Contains(input.bizTypeId)) { await _serviceMap[key].ModifyAsync(input); } } } } } }