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
d28e370a
Commit
d28e370a
authored
Mar 21, 2023
by
zxw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复装备统计内部装备数量查询错误
parent
765538cf
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
210 行增加
和
92 行删除
+210
-92
ActionLimitAttribute.cs
JunmpPoliceStation/App_Start/ActionLimitAttribute.cs
+7
-65
BorrowController.cs
JunmpPoliceStation/Controllers/BorrowController.cs
+1
-1
InventoryController.cs
JunmpPoliceStation/Controllers/InventoryController.cs
+18
-9
OrganizationController.cs
JunmpPoliceStation/Controllers/OrganizationController.cs
+3
-0
TjController.cs
JunmpPoliceStation/Controllers/TjController.cs
+34
-17
MemoryCacheHelper.cs
JunmpPoliceStation/Extensions/MemoryCacheHelper.cs
+147
-0
没有找到文件。
JunmpPoliceStation/App_Start/ActionLimitAttribute.cs
View file @
d28e370a
using
Google.Protobuf.WellKnownTypes
;
using
J
mpCommon
;
using
JmpCommon
;
using
J
unmpPoliceStation.Extensions
;
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
;
...
...
@@ -38,9 +34,9 @@ namespace JunmpPoliceStation.App_Start
}
var
key
=
userHostAddress
+
url
;
if
(
Exists
(
key
))
if
(
MemoryCacheHelper
.
Exists
(
key
))
{
int
value
=
int
.
Parse
(
Get
(
key
).
ToString
()
??
string
.
Empty
);
int
value
=
int
.
Parse
(
MemoryCacheHelper
.
Get
(
key
).
ToString
()
??
string
.
Empty
);
if
(
value
>
25
)
//每分钟上限访问25次
{
filterContext
.
Result
=
new
JsonResult
(
ResultCode
.
ACTION_LIMIT
);
...
...
@@ -50,11 +46,11 @@ namespace JunmpPoliceStation.App_Start
{
value
+=
1
;
}
AddMemoryCache
(
key
,
value
);
MemoryCacheHelper
.
AddMemoryCache
(
key
,
value
);
}
else
{
AddMemoryCache
(
key
,
1
);
MemoryCacheHelper
.
AddMemoryCache
(
key
,
1
);
}
}
}
...
...
@@ -76,59 +72,5 @@ namespace JunmpPoliceStation.App_Start
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/Controllers/BorrowController.cs
View file @
d28e370a
...
...
@@ -732,7 +732,7 @@ namespace JunmpPoliceStation.Controllers
/// "detailList": [
/// {
/// "quantity": 1,
/// "equipmentId": "b9f83e07-a559-45d9-869f-22fbc777723c",
/// "equipment
Detail
Id": "b9f83e07-a559-45d9-869f-22fbc777723c",
/// }]
/// }
/// </remarks>
...
...
JunmpPoliceStation/Controllers/InventoryController.cs
View file @
d28e370a
...
...
@@ -8391,11 +8391,11 @@ namespace JunmpPoliceStation.Controllers
List
<
ViewEquipment
>
equipmentList
=
_unitOfWork
.
ViewEquipmentRepository
.
GetList
(
expressionPoliceman
).
OrderBy
(
c
=>
c
.
FindCode
.
Length
).
ToList
();
var
data
=
equipmentList
.
GroupBy
(
t
=>
new
{
t
.
WarehouseCode
,
t
.
EquipmentSizecode
}).
Select
(
c
=>
new
var
data
=
equipmentList
.
GroupBy
(
t
=>
new
{
t
.
OrgId
,
t
.
WarehouseCode
,
t
.
EquipmentSizecode
}).
Select
(
c
=>
new
{
c
.
FirstOrDefault
().
OrgId
,
c
.
FirstOrDefault
().
WarehouseCode
,
c
.
FirstOrDefault
().
WarehouseName
,
WarehouseCode
=
c
.
FirstOrDefault
(
x
=>
x
.
WarehouseCode
!=
null
)?.
WarehouseCode
??
"00000000-0000-0000-0000-000000000000"
,
WarehouseName
=
c
.
FirstOrDefault
(
x
=>
x
.
WarehouseCode
!=
null
)?.
WarehouseName
??
""
,
c
.
FirstOrDefault
().
EquipmentCode
,
c
.
FirstOrDefault
().
EquipmentName
,
c
.
FirstOrDefault
().
EquipmentSizecode
,
...
...
@@ -8404,7 +8404,7 @@ namespace JunmpPoliceStation.Controllers
zkCount
=
c
.
Where
(
f
=>
f
.
CurrentState
.
Equals
(
0
)
||
f
.
CurrentState
.
Equals
(
3
)).
Count
(),
ckCount
=
c
.
Where
(
f
=>
!(
f
.
CurrentState
==
null
||
f
.
CurrentState
.
Equals
(
0
)
||
f
.
CurrentState
.
Equals
(
3
)
||
f
.
CurrentState
.
Equals
(
6
))).
Count
(),
bfCount
=
c
.
Where
(
f
=>
f
.
CurrentState
.
Equals
(
6
)).
Count
()
}).
Where
(
c
=>
c
.
WarehouseCode
!=
null
).
ToList
();
}).
Where
(
c
=>
c
.
OrgId
!=
null
).
ToList
();
return
JsonManager
.
ReturnSuccessResponse
(
data
);
}
else
...
...
@@ -8839,21 +8839,30 @@ namespace JunmpPoliceStation.Controllers
"EquipmentSizecodeNavigation"
,
"EquipmentCodeNavigation"
,
"WarehouseCodeNavigation"
,
"
WarehouseCodeNavigation.Orgization
"
,
"
Org
"
,
"CommonJpEquipmentStates"
,
"SupplierCodeNavigation"
,
"Cabinet"
,
"Shelf"
};
Expression
<
Func
<
CommonJpEquipmentInventory
,
bool
>>
expression
=
t
=>
OrgId
.
Equals
(
t
.
WarehouseCodeNavigation
.
Orgization
Id
);
Expression
<
Func
<
CommonJpEquipmentInventory
,
bool
>>
expression
=
t
=>
OrgId
.
Equals
(
t
.
Org
Id
);
expression
=
LambdaExtensions
.
AndAlso
(
expression
,
t
=>
t
.
InventoryState
!=
"loss"
);
//orgList.Add(orgInfo.Id);//查询所有组织机构仓库库存信息
if
(!
String
.
IsNullOrEmpty
(
entity
.
warehouseId
))
{
string
warehouseId
=
entity
.
warehouseId
;
expression
=
LambdaExtensions
.
AndAlso
(
expression
,
t
=>
t
.
WarehouseCode
.
Equals
(
warehouseId
));
if
(
warehouseId
==
"00000000-0000-0000-0000-000000000000"
)
{
//无归属仓库
expression
=
LambdaExtensions
.
AndAlso
(
expression
,
t
=>
string
.
IsNullOrEmpty
(
t
.
WarehouseCode
));
}
else
{
expression
=
LambdaExtensions
.
AndAlso
(
expression
,
t
=>
t
.
WarehouseCode
.
Equals
(
warehouseId
));
}
}
//装备型号
...
...
@@ -8923,8 +8932,8 @@ namespace JunmpPoliceStation.Controllers
equipment
.
EquipmentCode
,
warehouseName
=
equipment
.
WarehouseCodeNavigation
?.
Name
,
equipment
.
WarehouseCode
,
equipment
.
WarehouseCodeNavigation
?.
Orgization
?
.
Name
,
equipment
.
WarehouseCodeNavigation
?.
Orgization
Id
,
equipment
.
Org
.
Name
,
equipment
.
Org
Id
,
supplierName
=
equipment
.
SupplierCodeNavigation
?.
Name
,
equipment
.
SupplierCode
,
cabinetID
=
equipment
.
Cabinet
?.
Id
,
...
...
JunmpPoliceStation/Controllers/OrganizationController.cs
View file @
d28e370a
...
...
@@ -19,6 +19,7 @@ using JmpCommon.Tools;
using
System.Configuration
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
JunmpPoliceStation.Extensions
;
namespace
JunmpPoliceStation.Controllers
{
...
...
@@ -879,6 +880,8 @@ namespace JunmpPoliceStation.Controllers
if
(
result
)
{
//清除组织机构缓存
MemoryCacheHelper
.
RemoveMemoryCache
(
"orgModelList"
);
return
JsonManager
.
SimpleStatusResponse
(
ResultCode
.
OPERATE_SUCCESS
);
}
else
...
...
JunmpPoliceStation/Controllers/TjController.cs
View file @
d28e370a
...
...
@@ -20,6 +20,7 @@ using System.Net.WebSockets;
using
System.Threading.Tasks
;
using
Microsoft.EntityFrameworkCore.Internal
;
using
JmpModel.TempModel
;
using
JunmpPoliceStation.Extensions
;
namespace
JunmpPoliceStation.Controllers
{
...
...
@@ -590,23 +591,40 @@ namespace JunmpPoliceStation.Controllers
size
=
10
;
}
Expression
<
Func
<
BaseJpOrganization
,
bool
>>
expression
=
t
=>
t
.
State
==
1
;
ListEq
=
_unitOfWork
.
OrganizationRepository
.
GetList
(
expression
,
t
=>
t
.
Code
).
ToList
();
string
orgizationCode
=
Guid
.
Empty
.
ToString
();
List
<
BaseJpOrganization
>
dataList
=
null
;
if
(!
String
.
IsNullOrEmpty
(
entity
.
orgId
))
string
orgId
=
entity
.
orgId
;
if
(
string
.
IsNullOrEmpty
(
orgId
))
{
orgizationCode
=
entity
.
orgId
;
return
JsonManager
.
SimpleCustResponse
(
$"orgId is require"
);
}
var
org
=
_unitOfWork
.
DbContext
.
BaseJpOrganizations
.
FirstOrDefault
(
x
=>
x
.
Id
==
orgId
);
if
(
org
==
null
)
{
return
JsonManager
.
SimpleCustResponse
(
$"orgId is require"
);
}
var
findcode
=
ListEq
.
Where
(
c
=>
c
.
Id
.
Equals
(
orgizationCode
)).
FirstOrDefault
().
FindCode
;
var
orgModelList
=
new
List
<
OrgTreeModel
>();
if
(
MemoryCacheHelper
.
Exists
(
"orgModelList"
))
{
orgModelList
=
(
List
<
OrgTreeModel
>)
MemoryCacheHelper
.
Get
(
"orgModelList"
);
}
else
{
orgModelList
=
_unitOfWork
.
OrganizationRepository
.
Entities
.
Select
(
x
=>
new
OrgTreeModel
{
Id
=
x
.
Id
,
State
=
x
.
State
==
1
,
Name
=
x
.
Name
,
Code
=
x
.
Code
,
ParentId
=
x
.
ParentId
})
.
ToList
();
dataList
=
GetClassID
(
orgizationCode
);
//默认过期时间1天
MemoryCacheHelper
.
AddMemoryCache
(
"orgModelList"
,
orgModelList
,
1440
);
}
dataList
=
dataList
.
ToList
().
Concat
(
ListEq
.
Where
(
c
=>
c
.
Id
.
Equals
(
orgizationCode
))).
ToList
();
Expression
<
Func
<
ViewEquipment
,
bool
>>
expressionPoliceman
=
null
;
...
...
@@ -614,9 +632,8 @@ namespace JunmpPoliceStation.Controllers
string
equipmentCode
=
entity
.
equipmentCode
;
string
equipmentSizecode
=
entity
.
equipmentSizecode
;
List
<
string
>
IdList
=
dataList
.
Select
(
c
=>
c
.
Id
).
ToList
();
expressionPoliceman
=
t
=>
IdList
.
Contains
(
t
.
OrgId
);
var
idList
=
OrgTreeModel
.
GetOrgIdList
(
orgModelList
,
org
.
Id
);
expressionPoliceman
=
t
=>
idList
.
Contains
(
t
.
OrgId
);
if
(!
String
.
IsNullOrEmpty
(
typeId
))
{
...
...
@@ -635,7 +652,7 @@ namespace JunmpPoliceStation.Controllers
List
<
ViewEquipment
>
equipmentList
=
_unitOfWork
.
ViewEquipmentRepository
.
GetList
(
expressionPoliceman
).
OrderBy
(
c
=>
c
.
FindCode
.
Length
).
ToList
();
if
(
findc
ode
.
Length
==
6
)
if
(
org
.
FindC
ode
.
Length
==
6
)
{
var
data
=
equipmentList
.
GroupBy
(
t
=>
t
.
OrgName
).
Select
(
c
=>
new
{
...
...
@@ -679,7 +696,7 @@ namespace JunmpPoliceStation.Controllers
}
else
{
var
codeLen
=
findc
ode
.
Length
+
2
;
var
codeLen
=
org
.
FindC
ode
.
Length
+
2
;
var
data
=
equipmentList
.
GroupBy
(
t
=>
t
.
FindCode
.
PadLeft
(
codeLen
,
'0'
).
Substring
(
0
,
codeLen
)).
Select
(
c
=>
new
{
OrgName
=
c
.
OrderBy
(
f
=>
f
.
OrgCode
).
FirstOrDefault
().
AreaName
,
...
...
JunmpPoliceStation/Extensions/MemoryCacheHelper.cs
0 → 100644
View file @
d28e370a
using
Microsoft.Extensions.Caching.Distributed
;
using
Microsoft.Extensions.Caching.Memory
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
JmpModel.Model
;
namespace
JunmpPoliceStation.Extensions
{
public
class
MemoryCacheHelper
{
public
static
MemoryCache
_cache
=
new
MemoryCache
(
new
MemoryCacheOptions
());
/// <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
,
int
minutes
=
1
)
{
if
(
key
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
key
));
}
if
(
value
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
value
));
}
DateTimeOffset
time
=
DateTimeOffset
.
Now
.
AddMinutes
(
minutes
);
//一分钟后过期
_cache
.
Set
(
key
,
value
,
time
);
return
Exists
(
key
);
}
/// <summary>
/// 添加缓存
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public
static
bool
RemoveMemoryCache
(
string
key
)
{
if
(
key
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
key
));
}
_cache
.
Remove
(
key
);
return
!
Exists
(
key
);
}
}
public
class
OrgTreeModel
{
public
OrgTreeModel
()
{
Children
=
new
List
<
OrgTreeModel
>();
}
public
string
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
string
Code
{
get
;
set
;
}
public
bool
State
{
get
;
set
;
}
public
string
ParentId
{
get
;
set
;
}
public
List
<
OrgTreeModel
>
Children
{
get
;
set
;
}
/// <summary>
/// 获取组织机构本级及下级idList
/// </summary>
/// <param name="allList"></param>
/// <returns></returns>
public
static
List
<
string
>
GetOrgIdList
(
List
<
OrgTreeModel
>
allList
,
string
id
)
{
var
top
=
allList
.
FirstOrDefault
(
x
=>
x
.
Id
==
id
);
if
(
top
==
null
)
{
return
new
List
<
string
>();
}
var
strList
=
new
List
<
string
>();
if
(
top
.
State
)
{
strList
.
Add
(
top
.
Id
);
}
TraversalOrgTree
(
allList
,
allList
.
Where
(
x
=>
x
.
ParentId
==
top
.
Id
).
ToList
(),
ref
strList
);
return
strList
;
}
/// <summary>
/// 遍历
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
private
static
void
TraversalOrgTree
(
List
<
OrgTreeModel
>
allList
,
List
<
OrgTreeModel
>
list
,
ref
List
<
string
>
strList
)
{
if
(
list
.
Count
==
0
)
{
return
;
}
foreach
(
var
org
in
list
)
{
if
(
org
.
State
)
{
strList
.
Add
(
org
.
Id
);
}
TraversalOrgTree
(
allList
,
allList
.
Where
(
x
=>
x
.
ParentId
==
org
.
Id
).
ToList
(),
ref
strList
);
}
return
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论