Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
device-new-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
device-new-platform
Commits
9248a1f7
Commit
9248a1f7
authored
Jun 15, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正redis 最大连接数
parent
4733fb1a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
235 additions
and
198 deletions
+235
-198
device-manager/src/main/java/com/mortals/xhx/base/framework/listener/CustomerKeyExpirationListener.java
...ase/framework/listener/CustomerKeyExpirationListener.java
+5
-5
device-manager/src/main/java/com/mortals/xhx/daemon/task/DeviceStatTaskImpl.java
.../java/com/mortals/xhx/daemon/task/DeviceStatTaskImpl.java
+5
-1
device-manager/src/main/java/com/mortals/xhx/daemon/task/DeviceTotalStatTaskImpl.java
.../com/mortals/xhx/daemon/task/DeviceTotalStatTaskImpl.java
+11
-4
device-manager/src/main/java/com/mortals/xhx/module/device/service/DeviceService.java
.../com/mortals/xhx/module/device/service/DeviceService.java
+1
-5
device-manager/src/main/java/com/mortals/xhx/module/device/service/DeviceStatService.java
.../mortals/xhx/module/device/service/DeviceStatService.java
+6
-0
device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java
...als/xhx/module/device/service/impl/DeviceServiceImpl.java
+10
-167
device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceStatServiceImpl.java
...xhx/module/device/service/impl/DeviceStatServiceImpl.java
+197
-16
No files found.
device-manager/src/main/java/com/mortals/xhx/base/framework/listener/CustomerKeyExpirationListener.java
View file @
9248a1f7
...
@@ -119,14 +119,14 @@ public class CustomerKeyExpirationListener implements MessageListener {
...
@@ -119,14 +119,14 @@ public class CustomerKeyExpirationListener implements MessageListener {
if
(
messageoff
==
YesNoEnum
.
YES
.
getValue
())
{
if
(
messageoff
==
YesNoEnum
.
YES
.
getValue
())
{
// todo 发送短信
// todo 发送短信
//短信使用模板,如 设备告警:{产品}设备:{设备名称加编码}已离线,请注意检查!
//短信使用模板,如 设备告警:{产品}设备:{设备名称加编码}已离线,请注意检查!
DeviceAlarmInfoEntity
deviceAlarmInfoEntity
=
deviceAlarmInfoService
.
selectOne
(
new
DeviceAlarmInfoQuery
().
alarmDevice
(
deviceEntity
.
getId
())
);
int
count
=
deviceAlarmInfoService
.
count
(
new
DeviceAlarmInfoQuery
().
alarmDevice
(
deviceEntity
.
getId
()),
null
);
if
(
!
ObjectUtils
.
isEmpty
(
deviceAlarmInfoEntity
)
)
{
if
(
count
>
0
)
{
AlarmSmsSendEntity
alarmSmsSendEntity
=
new
AlarmSmsSendEntity
();
AlarmSmsSendEntity
alarmSmsSendEntity
=
new
AlarmSmsSendEntity
();
alarmSmsSendEntity
.
initAttrValue
();
alarmSmsSendEntity
.
initAttrValue
();
alarmSmsSendEntity
.
setId
(
IdUtil
.
getSnowflake
().
nextId
());
alarmSmsSendEntity
.
setId
(
IdUtil
.
getSnowflake
().
nextId
());
alarmSmsSendEntity
.
setSiteId
(
device
AlarmInfo
Entity
.
getSiteId
());
alarmSmsSendEntity
.
setSiteId
(
deviceEntity
.
getSiteId
());
alarmSmsSendEntity
.
setMobile
(
device
AlarmInfoEntity
.
getReceivePersonnelTelephone
());
alarmSmsSendEntity
.
setMobile
(
device
Entity
.
getLeadingOfficial
());
alarmSmsSendEntity
.
setReceiver
(
device
AlarmInfoEntity
.
getAlarmReceivePersonnel
());
alarmSmsSendEntity
.
setReceiver
(
device
Entity
.
getLeadingOfficialTelephone
());
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"1"
,
productEntity
.
getProductName
());
map
.
put
(
"1"
,
productEntity
.
getProductName
());
map
.
put
(
"2"
,
deviceEntity
.
getDeviceName
()
+
":"
+
deviceEntity
.
getDeviceName
());
map
.
put
(
"2"
,
deviceEntity
.
getDeviceName
()
+
":"
+
deviceEntity
.
getDeviceName
());
...
...
device-manager/src/main/java/com/mortals/xhx/daemon/task/DeviceStatTaskImpl.java
View file @
9248a1f7
...
@@ -51,13 +51,17 @@ public class DeviceStatTaskImpl implements ITaskExcuteService {
...
@@ -51,13 +51,17 @@ public class DeviceStatTaskImpl implements ITaskExcuteService {
}
else
{
}
else
{
waitDeviceInfos
.
add
(
deviceEntity
);
waitDeviceInfos
.
add
(
deviceEntity
);
}
}
try
{
Thread
.
sleep
(
500
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"线程休眠异常"
,
e
);
}
}
}
log
.
info
(
"waitDeviceInfos size:{}"
,
waitDeviceInfos
.
size
());
log
.
info
(
"waitDeviceInfos size:{}"
,
waitDeviceInfos
.
size
());
if
(!
ObjectUtils
.
isEmpty
(
waitDeviceInfos
))
{
if
(!
ObjectUtils
.
isEmpty
(
waitDeviceInfos
))
{
deviceService
.
update
(
waitDeviceInfos
);
deviceService
.
update
(
waitDeviceInfos
);
}
}
//获取所有在线设备
//获取所有在线设备
List
<
DeviceEntity
>
deviceList
=
deviceService
.
find
(
new
DeviceQuery
().
deviceStatus
(
DeviceStatusEnum
.
在线
.
getValue
()));
List
<
DeviceEntity
>
deviceList
=
deviceService
.
find
(
new
DeviceQuery
().
deviceStatus
(
DeviceStatusEnum
.
在线
.
getValue
()));
//更新离线
//更新离线
...
...
device-manager/src/main/java/com/mortals/xhx/daemon/task/DeviceTotalStatTaskImpl.java
View file @
9248a1f7
...
@@ -7,6 +7,8 @@ import com.mortals.xhx.common.code.PlatformTypeEnum;
...
@@ -7,6 +7,8 @@ import com.mortals.xhx.common.code.PlatformTypeEnum;
import
com.mortals.xhx.common.pdu.site.SitePdu
;
import
com.mortals.xhx.common.pdu.site.SitePdu
;
import
com.mortals.xhx.feign.site.ISiteFeign
;
import
com.mortals.xhx.feign.site.ISiteFeign
;
import
com.mortals.xhx.module.device.service.DeviceService
;
import
com.mortals.xhx.module.device.service.DeviceService
;
import
com.mortals.xhx.module.device.service.DeviceStatService
;
import
com.mortals.xhx.module.site.model.SiteEntity
;
import
com.mortals.xhx.module.site.model.SiteQuery
;
import
com.mortals.xhx.module.site.model.SiteQuery
;
import
com.mortals.xhx.module.site.service.SiteService
;
import
com.mortals.xhx.module.site.service.SiteService
;
import
lombok.extern.apachecommons.CommonsLog
;
import
lombok.extern.apachecommons.CommonsLog
;
...
@@ -14,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -14,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
/**
* 设备统计任务,生成当天统计数据
* 设备统计任务,生成当天统计数据
*
*
...
@@ -26,6 +30,8 @@ public class DeviceTotalStatTaskImpl implements ITaskExcuteService {
...
@@ -26,6 +30,8 @@ public class DeviceTotalStatTaskImpl implements ITaskExcuteService {
@Autowired
@Autowired
private
DeviceService
deviceService
;
private
DeviceService
deviceService
;
@Autowired
private
DeviceStatService
deviceStatService
;
@Value
(
"${platform.type:cloud}"
)
@Value
(
"${platform.type:cloud}"
)
private
String
platFormType
;
//版本,默认云服务版本
private
String
platFormType
;
//版本,默认云服务版本
...
@@ -43,12 +49,13 @@ public class DeviceTotalStatTaskImpl implements ITaskExcuteService {
...
@@ -43,12 +49,13 @@ public class DeviceTotalStatTaskImpl implements ITaskExcuteService {
SitePdu
sitePdu
=
new
SitePdu
();
SitePdu
sitePdu
=
new
SitePdu
();
sitePdu
.
setSize
(-
1
);
sitePdu
.
setSize
(-
1
);
siteFeign
.
list
(
sitePdu
).
getData
().
getData
().
parallelStream
().
forEach
(
item
->
{
siteFeign
.
list
(
sitePdu
).
getData
().
getData
().
parallelStream
().
forEach
(
item
->
{
deviceService
.
deviceStat
(
item
.
getId
(),
null
);
//
deviceService.deviceStat(item.getId(), null);
});
});
}
else
if
(
platFormType
.
equalsIgnoreCase
(
PlatformTypeEnum
.
STANDALONE
.
getValue
()))
{
}
else
if
(
platFormType
.
equalsIgnoreCase
(
PlatformTypeEnum
.
STANDALONE
.
getValue
()))
{
siteService
.
find
(
new
SiteQuery
()).
forEach
(
item
->
{
List
<
SiteEntity
>
siteEntities
=
siteService
.
find
(
new
SiteQuery
());
deviceService
.
deviceStat
(
item
.
getId
(),
null
);
for
(
SiteEntity
siteEntity
:
siteEntities
)
{
});
deviceStatService
.
deviceStat
(
siteEntity
.
getId
(),
null
);
}
}
}
}
}
...
...
device-manager/src/main/java/com/mortals/xhx/module/device/service/DeviceService.java
View file @
9248a1f7
...
@@ -68,11 +68,7 @@ public interface DeviceService extends ICRUDCacheService<DeviceEntity,Long>{
...
@@ -68,11 +68,7 @@ public interface DeviceService extends ICRUDCacheService<DeviceEntity,Long>{
DeviceDao
getDeviceDao
();
DeviceDao
getDeviceDao
();
/**
* 设备统计当天情况
* @param context
*/
void
deviceStat
(
Long
siteId
,
Context
context
);
List
<
DeviceMapEntity
>
deviceMap
(
DeviceEntity
query
,
Context
context
);
List
<
DeviceMapEntity
>
deviceMap
(
DeviceEntity
query
,
Context
context
);
...
...
device-manager/src/main/java/com/mortals/xhx/module/device/service/DeviceStatService.java
View file @
9248a1f7
...
@@ -17,6 +17,12 @@ import java.util.List;
...
@@ -17,6 +17,12 @@ import java.util.List;
*/
*/
public
interface
DeviceStatService
extends
ICRUDService
<
DeviceStatEntity
,
Long
>
{
public
interface
DeviceStatService
extends
ICRUDService
<
DeviceStatEntity
,
Long
>
{
/**
* 设备统计当天情况
* @param context
*/
void
deviceStat
(
Long
siteId
,
Context
context
);
List
<
DeviceStatEntity
>
getBillInfos
(
Long
siteId
,
String
createTimeStart
,
Integer
datePattern
,
PageInfo
pageInfo
,
Context
context
);
List
<
DeviceStatEntity
>
getBillInfos
(
Long
siteId
,
String
createTimeStart
,
Integer
datePattern
,
PageInfo
pageInfo
,
Context
context
);
}
}
\ No newline at end of file
device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java
View file @
9248a1f7
...
@@ -24,15 +24,13 @@ import com.mortals.xhx.common.pdu.site.SitePdu;
...
@@ -24,15 +24,13 @@ import com.mortals.xhx.common.pdu.site.SitePdu;
import
com.mortals.xhx.common.utils.BeanUtil
;
import
com.mortals.xhx.common.utils.BeanUtil
;
import
com.mortals.xhx.feign.IOfficeDeviceFeign
;
import
com.mortals.xhx.feign.IOfficeDeviceFeign
;
import
com.mortals.xhx.feign.site.ISiteFeign
;
import
com.mortals.xhx.feign.site.ISiteFeign
;
import
com.mortals.xhx.module.alarm.model.AlarmSmsSendEntity
;
import
com.mortals.xhx.module.alarm.model.AlarmSmsSendQuery
;
import
com.mortals.xhx.module.alarm.service.AlarmSmsSendService
;
import
com.mortals.xhx.module.device.dao.DeviceDao
;
import
com.mortals.xhx.module.device.dao.DeviceDao
;
import
com.mortals.xhx.module.device.model.*
;
import
com.mortals.xhx.module.device.model.DeviceEntity
;
import
com.mortals.xhx.module.device.service.DeviceAlarmInfoService
;
import
com.mortals.xhx.module.device.model.DeviceLogEntity
;
import
com.mortals.xhx.module.device.model.DeviceMapEntity
;
import
com.mortals.xhx.module.device.model.DeviceQuery
;
import
com.mortals.xhx.module.device.service.DeviceLogService
;
import
com.mortals.xhx.module.device.service.DeviceLogService
;
import
com.mortals.xhx.module.device.service.DeviceService
;
import
com.mortals.xhx.module.device.service.DeviceService
;
import
com.mortals.xhx.module.device.service.DeviceStatService
;
import
com.mortals.xhx.module.platform.model.PlatformEntity
;
import
com.mortals.xhx.module.platform.model.PlatformEntity
;
import
com.mortals.xhx.module.platform.model.PlatformQuery
;
import
com.mortals.xhx.module.platform.model.PlatformQuery
;
import
com.mortals.xhx.module.platform.service.PlatformService
;
import
com.mortals.xhx.module.platform.service.PlatformService
;
...
@@ -59,7 +57,6 @@ import java.util.stream.Collectors;
...
@@ -59,7 +57,6 @@ import java.util.stream.Collectors;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
Constant
.
MESSAGETYPE_NOTIFY_RESTART_APP
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
Constant
.
MESSAGETYPE_NOTIFY_RESTART_APP
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
Constant
.
PARAM_SERVER_PHP_IN_HTTP_URL
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
Constant
.
PARAM_SERVER_PHP_IN_HTTP_URL
;
import
static
java
.
math
.
BigDecimal
.
ROUND_HALF_DOWN
;
import
static
java
.
math
.
BigDecimal
.
ROUND_HALF_DOWN
;
import
static
java
.
util
.
stream
.
Collectors
.
counting
;
/**
/**
* DeviceService
* DeviceService
...
@@ -80,12 +77,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
...
@@ -80,12 +77,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
private
ISiteFeign
siteFeign
;
private
ISiteFeign
siteFeign
;
@Autowired
@Autowired
private
DeviceLogService
deviceLogService
;
private
DeviceLogService
deviceLogService
;
@Autowired
private
DeviceStatService
deviceStatService
;
@Autowired
private
DeviceAlarmInfoService
deviceAlarmInfoService
;
@Autowired
private
AlarmSmsSendService
alarmSmsSendService
;
@Autowired
@Autowired
private
MessageProducer
messageProducer
;
private
MessageProducer
messageProducer
;
@Autowired
@Autowired
...
@@ -211,8 +203,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
...
@@ -211,8 +203,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
deviceEntity
.
setOfflineTime
(
new
Date
());
deviceEntity
.
setOfflineTime
(
new
Date
());
deviceEntity
.
setEnabled
(
EnabledEnum
.
启用
.
getValue
());
deviceEntity
.
setEnabled
(
EnabledEnum
.
启用
.
getValue
());
this
.
update
(
deviceEntity
);
this
.
update
(
deviceEntity
);
PlatformEntity
platformEntity
=
platformService
.
getCache
(
deviceEntity
.
getPlatformId
()
==
null
?
"-1"
:
deviceEntity
.
getPlatformId
().
toString
());
PlatformEntity
platformEntity
=
platformService
.
getCache
(
deviceEntity
.
getPlatformId
()
==
null
?
"-1"
:
deviceEntity
.
getPlatformId
().
toString
());
ProductEntity
productEntity
=
productService
.
getCache
(
deviceEntity
.
getProductId
()
==
null
?
"-1"
:
deviceEntity
.
getProductId
().
toString
());
ProductEntity
productEntity
=
productService
.
getCache
(
deviceEntity
.
getProductId
()
==
null
?
"-1"
:
deviceEntity
.
getProductId
().
toString
());
if
(!
ObjectUtils
.
isEmpty
(
platformEntity
)
&&
!
ObjectUtils
.
isEmpty
(
productEntity
))
{
if
(!
ObjectUtils
.
isEmpty
(
platformEntity
)
&&
!
ObjectUtils
.
isEmpty
(
productEntity
))
{
//注册rabbmit相关队列与绑定
//注册rabbmit相关队列与绑定
messageProducer
.
queueAddAndBinds
(
QueueKey
.
DEFAULT_EXCHANGE
,
Constant
.
UPLOAD_TOPIC
+
deviceCode
,
Constant
.
UPLOAD_TOPIC
+
deviceCode
);
messageProducer
.
queueAddAndBinds
(
QueueKey
.
DEFAULT_EXCHANGE
,
Constant
.
UPLOAD_TOPIC
+
deviceCode
,
Constant
.
UPLOAD_TOPIC
+
deviceCode
);
...
@@ -395,160 +387,11 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
...
@@ -395,160 +387,11 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
return
this
.
getDao
();
return
this
.
getDao
();
}
}
/**
* 全部设备-》激活设备与未激活-》启用与停用设备-》离线与在线设备
*
* @param context
*/
@Override
public
void
deviceStat
(
Long
siteId
,
Context
context
)
{
//查询当天统计,如果有 则更新统计结果,否则新增
Calendar
calendar
=
Calendar
.
getInstance
();
DeviceStatEntity
deviceStatEntity
=
deviceStatService
.
selectOne
(
new
DeviceStatQuery
()
.
siteId
(
siteId
)
.
year
(
calendar
.
get
(
Calendar
.
YEAR
))
.
month
(
calendar
.
get
(
Calendar
.
MONTH
)
+
1
)
.
day
(
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
)));
if
(
ObjectUtils
.
isEmpty
(
deviceStatEntity
))
{
deviceStatEntity
=
new
DeviceStatEntity
();
deviceStatEntity
.
initAttrValue
();
deviceStatEntity
.
setSiteId
(
siteId
);
deviceStatEntity
.
setCreateTime
(
new
Date
());
deviceStatEntity
.
setYear
(
calendar
.
get
(
Calendar
.
YEAR
));
deviceStatEntity
.
setMonth
(
calendar
.
get
(
Calendar
.
MONTH
)
+
1
);
deviceStatEntity
.
setDay
(
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
));
}
//获取昨天统计数据
DeviceStatEntity
yesterdayDeviceStat
=
deviceStatService
.
selectOne
(
new
DeviceStatQuery
()
.
siteId
(
siteId
)
.
year
(
calendar
.
get
(
Calendar
.
YEAR
))
.
month
(
calendar
.
get
(
Calendar
.
MONTH
)
+
1
)
.
day
(
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
)));
if
(
ObjectUtils
.
isEmpty
(
yesterdayDeviceStat
))
{
yesterdayDeviceStat
=
new
DeviceStatEntity
();
yesterdayDeviceStat
.
initAttrValue
();
yesterdayDeviceStat
.
setSiteId
(
siteId
);
// yesterdayDeviceStat.setYear(DateUtil.year(DateUtil.yesterday()));
yesterdayDeviceStat
.
setYear
(
calendar
.
get
(
Calendar
.
YEAR
));
}
try
{
//获取设备总数
List
<
DeviceEntity
>
deviceList
=
this
.
find
(
new
DeviceQuery
().
siteId
(
siteId
));
Integer
deviceTotalCount
=
deviceList
.
size
();
//未激活数量
Long
deviceUnActiveCount
=
deviceList
.
parallelStream
()
.
filter
(
f
->
f
.
getDeviceStatus
()
==
DeviceStatusEnum
.
未激活
.
getValue
())
.
count
();
//激活设备
Integer
deviceActiveCount
=
deviceList
.
size
()
-
deviceUnActiveCount
.
intValue
();
deviceStatEntity
.
setDeviceTotalCount
(
deviceTotalCount
);
deviceStatEntity
.
setDeviceAddCount
(
deviceTotalCount
-
yesterdayDeviceStat
.
getDeviceTotalCount
());
///统计按当前站点归集 // TODO: 2022/8/22
if
(
platFormType
.
equalsIgnoreCase
(
PlatformTypeEnum
.
STANDALONE
.
getValue
()))
{
List
<
SiteEntity
>
list
=
siteService
.
getFlatSitesBySiteId
(
siteId
,
context
);
deviceStatEntity
.
setSiteTotalCount
(
list
.
size
());
deviceStatEntity
.
setSiteAddCount
(
list
.
size
()
-
yesterdayDeviceStat
.
getSiteTotalCount
());
}
else
{
Rest
<
List
<
SitePdu
>>
resp
=
siteFeign
.
getFlatSitesBySiteId
(
new
SitePdu
().
id
(
siteId
));
if
(
resp
.
getCode
()
==
1
)
{
List
<
SitePdu
>
sitePduList
=
resp
.
getData
();
deviceStatEntity
.
setSiteTotalCount
(
sitePduList
.
size
());
deviceStatEntity
.
setSiteAddCount
(
sitePduList
.
size
()
-
yesterdayDeviceStat
.
getSiteTotalCount
());
}
}
//在线数量
Long
deviceOnlineCount
=
deviceList
.
parallelStream
()
.
filter
(
f
->
f
.
getDeviceStatus
()
>
DeviceStatusEnum
.
未激活
.
getValue
())
.
filter
(
f
->
f
.
getEnabled
()
==
EnabledEnum
.
启用
.
getValue
())
.
filter
(
f
->
f
.
getDeviceStatus
()
==
DeviceStatusEnum
.
在线
.
getValue
())
.
count
();
deviceStatEntity
.
setDeviceOnlineCount
(
deviceOnlineCount
.
intValue
());
//在线率=在线设备/所有激活设备
if
(
deviceActiveCount
>
0
)
{
deviceStatEntity
.
setDeviceOnlineRatio
(
new
BigDecimal
(
deviceOnlineCount
).
divide
(
new
BigDecimal
(
deviceActiveCount
),
4
,
ROUND_HALF_DOWN
));
}
//离线数量
Long
deviceOfflineCount
=
deviceList
.
parallelStream
()
.
filter
(
f
->
f
.
getDeviceStatus
()
>
DeviceStatusEnum
.
未激活
.
getValue
())
.
filter
(
f
->
f
.
getEnabled
()
==
EnabledEnum
.
启用
.
getValue
())
.
filter
(
f
->
f
.
getDeviceStatus
()
==
DeviceStatusEnum
.
离线
.
getValue
())
.
count
();
deviceStatEntity
.
setDeviceOfflineCount
(
deviceOfflineCount
.
intValue
());
if
(
deviceActiveCount
>
0
)
{
deviceStatEntity
.
setDeviceOfflineRatio
(
new
BigDecimal
(
deviceOfflineCount
).
divide
(
new
BigDecimal
(
deviceActiveCount
),
4
,
ROUND_HALF_DOWN
));
}
//停用数量
Long
deviceStopCount
=
deviceList
.
parallelStream
()
.
filter
(
f
->
f
.
getDeviceStatus
()
>
DeviceStatusEnum
.
未激活
.
getValue
())
.
filter
(
f
->
f
.
getEnabled
()
==
YesNoEnum
.
NO
.
getValue
())
.
count
();
deviceStatEntity
.
setDeviceStopCount
(
deviceStopCount
.
intValue
());
if
(
deviceActiveCount
>
0
)
{
deviceStatEntity
.
setDeviceStopRatio
(
new
BigDecimal
(
deviceStopCount
).
divide
(
new
BigDecimal
(
deviceActiveCount
),
4
,
ROUND_HALF_DOWN
));
}
deviceStatEntity
.
setDeviceUnActiveCount
(
deviceUnActiveCount
.
intValue
());
if
(
deviceActiveCount
>
0
)
{
deviceStatEntity
.
setDeviceUnActiveRatio
(
new
BigDecimal
(
deviceUnActiveCount
).
divide
(
new
BigDecimal
(
deviceActiveCount
),
4
,
ROUND_HALF_DOWN
));
}
//今日告警数量
DeviceAlarmInfoQuery
deviceAlarmInfoQuery
=
new
DeviceAlarmInfoQuery
();
deviceAlarmInfoQuery
.
setCreateTimeStart
(
DateUtils
.
getCurrStrDate
());
deviceAlarmInfoQuery
.
setCreateTimeEnd
(
DateUtils
.
getCurrStrDate
());
List
<
DeviceAlarmInfoEntity
>
deviceAlarmInfoList
=
deviceAlarmInfoService
.
find
(
deviceAlarmInfoQuery
);
deviceStatEntity
.
setAlarmTotalCount
(
deviceAlarmInfoList
.
size
());
deviceStatEntity
.
setAlarmAddCount
(
deviceAlarmInfoList
.
size
()
-
yesterdayDeviceStat
.
getAlarmTotalCount
());
//推送数量
AlarmSmsSendQuery
alarmSmsSendQuery
=
new
AlarmSmsSendQuery
();
alarmSmsSendQuery
.
setSendTimeStart
(
DateUtils
.
getCurrStrDate
());
alarmSmsSendQuery
.
setSendTimeEnd
(
DateUtils
.
getCurrStrDate
());
alarmSmsSendQuery
.
setSendStatus
(
SendStatusEnum
.
发送成功
.
getValue
());
List
<
AlarmSmsSendEntity
>
alarmSmsSendEntities
=
alarmSmsSendService
.
find
(
alarmSmsSendQuery
);
deviceStatEntity
.
setPushTotalCount
(
alarmSmsSendEntities
.
size
());
deviceStatEntity
.
setPushAddCount
(
alarmSmsSendEntities
.
size
()
-
yesterdayDeviceStat
.
getPushTotalCount
());
//上行下行数量
DeviceLogQuery
deviceLogQuery
=
new
DeviceLogQuery
();
deviceLogQuery
.
setCreateTimeStart
(
DateUtils
.
getCurrStrDate
());
deviceLogQuery
.
setCreateTimeEnd
(
DateUtils
.
getCurrStrDate
());
Map
<
Boolean
,
Long
>
collect
=
deviceLogService
.
find
(
deviceLogQuery
).
parallelStream
().
collect
(
Collectors
.
partitioningBy
(
x
->
x
.
getLogType
()
==
LogTypeEnum
.
上报事件
.
getValue
(),
counting
()));
deviceStatEntity
.
setUploadMessageTotalCount
(
collect
.
getOrDefault
(
true
,
0L
).
intValue
());
deviceStatEntity
.
setDownloadMessageTotalCount
(
collect
.
getOrDefault
(
false
,
0L
).
intValue
());
deviceStatEntity
.
setSiteId
(
siteId
);
if
(
deviceStatEntity
.
newEntity
())
{
deviceStatEntity
.
setCreateTime
(
new
Date
());
deviceStatService
.
save
(
deviceStatEntity
);
}
else
{
deviceStatEntity
.
setUpdateTime
(
new
Date
());
deviceStatService
.
update
(
deviceStatEntity
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"统计异常"
,
e
);
throw
new
AppException
(
"统计异常!"
);
}
}
@Override
@Override
public
List
<
DeviceMapEntity
>
deviceMap
(
DeviceEntity
query
,
Context
context
)
{
public
List
<
DeviceMapEntity
>
deviceMap
(
DeviceEntity
query
,
Context
context
)
{
String
longitude
=
"0.00"
;
String
longitude
=
"0.00"
;
String
latitude
=
"0.00"
;
String
latitude
=
"0.00"
;
if
(
platFormType
.
equalsIgnoreCase
(
PlatformTypeEnum
.
STANDALONE
.
getValue
()))
{
if
(
platFormType
.
equalsIgnoreCase
(
PlatformTypeEnum
.
STANDALONE
.
getValue
()))
{
SiteEntity
siteEntity
=
siteService
.
get
(
query
.
getSiteId
());
SiteEntity
siteEntity
=
siteService
.
get
(
query
.
getSiteId
());
if
(
ObjectUtils
.
isEmpty
(
siteEntity
))
throw
new
AppException
(
"未找到指定站点!"
);
if
(
ObjectUtils
.
isEmpty
(
siteEntity
))
throw
new
AppException
(
"未找到指定站点!"
);
...
@@ -568,7 +411,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
...
@@ -568,7 +411,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
.
stream
().
map
(
item
->
{
.
stream
().
map
(
item
->
{
DeviceMapEntity
deviceMapEntity
=
new
DeviceMapEntity
();
DeviceMapEntity
deviceMapEntity
=
new
DeviceMapEntity
();
deviceMapEntity
.
setProductId
(
item
.
getKey
());
deviceMapEntity
.
setProductId
(
item
.
getKey
());
ProductEntity
productEntity
=
productService
.
get
(
item
.
getKey
());
ProductEntity
productEntity
=
productService
.
get
Cache
(
item
.
getKey
()
==
null
?
"-1"
:
item
.
getKey
().
toString
());
deviceMapEntity
.
setProductCode
(
productEntity
==
null
?
""
:
productEntity
.
getProductCode
());
deviceMapEntity
.
setProductCode
(
productEntity
==
null
?
""
:
productEntity
.
getProductCode
());
if
(
ObjectUtils
.
isEmpty
(
item
.
getValue
()))
{
if
(
ObjectUtils
.
isEmpty
(
item
.
getValue
()))
{
deviceMapEntity
.
setDeviceList
(
Collections
.
EMPTY_LIST
);
deviceMapEntity
.
setDeviceList
(
Collections
.
EMPTY_LIST
);
...
@@ -578,8 +421,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
...
@@ -578,8 +421,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
return
deviceMapEntity
;
return
deviceMapEntity
;
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
//更新坐标点 轴步进 0.0001~~11米
//更新坐标点 轴步进 0.0001~~11米
BigDecimal
lngStep
=
new
BigDecimal
(
0.0000
5
);
BigDecimal
lngStep
=
new
BigDecimal
(
0.0000
3
);
BigDecimal
latiStep
=
new
BigDecimal
(
0.0000
5
);
BigDecimal
latiStep
=
new
BigDecimal
(
0.0000
3
);
BigDecimal
centerLng
=
new
BigDecimal
(
longitude
);
BigDecimal
centerLng
=
new
BigDecimal
(
longitude
);
...
...
device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceStatServiceImpl.java
View file @
9248a1f7
package
com.mortals.xhx.module.device.service.impl
;
package
com.mortals.xhx.module.device.service.impl
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.model.OrderCol
;
import
com.mortals.framework.model.OrderCol
;
import
com.mortals.framework.model.PageInfo
;
import
com.mortals.framework.model.PageInfo
;
import
com.mortals.framework.model.Result
;
import
com.mortals.framework.model.Result
;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
import
com.mortals.xhx.common.code.DaySelectEnum
;
import
com.mortals.framework.util.DateUtils
;
import
com.mortals.xhx.common.code.TimeUnitEnum
;
import
com.mortals.xhx.common.code.*
;
import
com.mortals.xhx.common.pdu.site.SitePdu
;
import
com.mortals.xhx.feign.site.ISiteFeign
;
import
com.mortals.xhx.module.alarm.model.AlarmSmsSendQuery
;
import
com.mortals.xhx.module.alarm.service.AlarmSmsSendService
;
import
com.mortals.xhx.module.device.dao.DeviceStatDao
;
import
com.mortals.xhx.module.device.dao.DeviceStatDao
;
import
com.mortals.xhx.module.device.model.DeviceStatEntity
;
import
com.mortals.xhx.module.device.model.*
;
import
com.mortals.xhx.module.device.model.DeviceStatQuery
;
import
com.mortals.xhx.module.device.service.DeviceAlarmInfoService
;
import
com.mortals.xhx.module.device.service.DeviceLogService
;
import
com.mortals.xhx.module.device.service.DeviceService
;
import
com.mortals.xhx.module.device.service.DeviceStatService
;
import
com.mortals.xhx.module.device.service.DeviceStatService
;
import
com.mortals.xhx.module.site.model.SiteEntity
;
import
com.mortals.xhx.module.site.service.SiteService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
java.util.ArrayList
;
import
java.math.BigDecimal
;
import
java.util.Arrays
;
import
java.util.*
;
import
java.util.List
;
import
static
java
.
math
.
BigDecimal
.
ROUND_HALF_DOWN
;
/**
/**
* DeviceStatService
* DeviceStatService
...
@@ -29,6 +41,24 @@ import java.util.List;
...
@@ -29,6 +41,24 @@ import java.util.List;
@Service
(
"deviceStatService"
)
@Service
(
"deviceStatService"
)
public
class
DeviceStatServiceImpl
extends
AbstractCRUDServiceImpl
<
DeviceStatDao
,
DeviceStatEntity
,
Long
>
implements
DeviceStatService
{
public
class
DeviceStatServiceImpl
extends
AbstractCRUDServiceImpl
<
DeviceStatDao
,
DeviceStatEntity
,
Long
>
implements
DeviceStatService
{
@Autowired
private
DeviceService
deviceService
;
@Autowired
private
SiteService
siteService
;
@Value
(
"${platform.type:cloud}"
)
private
String
platFormType
;
//版本,默认云服务版本
@Autowired
private
DeviceStatService
deviceStatService
;
@Autowired
private
DeviceAlarmInfoService
deviceAlarmInfoService
;
@Autowired
private
AlarmSmsSendService
alarmSmsSendService
;
@Autowired
private
DeviceLogService
deviceLogService
;
@Autowired
private
ISiteFeign
siteFeign
;
@Override
@Override
public
List
<
DeviceStatEntity
>
find
(
DeviceStatEntity
params
,
Context
context
)
throws
AppException
{
public
List
<
DeviceStatEntity
>
find
(
DeviceStatEntity
params
,
Context
context
)
throws
AppException
{
...
@@ -45,31 +75,31 @@ public class DeviceStatServiceImpl extends AbstractCRUDServiceImpl<DeviceStatDao
...
@@ -45,31 +75,31 @@ public class DeviceStatServiceImpl extends AbstractCRUDServiceImpl<DeviceStatDao
switch
(
DaySelectEnum
.
getByValue
(
query
.
getSelected
()))
{
switch
(
DaySelectEnum
.
getByValue
(
query
.
getSelected
()))
{
case
今天:
case
今天:
page
.
setPrePageResult
(
1
);
page
.
setPrePageResult
(
1
);
billInfos
=
this
.
getBillInfos
(
query
.
getSiteId
(),
query
.
getCreateTimeStart
(),
TimeUnitEnum
.
DAY
.
getValue
(),
page
,
context
);
billInfos
=
this
.
getBillInfos
(
query
.
getSiteId
(),
query
.
getCreateTimeStart
(),
TimeUnitEnum
.
DAY
.
getValue
(),
page
,
context
);
deviceStatEntityResult
.
setList
(
billInfos
);
deviceStatEntityResult
.
setList
(
billInfos
);
deviceStatEntityResult
.
setPageInfo
(
page
);
deviceStatEntityResult
.
setPageInfo
(
page
);
break
;
break
;
case
近七天:
case
近七天:
page
.
setPrePageResult
(
7
);
page
.
setPrePageResult
(
7
);
billInfos
=
this
.
getBillInfos
(
query
.
getSiteId
(),
query
.
getCreateTimeStart
(),
TimeUnitEnum
.
DAY
.
getValue
(),
page
,
context
);
billInfos
=
this
.
getBillInfos
(
query
.
getSiteId
(),
query
.
getCreateTimeStart
(),
TimeUnitEnum
.
DAY
.
getValue
(),
page
,
context
);
deviceStatEntityResult
.
setList
(
billInfos
);
deviceStatEntityResult
.
setList
(
billInfos
);
deviceStatEntityResult
.
setPageInfo
(
page
);
deviceStatEntityResult
.
setPageInfo
(
page
);
break
;
break
;
case
近三十天:
case
近三十天:
page
.
setPrePageResult
(
30
);
page
.
setPrePageResult
(
30
);
billInfos
=
this
.
getBillInfos
(
query
.
getSiteId
(),
query
.
getCreateTimeStart
(),
TimeUnitEnum
.
DAY
.
getValue
(),
page
,
context
);
billInfos
=
this
.
getBillInfos
(
query
.
getSiteId
(),
query
.
getCreateTimeStart
(),
TimeUnitEnum
.
DAY
.
getValue
(),
page
,
context
);
deviceStatEntityResult
.
setList
(
billInfos
);
deviceStatEntityResult
.
setList
(
billInfos
);
deviceStatEntityResult
.
setPageInfo
(
page
);
deviceStatEntityResult
.
setPageInfo
(
page
);
break
;
break
;
case
近三月:
case
近三月:
page
.
setPrePageResult
(
3
);
page
.
setPrePageResult
(
3
);
billInfos
=
this
.
getBillInfos
(
query
.
getSiteId
(),
query
.
getCreateTimeStart
(),
TimeUnitEnum
.
MONTH
.
getValue
(),
page
,
context
);
billInfos
=
this
.
getBillInfos
(
query
.
getSiteId
(),
query
.
getCreateTimeStart
(),
TimeUnitEnum
.
MONTH
.
getValue
(),
page
,
context
);
deviceStatEntityResult
.
setList
(
billInfos
);
deviceStatEntityResult
.
setList
(
billInfos
);
deviceStatEntityResult
.
setPageInfo
(
page
);
deviceStatEntityResult
.
setPageInfo
(
page
);
break
;
break
;
case
今年:
case
今年:
page
.
setPrePageResult
(
1
);
page
.
setPrePageResult
(
1
);
billInfos
=
this
.
getBillInfos
(
query
.
getSiteId
(),
query
.
getCreateTimeStart
(),
TimeUnitEnum
.
YEAR
.
getValue
(),
page
,
context
);
billInfos
=
this
.
getBillInfos
(
query
.
getSiteId
(),
query
.
getCreateTimeStart
(),
TimeUnitEnum
.
YEAR
.
getValue
(),
page
,
context
);
deviceStatEntityResult
.
setList
(
billInfos
);
deviceStatEntityResult
.
setList
(
billInfos
);
deviceStatEntityResult
.
setPageInfo
(
page
);
deviceStatEntityResult
.
setPageInfo
(
page
);
break
;
break
;
...
@@ -83,22 +113,22 @@ public class DeviceStatServiceImpl extends AbstractCRUDServiceImpl<DeviceStatDao
...
@@ -83,22 +113,22 @@ public class DeviceStatServiceImpl extends AbstractCRUDServiceImpl<DeviceStatDao
}
}
@Override
@Override
public
List
<
DeviceStatEntity
>
getBillInfos
(
Long
siteId
,
String
createTimeStart
,
Integer
datePattern
,
PageInfo
pageInfo
,
Context
context
)
{
public
List
<
DeviceStatEntity
>
getBillInfos
(
Long
siteId
,
String
createTimeStart
,
Integer
datePattern
,
PageInfo
pageInfo
,
Context
context
)
{
List
<
DeviceStatEntity
>
statList
=
new
ArrayList
<>();
List
<
DeviceStatEntity
>
statList
=
new
ArrayList
<>();
DeviceStatQuery
query
=
new
DeviceStatQuery
();
DeviceStatQuery
query
=
new
DeviceStatQuery
();
query
.
setSiteId
(
siteId
);
query
.
setSiteId
(
siteId
);
query
.
setCreateTimeStart
(
createTimeStart
);
query
.
setCreateTimeStart
(
createTimeStart
);
if
(
datePattern
==
TimeUnitEnum
.
DAY
.
getValue
())
{
if
(
datePattern
==
TimeUnitEnum
.
DAY
.
getValue
())
{
query
.
setGroupList
(
Arrays
.
asList
(
"day"
));
query
.
setGroupList
(
Arrays
.
asList
(
"day"
));
query
.
setOrderColList
(
Arrays
.
asList
(
new
OrderCol
(
"year"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"month"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"day"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"createTime"
)));
query
.
setOrderColList
(
Arrays
.
asList
(
new
OrderCol
(
"year"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"month"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"day"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"createTime"
)));
statList
=
this
.
getDao
().
getStatList
(
query
,
pageInfo
);
statList
=
this
.
getDao
().
getStatList
(
query
,
pageInfo
);
}
else
if
(
datePattern
==
TimeUnitEnum
.
MONTH
.
getValue
())
{
}
else
if
(
datePattern
==
TimeUnitEnum
.
MONTH
.
getValue
())
{
query
.
setGroupList
(
Arrays
.
asList
(
"month"
));
query
.
setGroupList
(
Arrays
.
asList
(
"month"
));
query
.
setOrderColList
(
Arrays
.
asList
(
new
OrderCol
(
"year"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"month"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"createTime"
)));
query
.
setOrderColList
(
Arrays
.
asList
(
new
OrderCol
(
"year"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"month"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"createTime"
)));
statList
=
this
.
getDao
().
getStatList
(
query
,
pageInfo
);
statList
=
this
.
getDao
().
getStatList
(
query
,
pageInfo
);
}
else
if
(
datePattern
==
TimeUnitEnum
.
YEAR
.
getValue
())
{
}
else
if
(
datePattern
==
TimeUnitEnum
.
YEAR
.
getValue
())
{
query
.
setGroupList
(
Arrays
.
asList
(
"year"
));
query
.
setGroupList
(
Arrays
.
asList
(
"year"
));
query
.
setOrderColList
(
Arrays
.
asList
(
new
OrderCol
(
"year"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"createTime"
)));
query
.
setOrderColList
(
Arrays
.
asList
(
new
OrderCol
(
"year"
,
OrderCol
.
DESCENDING
),
new
OrderCol
(
"createTime"
)));
statList
=
this
.
getDao
().
getStatList
(
query
,
pageInfo
);
statList
=
this
.
getDao
().
getStatList
(
query
,
pageInfo
);
}
else
{
}
else
{
throw
new
AppException
(
"不支持当前日期格式查询统计!"
);
throw
new
AppException
(
"不支持当前日期格式查询统计!"
);
...
@@ -106,4 +136,155 @@ public class DeviceStatServiceImpl extends AbstractCRUDServiceImpl<DeviceStatDao
...
@@ -106,4 +136,155 @@ public class DeviceStatServiceImpl extends AbstractCRUDServiceImpl<DeviceStatDao
return
statList
;
return
statList
;
}
}
/**
* 全部设备-》激活设备与未激活-》启用与停用设备-》离线与在线设备
*
* @param context
*/
@Override
public
void
deviceStat
(
Long
siteId
,
Context
context
)
{
//查询当天统计,如果有 则更新统计结果,否则新增
Calendar
calendar
=
Calendar
.
getInstance
();
DeviceStatEntity
deviceStatEntity
=
this
.
selectOne
(
new
DeviceStatQuery
()
.
siteId
(
siteId
)
.
year
(
calendar
.
get
(
Calendar
.
YEAR
))
.
month
(
calendar
.
get
(
Calendar
.
MONTH
)
+
1
)
.
day
(
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
)));
if
(
ObjectUtils
.
isEmpty
(
deviceStatEntity
))
{
deviceStatEntity
=
new
DeviceStatEntity
();
deviceStatEntity
.
initAttrValue
();
deviceStatEntity
.
setSiteId
(
siteId
);
deviceStatEntity
.
setCreateTime
(
new
Date
());
deviceStatEntity
.
setYear
(
calendar
.
get
(
Calendar
.
YEAR
));
deviceStatEntity
.
setMonth
(
calendar
.
get
(
Calendar
.
MONTH
)
+
1
);
deviceStatEntity
.
setDay
(
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
));
}
//获取昨天统计数据
DeviceStatEntity
yesterdayDeviceStat
=
this
.
selectOne
(
new
DeviceStatQuery
()
.
siteId
(
siteId
)
.
year
(
calendar
.
get
(
Calendar
.
YEAR
))
.
month
(
calendar
.
get
(
Calendar
.
MONTH
)
+
1
)
.
day
(
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
)));
if
(
ObjectUtils
.
isEmpty
(
yesterdayDeviceStat
))
{
yesterdayDeviceStat
=
new
DeviceStatEntity
();
yesterdayDeviceStat
.
initAttrValue
();
yesterdayDeviceStat
.
setSiteId
(
siteId
);
// yesterdayDeviceStat.setYear(DateUtil.year(DateUtil.yesterday()));
yesterdayDeviceStat
.
setYear
(
calendar
.
get
(
Calendar
.
YEAR
));
}
try
{
//获取设备总数
List
<
DeviceEntity
>
deviceList
=
deviceService
.
find
(
new
DeviceQuery
().
siteId
(
siteId
));
Integer
deviceTotalCount
=
deviceList
.
size
();
//未激活数量
Long
deviceUnActiveCount
=
deviceList
.
parallelStream
()
.
filter
(
f
->
f
.
getDeviceStatus
()
==
DeviceStatusEnum
.
未激活
.
getValue
())
.
count
();
//激活设备
Integer
deviceActiveCount
=
deviceList
.
size
()
-
deviceUnActiveCount
.
intValue
();
deviceStatEntity
.
setDeviceTotalCount
(
deviceTotalCount
);
deviceStatEntity
.
setDeviceAddCount
(
deviceTotalCount
-
yesterdayDeviceStat
.
getDeviceTotalCount
());
///统计按当前站点归集 // TODO: 2022/8/22
if
(
platFormType
.
equalsIgnoreCase
(
PlatformTypeEnum
.
STANDALONE
.
getValue
()))
{
List
<
SiteEntity
>
list
=
siteService
.
getFlatSitesBySiteId
(
siteId
,
context
);
deviceStatEntity
.
setSiteTotalCount
(
list
.
size
());
deviceStatEntity
.
setSiteAddCount
(
list
.
size
()
-
yesterdayDeviceStat
.
getSiteTotalCount
());
}
else
{
Rest
<
List
<
SitePdu
>>
resp
=
siteFeign
.
getFlatSitesBySiteId
(
new
SitePdu
().
id
(
siteId
));
if
(
resp
.
getCode
()
==
1
)
{
List
<
SitePdu
>
sitePduList
=
resp
.
getData
();
deviceStatEntity
.
setSiteTotalCount
(
sitePduList
.
size
());
deviceStatEntity
.
setSiteAddCount
(
sitePduList
.
size
()
-
yesterdayDeviceStat
.
getSiteTotalCount
());
}
}
//在线数量
Long
deviceOnlineCount
=
deviceList
.
parallelStream
()
.
filter
(
f
->
f
.
getDeviceStatus
()
>
DeviceStatusEnum
.
未激活
.
getValue
())
.
filter
(
f
->
f
.
getEnabled
()
==
EnabledEnum
.
启用
.
getValue
())
.
filter
(
f
->
f
.
getDeviceStatus
()
==
DeviceStatusEnum
.
在线
.
getValue
())
.
count
();
deviceStatEntity
.
setDeviceOnlineCount
(
deviceOnlineCount
.
intValue
());
//在线率=在线设备/所有激活设备
if
(
deviceActiveCount
>
0
)
{
deviceStatEntity
.
setDeviceOnlineRatio
(
new
BigDecimal
(
deviceOnlineCount
).
divide
(
new
BigDecimal
(
deviceActiveCount
),
4
,
ROUND_HALF_DOWN
));
}
//离线数量
Long
deviceOfflineCount
=
deviceList
.
parallelStream
()
.
filter
(
f
->
f
.
getDeviceStatus
()
>
DeviceStatusEnum
.
未激活
.
getValue
())
.
filter
(
f
->
f
.
getEnabled
()
==
EnabledEnum
.
启用
.
getValue
())
.
filter
(
f
->
f
.
getDeviceStatus
()
==
DeviceStatusEnum
.
离线
.
getValue
())
.
count
();
deviceStatEntity
.
setDeviceOfflineCount
(
deviceOfflineCount
.
intValue
());
if
(
deviceActiveCount
>
0
)
{
deviceStatEntity
.
setDeviceOfflineRatio
(
new
BigDecimal
(
deviceOfflineCount
).
divide
(
new
BigDecimal
(
deviceActiveCount
),
4
,
ROUND_HALF_DOWN
));
}
//停用数量
Long
deviceStopCount
=
deviceList
.
parallelStream
()
.
filter
(
f
->
f
.
getDeviceStatus
()
>
DeviceStatusEnum
.
未激活
.
getValue
())
.
filter
(
f
->
f
.
getEnabled
()
==
YesNoEnum
.
NO
.
getValue
())
.
count
();
deviceStatEntity
.
setDeviceStopCount
(
deviceStopCount
.
intValue
());
if
(
deviceActiveCount
>
0
)
{
deviceStatEntity
.
setDeviceStopRatio
(
new
BigDecimal
(
deviceStopCount
).
divide
(
new
BigDecimal
(
deviceActiveCount
),
4
,
ROUND_HALF_DOWN
));
}
deviceStatEntity
.
setDeviceUnActiveCount
(
deviceUnActiveCount
.
intValue
());
if
(
deviceActiveCount
>
0
)
{
deviceStatEntity
.
setDeviceUnActiveRatio
(
new
BigDecimal
(
deviceUnActiveCount
).
divide
(
new
BigDecimal
(
deviceActiveCount
),
4
,
ROUND_HALF_DOWN
));
}
//今日告警数量
DeviceAlarmInfoQuery
deviceAlarmInfoQuery
=
new
DeviceAlarmInfoQuery
();
deviceAlarmInfoQuery
.
setCreateTimeStart
(
DateUtils
.
getCurrStrDate
());
deviceAlarmInfoQuery
.
setCreateTimeEnd
(
DateUtils
.
getCurrStrDate
());
int
alarmTotalCount
=
deviceAlarmInfoService
.
count
(
deviceAlarmInfoQuery
,
null
);
deviceStatEntity
.
setAlarmTotalCount
(
alarmTotalCount
);
deviceStatEntity
.
setAlarmAddCount
(
alarmTotalCount
-
yesterdayDeviceStat
.
getAlarmTotalCount
());
//推送数量
AlarmSmsSendQuery
alarmSmsSendQuery
=
new
AlarmSmsSendQuery
();
alarmSmsSendQuery
.
setSendTimeStart
(
DateUtils
.
getCurrStrDate
());
alarmSmsSendQuery
.
setSendTimeEnd
(
DateUtils
.
getCurrStrDate
());
alarmSmsSendQuery
.
setSendStatus
(
SendStatusEnum
.
发送成功
.
getValue
());
int
pushTotalCount
=
alarmSmsSendService
.
count
(
alarmSmsSendQuery
,
null
);
deviceStatEntity
.
setPushTotalCount
(
pushTotalCount
);
deviceStatEntity
.
setPushAddCount
(
pushTotalCount
-
yesterdayDeviceStat
.
getPushTotalCount
());
//上行下行数量
DeviceLogQuery
deviceLogQuery
=
new
DeviceLogQuery
();
deviceLogQuery
.
setCreateTimeStart
(
DateUtils
.
getCurrStrDate
());
deviceLogQuery
.
setCreateTimeEnd
(
DateUtils
.
getCurrStrDate
());
deviceLogQuery
.
setLogType
(
LogTypeEnum
.
上报事件
.
getValue
());
int
uploadMessageTotalCount
=
deviceLogService
.
count
(
deviceLogQuery
,
null
);
deviceLogQuery
.
setLogType
(
LogTypeEnum
.
下发服务
.
getValue
());
int
downloadMessageTotalCount
=
deviceLogService
.
count
(
deviceLogQuery
,
null
);
deviceStatEntity
.
setUploadMessageTotalCount
(
uploadMessageTotalCount
);
deviceStatEntity
.
setDownloadMessageTotalCount
(
downloadMessageTotalCount
);
deviceStatEntity
.
setSiteId
(
siteId
);
if
(
deviceStatEntity
.
newEntity
())
{
deviceStatEntity
.
setCreateTime
(
new
Date
());
deviceStatService
.
save
(
deviceStatEntity
);
}
else
{
deviceStatEntity
.
setUpdateTime
(
new
Date
());
deviceStatService
.
update
(
deviceStatEntity
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"统计异常"
,
e
);
throw
new
AppException
(
"统计异常!"
);
}
}
}
}
\ No newline at end of file
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