baseline: 小军 WMS 二开代码原始快照(含 SynOABusiness.cs Debugger.Break)
This commit is contained in:
commit
c2b0e7be0d
6522 files changed
+3530643
No files matched your search
+40
@@ -0,0 +1,40 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Opsoft.NetCore.O3App.Shared;
|
||||
using Opsoft.NetCore.O3App.WebApi.Models;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Opsoft.NetCore.O3App.WebApi
|
||||
{
|
||||
public sealed class GlobalExceptionFilterAttribute : ExceptionFilterAttribute
|
||||
{
|
||||
public IErrorFormatter ErrorFormatter { get; }
|
||||
public ILogger Logger;
|
||||
|
||||
public GlobalExceptionFilterAttribute(
|
||||
IErrorFormatter errorFormatter,
|
||||
ILogger<GlobalExceptionFilterAttribute> logger)
|
||||
{
|
||||
ErrorFormatter = errorFormatter ?? throw new ArgumentNullException(nameof(errorFormatter));
|
||||
Logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
public override Task OnExceptionAsync(ExceptionContext context)
|
||||
{
|
||||
Console.Error.WriteLine($"系统出现异常:{Environment.NewLine}{ErrorFormatter.Format(context.Exception)}");
|
||||
Logger.Error(context.Exception, ErrorFormatter.Format(context.Exception), context.ActionDescriptor.DisplayName, context.Exception.GetType().Name);
|
||||
var response = new BaseResponse() { Message = $"系统出现异常:{context.Exception.Message},请联系管理员。" };
|
||||
context.Result = new ObjectResult(response)
|
||||
{
|
||||
StatusCode = (int)System.Net.HttpStatusCode.InternalServerError
|
||||
};
|
||||
return HandleExceptionAsync(context);
|
||||
}
|
||||
|
||||
private Task HandleExceptionAsync(ExceptionContext context)
|
||||
{
|
||||
//Place your exception handling operation here.
|
||||
return base.OnExceptionAsync(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace Opsoft.NetCore.O3App.WebApi.Filters
|
||||
{
|
||||
public class IdempotentAttribute : Attribute, IFilterFactory
|
||||
{
|
||||
public bool IsReusable => false;
|
||||
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
|
||||
{
|
||||
var memoryCache = (IMemoryCache)serviceProvider.GetService(typeof(IMemoryCache));
|
||||
var filter = new IdempotentAttributeFilter(memoryCache);
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Newtonsoft.Json;
|
||||
using Opsoft.Data;
|
||||
using Opsoft.NetCore.O3App.Domain.UnitOfWork.WMS.Model;
|
||||
using Opsoft.NetCore.O3App.WebApi.Models;
|
||||
using System;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using StatusCodes = Microsoft.AspNetCore.Http.StatusCodes;
|
||||
|
||||
namespace Opsoft.NetCore.O3App.WebApi.Filters
|
||||
{
|
||||
public class IdempotentAttributeFilter : IActionFilter, IResultFilter, IResourceFilter
|
||||
{
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
private string _idempotentKey;
|
||||
private string _idempotentBillTypeKey;
|
||||
private string _tranType;
|
||||
private string _date;
|
||||
private bool _doCheck = false;
|
||||
private const string IdempotentIpKeyHeaderName = "IdempotencyKey_IP";
|
||||
private const string IdempotentIdKeyHeaderName = "IdempotencyKey_ID";
|
||||
|
||||
public IdempotentAttributeFilter(IMemoryCache memoryCache)
|
||||
{
|
||||
_memoryCache = memoryCache;
|
||||
}
|
||||
|
||||
public void OnResultExecuted(ResultExecutedContext context)
|
||||
{
|
||||
//清除单据处理缓存
|
||||
if (!_idempotentBillTypeKey.IsNullOrEmpty() && _doCheck && _memoryCache.TryGetValue(_idempotentBillTypeKey, out string value))
|
||||
{
|
||||
_memoryCache.Remove(_idempotentBillTypeKey);
|
||||
}
|
||||
//清除唯一幂等
|
||||
if (_doCheck && _memoryCache.TryGetValue(_idempotentKey, out IdempotentCacheData cacheData))
|
||||
{
|
||||
var contextResult = JsonConvert.DeserializeObject<BaseResponse<object>>(JsonConvert.SerializeObject((context.Result as JsonResult).Value));
|
||||
if (cacheData.ProcessStatus == 2)
|
||||
{
|
||||
_memoryCache.Remove(_idempotentKey);
|
||||
}
|
||||
else if (cacheData.ProcessStatus == 1 && contextResult.StatusCode != StatusCodes.Status200OK)
|
||||
{
|
||||
_memoryCache.Remove(_idempotentKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnResultExecuting(ResultExecutingContext context)
|
||||
{
|
||||
if (_doCheck && _memoryCache.TryGetValue(_idempotentKey, out IdempotentCacheData cacheData))
|
||||
{
|
||||
var contextResult = JsonConvert.DeserializeObject<BaseResponse<object>>(JsonConvert.SerializeObject((context.Result as JsonResult).Value));
|
||||
if (cacheData.ProcessStatus == 1 && contextResult.StatusCode == StatusCodes.Status200OK)
|
||||
{
|
||||
cacheData.ProcessStatus = 2;
|
||||
cacheData.Result = contextResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnActionExecuted(ActionExecutedContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
if (context.HttpContext.Request.Headers.TryGetValue(IdempotentIpKeyHeaderName, out StringValues ip)
|
||||
&&
|
||||
context.HttpContext.Request.Headers.TryGetValue(IdempotentIdKeyHeaderName, out StringValues id))
|
||||
{
|
||||
_doCheck = true;
|
||||
_idempotentKey = ip + ":" + id;
|
||||
if (!_memoryCache.TryGetValue(_idempotentKey, out IdempotentCacheData cacheData))
|
||||
{
|
||||
//记录状态
|
||||
cacheData = new IdempotentCacheData
|
||||
{
|
||||
IdempotentKey = _idempotentKey,
|
||||
ProcessStatus = 1,
|
||||
Result = null
|
||||
};
|
||||
|
||||
var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromHours(1));
|
||||
_memoryCache.Set(_idempotentKey, cacheData, cacheEntryOptions);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cacheData.ProcessStatus == 1)
|
||||
{
|
||||
context.Result = new ObjectResult(new BaseResponse<object>
|
||||
{
|
||||
Success = false,
|
||||
StatusCode = StatusCodes.Status102Processing,
|
||||
Message = "提交失败!操作执行中,请勿重复提交!",
|
||||
Data = "提交失败!操作执行中,请勿重复提交!"
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (cacheData.ProcessStatus == 2)
|
||||
{
|
||||
context.Result = new ObjectResult(new BaseResponse<object>
|
||||
{
|
||||
Success = true,
|
||||
StatusCode = StatusCodes.Status200OK,
|
||||
Message = "执行成功!",
|
||||
Data = (cacheData.Result as BaseResponse<object>).Data
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnResourceExecuted(ResourceExecutedContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnResourceExecuting(ResourceExecutingContext context)
|
||||
{
|
||||
//参数获取
|
||||
context.HttpContext.Request.EnableBuffering();
|
||||
context.HttpContext.Request.Body.Position = 0;
|
||||
var reader = new StreamReader(context.HttpContext.Request.Body);
|
||||
string body = reader.ReadToEnd();
|
||||
context.HttpContext.Request.Body.Position = 0;
|
||||
//获取传递的参数
|
||||
InputBarCode<object> inputData = JsonConvert.DeserializeObject<InputBarCode<object>>(body);
|
||||
if (inputData != null)
|
||||
{
|
||||
_tranType = inputData.TranType;
|
||||
_date = inputData.FDate;
|
||||
}
|
||||
if (_date.IsNullOrEmpty())
|
||||
{
|
||||
_date = DateTime.Now.ToString("yyyy/MM/dd");
|
||||
}
|
||||
|
||||
//关帐、月结限制
|
||||
string token = context.HttpContext.Request.Headers["Authorization"].ToStringEx().Substring(7);
|
||||
JwtSecurityToken jwtToken = new JwtSecurityTokenHandler().ReadJwtToken(token);
|
||||
var userId = jwtToken.Claims.First(o => o.Type == ClaimTypes.Name).Value;
|
||||
dynamic temType = JsonConvert.DeserializeObject<dynamic>(jwtToken.Claims.First(o => o.Type == ClaimTypes.UserData).Value);
|
||||
string dbAias = temType.DBaias;
|
||||
using APPServerContext dbContext = new APPServerContext(dbAias, userId);
|
||||
var closeAccountTable = dbContext.Database.SqlQuery(
|
||||
@"SELECT T01.FDATE
|
||||
FROM T_STK_CLOSEACCOUNTENTRY T01
|
||||
LEFT JOIN T_STK_CLOSEACCOUNT T02 ON T01.FINTERID = T02.FINTERID
|
||||
WHERE UPPER(T02.FBILLNO)='STK_CLOSEACCOUNT' AND T01.FBILLTYPE='A'");
|
||||
if (closeAccountTable != null && closeAccountTable.Rows.Count > 0)
|
||||
{
|
||||
if (Convert.ToDateTime(_date).ToString("yyyyMMdd").ToInt() <= Convert.ToDateTime(closeAccountTable.Rows[0]["FDATE"]).ToString("yyyyMMdd").ToInt())
|
||||
{
|
||||
context.Result = new ObjectResult(new BaseResponse<object>
|
||||
{
|
||||
Success = false,
|
||||
StatusCode = StatusCodes.Status403Forbidden,
|
||||
Message = "现已关账,当前单据提交失败!",
|
||||
Data = "现已关账,当前单据提交失败!"
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var settleMonthTable =
|
||||
dbContext.Database.SqlQuery(
|
||||
"SELECT FYEAR,FPERIOD FROM T_GL_CLOSEACCOUNT ORDER BY FYEAR DESC,FPERIOD DESC");
|
||||
if (settleMonthTable != null && settleMonthTable.Rows.Count > 0)
|
||||
{
|
||||
var closeYear = settleMonthTable.Rows[0]["FYEAR"].ToInt32();
|
||||
var closeMonth = settleMonthTable.Rows[0]["FPERIOD"].ToInt32();
|
||||
if (Convert.ToDateTime(_date).Year < closeYear)
|
||||
{
|
||||
context.Result = new ObjectResult(new BaseResponse<object>
|
||||
{
|
||||
Success = false,
|
||||
StatusCode = StatusCodes.Status403Forbidden,
|
||||
Message = "已月结,当前单据提交失败!",
|
||||
Data = "已月结,当前单据提交失败!"
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (Convert.ToDateTime(_date).Year == closeYear)
|
||||
{
|
||||
if (Convert.ToDateTime(_date).Month <= closeMonth)
|
||||
{
|
||||
context.Result = new ObjectResult(new BaseResponse<object>
|
||||
{
|
||||
Success = false,
|
||||
StatusCode = StatusCodes.Status403Forbidden,
|
||||
Message = "已月结,当前单据提交失败!",
|
||||
Data = "已月结,当前单据提交失败!"
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (context.HttpContext.Request.Headers.TryGetValue(IdempotentIpKeyHeaderName, out StringValues ip)
|
||||
&&
|
||||
context.HttpContext.Request.Headers.TryGetValue(IdempotentIdKeyHeaderName, out StringValues id))
|
||||
{
|
||||
_idempotentBillTypeKey = ip + ":" + _tranType;
|
||||
|
||||
//判断是否重复提交
|
||||
if (_memoryCache.TryGetValue(_idempotentBillTypeKey, out string value))
|
||||
{
|
||||
context.Result = new ObjectResult(new BaseResponse<object>
|
||||
{
|
||||
Success = false,
|
||||
StatusCode = StatusCodes.Status102Processing,
|
||||
Message = "提交失败!当前设备有未处理完成的当前单据,请勿重复提交!",
|
||||
Data = "提交失败!当前设备有未处理完成的当前单据,请勿重复提交!"
|
||||
});
|
||||
return;
|
||||
}
|
||||
_memoryCache.Set(_idempotentBillTypeKey, _idempotentBillTypeKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Opsoft.NetCore.O3App.WebApi
|
||||
{
|
||||
public class ResultConvertFilterAttribute : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuted(ActionExecutedContext context)
|
||||
{
|
||||
if (context.Result is ObjectResult)
|
||||
{
|
||||
context.Result = new JsonResult((context.Result as ObjectResult).Value);
|
||||
}
|
||||
base.OnActionExecuted(context);
|
||||
}
|
||||
public override void OnResultExecuting(ResultExecutingContext context)
|
||||
{
|
||||
if (context.Result is ObjectResult)
|
||||
{
|
||||
context.Result = new JsonResult((context.Result as ObjectResult).Value);
|
||||
}
|
||||
base.OnResultExecuting(context);
|
||||
}
|
||||
public override Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
|
||||
{
|
||||
if (context.Result is ObjectResult)
|
||||
{
|
||||
context.Result = new JsonResult((context.Result as ObjectResult).Value);
|
||||
}
|
||||
return base.OnResultExecutionAsync(context, next);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user