严智鑫
2024-08-01 903adb90f70518fce4bc22d69008c3eee30e4f89
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
package com.mes.job;
 
import cn.hutool.json.JSONObject;
import com.mes.bigstorage.entity.BigStorageCageDetails;
import com.mes.bigstorage.service.BigStorageCageDetailsService;
import com.mes.bigstorage.service.BigStorageCageService;
import com.mes.common.S7object;
import com.mes.common.utils.RedisUtil;
import com.mes.device.PlcParameterObject;
import com.mes.temperingglass.entity.TemperingGlassInfo;
import com.mes.temperingglass.service.TemperingGlassInfoService;
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.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * @author SNG-015
 */
@Component
@Slf4j
public class PlcSlicecage {
 
    @Resource
    private BigStorageCageService bigStorageCageService;
    @Resource
    private BigStorageCageDetailsService bigStorageCageDetailsService;
    @Resource
    private TemperingGlassInfoService temperingGlassInfoService;
    @Resource
    private RedisUtil redisUtil;
 
    private JSONObject jsonObject = new JSONObject();
    public void queryDataSource1() throws InterruptedException {
        List<Double> carPostion=new ArrayList<>();
        carPostion.add(0.25);
        carPostion.add(0.5);
        jsonObject.append("carPostion",carPostion);
        //界面展示笼子信息
        jsonObject.append("bigStorageCageInfos", bigStorageCageService.querybigStorageCageDetail());
 
        //进片任务数据
        List<BigStorageCageDetails> bigStorageCageDetailsFeedTask=bigStorageCageDetailsService.selectFeedTask();
        jsonObject.append("bigStorageCageDetailsFeedTask", bigStorageCageDetailsFeedTask);
 
        //出片任务数据
        List<BigStorageCageDetails> bigStorageCageDetailsOutTask=bigStorageCageDetailsService.selectOutTask();
        jsonObject.append("bigStorageCageDetailsOutTask", bigStorageCageDetailsOutTask);
 
        //理片笼使用情况
        List<Map<String, Object>> bigStorageCageUsage=bigStorageCageService.selectBigStorageCageUsage();
        jsonObject.append("bigStorageCageUsage", bigStorageCageUsage);
 
        //理片笼表格信息
        jsonObject.append("bigStorageCageInfo", bigStorageCageService.querybigStorageCageDetailAll());
 
        //钢化开关
        boolean temperingSwitch=false;
        if(redisUtil.getCacheObject("temperingSwitch")==null){
            redisUtil.setCacheObject("temperingSwitch", false);
        }else{
            temperingSwitch=redisUtil.getCacheObject("temperingSwitch");
        }
        jsonObject.append("temperingSwitch", temperingSwitch);
 
    }
 
    public void queryDataSource2() throws InterruptedException {
        //出片队列
        List<TemperingGlassInfo> temperingGlassInfoList= temperingGlassInfoService.list();
        jsonObject.append("temperingGlassInfoList", temperingGlassInfoList);
 
    }
    /**
     * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成)
     * fixedDelay : 上一个调用结束后再次调用的延时
     */
    @Scheduled(fixedDelay = 1000)
    public void plcStorageCageTask() throws InterruptedException {
        jsonObject = new JSONObject();
        try {
            //查询使用数据源1查询数据
            queryDataSource1();
            //查询使用数据源2查询数据
            queryDataSource2();
 
            ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("slicecage");
            if (sendwServer != null) {
                for (WebSocketServer webserver : sendwServer) {
                    if (webserver != null) {
                        webserver.sendMessage(jsonObject.toString());
                        List<String> messages = webserver.getMessages();
                        if (!messages.isEmpty()) {
                            // // 将最后一个消息转换为整数类型的列表
                            webserver.clearMessages();
                        }
                    } else {
                        log.info("Home is closed");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
}