Commit 2418c3c5 authored by 赵啸非's avatar 赵啸非

添加手动刷新

parent 842a2233
......@@ -10,11 +10,20 @@
<el-button type="text" size="mini"
>数据更新:{{ formatterDate(statData.updateTime) }}</el-button
>
<el-button icon="el-icon-refresh" size="mini" type="text">手动刷新</el-button>
<el-button
icon="el-icon-refresh"
size="mini"
@click="syncDeviceStat"
type="text"
>手动刷新</el-button
>
</el-row>
<el-card style="margin-left: 50px; margin-right: 50px; margin-top: 10px">
<el-row :gutter="20" style="height:80px;align-items: center;margin-top:10px" >
<el-row
:gutter="20"
style="height: 80px; align-items: center; margin-top: 10px"
>
<el-col :span="3">
<el-row type="flex" justify="center">
<span style="font-size: 20px"
......@@ -22,8 +31,19 @@
></el-row
>
<el-row type="flex" justify="center">
<span style="font-size: 12px;"
><span style="color:#6182f6">昨日 </span ><span v-bind:class="{success: statData.deviceAddCount>=0, warn: statData.deviceAddCount<0}">{{ statData.deviceAddCount>=0?'+'+statData.deviceAddCount:"-"+statData.deviceAddCount }}</span></span
<span style="font-size: 12px"
><span style="color: #6182f6">昨日 </span
><span
v-bind:class="{
success: statData.deviceAddCount >= 0,
warn: statData.deviceAddCount < 0,
}"
>{{
statData.deviceAddCount >= 0
? "+" + statData.deviceAddCount
: "-" + statData.deviceAddCount
}}</span
></span
></el-row
>
<el-row type="flex" justify="center">
......@@ -39,8 +59,19 @@
></el-row
>
<el-row type="flex" justify="center">
<span style="font-size: 12px;"
><span style="color:#6182f6">昨日 </span ><span v-bind:class="{success: statData.siteAddCount>=0, warn: statData.siteAddCount<0}">{{ statData.siteAddCount>=0?'+'+statData.siteAddCount:"-"+statData.siteAddCount }}</span></span
<span style="font-size: 12px"
><span style="color: #6182f6">昨日 </span
><span
v-bind:class="{
success: statData.siteAddCount >= 0,
warn: statData.siteAddCount < 0,
}"
>{{
statData.siteAddCount >= 0
? "+" + statData.siteAddCount
: "-" + statData.siteAddCount
}}</span
></span
></el-row
>
<el-row type="flex" justify="center">
......@@ -57,8 +88,12 @@
>
<el-row type="flex" justify="center">
<span style="font-size: 12px;"
><span style="color:#6182f6">上线率 </span ><span v-bind:class="{success: statData.deviceOnlineRatio>=0}">{{ statData.deviceOnlineRatio* 100 }}%</span></span
<span style="font-size: 12px"
><span style="color: #6182f6">上线率 </span
><span
v-bind:class="{ success: statData.deviceOnlineRatio >= 0 }"
>{{ statData.deviceOnlineRatio * 100 }}%</span
></span
></el-row
>
<el-row type="flex" justify="center">
......@@ -74,8 +109,11 @@
></el-row
>
<el-row type="flex" justify="center">
<span style="font-size: 12px;"
><span style="color:#6182f6">离线率 </span ><span v-bind:class="{warn: statData.deviceOfflineRatio>=0}">{{ statData.deviceOfflineRatio* 100 }}%</span></span
<span style="font-size: 12px"
><span style="color: #6182f6">离线率 </span
><span v-bind:class="{ warn: statData.deviceOfflineRatio >= 0 }"
>{{ statData.deviceOfflineRatio * 100 }}%</span
></span
></el-row
>
<el-row type="flex" justify="center">
......@@ -91,8 +129,11 @@
></el-row
>
<el-row type="flex" justify="center">
<span style="font-size: 12px;"
><span style="color:#6182f6">停用率 </span ><span v-bind:class="{warn: statData.deviceStopRatio>=0}">{{ statData.deviceStopRatio* 100 }}%</span></span
<span style="font-size: 12px"
><span style="color: #6182f6">停用率 </span
><span v-bind:class="{ warn: statData.deviceStopRatio >= 0 }"
>{{ statData.deviceStopRatio * 100 }}%</span
></span
></el-row
>
<el-row type="flex" justify="center">
......@@ -108,8 +149,19 @@
></el-row
>
<el-row type="flex" justify="center">
<span style="font-size: 12px;"
><span style="color:#6182f6">昨日 </span ><span v-bind:class="{success: statData.alarmAddCount>=0, warn: statData.alarmAddCount<0}">{{ statData.alarmAddCount>=0?'+'+statData.alarmAddCount:"-"+statData.alarmAddCount }}</span></span
<span style="font-size: 12px"
><span style="color: #6182f6">昨日 </span
><span
v-bind:class="{
success: statData.alarmAddCount >= 0,
warn: statData.alarmAddCount < 0,
}"
>{{
statData.alarmAddCount >= 0
? "+" + statData.alarmAddCount
: "-" + statData.alarmAddCount
}}</span
></span
></el-row
>
<el-row type="flex" justify="center">
......@@ -118,7 +170,7 @@
>
</el-row>
</el-col>
<el-col :span="3" >
<el-col :span="3">
<el-row type="flex" justify="center"
><span style="font-size: 20px"
><b>{{ statData.pushTotalCount }}</b></span
......@@ -126,8 +178,19 @@
>
<el-row type="flex" justify="center">
<span style="font-size: 12px;"
><span style="color:#6182f6">昨日 </span ><span v-bind:class="{success: statData.pushAddCount>=0, warn: statData.pushAddCount<0}">{{ statData.pushAddCount>=0?'+'+statData.pushAddCount:"-"+statData.pushAddCount }}</span></span
<span style="font-size: 12px"
><span style="color: #6182f6">昨日 </span
><span
v-bind:class="{
success: statData.pushAddCount >= 0,
warn: statData.pushAddCount < 0,
}"
>{{
statData.pushAddCount >= 0
? "+" + statData.pushAddCount
: "-" + statData.pushAddCount
}}</span
></span
></el-row
>
......@@ -137,16 +200,16 @@
>
</el-row>
</el-col>
<el-col :span="3" type="flex" style="height:100%" >
<el-row type="flex" style="margin-top:6px" justify="center"
<el-col :span="3" type="flex" style="height: 100%">
<el-row type="flex" style="margin-top: 6px" justify="center"
><span style="font-size: 13px"
><span style="color:#6182f6">今日下发命令 </span>
><span style="color: #6182f6">今日下发命令 </span>
<b>{{ statData.uploadMessageTotalCount }}</b></span
></el-row
>
<el-row type="flex" style="margin-top:6px" justify="center"
<el-row type="flex" style="margin-top: 6px" justify="center"
><span style="font-size: 13px"
><span style="color:#6182f6">今日下发命令 </span>
><span style="color: #6182f6">今日下发命令 </span>
<b>{{ statData.downloadMessageTotalCount }}</b></span
></el-row
>
......@@ -213,9 +276,7 @@ export default {
this.$post("/device/stat/list", query)
.then((res) => {
if (res.code == 1) {
console.log("res", res);
this.statData = res.data.data[0];
console.log("statData", this.statData);
}
this.loading = false;
})
......@@ -237,6 +298,20 @@ export default {
console.log("process", process.env);
},
methods: {
syncDeviceStat() {
this.$post("/device/stat/syncDeviceStat", {})
.then((res) => {
if (res.code == 1) {
this.statData = res.data.data[0];
} else {
this.$message.error(res.msg);
}
})
.catch((error) => {
this.$message.error(error.message);
});
},
findDeviceTotalStat(beforeday) {
let query = { createTimeStart: this.formatterDate(beforeday) };
this.$post("/device/stat/list", query)
......@@ -709,10 +784,10 @@ export default {
</script>
<style scoped>
.success{
color:green
.success {
color: green;
}
.warn{
.warn {
color: rgb(215, 25, 25);
}
......@@ -721,7 +796,7 @@ export default {
position: relative;
}
.homeIndex::before {
content: '';
content: "";
position: absolute;
top: 0;
left: 0;
......@@ -729,6 +804,5 @@ export default {
height: 35%;
background: #1848c8;
}
</style>
......@@ -62,7 +62,8 @@ public class DeviceTotalStatTaskImpl implements ITaskExcuteService {
@Override
public void excuteTask(ITask task) throws AppException {
doDeviceStat();
deviceService.deviceStat(null);
//doDeviceStat();
}
......
......@@ -53,6 +53,12 @@ public interface DeviceService extends ICRUDCacheService<DeviceEntity,Long>{
DeviceDao getDeviceDao();
/**
* 设备统计当天情况
* @param context
*/
void deviceStat(Context context);
......
package com.mortals.xhx.module.device.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.PatternPool;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
......@@ -9,18 +10,25 @@ import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.busiz.req.DeviceReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.*;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.utils.BeanUtil;
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.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceQuery;
import com.mortals.xhx.module.device.model.*;
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.platform.model.PlatformEntity;
import com.mortals.xhx.module.platform.model.PlatformQuery;
import com.mortals.xhx.module.platform.service.PlatformService;
......@@ -35,7 +43,12 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import static java.math.BigDecimal.ROUND_HALF_DOWN;
import static java.util.stream.Collectors.counting;
/**
* DeviceService
......@@ -56,6 +69,14 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
private DefaultTbCoreConsumerService consumerService;
@Autowired
private ISiteFeign siteFeign;
@Autowired
private DeviceLogService deviceLogService;
@Autowired
private DeviceStatService deviceStatService;
@Autowired
private DeviceAlarmInfoService deviceAlarmInfoService;
@Autowired
private AlarmSmsSendService alarmSmsSendService;
@Override
protected String getExtKey(DeviceEntity data) {
......@@ -130,7 +151,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
}
@Override
public ApiResp<String> sendDeviceMessage(DeviceEntity deviceEntity, TopicPartitionInfo info, TbQueueMsgHeaders header, String message,TbQueueCallback callback, Context context) {
public ApiResp<String> sendDeviceMessage(DeviceEntity deviceEntity, TopicPartitionInfo info, TbQueueMsgHeaders header, String message, TbQueueCallback callback, Context context) {
ApiResp<String> resp = new ApiResp<>();
resp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
resp.setMsg(ApiRespCodeEnum.SUCCESS.getLabel());
......@@ -145,7 +166,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
deviceQuery.setIdList(deviceIds);
List<DeviceEntity> deviceEntityList = this.find(deviceQuery);
for (DeviceEntity deviceEntity : deviceEntityList) {
resp = sendDeviceMessage(deviceEntity, info, header, message,null, context);
resp = sendDeviceMessage(deviceEntity, info, header, message, null, context);
}
return resp;
}
......@@ -206,10 +227,10 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
Set<TopicPartitionInfo> set = new HashSet<>();
set.add(topicPartitionInfo);
if(status==YesNoEnum.YES.getValue()){
if (status == YesNoEnum.YES.getValue()) {
//开启
consumerService.getMainConsumer().subscribe(set);
}else{
} else {
//关闭
consumerService.getMainConsumer().unsubscribe(set);
}
......@@ -303,6 +324,106 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
return this.getDao();
}
@Override
public void deviceStat(Context context) {
//查询当天统计,如果有 则更新统计结果,否则新增
DeviceStatEntity deviceStatEntity = deviceStatService.selectOne(new DeviceStatQuery()
.year(DateUtil.year(new Date()))
.month(DateUtil.month(new Date()) + 1)
.day(DateUtil.dayOfMonth(new Date())));
if (ObjectUtils.isEmpty(deviceStatEntity)) {
deviceStatEntity = new DeviceStatEntity();
deviceStatEntity.initAttrValue();
deviceStatEntity.setCreateTime(new Date());
deviceStatEntity.setYear(DateUtil.year(new Date()));
deviceStatEntity.setMonth(DateUtil.month(new Date()) + 1);
deviceStatEntity.setDay(DateUtil.dayOfMonth(new Date()));
}
//获取昨天统计数据
DeviceStatEntity yesterdayDeviceStat = deviceStatService.selectOne(new DeviceStatQuery()
.year(DateUtil.year(DateUtil.yesterday()))
.month(DateUtil.month(DateUtil.yesterday()) + 1)
.day(DateUtil.dayOfMonth(DateUtil.yesterday())));
if (ObjectUtils.isEmpty(yesterdayDeviceStat)) {
yesterdayDeviceStat = new DeviceStatEntity();
yesterdayDeviceStat.initAttrValue();
}
try {
//获取设备总数
List<DeviceEntity> deviceList = this.find(new DeviceQuery());
Integer deviceTotalCount = deviceList.size();
deviceStatEntity.setDeviceTotalCount(deviceTotalCount);
deviceStatEntity.setDeviceAddCount(deviceTotalCount - yesterdayDeviceStat.getDeviceTotalCount());
//站点数量
SitePdu sitePdu = new SitePdu();
sitePdu.setSize(-1);
Rest<RespData<List<SitePdu>>> resp = siteFeign.list(sitePdu);
if (resp.getCode() == 1) {
List<SitePdu> sitePduList = resp.getData().getData();
deviceStatEntity.setSiteTotalCount(sitePduList.size());
deviceStatEntity.setSiteAddCount(sitePduList.size() - yesterdayDeviceStat.getSiteTotalCount());
}
//在线数量
Long deviceOnlineCount = deviceList.parallelStream().filter(f -> f.getDeviceStatus() == DeviceStatusEnum.在线.getValue()).count();
deviceStatEntity.setDeviceOnlineCount(deviceOnlineCount.intValue());
deviceStatEntity.setDeviceOnlineRatio(new BigDecimal(deviceOnlineCount).divide(new BigDecimal(deviceList.size()), ROUND_HALF_DOWN).setScale(2));
//离线数量
Long deviceOfflineCount = deviceList.parallelStream().filter(f -> f.getDeviceStatus() == DeviceStatusEnum.离线.getValue()).count();
deviceStatEntity.setDeviceOfflineCount(deviceOfflineCount.intValue());
deviceStatEntity.setDeviceOfflineRatio(new BigDecimal(deviceOfflineCount).divide(new BigDecimal(deviceList.size()), ROUND_HALF_DOWN).setScale(2));
//停用数量
Long deviceStopCount = deviceList.parallelStream().filter(f -> f.getEnabled() == YesNoEnum.NO.getValue()).count();
deviceStatEntity.setDeviceStopCount(deviceStopCount.intValue());
deviceStatEntity.setDeviceStopRatio(new BigDecimal(deviceStopCount).divide(new BigDecimal(deviceList.size()), ROUND_HALF_DOWN).setScale(2));
//今日告警数量
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());
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
protected void removeBefore(Long[] ids, Context context) throws AppException {
Arrays.asList(ids).stream().forEach(id -> {
......@@ -366,7 +487,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
DeviceEntity deviceEntity = this.selectOne(new DeviceQuery().deviceCode(entity.getDeviceCode()));
if (!ObjectUtils.isEmpty(deviceEntity)) {
//如果原始的域当前的站点不一致,做更新处理,否则提示编码重复
if (!ObjectUtils.isEmpty(entity.getSiteId())&&entity.getSiteId() != deviceEntity.getSiteId()) {
if (!ObjectUtils.isEmpty(entity.getSiteId()) && entity.getSiteId() != deviceEntity.getSiteId()) {
entity.setId(deviceEntity.getId());
entity.setUpdateTime(new Date());
entity.setUpdateUserId(getContextUserId(context));
......
package com.mortals.xhx.module.device.web;
import cn.hutool.core.date.DateUtil;
import com.mortals.framework.common.Rest;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.device.model.DeviceStatQuery;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.sitestat.model.SitestatQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.device.model.DeviceStatEntity;
import com.mortals.xhx.module.device.service.DeviceStatService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
/**
*
* 设备统计
*
* @author zxfei
* @date 2022-07-05
*/
* 设备统计
*
* @author zxfei
* @date 2022-07-05
*/
@RestController
@RequestMapping("device/stat")
public class DeviceStatController extends BaseCRUDJsonBodyMappingController<DeviceStatService,DeviceStatEntity,Long> {
public class DeviceStatController extends BaseCRUDJsonBodyMappingController<DeviceStatService, DeviceStatEntity, Long> {
@Autowired
private ParamService paramService;
private DeviceService deviceService;
public DeviceStatController(){
super.setModuleDesc( "设备统计");
public DeviceStatController() {
super.setModuleDesc("设备统计");
}
@Override
......@@ -46,4 +55,24 @@ public class DeviceStatController extends BaseCRUDJsonBodyMappingController<Devi
}
/**
* 站点信息
*/
@PostMapping(value = "syncDeviceStat")
public Rest<Object> syncDeviceStat() {
try {
//刷新成功,返回列表
deviceService.deviceStat(getContext());
DeviceStatQuery deviceStatQuery = new DeviceStatQuery();
deviceStatQuery.setYear(DateUtil.year(new Date()));
deviceStatQuery.setMonth(DateUtil.month(new Date()) + 1);
deviceStatQuery.setDay(DateUtil.dayOfMonth(new Date()));
Rest<Object> resp = this.list(deviceStatQuery);
return resp;
} catch (Exception e) {
log.error("刷新异常", e);
return Rest.fail(KEY_RESULT_CODE, super.convertException(e));
}
}
}
\ No newline at end of file
......@@ -14,11 +14,14 @@ import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.feign.user.IUserFeign;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.sitestat.model.SitestatEntity;
import com.mortals.xhx.module.sitestat.model.SitestatQuery;
import com.mortals.xhx.module.sitestat.service.SitestatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -39,6 +42,8 @@ public class SitestatController extends BaseCRUDJsonBodyMappingController<Sitest
@Autowired
private IAuthTokenService authTokenService;
@Autowired
private DeviceService deviceService;
@Autowired
......@@ -148,4 +153,7 @@ public class SitestatController extends BaseCRUDJsonBodyMappingController<Sitest
return jsonObject.toJSONString();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment