204 lines
6.6 KiB
C#
204 lines
6.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Reflection;
|
|
using System.Security.Claims;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Channels;
|
|
using System.Threading.Tasks;
|
|
using Aspose.Cells.Drawing;
|
|
using JNPF;
|
|
using JNPF.Common.Contracts;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.DataEncryption;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Extras.CollectiveOAuth.Enums;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.VisualDev;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json.Linq;
|
|
using NPOI.HSSF.UserModel;
|
|
using NPOI.SS.UserModel;
|
|
using NPOI.XSSF.UserModel;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Attributes;
|
|
using Tnb.WarehouseMgr.Entities.Consts;
|
|
using Tnb.WarehouseMgr.Entities.Dto;
|
|
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
|
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(StringComparer.OrdinalIgnoreCase);
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
private readonly ChannelWriter<NotifyMessage> _channelWriter;
|
|
|
|
public BaseWareHouseService(ChannelWriter<NotifyMessage>? channelWriter = default)
|
|
{
|
|
_channelWriter = channelWriter;
|
|
}
|
|
|
|
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 ?? string.Empty;
|
|
if (!callerName.IsNullOrEmpty())
|
|
{
|
|
var obj = Activator.CreateInstance(serviceType) as IWHStorageService;
|
|
if (obj == null) continue;
|
|
_stroageMap[callerName] = obj;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected Task<ClaimsPrincipal> GetUserIdentity()
|
|
{
|
|
var claims = JWTEncryption.ReadJwtToken(UserManager.AsscessToken)?.Claims;
|
|
ClaimsIdentity toKen = new ClaimsIdentity();
|
|
foreach (Claim item in claims)
|
|
{
|
|
toKen.AddClaim(item);
|
|
}
|
|
var curUser = new ClaimsPrincipal(toKen);
|
|
return Task.FromResult(curUser);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断最终目标库位是否可以放置当前载具
|
|
/// </summary>
|
|
/// <param name="carry">当前载具</param>
|
|
/// <param name="locDest">目标库位</param>
|
|
/// <returns></returns>
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
[NonAction]
|
|
protected Task<bool> IsCarryAndLocationMatchByCarryStd(WmsCarryH carry, BasLocation locDest)
|
|
{
|
|
bool isMatch = false;
|
|
if (carry == null) throw new ArgumentNullException(nameof(carry));
|
|
if (locDest == null) throw new ArgumentNullException(nameof(locDest));
|
|
if (!carry.carrystd_id.IsNullOrEmpty() && !locDest.carrystd_id.IsNullOrEmpty())
|
|
{
|
|
var jsonArr = JArray.Parse(locDest.carrystd_id);
|
|
var locCarryStdArr = jsonArr.Select(x => x.ToObject<string>()).ToArray();
|
|
isMatch = locCarryStdArr.Contains(carry.carrystd_id);
|
|
}
|
|
return Task.FromResult(isMatch);
|
|
}
|
|
/// <summary>
|
|
/// 发布消息
|
|
/// </summary>
|
|
/// <param name="taskName"></param>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
protected async Task Publish(string taskName)
|
|
{
|
|
NotifyMessage message = new() { TaskName = taskName };
|
|
if (_channelWriter != null)
|
|
await _channelWriter.WriteAsync(message);
|
|
}
|
|
|
|
[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<Result> ToApiResult()
|
|
{
|
|
Result result = new();
|
|
return Task.FromResult(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Api响应结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
protected Task<Result> ToApiResult(HttpStatusCode statusCode, object data)
|
|
{
|
|
Result result = new()
|
|
{
|
|
code = statusCode,
|
|
data = data
|
|
};
|
|
return Task.FromResult(result);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Api响应结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
protected Task<Result> ToApiResult(object data)
|
|
{
|
|
Result result = new()
|
|
{
|
|
data = data
|
|
};
|
|
return Task.FromResult(result);
|
|
}
|
|
/// <summary>
|
|
/// Api响应结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
protected Task<Result> ToApiResult(HttpStatusCode statusCode, string msg)
|
|
{
|
|
Result result = new()
|
|
{
|
|
code = statusCode,
|
|
msg = msg
|
|
};
|
|
return Task.FromResult(result);
|
|
}
|
|
/// <summary>
|
|
/// Api响应结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
protected Task<Result> ToApiResult(HttpStatusCode statusCode, string msg, object data)
|
|
{
|
|
Result result = new()
|
|
{
|
|
code = statusCode,
|
|
msg = msg,
|
|
data = data
|
|
};
|
|
return Task.FromResult(result);
|
|
}
|
|
}
|
|
}
|