Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
TDLCloud
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WitCloud
TDLCloud
Commits
df813d4c
Commit
df813d4c
authored
Jul 08, 2020
by
Carit Zhu
🎱
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add offset update in redis for updateTDLOffset interface in TDLDeviceController.
parent
132b828f
Pipeline
#419
passed with stage
in 0 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
6 deletions
+57
-6
TDLDeviceMapper.java
src/main/java/com/example/tdl/mapper/TDLDeviceMapper.java
+0
-1
AlarmRule.java
src/main/java/com/example/tdl/util/AlarmRule.java
+39
-2
TDLDeviceController.java
src/main/java/com/example/tdl/web/TDLDeviceController.java
+16
-3
messages_en.properties
src/main/resources/i18n/messages_en.properties
+1
-0
messages_zh_CN.properties
src/main/resources/i18n/messages_zh_CN.properties
+1
-0
No files found.
src/main/java/com/example/tdl/mapper/TDLDeviceMapper.java
View file @
df813d4c
...
@@ -2,7 +2,6 @@ package com.example.tdl.mapper;
...
@@ -2,7 +2,6 @@ package com.example.tdl.mapper;
import
com.example.tdl.domain.vo.*
;
import
com.example.tdl.domain.vo.*
;
import
com.example.tdl.entity.TDLDataOffset
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
...
...
src/main/java/com/example/tdl/util/AlarmRule.java
View file @
df813d4c
package
com
.
example
.
tdl
.
util
;
package
com
.
example
.
tdl
.
util
;
import
com.example.tdl.domain.vo.AlarmRuleVo
;
import
com.example.tdl.domain.vo.AlarmRuleVo
;
import
com.example.tdl.domain.vo.ResultAlarmVo
;
import
com.example.tdl.domain.vo.ResultBoschAlarmVo
;
import
com.example.tdl.domain.vo.ResultBoschAlarmVo
;
import
com.example.tdl.entity.TDLDataOffset
;
import
com.example.tdl.entity.TDLDataOffset
;
import
com.example.tdl.service.AlarmService
;
import
com.example.tdl.service.BoschAlarmService
;
import
com.example.tdl.service.BoschAlarmService
;
import
com.example.tdl.service.redis.AlarmRedisService
;
import
com.example.tdl.service.redis.AlarmRedisService
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonSyntaxException
;
import
com.google.gson.reflect.TypeToken
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
public
class
AlarmRule
{
public
class
AlarmRule
{
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
AlarmRule
.
class
);
private
static
Gson
gson
=
new
Gson
();
private
static
Gson
gson
=
new
Gson
();
...
@@ -96,4 +99,38 @@ public class AlarmRule {
...
@@ -96,4 +99,38 @@ public class AlarmRule {
alarmRedisService
.
hmSet
(
topic
,
"TDL-"
+
TDLSN
+
"_"
+
alias
,
gson
.
toJson
(
alarmRuleVos
));
alarmRedisService
.
hmSet
(
topic
,
"TDL-"
+
TDLSN
+
"_"
+
alias
,
gson
.
toJson
(
alarmRuleVos
));
}
}
}
}
public
static
void
updateOffset
(
String
topic
,
String
TDLSN
,
String
alias
,
Double
offset
,
AlarmRedisService
alarmRedisService
)
{
try
{
String
hashKey
=
"TDL-"
+
TDLSN
+
"_"
+
alias
;
/* Get alarm rule from redis */
Object
hashValueObject
=
alarmRedisService
.
getHash
(
topic
,
hashKey
);
List
<
AlarmRuleVo
>
alarmRuleList
=
gson
.
fromJson
(
hashValueObject
.
toString
(),
new
TypeToken
<
ArrayList
<
AlarmRuleVo
>>()
{}.
getType
());
/* Update offset */
if
(
alarmRuleList
!=
null
&&
alarmRuleList
.
size
()
>
0
)
{
alarmRuleList
.
get
(
0
).
setOffset
(
offset
);
/* Write back to redis */
alarmRedisService
.
hmSet
(
topic
,
hashKey
,
gson
.
toJson
(
alarmRuleList
));
}
}
catch
(
JsonSyntaxException
e
)
{
logger
.
error
(
"Update offset("
+
alias
+
") JsonSyntaxException: "
+
e
.
getMessage
());
}
}
public
static
void
updateOffset
(
String
topic
,
String
TDLSN
,
TDLDataOffset
offset
,
AlarmRedisService
alarmRedisService
)
{
if
(
offset
==
null
)
return
;
/* 更新温度校准值 */
if
(
offset
.
getTempOffset
()
!=
null
)
{
updateOffset
(
topic
,
TDLSN
,
"T"
,
offset
.
getTempOffset
(),
alarmRedisService
);
}
/* 更新湿度校准值 */
if
(
offset
.
getHumidityOffset
()
!=
null
)
{
updateOffset
(
topic
,
TDLSN
,
"h"
,
offset
.
getHumidityOffset
(),
alarmRedisService
);
}
}
}
}
src/main/java/com/example/tdl/web/TDLDeviceController.java
View file @
df813d4c
...
@@ -7,7 +7,9 @@ import com.example.tdl.domain.dto.CommFeedback;
...
@@ -7,7 +7,9 @@ import com.example.tdl.domain.dto.CommFeedback;
import
com.example.tdl.domain.vo.*
;
import
com.example.tdl.domain.vo.*
;
import
com.example.tdl.entity.TDLDataOffset
;
import
com.example.tdl.entity.TDLDataOffset
;
import
com.example.tdl.service.TDLDeviceService
;
import
com.example.tdl.service.TDLDeviceService
;
import
com.example.tdl.service.redis.AlarmRedisService
;
import
com.example.tdl.service.redis.TokenRedisService
;
import
com.example.tdl.service.redis.TokenRedisService
;
import
com.example.tdl.util.AlarmRule
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiImplicitParams
;
...
@@ -20,7 +22,6 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -20,7 +22,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
retrofit2.http.HTTP
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
...
@@ -41,6 +42,8 @@ public class TDLDeviceController {
...
@@ -41,6 +42,8 @@ public class TDLDeviceController {
@Autowired
@Autowired
private
TokenRedisService
tokenRedisService
;
private
TokenRedisService
tokenRedisService
;
@Autowired
private
AlarmRedisService
alarmRedisService
;
@Autowired
@Autowired
private
I18nController
i18n
;
private
I18nController
i18n
;
...
@@ -292,8 +295,18 @@ public class TDLDeviceController {
...
@@ -292,8 +295,18 @@ public class TDLDeviceController {
String
offset
=
gson
.
toJson
(
updateTDLOffsetVo
.
getOffset
(),
TDLDataOffset
.
class
);
String
offset
=
gson
.
toJson
(
updateTDLOffsetVo
.
getOffset
(),
TDLDataOffset
.
class
);
int
a
=
tdlDeviceService
.
updateTDLOffset
(
updateTDLOffsetVo
.
getTdlSN
(),
offset
);
int
a
=
tdlDeviceService
.
updateTDLOffset
(
updateTDLOffsetVo
.
getTdlSN
(),
offset
);
if
(
a
>=
0
){
if
(
a
>=
0
){
fb
.
setCode
(
1
);
/* 更新Redis里面的offset信息 */
fb
.
setMessage
(
i18n
.
getMessage
(
request
,
"updateTDLOffsetSuccess"
));
ResultTDLDeviceVo
resultTDLDeviceVo
=
tdlDeviceService
.
getByTDLSN
(
updateTDLOffsetVo
.
getTdlSN
());
if
(
resultTDLDeviceVo
.
getGatewaySN
()
!=
null
&&
resultTDLDeviceVo
.
getGatewayType
()
!=
null
)
{
String
topic
=
"TDL/"
+
resultTDLDeviceVo
.
getGatewayType
()+
"/"
+
resultTDLDeviceVo
.
getGatewaySN
()+
"/Data"
;
AlarmRule
.
updateOffset
(
topic
,
updateTDLOffsetVo
.
getTdlSN
(),
updateTDLOffsetVo
.
getOffset
(),
alarmRedisService
);
fb
.
setCode
(
1
);
fb
.
setMessage
(
i18n
.
getMessage
(
request
,
"updateTDLOffsetSuccess"
));
}
else
{
fb
.
setCode
(
0
);
fb
.
setMessage
(
i18n
.
getMessage
(
request
,
"TDLNotBoundGateway"
));
}
}
else
{
}
else
{
fb
.
setCode
(
0
);
fb
.
setCode
(
0
);
fb
.
setMessage
(
i18n
.
getMessage
(
request
,
"updateTDLOffsetFailure"
));
fb
.
setMessage
(
i18n
.
getMessage
(
request
,
"updateTDLOffsetFailure"
));
...
...
src/main/resources/i18n/messages_en.properties
View file @
df813d4c
...
@@ -212,6 +212,7 @@ updateTDLCompanyFailure=Failed to allocate the sensor to the company
...
@@ -212,6 +212,7 @@ updateTDLCompanyFailure=Failed to allocate the sensor to the company
wrongTDLOffset
=
Offset of sensor cannot be empty
wrongTDLOffset
=
Offset of sensor cannot be empty
updateTDLOffsetSuccess
=
Update TDL offset successfully
updateTDLOffsetSuccess
=
Update TDL offset successfully
updateTDLOffsetFailure
=
Update TDL offset failed
updateTDLOffsetFailure
=
Update TDL offset failed
TDLNotBoundGateway
=
TDL not bound to gateway
warehouseName
=
Warehouse's name must not be null
warehouseName
=
Warehouse's name must not be null
property
=
Warehouse's property must not be null
property
=
Warehouse's property must not be null
wrongProperty
=
Please enter the correct property
wrongProperty
=
Please enter the correct property
...
...
src/main/resources/i18n/messages_zh_CN.properties
View file @
df813d4c
...
@@ -240,6 +240,7 @@ updateTDLCompanyFailure=\u4F20\u611F\u5668\u5206\u914D\u516C\u53F8\u5931\u8D25
...
@@ -240,6 +240,7 @@ updateTDLCompanyFailure=\u4F20\u611F\u5668\u5206\u914D\u516C\u53F8\u5931\u8D25
wrongTDLOffset
=
\u
4F20
\u
611F
\u5668\u6821\u
51C6
\u
503C
\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
wrongTDLOffset
=
\u
4F20
\u
611F
\u5668\u6821\u
51C6
\u
503C
\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
updateTDLOffsetSuccess
=
\u
4F20
\u
611F
\u5668\u
4FEE
\u6539\u6821\u
51C6
\u
503C
\u6210\u
529F
updateTDLOffsetSuccess
=
\u
4F20
\u
611F
\u5668\u
4FEE
\u6539\u6821\u
51C6
\u
503C
\u6210\u
529F
updateTDLOffsetFailure
=
\u
4F20
\u
611F
\u5668\u
4FEE
\u6539\u6821\u
51C6
\u
503C
\u5931\u
8D25
updateTDLOffsetFailure
=
\u
4F20
\u
611F
\u5668\u
4FEE
\u6539\u6821\u
51C6
\u
503C
\u5931\u
8D25
TDLNotBoundGateway
=
\u
4F20
\u
611F
\u5668\u
672A
\u
7ED1
\u
5B9A
\u
7F51
\u5173
#\u4ED3\u5E93
#\u4ED3\u5E93
warehouseName
=
\u
4ED3
\u
5E93
\u
540D
\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
warehouseName
=
\u
4ED3
\u
5E93
\u
540D
\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
property
=
\u
4ED3
\u
5E93
\u
5C5E
\u6027\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
property
=
\u
4ED3
\u
5E93
\u
5C5E
\u6027\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment