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 个修改的文件
包含
249 行增加
和
303 行删除
+249
-303
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
+157
-168
没有找到文件。
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
using
AutoMapper
;
using
Common.Global
;
using
JmpDehumidifierLib
;
using
LitJson
;
using
Models.Table
;
using
Services
;
using
Newtonsoft.Json
;
using
Services.Interface
;
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Data
;
using
System.Diagnostics
;
using
System.IO
;
using
System.Linq
;
using
System.Management
;
using
System.Net
;
using
System.ServiceProcess
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
Common
...
...
@@ -28,27 +19,31 @@ namespace Common
private
readonly
IDevHistoryService
_devHistoryService
;
private
readonly
IDevService
_devService
;
public
DehumidifierHelper
(
IMapper
mapper
,
IDevHistoryService
devHistoryService
,
IDevService
devService
)
public
DehumidifierHelper
(
IMapper
mapper
,
IDevHistoryService
devHistoryService
,
IDevService
devService
)
{
_devHistoryService
=
devHistoryService
;
_devService
=
devService
;
Mapper
=
mapper
;
}
Dictionary
<
string
,
Dehumidifier
>
devList
=
new
Dictionary
<
string
,
Dehumidifier
>();
private
Dictionary
<
string
,
Dehumidifier
>
devList
=
new
Dictionary
<
string
,
Dehumidifier
>();
private
Dictionary
<
string
,
int
?>
devStateDic
=
new
Dictionary
<
string
,
int
?>();
//当前状态字典
public
async
void
OnStart
()
public
async
void
StartDehumidifier
()
{
try
{
List
<
Dev
>?
devs
=
await
_devService
.
Query
();
if
(
devs
!=
null
)
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
.
devState
==
1
).
Select
(
s
=>
s
.
devIp
).
ToList
();
devStateDic
=
devs
.
Select
(
s
=>
new
{
Key
=
s
.
devIp
,
Value
=
s
.
setState
})
.
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
)
{
...
...
@@ -56,7 +51,18 @@ namespace Common
{
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
);
//item.Value.OnStatusChanged += OnStatusChanged;
}
}
else
...
...
@@ -65,7 +71,6 @@ namespace Common
}
}
}
}
catch
(
Exception
ex
)
{
...
...
@@ -73,202 +78,186 @@ namespace Common
}
}
//
控制设备
p
rivate
void
ContorlDev
(
int
isOpen
,
int
Humid
,
string
devIp
=
""
)
//
设定除湿机
p
ublic
void
SetDehumidifier
(
Dev
myDev
)
{
try
{
if
(
string
.
IsNullOrEmpty
(
devIp
))
if
(
devStateDic
.
TryGetValue
(
myDev
.
devIp
,
out
int
?
nowState
))
{
foreach
(
var
item
in
devList
)
if
(!
devList
.
ContainsKey
(
myDev
.
devIp
)
)
{
item
.
Value
.
SetHumid
((
byte
)
Humid
);
//设定湿度
devList
.
Add
(
myDev
.
devIp
,
new
Dehumidifier
(
myDev
.
devIp
,
Convert
.
ToInt32
(
myDev
.
devPort
)));
}
if
(
isOpen
==
1
)
if
(
nowState
!=
myDev
.
setState
)
{
if
(
myDev
.
setState
==
0
)
{
item
.
Value
.
OpenMachine
(
true
);
devList
[
myDev
.
devIp
].
OnStatusChanged
-=
new
Dehumidifier
.
StatusChanged
(
OnStatusChanged
);
devList
[
myDev
.
devIp
].
Close
();
}
if
(
isOpen
==
0
)
else
if
(
myDev
.
setState
==
1
)
{
item
.
Value
.
OpenMachine
(
false
);
if
(
devList
[
myDev
.
devIp
].
Open
())
{
//设置湿度
if
(!
string
.
IsNullOrEmpty
(
myDev
.
setSd
)
||
myDev
.
setSd
==
"0"
)
{
try
{
devList
[
myDev
.
devIp
].
SetHumid
((
byte
)
Convert
.
ToInt32
(
myDev
.
setSd
));
}
catch
(
Exception
ex
)
{
}
}
devList
[
myDev
.
devIp
].
OnStatusChanged
+=
new
Dehumidifier
.
StatusChanged
(
OnStatusChanged
);
//item.Value.OnStatusChanged += OnStatusChanged;
}
}
}
}
else
{
if
(
devList
.
TryGetValue
(
devIp
,
out
Dehumidifier
dehumidifier
))
else
if
(
nowState
==
1
)
{
dehumidifier
.
SetHumid
((
byte
)
Humid
);
//设定湿度
if
(
isOpen
==
1
)
{
dehumidifier
.
OpenMachine
(
true
);
}
if
(
isOpen
==
0
)
{
dehumidifier
.
OpenMachine
(
false
);
}
devList
[
myDev
.
devIp
].
SetHumid
((
byte
)
Convert
.
ToInt32
(
myDev
.
setSd
));
}
}
}
catch
(
Exception
ex
)
{
}
}
private
Dictionary
<
string
,
DevHistory
>
DevHistoryDic
=
new
Dictionary
<
string
,
DevHistory
>();
private
async
void
OnStatusChanged
(
MachineStatus
args
)
{
if
(
args
.
ErrorCode
==
0
)
try
{
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
();
//string data = "{'devCode':'" + devCode + "','devIp':'" + devIp + "','warehouseWd':'" + warehouseWd + "','warehouseSd':'" + warehouseSd + "','devState':'" + devState + "'}";
//保存数据
var
myDev
=
(
await
_devService
.
Query
()).
FirstOrDefault
(
s
=>
s
.
devIp
.
Equals
(
devIp
));
if
(
myDev
!=
null
)
if
(
args
.
ErrorCode
==
0
)
{
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
,
};
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
();
await
_devHistoryService
.
Add
(
record
);
}
}
else
{
foreach
(
var
item
in
devList
)
{
if
(
item
.
Key
.
Equals
(
args
.
ip
))
var
myDev
=
(
await
_devService
.
Query
()).
FirstOrDefault
(
s
=>
s
.
devIp
.
Equals
(
devIp
));
if
(
myDev
!=
null
)
{
Dehumidifier
dev
=
new
Dehumidifier
(
args
.
ip
,
args
.
port
);
devList
.
Remove
(
item
.
Key
);
devList
.
Add
(
args
.
ip
,
dev
);
if
(
dev
.
Open
())
DevHistory
record
=
new
DevHistory
()
{
dev
.
OnStatusChanged
+=
new
Dehumidifier
.
StatusChanged
(
OnStatusChanged
);
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
(
devStateDic
.
TryGetValue
(
devIp
,
out
int
?
nowState
))
{
if
(
nowState
!=
devState
)
{
//上报除湿机的状态变更 并更新字典
var
param
=
JsonConvert
.
SerializeObject
(
new
{
devName
=
record
.
devName
,
warehouseId
=
record
.
warehouseId
,
devId
=
record
.
devId
,
state
=
devState
,
});
HttpHelper
.
HttpPost
(
AdminGlobalContext
.
jyzbConfig
.
Url
+
""
,
param
);
devStateDic
[
devIp
]
=
devState
;
}
}
}
}
}
}
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
);
}
public
static
string
GetMacAddress
()
{
try
{
string
mac
=
""
;
ManagementClass
mc
=
new
ManagementClass
(
"Win32_NetworkAdapterConfiguration"
);
ManagementObjectCollection
moc
=
mc
.
GetInstances
();
foreach
(
ManagementObject
mo
in
moc
)
{
if
((
bool
)
mo
[
"IPEnabled"
]
==
true
)
{
mac
=
mo
[
"MacAddress"
].
ToString
();
break
;
}
}
return
mac
;
}
catch
{
return
"unknow"
;
}
}
await
_devHistoryService
.
Add
(
record
);
myDev
.
updateTime
=
DateTime
.
Now
;
myDev
.
devState
=
devState
;
myDev
.
warehouseSd
=
warehouseSd
;
myDev
.
warehouseWd
=
warehouseWd
;
public
static
string
GetHttpRqst
(
string
strUrl
,
string
json
=
""
)
{
try
{
await
_devService
.
Update
(
myDev
);
HttpWebRequest
request
=
(
HttpWebRequest
)
WebRequest
.
Create
(
strUrl
);
request
.
Method
=
"POST"
;
var
historypParam
=
JsonConvert
.
SerializeObject
(
new
{
deviceName
=
record
.
devName
,
warehouseId
=
record
.
warehouseId
,
createTime
=
(
long
)(
record
.
createTime
.
Value
-
new
DateTime
(
1970
,
1
,
1
)).
TotalSeconds
,
temperature
=
record
.
warehouseWd
,
humidity
=
record
.
warehouseSd
,
});
HttpHelper
.
HttpPost
(
AdminGlobalContext
.
jyzbConfig
.
Url
+
""
,
historypParam
);
}
if
(!
string
.
IsNullOrEmpty
(
json
))
Thread
.
Sleep
(
10000
);
//10s
}
else
{
request
.
ContentType
=
"application/json"
;
byte
[]
data
=
Encoding
.
UTF8
.
GetBytes
(
json
);
request
.
ContentLength
=
data
.
Length
;
using
(
Stream
reqStream
=
request
.
GetRequestStream
())
//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);
// }
// }
//}
if
(
devList
.
TryGetValue
(
args
.
ip
,
out
Dehumidifier
dehumidifier
))
{
reqStream
.
Write
(
data
,
0
,
data
.
Length
);
reqStream
.
Close
();
if
(
dehumidifier
.
Open
())
{
dehumidifier
.
OnStatusChanged
+=
new
Dehumidifier
.
StatusChanged
(
OnStatusChanged
);
}
}
else
{
Dehumidifier
dev
=
new
Dehumidifier
(
args
.
ip
,
args
.
port
);
devList
.
Add
(
args
.
ip
,
dev
);
if
(
dev
.
Open
())
{
dev
.
OnStatusChanged
+=
new
Dehumidifier
.
StatusChanged
(
OnStatusChanged
);
}
}
}
HttpWebResponse
response
=
(
HttpWebResponse
)
request
.
GetResponse
();
Stream
responseStream
=
response
.
GetResponseStream
();
StreamReader
streamReader
=
new
StreamReader
(
responseStream
,
Encoding
.
UTF8
);
string
retString
=
streamReader
.
ReadToEnd
();
streamReader
.
Close
();
responseStream
.
Close
();
response
.
Close
();
return
retString
;
Thread
.
Sleep
(
30000
);
//30s
}
}
catch
(
Exception
ex
)
{
return
string
.
Empty
;
}
}
public
static
string
getKey
(
JsonData
data
,
string
key
)
{
if
(
JsonDataContainsKey
(
data
,
key
))
{
if
(
data
[
key
]
==
null
)
{
return
""
;
}
else
{
return
data
[
key
].
ToString
();
}
}
else
{
return
""
;
}
}
public
static
bool
JsonDataContainsKey
(
JsonData
data
,
string
key
)
{
bool
result
=
false
;
if
(
data
==
null
)
return
result
;
if
(!
data
.
IsObject
)
{
return
result
;
}
IDictionary
tdictionary
=
data
as
IDictionary
;
if
(
tdictionary
==
null
)
return
result
;
if
(
tdictionary
.
Contains
(
key
))
{
result
=
true
;
}
return
result
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论