package com.whyc.schedule;
|
|
import com.whyc.factory.ThreadPoolExecutorFactory;
|
import com.whyc.service.UpsPowerDataHistoryService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import java.text.ParseException;
|
|
@EnableScheduling
|
@Component
|
public class HistoryScheduleService {
|
|
@Autowired
|
private UpsPowerDataHistoryService dataHistoryService;
|
|
/**
|
* 数据 TODO 暂不分表
|
*/
|
/*@Scheduled(cron = "0/4 * * * * ? ")
|
public void alarmHistory() {
|
ThreadPoolExecutorFactory.getPoolExecutor().execute(() -> {
|
|
});
|
}*/
|
|
|
/**数据保留3个月,每天凌晨0点执行一次*/
|
@Scheduled(cron = "0 0 0 * * ?")
|
public void dataHistoryDeleteBeyond3Month() {
|
ThreadPoolExecutorFactory.getPoolExecutor().execute(() -> {
|
try {
|
dataHistoryService.deleteTableBeyond3Month();
|
} catch (ParseException e) {
|
//e.printStackTrace();
|
}
|
});
|
}
|
|
/**
|
* 5分钟推一笔
|
*/
|
@Scheduled(cron = "0 0/5 * * * ?")
|
public void dataHistory() {
|
ThreadPoolExecutorFactory.getPoolExecutor().execute(() -> {
|
dataHistoryService.getAndSaveHistory();
|
});
|
}
|
}
|
//
|
// public static void ChangeRT_AlarmToHistoryAlarm(MysqlConnPool pool,UPSPwrDeviceAlarm_Data alm){
|
//
|
// ArrayList<String> sql_strs = new ArrayList<String>();
|
// Sql_Mysql sql = new Sql_Mysql(pool);
|
//
|
//
|
// try {
|
//
|
// UPSPwrDevHistoryAlm_SubtableThread_SQL.createPwrHistoryTable(pool, alm);
|
//
|
// //将当前设备实时告警表中的历史告警记录插入到设备历史告警表中
|
// String sql_str2 = " INSERT INTO " + Sql_Mysql.TB_UPSPWRDEV_ALARM_HISTORY + Com.getDateTimeFormat(alm.alm_start_time,Com.DTF_Y) +"(record_id,power_device_id,alm_type,alm_level,alm_start_time,alm_end_time,alm_value,alm_is_confirmed,alm_confirmed_time,alm_cleared_type) (SELECT record_id,power_device_id,alm_type,alm_level,alm_start_time,alm_end_time,alm_value,alm_is_confirmed,alm_confirmed_time,alm_cleared_type from "+Sql_Mysql.TB_UPSPWRDEV_ALARM+" WHERE power_device_id = " + alm.pwrdev_id + " and alm_type = " + alm.alm_type + " and alm_cleared_type = " + UPSPwrDeviceAlarm_Data.ALM_CLEARED_TYPE_HIST + ")";
|
//
|
// //将实时告警表中的非实时告警删除
|
// String sql_str3 = " DELETE FROM " + Sql_Mysql.TB_UPSPWRDEV_ALARM +" WHERE power_device_id = "+ alm.pwrdev_id + " and alm_type = " + alm.alm_type + " and alm_cleared_type = " + UPSPwrDeviceAlarm_Data.ALM_CLEARED_TYPE_HIST;
|
//
|
// //System.err.println(sql_str2);
|
// //System.err.println(sql_str3);
|
// //sql_strs.add(sql_str1);
|
// sql_strs.add(sql_str2);
|
// sql_strs.add(sql_str3);
|
// sql.makeManualCommit(sql_strs);
|
//
|
// } catch (Exception e) {
|
// sql.logger.error(e.toString(), e);
|
// } finally {
|
// sql.close_con();
|
// }
|
//
|
// }
|
//
|
// /***************************** db_upspwrdev_alarm 数据库 **********************************/
|
// public final static String TB_UPSPWRDEV_ALARM = DB_UPSPWRDEV_ALARM + ".tb_upspwrdev_alarm"; //UPS电源实时告警表
|
// public final static String TB_UPSPWRDEV_ALARM_HISTORY = DB_UPSPWRDEV_ALARM + ".tb_upspwrdev_alarm_history_"; //UPS电源历史告警表
|
//
|
// /**
|
// * 创建电源历史告警分表
|
// * @param pool
|
// * @param alm
|
// */
|
// public static void createPwrHistoryTable(MysqlConnPool pool,UPSPwrDeviceAlarm_Data alm) {
|
// String sql_str = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.TB_UPSPWRDEV_ALARM_HISTORY + Com.getDateTimeFormat(alm.alm_start_time, Com.DTF_Y) + "(" +
|
// " `num` bigint(20) NOT NULL AUTO_INCREMENT," +
|
// " `record_id` bigint(20) NOT NULL DEFAULT '0'," +
|
// " `power_device_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '电源id'," +
|
// " `alm_type` int(11) NOT NULL DEFAULT '0' COMMENT '告警id'," +
|
// " `alm_level` int(11) NOT NULL DEFAULT '0' COMMENT '告警等级'," +
|
// " `alm_start_time` datetime NOT NULL DEFAULT '1982-01-01 00:00:00' COMMENT '告警开始时间'," +
|
// " `alm_end_time` datetime NOT NULL DEFAULT '1982-01-01 00:00:00' COMMENT '告警结束时间'," +
|
// " `alm_value` float NOT NULL DEFAULT '0' COMMENT '告警值'," +
|
// " `alm_is_confirmed` tinyint(1) NOT NULL DEFAULT '0' COMMENT '告警是否确认'," +
|
// " `alm_confirmed_time` datetime NOT NULL DEFAULT '1982-01-01 00:00:00' COMMENT '告警确认时间'," +
|
// " `alm_cleared_type` int(11) NOT NULL DEFAULT '0' COMMENT '告警状态0-实时告警 1-历史告警 2-取消的告警'," +
|
// " PRIMARY KEY (`num`)," +
|
// " KEY `index_record_id` (`record_id`)," +
|
// " KEY `index_pwrdev_id` (`power_device_id`)," +
|
// " KEY `index_alm_type` (`alm_type`)," +
|
// " KEY `index_alm_start_time` (`alm_start_time`)," +
|
// " KEY `index_alm_cleared_type` (`alm_cleared_type`)" +
|
// ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='UPS电源历史告警表';" ;
|
// Sql_Mysql sql = new Sql_Mysql(pool);
|
// try {
|
// sql.sqlMysqlExecute(sql_str);
|
// } catch (SQLException e) {
|
// sql.logger.error(e.toString(), e);
|
// } finally{
|
// sql.close_con();
|
// }
|
//
|
// }
|
//
|
//}
|