Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
glsx-rest-admin-job-archetype
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 27cfc60f
authored
Apr 21, 2021
by
fz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1.时间触发条件添加大于,小于判断异
1 parent
c5e8ff01
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
20 deletions
glsx-rest-admin-job/src/main/java/cn/com/glsx/smartdevice/Common/ELogic.java
glsx-rest-admin-job/src/main/java/cn/com/glsx/smartdevice/service/SceneService.java
glsx-rest-admin-job/src/main/java/cn/com/glsx/smartdevice/Common/ELogic.java
View file @
27cfc60
...
@@ -19,6 +19,11 @@ public enum ELogic {
...
@@ -19,6 +19,11 @@ public enum ELogic {
}
}
@Override
@Override
public
boolean
getDate
(
long
dateCondition
,
long
dateNow
)
{
return
dateNow
<
dateCondition
;
}
@Override
public
String
getName
(){
public
String
getName
(){
return
"小于"
;
return
"小于"
;
}
}
...
@@ -34,6 +39,11 @@ public enum ELogic {
...
@@ -34,6 +39,11 @@ public enum ELogic {
return
Double
.
parseDouble
(
deviceOrderValueReal
)
>
Double
.
parseDouble
(
deviceOrderValue
);
return
Double
.
parseDouble
(
deviceOrderValueReal
)
>
Double
.
parseDouble
(
deviceOrderValue
);
}
}
@Override
public
boolean
getDate
(
long
dateCondition
,
long
dateNow
)
{
return
dateNow
>
dateCondition
;
}
@Override
@Override
public
String
getName
(){
public
String
getName
(){
...
@@ -51,6 +61,11 @@ public enum ELogic {
...
@@ -51,6 +61,11 @@ public enum ELogic {
return
deviceOrderValueReal
.
equals
(
deviceOrderValue
);
return
deviceOrderValueReal
.
equals
(
deviceOrderValue
);
}
}
@Override
public
boolean
getDate
(
long
dateCondition
,
long
dateNow
)
{
return
dateNow
==
dateCondition
;
}
@Override
@Override
public
String
getName
(){
public
String
getName
(){
...
@@ -67,6 +82,15 @@ public enum ELogic {
...
@@ -67,6 +82,15 @@ public enum ELogic {
return
false
;
return
false
;
}
}
public
static
boolean
getDateByCode
(
Integer
code
,
long
dateCondition
,
long
dateNow
)
{
for
(
ELogic
day
:
ELogic
.
values
())
{
if
(
day
.
getCode
().
equals
(
code
))
{
return
day
.
getDate
(
dateCondition
,
dateNow
);
}
}
return
false
;
}
public
static
String
getNameByCode
(
Integer
code
)
{
public
static
String
getNameByCode
(
Integer
code
)
{
for
(
ELogic
day
:
ELogic
.
values
())
{
for
(
ELogic
day
:
ELogic
.
values
())
{
if
(
day
.
getCode
().
equals
(
code
))
{
if
(
day
.
getCode
().
equals
(
code
))
{
...
@@ -81,5 +105,7 @@ public enum ELogic {
...
@@ -81,5 +105,7 @@ public enum ELogic {
//deviceOrderValue:触发条件中的设备状态值,deviceOrderValueReal:数据库中的设备状态值
//deviceOrderValue:触发条件中的设备状态值,deviceOrderValueReal:数据库中的设备状态值
public
abstract
boolean
getValue
(
String
deviceOrderValue
,
String
deviceOrderValueReal
);
public
abstract
boolean
getValue
(
String
deviceOrderValue
,
String
deviceOrderValueReal
);
public
abstract
boolean
getDate
(
long
deviceOrderValue
,
long
deviceOrderValueReal
);
public
abstract
String
getName
();
public
abstract
String
getName
();
}
}
glsx-rest-admin-job/src/main/java/cn/com/glsx/smartdevice/service/SceneService.java
View file @
27cfc60
...
@@ -23,6 +23,8 @@ import org.apache.commons.lang3.StringUtils;
...
@@ -23,6 +23,8 @@ import org.apache.commons.lang3.StringUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
/**
/**
...
@@ -62,20 +64,20 @@ public class SceneService {
...
@@ -62,20 +64,20 @@ public class SceneService {
log
.
error
(
"创建策略失败:"
+
e
.
getMessage
());
log
.
error
(
"创建策略失败:"
+
e
.
getMessage
());
}
}
if
(
null
!=
conditionStrategy
)
{
if
(
null
!=
conditionStrategy
)
{
//获取当前时间
//获取当前时间
long
rangeBegintTime
=
System
.
currentTimeMillis
();
long
rangeBegintTime
=
System
.
currentTimeMillis
();
//判断当前日期,转为周期类型
//判断当前日期,转为周期类型
Integer
executeCycle
=
getExecuteCycle
();
Integer
executeCycle
=
getExecuteCycle
();
if
(
null
==
executeCycle
)
{
if
(
null
==
executeCycle
)
{
log
.
info
(
"查询周期失败,无法获取对应的周期"
);
log
.
info
(
"查询周期失败,无法获取对应的周期"
);
return
;
return
;
}
}
//获取符合周期类型且满足判断策略(任意满足,全部满足触发)的触发条件
//获取符合周期类型且满足判断策略(任意满足,全部满足触发)的触发条件
List
<
ScenseData
>
dataAnyCondition
=
conditionStrategy
.
getScenseData
(
executeCycle
);
List
<
ScenseData
>
dataAnyCondition
=
conditionStrategy
.
getScenseData
(
executeCycle
);
if
(
CollectionUtils
.
isEmpty
(
dataAnyCondition
))
{
if
(
CollectionUtils
.
isEmpty
(
dataAnyCondition
))
{
log
.
info
(
"无触发条件:"
+
executeCycle
);
log
.
info
(
"无触发条件:"
+
executeCycle
);
return
;
return
;
}
}
...
@@ -92,7 +94,7 @@ public class SceneService {
...
@@ -92,7 +94,7 @@ public class SceneService {
//判断当前场景的触发情况(时间符合或者设备状态符合)
//判断当前场景的触发情况(时间符合或者设备状态符合)
boolean
isTrigger
=
finalConditionStrategy
.
isTrigger
(
dataList
,
rangeBegintTime
,
boolean
isTrigger
=
finalConditionStrategy
.
isTrigger
(
dataList
,
rangeBegintTime
,
(
ScenseData
condition
)
->
getTriggerResult
(
rangeBegintTime
,
condition
,
conditionType
));
(
ScenseData
condition
)
->
getTriggerResult
(
rangeBegintTime
,
condition
,
conditionType
));
if
(
isTrigger
)
{
if
(
isTrigger
)
{
//如果符合触发场景,推送kafka
//如果符合触发场景,推送kafka
...
@@ -107,10 +109,11 @@ public class SceneService {
...
@@ -107,10 +109,11 @@ public class SceneService {
//todo 如果耗时过长,计划采用分片
//todo 如果耗时过长,计划采用分片
//打印耗时
//打印耗时
long
time
=
System
.
currentTimeMillis
()
-
rangeBegintTime
;
long
time
=
System
.
currentTimeMillis
()
-
rangeBegintTime
;
log
.
info
(
"execute====time:"
+
time
+
"====conditionType:"
+
conditionType
);
log
.
info
(
"execute====time:"
+
time
+
"====conditionType:"
+
conditionType
);
}
}
}
}
//根据当前时间对应的执行周期类型
//根据当前时间对应的执行周期类型
private
Integer
getExecuteCycle
()
{
private
Integer
getExecuteCycle
()
{
//判断当天的日类型
//判断当天的日类型
...
@@ -137,7 +140,7 @@ public class SceneService {
...
@@ -137,7 +140,7 @@ public class SceneService {
scenseDataList
=
new
ArrayList
<>();
scenseDataList
=
new
ArrayList
<>();
}
}
if
(!
Constants
.
CONDITION_CLICK
.
equals
(
data
.
getParamKey
()))
if
(!
Constants
.
CONDITION_CLICK
.
equals
(
data
.
getParamKey
()))
scenseDataList
.
add
(
data
);
scenseDataList
.
add
(
data
);
scenseDataMap
.
put
(
scenseId
,
scenseDataList
);
scenseDataMap
.
put
(
scenseId
,
scenseDataList
);
});
});
...
@@ -146,13 +149,13 @@ public class SceneService {
...
@@ -146,13 +149,13 @@ public class SceneService {
}
}
//触发条件判断
//触发条件判断
private
boolean
getTriggerResult
(
long
rangeBegintTime
,
ScenseData
condition
,
int
conditionType
)
{
private
boolean
getTriggerResult
(
long
rangeBegintTime
,
ScenseData
condition
,
int
conditionType
)
{
String
key
=
condition
.
getParamKey
();
String
key
=
condition
.
getParamKey
();
String
value
=
condition
.
getParamValue
();
String
value
=
condition
.
getParamValue
();
//log.info("fz====scenseId:"+condition.getSceneId()+"===key:"+key+"==VAL:"+value);
//log.info("fz====scenseId:"+condition.getSceneId()+"===key:"+key+"==VAL:"+value);
if
(
StringUtils
.
isEmpty
(
value
))
{
if
(
StringUtils
.
isEmpty
(
value
))
{
log
.
info
(
"触发条件的value不存在===id:"
+
condition
.
getId
());
log
.
info
(
"触发条件的value不存在===id:"
+
condition
.
getId
());
return
false
;
return
false
;
}
}
...
@@ -160,7 +163,7 @@ public class SceneService {
...
@@ -160,7 +163,7 @@ public class SceneService {
try
{
try
{
paramValue
=
JSON
.
parseObject
(
JSON
.
parse
(
value
).
toString
(),
ScenseParamValue
.
class
);
paramValue
=
JSON
.
parseObject
(
JSON
.
parse
(
value
).
toString
(),
ScenseParamValue
.
class
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
info
(
"JSON解析异常:ScenseParamValue===="
+
e
.
getMessage
()+
"===conditionId:"
+
condition
.
getId
()+
"===conditionType:"
+
conditionType
);
log
.
info
(
"JSON解析异常:ScenseParamValue===="
+
e
.
getMessage
()
+
"===conditionId:"
+
condition
.
getId
()
+
"===conditionType:"
+
conditionType
);
return
false
;
return
false
;
}
}
...
@@ -171,37 +174,57 @@ public class SceneService {
...
@@ -171,37 +174,57 @@ public class SceneService {
String
deviceId
=
paramValue
.
getSelect
();
String
deviceId
=
paramValue
.
getSelect
();
//参数二,设备指令
//参数二,设备指令
String
deviceOrderCode
=
paramValue
.
getOrder
();
String
deviceOrderCode
=
paramValue
.
getOrder
();
//参数三,逻辑
(1:<,2:>,3:=)
//参数三,逻辑
int
logic
=
Integer
.
parseInt
(
paramValue
.
getOrderCondition
());
int
logic
=
Integer
.
parseInt
(
paramValue
.
getOrderCondition
());
//参数四,值
//参数四,值
//触发状态值,如果value没有值,则取ordervalue
//触发状态值,如果value没有值,则取ordervalue
String
Value
=
paramValue
.
getValue
();
String
Value
=
paramValue
.
getValue
();
if
(
StringUtils
.
isEmpty
(
Value
))
{
if
(
StringUtils
.
isEmpty
(
Value
))
{
Value
=
paramValue
.
getOrderVal
();
Value
=
paramValue
.
getOrderVal
();
if
(
StringUtils
.
isEmpty
(
Value
))
{
if
(
StringUtils
.
isEmpty
(
Value
))
{
log
.
info
(
"设备触发状态值不存在===deviceId:"
+
deviceId
+
"===deviceOrderCode:"
+
deviceOrderCode
+
"===conditionType:"
+
conditionType
);
log
.
info
(
"设备触发状态值不存在===deviceId:"
+
deviceId
+
"===deviceOrderCode:"
+
deviceOrderCode
+
"===conditionType:"
+
conditionType
);
return
false
;
return
false
;
}
}
}
}
DeviceStatus
status
=
deviceStatusMapper
.
getByIdAndCode
(
deviceId
,
deviceOrderCode
);
DeviceStatus
status
=
deviceStatusMapper
.
getByIdAndCode
(
deviceId
,
deviceOrderCode
);
if
(
null
==
status
)
{
if
(
null
==
status
)
{
log
.
info
(
"设备状态不存在===deviceId:"
+
deviceId
+
"===deviceOrderCode:"
+
deviceOrderCode
+
"===conditionType:"
+
conditionType
);
log
.
info
(
"设备状态不存在===deviceId:"
+
deviceId
+
"===deviceOrderCode:"
+
deviceOrderCode
+
"===conditionType:"
+
conditionType
);
return
false
;
return
false
;
}
}
//根据logic逻辑码,判断触发条件与数据库中实际的值,判断是否满足
//根据logic逻辑码,判断触发条件与数据库中实际的值,判断是否满足
//log.info("fz===scenseId:"+condition.getSceneId()+"===condition_val:"+Value+"====realval:"+status.getDeviceOrderValue()+"===logic:"+logic);
//log.info("fz===scenseId:"+condition.getSceneId()+"===condition_val:"+Value+"====realval:"+status.getDeviceOrderValue()+"===logic:"+logic);
return
ELogic
.
getValueByCode
(
logic
,
Value
,
status
.
getDeviceOrderValue
());
return
ELogic
.
getValueByCode
(
logic
,
Value
,
status
.
getDeviceOrderValue
());
}
}
//scene_condition_time指定时间
//scene_condition_time指定时间
if
(
Constants
.
CONDITION_TIME
.
equals
(
key
))
{
if
(
Constants
.
CONDITION_TIME
.
equals
(
key
))
{
//触发时间(时分)与当前时间(时分)是否相同
//触发时间(时分)与当前时间(时分)是否相同
return
ELogic
.
getValueByCode
(
ELogic
.
EQUALS
.
getCode
(),
paramValue
.
getDate
(),
DateUtils
.
getDate
(
new
Date
(
rangeBegintTime
),
"HH:mm"
));
}
//触发设置的时间
String
dateCondition
=
paramValue
.
getDate
();
//触发规则,逻辑(1:<,2:>,3:=)
String
select
=
paramValue
.
getSelect
();
//现在的时间
String
datenow
=
DateUtils
.
getDate
(
new
Date
(
rangeBegintTime
),
"HH:mm"
);
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"HH:mm"
);
try
{
long
dateConditionlong
=
df
.
parse
(
dateCondition
).
getTime
();
long
datenowlong
=
df
.
parse
(
datenow
).
getTime
();
return
ELogic
.
getDateByCode
(
Integer
.
valueOf
(
select
),
dateConditionlong
,
datenowlong
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
log
.
info
(
"时间解析异常===key:"
+
key
+
"===value:"
+
value
+
"===conditionType:"
+
conditionType
);
return
false
;
}
}
return
false
;
return
false
;
}
}
}
}
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