Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
glinfo-api
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
林业通
glinfo-api
Commits
ab884fc5
提交
ab884fc5
authored
2月 23, 2022
作者:
林业通
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
开关修改
上级
10bd1004
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
68 行增加
和
74 行删除
+68
-74
MqConsumer.java
...rc/main/java/tech/glinfo/enbao/modules/mq/MqConsumer.java
+9
-8
SwitchParse.java
...c/main/java/tech/glinfo/enbao/modules/mq/SwitchParse.java
+59
-66
没有找到文件。
appapi/src/main/java/tech/glinfo/enbao/modules/mq/MqConsumer.java
浏览文件 @
ab884fc5
...
...
@@ -137,16 +137,17 @@ public class MqConsumer {
map1
.
put
(
"status"
,
"2"
);
mapList
.
add
(
map1
);
jmsTemplate
.
convertAndSend
(
socketioTopic
,
JSON
.
toJSONString
(
new
MapUtils
().
put
(
"deviceId"
,
"onlineStatus"
).
put
(
"list"
,
JSON
.
toJSONString
(
mapList
))));
//更新设备状态为在线
new
Thread
(()
->
{
ShDeviceEntity
deviceEntity
=
new
ShDeviceEntity
();
deviceEntity
.
setId
(
device
.
getId
());
deviceEntity
.
setOnlineStatus
(
2
);
deviceEntity
.
setOnlineTime
(
new
Date
());
otherShDeviceService
.
updateById
(
deviceEntity
);
}).
start
();
}
//更新设备状态为在线
new
Thread
(()
->
{
ShDeviceEntity
deviceEntity
=
new
ShDeviceEntity
();
deviceEntity
.
setId
(
device
.
getId
());
deviceEntity
.
setOnlineStatus
(
2
);
deviceEntity
.
setOnlineTime
(
new
Date
());
otherShDeviceService
.
updateById
(
deviceEntity
);
}).
start
();
String
sendMessage
=
null
;
Map
<
String
,
String
>
ws
=
null
;
// redisUtils.get(Constants.PARSE_CLASS + datas.get("deviceType"));
...
...
appapi/src/main/java/tech/glinfo/enbao/modules/mq/SwitchParse.java
浏览文件 @
ab884fc5
...
...
@@ -2,25 +2,23 @@ package tech.glinfo.enbao.modules.mq;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
org.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
tech.glinfo.enbao.common.utils.ByteUtils
;
import
tech.glinfo.enbao.common.utils.DateUtils
;
import
tech.glinfo.enbao.common.utils.RedisUtils
;
import
tech.glinfo.enbao.common.utils.StringUtils
;
import
tech.glinfo.enbao.modules.sh.entity.ShDeviceDataEntity
;
import
tech.glinfo.enbao.modules.sh.entity.ShDeviceEntity
;
import
tech.glinfo.enbao.modules.sh.entity.ShDeviceRecordEntity
;
import
tech.glinfo.enbao.modules.sh.entity.ShDlinkEntity
;
import
tech.glinfo.enbao.modules.sh.entity.ShInstructionParsingEntity
;
import
tech.glinfo.enbao.modules.sh.service.*
;
import
tech.glinfo.enbao.modules.sh.service.OtherShDeviceService
;
import
tech.glinfo.enbao.modules.sh.service.OtherShDlinkService
;
import
tech.glinfo.enbao.modules.sh.service.ShDeviceRecordService
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
//智能开关
@Component
(
"switchParse"
)
...
...
@@ -34,9 +32,6 @@ public class SwitchParse implements IParse {
@Autowired
private
ShDeviceRecordService
shDeviceRecordService
;
@Autowired
private
ShDeviceDataService
shDeviceDataService
;
@Autowired
private
RedisUtils
redisUtils
;
...
...
@@ -46,6 +41,9 @@ public class SwitchParse implements IParse {
@Autowired
private
MqProducer
mqProducer
;
@Autowired
private
OtherShDlinkService
otherShDlinkService
;
@Override
public
Map
<
String
,
String
>
run
(
Object
o
,
Map
<
String
,
String
>
datas
)
{
ShDeviceEntity
device
=
(
ShDeviceEntity
)
o
;
...
...
@@ -107,75 +105,70 @@ public class SwitchParse implements IParse {
}
else
if
(
"18"
.
equals
(
datas
.
get
(
"cmd"
)))
{
//开关响应
String
content
=
datas
.
get
(
"content"
);
logger
.
info
(
"开关响应 : {}"
,
content
);
//开关状态
/*if (content.equals("00")) {
//保存开关记录
logger.info("receiveId : {}", datas.get("receiveId"));
String action = redisUtils.get(datas.get("receiveId") + "action1");
String action2 = redisUtils.get(datas.get("receiveId") + "action2");
if (StringUtils.isNotBlank(action)) {
ws
.
put
(
"action"
,
content
);
}
else
if
(
"20"
.
equals
(
datas
.
get
(
"cmd"
)))
{
//事件上报
//保存开关记录
String
content
=
datas
.
get
(
"content"
);
String
type
=
content
.
substring
(
2
,
4
);
String
action1
=
content
.
substring
(
6
,
8
);
String
action2
=
content
.
substring
(
8
,
10
);
switch
(
type
)
{
case
"01"
:
{
ShDeviceRecordEntity
recordEntity
=
new
ShDeviceRecordEntity
();
recordEntity
.
setDeviceId
(
device
.
getId
());
recordEntity.setAction(Integer.parseInt(action));
//开关1 1:开 2:关
recordEntity
.
setAction
(
action1
.
equals
(
"01"
)
?
1
:
2
);
shDeviceRecordService
.
save
(
recordEntity
);
redisUtils.delete(datas.get("receiveId") + "action1")
;
break
;
}
if (StringUtils.isNotBlank(action2)) {
case
"02"
:
{
ShDeviceRecordEntity
recordEntity
=
new
ShDeviceRecordEntity
();
recordEntity
.
setDeviceId
(
device
.
getId
());
recordEntity.setAction(Integer.parseInt(action2));
//开关2 3:开 4:关
recordEntity
.
setAction
(
action2
.
equals
(
"01"
)
?
3
:
4
);
shDeviceRecordService
.
save
(
recordEntity
);
redisUtils.delete(datas.get("receiveId") + "action2")
;
break
;
}
case
"03"
:
{
Date
date
=
new
Date
();
ShDeviceRecordEntity
recordEntity
=
new
ShDeviceRecordEntity
();
recordEntity
.
setDeviceId
(
device
.
getId
());
//开关1 1:开 2:关
recordEntity
.
setAction
(
action1
.
equals
(
"01"
)
?
1
:
2
);
recordEntity
.
setCreateTime
(
date
);
shDeviceRecordService
.
save
(
recordEntity
);
}*/
ws
.
put
(
"action"
,
content
);
}
else
if
(
"1A"
.
equals
(
datas
.
get
(
"cmd"
)))
{
//温控响应
String
content
=
datas
.
get
(
"content"
);
logger
.
info
(
"设置温控响应 : {}"
,
content
);
/* String content1 = redisUtils.get(device.getNumbering() + "temp");
//设备响应成功之后修改数据,不用等30秒,页面体验好些
if ("00".equals(content)) {
if (content1 != null) {
ShDeviceDataEntity entity = shDeviceDataService.getOne(new QueryWrapper<ShDeviceDataEntity>().eq("device_id", device.getId()));
if (entity != null) {
JSONObject jsonObj = new JSONObject(entity.getValue());
jsonObj.put("highTemp1", ByteUtils.signHex2IntString(content1.substring(0, 2)));
jsonObj.put("highTempStatus1", ByteUtils.signHex2IntString(content1.substring(2, 4)));
jsonObj.put("lowTemp1", ByteUtils.signHex2IntString(content1.substring(4, 6)));
jsonObj.put("lowTempStatus1", ByteUtils.signHex2IntString(content1.substring(6, 8)));
jsonObj.put("highTemp2", ByteUtils.signHex2IntString(content1.substring(8, 10)));
jsonObj.put("highTempStatus2", ByteUtils.signHex2IntString(content1.substring(10, 12)));
jsonObj.put("lowTemp2", ByteUtils.signHex2IntString(content1.substring(12, 14)));
jsonObj.put("lowTempStatus2", ByteUtils.signHex2IntString(content1.substring(14, 16)));
entity.setValue(jsonObj.toString());
shDeviceDataService.updateById(entity);
}
ShDeviceRecordEntity
recordEntity1
=
new
ShDeviceRecordEntity
();
recordEntity1
.
setDeviceId
(
device
.
getId
());
//开关2 3:开 4:关
recordEntity1
.
setAction
(
action2
.
equals
(
"01"
)
?
3
:
4
);
recordEntity1
.
setCreateTime
(
date
);
shDeviceRecordService
.
save
(
recordEntity1
);
break
;
}
}
redisUtils.delete(device.getNumbering() + "temp");*/
}
else
if
(
"20"
.
equals
(
datas
.
get
(
"cmd"
)))
{
//事件上报
//保存开关记录
String
content
=
datas
.
get
(
"content"
);
String
type
=
content
.
substring
(
2
,
4
);
String
action
=
content
.
substring
(
6
,
8
);
ShDeviceRecordEntity
recordEntity
=
new
ShDeviceRecordEntity
();
recordEntity
.
setDeviceId
(
device
.
getId
());
if
(
type
.
equals
(
"01"
))
{
//开关1 1:开 2:关
recordEntity
.
setAction
(
action
.
equals
(
"01"
)
?
1
:
2
);
}
else
{
//开关2 3:开 4:关
recordEntity
.
setAction
(
action
.
equals
(
"01"
)
?
3
:
4
);
}
shDeviceRecordService
.
save
(
recordEntity
);
sendCmd
(
device
.
getId
(),
action1
.
equals
(
"01"
)
?
"1"
:
"2"
,
action2
.
equals
(
"01"
)
?
"1"
:
"2"
);
}
return
ws
;
}
private
void
sendCmd
(
Integer
id
,
String
statusO
,
String
statusT
)
{
String
sss
=
DateUtils
.
format
(
new
Date
(),
"yyyy-MM-dd HH:mm"
);
ShDlinkEntity
dlinkEntity
=
otherShDlinkService
.
checkTime
(
sss
.
substring
(
sss
.
length
()-
5
),
id
,
statusO
,
statusT
);
if
(
dlinkEntity
!=
null
)
{
String
key
=
"device:dlink:"
+
dlinkEntity
.
getStart
()
+
"-"
+
dlinkEntity
.
getEnd
()
+
":"
+
dlinkEntity
.
getDeviceId
();
String
json
=
redisUtils
.
get
(
key
);
logger
.
info
(
"场景找到1"
+
json
);
if
(
StringUtils
.
isNotBlank
(
json
))
{
for
(
String
s
:
json
.
split
(
"-"
))
{
logger
.
info
(
"场景找到2"
+
s
);
mqProducer
.
sendT
(
s
);
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论