严智鑫
2024-04-24 18f6e14f2cb0e19fc8726e9821bc4db172a04d17
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
package com.mes.downstorage.service.impl;
 
import com.github.yulichang.query.MPJQueryWrapper;
import com.mes.common.PLCAutoMes;
import com.mes.common.S7control;
import com.mes.device.PlcParameterObject;
import com.mes.downglassinfo.entity.DownGlassTask;
import com.mes.downglassinfo.service.DownGlassTaskService;
import com.mes.downstorage.entity.DownStorageCage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mes.downstorage.entity.DownStorageCageDetails;
import com.mes.downstorage.mapper.DownStorageCageDetailsMapper;
import com.mes.downstorage.mapper.DownStorageCageMapper;
import com.mes.downstorage.service.DownStorageCageDetailsService;
import com.mes.downstorage.service.DownStorageCageService;
import com.mes.glassinfo.entity.GlassInfo;
import com.mes.glassinfo.service.GlassInfoService;
import com.mes.tools.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoush
 * @since 2024-03-27
 */
@Slf4j
@Service
public class DownStorageCageServiceImpl extends ServiceImpl<DownStorageCageMapper, DownStorageCage> implements DownStorageCageService {
    @Autowired
    private DownStorageCageMapper downStorageCageMapper;
 
    @Autowired
    private GlassInfoService glassInfoService;
 
    @Autowired
    private DownGlassTaskService downGlassTaskService;
    @Autowired
    private DownStorageCageDetailsService downStorageCageDetailsService;
    @Override
    public List<Map> gettask(){
        downStorageCageMapper.selectList(null);
//        downStorageCageMapper.selectJoin();
        return null;
    };
 
 
 
    @Override
    public List<DownStorageCageDetails> getCacheLeisure() {
        log.info(" 查询笼子内空闲");
        List<DownStorageCageDetails> list = downStorageCageMapper.selectJoinList(
                DownStorageCageDetails.class, new MPJQueryWrapper<DownStorageCageDetails>()
                        .select("escd.*")
                        .leftJoin("down_storage_cage_details escd on t.slot = escd.slot")
                        .isNull("escd.slot")
                        .orderByAsc("escd.slot")
        );
        return list;
    }
 
 
    @Override
    public List<Map> selectCacheEmpty(){
        return baseMapper.selectJoinList(
                Map.class,new MPJQueryWrapper<DownStorageCage>().selectAll(DownStorageCage.class)
                        .select("escd.glass_id","escd.flow_card_id","escd.width","escd.height")
                        .leftJoin("down_storage_cage_details escd on t.device_id=escd.device_id and t.slot=escd.slot")
                        .isNull("escd.slot")
        );
    }
 
 
 
 
 
 
 
    @Override
    public List<DownStorageCageDetails> getCacheOut(int start, int end) {
        log.info("根据传入的工位查询符合按照顺序和大小出片的小片");
        return  downStorageCageMapper.selectJoinList(
                DownStorageCageDetails.class, new MPJQueryWrapper<DownStorageCageDetails>()
                        .select("escd.*")
                        .leftJoin("down_storage_cage_details escd on t.slot = escd.slot")
                        .leftJoin("down_workstation dw on escd.flow_card_id = dw.flow_card_id")
                        .leftJoin("glass_info gi on dw.flow_card_id = gi.flowcard_id  and gi.flowcard_id=escd.flow_card_id ")
                        .isNotNull("escd.slot")
                        .between("dw.workstation_id", start, end)
                        .orderByDesc("escd.width")
                        .orderByDesc("escd.height")
        );
    }
 
 
 
 
 
    @Override
    public List<Map> getCacheInfo() {
        log.info(" 查询笼子内信息");
        return downStorageCageMapper.selectJoinList(
                Map.class, new MPJQueryWrapper<DownStorageCageDetails>()
                        .select("escd.*")
                        .leftJoin("down_storage_cage_details escd on t.slot = escd.slot")
                        .orderByAsc("t.slot")
        );
 
    }
 
 
 
    @Override
    public List<DownStorageCageDetails> getIsExistIntoCacheByLayoutAndSequence(Integer tempering_layout_id, Integer tempering_feed_sequence, double width) {
        log.info(" 查询可进此片玻璃的栅格号  找到相同版图id并且大于前面的顺序的空格");
        List<DownStorageCageDetails> list = downStorageCageMapper.selectJoinList(
                DownStorageCageDetails.class, new MPJQueryWrapper<DownStorageCageDetails>()
                        .select("escd.*")
                        .leftJoin("down_storage_cage_details escd on t.slot = escd.slot")
                        .isNotNull("escd.slot")
                        .eq("escd.tempering_layout_id", tempering_layout_id)
                        .lt("escd.tempering_feed_sequence", tempering_feed_sequence)
                        .gt("t.remain_width", width)
                        .orderByAsc("escd.tempering_feed_sequence")
        );
        return list;
    }
 
 
 
 
 
 
 
    @Override
    public List<DownStorageCageDetails> IsExistIntoCacheByflowcardid(String flowcardid, double width) {
        log.info(" 查询可进此片玻璃的栅格号");
        return downStorageCageMapper.selectJoinList(
                DownStorageCageDetails.class, new MPJQueryWrapper<DownStorageCageDetails>()
                        .select("escd.*")
                        .leftJoin("down_storage_cage_details escd on t.slot = escd.slot")
                        .isNotNull("escd.slot")
                        .lt("escd.flow_card_id", flowcardid)
                        // 条件 t.remain_width - width > 0
                        .apply("t.remain_width - " + width + " > 0")
                        .orderByDesc("escd.tempering_layout_id, escd.tempering_feed_sequence")
        );
 
    }
 
 
    @Override
    public List<DownStorageCageDetails> getIsExistIntoCacheByLayout(Integer tempering_layout_id, double width) {
        log.info(" 查询可进此片玻璃的栅格号");
        return downStorageCageMapper.selectJoinList(
                DownStorageCageDetails.class, new MPJQueryWrapper<DownStorageCageDetails>()
                        .select("escd.*")
                        .leftJoin("down_storage_cage_details escd on t.slot = escd.slot")
                        .isNotNull("escd.slot")
                        .lt("escd.tempering_layout_id", tempering_layout_id)
                        // 条件 t.remain_width - width > 0
                        .apply("t.remain_width - " + width + " > 0")
                        .orderByDesc("escd.tempering_layout_id, escd.tempering_feed_sequence")
        );
 
    }
 
 
 
 
 
 
 
    @Override
    public List<DownStorageCageDetails> getIsExistIntoCacheByflowcardid(String flowcardid, double width) {
        log.info(" 单片情况  查询可进此片玻璃的栅格号  找到相同流程卡号的空格");
 
        return downStorageCageMapper.selectJoinList(
                DownStorageCageDetails.class, new MPJQueryWrapper<DownStorageCageDetails>()
                        .select("escd.*")
                        .leftJoin("down_storage_cage_details escd on t.slot = escd.slot")
                        .isNotNull("escd.slot")
                        .eq("escd.flow_card_id", flowcardid)
                        .gt("t.remain_width", width)
                        .orderByAsc("escd.sequence")
        );
 
    }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    public DownGlassTask createDownGlassTask(GlassInfo glassInfo, String startCell, String endCell,String taskType ) {
        DownGlassTask downGlassTask = new DownGlassTask();
        downGlassTask.setId(glassInfo.getId());
        downGlassTask.setStartCell(startCell);
        downGlassTask.setTaskType(taskType);
        downGlassTask.setEndCell(endCell);
        downGlassTask.setWidth(glassInfo.getWidth());
        downGlassTask.setHeight(glassInfo.getHeight());
        downGlassTask.setFilmsid(String.valueOf(glassInfo.getFilmsid()));
        downGlassTask.setThickness(glassInfo.getThickness());
        downGlassTask.setFlowCardId(glassInfo.getFlowcardId());
 
        return downGlassTask;
    }
 
 
    public DownGlassTask createDownGlassTask(DownStorageCageDetails glassInfo, String startCell, String endCell,String taskType ) {
        DownGlassTask downGlassTask = new DownGlassTask();
        downGlassTask.setId(glassInfo.getId());
        downGlassTask.setStartCell(startCell);
        downGlassTask.setTaskType(taskType);
        downGlassTask.setEndCell(endCell);
        downGlassTask.setWidth(glassInfo.getWidth());
        downGlassTask.setHeight(glassInfo.getHeight());
        downGlassTask.setFilmsid(String.valueOf(glassInfo.getFilmsid()));
        downGlassTask.setThickness(glassInfo.getThickness());
        downGlassTask.setFlowCardId(glassInfo.getFlowCardId());
 
        return downGlassTask;
    }
 
 
    @Override
    public boolean processInto(String Number) {
 
        //按id查询玻璃信息表里的玻璃
        GlassInfo GlassInfo = glassInfoService.selectGlassId(Number);
     PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
        //存在此玻璃编号
        if (GlassInfo != null) {
            //同找到同流程卡附近空格
            List<DownStorageCageDetails> list = getIsExistIntoCacheByflowcardid(GlassInfo.getFlowcardId(),  GlassInfo.getWidth());
 
            List<Map> selectCacheEmpty=selectCacheEmpty();
 
            //            list<Map> list=selectCacheEmpty();
//            list<Map> = downStorageCageService.selectCacheEmpty();
            if (selectCacheEmpty.size() > 0) {
                //存在空格
                //1.生成任务:  起始位置0   结束位置this.slot  任务类型 1   (进片任务)
                //2.回复 1进片
                DownStorageCageDetails item = list.get(0);
 
                //selectInfo.insertCacheTask(GlassInfo.getId() + "", "0", item.getSlot() + "", "1", GlassInfo.getWidth(), GlassInfo.getHeight(), GlassInfo.getFilmsid(), GlassInfo.getThickness(), GlassInfo.getFlowcardId());
 
                DownGlassTask downGlassTask =   createDownGlassTask(GlassInfo,"0",item.getSlot()+"","1");
 
                downGlassTaskService.insertCacheTask(downGlassTask);
 
               S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(), (short) 1);
 
 
                //完成后插入小片数据到缓存表
                return true;
            }
 
        } else {
            // ID编号不存在   不处理/回复PLC  进行报警提示
        }
        //返回结果
        return false;
    }
 
 
    /**
     * 理片 出
     * @return
     */
    //
    @Override
    public boolean processOut() {
        // 查询任务
 
 
        PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
 
        List<DownStorageCageDetails> list = downStorageCageDetailsService.CacheOut(1, 5);
        List<DownStorageCageDetails> list2 = downStorageCageDetailsService.CacheOut(6, 10);
        List<DownStorageCageDetails> list3 = downStorageCageDetailsService.CacheOut(1, 10);
        //自动绑定架子
 
 
 
 
        // 优先 超出尺寸优先人工出片 人工处理
 
        if (!list3.isEmpty()) {
            DownStorageCageDetails item3 = list3.get(0);
            if (item3.getHeight() >= 1 && item3.getWidth() >= 1) {
 
                String endcell = "13";
                String SendEndcell = "1";
 
//                selectInfo.insertCacheTask(item3.getGlassId() + "", "0", endcell, "2", item3.getWidth(), item3.getHeight(), item3.getFilmsid(), item3.getThickness(), item3.getFlowCardId());
 
                DownGlassTask downGlassTask =createDownGlassTask(item3,"0",endcell,"2");
 
                downGlassTaskService.insertCacheTask(downGlassTask);
                S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.28").getAddress(), SendEndcell);
                S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.20").getAddress(), "1");
                return true;
            }
        }
 
 
        //如果同时前后端都空闲 优先后端出片并且优先满架
        else if (!list2.isEmpty()) {
 
            DownStorageCageDetails item3 = list2.get(0);
            String endcell = "11";
            String SendEndcell = "1";
            // selectInfo.insertCacheTask(item3.getGlassId() + "", "0", endcell, "2", item3.getWidth(), item3.getHeight(), item3.getFilmsid(), item3.getThickness(), item3.getFlowCardId());
            DownGlassTask downGlassTask =createDownGlassTask(item3,"0",endcell,"2");
            downGlassTaskService.insertCacheTask(downGlassTask);
 
            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.28").getAddress(), SendEndcell);
            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.20").getAddress(), "1");
            return true;
 
        }
        // 按照大小符合前端出片
        else if (!list.isEmpty()) {
            DownStorageCageDetails item = list.get(0);
 
            // 出到 G06
            //selectInfo.insertCacheTask(item.getGlassId() + "", "0", "06", "2", item.getWidth(), item.getHeight(), item.getFilmsid(), item.getThickness(), item.getFlowCardId());
 
            DownGlassTask downGlassTask =createDownGlassTask(item,"0","06","2");
            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.28").getAddress(), "1");
            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.20").getAddress(), "1");
            return true;
 
            // 按照大小符合后端出片
        } else if (!list2.isEmpty()) {
            DownStorageCageDetails item2 = list2.get(0);
 
            // 出到 G11
            // selectInfo.insertCacheTask(item2.getGlassId() + "", "0", "11", "2", item2.getWidth(), item2.getHeight(), item2.getFilmsid(), item2.getThickness(), item2.getFlowCardId());
            DownGlassTask downGlassTask =createDownGlassTask(item2,"0","11","2");
            downGlassTaskService.insertCacheTask(downGlassTask);
 
            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.28").getAddress(), "2");
            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.20").getAddress(), "1");
            return true;
 
 
        }
 
 
 
        // 返回结果
        return false;
    }
 
 
 
 
 
 
}