ZengTao
2024-12-25 2935442d9bdb795fecaa704d3bce2f6249b208d4
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
package com.mes.job;
 
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mes.common.config.Const;
import com.mes.damage.entity.Damage;
import com.mes.damage.service.DamageService;
import com.mes.temperingglass.service.TemperingGlassInfoService;
import com.mes.temperingglass.entity.TemperingGlassInfo;
import com.mes.tools.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author SNG-010
 */
@Component
@Slf4j
public class PlcTemperingGlassTask {
 
    @Autowired
    private TemperingGlassInfoService temperingAgoService;
    @Autowired
    private DamageService damageService;
 
    /**
     * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成)
     * fixedDelay : 上一个调用结束后再次调用的延时
     */
 
    @Scheduled(fixedDelay = 1000)
    public void temperingGlassHome() {
        JSONObject jsonObject = new JSONObject();
        //正在等待进片的玻璃
        List<TemperingGlassInfo> waitingGlass = temperingAgoService.selectWaitingGlass();
        if (waitingGlass != null) {
            jsonObject.append("waitingGlass", waitingGlass);
        }
 
        //获取整在炉中的两个版图id
        List<TemperingGlassInfo> layoutId = temperingAgoService.selectLayoutId();
        //进炉中的玻璃
        if (!layoutId.isEmpty()) {
            for (int i = 0; i < layoutId.size(); i++){
                List<TemperingGlassInfo> intoGlass = temperingAgoService.selectIntoGlass(layoutId.get(i));
                jsonObject.append("intoGlass"+(i+1), intoGlass);
            }
//            List<TemperingGlassInfo> intoGlass = temperingAgoService.selectIntoGlass(layoutId.get(0));
//            jsonObject.append("intoGlass", intoGlass);
//            //进炉中的第二个版图
//            if (layoutId.size() > 1) {
//                List<TemperingGlassInfo> intoGlass2 = temperingAgoService.selectIntoGlass(layoutId.get(1));
//                jsonObject.append("intoGlass2", intoGlass2);
//            }
 
        }
        //出炉后的玻璃
        List<TemperingGlassInfo> outGlass = temperingAgoService.selectOutGlass();
        if (outGlass != null) {
            jsonObject.append("outGlass", outGlass);
        }
 
        //过旋转台钢化后的玻璃
        List<TemperingGlassInfo> overGlass = temperingAgoService.selectOverGlass();
        if (outGlass != null) {
            jsonObject.append("overGlass", overGlass);
        }
 
 
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("temperingGlass");
        if (sendwServer != null) {
            for (WebSocketServer webserver : sendwServer) {
                if (webserver != null) {
                    webserver.sendMessage(jsonObject.toString());
                } else {
                    log.info("Home is closed");
                }
            }
        }
    }
 
    @Scheduled(fixedDelay = 1000)
    public void temperingIsRun() {
        JSONObject jsonObject = new JSONObject();
        //正在进行的任务
        List<TemperingGlassInfo> temperingTaskType = temperingAgoService.selectTaskType();
        jsonObject.append("temperingTaskType", temperingTaskType);
 
 
        ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("temperingIsRun");
        if (sendwServer != null) {
            for (WebSocketServer webserver : sendwServer) {
                if (webserver != null) {
                    webserver.sendMessage(jsonObject.toString());
                } else {
                    log.info("Home is closed");
                }
            }
        }
 
    }
 
 
}