zhoushihao
2025-01-16 bc6ccc184a87cc623bb6329b7b3f5400f0c209b4
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package com.mes.job;
 
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import com.mes.bigstorage.service.BigStorageCageDetailsService;
import com.mes.bigstorage.service.BigStorageCageService;
import com.mes.bigstoragecagetask.entity.BigStorageCageTask;
import com.mes.bigstoragecagetask.service.BigStorageCageTaskService;
import com.mes.glassinfo.service.GlassInfoService;
import com.mes.temperingglass.entity.TemperingGlassInfo;
import com.mes.temperingglass.service.TemperingGlassInfoService;
import com.mes.tools.WebSocketServer;
import com.mes.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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 OPCPlcSlicecage {
 
    @Resource
    private BigStorageCageService bigStorageCageService;
    @Resource
    private BigStorageCageDetailsService bigStorageCageDetailsService;
    @Resource
    private TemperingGlassInfoService temperingGlassInfoService;
    @Resource
    private RedisUtil redisUtil;
    @Autowired
    private GlassInfoService glassInfoService;
    @Resource
    private BigStorageCageTaskService bigStorageCageTaskService;
 
    @Autowired(required = false)
    MiloService miloService;
 
    private JSONObject jsonObject = new JSONObject();
 
    public void queryDataSource1() throws Exception {
        List<Double> carPostion = new ArrayList<>();
        carPostion.add(0.25);
        carPostion.add(0.5);
        jsonObject.append("carPostion", carPostion);
        //界面展示笼子信息
      jsonObject.append("bigStorageCageInfos", bigStorageCageDetailsService.querybigStorageCageDetail());
 
        try{
            //进片任务数据
            List<BigStorageCageTask> inTaskList = new ArrayList();
            ReadWriteEntity fromOpcUa = miloService.readFromOpcUa("DLP1A.DLP1A.FROM1");
            for (int i = 1; i <= 6; i++) {
                ReadWriteEntity requestWord = miloService.readFromOpcUa("DLP1A.DLP1A.DI" + i);
                ReadWriteEntity targetSlotWord = miloService.readFromOpcUa("DLP1A.DLP1A.TO" + i);
                ReadWriteEntity stateWord = miloService.readFromOpcUa("DLP1A.DLP1A.STATE" + i);
                if (null != requestWord.getValue()) {
                    BigStorageCageTask task = new BigStorageCageTask();
                    task.setGlassId(requestWord.getValue() + "");
                    task.setStartSlot(Integer.parseInt(fromOpcUa.getValue() + ""));
                    task.setTargetSlot(Integer.parseInt(targetSlotWord.getValue() + ""));
                    task.setTaskState(Integer.parseInt(stateWord.getValue() + ""));
                    inTaskList.add(task);
                    continue;
                }
            }
            jsonObject.append("bigStorageCageDetailsFeedTask", inTaskList);
 
            //进片联机
            ReadWriteEntity inkageEntity = miloService.readFromOpcUa("DLP1A.DLP1A.mesControl");
            jsonObject.append("inkageEntity", inkageEntity.getValue());
            //进片请求
            ReadWriteEntity requestEntity = miloService.readFromOpcUa("DLP1A.DLP1A.RequestMes");
            jsonObject.append("requestEntity", requestEntity.getValue());
            //启动命令
            ReadWriteEntity mesReplyEntity = miloService.readFromOpcUa("DLP1A.DLP1A.MesReply");
            jsonObject.append("mesReplyEntity", mesReplyEntity.getValue());
            //出片联机
            ReadWriteEntity outInkageEntity = miloService.readFromOpcUa("DLP1B.DLP1B.mesControl");
            jsonObject.append("outInkageEntity", outInkageEntity.getValue());
            //出片请求
            ReadWriteEntity outRequestEntity = miloService.readFromOpcUa("DLP1B.DLP1B.RequestMes");
            jsonObject.append("outRequestEntity", outRequestEntity.getValue());
        }catch(Exception e){
            //todo:不做任务处理
        }
 
        //出片任务数据
        List<BigStorageCageTask> outTaskList = bigStorageCageTaskService.queryTaskMessage("big_storage_cage_out_one_task");
        jsonObject.append("bigStorageCageDetailsOutTask", outTaskList);
 
 
        //钢化开关
        boolean temperingSwitch = false;
        if (redisUtil.getCacheObject("temperingSwitch") == null) {
            redisUtil.setCacheObject("temperingSwitch", false);
        } else {
            temperingSwitch = redisUtil.getCacheObject("temperingSwitch");
        }
        jsonObject.append("temperingSwitch", temperingSwitch);
 
        //调度开关
        boolean dispatchSwitch = false;
        if (redisUtil.getCacheObject("dispatchSwitch") == null) {
            redisUtil.setCacheObject("dispatchSwitch", false);
        } else {
            dispatchSwitch = redisUtil.getCacheObject("dispatchSwitch");
        }
        jsonObject.append("dispatchSwitch", dispatchSwitch);
 
        //理片笼使用情况
        List<Map<String, Object>> bigStorageCageUsage = bigStorageCageService.selectBigStorageCageUsage();
        jsonObject.append("bigStorageCageUsage", bigStorageCageUsage);
 
 
        //打印开关
        boolean autoPrint = false;
        if (redisUtil.getCacheObject("autoPrint") == null) {
            redisUtil.setCacheObject("autoPrint", false);
        } else {
            autoPrint = redisUtil.getCacheObject("autoPrint");
        }
        jsonObject.append("autoPrint", autoPrint);
 
        //当前指定工程
        String temperingengineerId = "";
        if (redisUtil.getCacheObject("temperingengineerId") == null) {
            redisUtil.setCacheObject("temperingengineerId", temperingengineerId);
        } else {
            temperingengineerId = redisUtil.getCacheObject("temperingengineerId");
        }
        jsonObject.append("temperingengineerId", temperingengineerId);
 
 
    }
 
    public void queryDataSource2() throws InterruptedException {
        //出片队列
        List<TemperingGlassInfo> temperingGlassInfoList = temperingGlassInfoService.list(
                new LambdaQueryWrapper<TemperingGlassInfo>()
                        .inSql(TemperingGlassInfo::getEngineerId, "select distinct engineer_id from tempering_glass_info where state<4")
        );
        jsonObject.append("temperingGlassInfoList", temperingGlassInfoList);
 
    }
 
    /**
     * fixedRate : 上一个调用开始后再次调用的延时(不用等待上一次调用完成)
     * fixedDelay : 上一个调用结束后再次调用的延时
     */
    @Scheduled(fixedDelay = 3000)
    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();
        }
    }
}