手环监控Job流程:
1.从缓存中获取手环的deviceCodeMap,并进行判断: ---(开启状态的)
为null:该Job此次任务结束,等待下次任务
不为null:执行void process(Map<Object, Object> deviceCodeMap)方法
2.
2.1.在process()方法中,获取告警定义(手环无位点上报,【手环空位点上报[我的任务]】),
2.2.遍历deviceCodeMap ,
2.2.1/首先过滤开启不足一分钟的手环,和设置成过滤状态的手环设备
2.2.2/然后根据 手环的编码【参数】,和一定的时间区间【参数】,事件类型(已写死在sql中了),
查询 bl_event_record表,获取这个手环的事件记录
2.2.2.1/判断事件记录列表:
为null:手环无位点上报,持久化,发告警,【清除空位点缓存,我的逻辑】
不为null:进一步判断是否是空位点:
是空位点:
获取空位点缓存,判断缓存是否为null:
null:第一次空位点上报的事件记录,创建触发器实体【20分钟】,存入缓存
非null:判断是否满足告警产生条件(缓存不为null,且缓存中的时间+20小于等于当前时间)
满足:修改缓存,持久化,发告警
不是空位点:即是有效位点
清空位点缓存
问题:
0.nextPossibleTriggerTime != null && nextPossibleTriggerTime.before(now)
1.触发器实体中的triggeredAlarmCounter,没有用到
2.话术中的间隔时间怎么设置?因为第一次20分钟,以后10分钟一次
3.数据库中startTime和endTime字段类型是时间戳(有具体的时分秒),但查询封装后对应的时间没有具体的时分秒,全是
2019-04-03 16:55:36 2019-04-03 16:55:36
startTime=2019-04-03 00:00:00, endTime=2019-04-03 00:00:00]
后面根据的代码逻辑就有问题:
如,设置触发器实体的下次期望触发时间,因为他是根据getStartTime,然后设置的
4// 有效位点,清除空位点缓存,是否可以优化:
redisTemplate.opsForHash().delete(MonitorCacheConstant.MONITOR_BLANKSITEREPORT_DEVICES, braceletLocationSingleRecord.getDeviceId());
因为,每一次遍历,只要发现是有效位点,这句都会执行---》可以加个判断,非null的时候才删除
从数据库中查的数据:{1507636;rs.getDate方式:2019-04-03865352032097411;{};2019-04-03 18:39:24.0;2019-04-03 18:39:24.0}
工具类转换的Wed Apr 03 18:39:24 CST 2019
从数据库中查的数据:{1507643;rs.getDate方式:2019-04-03865352032097411;{};2019-04-03 18:39:39.0;2019-04-03 18:39:39.0}
工具类转换的Wed Apr 03 18:39:39 CST 2019
目前问题:
序列化 :实现普通的序列化接口 (已解决)
时间问题:用工具类转:具体看service方法 (已解决)
getOuterSerialNumberByDeviceCode获取外部码:期望1,发现2 (待定,有时有,有时没有,测试数据的问题)
最新问题:
邮件发送job里,发送配置为0,要查看alarmsendingConf表
package com.mdiaf.webapp.filter;
org.springframework.data.redis.serializer.SerializationException:
Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException:
Failed to serialize object using DefaultSerializer; nested exception is java.lang.IllegalArgumentException:
DefaultSerializer requires a Serializable payload but received an object of type [com.mdiaf.monitor.entity.AlarmTriggerEntity]
# 表结构:bl_event_record
DESC bl_event_record;
BLE基站无位点上报告警: bl_event_record表 18:00-18:00 eventType = 'Locationinfo' ,createOn content中未涉及的基站(位置)
SELECT DISTINCT eventtype FROM bl_event_record
SELECT * FROM bl_event_record WHERE eventType = 'LocationGathering' ORDER BY createdon DESC
# 根据eventType 和 createOn进行查询
SELECT * FROM bl_event_record WHERE eventType = 'LocationInfo' ORDER BY createdon DESC
SELECT COUNT(*) FROM bl_event_record WHERE eventType = 'LocationInfo' ORDER BY createdon DESC
-- 要去重查询:
SELECT DISTINCT deviceId FROM bl_event_record WHERE eventType = 'LocationInfo' AND createdon > '2019-03-31 18:44:41' ORDER BY createdon DESC
SELECT DISTINCT deviceId FROM bl_event_record WHERE eventType = 'LocationInfo' AND createdon > '2019-03-31 18:44:41' AND deviceid = '65310' ORDER BY createdon DESC
SELECT * FROM bl_event_record WHERE eventType = 'LocationInfo' AND createdon > '2019-03-31 18:44:41' ORDER BY createdon DESC
SELECT COUNT(*) FROM bl_event_record WHERE eventType = 'LocationInfo' AND createdon > '2019-04-01 18:44:41' ORDER BY createdon DESC
## 问题:在获取设备名称时,一个deviceCode 对应多个 OutterSerialNumber
4.8
package com.mdiaf.monitor.job;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import com.mdiaf.baf.AiafContext;
import com.mdiaf.batch.service.BafJobCommand;
import com.mdiaf.bmf.SObject;
import com.mdiaf.groovy.GroovyBafBinding;
import com.mdiaf.monitor.constant.ConfigParameterConstant;
import com.mdiaf.monitor.enums.AlarmTypeEnums;
import com.mdiaf.monitor.genmodel.AlarmDefinition;
import com.mdiaf.monitor.service.AlarmService;
import com.mdiaf.monitor.service.DeviceService;
import com.mdiaf.orm.service.BafJobOrmService;
import com.mdiaf.orm.service.util.OrmUtilities;
import com.mdiaf.pas.service.AdminAggrManager;
import com.mdiaf.recon.genmodel.BafJob;
import com.mdiaf.util.BafDateUtils;
import com.mdiaf.util.LogType;
import com.mdiaf.webapp.util.DateUtil;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
@Component
public class MonitorTimestampItemNotCreatedScanJob implements BafJobCommand {
@Autowired
private DeviceService deviceService;
@Autowired
private AlarmService alarmService;
@Autowired
private AdminAggrManager adminAggrManager;
@Autowired
private RedisTemplate<Serializable, Serializable> redisTemplate;
private final Logger log = LoggerFactory.getLogger(LogType.JOB);
@Override
public String getJobInstKey(Object jobParameters, SObject jobId) throws Exception {
if (StringUtils.isNotEmpty((String) jobParameters)) { //Should of format yyyy-MM-dd
//jobTime = BafDateUtils.parseDate((String) jobParameters);
return (String) jobParameters;
}
Date jobTime = new Date();
String currentJobEndTime = BafDateUtils.formatDate(jobTime, BafDateUtils.SYS_DEFAULT_DATE_FORMAT_STRING2);
return currentJobEndTime;
}
@Override
public void execute(JobExecutionContext context) throws Exception {
try {
List<AlarmDefinition> alarmDefinitionList = alarmService.getAlarmDefinitionListByAlarmType(AlarmTypeEnums.TimestampItemNotCreated);
for (final AlarmDefinition alarmDefinition : alarmDefinitionList) {
new Thread(alarmDefinition.getAlarmCode()) {
public void run() {
log.debug("Thread: " + getName() + "running");
process(alarmDefinition);
}
}.start();
}
} catch (Exception e) {
log.error("监控流程状态时间节点未生成Job异常:{}", e.getMessage(), e);
}
}
private void process(AlarmDefinition alarmDefinition) {
// 获取并计算时间段,取该时间段内的数据
Date endTime = new Date();
int intervalTime = adminAggrManager.getConfigParameterValue(ConfigParameterConstant.WorkflowProcess_TimestampItemNotCreated_CHECKING_INTERVAL, 1);
Date startTime = DateUtil.addMinute(endTime, -intervalTime);
// String preConditionGroovyLine = alarmDefinition.getPreconditionScript();
String triggerGroovyLine = alarmDefinition.getTriggerScript();
if (StringUtils.isBlank(triggerGroovyLine))
return;
Binding binding = new GroovyBafBinding(AiafContext.getContext());
binding.setVariable("startTime", BafDateUtils.formatTimestamp(startTime));
binding.setVariable("endTime", BafDateUtils.formatTimestamp(endTime));
GroovyShell shell = new GroovyShell(binding);
Script script = shell.parse(triggerGroovyLine);
script.setBinding(binding);
Object result = script.run();
}
@Override
public List<String> getMissedJobs(Long jobId) {
//List<String> jobKeys = Lists.newArrayList();
getLastSuccessJobInstKey(jobId);
return null;
}
private String getLastSuccessJobInstKey(Long jobId) {
OrmUtilities.modifyBegin();
BafJobOrmService bafJobOrmService = AiafContext.getBean(BafJobOrmService.class);
BafJob bafJob = bafJobOrmService.findOneById(jobId);
String result = bafJob == null ? null : bafJob.getLastSuccessJobKey();
OrmUtilities.modifyEnd();
return result;
}
}