108 lines
3.5 KiB
C#
108 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Aspose.Cells.Drawing;
|
|
using JNPF;
|
|
using JNPF.Common.Contracts;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.VisualDev;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Tnb.WarehouseMgr.Entities.Attributes;
|
|
using Tnb.WarehouseMgr.Entities.Dto;
|
|
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
|
|
using Tnb.WarehouseMgr.Entities.Entity;
|
|
using Tnb.WarehouseMgr.Interfaces;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
public class BaseWareHouseService : IOverideVisualDevService, IDynamicApiController, ITransient
|
|
{
|
|
private static Dictionary<string, IWHStorageService> _stroageMap = new Dictionary<string, IWHStorageService>(StringComparer.OrdinalIgnoreCase);
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
|
|
static BaseWareHouseService()
|
|
{
|
|
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList();
|
|
foreach (var serviceType in serviceTypes)
|
|
{
|
|
var callerName = serviceType.GetCustomAttribute<CallerAttribute>()?.Name;
|
|
if (!callerName.IsNullOrEmpty())
|
|
{
|
|
_stroageMap[callerName!] = (IWHStorageService)Activator.CreateInstance(serviceType)!;
|
|
}
|
|
}
|
|
}
|
|
[NonAction]
|
|
protected async Task DoUpdate(WareHouseUpInput input)
|
|
{
|
|
if (_stroageMap.ContainsKey(input.loginType))
|
|
{
|
|
await _stroageMap[input.loginType].Do(input);
|
|
}
|
|
}
|
|
[NonAction]
|
|
public virtual Task ModifyAsync(WareHouseUpInput input)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Api响应结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
protected Task<DataResult> ToApiResult()
|
|
{
|
|
DataResult result = new(); ;
|
|
return Task.FromResult(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Api响应结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
protected Task<DataResult> ToApiResult(HttpStatusCode statusCode, object data)
|
|
{
|
|
DataResult result = new();
|
|
result.code = statusCode;
|
|
result.data = data;
|
|
return Task.FromResult(result);
|
|
}
|
|
/// <summary>
|
|
/// Api响应结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
protected Task<DataResult> ToApiResult(HttpStatusCode statusCode, string msg)
|
|
{
|
|
DataResult result = new();
|
|
result.code = statusCode;
|
|
result.msg = msg;
|
|
return Task.FromResult(result);
|
|
}
|
|
/// <summary>
|
|
/// Api响应结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
protected Task<DataResult> ToApiResult(HttpStatusCode statusCode, string msg, object data)
|
|
{
|
|
DataResult result = new();
|
|
result.code = statusCode;
|
|
result.msg = msg;
|
|
result.data = data;
|
|
return Task.FromResult(result);
|
|
}
|
|
}
|
|
}
|