package com.lf.server.config;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
import com.lf.server.entity.data.FmeLogEntity;
|
import com.lf.server.service.all.ScheduleService;
|
import com.lf.server.service.all.WebSocketService;
|
import com.lf.server.service.show.AutoQueryService;
|
import com.lf.server.service.show.OneMapService;
|
import com.lf.server.service.sys.AttachService;
|
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.LogFactory;
|
import org.apache.ibatis.annotations.Result;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
/**
|
* 日程配置类
|
* @author WWW
|
*/
|
@Component
|
@EnableScheduling
|
public class ScheduleConfig {
|
@Resource
|
AttachService attachService;
|
|
@Resource
|
ScheduleService scheduleService;
|
|
@Resource
|
AutoQueryService autoQueryService;
|
|
@Resource
|
OneMapService oneMapService;
|
|
private static boolean isBusy = false;
|
|
private static final Log log = LogFactory.getLog(ScheduleConfig.class);
|
|
@Scheduled(cron = "0 0 1 * * ?")
|
public void autoQuery() {
|
autoQueryService.autoQuery();
|
}
|
|
@Scheduled(cron = "0 0 2 * * ?")
|
public void calcData() {
|
oneMapService.calcData();
|
}
|
|
@Scheduled(fixedRate = 15 * 1000)
|
public void pushMonitorInfo() {
|
try {
|
JSONObject jsonObject = new JSONObject();
|
|
// 查询Cpu信息
|
jsonObject.put("cpuInfo", scheduleService.selectCpuInfo());
|
// 查询内存信息
|
jsonObject.put("memInfo", scheduleService.selectMemInfo());
|
// 查询在线用户
|
jsonObject.put("userInfo", scheduleService.selectOnlineUsers());
|
|
String json = JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue);
|
|
WebSocketService.broadCastInfo(json);
|
} catch (Exception ex) {
|
log.error(ex.getMessage(), ex);
|
}
|
}
|
|
@Scheduled(fixedRate = 30 * 1000)
|
public void checkSystemStatus() {
|
try {
|
JSONObject jsonObject = new JSONObject();
|
|
// 查询服务资源状态
|
jsonObject.put("resInfo", scheduleService.selectResStatus());
|
|
String json = JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue);
|
|
WebSocketService.broadCastInfo(json);
|
} catch (Exception ex) {
|
log.error(ex.getMessage(), ex);
|
}
|
}
|
|
@Scheduled(fixedRate = 30 * 1000)
|
public void countSystemStatus() {
|
// noinspection AlibabaRemoveCommentedCode
|
try {
|
JSONObject jsonObject = new JSONObject();
|
|
// 服务资源状态 sys_res
|
jsonObject.put("resUseCount", scheduleService.countResStatus());
|
|
// 用户登录状态 sys_login
|
jsonObject.put("userLoginCount", scheduleService.userLoginCount());
|
|
// 资源操作状态 sys_operate
|
jsonObject.put("operateCount", scheduleService.operateCount());
|
|
// 资源调用状态
|
String json = JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue);
|
|
WebSocketService.broadCastInfo(json);
|
} catch (Exception ex) {
|
log.error(ex.getMessage(), ex);
|
}
|
}
|
|
/**
|
* 同步附件
|
*/
|
@Scheduled(fixedRate = 30 * 1000)
|
public void syncAttaches() {
|
try {
|
List<FmeLogEntity> list = attachService.selectFmeLogs();
|
if (isBusy || null == list || list.isEmpty()) {
|
return;
|
}
|
|
isBusy = true;
|
for (FmeLogEntity entity : list) {
|
attachService.syncAttaches(entity);
|
attachService.updateFmeLog(entity.getId());
|
}
|
isBusy = false;
|
} catch (Exception ex) {
|
isBusy = false;
|
log.error(ex.getMessage(), ex);
|
}
|
}
|
}
|