use of io.jpom.service.monitor.MonitorService in project Jpom by dromara.
the class LoadJsonConfigToDb method loadMonitorInfo.
public void loadMonitorInfo() {
File backupOldData = FileUtil.file(ConfigBean.getInstance().getDataPath(), "backup_old_data");
// 读取 monitor 文件内容
File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.MONITOR_FILE);
if (!FileUtil.exist(file)) {
return;
}
try {
JSON json = JsonFileUtil.readJson(file.getAbsolutePath());
JSONArray jsonArray = JsonFileUtil.formatToArray((JSONObject) json);
List<MonitorModel> monitorModels = jsonArray.toJavaList(MonitorModel.class);
if (monitorModels == null) {
return;
}
MonitorService monitorService = SpringUtil.getBean(MonitorService.class);
monitorService.insert(monitorModels);
// 将 json 文件转移到备份目录
FileUtil.move(file, FileUtil.mkdir(backupOldData), true);
DefaultSystemLog.getLog().info("{} mv to {}", FileUtil.getAbsolutePath(file), FileUtil.getAbsolutePath(backupOldData));
} catch (Exception e) {
DefaultSystemLog.getLog().error("load monitor error ", e);
}
}
Aggregations