Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
JunmpPoliceStation
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Members
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
zxw
JunmpPoliceStation
Commits
99a8e7a9
Commit
99a8e7a9
authored
Dec 07, 2022
by
zxw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
12-07部署
parent
63b28915
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
154 行增加
和
23 行删除
+154
-23
ResultCode.cs
JmpCommon/ResultCode.cs
+1
-0
ActionLimitAttribute.cs
JunmpPoliceStation/App_Start/ActionLimitAttribute.cs
+134
-0
AuthLoginAttribute.cs
JunmpPoliceStation/App_Start/AuthLoginAttribute.cs
+0
-19
BorrowController.cs
JunmpPoliceStation/Controllers/BorrowController.cs
+1
-0
TjController.cs
JunmpPoliceStation/Controllers/TjController.cs
+16
-4
Startup.cs
JunmpPoliceStation/Startup.cs
+2
-0
没有找到文件。
JmpCommon/ResultCode.cs
View file @
99a8e7a9
...
...
@@ -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>
...
...
JunmpPoliceStation/App_Start/ActionLimitAttribute.cs
0 → 100644
View file @
99a8e7a9
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
);
}
}
}
JunmpPoliceStation/App_Start/AuthLoginAttribute.cs
View file @
99a8e7a9
...
...
@@ -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
{
...
...
JunmpPoliceStation/Controllers/BorrowController.cs
View file @
99a8e7a9
...
...
@@ -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
,
...
...
JunmpPoliceStation/Controllers/TjController.cs
View file @
99a8e7a9
...
...
@@ -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
...
...
JunmpPoliceStation/Startup.cs
View file @
99a8e7a9
...
...
@@ -155,6 +155,8 @@ namespace JunmpPoliceStation
options
.
KnownNetworks
.
Clear
();
options
.
KnownProxies
.
Clear
();
});
services
.
AddScoped
<
ActionLimitAttribute
>();
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论