Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
glsx-smart-message-channel
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 7031a077
authored
Apr 19, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]pulsar消费服务
1 parent
c3712588
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
35 deletions
src/main/java/cn/com/glsx/consumer/comsumers/TuyaComsumer.java
src/main/java/cn/com/glsx/consumer/mapper/SmartSceneDataMapper.java
src/main/java/cn/com/glsx/consumer/service/TuyaConmsumerService.java → src/main/java/cn/com/glsx/consumer/service/InfoService.java
src/main/resources/mapper/SmartSceneDataMapper.xml
src/main/java/cn/com/glsx/consumer/comsumers/TuyaComsumer.java
View file @
7031a07
...
@@ -5,7 +5,7 @@ import cn.com.glsx.consumer.common.AESBase64Utils;
...
@@ -5,7 +5,7 @@ import cn.com.glsx.consumer.common.AESBase64Utils;
import
cn.com.glsx.consumer.common.Contants
;
import
cn.com.glsx.consumer.common.Contants
;
import
cn.com.glsx.consumer.common.MqConsumer
;
import
cn.com.glsx.consumer.common.MqConsumer
;
import
cn.com.glsx.consumer.entity.MessageVO
;
import
cn.com.glsx.consumer.entity.MessageVO
;
import
cn.com.glsx.consumer.service.
TuyaConmsumer
Service
;
import
cn.com.glsx.consumer.service.
Info
Service
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -33,7 +33,7 @@ public class TuyaComsumer implements CommandLineRunner {
...
@@ -33,7 +33,7 @@ public class TuyaComsumer implements CommandLineRunner {
private
String
topic
;
private
String
topic
;
@Autowired
@Autowired
private
TuyaConmsumerService
tuyaConmsumer
Service
;
private
InfoService
info
Service
;
@Override
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
public
void
run
(
String
...
args
)
throws
Exception
{
...
@@ -49,7 +49,7 @@ public class TuyaComsumer implements CommandLineRunner {
...
@@ -49,7 +49,7 @@ public class TuyaComsumer implements CommandLineRunner {
if
(
protocol
.
equals
(
Contants
.
STATUS_APPEAR
)){
if
(
protocol
.
equals
(
Contants
.
STATUS_APPEAR
)){
String
data
=
AESBase64Utils
.
decrypt
(
vo
.
getData
(),
accessKey
.
substring
(
8
,
24
));
String
data
=
AESBase64Utils
.
decrypt
(
vo
.
getData
(),
accessKey
.
substring
(
8
,
24
));
log
.
info
(
"the real message data:"
+
data
);
log
.
info
(
"the real message data:"
+
data
);
tuyaConmsumer
Service
.
processMessage
(
data
);
info
Service
.
processMessage
(
data
);
}
}
}
}
);
);
...
...
src/main/java/cn/com/glsx/consumer/mapper/SmartSceneDataMapper.java
View file @
7031a07
...
@@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Param;
...
@@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Param;
import
java.util.List
;
import
java.util.List
;
public
interface
SmartSceneDataMapper
extends
CommonBaseMapper
<
SmartSceneData
>
{
public
interface
SmartSceneDataMapper
extends
CommonBaseMapper
<
SmartSceneData
>
{
List
<
SmartSceneData
>
findSceneDataByDeviceId
(
@Param
(
"deviceId"
)
String
deviceId
);
List
<
SmartSceneData
>
findSceneDataByDeviceId
(
@Param
(
"deviceId"
)
String
deviceId
,
@Param
(
"order"
)
String
order
);
List
<
SmartSceneData
>
findBySceneId
(
Long
sceneId
);
List
<
SmartSceneData
>
findBySceneId
(
@Param
(
"sceneId"
)
Long
sceneId
,
@Param
(
"order"
)
String
order
);
}
}
\ No newline at end of file
\ No newline at end of file
src/main/java/cn/com/glsx/consumer/service/
TuyaConmsumer
Service.java
→
src/main/java/cn/com/glsx/consumer/service/
Info
Service.java
View file @
7031a07
...
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
...
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
*/
*/
@Service
@Service
@Slf4j
@Slf4j
public
class
TuyaConmsumer
Service
{
public
class
Info
Service
{
@Autowired
@Autowired
private
SmartDevideStatusMapper
smartDevideStatusMapper
;
private
SmartDevideStatusMapper
smartDevideStatusMapper
;
...
@@ -68,38 +68,46 @@ public class TuyaConmsumerService {
...
@@ -68,38 +68,46 @@ public class TuyaConmsumerService {
smartDevideStatusMapper
.
updateByPrimaryKeySelective
(
index
);
smartDevideStatusMapper
.
updateByPrimaryKeySelective
(
index
);
}
}
});
});
// 判断该设备是否在用户场景里面
list
.
forEach
(
in
->{
List
<
SmartSceneData
>
smartSceneDataList
=
smartSceneDataMapper
.
findSceneDataByDeviceId
(
list
.
get
(
0
).
getDeviceId
());
// 判断该设备是否在用户场景里面
if
(
CollectionUtils
.
isEmpty
(
smartSceneDataList
))
{
List
<
SmartSceneData
>
smartSceneDataList
=
smartSceneDataMapper
.
findSceneDataByDeviceId
(
in
.
getDeviceId
(),
in
.
getDeviceOrderCode
());
log
.
info
(
"未查到用户场景,设备id{}"
,
list
.
get
(
0
).
getDeviceId
());
if
(
CollectionUtils
.
isEmpty
(
smartSceneDataList
))
{
return
;
log
.
info
(
"未查到用户场景,设备id{}"
,
in
.
getDeviceId
());
}
smartSceneDataList
.
forEach
(
index
->
{
Integer
executeCycle
=
index
.
getExecuteCycle
();
// 判断场景是否触发
List
<
SmartSceneData
>
sceneDataList
=
smartSceneDataMapper
.
findBySceneId
(
index
.
getSceneId
());
// 判断场景条件是否配置了时间并且是全部条件满足执行的
List
<
SmartSceneData
>
scene_condition_time
=
sceneDataList
.
stream
().
filter
(
inx
->
inx
.
getParamKey
().
equals
(
"scene_condition_status"
)).
collect
(
Collectors
.
toList
());
if
(
list
.
size
()
!=
scene_condition_time
.
size
()
&&
index
.
getConditionRule
().
equals
(
"2"
))
{
log
.
info
(
"场景id{}不符合必要条件条件"
,
index
.
getSceneId
());
return
;
return
;
}
}
boolean
isTrigger
=
conditionStrategy
.
isTrigger
(
sceneDataList
,
executeCycle
,
smartSceneDataList
.
forEach
(
index
->
{
(
SmartSceneData
condition
)
->
getTriggerResult
(
condition
));
List
<
SmartSceneData
>
sceneDataList
=
null
;
log
.
info
(
"场景id{}---{}触发条件"
,
index
.
getSceneId
(),
isTrigger
?
"符合"
:
"不符合"
);
Integer
executeCycle
=
index
.
getExecuteCycle
();
if
(
isTrigger
)
{
// 判断场景是否触发
// 下发场景
if
(
index
.
getConditionRule
().
equals
(
"1"
)){
Map
<
String
,
String
>
requestMap
=
new
HashMap
<>();
sceneDataList
=
smartSceneDataMapper
.
findBySceneId
(
index
.
getSceneId
(),
in
.
getDeviceOrderCode
());
requestMap
.
put
(
"id"
,
index
.
getSceneId
()
+
""
);
}
else
{
try
{
sceneDataList
=
smartSceneDataMapper
.
findBySceneId
(
index
.
getSceneId
(),
null
);
String
responseBody
=
HttpUtil
.
sendPost
(
issueOrderUrl
,
JSONObject
.
toJSONString
(
requestMap
),
new
HashMap
<>());
log
.
info
(
"场景id{}下发结果{}"
,
index
.
getSceneId
(),
responseBody
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
info
(
"场景id{}下发指令异常,{}"
,
index
.
getSceneId
(),
e
);
}
}
}
// 判断场景条件是否配置了时间并且是全部条件满足执行的
List
<
SmartSceneData
>
scene_condition_time
=
sceneDataList
.
stream
().
filter
(
inx
->
inx
.
getParamKey
().
equals
(
"scene_condition_status"
)).
collect
(
Collectors
.
toList
());
if
(
list
.
size
()
!=
scene_condition_time
.
size
()
&&
index
.
getConditionRule
().
equals
(
"2"
))
{
log
.
info
(
"场景id{}不符合必要条件条件"
,
index
.
getSceneId
());
return
;
}
boolean
isTrigger
=
conditionStrategy
.
isTrigger
(
sceneDataList
,
executeCycle
,
(
SmartSceneData
condition
)
->
getTriggerResult
(
condition
));
log
.
info
(
"场景id{}---{}触发条件"
,
index
.
getSceneId
(),
isTrigger
?
"符合"
:
"不符合"
);
if
(
isTrigger
)
{
// 下发场景
Map
<
String
,
String
>
requestMap
=
new
HashMap
<>();
requestMap
.
put
(
"id"
,
index
.
getSceneId
()
+
""
);
try
{
String
responseBody
=
HttpUtil
.
sendPost
(
issueOrderUrl
,
JSONObject
.
toJSONString
(
requestMap
),
new
HashMap
<>());
log
.
info
(
"场景id{}下发结果{}"
,
index
.
getSceneId
(),
responseBody
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
info
(
"场景id{}下发指令异常,{}"
,
index
.
getSceneId
(),
e
);
}
}
});
});
});
}
}
}
}
...
...
src/main/resources/mapper/SmartSceneDataMapper.xml
View file @
7031a07
...
@@ -23,10 +23,13 @@
...
@@ -23,10 +23,13 @@
</sql>
</sql>
<select
id=
"findSceneDataByDeviceId"
resultMap=
"BaseResultMap"
>
<select
id=
"findSceneDataByDeviceId"
resultMap=
"BaseResultMap"
>
select t1.scene_id,t2.condition_rule,t2.execute_cycle from smart_scene t2 left join smart_scene_data t1 on t1.scene_id=t2.id
select t1.scene_id,t2.condition_rule,t2.execute_cycle from smart_scene t2 left join smart_scene_data t1 on t1.scene_id=t2.id
where device_id=#{deviceId} and param_key='scene_condition_status' and t2.status=1 GROUP BY t1.scene_id
where device_id=#{deviceId} and param_key='scene_condition_status' and t2.status=1
and param_value like concat('%',#{order},'%')
GROUP BY t1.scene_id
</select>
</select>
<select
id=
"findBySceneId"
resultMap=
"BaseResultMap"
>
<select
id=
"findBySceneId"
resultMap=
"BaseResultMap"
>
select t1.*,t2.condition_rule,t2.execute_cycle from smart_scene_data t1 left join smart_scene t2 on t1.scene_id=t2.id
select t1.*,t2.condition_rule,t2.execute_cycle from smart_scene_data t1 left join smart_scene t2 on t1.scene_id=t2.id
where scene_id=#{sceneId} and (param_key='scene_condition_status' or param_key='scene_condition_time') and t2.status=1
where scene_id=#{sceneId} and (param_key='scene_condition_status' or param_key='scene_condition_time') and t2.status=1
<if
test=
"order != null"
>
and param_value like concat('%',#{order},'%')
</if>
</select>
</select>
</mapper>
</mapper>
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment