Commit 99a8e7a9 by zxw

12-07部署

parent 63b28915
......@@ -66,6 +66,7 @@ namespace JmpCommon
public static ResultInfo MISSION_ERROR = new ResultInfo { Code = "10047", Msg = "该单据正在任务中或已有物资出入库" };
public static ResultInfo MISSION_EXIST = new ResultInfo { Code = "10048", Msg = "存在进行中的任务" };
public static ResultInfo ORDER_START = new ResultInfo { Code = "10049", Msg = "物资与单据状态不匹配" };
public static ResultInfo ACTION_LIMIT = new ResultInfo { Code = "10050", Msg = "接口访问次数上限,请稍后再试" };
}
/// <summary>
......
using Google.Protobuf.WellKnownTypes;
using JmpCommon;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace JunmpPoliceStation.App_Start
{
public class ActionLimitAttribute : ActionFilterAttribute
{
private ILogger<ActionLimitAttribute> _logger;
public static MemoryCache _cache = new MemoryCache(new MemoryCacheOptions());
public ActionLimitAttribute(ILogger<ActionLimitAttribute> logger)
{
_logger = logger;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
try
{
//获取访问ip
var userHostAddress = filterContext.HttpContext.Connection.RemoteIpAddress?.MapToIPv4().ToString();
if (!string.IsNullOrEmpty(userHostAddress) && IsIP(userHostAddress))
{
//有效ip
var url = filterContext.ActionDescriptor.RouteValues["controller"] + "/" + filterContext.ActionDescriptor.RouteValues["action"];
_logger.LogDebug("获取访问ip:" + userHostAddress + "地址:api/" + url);
if (userHostAddress == "127.0.0.1")
{
//本地ip过滤
return;
}
var key = userHostAddress + url;
if (Exists(key))
{
int value = int.Parse(Get(key).ToString() ?? string.Empty);
if (value > 25) //每分钟上限访问25次
{
filterContext.Result = new JsonResult(ResultCode.ACTION_LIMIT);
return;
}
else
{
value += 1;
}
AddMemoryCache(key, value);
}
else
{
AddMemoryCache(key, 1);
}
}
}
catch (Exception e)
{
_logger.LogError("ActionLimitAttribute 错误:" + e.ToString());
filterContext.Result = new JsonResult(e.ToString());
}
}
/// <summary>
/// 检查IP地址格式
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
private static bool IsIP(string ip)
{
return System.Text.RegularExpressions.Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
}
/// <summary>
/// 验证缓存项是否存在
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
public static bool Exists(string key)
{
if (key == null)
{
return false;
}
return _cache.TryGetValue(key, out _);
}
/// <summary>
/// 获取缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static object Get(string key)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
if (!Exists(key))
throw new ArgumentNullException(nameof(key));
return _cache.Get(key);
}
/// <summary>
/// 添加缓存
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static bool AddMemoryCache(string key, object value)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
DateTimeOffset time = DateTimeOffset.Now.AddMinutes(1); //一分钟后过期
_cache.Set(key, value, time);
return Exists(key);
}
}
}
......@@ -67,14 +67,6 @@ namespace JunmpPoliceStation.App_Start
public override void OnActionExecuting(ActionExecutingContext context)
{
//获取访问ip
var userHostAddress = context.HttpContext.Connection.RemoteIpAddress?.MapToIPv4().ToString();
if (!string.IsNullOrEmpty(userHostAddress) && IsIP(userHostAddress))
{
//有效ip
_logger.LogDebug("获取访问ip:" + userHostAddress);
}
if (bool.TryParse(Configuration.GetSection("Auth:NoSign").Value, out bool noSignFlag) && noSignFlag)
{
return;
......@@ -200,17 +192,6 @@ namespace JunmpPoliceStation.App_Start
context.Result = new JsonResult(ex.ToString());
}
}
/// <summary>
/// 检查IP地址格式
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
private static bool IsIP(string ip)
{
return System.Text.RegularExpressions.Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
}
}
public class PlaInfo
{
......
......@@ -2022,6 +2022,7 @@ namespace JunmpPoliceStation.Controllers
policeName = t.Police?.Name,
processActionType = t.ProcessCurrent?.ActionType,
fileUrl = t.FileUrl,
isBindCabinet = t.IsBindCabinet,
historyList = t.ProcessCurrent?.CommonJpProcessHistories?.Select(x => new
{
x.Id,
......
......@@ -791,7 +791,7 @@ namespace JunmpPoliceStation.Controllers
};
Expression<Func<CommonJpEquipmentInventory, bool>> expression = t => OrgId==t.OrgId && (!t.InventoryState.Equals("loss"));
Expression<Func<CommonJpEquipmentInventory, bool>> expression = t => OrgId == t.OrgId && (!t.InventoryState.Equals("loss"));
//装备名称
if (!String.IsNullOrEmpty(entity.equipmentCode))
......@@ -806,7 +806,7 @@ namespace JunmpPoliceStation.Controllers
equipmentCode = c.Key,
equipmentName = c.FirstOrDefault().EquipmentCodeNavigation.Name,
sumCount = c.Count(),
syCount =c.Sum(c=>c.Org.BaseJpCabinetOutinlogs.Where(p=>p.State=="out" && p.OperationTime >= Convert.ToDateTime(startTime) && p.OperationTime <= Convert.ToDateTime(endTime)).Count())+ c.Sum(c => c.CommonJpEquipmentStates.Where(f => (f.ActionState.Equals(2) || f.ActionState.Equals(3) || f.ActionState.Equals(5) || f.ActionState.Equals(14) || f.ActionState.Equals(15)) && f.OutTime >= Convert.ToDateTime(startTime) && f.OutTime <= Convert.ToDateTime(endTime)).Count()),
syCount = c.Sum(c => c.Org.BaseJpCabinetOutinlogs.Where(p => p.State == "out" && p.OperationTime >= Convert.ToDateTime(startTime) && p.OperationTime <= Convert.ToDateTime(endTime)).Count()) + c.Sum(c => c.CommonJpEquipmentStates.Where(f => (f.ActionState.Equals(2) || f.ActionState.Equals(3) || f.ActionState.Equals(5) || f.ActionState.Equals(14) || f.ActionState.Equals(15)) && f.OutTime >= Convert.ToDateTime(startTime) && f.OutTime <= Convert.ToDateTime(endTime)).Count()),
wxCount = c.Sum(c => c.CommonJpEquipmentStates.Where(f => f.ActionState.Equals(6) && f.OutTime >= Convert.ToDateTime(startTime) && f.OutTime <= Convert.ToDateTime(endTime)).Count())
}).OrderByDescending(f => f.syCount).ToList();
......@@ -1008,16 +1008,28 @@ namespace JunmpPoliceStation.Controllers
int newpage = page * size;
int newsize = size;
List<useCountResult> data = _unitOfWork.ViewEquipmentRepository.Exec_UseCount(" EXEC useCount @orgid ='" + OrgId + "',@startTime ='" + startTime + "'" +
",@endTime ='" + endTime + "'"+ ",@eqcode ='" + equipmentCode + "'" + ",@newspage ='" + newpage + "'" + ",@pageSize ='" + newsize + "'").ToList();
",@endTime ='" + endTime + "'" + ",@eqcode ='" + equipmentCode + "'" + ",@newspage ='" + newpage + "'" + ",@pageSize ='" + newsize + "'").ToList();
//var x= data[0].result.ToString();
//JsonData requestData = JsonMapper.ToObject(x);
var res=JsonConvert.DeserializeObject(data[0].result.ToString());
var res = JsonConvert.DeserializeObject(data[0]?.result?.ToString() ?? string.Empty);
//var content = new
//{
// totalElements = data.Count(),
// content = data.Skip(page * size).Take(size).ToList()
//};
if (res == null)
{
res = new List<object>()
{
new
{
totalElements = 0,
content = new List<object>()
}
};
}
return JsonManager.ReturnSuccessResponse(res);
}
else
......
......@@ -155,6 +155,8 @@ namespace JunmpPoliceStation
options.KnownNetworks.Clear();
options.KnownProxies.Clear();
});
services.AddScoped<ActionLimitAttribute>();
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论