调整PC端调用业务回更代码

This commit is contained in:
alex
2023-08-18 17:51:12 +08:00
parent 96b5f3ca8c
commit 89a4df8073

View File

@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Text;
@@ -15,25 +17,20 @@ namespace Tnb.WarehouseMgr
[Caller("web")]
public class PcStroageService : IWHStorageService
{
private static Dictionary<string, BaseWareHouseService> _serviceMap = new Dictionary<string, BaseWareHouseService>(StringComparer.OrdinalIgnoreCase);
private static Dictionary<string, Func<WareHouseUpInput, Task>> _serviceCallbackMap = new(StringComparer.OrdinalIgnoreCase);
static PcStroageService()
{
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && !typeof(IPdaStroage).IsAssignableFrom(u) && u.IsSubclassOf(typeof(BaseWareHouseService))).ToList();
foreach (var serviceType in serviceTypes)
{
var bizTypeId = serviceType.GetCustomAttribute<ServiceModuleAttribute>()?.BizTypeId;
if (!bizTypeId.IsNullOrEmpty())
{
_serviceMap[bizTypeId!] = (BaseWareHouseService)App.GetService(serviceType)!;
}
}
_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 (_serviceMap.ContainsKey(input.bizTypeId))
if (_serviceCallbackMap.ContainsKey(input.bizTypeId))
{
await _serviceMap[input.bizTypeId].ModifyAsync(input);
await _serviceCallbackMap[input.bizTypeId].Invoke(input);
}
}
}