严智鑫
2025-03-11 67cbfd8f7c2ed9598eef92470313f3cf31028ea1
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package com.mes.job;
 
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.common.S7objectFlipSlice;
import com.mes.common.S7objectMachine;
import com.mes.common.S7objectMarking;
import com.mes.device.PlcParameterInfo;
import com.mes.device.PlcParameterObject;
import com.mes.md.entity.*;
import com.mes.md.mapper.GlassInfoMapper;
import com.mes.md.mapper.MachineMapper;
import com.mes.md.mapper.TaskingMapper;
import com.mes.md.service.*;
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.Map;
 
/**
 * 自动打标机
 * @Author : yanzhxiin
 * @Date: 2024/8/20 11:19
 * @Description:
 */
@Component
@Slf4j
public class MachineTask {
 
    public static String engineerId = "";
 
    @Autowired
    TaskingMapper taskingMapper;
    @Autowired
    MachineMapper machineMapper;
    @Autowired
    TaskingService taskingService;
    @Autowired
    ProjectService projectService;
    @Autowired
    PrimitiveTaskService primitiveTaskService;
    @Autowired
    KBBTJPDrawingBPService kBBTJPDrawingBPService;
    @Autowired
    LineConfigurationService lineConfigurationService;
    @Autowired
    private GlassInfoMapper glassInfoMapper;
    public List<Map> sendRecords = new ArrayList<>();
    private List<Machine> machineListLoad;
    private List<Machine> machineListEdging;
    private List<Machine> machineListFlipSlice;
    private List<Machine> machineListMarking;
    private List<Machine> machineListSilkScreen;
    private List<Machine> machineListRotate;
    private List<Machine> machineListGlueDispenser;
    private List<Machine> machineListScanQrCode;
    private List<Machine> machineListLamination;
 
    //机械手
    @Scheduled(fixedDelay = 500)
    public void MarkingTasks() {
        machineListLoad =machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName,"上片"));
        JSONObject jsonObject = new JSONObject();
        jsonObject.append("sessionMapName", "loadTask");
        for (Machine machine : machineListLoad) {
            JSONObject jsonObjectItem = new JSONObject();
            //标准模式  找已领取未完成的第一条任务
            LineConfiguration lineConfiguration=lineConfigurationService.machineLineConfiguration(machine);
            //此线路已领取的任务
            List<PrimitiveTask> findPrimitiveTasking=primitiveTaskService.findPrimitiveTasking(machine,lineConfiguration.getLineId());
            //此线路未领取的任务  本地
            //List<PrimitiveTask> findPrimitiveTask=primitiveTaskService.findPrimitiveTaskNotFinish();
            //此线路未领取的任务  客户数据库
            List<KBBTJPDrawingBP> list =kBBTJPDrawingBPService.notReceiveKBBTJPDrawingBP();
            jsonObjectItem.append("findPrimitiveTask", list);
            jsonObjectItem.append("findPrimitiveTasking", findPrimitiveTasking);
            //jsonObject.append("findPrimitiveTask", findPrimitiveTask);
            jsonObjectItem.append("machine", machine);
            jsonObjectItem.append("sendRecords", sendRecords);
            jsonObject.append(machine.getId().toString(), jsonObjectItem);
        }
        this.webSocketServer(jsonObject);
    }
    //磨边机
    @Scheduled(fixedDelay = 500)
    public void edgingTasks() {
        machineListEdging =machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName,"磨边"));
        JSONObject jsonObject = new JSONObject();
        jsonObject.append("sessionMapName", "edgingTask");
        for (Machine machine : machineListEdging) {
            JSONObject jsonObjectItem = new JSONObject();
            List<Tasking> taskingList=taskingService.findMachineTask(machine);
            jsonObjectItem.append("taskingList", taskingList);
            jsonObjectItem.append("machine", machine);
            jsonObjectItem.append("sendRecords", sendRecords);
            jsonObject.append(machine.getId().toString(), jsonObjectItem);
        }
        this.webSocketServer(jsonObject);
    }
 
    //翻片台
    @Scheduled(fixedDelay = 500)
    public void flipSliceTasks() {
        machineListFlipSlice =machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName,"翻片"));
        JSONObject jsonObject = new JSONObject();
        jsonObject.append("sessionMapName", "flipSlice");
        for (Machine machine : machineListFlipSlice) {
            JSONObject jsonObjectItem = new JSONObject();
            List<Tasking> taskingList=taskingService.findMachineTask(machine);
            jsonObjectItem.append("taskingList", taskingList);
            jsonObjectItem.append("machine", machine);
            jsonObjectItem.append("sendRecords", sendRecords);
            jsonObject.append(machine.getId().toString(), jsonObjectItem);
        }
        this.webSocketServer(jsonObject);
    }
 
    //打标机
    @Scheduled(fixedDelay = 500)
    public void markingTasks() {
        machineListMarking =machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName,"自动打标机"));
 
        JSONObject jsonObject = new JSONObject();
        jsonObject.append("sessionMapName", "marking");
        for (Machine machine : machineListMarking) {
            JSONObject jsonObjectItem = new JSONObject();
            List<Tasking> taskingList=taskingService.findMachineTask(machine);
            jsonObjectItem.append("taskingList", taskingList);
            jsonObjectItem.append("machine", machine);
            jsonObjectItem.append("sendRecords", sendRecords);
            jsonObject.append(machine.getId().toString(), jsonObjectItem);
        }
        this.webSocketServer(jsonObject);
    }
 
    //丝印机
    @Scheduled(fixedDelay = 500)
    public void silkScreenTasks() {
        machineListSilkScreen =machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName,"自动丝印机"));
        JSONObject jsonObject = new JSONObject();
        jsonObject.append("sessionMapName", "silkScreenTask");
        for (Machine machine : machineListSilkScreen) {
            JSONObject jsonObjectItem = new JSONObject();
            List<Tasking> taskingList=taskingService.findMachineTask(machine);
            jsonObjectItem.append("taskingList", taskingList);
            jsonObjectItem.append("machine", machine);
            jsonObjectItem.append("sendRecords", sendRecords);
            jsonObject.append(machine.getId().toString(), jsonObjectItem);
        }
        this.webSocketServer(jsonObject);
    }
    //点胶机
    //@Scheduled(fixedDelay = 500)
    public void glueDispenserTasks() {
        machineListGlueDispenser =machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName,"自动点胶机"));
        JSONObject jsonObject = new JSONObject();
        jsonObject.append("sessionMapName", "glueDispenser");
        for (Machine machine : machineListGlueDispenser) {
            JSONObject jsonObjectItem = new JSONObject();
            List<Tasking> taskingList=taskingService.findMachineTask(machine);
            jsonObjectItem.append("taskingList", taskingList);
            jsonObjectItem.append("machine", machine);
            jsonObjectItem.append("sendRecords", sendRecords);
            jsonObject.append(machine.getId().toString(), jsonObjectItem);
        }
        this.webSocketServer(jsonObject);
    }
    //旋转台
    @Scheduled(fixedDelay = 500)
    public void rotateTasks() {
        machineListRotate =machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName,"旋转台"));
        JSONObject jsonObject = new JSONObject();
        jsonObject.append("sessionMapName", "rotate");
        for (Machine machine : machineListRotate) {
            JSONObject jsonObjectItem = new JSONObject();
            List<Tasking> taskingList=taskingService.findMachineTask(machine);
            jsonObjectItem.append("taskingList", taskingList);
            jsonObjectItem.append("machine", machine);
            jsonObjectItem.append("sendRecords", sendRecords);
            jsonObject.append(machine.getId().toString(), jsonObjectItem);
        }
        this.webSocketServer(jsonObject);
    }
    //贴膜机
    @Scheduled(fixedDelay = 500)
    public void laminationTasks() {
        machineListLamination =machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName,"自动贴膜机"));
        JSONObject jsonObject = new JSONObject();
        jsonObject.append("sessionMapName", "lamination");
        for (Machine machine : machineListLamination) {
            JSONObject jsonObjectItem = new JSONObject();
            List<Tasking> taskingList=taskingService.findMachineTask(machine);
            jsonObjectItem.append("taskingList", taskingList);
            jsonObjectItem.append("machine", machine);
            jsonObjectItem.append("sendRecords", sendRecords);
            jsonObject.append(machine.getId().toString(), jsonObjectItem);
        }
        this.webSocketServer(jsonObject);
    }
 
 
    //报工页面查询
    @Scheduled(fixedDelay = 1000)
    public void manualReporting() {
 
        machineListScanQrCode =machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName,"识别报工"));
        JSONObject jsonObject = new JSONObject();
        jsonObject.append("sessionMapName", "manualReporting");
        for (Machine machine : machineListScanQrCode) {
            JSONObject jsonObjectItem = new JSONObject();
            List<Tasking> taskingList=taskingMapper.selectJoinList(Tasking.class,new MPJLambdaWrapper<Tasking>()
                    .selectAll(Tasking.class)
                    .innerJoin(LineConfiguration.class,LineConfiguration::getId,Tasking::getLineConfigurationId)
                    .innerJoin(Machine.class,Machine::getId,LineConfiguration::getMachineId)
                    .eq(LineConfiguration::getMachineId,machine.getId())
                    .eq(Tasking::getGlassState,"正常")
                    .eq(Tasking::getState,"线上")
                    .ne(Tasking::getWorkState,"完工")
                    .orderByDesc(Tasking::getOperationRecordTime));
            jsonObjectItem.append("taskingList", taskingList);
            jsonObjectItem.append("machine", machine);
            jsonObject.append(machine.getId().toString(), jsonObjectItem);
        }
 
        this.webSocketServer(jsonObject);
    }
    //线下玻璃查询
    @Scheduled(fixedDelay = 1000)
    public void downLineTask() {
        JSONObject jsonObject = new JSONObject();
        List<Tasking> downLineTask=taskingService.findDownLineTask();
        jsonObject.append("sessionMapName", "downLineTask");
        jsonObject.append("downLineTask", downLineTask);
        this.webSocketServer(jsonObject);
    }
 
 
    public void webSocketServer(JSONObject jsonObject) {
        try {
            String sessionMapName=jsonObject.getJSONArray("sessionMapName").get(0).toString();
            ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get(sessionMapName);
            if (sendwServer != null) {
                for (WebSocketServer webserver : sendwServer) {
                    if (webserver != null) {
                        try {
                            webserver.sendMessage(jsonObject.toString());
                            List<String> messages = webserver.getMessages();
                            if (!messages.isEmpty()) {
                                // // 将最后一个消息转换为整数类型的列表
                                webserver.clearMessages();
                            }
                        }catch (Exception e) {
 
                        }
                    } else {
                        log.info("Home is closed");
                    }
                }
            }
        }catch (Exception e) {
 
        }
 
    }
 
}