Commit a47eecb4 authored by 赵啸非's avatar 赵啸非

添加告警消息统计逻辑

parent 837df04d
...@@ -83,4 +83,37 @@ ALTER TABLE mortals_xhx_idgenerator ADD COLUMN `createTime` datetime(0) NULL DE ...@@ -83,4 +83,37 @@ ALTER TABLE mortals_xhx_idgenerator ADD COLUMN `createTime` datetime(0) NULL DE
ALTER TABLE mortals_xhx_device ADD COLUMN `resolution` varchar(64) DEFAULT '' COMMENT '设备分辨率' AFTER deviceInFloor; ALTER TABLE mortals_xhx_device ADD COLUMN `resolution` varchar(64) DEFAULT '' COMMENT '设备分辨率' AFTER deviceInFloor;
ALTER TABLE mortals_xhx_device ADD COLUMN `resolutionValue` varchar(64) DEFAULT '' COMMENT '设备分辨率' AFTER resolution; ALTER TABLE mortals_xhx_device ADD COLUMN `resolutionValue` varchar(64) DEFAULT '' COMMENT '设备分辨率' AFTER resolution;
UPDATE mortals_xhx_device_module_distribute SET imageResolution =imageResolutionValue UPDATE mortals_xhx_device_module_distribute SET imageResolution =imageResolutionValue
\ No newline at end of file
-- ----------------------------
2024-03-26
-- ----------------------------
-- ----------------------------
-- 设备消息统计表
-- ----------------------------
DROP TABLE IF EXISTS `mortals_xhx_device_message_stat`;
CREATE TABLE mortals_xhx_device_message_stat(
`id` bigint(20) AUTO_INCREMENT COMMENT 'ID',
`siteId` bigint(20) COMMENT '站点Id,来源基础服务平台',
`productId` bigint(20) COMMENT '产品Id',
`productCode` varchar(256) COMMENT '产品编码',
`productName` varchar(256) COMMENT '产品名称',
`alarmTotalCount` int(9) NOT NULL DEFAULT '0' COMMENT '今日告警数量',
`pushTotalCount` int(9) NOT NULL DEFAULT '0' COMMENT '今日消息推送数量',
`uploadMessageTotalCount` int(9) NOT NULL DEFAULT '0' COMMENT '今日上行消息数量',
`downloadMessageTotalCount` int(9) NOT NULL DEFAULT '0' COMMENT '今日下行消息数量',
`year` int(9) NOT NULL COMMENT '年',
`month` int(9) NOT NULL COMMENT '月',
`day` int(9) NOT NULL COMMENT '日',
`createTime` datetime NOT NULL COMMENT '创建时间',
`updateUserId` bigint(20) COMMENT '更新用户',
`updateTime` datetime COMMENT '更新时间',
PRIMARY KEY (`id`)
,KEY `siteId` (`siteId`) USING BTREE
,KEY `productId` (`productId`) USING BTREE
,KEY `productCode` (`productCode`) USING BTREE
,KEY `productName` (`productName`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='设备消息统计';
...@@ -6,6 +6,7 @@ import com.mortals.framework.service.ITaskExcuteService; ...@@ -6,6 +6,7 @@ import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.common.code.PlatformTypeEnum; 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.DeviceMessageStatService;
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.model.SiteEntity;
import com.mortals.xhx.module.site.model.SiteQuery; import com.mortals.xhx.module.site.model.SiteQuery;
...@@ -29,6 +30,9 @@ public class DeviceTotalStatTaskImpl implements ITaskExcuteService { ...@@ -29,6 +30,9 @@ public class DeviceTotalStatTaskImpl implements ITaskExcuteService {
@Autowired @Autowired
private DeviceStatService deviceStatService; private DeviceStatService deviceStatService;
@Autowired
private DeviceMessageStatService deviceMessageStatService;
@Value("${platform.type:cloud}") @Value("${platform.type:cloud}")
private String platFormType;//版本,默认云服务版本 private String platFormType;//版本,默认云服务版本
...@@ -48,12 +52,15 @@ public class DeviceTotalStatTaskImpl implements ITaskExcuteService { ...@@ -48,12 +52,15 @@ public class DeviceTotalStatTaskImpl implements ITaskExcuteService {
List<SitePdu> siteList = siteFeign.list(sitePdu).getData().getData(); List<SitePdu> siteList = siteFeign.list(sitePdu).getData().getData();
for (SitePdu item : siteList) { for (SitePdu item : siteList) {
deviceStatService.deviceStat(item.getId(), null); deviceStatService.deviceStat(item.getId(), null);
deviceMessageStatService.deviceMessageStat(item.getId(), null);
} }
} else if (platFormType.equalsIgnoreCase(PlatformTypeEnum.STANDALONE.getValue())) { } else if (platFormType.equalsIgnoreCase(PlatformTypeEnum.STANDALONE.getValue())) {
List<SiteEntity> siteEntities = siteService.find(new SiteQuery()); List<SiteEntity> siteEntities = siteService.find(new SiteQuery());
for (SiteEntity siteEntity : siteEntities) { for (SiteEntity siteEntity : siteEntities) {
//判断如果当前节点无设备 则不统计 //判断如果当前节点无设备 则不统计
deviceStatService.deviceStat(siteEntity.getId(), null); deviceStatService.deviceStat(siteEntity.getId(), null);
deviceMessageStatService.deviceMessageStat(siteEntity.getId(), null);
} }
} }
log.info("设备统计任务,生成当天统计数据结束"); log.info("设备统计任务,生成当天统计数据结束");
......
package com.mortals.xhx.module.device.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.framework.model.PageInfo;
import com.mortals.xhx.module.device.model.DeviceMessageStatEntity;
import java.util.List;
/**
* 设备消息统计Dao
* 设备消息统计 DAO接口
*
* @author zxfei
* @date 2024-03-26
*/
public interface DeviceMessageStatDao extends ICRUDDao<DeviceMessageStatEntity,Long>{
String SQLID_GET_STATLIST = "getStatList";
List<DeviceMessageStatEntity> getStatList(DeviceMessageStatEntity query, PageInfo pageInfo);
}
package com.mortals.xhx.module.device.dao.ibatis;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.ParamDto;
import com.mortals.xhx.module.device.dao.DeviceMessageStatDao;
import com.mortals.xhx.module.device.model.DeviceMessageStatEntity;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 设备消息统计DaoImpl DAO接口
*
* @author zxfei
* @date 2024-03-26
*/
@Repository("deviceMessageStatDao")
public class DeviceMessageStatDaoImpl extends BaseCRUDDaoMybatis<DeviceMessageStatEntity,Long> implements DeviceMessageStatDao {
@Override
public List<DeviceMessageStatEntity> getStatList(DeviceMessageStatEntity query, PageInfo pageInfo) {
ParamDto queryParam = super.getQueryParam(query);
if (pageInfo.getPrePageResult() == -1) {
return getSqlSession().selectList(SQLID_GET_STATLIST, queryParam);
} else {
RowBounds rowBounds = new RowBounds(pageInfo.getBeginIndex(), pageInfo.getPrePageResult());
return getSqlSession().selectList(SQLID_GET_STATLIST, queryParam, rowBounds);
}
}
}
package com.mortals.xhx.module.device.model;
import java.util.List;
import java.util.ArrayList;
import java.math.BigDecimal;
import cn.hutool.core.date.DateUtil;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.device.model.vo.DeviceMessageStatVo;
import lombok.Data;
/**
* 设备消息统计实体对象
*
* @author zxfei
* @date 2024-03-26
*/
@Data
public class DeviceMessageStatEntity extends DeviceMessageStatVo {
private static final long serialVersionUID = 1L;
/**
* 站点Id,来源基础服务平台
*/
private Long siteId;
/**
* 产品Id
*/
private Long productId;
/**
* 产品编码
*/
private String productCode;
/**
* 产品名称
*/
private String productName;
/**
* 今日告警数量
*/
private Integer alarmTotalCount;
/**
* 今日消息推送数量
*/
private Integer pushTotalCount;
/**
* 今日上行消息数量
*/
private Integer uploadMessageTotalCount;
/**
* 今日下行消息数量
*/
private Integer downloadMessageTotalCount;
/**
* 年
*/
private Integer year;
/**
* 月
*/
private Integer month;
/**
* 日
*/
private Integer day;
@Override
public int hashCode() {
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof DeviceMessageStatEntity) {
DeviceMessageStatEntity tmp = (DeviceMessageStatEntity) obj;
if (this.getId() == tmp.getId()) {
return true;
}
}
return false;
}
public void initAttrValue(){
this.siteId = null;
this.productId = null;
this.productCode = "";
this.productName = "";
this.alarmTotalCount = 0;
this.pushTotalCount = 0;
this.uploadMessageTotalCount = 0;
this.downloadMessageTotalCount = 0;
this.year = DateUtil.year(new Date());
this.month = DateUtil.month(new Date())+1;
this.day = DateUtil.dayOfMonth(new Date());
}
}
\ No newline at end of file
package com.mortals.xhx.module.device.model.vo;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.device.model.DeviceMessageStatEntity;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import com.mortals.framework.annotation.Excel;
import java.math.BigDecimal;
import java.util.Date;
/**
* 设备消息统计视图对象
*
* @author zxfei
* @date 2024-03-26
*/
@Data
public class DeviceMessageStatVo extends BaseEntityLong {
/** ID列表 */
private List <Long> idList;
}
\ No newline at end of file
package com.mortals.xhx.module.device.service;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.device.dao.DeviceMessageStatDao;
import com.mortals.xhx.module.device.model.DeviceMessageStatEntity;
/**
* DeviceMessageStatService
*
* 设备消息统计 service接口
*
* @author zxfei
* @date 2024-03-26
*/
public interface DeviceMessageStatService extends ICRUDService<DeviceMessageStatEntity,Long>{
DeviceMessageStatDao getDao();
/**
* 设备统计当天消息情况
* @param context
*/
void deviceMessageStat(Long siteId, Context context);
}
\ No newline at end of file
package com.mortals.xhx.module.device.service.impl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.module.device.dao.DeviceMessageStatDao;
import com.mortals.xhx.module.device.model.DeviceAlarmInfoQuery;
import com.mortals.xhx.module.device.model.DeviceMessageStatEntity;
import com.mortals.xhx.module.device.model.DeviceMessageStatQuery;
import com.mortals.xhx.module.device.service.DeviceAlarmInfoService;
import com.mortals.xhx.module.device.service.DeviceLogService;
import com.mortals.xhx.module.device.service.DeviceMessageStatService;
import com.mortals.xhx.module.product.model.ProductEntity;
import com.mortals.xhx.module.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* DeviceMessageStatService
* 设备消息统计 service实现
*
* @author zxfei
* @date 2024-03-26
*/
@Service("deviceMessageStatService")
@Slf4j
public class DeviceMessageStatServiceImpl extends AbstractCRUDServiceImpl<DeviceMessageStatDao, DeviceMessageStatEntity, Long> implements DeviceMessageStatService {
@Autowired
private DeviceAlarmInfoService deviceAlarmInfoService;
@Autowired
private DeviceLogService deviceLogService;
@Autowired
private ProductService productService;
@Override
public void deviceMessageStat(Long siteId, Context context) {
//查询当天统计,如果有 则更新统计结果,否则新增
try {
List<ProductEntity> productEntities = productService.find(new ProductEntity());
for (ProductEntity productEntity : productEntities) {
Calendar calendar = Calendar.getInstance();
DeviceMessageStatEntity deviceStatEntity = this.selectOne(new DeviceMessageStatQuery()
.siteId(siteId)
.productId(productEntity.getId())
.year(calendar.get(Calendar.YEAR))
.month(calendar.get(Calendar.MONTH) + 1)
.day(calendar.get(Calendar.DAY_OF_MONTH)));
if (ObjectUtils.isEmpty(deviceStatEntity)) {
deviceStatEntity = new DeviceMessageStatEntity();
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));
}
//告警数量 按产品分组
DeviceAlarmInfoQuery deviceAlarmInfoQuery = new DeviceAlarmInfoQuery();
deviceAlarmInfoQuery.setCreateTimeStart(DateUtils.getCurrStrDate());
deviceAlarmInfoQuery.setCreateTimeEnd(DateUtils.getCurrStrDate());
deviceAlarmInfoQuery.setProductId(productEntity.getId());
int alarmTotalCount = deviceAlarmInfoService.count(deviceAlarmInfoQuery, null);
deviceStatEntity.setAlarmTotalCount(alarmTotalCount);
/* //上行下行数量
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);*/
if (deviceStatEntity.newEntity()) {
deviceStatEntity.setCreateTime(new Date());
this.save(deviceStatEntity);
} else {
deviceStatEntity.setUpdateTime(new Date());
this.update(deviceStatEntity);
}
}
} catch (Exception e) {
log.error("统计异常", e);
throw new AppException("统计异常!");
}
}
@Override
public Result<DeviceMessageStatEntity> find(DeviceMessageStatEntity query, PageInfo pageInfo, Context context) throws AppException {
Result<DeviceMessageStatEntity> deviceStatEntityResult = new Result<>();
List<DeviceMessageStatEntity> billInfos = this.getDao().getStatList(query, pageInfo);
deviceStatEntityResult.setList(billInfos);
deviceStatEntityResult.setPageInfo(pageInfo);
return deviceStatEntityResult;
}
}
\ No newline at end of file
package com.mortals.xhx.module.device.web;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.device.model.DeviceMessageStatEntity;
import com.mortals.xhx.module.device.service.DeviceMessageStatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* 设备消息统计
*
* @author zxfei
* @date 2024-03-26
*/
@RestController
@RequestMapping("device/message/stat")
public class DeviceMessageStatController extends BaseCRUDJsonBodyMappingController<DeviceMessageStatService, DeviceMessageStatEntity, Long> {
@Autowired
private ParamService paramService;
public DeviceMessageStatController() {
super.setModuleDesc("设备消息统计");
}
@Override
protected void init(Map<String, Object> model, Context context) {
super.init(model, context);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.module.device.dao.ibatis.DeviceMessageStatDaoImpl">
<!-- 获取统计列表 -->
<select id="getStatList" parameterType="paramDto" resultMap="DeviceStatEntity-Map">
select
<!-- 获取分组字段 -->
<if test="groupList != null and !groupList.isEmpty()">
<foreach collection="groupList" open="" close="" index="index" item="item">
${item},
</foreach>
</if>
id,
siteId,
productId,
productCode,
productName,
createTime,
year,
month,
day,
<!-- 告警数量-->
sum(IFNULL(a.alarmTotalCount, 0)) alarmTotalCount,
<!-- 消息推送数量-->
sum(IFNULL(a.pushTotalCount,0)) pushTotalCount,
sum(IFNULL(a.uploadMessageTotalCount,0)) uploadMessageTotalCount,
sum(IFNULL(a.downloadMessageTotalCount,0)) downloadMessageTotalCount
from mortals_xhx_device_message_stat as a
<trim suffixOverrides="where" suffix="">
where
<trim prefixOverrides="and" prefix="">
<include refid="_condition_"/>
</trim>
</trim>
<include refid="_group_by_"/>
<include refid="_orderCols_"/>
</select>
</mapper>
\ No newline at end of file
###登录
POST {{baseUrl}}/login/login
Content-Type: application/json
{
"loginName":"admin",
"password":"admin",
"securityCode":"8888"
}
> {%
client.global.set("SmsSet_id", JSON.parse(response.body).data.id);
client.global.set("authToken", JSON.parse(response.body).data.token);
%}
###设备消息统计列表
POST {{baseUrl}}/device/message/stat/list
Content-Type: application/json
{
"siteId":190,
"productId":709,
"productCode":"Yiwfue",
"productName":"cGCSyE",
"alarmTotalCount":0,
"pushTotalCount":0,
"uploadMessageTotalCount":0,
"downloadMessageTotalCount":0,
"page":1,
"size":10
}
###设备消息统计更新与保存
POST {{baseUrl}}/device/message/stat/save
Authorization: {{authToken}}
Content-Type: application/json
{
"siteId":707,
"productId":130,
"productCode":"eKWzZy",
"productName":"0F6Mab",
"alarmTotalCount":0,
"pushTotalCount":0,
"uploadMessageTotalCount":0,
"downloadMessageTotalCount":0,
"year":580,
"month":584,
"day":16,
}
> {%
client.global.set("DeviceMessageStat_id", JSON.parse(response.body).data.id);
%}
###设备消息统计查看
GET {{baseUrl}}/device/message/stat/info?id={{DeviceMessageStat_id}}
Accept: application/json
###设备消息统计编辑
GET {{baseUrl}}/device/message/stat/edit?id={{DeviceMessageStat_id}}
Accept: application/json
###设备消息统计删除
GET {{baseUrl}}/device/message/stat/delete?id={{DeviceMessageStat_id}}
Authorization: {{authToken}}
Accept: application/json
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