zhoushihao
2024-11-07 251226a24312a1f3e168db93015be187fb3a44d4
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
package com.mes.job;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject;
import com.mes.rawglassdetails.entity.RawGlassStorageDetails;
import com.mes.rawglassstation.service.RawGlassStorageStationService;
import com.mes.rawglasstask.entity.RawGlassStorageTask;
import com.mes.rawglasstask.service.RawGlassStorageTaskService;
import com.mes.tools.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * @author wangfei
 */
@Slf4j
@Component
public class RawGlassPushMessage {
 
    @Resource
    private RawGlassStorageStationService rawGlassStorageStationService;
 
    @Resource
    private RawGlassStorageTaskService rawGlassStorageTaskService;
 
    @Scheduled(fixedDelay = 2000)
    public void sendRawGlassMessage() {
        log.info("发送任务信息和架子信息");
        JSONObject jsonObject = new JSONObject();
        List<RawGlassStorageDetails> rawStationDetailsList =
                rawGlassStorageStationService.listRawGlassDetails();
        List<RawGlassStorageTask> tasks = rawGlassStorageTaskService.listRawGlassTask();
        jsonObject.append("rawStationDetailsList", rawStationDetailsList);
        jsonObject.append("tasks", tasks);
        List<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("rawGlass");
        if (CollectionUtil.isNotEmpty(sendwServer)) {
            sendwServer.stream().forEach(e -> {
                e.sendMessage(String.valueOf(jsonObject));
            });
        }
    }
}