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 44f0d754
authored
Apr 22, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]pulsar消费服务
1 parent
94625a6d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
19 deletions
pom.xml
src/main/java/cn/com/glsx/consumer/common/Contants.java
src/main/java/cn/com/glsx/consumer/entity/SmartDevideStatus.java
src/main/java/cn/com/glsx/consumer/service/InfoService.java
src/main/resources/config/generatorConfig.xml
pom.xml
View file @
44f0d75
...
@@ -63,6 +63,11 @@
...
@@ -63,6 +63,11 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.glsx
</groupId>
<groupId>
com.glsx
</groupId>
<artifactId>
rest-admin-redis
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
com.glsx
</groupId>
<artifactId>
rest-admin-mybatis
</artifactId>
<artifactId>
rest-admin-mybatis
</artifactId>
<version>
1.1.0-SNAPSHOT
</version>
<version>
1.1.0-SNAPSHOT
</version>
</dependency>
</dependency>
...
...
src/main/java/cn/com/glsx/consumer/common/Contants.java
View file @
44f0d75
...
@@ -9,4 +9,5 @@ public class Contants {
...
@@ -9,4 +9,5 @@ public class Contants {
public
static
final
int
STATUS_APPEAR
=
4
;
public
static
final
int
STATUS_APPEAR
=
4
;
public
static
final
int
SCENE_CONDITION_ALL
=
2
;
public
static
final
int
SCENE_CONDITION_ALL
=
2
;
public
static
final
int
SCENE_CONDITION_ANY
=
1
;
public
static
final
int
SCENE_CONDITION_ANY
=
1
;
public
static
final
String
SCENE_STATUS
=
"scene_status"
;
}
}
src/main/java/cn/com/glsx/consumer/entity/SmartDevideStatus.java
View file @
44f0d75
...
@@ -43,6 +43,9 @@ public class SmartDevideStatus implements Serializable {
...
@@ -43,6 +43,9 @@ public class SmartDevideStatus implements Serializable {
@Column
(
name
=
"product_key"
)
@Column
(
name
=
"product_key"
)
private
String
productKey
;
private
String
productKey
;
@Transient
private
Boolean
flag
=
true
;
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
/**
/**
...
@@ -168,4 +171,11 @@ public class SmartDevideStatus implements Serializable {
...
@@ -168,4 +171,11 @@ public class SmartDevideStatus implements Serializable {
this
.
productKey
=
productKey
==
null
?
null
:
productKey
.
trim
();
this
.
productKey
=
productKey
==
null
?
null
:
productKey
.
trim
();
}
}
public
Boolean
getFlag
()
{
return
flag
;
}
public
void
setFlag
(
Boolean
flag
)
{
this
.
flag
=
flag
;
}
}
}
\ No newline at end of file
\ No newline at end of file
src/main/java/cn/com/glsx/consumer/service/InfoService.java
View file @
44f0d75
package
cn
.
com
.
glsx
.
consumer
.
service
;
package
cn
.
com
.
glsx
.
consumer
.
service
;
import
cn.com.glsx.consumer.common.Contants
;
import
cn.com.glsx.consumer.common.EDay
;
import
cn.com.glsx.consumer.common.EDay
;
import
cn.com.glsx.consumer.common.ELogic
;
import
cn.com.glsx.consumer.common.ELogic
;
import
cn.com.glsx.consumer.entity.DayInfo
;
import
cn.com.glsx.consumer.entity.DayInfo
;
...
@@ -11,6 +12,7 @@ import cn.com.glsx.consumer.entity.SmartSceneData;
...
@@ -11,6 +12,7 @@ import cn.com.glsx.consumer.entity.SmartSceneData;
import
cn.com.glsx.consumer.mapper.DayInfoMapper
;
import
cn.com.glsx.consumer.mapper.DayInfoMapper
;
import
cn.com.glsx.consumer.mapper.SmartDevideStatusMapper
;
import
cn.com.glsx.consumer.mapper.SmartDevideStatusMapper
;
import
cn.com.glsx.consumer.mapper.SmartSceneDataMapper
;
import
cn.com.glsx.consumer.mapper.SmartSceneDataMapper
;
import
cn.com.glsx.consumer.redis.RedisService
;
import
cn.com.glsx.consumer.utils.DateUtils
;
import
cn.com.glsx.consumer.utils.DateUtils
;
import
cn.com.glsx.consumer.utils.HttpUtil
;
import
cn.com.glsx.consumer.utils.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
...
@@ -52,6 +54,9 @@ public class InfoService {
...
@@ -52,6 +54,9 @@ public class InfoService {
@Value
(
"${issueOrderUrl}"
)
@Value
(
"${issueOrderUrl}"
)
private
String
issueOrderUrl
;
private
String
issueOrderUrl
;
@Autowired
private
RedisService
redisService
;
/**
/**
* 处理消息
* 处理消息
*
*
...
@@ -68,21 +73,22 @@ public class InfoService {
...
@@ -68,21 +73,22 @@ public class InfoService {
smartDevideStatusMapper
.
updateByPrimaryKeySelective
(
index
);
smartDevideStatusMapper
.
updateByPrimaryKeySelective
(
index
);
}
}
});
});
list
.
forEach
(
in
->
{
list
.
forEach
(
in
->
{
// 判断该设备是否在用户场景里面
// 判断该设备是否在用户场景里面
List
<
SmartSceneData
>
smartSceneDataList
=
smartSceneDataMapper
.
findSceneDataByDeviceId
(
in
.
getDeviceId
(),
in
.
getDeviceOrderCode
());
List
<
SmartSceneData
>
smartSceneDataList
=
smartSceneDataMapper
.
findSceneDataByDeviceId
(
in
.
getDeviceId
(),
in
.
getDeviceOrderCode
());
if
(
CollectionUtils
.
isEmpty
(
smartSceneDataList
))
{
if
(
CollectionUtils
.
isEmpty
(
smartSceneDataList
))
{
log
.
info
(
"未查到用户场景,设备id{}"
,
in
.
getDeviceId
());
log
.
info
(
"未查到用户场景,设备id{}"
,
in
.
getDeviceId
());
return
;
return
;
}
}
smartSceneDataList
.
forEach
(
index
->
{
smartSceneDataList
.
forEach
(
index
->
{
List
<
SmartSceneData
>
sceneDataList
=
null
;
String
key
=
index
.
getSceneId
()
+
"_"
+
Contants
.
SCENE_STATUS
;
List
<
SmartSceneData
>
sceneDataList
=
null
;
Integer
executeCycle
=
index
.
getExecuteCycle
();
Integer
executeCycle
=
index
.
getExecuteCycle
();
// 判断场景是否触发
// 判断场景是否触发
if
(
index
.
getConditionRule
().
equals
(
"1"
))
{
if
(
index
.
getConditionRule
().
equals
(
"1"
))
{
sceneDataList
=
smartSceneDataMapper
.
findBySceneId
(
index
.
getSceneId
(),
in
.
getDeviceOrderCode
());
sceneDataList
=
smartSceneDataMapper
.
findBySceneId
(
index
.
getSceneId
(),
in
.
getDeviceOrderCode
());
}
else
{
}
else
{
sceneDataList
=
smartSceneDataMapper
.
findBySceneId
(
index
.
getSceneId
(),
null
);
sceneDataList
=
smartSceneDataMapper
.
findBySceneId
(
index
.
getSceneId
(),
null
);
}
}
// 判断场景条件是否配置了时间并且是全部条件满足执行的
// 判断场景条件是否配置了时间并且是全部条件满足执行的
List
<
SmartSceneData
>
scene_condition_time
=
sceneDataList
.
stream
().
filter
(
inx
->
inx
.
getParamKey
().
equals
(
"scene_condition_status"
)).
collect
(
Collectors
.
toList
());
List
<
SmartSceneData
>
scene_condition_time
=
sceneDataList
.
stream
().
filter
(
inx
->
inx
.
getParamKey
().
equals
(
"scene_condition_status"
)).
collect
(
Collectors
.
toList
());
...
@@ -92,6 +98,20 @@ public class InfoService {
...
@@ -92,6 +98,20 @@ public class InfoService {
}
}
boolean
isTrigger
=
conditionStrategy
.
isTrigger
(
scene_condition_time
,
index
.
getConditionRule
(),
boolean
isTrigger
=
conditionStrategy
.
isTrigger
(
scene_condition_time
,
index
.
getConditionRule
(),
(
SmartSceneData
condition
)
->
getTriggerResult
(
condition
));
(
SmartSceneData
condition
)
->
getTriggerResult
(
condition
));
// 温度控制
Object
o
=
redisService
.
get
(
key
);
if
(
isTrigger
&&
!
in
.
getFlag
())
{
if
(
o
==
null
)
{
redisService
.
set
(
key
,
key
);
}
else
{
log
.
info
(
"场景id{}温湿度已经触发过一次"
,
index
.
getSceneId
());
return
;
}
}
// 重新触发的话
if
(!
isTrigger
&&
!
in
.
getFlag
())
{
redisService
.
delete
(
key
);
}
log
.
info
(
"场景id{}---{}触发条件"
,
index
.
getSceneId
(),
isTrigger
?
"符合"
:
"不符合"
);
log
.
info
(
"场景id{}---{}触发条件"
,
index
.
getSceneId
(),
isTrigger
?
"符合"
:
"不符合"
);
if
(
isTrigger
)
{
if
(
isTrigger
)
{
// 下发场景
// 下发场景
...
@@ -118,14 +138,10 @@ public class InfoService {
...
@@ -118,14 +138,10 @@ public class InfoService {
status
.
forEach
(
index
->
{
status
.
forEach
(
index
->
{
SmartDevideStatus
smartDevideStatus
=
smartDevideStatusMapper
.
findDevStatusByIdAndCode
(
deviceStatus
.
getDevId
(),
index
.
getCode
());
SmartDevideStatus
smartDevideStatus
=
smartDevideStatusMapper
.
findDevStatusByIdAndCode
(
deviceStatus
.
getDevId
(),
index
.
getCode
());
// 温度特殊处理
// 温度特殊处理
if
(
smartDevideStatus
!=
null
)
{
if
(
smartDevideStatus
!=
null
)
{
String
code
=
index
.
getCode
();
String
code
=
index
.
getCode
();
String
deviceOrderValue
=
smartDevideStatus
.
getDeviceOrderValue
();
if
(
code
.
equals
(
"va_temperature"
)
||
code
.
equals
(
"va_humidity"
))
{
if
(
code
.
equals
(
"va_temperature"
)
||
code
.
equals
(
"va_humidity"
)){
smartDevideStatus
.
setFlag
(
false
);
if
(
deviceOrderValue
.
substring
(
0
,
deviceOrderValue
.
length
()-
1
).
equals
(
index
.
getValue
().
substring
(
0
,
deviceOrderValue
.
length
()-
1
))){
log
.
info
(
"温湿度误差在0.1之内,不用触发场景"
);
return
;
}
}
}
}
}
if
(
smartDevideStatus
==
null
)
{
if
(
smartDevideStatus
==
null
)
{
...
@@ -173,7 +189,7 @@ public class InfoService {
...
@@ -173,7 +189,7 @@ public class InfoService {
log
.
info
(
"JSON解析异常:ScenseParamValue===="
+
e
.
getMessage
()
+
"===conditionId:"
+
condition
.
getId
());
log
.
info
(
"JSON解析异常:ScenseParamValue===="
+
e
.
getMessage
()
+
"===conditionId:"
+
condition
.
getId
());
return
false
;
return
false
;
}
}
log
.
info
(
"JSON转化后参数{}"
,
paramValue
);
log
.
info
(
"JSON转化后参数{}"
,
paramValue
);
//参数一,设备id
//参数一,设备id
String
deviceId
=
paramValue
.
getSelect
();
String
deviceId
=
paramValue
.
getSelect
();
//参数二,设备指令
//参数二,设备指令
...
@@ -188,8 +204,8 @@ public class InfoService {
...
@@ -188,8 +204,8 @@ public class InfoService {
String
Value
=
null
;
String
Value
=
null
;
//触发状态值,如果value没有值,则取ordervalue
//触发状态值,如果value没有值,则取ordervalue
if
(
deviceOrderCode
.
equals
(
"va_temperature"
)
||
deviceOrderCode
.
equals
(
"va_humidity"
))
{
if
(
deviceOrderCode
.
equals
(
"va_temperature"
)
||
deviceOrderCode
.
equals
(
"va_humidity"
))
{
if
(
StringUtils
.
isNotBlank
(
paramValue
.
getValue
()))
{
if
(
StringUtils
.
isNotBlank
(
paramValue
.
getValue
()))
{
log
.
info
(
"温湿度值为{}"
,
paramValue
.
getValue
());
log
.
info
(
"温湿度值为{}"
,
paramValue
.
getValue
());
Value
=
Integer
.
parseInt
(
paramValue
.
getValue
())
*
10
+
""
;
Value
=
Integer
.
parseInt
(
paramValue
.
getValue
())
*
10
+
""
;
}
}
// 处理特殊温度时候情况
// 处理特殊温度时候情况
...
@@ -205,7 +221,7 @@ public class InfoService {
...
@@ -205,7 +221,7 @@ public class InfoService {
}
}
//根据logic逻辑码,判断触发条件与数据库中实际的值,判断是否满足
//根据logic逻辑码,判断触发条件与数据库中实际的值,判断是否满足
boolean
valueByCode
=
ELogic
.
getValueByCode
(
logic
,
Value
,
smartDevideStatus
.
getDeviceOrderValue
()
==
null
?
""
:
smartDevideStatus
.
getDeviceOrderValue
());
boolean
valueByCode
=
ELogic
.
getValueByCode
(
logic
,
Value
,
smartDevideStatus
.
getDeviceOrderValue
()
==
null
?
""
:
smartDevideStatus
.
getDeviceOrderValue
());
log
.
info
(
"deviceOrderCode为{}的判断是{}"
,
deviceOrderCode
,
valueByCode
);
log
.
info
(
"deviceOrderCode为{}的判断是{}"
,
deviceOrderCode
,
valueByCode
);
return
valueByCode
;
return
valueByCode
;
}
}
}
}
src/main/resources/config/generatorConfig.xml
View file @
44f0d75
...
@@ -68,7 +68,7 @@
...
@@ -68,7 +68,7 @@
</javaClientGenerator>
</javaClientGenerator>
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 -->
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 -->
<table
tableName=
"smart_d
ate"
domainObjectName=
"SmartSceneData
"
enableCountByExample=
"false"
enableUpdateByExample=
"false"
enableDeleteByExample=
"false"
<table
tableName=
"smart_d
evice"
domainObjectName=
"SmartDevice
"
enableCountByExample=
"false"
enableUpdateByExample=
"false"
enableDeleteByExample=
"false"
enableSelectByExample=
"false"
selectByExampleQueryId=
"false"
/>
enableSelectByExample=
"false"
selectByExampleQueryId=
"false"
/>
</context>
</context>
</generatorConfiguration>
</generatorConfiguration>
\ 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