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 de461201
authored
Mar 19, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]智能设备场景kafka消费
1 parent
173ead00
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
261 deletions
pom.xml
src/main/java/cn/com/glsx/smart/entity/DeviceOrder.java
src/main/java/cn/com/glsx/smart/entity/DeviceOrderDetail.java
src/main/java/cn/com/glsx/smart/entity/SmartDevideStatus.java
src/main/java/cn/com/glsx/smart/mapper/SmartDevideStatusMapper.java
src/main/java/cn/com/glsx/smart/service/OrderIssueService.java
src/main/resources/mapper/SmartDevideStatusMapper.xml
pom.xml
View file @
de46120
...
...
@@ -55,15 +55,25 @@
<version>
1.1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
net.sf.json-lib
</groupId>
<artifactId>
json-lib
</artifactId>
<version>
2.4
</version>
</dependency>
<dependency>
<groupId>
org.apache.kafka
</groupId>
<artifactId>
kafka_2.10
</artifactId>
<version>
0.8.1.1
</version>
<exclusions>
<exclusion>
<groupId>
javax.jms
</groupId>
<artifactId>
jms
</artifactId>
</exclusion>
<exclusion>
<groupId>
com.sun.jdmk
</groupId>
<artifactId>
jmxtools
</artifactId>
</exclusion>
<exclusion>
<groupId>
com.sun.jmx
</groupId>
<artifactId>
jmxri
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
...
...
src/main/java/cn/com/glsx/smart/entity/DeviceOrder.java
deleted
100644 → 0
View file @
173ead0
package
cn
.
com
.
glsx
.
smart
.
entity
;
import
lombok.Data
;
import
java.util.List
;
/**
* @author zhouhaibao
* @date 2021/3/16 15:14
*/
@Data
public
class
DeviceOrder
{
private
List
<
DeviceOrderDetail
>
commands
;
}
src/main/java/cn/com/glsx/smart/entity/DeviceOrderDetail.java
deleted
100644 → 0
View file @
173ead0
package
cn
.
com
.
glsx
.
smart
.
entity
;
import
lombok.Data
;
/**
* @author zhouhaibao
* @date 2021/3/16 15:14
*/
@Data
public
class
DeviceOrderDetail
{
private
String
code
;
private
String
value
;
}
src/main/java/cn/com/glsx/smart/entity/SmartDevideStatus.java
deleted
100644 → 0
View file @
173ead0
package
cn
.
com
.
glsx
.
smart
.
entity
;
import
java.io.Serializable
;
import
java.util.Date
;
import
javax.persistence.*
;
@Table
(
name
=
"smart_devide_status"
)
public
class
SmartDevideStatus
implements
Serializable
{
@Id
private
Integer
id
;
/**
* 设备id
*/
@Column
(
name
=
"device_id"
)
private
String
deviceId
;
/**
* 设备指令
*/
@Column
(
name
=
"device_order_code"
)
private
String
deviceOrderCode
;
/**
* 设备指令值
*/
@Column
(
name
=
"device_order_value"
)
private
String
deviceOrderValue
;
/**
* 创建时间
*/
private
Date
createtime
;
/**
* 更新时间
*/
private
Date
updatetime
;
/**
* 产品id
*/
@Column
(
name
=
"product_key"
)
private
String
productKey
;
private
static
final
long
serialVersionUID
=
1L
;
/**
* @return id
*/
public
Integer
getId
()
{
return
id
;
}
/**
* @param id
*/
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
/**
* 获取设备id
*
* @return device_id - 设备id
*/
public
String
getDeviceId
()
{
return
deviceId
;
}
/**
* 设置设备id
*
* @param deviceId 设备id
*/
public
void
setDeviceId
(
String
deviceId
)
{
this
.
deviceId
=
deviceId
==
null
?
null
:
deviceId
.
trim
();
}
/**
* 获取设备指令
*
* @return device_order_code - 设备指令
*/
public
String
getDeviceOrderCode
()
{
return
deviceOrderCode
;
}
/**
* 设置设备指令
*
* @param deviceOrderCode 设备指令
*/
public
void
setDeviceOrderCode
(
String
deviceOrderCode
)
{
this
.
deviceOrderCode
=
deviceOrderCode
==
null
?
null
:
deviceOrderCode
.
trim
();
}
/**
* 获取设备指令值
*
* @return device_order_value - 设备指令值
*/
public
String
getDeviceOrderValue
()
{
return
deviceOrderValue
;
}
/**
* 设置设备指令值
*
* @param deviceOrderValue 设备指令值
*/
public
void
setDeviceOrderValue
(
String
deviceOrderValue
)
{
this
.
deviceOrderValue
=
deviceOrderValue
==
null
?
null
:
deviceOrderValue
.
trim
();
}
/**
* 获取创建时间
*
* @return createtime - 创建时间
*/
public
Date
getCreatetime
()
{
return
createtime
;
}
/**
* 设置创建时间
*
* @param createtime 创建时间
*/
public
void
setCreatetime
(
Date
createtime
)
{
this
.
createtime
=
createtime
;
}
/**
* 获取更新时间
*
* @return updatetime - 更新时间
*/
public
Date
getUpdatetime
()
{
return
updatetime
;
}
/**
* 设置更新时间
*
* @param updatetime 更新时间
*/
public
void
setUpdatetime
(
Date
updatetime
)
{
this
.
updatetime
=
updatetime
;
}
/**
* 获取产品id
*
* @return product_key - 产品id
*/
public
String
getProductKey
()
{
return
productKey
;
}
/**
* 设置产品id
*
* @param productKey 产品id
*/
public
void
setProductKey
(
String
productKey
)
{
this
.
productKey
=
productKey
==
null
?
null
:
productKey
.
trim
();
}
@Override
public
String
toString
()
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
getClass
().
getSimpleName
());
sb
.
append
(
" ["
);
sb
.
append
(
"Hash = "
).
append
(
hashCode
());
sb
.
append
(
", id="
).
append
(
id
);
sb
.
append
(
", deviceId="
).
append
(
deviceId
);
sb
.
append
(
", deviceOrderCode="
).
append
(
deviceOrderCode
);
sb
.
append
(
", deviceOrderValue="
).
append
(
deviceOrderValue
);
sb
.
append
(
", createtime="
).
append
(
createtime
);
sb
.
append
(
", updatetime="
).
append
(
updatetime
);
sb
.
append
(
", productKey="
).
append
(
productKey
);
sb
.
append
(
", serialVersionUID="
).
append
(
serialVersionUID
);
sb
.
append
(
"]"
);
return
sb
.
toString
();
}
}
\ No newline at end of file
src/main/java/cn/com/glsx/smart/mapper/SmartDevideStatusMapper.java
deleted
100644 → 0
View file @
173ead0
package
cn
.
com
.
glsx
.
smart
.
mapper
;
import
cn.com.glsx.smart.entity.SmartDevideStatus
;
import
com.glsx.plat.mybatis.mapper.CommonBaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
@Mapper
public
interface
SmartDevideStatusMapper
extends
CommonBaseMapper
<
SmartDevideStatus
>
{
}
\ No newline at end of file
src/main/java/cn/com/glsx/smart/service/OrderIssueService.java
View file @
de46120
...
...
@@ -7,6 +7,7 @@ import cn.com.glsx.smart.mapper.SmartTemplateParamMapper;
import
cn.com.glsx.smart.utils.HttpUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
@@ -39,17 +40,25 @@ public class OrderIssueService {
*/
public
void
processMessage
(
String
data
)
{
MessageVo
messageVo
=
JSONObject
.
parseObject
(
data
,
MessageVo
.
class
);
if
(
messageVo
==
null
||
messageVo
.
getScenseId
()==
null
){
log
.
info
(
"数据异常"
);
return
;
}
List
<
SmartTemplateParam
>
smartTemplateParamList
=
smartTemplateParamMapper
.
findByTemplateId
(
Integer
.
parseInt
(
messageVo
.
getScenseId
()));
if
(!
CollectionUtils
.
isNotEmpty
(
smartTemplateParamList
)){
log
.
info
(
"未查到该场景id的条件{}"
,
messageVo
.
getScenseId
());
return
;
}
// 下发指令
List
<
SmartTemplateParam
>
orders
=
smartTemplateParamList
.
stream
().
filter
(
index
->
index
.
getParamKey
().
equals
(
Constants
.
Order_Issue
)).
collect
(
Collectors
.
toList
());
orders
.
forEach
(
index
->{
Map
<
String
,
List
<
Map
<
String
,
String
>>>
ordermaps
=
new
HashMap
<>();
List
<
Map
<
String
,
String
>>
maps
=
new
ArrayList
<>();
Map
<
String
,
String
>
ordermap
=
new
HashMap
<>();
List
<
String
>
list
=
JSONObject
.
parseArray
(
index
.
getParamValue
(),
String
.
class
);
String
devideId
=
list
.
get
(
0
)
;
ordermap
.
put
(
"code"
,
list
.
get
(
1
)
);
ordermap
.
put
(
"value"
,
list
.
get
(
2
));
Map
<
String
,
List
<
Map
<
String
,
Object
>>>
ordermaps
=
new
HashMap
<>();
List
<
Map
<
String
,
Object
>>
maps
=
new
ArrayList
<>();
Map
<
String
,
Object
>
ordermap
=
new
HashMap
<>();
List
<
Object
>
objects
=
JSONObject
.
parseArray
(
index
.
getParamValue
(),
Object
.
class
);
String
devideId
=
objects
.
get
(
0
)+
""
;
ordermap
.
put
(
"code"
,
objects
.
get
(
1
)+
""
);
ordermap
.
put
(
"value"
,
objects
.
get
(
2
));
maps
.
add
(
ordermap
);
ordermaps
.
put
(
"commands"
,
maps
);
try
{
...
...
@@ -59,6 +68,8 @@ public class OrderIssueService {
if
(
code
!=
null
)
{
if
(
Integer
.
parseInt
(
code
.
toString
())==
200
)
{
log
.
info
(
"设备{},{}"
,
devideId
,
message
);
}
else
{
log
.
info
(
"设备{}下发失败,错误信息{}"
,
devideId
,
message
);
}
}
}
catch
(
IOException
e
)
{
...
...
@@ -66,7 +77,8 @@ public class OrderIssueService {
log
.
info
(
"设备{}下发失败"
,
devideId
);
}
});
// 推送消息----- TODO
// 推送消息
开始
----- TODO
List
<
SmartTemplateParam
>
messageOrders
=
smartTemplateParamList
.
stream
().
filter
(
index
->
index
.
getParamKey
().
equals
(
Constants
.
MESSAGE_NOTI
)).
collect
(
Collectors
.
toList
());
// 推送消息结束 -----TODO
}
}
src/main/resources/mapper/SmartDevideStatusMapper.xml
deleted
100644 → 0
View file @
173ead0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"cn.com.glsx.smart.mapper.SmartDevideStatusMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"cn.com.glsx.smart.entity.SmartDevideStatus"
>
<!--
WARNING - @mbg.generated
-->
<id
column=
"id"
jdbcType=
"INTEGER"
property=
"id"
/>
<result
column=
"device_id"
jdbcType=
"VARCHAR"
property=
"deviceId"
/>
<result
column=
"device_order_code"
jdbcType=
"VARCHAR"
property=
"deviceOrderCode"
/>
<result
column=
"device_order_value"
jdbcType=
"VARCHAR"
property=
"deviceOrderValue"
/>
<result
column=
"createtime"
jdbcType=
"TIMESTAMP"
property=
"createtime"
/>
<result
column=
"updatetime"
jdbcType=
"TIMESTAMP"
property=
"updatetime"
/>
<result
column=
"product_key"
jdbcType=
"VARCHAR"
property=
"productKey"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
<!--
WARNING - @mbg.generated
-->
id, device_id, device_order_code, device_order_value, createtime, updatetime, product_key
</sql>
</mapper>
\ 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