Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jyzb_local_platform
概览
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
赵剑炜
jyzb_local_platform
Commits
6c3db362
Commit
6c3db362
authored
Dec 28, 2023
by
Seniorious
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
633f8b75
全部展开
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
92 行增加
和
135 行删除
+92
-135
BaseInfoController.cs
WebApiNET6-master/APIs/Controllers/BaseInfoController.cs
+71
-3
CommonReq.cs
WebApiNET6-master/APIs/Req/CommonReq.cs
+8
-0
Startup.cs
WebApiNET6-master/APIs/Startup.cs
+4
-5
DehumidifierTask.cs
WebApiNET6-master/APIs/TimedTasks/DehumidifierTask.cs
+8
-126
appsettings.json
WebApiNET6-master/APIs/appsettings.json
+1
-1
DehumidifierHelper.cs
WebApiNET6-master/Common/DehumidifierHelper.cs
+0
-0
没有找到文件。
WebApiNET6-master/APIs/Controllers/BaseInfoController.cs
View file @
6c3db362
using
APIs.Common
;
using
APIs.Dto
;
using
APIs.Req
;
using
APIs.TimedTasks
;
using
Autofac.Core
;
using
AutoMapper
;
using
Common
;
...
...
@@ -36,6 +37,8 @@ using static Common.HttpHelper;
using
static
Dm
.
net
.
buffer
.
ByteArrayBuffer
;
using
static
Microsoft
.
AspNetCore
.
Razor
.
Language
.
TagHelperMetadata
;
using
static
System
.
Net
.
Mime
.
MediaTypeNames
;
using
static
JmpDehumidifierLib
.
Dehumidifier
;
using
JmpDehumidifierLib
;
namespace
APIs.Controllers
{
...
...
@@ -44,6 +47,7 @@ namespace APIs.Controllers
public
class
BaseInfoController
:
ControllerBase
{
public
IMapper
Mapper
{
get
;
}
private
readonly
IPoliceService
_policeService
;
private
readonly
IEquipmentTypeService
_equipmentTypeService
;
private
readonly
IEquipmentSizeService
_equipmentSizeService
;
...
...
@@ -64,14 +68,16 @@ namespace APIs.Controllers
private
readonly
IBussinessInventoryService
_bussinessInventoryService
;
private
readonly
IBussinessInventoryDetailService
_bussinessInventoryDetailService
;
private
readonly
IChannelService
_channelService
;
private
readonly
DehumidifierHelper
_dehumidifierHelper
;
public
BaseInfoController
(
IMapper
mapper
,
IPoliceService
policeService
,
IEquipmentTypeService
equipmentTypeService
,
public
BaseInfoController
(
IMapper
mapper
,
DehumidifierHelper
dehumidifierHelper
,
IPoliceService
policeService
,
IEquipmentTypeService
equipmentTypeService
,
IEquipmentSizeService
equipmentSizeService
,
ICarService
carService
,
IInventoryService
inventoryService
,
IInvService
invService
,
IUsersService
usersService
,
ILogService
logService
,
IDevHistoryService
devHistoryService
,
IDevService
devService
,
IWarehouseService
warehouseService
,
IOrderService
orderService
,
ISupplierService
supplierService
,
IThisInfoService
thisInfoService
,
IPrintService
printService
,
IPoliceFingerService
policeFingerService
,
IPoliceInfoService
policeInfoService
,
IBussinessInventoryService
bussinessInventoryService
,
IBussinessInventoryDetailService
bussinessInventoryDetailService
,
IChannelService
channelService
)
{
_dehumidifierHelper
=
dehumidifierHelper
;
_carService
=
carService
;
_equipmentSizeService
=
equipmentSizeService
;
_equipmentTypeService
=
equipmentTypeService
;
...
...
@@ -96,6 +102,68 @@ namespace APIs.Controllers
}
/// <summary>
/// 设定除湿机
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[
HttpPost
]
public
async
Task
<
ApiResult
>
SetDehumidifier
([
FromBody
]
SetDehumidifierReq
req
)
{
try
{
if
(
string
.
IsNullOrEmpty
(
req
.
devId
)
||
req
.
setState
==
null
)
{
return
new
ApiResult
{
code
=
ResultCode
.
OPERATE_FAILED
.
Code
,
msg
=
"参数不正确"
,
};
}
Dev
myDev
=
await
_devService
.
QueryOne
(
s
=>
s
.
id
.
Equals
(
req
.
devId
));
if
(
myDev
!=
null
)
{
if
(!
string
.
IsNullOrEmpty
(
req
.
setHumid
))
{
myDev
.
setSd
=
req
.
setHumid
;
}
if
(
req
.
setState
!=
null
)
{
myDev
.
setState
=
req
.
setState
;
}
myDev
.
updateTime
=
DateTime
.
Now
;
}
else
{
return
new
ApiResult
{
code
=
ResultCode
.
OPERATE_FAILED
.
Code
,
msg
=
"无设备信息"
,
};
}
_dehumidifierHelper
.
SetDehumidifier
(
myDev
);
await
_devService
.
Update
(
myDev
);
return
new
ApiResult
{
code
=
ResultCode
.
OPERATE_SUCCESS
.
Code
,
msg
=
ResultCode
.
OPERATE_SUCCESS
.
Msg
,
};
}
catch
(
Exception
ex
)
{
var
error
=
new
ApiResult
{
code
=
ResultCode
.
OPERATE_FAILED
.
Code
,
msg
=
ex
.
Message
,
};
return
error
;
}
}
/// <summary>
/// 手持机获取盘点单据
/// </summary>
/// <param name="req"></param>
...
...
@@ -152,7 +220,7 @@ namespace APIs.Controllers
detailList
=
rs
.
DetailList
});
var
json
=
HttpHelper
.
HttpPost
(
AdminGlobalContext
.
jyzbConfig
.
Url
+
"BussinessInventory/Start"
,
param
);
var
json
=
HttpHelper
.
HttpPost
(
AdminGlobalContext
.
jyzbConfig
.
Url
+
"
/
BussinessInventory/Start"
,
param
);
if
(
string
.
IsNullOrEmpty
(
json
))
{
await
_bussinessInventoryService
.
OrderRollBack
(
rs
);
...
...
@@ -811,7 +879,7 @@ namespace APIs.Controllers
};
}
else
{
var
json
=
HttpHelper
.
HttpPost
(
AdminGlobalContext
.
jyzbConfig
.
Url
+
"
BussinessInventory/UpdateFinger
"
,
JsonConvert
.
SerializeObject
(
req
));
var
json
=
HttpHelper
.
HttpPost
(
AdminGlobalContext
.
jyzbConfig
.
Url
+
"
/PolicemanFinger/insertOrUpdateFingerInfo
"
,
JsonConvert
.
SerializeObject
(
req
));
var
httprs
=
JsonConvert
.
DeserializeObject
<
HttpHelper
.
res
<
string
>>(
json
);
if
(
httprs
!=
null
&&
httprs
.
code
==
"9920"
)
...
...
WebApiNET6-master/APIs/Req/CommonReq.cs
View file @
6c3db362
...
...
@@ -38,4 +38,11 @@ namespace APIs.Req
public
string
policeId
{
get
;
set
;
}
public
List
<
PoliceFinger
>
fingerList
{
get
;
set
;
}
}
public
class
SetDehumidifierReq
{
public
string
devId
{
get
;
set
;
}
public
int
?
setState
{
get
;
set
;
}
public
string
setHumid
{
get
;
set
;
}
}
}
\ No newline at end of file
WebApiNET6-master/APIs/Startup.cs
View file @
6c3db362
...
...
@@ -21,6 +21,7 @@ using Microsoft.AspNetCore.Mvc;
using
Quartz.Impl
;
using
Quartz
;
using
APIs.TimedTasks
;
using
Common
;
namespace
APIs
{
...
...
@@ -78,6 +79,7 @@ namespace APIs
services
.
AddScoped
<
IBussinessInventoryService
,
BussinessInventoryService
>();
services
.
AddScoped
<
IBussinessInventoryDetailService
,
BussinessInventoryDetailService
>();
services
.
AddScoped
<
IChannelService
,
ChannelService
>();
#
endregion
#
region
Repository
...
...
@@ -112,12 +114,9 @@ namespace APIs
#
endregion
#
region
定时任务
//注册ISchedulerFactory的实例
services
.
AddSingleton
<
ISchedulerFactory
,
StdSchedulerFactory
>();
#
endregion
#
region
后台常驻任务
#
region
除湿机
services
.
AddSingleton
<
IHostedService
,
DehumidifierTask
>();
services
.
AddSingleton
<
DehumidifierHelper
>();
#
endregion
#
region
初始化全局配置信息
...
...
WebApiNET6-master/APIs/TimedTasks/DehumidifierTask.cs
View file @
6c3db362
...
...
@@ -5,157 +5,39 @@ using Services.Interface;
using
JmpDehumidifierLib
;
using
Models.Table
;
using
static
JmpDehumidifierLib
.
Dehumidifier
;
using
Newtonsoft.Json
;
using
Common.Global
;
using
Microsoft.AspNetCore.Mvc.ViewComponents
;
namespace
APIs.TimedTasks
{
public
class
DehumidifierTask
:
IHostedService
{
//private readonly ILogger<DehumidifierTask> _logger;
public
IMapper
Mapper
{
get
;
}
private
readonly
IDevHistoryService
_devHistoryService
;
private
readonly
IDevService
_devService
;
private
readonly
DehumidifierHelper
_dehumidifierHelper
;
public
DehumidifierTask
(
IMapper
mapper
,
IDevHistoryService
devHistoryService
,
IDevService
devService
/*ILogger<DehumidifierTask> logger*/
)
public
DehumidifierTask
(
IMapper
mapper
,
DehumidifierHelper
dehumidifierHelper
)
{
_devHistoryService
=
devHistoryService
;
_devService
=
devService
;
_dehumidifierHelper
=
dehumidifierHelper
;
Mapper
=
mapper
;
//_logger = logger;
}
Dictionary
<
string
,
Dehumidifier
>
devList
=
new
Dictionary
<
string
,
Dehumidifier
>();
public
Task
StartAsync
(
CancellationToken
cancellationToken
)
public
async
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
//_logger.LogInformation("订阅事件开始");
//开启本组织机构下所有除湿机并订阅温湿度变化事件
try
{
List
<
Dev
>?
devs
=
_devService
.
Query
().
Result
;
if
(
devs
!=
null
)
{
devList
=
devs
.
Select
(
s
=>
new
{
Key
=
s
.
devIp
,
Value
=
new
Dehumidifier
(
s
.
devIp
,
Convert
.
ToInt32
(
s
.
devPort
))
})
.
ToDictionary
(
s
=>
s
.
Key
,
s
=>
s
.
Value
);
var
openIpList
=
devs
.
Where
(
s
=>
s
.
setState
==
1
).
Select
(
s
=>
s
.
devIp
).
ToList
();
foreach
(
var
item
in
devList
)
{
if
(
openIpList
.
Contains
(
item
.
Key
))
{
if
(
item
.
Value
.
Open
())
{
try
//避免影响设备温湿度获取
{
var
mySetSd
=
devs
.
FirstOrDefault
(
s
=>
s
.
devIp
.
Equals
(
item
.
Key
))?.
setSd
;
if
(!
string
.
IsNullOrEmpty
(
mySetSd
))
{
item
.
Value
.
SetHumid
((
byte
)
Convert
.
ToInt32
(
mySetSd
));
}
}
catch
(
Exception
ex
)
{
}
item
.
Value
.
OnStatusChanged
+=
new
Dehumidifier
.
StatusChanged
(
OnStatusChanged
);
}
}
else
{
item
.
Value
.
Close
();
}
}
}
_dehumidifierHelper
.
StartDehumidifier
();
}
catch
(
Exception
ex
)
{
//异常处理
}
return
Task
.
CompletedTask
;
}
private
Dictionary
<
string
,
DevHistory
>
DevHistoryDic
=
new
Dictionary
<
string
,
DevHistory
>();
private
async
void
OnStatusChanged
(
MachineStatus
args
)
{
if
(
args
.
ErrorCode
==
0
)
{
var
devIp
=
args
.
ip
;
var
warehouseWd
=
args
.
Temp
.
ToString
();
// 室内温度
var
warehouseSd
=
args
.
Humid
.
ToString
();
// 室内湿度
var
devState
=
args
.
IsWorking
?
1
:
0
;
var
devPort
=
args
.
port
.
ToString
();
var
myDev
=
(
await
_devService
.
Query
()).
FirstOrDefault
(
s
=>
s
.
devIp
.
Equals
(
devIp
));
if
(
myDev
!=
null
)
{
DevHistory
record
=
new
DevHistory
()
{
warehouseId
=
myDev
.
warehouseId
,
devCode
=
myDev
.
devCode
,
devIp
=
devIp
,
devPort
=
devPort
,
devName
=
myDev
.
devName
,
devId
=
myDev
.
id
,
devState
=
devState
,
warehouseSd
=
warehouseSd
,
warehouseWd
=
warehouseWd
,
setSd
=
myDev
.
setSd
,
createTime
=
DateTime
.
Now
,
};
if
(
DevHistoryDic
.
TryGetValue
(
devIp
,
out
DevHistory
thisHistory
))
{
if
(
thisHistory
.
warehouseWd
.
Equals
(
record
.
warehouseWd
)
&&
thisHistory
.
warehouseSd
.
Equals
(
record
.
warehouseSd
)
&&
thisHistory
.
devState
==
record
.
devState
)
{
return
;
}
else
{
DevHistoryDic
[
devIp
]
=
record
;
}
}
else
{
DevHistoryDic
.
Add
(
record
.
devIp
,
record
);
}
await
_devHistoryService
.
Add
(
record
);
myDev
.
updateTime
=
DateTime
.
Now
;
myDev
.
devState
=
devState
;
myDev
.
warehouseSd
=
warehouseSd
;
myDev
.
warehouseWd
=
warehouseWd
;
await
_devService
.
Update
(
myDev
);
}
Thread
.
Sleep
(
10000
);
}
else
{
foreach
(
var
item
in
devList
)
{
if
(
item
.
Key
.
Equals
(
args
.
ip
))
{
Dehumidifier
dev
=
new
Dehumidifier
(
args
.
ip
,
args
.
port
);
devList
.
Remove
(
item
.
Key
);
devList
.
Add
(
args
.
ip
,
dev
);
if
(
dev
.
Open
())
{
dev
.
OnStatusChanged
+=
new
Dehumidifier
.
StatusChanged
(
OnStatusChanged
);
}
}
}
}
}
public
Task
StopAsync
(
CancellationToken
cancellationToken
)
{
//_logger.LogInformation("订阅事件结束");
// TODO: 在这里取消订阅事件
return
Task
.
CompletedTask
;
}
}
...
...
WebApiNET6-master/APIs/appsettings.json
View file @
6c3db362
...
...
@@ -9,7 +9,7 @@
"Launch"
:
"http://*:5233;http://*:5243"
,
"AllowedHosts"
:
"*"
,
"ConnectionStrings"
:
{
"MySQL"
:
"server=192.168.3.128;port=3306;Database=pw;Uid=root;Pwd=123456;"
"MySQL"
:
"server=192.168.3.128;port=3306;Database=pw
1
;Uid=root;Pwd=123456;"
//RabbitMQ配置
},
...
...
WebApiNET6-master/Common/DehumidifierHelper.cs
View file @
6c3db362
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论