change - add采集设备告警、超过电阈值定时任务

main
yinq 4 months ago
parent 0c66b0d39e
commit c247d56deb

@ -48,11 +48,11 @@ public class EmsBaseMonitorThresholdServiceImpl implements IEmsBaseMonitorThresh
public List<EmsBaseMonitorThreshold> selectEmsBaseMonitorThresholdList(EmsBaseMonitorThreshold emsBaseMonitorThreshold) {
List<EmsBaseMonitorThreshold> monitorThresholds = emsBaseMonitorThresholdMapper.selectEmsBaseMonitorThresholdList(emsBaseMonitorThreshold);
if (monitorThresholds.size() == 0 && StringUtils.isNotEmpty(emsBaseMonitorThreshold.getMonitorCode())){
if (monitorThresholds.size() == 0 && StringUtils.isNotEmpty(emsBaseMonitorThreshold.getMonitorCode())) {
EmsBaseMonitorInfo monitorInfo = new EmsBaseMonitorInfo();
monitorInfo.setMonitorCode(emsBaseMonitorThreshold.getMonitorCode());
List<EmsBaseMonitorInfo> monitorInfoList = emsBaseMonitorInfoMapper.selectEmsBaseMonitorInfoList(monitorInfo);
if (monitorInfoList.size() > 0) {
if (monitorInfoList.size() > 0 && monitorInfoList.get(0).getIsAmmeter().equals("1")) {
EmsBaseMonitorInfo emsBaseMonitorInfo = monitorInfoList.get(0);
emsBaseMonitorThreshold.setCreateBy(SecurityUtils.getUsername());
emsBaseMonitorThreshold.setMonitorType(emsBaseMonitorInfo.getMonitorType());

@ -65,4 +65,15 @@ public interface IEmsRecordAlarmDataService
* @return
*/
public int handleExceptionsAlarmData(Long[] objIds);
/**
*
*/
public void collectDeviceAlarmsTask();
/**
*
*/
public void exceedDnbThresholdAlarmsTask();
}

@ -1,7 +1,22 @@
package com.os.ems.record.service.impl;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.os.common.utils.DateUtils;
import com.os.common.utils.StringUtils;
import com.os.ems.base.domain.EmsBaseCollectDeviceInfo;
import com.os.ems.base.domain.EmsBaseMonitorThreshold;
import com.os.ems.base.mapper.EmsBaseCollectDeviceInfoMapper;
import com.os.ems.base.mapper.EmsBaseMonitorThresholdMapper;
import com.os.ems.record.domain.EmsRecordAlarmRule;
import com.os.ems.record.domain.EmsRecordDnbInstant;
import com.os.ems.record.mapper.EmsRecordAlarmRuleMapper;
import com.os.ems.record.mapper.EmsRecordDnbInstantMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.os.ems.record.mapper.EmsRecordAlarmDataMapper;
@ -12,92 +27,98 @@ import static com.os.common.utils.SecurityUtils.getUsername;
/**
* Service
*
*
* @author Yinq
* @date 2024-05-15
*/
@Service
public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
{
@Service("AlarmDataService")
public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService {
@Autowired
private EmsRecordAlarmDataMapper emsRecordAlarmDataMapper;
@Autowired
private EmsRecordAlarmRuleMapper emsRecordAlarmRuleMapper;
@Autowired
private EmsBaseCollectDeviceInfoMapper emsBaseCollectDeviceInfoMapper;
@Autowired
private EmsRecordDnbInstantMapper emsRecordDnbInstantMapper;
@Autowired
private EmsBaseMonitorThresholdMapper emsBaseMonitorThresholdMapper;
/**
*
*
*
* @param objId
* @return
*/
@Override
public EmsRecordAlarmData selectEmsRecordAlarmDataByObjId(Long objId)
{
public EmsRecordAlarmData selectEmsRecordAlarmDataByObjId(Long objId) {
return emsRecordAlarmDataMapper.selectEmsRecordAlarmDataByObjId(objId);
}
/**
*
*
*
* @param emsRecordAlarmData
* @return
*/
@Override
public List<EmsRecordAlarmData> selectEmsRecordAlarmDataList(EmsRecordAlarmData emsRecordAlarmData)
{
public List<EmsRecordAlarmData> selectEmsRecordAlarmDataList(EmsRecordAlarmData emsRecordAlarmData) {
return emsRecordAlarmDataMapper.selectEmsRecordAlarmDataList(emsRecordAlarmData);
}
/**
*
*
*
* @param emsRecordAlarmData
* @return
*/
@Override
public int insertEmsRecordAlarmData(EmsRecordAlarmData emsRecordAlarmData)
{
public int insertEmsRecordAlarmData(EmsRecordAlarmData emsRecordAlarmData) {
emsRecordAlarmData.setCreateTime(DateUtils.getNowDate());
return emsRecordAlarmDataMapper.insertEmsRecordAlarmData(emsRecordAlarmData);
}
/**
*
*
*
* @param emsRecordAlarmData
* @return
*/
@Override
public int updateEmsRecordAlarmData(EmsRecordAlarmData emsRecordAlarmData)
{
public int updateEmsRecordAlarmData(EmsRecordAlarmData emsRecordAlarmData) {
emsRecordAlarmData.setUpdateTime(DateUtils.getNowDate());
return emsRecordAlarmDataMapper.updateEmsRecordAlarmData(emsRecordAlarmData);
}
/**
*
*
*
* @param objIds
* @return
*/
@Override
public int deleteEmsRecordAlarmDataByObjIds(Long[] objIds)
{
public int deleteEmsRecordAlarmDataByObjIds(Long[] objIds) {
return emsRecordAlarmDataMapper.deleteEmsRecordAlarmDataByObjIds(objIds);
}
/**
*
*
*
* @param objId
* @return
*/
@Override
public int deleteEmsRecordAlarmDataByObjId(Long objId)
{
public int deleteEmsRecordAlarmDataByObjId(Long objId) {
return emsRecordAlarmDataMapper.deleteEmsRecordAlarmDataByObjId(objId);
}
/**
*
*
* @param objIds
* @return
*/
@ -113,4 +134,155 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
}
return 1;
}
/**
*
*/
public void collectDeviceAlarmsTask() {
long minuteValue = 1000 * 60;
Date date = new Date();
EmsRecordAlarmRule alarmRule = new EmsRecordAlarmRule();
alarmRule.setTriggerRule(1L);
List<EmsRecordAlarmRule> alarmRules = emsRecordAlarmRuleMapper.selectEmsRecordAlarmRuleList(alarmRule);
if (alarmRules.size() > 0) {
minuteValue = alarmRules.get(0).getDeviceOfflineTime() * minuteValue;
} else {
return;
}
EmsBaseCollectDeviceInfo collectDeviceInfo = new EmsBaseCollectDeviceInfo();
collectDeviceInfo.setIsFlag("1");
List<EmsBaseCollectDeviceInfo> deviceInfoList = emsBaseCollectDeviceInfoMapper.selectEmsBaseCollectDeviceInfoList(collectDeviceInfo);
if (deviceInfoList.size() > 0) {
EmsRecordAlarmData recordAlarmData = new EmsRecordAlarmData();
recordAlarmData.setAlarmType(1L);
recordAlarmData.setAlarmStatus(1L);
List<EmsRecordAlarmData> alarmDataList = emsRecordAlarmDataMapper.selectEmsRecordAlarmDataList(recordAlarmData);
List<String> collectDeviceIdList = alarmDataList.stream().map(EmsRecordAlarmData::getCollectDeviceId).collect(Collectors.toList());
for (EmsBaseCollectDeviceInfo deviceInfo : deviceInfoList) {
if (collectDeviceIdList.contains(deviceInfo.getCollectDeviceId())) {
continue;
}
if ((deviceInfo.getUpdateTime().getTime() + minuteValue) < date.getTime()) {
EmsRecordAlarmData alarmData = new EmsRecordAlarmData();
alarmData.setCollectDeviceId(deviceInfo.getCollectDeviceId());
alarmData.setCollectTime(new Date());
alarmData.setAlarmType(1L);
alarmData.setAlarmStatus(1L);
alarmData.setAlarmData("设备离线已超过" + alarmRules.get(0).getDeviceOfflineTime() + "分钟");
this.insertEmsRecordAlarmData(alarmData);
}
}
}
}
/**
*
*/
public void exceedDnbThresholdAlarmsTask() {
EmsBaseMonitorThreshold monitorThreshold = new EmsBaseMonitorThreshold();
monitorThreshold.setMonitorType(2L);
List<EmsBaseMonitorThreshold> thresholdList = emsBaseMonitorThresholdMapper.selectEmsBaseMonitorThresholdList(monitorThreshold);
EmsRecordDnbInstant dnbInstant = new EmsRecordDnbInstant();
List<EmsRecordDnbInstant> dnbInstantList = emsRecordDnbInstantMapper.selectEmsRecordDnbInstantList(dnbInstant);
Map<String, String> thresholdMap = compareThresholdAndRecord(thresholdList, dnbInstantList);
//防止多次存入异常数据
EmsRecordAlarmData recordAlarmData = new EmsRecordAlarmData();
recordAlarmData.setAlarmType(0L);
recordAlarmData.setAlarmStatus(1L);
List<EmsRecordAlarmData> alarmDataList = emsRecordAlarmDataMapper.selectEmsRecordAlarmDataList(recordAlarmData);
List<String> monitorIdList = alarmDataList.stream().map(EmsRecordAlarmData::getMonitorId).collect(Collectors.toList());
for (String monitorId : thresholdMap.keySet()) {
if (monitorIdList.contains(monitorId)) {
continue;
}
EmsRecordAlarmData alarmData = new EmsRecordAlarmData();
alarmData.setMonitorId(monitorId);
alarmData.setCollectTime(new Date());
alarmData.setAlarmType(0L);
alarmData.setAlarmStatus(1L);
alarmData.setAlarmData(thresholdMap.get(monitorId));
this.insertEmsRecordAlarmData(alarmData);
}
}
/**
*
*
* @param baseDnbThresholds
* @param recordDnbInstants
* @return
*/
public Map<String, String> compareThresholdAndRecord(List<EmsBaseMonitorThreshold> baseDnbThresholds, List<EmsRecordDnbInstant> recordDnbInstants) {
Map<String, String> resultMap = new HashMap<>();
for (EmsRecordDnbInstant recordDnbInstant : recordDnbInstants) {
String monitorCode = recordDnbInstant.getMonitorCode();
EmsBaseMonitorThreshold baseDnbThreshold = null;
for (EmsBaseMonitorThreshold threshold : baseDnbThresholds) {
if (threshold.getMonitorCode().equals(monitorCode)) {
baseDnbThreshold = threshold;
break;
}
}
if (baseDnbThreshold != null) {
String reason = compare(recordDnbInstant, baseDnbThreshold);
if (reason != null) {
resultMap.put(monitorCode, reason);
}
}
}
return resultMap;
}
private String compare(EmsRecordDnbInstant recordDnbInstant, EmsBaseMonitorThreshold baseDnbThreshold) {
if (StringUtils.isNull(recordDnbInstant.getIA())) {
return null;
}
BigDecimal zero = new BigDecimal("0.00");
if (recordDnbInstant.getVA().compareTo(zero) == 0 || recordDnbInstant.getVB().compareTo(zero) == 0
|| recordDnbInstant.getVC().compareTo(zero) == 0) {
return "缺项报警";
}
if (recordDnbInstant.getIA().compareTo(baseDnbThreshold.getiAMax()) > 0) {
return "超过A相电流最大值";
}
if (recordDnbInstant.getIB().compareTo(baseDnbThreshold.getiBMax()) > 0) {
return "超过B相电流最大值";
}
if (recordDnbInstant.getIC().compareTo(baseDnbThreshold.getiCMax()) > 0) {
return "超过C相电流最大值";
}
if (recordDnbInstant.getVA().compareTo(baseDnbThreshold.getvAMax()) > 0) {
return "超过A相电压最大值";
}
if (recordDnbInstant.getVB().compareTo(baseDnbThreshold.getvBMax()) > 0) {
return "超过B相电压最大值";
}
if (recordDnbInstant.getVC().compareTo(baseDnbThreshold.getvCMax()) > 0) {
return "超过C相电压最大值";
}
if (recordDnbInstant.getIA().compareTo(baseDnbThreshold.getiAMin()) < 0) {
return "小于A相电流最小值";
}
if (recordDnbInstant.getIB().compareTo(baseDnbThreshold.getiBMin()) < 0) {
return "小于B相电流最小值";
}
if (recordDnbInstant.getIC().compareTo(baseDnbThreshold.getiCMin()) < 0) {
return "小于C相电流最小值";
}
if (recordDnbInstant.getVA().compareTo(baseDnbThreshold.getvAMin()) < 0) {
return "小于A相电压最小值";
}
if (recordDnbInstant.getVB().compareTo(baseDnbThreshold.getvBMin()) < 0) {
return "小于B相电压最小值";
}
if (recordDnbInstant.getVC().compareTo(baseDnbThreshold.getvCMin()) < 0) {
return "小于C相电压最小值";
}
return null;
}
}

@ -30,15 +30,21 @@
</dependency>
<!-- 通用工具-->
<!-- <dependency>-->
<!-- <groupId>com.haiwei</groupId>-->
<!-- <artifactId>haiwei-common</artifactId>-->
<!-- </dependency>-->
<!-- MES模块-->
<dependency>
<groupId>com.haiwei</groupId>
<artifactId>haiwei-common</artifactId>
<artifactId>haiwei-mes</artifactId>
</dependency>
<!-- MES模块-->
<!-- 能源模块-->
<dependency>
<groupId>com.haiwei</groupId>
<artifactId>haiwei-mes</artifactId>
<artifactId>haiwei-ems</artifactId>
</dependency>
</dependencies>

@ -0,0 +1,39 @@
package com.os.quartz.task;
import com.os.ems.record.service.IEmsRecordAlarmDataService;
import com.os.mes.api.domain.ERPParamDto;
import com.os.mes.api.service.IERPPortService;
import com.os.mes.api.utils.ERPConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* @Author YinQ
* @create 2023-10-08 9:11
*/
@Component("EMSTask")
public class EMSTask {
@Autowired
private IEmsRecordAlarmDataService emsRecordAlarmDataService;
/**
*
*/
public void collectDeviceAlarmsTask() {
emsRecordAlarmDataService.collectDeviceAlarmsTask();
}
/**
*
*/
public void exceedDnbThresholdAlarmsTask() {
emsRecordAlarmDataService.exceedDnbThresholdAlarmsTask();
}
}
Loading…
Cancel
Save