13693261870
2025-06-24 8565bd83fcd670ec8379084d600eb97d18037d21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.terra.system.config;
 
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.terra.system.entity.data.FmeLogEntity;
import com.terra.system.service.all.ScheduleService;
import com.terra.system.service.all.WebSocketService;
import com.terra.system.service.show.AutoQueryService;
import com.terra.system.service.sys.AttachService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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;
 
    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(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);
        }
    }
}