Files
tnb.server/WarehouseMgr/Tnb.WarehouseMgr/PcStroageService.cs
2023-08-18 17:51:12 +08:00

38 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using JNPF;
using JNPF.Common.Extension;
using Tnb.WarehouseMgr.Entities.Attributes;
using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
[Caller("web")]
public class PcStroageService : IWHStorageService
{
private static Dictionary<string, Func<WareHouseUpInput, Task>> _serviceCallbackMap = new(StringComparer.OrdinalIgnoreCase);
static PcStroageService()
{
_serviceCallbackMap = App.EffectiveTypes.AsParallel().Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && !typeof(IPdaStroage).IsAssignableFrom(u)
&& u.IsSubclassOf(typeof(BaseWareHouseService)) && u.GetCustomAttribute<ServiceModuleAttribute>() != null)
.ToDictionary(x => x.GetCustomAttribute<ServiceModuleAttribute>().BizTypeId,
x => (Func<WareHouseUpInput, Task>)Delegate.CreateDelegate(typeof(Func<WareHouseUpInput, Task>), App.GetService(x), x.GetMethod(nameof(WareHouseService.ModifyAsync))));
}
public async Task Do(WareHouseUpInput input)
{
if (_serviceCallbackMap.ContainsKey(input.bizTypeId))
{
await _serviceCallbackMap[input.bizTypeId].Invoke(input);
}
}
}
}