Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zhny
Project
Project
Details
Activity
Releases
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
王夏晖
zhny
Commits
2b9a3278
Commit
2b9a3278
authored
Sep 21, 2018
by
jichao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
53eb12c6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
43 deletions
+42
-43
BusDeviceRepository.java
...isoft/business/device/assets/dao/BusDeviceRepository.java
+5
-4
BusDeviceServiceImpl.java
...ness/device/assets/service/impl/BusDeviceServiceImpl.java
+2
-2
BusDeviceTask.java
.../java/org/rcisoft/business/device/task/BusDeviceTask.java
+1
-1
SystemServiceImpl.java
...isoft/business/system/service/impl/SystemServiceImpl.java
+32
-36
ParamStatus.java
...main/java/org/rcisoft/business/system/vo/ParamStatus.java
+2
-0
No files found.
src/main/java/org/rcisoft/business/device/assets/dao/BusDeviceRepository.java
View file @
2b9a3278
...
@@ -2,9 +2,9 @@ package org.rcisoft.business.device.assets.dao;
...
@@ -2,9 +2,9 @@ package org.rcisoft.business.device.assets.dao;
import
org.apache.ibatis.annotations.*
;
import
org.apache.ibatis.annotations.*
;
import
org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo
;
import
org.rcisoft.business.device.assets.vo.DeviceAssetStatisticVo
;
import
org.rcisoft.core.base.BaseMapper
;
import
org.rcisoft.business.device.assets.entity.BusDevice
;
import
org.rcisoft.business.device.assets.entity.BusDevice
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Repository
;
import
tk.mybatis.mapper.common.Mapper
;
import
java.util.List
;
import
java.util.List
;
...
@@ -14,7 +14,7 @@ import java.util.Map;
...
@@ -14,7 +14,7 @@ import java.util.Map;
* Created with on 2018-4-12 15:33:23.
* Created with on 2018-4-12 15:33:23.
*/
*/
@Repository
@Repository
public
interface
BusDeviceRepository
extends
Base
Mapper
<
BusDevice
>
{
public
interface
BusDeviceRepository
extends
Mapper
<
BusDevice
>
{
/**
/**
* 分页查询 busDevice
* 分页查询 busDevice
...
@@ -73,9 +73,10 @@ public interface BusDeviceRepository extends BaseMapper<BusDevice> {
...
@@ -73,9 +73,10 @@ public interface BusDeviceRepository extends BaseMapper<BusDevice> {
* @return
* @return
*/
*/
@Select
(
"<script>select d.DEV_ID,d.SHUT_POWER,d.RUN_TM,sum(e.elec) ELEC from bus_device d,bus_device_meter m,energy_count_m e "
+
@Select
(
"<script>select d.DEV_ID,d.SHUT_POWER,d.RUN_TM,sum(e.elec) ELEC from bus_device d,bus_device_meter m,energy_count_m e "
+
"where d.DEV_NUM=m.DEV_NUM and m.MET_NUM=e.MET_NUM and date_format(e.CREATE_TIME, '%Y-%m-%d %H:%i')=#{time}"
+
"where d.DEV_NUM=m.DEV_NUM and m.MET_NUM=e.MET_NUM and date_format(e.CREATE_TIME, '%Y-%m-%d %H:%i')=#{time}
"
+
"group by d.DEV_ID,d.SHUT_POWER,d.RUN_TM</script>"
)
"group by d.DEV_ID,d.SHUT_POWER,d.RUN_TM</script>"
)
List
<
Map
<
String
,
Object
>>
addRunTime
(
@Param
(
"time"
)
String
time
);
@ResultType
(
Map
.
class
)
List
<
Map
<
String
,
Object
>>
selectRunTime
(
@Param
(
"time"
)
String
time
);
/**
/**
* 批量更新设备的运行时长
* 批量更新设备的运行时长
...
...
src/main/java/org/rcisoft/business/device/assets/service/impl/BusDeviceServiceImpl.java
View file @
2b9a3278
...
@@ -229,9 +229,9 @@ public class BusDeviceServiceImpl implements BusDeviceService {
...
@@ -229,9 +229,9 @@ public class BusDeviceServiceImpl implements BusDeviceService {
//最后需要保存的数据
//最后需要保存的数据
List
<
BusDevice
>
saveList
=
new
ArrayList
<>();
List
<
BusDevice
>
saveList
=
new
ArrayList
<>();
//得到当前时间前10分钟的时间
//得到当前时间前10分钟的时间
String
time
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
).
format
(
new
Date
(
System
.
currentTimeMillis
()
-
6
00000
));
String
time
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
).
format
(
new
Date
(
System
.
currentTimeMillis
()
-
9
00000
));
//查询10分钟前所有数据的耗电量信息
//查询10分钟前所有数据的耗电量信息
List
<
Map
<
String
,
Object
>>
list
=
busDeviceRepository
.
add
RunTime
(
time
);
List
<
Map
<
String
,
Object
>>
list
=
busDeviceRepository
.
select
RunTime
(
time
);
list
.
forEach
(
map
->
{
list
.
forEach
(
map
->
{
BigDecimal
shutPower
=
(
BigDecimal
)
map
.
get
(
"SHUT_POWER"
);
BigDecimal
shutPower
=
(
BigDecimal
)
map
.
get
(
"SHUT_POWER"
);
shutPower
=
shutPower
==
null
?
new
BigDecimal
(
0
)
:
shutPower
;
shutPower
=
shutPower
==
null
?
new
BigDecimal
(
0
)
:
shutPower
;
...
...
src/main/java/org/rcisoft/business/device/task/BusDeviceTask.java
View file @
2b9a3278
...
@@ -18,7 +18,7 @@ public class BusDeviceTask {
...
@@ -18,7 +18,7 @@ public class BusDeviceTask {
/**
/**
* 每10分钟查询更新一次
* 每10分钟查询更新一次
*/
*/
@Scheduled
(
cron
=
"0
0/10
* * * ?"
)
@Scheduled
(
cron
=
"0
5,15,25,35,45,55
* * * ?"
)
public
void
runTime
()
{
public
void
runTime
()
{
busDeviceServiceImpl
.
addRunTime
();
busDeviceServiceImpl
.
addRunTime
();
}
}
...
...
src/main/java/org/rcisoft/business/system/service/impl/SystemServiceImpl.java
View file @
2b9a3278
...
@@ -179,23 +179,44 @@ public class SystemServiceImpl implements SystemService {
...
@@ -179,23 +179,44 @@ public class SystemServiceImpl implements SystemService {
@Override
@Override
public
String
selectDataByCache
(
String
proId
)
{
public
String
selectDataByCache
(
String
proId
)
{
String
newData
=
redisServiceImpl
.
get
(
proId
);
// String newData = redisServiceImpl.get(proId);
String
oldData
=
redisServiceImpl
.
get
(
proId
+
"-old"
);
// String oldData = redisServiceImpl.get(proId + "-old");
return
"{\"newData\":"
+
newData
+
",\"oldData\":"
+
oldData
+
"}"
;
// return "{\"newData\":" + newData + ",\"oldData\":" + oldData + "}";
return
redisServiceImpl
.
get
(
proId
);
}
}
@Override
@Override
public
List
<
ParamStatus
>
selectDeviceAll
(
String
proId
)
{
public
List
<
ParamStatus
>
selectDeviceAll
(
String
proId
)
{
// 根据proId得到redis中的数据
String
data
=
redisServiceImpl
.
get
(
proId
);
// 得到json数据
JSONObject
json
=
JSON
.
parseObject
(
data
);
List
<
ParamStatus
>
list
=
deviceParamRepository
.
selectDeviceAll
(
proId
);
List
<
ParamStatus
>
list
=
deviceParamRepository
.
selectDeviceAll
(
proId
);
list
.
forEach
(
paramStatus
->
{
list
.
forEach
(
paramStatus
->
{
// 设备来源
String
devNum
=
paramStatus
.
getDevNum
();
String
devNum
=
paramStatus
.
getDevNum
();
// 参数
String
param
=
paramStatus
.
getParam
();
// 如果devNum不是空,截取字符串
// 如果devNum不是空,截取字符串
if
(
StringUtils
.
isNotEmpty
(
devNum
))
{
if
(
StringUtils
.
isNotEmpty
(
devNum
))
{
devNum
=
devNum
.
split
(
proId
+
"_"
)[
1
];
devNum
=
devNum
.
split
(
proId
+
"_"
)[
1
];
}
}
paramStatus
.
setDevNum
(
devNum
);
paramStatus
.
setDevNum
(
devNum
);
// 默认都设为掉线状态
// 默认都设为掉线状态
paramStatus
.
setStatus
(
2
);
// paramStatus.setStatus(2);
// 默认值为0
paramStatus
.
setValue
(
0
);
// 获得数据
JSONObject
jsonObject
=
(
JSONObject
)
json
.
get
(
devNum
);
if
(
jsonObject
!=
null
)
{
JSONObject
valueObject
=
(
JSONObject
)
jsonObject
.
get
(
"REG_VAL"
);
if
(
valueObject
!=
null
)
{
Object
value
=
valueObject
.
get
(
param
);
if
(
value
!=
null
)
{
paramStatus
.
setValue
(
value
);
}
}
}
});
});
return
list
;
return
list
;
}
}
...
@@ -211,55 +232,30 @@ public class SystemServiceImpl implements SystemService {
...
@@ -211,55 +232,30 @@ public class SystemServiceImpl implements SystemService {
if
(!
proId
.
equals
(
""
))
{
if
(!
proId
.
equals
(
""
))
{
// 根据proId得到redis中的数据
// 根据proId得到redis中的数据
String
newData
=
redisServiceImpl
.
get
(
proId
);
String
newData
=
redisServiceImpl
.
get
(
proId
);
String
oldData
=
redisServiceImpl
.
get
(
proId
+
"-old"
);
// 循环list,根据param查询数据,新的-旧的 > 0.003:认为是开启状态
JSONObject
newJson
=
JSON
.
parseObject
(
newData
);
JSONObject
newJson
=
JSON
.
parseObject
(
newData
);
JSONObject
oldJson
=
JSON
.
parseObject
(
oldData
);
if
(
newJson
!=
null
)
{
if
(
newJson
!=
null
&&
oldJson
!=
null
)
{
// 循环,获取两个数据做对比
// 循环,获取两个数据做对比
for
(
ParamStatus
paramStatus
:
paramStatusList
)
{
for
(
ParamStatus
paramStatus
:
paramStatusList
)
{
String
devNum
=
paramStatus
.
getDevNum
();
String
devNum
=
paramStatus
.
getDevNum
();
String
param
=
paramStatus
.
getParam
();
String
param
=
paramStatus
.
getParam
();
if
(
StringUtils
.
isNotEmpty
(
devNum
)
&&
StringUtils
.
isNotEmpty
(
param
))
{
if
(
StringUtils
.
isNotEmpty
(
devNum
)
&&
StringUtils
.
isNotEmpty
(
param
))
{
BigDecimal
newElec
=
null
,
oldElec
=
null
;
// 新数据
// 新数据
JSONObject
newObj
=
(
JSONObject
)
newJson
.
get
(
devNum
);
JSONObject
newObj
=
(
JSONObject
)
newJson
.
get
(
devNum
);
if
(
newObj
!=
null
)
{
if
(
newObj
!=
null
)
{
//
先判断设备中的status,如果=0,是掉线状态,用2表示
//
赋值status
Integer
status
=
(
Integer
)
newObj
.
get
(
"status"
);
Integer
status
=
(
Integer
)
newObj
.
get
(
"status"
);
if
(
status
==
0
)
{
// status=1,在线状态,继续判断
paramStatus
.
setStatus
(
2
);
// status=0,掉线状态,前台直接变成掉线状态
continue
;
paramStatus
.
setStatus
(
status
);
}
JSONObject
newVal
=
(
JSONObject
)
newObj
.
get
(
"REG_VAL"
);
JSONObject
newVal
=
(
JSONObject
)
newObj
.
get
(
"REG_VAL"
);
if
(
newVal
!=
null
)
{
if
(
newVal
!=
null
)
{
Object
o
=
newVal
.
get
(
param
);
Object
o
=
newVal
.
get
(
param
);
if
(
o
!=
null
)
{
if
(
o
!=
null
)
{
newElec
=
new
BigDecimal
(
o
.
toString
());
// 赋值value
paramStatus
.
setValue
(
o
);
}
}
}
}
}
}
// 旧数据
JSONObject
oldObj
=
(
JSONObject
)
oldJson
.
get
(
devNum
);
if
(
oldObj
!=
null
)
{
JSONObject
oldVal
=
(
JSONObject
)
oldObj
.
get
(
"REG_VAL"
);
if
(
oldVal
!=
null
)
{
Object
o
=
oldVal
.
get
(
param
);
if
(
o
!=
null
)
{
oldElec
=
new
BigDecimal
(
o
.
toString
());
}
}
}
// 判断两个比较电量大小
if
(
newElec
!=
null
&&
oldElec
!=
null
)
{
// 如果两数相减小于0.003,认为是关闭,大于等于认为是开启
if
(
newElec
.
subtract
(
oldElec
).
compareTo
(
new
BigDecimal
(
0.001
))
<
0
)
paramStatus
.
setStatus
(
0
);
else
paramStatus
.
setStatus
(
1
);
}
}
else
{
paramStatus
.
setStatus
(
2
);
}
}
}
}
}
}
...
...
src/main/java/org/rcisoft/business/system/vo/ParamStatus.java
View file @
2b9a3278
...
@@ -23,5 +23,7 @@ public class ParamStatus {
...
@@ -23,5 +23,7 @@ public class ParamStatus {
private
Integer
status
;
private
Integer
status
;
// 用来截取电量 13388062265_power_ct01 -> power_ct01
// 用来截取电量 13388062265_power_ct01 -> power_ct01
private
String
proId
;
private
String
proId
;
// 需要对比的数值
private
Object
value
;
}
}
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