Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
glsx-smart-device-kafka-consumer
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 a1b659ce
authored
Mar 22, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]智能设备场景kafka消费
1 parent
38db439f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
33 deletions
src/main/java/cn/com/glsx/smart/entity/ExecuteTaskVo.java
src/main/java/cn/com/glsx/smart/entity/ResponseVo.java
src/main/java/cn/com/glsx/smart/service/OrderIssueService.java
src/main/java/cn/com/glsx/smart/entity/ExecuteTaskVo.java
0 → 100644
View file @
a1b659c
package
cn
.
com
.
glsx
.
smart
.
entity
;
import
lombok.Data
;
/**
* @author zhouhaibao
* @date 2021/3/22 15:52
*/
@Data
public
class
ExecuteTaskVo
{
private
String
deviceId
;
private
String
orderCode
;
private
String
orderValue
;
private
String
orderValueType
;
private
String
remoteId
;
}
src/main/java/cn/com/glsx/smart/entity/ResponseVo.java
0 → 100644
View file @
a1b659c
package
cn
.
com
.
glsx
.
smart
.
entity
;
import
lombok.Data
;
/**
* @author zhouhaibao
* @date 2021/3/22 16:18
*/
@Data
public
class
ResponseVo
{
private
String
code
;
private
String
message
;
}
src/main/java/cn/com/glsx/smart/service/OrderIssueService.java
View file @
a1b659c
package
cn
.
com
.
glsx
.
smart
.
service
;
import
cn.com.glsx.smart.commons.Constants
;
import
cn.com.glsx.smart.entity.ExecuteTaskVo
;
import
cn.com.glsx.smart.entity.MessageVo
;
import
cn.com.glsx.smart.entity.ResponseVo
;
import
cn.com.glsx.smart.entity.SmartTemplateParam
;
import
cn.com.glsx.smart.mapper.SmartTemplateParamMapper
;
import
cn.com.glsx.smart.utils.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
@@ -40,50 +44,63 @@ public class OrderIssueService {
*/
public
void
processMessage
(
String
data
)
{
MessageVo
messageVo
=
JSONObject
.
parseObject
(
data
,
MessageVo
.
class
);
if
(
messageVo
==
null
||
messageVo
.
getScenseId
()==
null
)
{
if
(
messageVo
==
null
||
messageVo
.
getScenseId
()
==
null
)
{
log
.
info
(
"数据异常"
);
return
;
}
List
<
SmartTemplateParam
>
smartTemplateParamList
=
smartTemplateParamMapper
.
findByTemplateId
(
Integer
.
parseInt
(
messageVo
.
getScenseId
()));
if
(
CollectionUtils
.
isEmpty
(
smartTemplateParamList
))
{
log
.
info
(
"未查到该场景id的条件{}"
,
messageVo
.
getScenseId
());
List
<
SmartTemplateParam
>
smartTemplateParamList
=
smartTemplateParamMapper
.
findByTemplateId
(
Integer
.
parseInt
(
messageVo
.
getScenseId
()));
if
(
CollectionUtils
.
isEmpty
(
smartTemplateParamList
))
{
log
.
info
(
"未查到该场景id的条件{}"
,
messageVo
.
getScenseId
());
return
;
}
// 下发指令
List
<
SmartTemplateParam
>
orders
=
smartTemplateParamList
.
stream
().
filter
(
index
->
index
.
getParamKey
().
equals
(
Constants
.
Order_Issue
)).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
orders
))
{
log
.
info
(
"未查到该场景id的指令{}"
,
messageVo
.
getScenseId
());
if
(
CollectionUtils
.
isEmpty
(
orders
))
{
log
.
info
(
"未查到该场景id的指令{}"
,
messageVo
.
getScenseId
());
return
;
}
orders
.
forEach
(
index
->{
Map
<
String
,
List
<
Map
<
String
,
Object
>>>
ordermaps
=
new
HashMap
<>();
List
<
Map
<
String
,
Object
>>
maps
=
new
ArrayList
<>();
Map
<
String
,
Object
>
ordermap
=
new
HashMap
<>();
if
(
index
.
getParamValue
()==
null
||
index
.
getParamValue
().
split
(
","
).
length
!=
4
){
log
.
info
(
"参数异常{}"
,
index
.
getParamKey
());
orders
.
forEach
(
index
->
{
Map
<
String
,
List
<
Map
<
String
,
Object
>>>
ordermaps
=
new
HashMap
<>();
List
<
Map
<
String
,
Object
>>
maps
=
new
ArrayList
<>();
Map
<
String
,
Object
>
ordermap
=
new
HashMap
<>();
String
paramValue
=
index
.
getParamValue
();
if
(
StringUtils
.
isEmpty
(
paramValue
))
{
log
.
info
(
"参数异常{}"
,
index
.
getParamKey
());
return
;
}
String
[]
objects
=
index
.
getParamValue
().
split
(
","
);
String
devideId
=
objects
[
0
];
String
valueType
=
objects
[
3
];
ordermap
.
put
(
"code"
,
objects
[
1
]);
ordermap
.
put
(
"value"
,
revertType
(
valueType
,
objects
[
2
]));
maps
.
add
(
ordermap
);
ordermaps
.
put
(
"commands"
,
maps
);
ExecuteTaskVo
executeTaskVo
=
JSONObject
.
parseObject
(
paramValue
,
ExecuteTaskVo
.
class
);
if
(
StringUtils
.
isEmpty
(
executeTaskVo
.
getOrderCode
())
||
StringUtils
.
isEmpty
(
executeTaskVo
.
getDeviceId
()))
{
log
.
info
(
"参数异常{}"
,
index
.
getParamKey
());
return
;
}
// 根据遥控器id下发普通指令还是红外遥控指令
String
remoteId
=
executeTaskVo
.
getRemoteId
();
String
devideId
=
executeTaskVo
.
getDeviceId
();
JSONObject
jsonObject
=
null
;
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendPost
(
orderIssueurl
.
replace
(
"{device_id}"
,
devideId
),
JSONObject
.
toJSONString
(
ordermaps
),
new
HashMap
<>());
if
(
jsonObject
!=
null
)
{
Object
code
=
jsonObject
.
get
(
"code"
);
Object
message
=
jsonObject
.
get
(
"message"
);
if
(
Integer
.
parseInt
(
code
.
toString
())==
200
)
{
log
.
info
(
"设备{},{}"
,
devideId
,
message
);
if
(
StringUtils
.
isBlank
(
remoteId
))
{
String
valueType
=
executeTaskVo
.
getOrderValueType
();
ordermap
.
put
(
"code"
,
executeTaskVo
.
getOrderCode
());
ordermap
.
put
(
"value"
,
revertType
(
valueType
,
executeTaskVo
.
getOrderValue
()));
maps
.
add
(
ordermap
);
ordermaps
.
put
(
"commands"
,
maps
);
// 下发普通指令
jsonObject
=
HttpUtil
.
sendPost
(
orderIssueurl
.
replace
(
"{device_id}"
,
devideId
),
JSONObject
.
toJSONString
(
ordermaps
),
new
HashMap
<>());
}
else
{
ordermap
.
put
(
"key"
,
executeTaskVo
.
getOrderCode
());
// 下发红外遥控指令
jsonObject
=
HttpUtil
.
sendPost
(
orderIssueurl
.
replace
(
"{remote_id}"
,
remoteId
).
replace
(
"{infrared_id}"
,
devideId
),
JSONObject
.
toJSONString
(
ordermap
),
new
HashMap
<>());
}
if
(
jsonObject
!=
null
){
ResponseVo
responseVo
=
JSONObject
.
toJavaObject
(
jsonObject
,
ResponseVo
.
class
);
if
(
responseVo
.
getCode
().
equals
(
"200"
)){
log
.
info
(
"设备{}下发成功"
,
devideId
);
}
else
{
log
.
info
(
"设备{}下发失败,错误信息
{}"
,
devideId
,
message
);
log
.
info
(
"设备{}下发失败,错误信息
为{}"
,
devideId
,
responseVo
.
getMessage
()
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
log
.
info
(
"设备{}下发失败"
,
devideId
);
}
});
// 推送消息开始 ----- TODO
...
...
@@ -92,19 +109,19 @@ public class OrderIssueService {
}
private
Object
revertType
(
String
valueType
,
String
object
)
{
Object
orderValue
=
null
;
switch
(
valueType
){
Object
orderValue
=
null
;
switch
(
valueType
)
{
case
"1"
:
orderValue
=
object
;
orderValue
=
object
;
break
;
case
"2"
:
orderValue
=
Integer
.
parseInt
(
object
);
orderValue
=
Integer
.
parseInt
(
object
);
break
;
case
"3"
:
orderValue
=
Boolean
.
valueOf
(
object
);
orderValue
=
Boolean
.
valueOf
(
object
);
break
;
default
:
orderValue
=
object
;
orderValue
=
object
;
break
;
}
return
orderValue
;
...
...
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