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

update codes

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