Commit da291251 authored by 赵建伟's avatar 赵建伟

update codes

parent 8ec00e0c
...@@ -39,4 +39,9 @@ public class IndexController { ...@@ -39,4 +39,9 @@ public class IndexController {
return "index"; return "index";
} }
@GetMapping("/demo")
public String demo(Model model) {
return "static/demo";
}
} }
...@@ -16,27 +16,27 @@ public class DqScheduler { ...@@ -16,27 +16,27 @@ public class DqScheduler {
@Autowired @Autowired
private MonitorService monitorService; private MonitorService monitorService;
@Scheduled(cron="0 10 15 * * ?") @Scheduled(cron="*/60 * * * * ?")
private void uniqueCheckProcess(){ private void uniqueCheckProcess(){
checkService.checkAndPersistSimpleResult(Constants.CHECK_UNIQUE); checkService.checkAndPersistSimpleResult(Constants.CHECK_UNIQUE);
} }
@Scheduled(cron="0 20 15 * * ?") @Scheduled(cron="*/60 * * * * ?")
private void unblankCheckProcess(){ private void unblankCheckProcess(){
checkService.checkAndPersistSimpleResult(Constants.CHECK_UNBLANK); checkService.checkAndPersistSimpleResult(Constants.CHECK_UNBLANK);
} }
@Scheduled(cron="0 30 15 * * ?") @Scheduled(cron="*/60 * * * * ?")
private void referCheckProcess(){ private void referCheckProcess(){
checkService.checkAndPersistMultipleResult(Constants.CHECK_REFER); checkService.checkAndPersistDeplexResult(Constants.CHECK_REFER);
} }
@Scheduled(cron="0 40 15 * * ?") @Scheduled(cron="*/60 * * * * ?")
private void volatilityMonitorProcess(){ private void volatilityMonitorProcess(){
monitorService.monitorAndPersistVolatilityResult(Constants.MONITOR_PV); monitorService.monitorAndPersistVolatilityResult(Constants.MONITOR_PV);
} }
@Scheduled(cron="0 50 15 * * ?") @Scheduled(cron="*/60 * * * * ?")
private void specialMonitorProcess(){ private void specialMonitorProcess(){
monitorService.monitorAndPersistSpecialResult(); monitorService.monitorAndPersistSpecialResult();
} }
......
...@@ -12,6 +12,6 @@ public interface CheckService { ...@@ -12,6 +12,6 @@ public interface CheckService {
* 校验并持久化复杂型校验结果 * 校验并持久化复杂型校验结果
* @param checkType * @param checkType
*/ */
void checkAndPersistMultipleResult(String checkType); void checkAndPersistDeplexResult(String checkType);
} }
...@@ -28,6 +28,7 @@ import com.gmei.data.dqmp.pool.JdbcConnectPool; ...@@ -28,6 +28,7 @@ import com.gmei.data.dqmp.pool.JdbcConnectPool;
import com.gmei.data.dqmp.service.CheckService; import com.gmei.data.dqmp.service.CheckService;
import com.gmei.data.dqmp.service.DingdingService; import com.gmei.data.dqmp.service.DingdingService;
import com.gmei.data.dqmp.service.MailService; import com.gmei.data.dqmp.service.MailService;
import com.gmei.data.dqmp.utils.CrontabUtils;
import com.gmei.data.dqmp.utils.DateUtils; import com.gmei.data.dqmp.utils.DateUtils;
@Service @Service
...@@ -61,6 +62,10 @@ public class CheckServiceImpl implements CheckService { ...@@ -61,6 +62,10 @@ public class CheckServiceImpl implements CheckService {
.andIsValidEqualTo(Constants.IS_VALID_ON); .andIsValidEqualTo(Constants.IS_VALID_ON);
List<TblSqlCheckSingle> sqlList = tblSqlCheckSingleMapper.selectByExampleWithBLOBs(tblCheckSingleSqlCriteria); List<TblSqlCheckSingle> sqlList = tblSqlCheckSingleMapper.selectByExampleWithBLOBs(tblCheckSingleSqlCriteria);
for (TblSqlCheckSingle tblCheckSql : sqlList) { for (TblSqlCheckSingle tblCheckSql : sqlList) {
String checkTime = tblCheckSql.getCheckTime();
if(!CrontabUtils.isToRunByMinites(checkTime)) {
continue;
}
String sql = tblCheckSql.getSqlContent(); String sql = tblCheckSql.getSqlContent();
Integer id = tblCheckSql.getId(); Integer id = tblCheckSql.getId();
Double threshold = tblCheckSql.getThreshold(); Double threshold = tblCheckSql.getThreshold();
...@@ -69,7 +74,7 @@ public class CheckServiceImpl implements CheckService { ...@@ -69,7 +74,7 @@ public class CheckServiceImpl implements CheckService {
TblResultCheckUnique uniqueCheckResult = getUniqueCheckResult(sql); TblResultCheckUnique uniqueCheckResult = getUniqueCheckResult(sql);
if (uniqueCheckResult == null) { if (uniqueCheckResult == null) {
logger.error("Find result is empty!"); logger.error("Find result is empty!");
return; continue;
}else { }else {
Double uniqueRate = uniqueCheckResult.getUniqueRate(); Double uniqueRate = uniqueCheckResult.getUniqueRate();
if(null != uniqueRate && uniqueRate < threshold) { if(null != uniqueRate && uniqueRate < threshold) {
...@@ -83,7 +88,7 @@ public class CheckServiceImpl implements CheckService { ...@@ -83,7 +88,7 @@ public class CheckServiceImpl implements CheckService {
TblResultCheckUnblank tblResultCheckUnblank = getUnblankCheckResult(sql); TblResultCheckUnblank tblResultCheckUnblank = getUnblankCheckResult(sql);
if (tblResultCheckUnblank == null) { if (tblResultCheckUnblank == null) {
logger.error("Find result is empty!"); logger.error("Find result is empty!");
return; continue;
}else { }else {
Double unblankRate = tblResultCheckUnblank.getUnblankRate(); Double unblankRate = tblResultCheckUnblank.getUnblankRate();
if(null != unblankRate && unblankRate < threshold) { if(null != unblankRate && unblankRate < threshold) {
...@@ -107,13 +112,17 @@ public class CheckServiceImpl implements CheckService { ...@@ -107,13 +112,17 @@ public class CheckServiceImpl implements CheckService {
* @param checkType * @param checkType
*/ */
@Override @Override
public void checkAndPersistMultipleResult(String checkType) { public void checkAndPersistDeplexResult(String checkType) {
TblSqlCheckDuplexCriteria tblCheckMultipleSqlCriteria = new TblSqlCheckDuplexCriteria(); TblSqlCheckDuplexCriteria tblCheckMultipleSqlCriteria = new TblSqlCheckDuplexCriteria();
tblCheckMultipleSqlCriteria.createCriteria() tblCheckMultipleSqlCriteria.createCriteria()
.andCheckTypeEqualTo(checkType) .andCheckTypeEqualTo(checkType)
.andIsValidEqualTo(Constants.IS_VALID_ON); .andIsValidEqualTo(Constants.IS_VALID_ON);
List<TblSqlCheckDuplex> sqlList = tblSqlCheckDuplexMapper.selectByExampleWithBLOBs(tblCheckMultipleSqlCriteria); List<TblSqlCheckDuplex> sqlList = tblSqlCheckDuplexMapper.selectByExampleWithBLOBs(tblCheckMultipleSqlCriteria);
for (TblSqlCheckDuplex tblCheckSql : sqlList) { for (TblSqlCheckDuplex tblCheckSql : sqlList) {
String checkTime = tblCheckSql.getCheckTime();
if(!CrontabUtils.isToRunByMinites(checkTime)) {
continue;
}
String sql = tblCheckSql.getSqlContent(); String sql = tblCheckSql.getSqlContent();
Integer id = tblCheckSql.getId(); Integer id = tblCheckSql.getId();
Double threshold = tblCheckSql.getThreshold(); Double threshold = tblCheckSql.getThreshold();
...@@ -122,7 +131,7 @@ public class CheckServiceImpl implements CheckService { ...@@ -122,7 +131,7 @@ public class CheckServiceImpl implements CheckService {
TblResultCheckRefer referCheckResult = getReferCheckResult(sql); TblResultCheckRefer referCheckResult = getReferCheckResult(sql);
if (referCheckResult == null) { if (referCheckResult == null) {
logger.error("Find result is empty!"); logger.error("Find result is empty!");
return; continue;
}else { }else {
Double matchedRate = referCheckResult.getMatchedRate(); Double matchedRate = referCheckResult.getMatchedRate();
if(null != matchedRate && matchedRate < threshold) { if(null != matchedRate && matchedRate < threshold) {
......
...@@ -26,6 +26,7 @@ import com.gmei.data.dqmp.pool.JdbcConnectPool; ...@@ -26,6 +26,7 @@ import com.gmei.data.dqmp.pool.JdbcConnectPool;
import com.gmei.data.dqmp.service.DingdingService; import com.gmei.data.dqmp.service.DingdingService;
import com.gmei.data.dqmp.service.MailService; import com.gmei.data.dqmp.service.MailService;
import com.gmei.data.dqmp.service.MonitorService; import com.gmei.data.dqmp.service.MonitorService;
import com.gmei.data.dqmp.utils.CrontabUtils;
import com.gmei.data.dqmp.utils.DateUtils; import com.gmei.data.dqmp.utils.DateUtils;
@Service @Service
...@@ -58,6 +59,10 @@ public class MonitorServiceImpl implements MonitorService { ...@@ -58,6 +59,10 @@ public class MonitorServiceImpl implements MonitorService {
List<TblSqlMonitorVolatility> sqlList = tblSqlMonitorVolatilityMapper List<TblSqlMonitorVolatility> sqlList = tblSqlMonitorVolatilityMapper
.selectByExampleWithBLOBs(tblmonitorVolatilitySqlCriteria); .selectByExampleWithBLOBs(tblmonitorVolatilitySqlCriteria);
for (TblSqlMonitorVolatility tblCheckSql : sqlList) { for (TblSqlMonitorVolatility tblCheckSql : sqlList) {
String checkTime = tblCheckSql.getCheckTime();
if(!CrontabUtils.isToRunByMinites(checkTime)) {
continue;
}
String sql = tblCheckSql.getSqlContent(); String sql = tblCheckSql.getSqlContent();
Integer id = tblCheckSql.getId(); Integer id = tblCheckSql.getId();
Double threshold = tblCheckSql.getThreshold(); Double threshold = tblCheckSql.getThreshold();
...@@ -65,7 +70,7 @@ public class MonitorServiceImpl implements MonitorService { ...@@ -65,7 +70,7 @@ public class MonitorServiceImpl implements MonitorService {
TblResultMonitorVolatility tblResultMonitorVolatility = getMonitorVolatilityResult(sql, indicatorType); TblResultMonitorVolatility tblResultMonitorVolatility = getMonitorVolatilityResult(sql, indicatorType);
if (tblResultMonitorVolatility == null) { if (tblResultMonitorVolatility == null) {
logger.error("Find result is empty!"); logger.error("Find result is empty!");
return; continue;
}else { }else {
Long indicatorValue = tblResultMonitorVolatility.getIndicatorValue(); Long indicatorValue = tblResultMonitorVolatility.getIndicatorValue();
if(null != indicatorValue && indicatorValue < threshold) { if(null != indicatorValue && indicatorValue < threshold) {
...@@ -93,6 +98,10 @@ public class MonitorServiceImpl implements MonitorService { ...@@ -93,6 +98,10 @@ public class MonitorServiceImpl implements MonitorService {
tblMonitorSpecialSqlCriteria.createCriteria().andIsValidEqualTo(Constants.IS_VALID_ON); tblMonitorSpecialSqlCriteria.createCriteria().andIsValidEqualTo(Constants.IS_VALID_ON);
List<TblSqlMonitorSpecial> sqlList = tblSqlMonitorSpecialMapper.selectByExampleWithBLOBs(tblMonitorSpecialSqlCriteria); List<TblSqlMonitorSpecial> sqlList = tblSqlMonitorSpecialMapper.selectByExampleWithBLOBs(tblMonitorSpecialSqlCriteria);
for (TblSqlMonitorSpecial tblCheckSql : sqlList) { for (TblSqlMonitorSpecial tblCheckSql : sqlList) {
String checkTime = tblCheckSql.getCheckTime();
if(!CrontabUtils.isToRunByMinites(checkTime)) {
continue;
}
String sql = tblCheckSql.getSqlContent(); String sql = tblCheckSql.getSqlContent();
Integer id = tblCheckSql.getId(); Integer id = tblCheckSql.getId();
Double threshold = tblCheckSql.getThreshold(); Double threshold = tblCheckSql.getThreshold();
...@@ -100,7 +109,7 @@ public class MonitorServiceImpl implements MonitorService { ...@@ -100,7 +109,7 @@ public class MonitorServiceImpl implements MonitorService {
TblResultMonitorSpecial tblResultMonitorSpecial = getMonitorSpecialResult(sql); TblResultMonitorSpecial tblResultMonitorSpecial = getMonitorSpecialResult(sql);
if (tblResultMonitorSpecial == null) { if (tblResultMonitorSpecial == null) {
logger.error("Find result is empty!"); logger.error("Find result is empty!");
return; continue;
}else { }else {
Long indicatorValue = tblResultMonitorSpecial.getIndicatorValue(); Long indicatorValue = tblResultMonitorSpecial.getIndicatorValue();
if(null != indicatorValue && indicatorValue < threshold) { if(null != indicatorValue && indicatorValue < threshold) {
......
...@@ -12,21 +12,21 @@ public class CrontabUtils { ...@@ -12,21 +12,21 @@ public class CrontabUtils {
private static final Logger logger = LoggerFactory.getLogger(CrontabUtils.class); private static final Logger logger = LoggerFactory.getLogger(CrontabUtils.class);
/** /**
* 根据crontab表达式判断当前任务是否应该执行【未来一分钟以内】 * 根据crontab表达式判断当前任务是否应该执行【未来1小时以内】
* @param crontabStr * @param crontabStr
* @return * @return
*/ */
public static boolean isToRun(String crontabStr) { public static boolean isToRunByTimeRange(String crontabStr) {
boolean rs = false; boolean rs = false;
Date currentDate = new Date(); Date currentDate = new Date();
long currentDateMilliseconds = currentDate.getTime(); long currentDateMilliseconds = currentDate.getTime();
CronExpression expression = null; CronExpression expression = null;
try { try {
expression = new CronExpression("0 14 20 * * ?"); expression = new CronExpression(crontabStr);
Date newDate = expression.getNextValidTimeAfter(currentDate); Date newDate = expression.getNextValidTimeAfter(currentDate);
long newDateMilliseconds = newDate.getTime(); long newDateMilliseconds = newDate.getTime();
long diffSeconds = (newDateMilliseconds - currentDateMilliseconds)/1000; long diffSeconds = (newDateMilliseconds - currentDateMilliseconds)/1000;
if(diffSeconds < 60) { if(diffSeconds < 60 * 60) {
rs = true; rs = true;
} }
} catch (ParseException e) { } catch (ParseException e) {
...@@ -37,7 +37,27 @@ public class CrontabUtils { ...@@ -37,7 +37,27 @@ public class CrontabUtils {
return rs; return rs;
} }
/**
* 根据crontab表达式判断当前任务是否应该执行【是否跟当前年月日时分一致】
* @param crontabStr
* @return
*/
public static boolean isToRunByMinites(String crontabStr) {
boolean rs = false;
try {
CronExpression expression = new CronExpression(crontabStr);
Date currentDate = new Date();
rs = expression.isSatisfiedBy(currentDate);
} catch (ParseException e) {
logger.error("Fail to parse cron express", e);
} catch (Exception e) {
logger.error("Fail to update rule nextTime", e);
}
return rs;
}
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(isToRun("")); System.out.println(isToRunByTimeRange("0 0 12 25 * ?"));
System.out.println(isToRunByMinites("* 57 10 25 * ?"));
} }
} }
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