严智鑫
2024-05-07 b365a0879edc787655b908b0dbb65b5e966bb23b
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
package com.mes.common;
import cn.hutool.core.date.DateTime;
import cn.hutool.json.JSONObject;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.edgstoragecage.entity.EdgStorageCage;
import com.mes.edgstoragecage.entity.EdgStorageCageDetails;
import com.mes.edgstoragecage.mapper.EdgStorageCageDetailsMapper;
import com.mes.edgstoragecage.service.EdgStorageCageDetailsService;
import com.mes.edgstoragecage.service.EdgStorageCageService;
import com.mes.glassinfo.entity.GlassInfo;
import com.mes.glassinfo.service.GlassInfoService;
import com.mes.taskcache.entity.TaskCache;
import com.mes.taskcache.mapper.TaskCacheMapper;
import com.mes.taskcache.service.TaskCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
@Slf4j
public class PlcHomeEdg extends Thread {
 
 
 
    @Autowired
    TaskCacheService taskCacheService;
    @Autowired
    GlassInfoService glassInfoService;
    @Autowired
    EdgStorageCageService edgStorageCageService;
    @Autowired
    EdgStorageCageDetailsService edgStorageCageDetailsService;
    @Autowired
    private EdgStorageCageDetailsMapper edgStorageCageDetailsMapper;
 
    private Map<String,String> mapParameter=new HashMap<String,String>();
    private Map<String,String> mapValue=new HashMap<String,String>();
    private Map<String,Object> mapSettings=new HashMap<String,Object>();
 
 
    private void initialize(){
        mapParameter.put("A06_request_word","DB11.0");
        mapParameter.put("A05_scanning_ID","DB11.2");
        mapParameter.put("MES_confirmation_word","DB11.40");
        mapParameter.put("A09_glass_status","DB11.70");
        mapParameter.put("A10_glass_status","DB11.72");
        mapParameter.put("A09_prohibit_film_production","DB11.74");
        mapParameter.put("A10_prohibit_film_production","DB11.76");
        mapSettings.put("territoryPoor",3);
 
//        mapValue.put("A06_request_word","1");//请求字
//        mapValue.put("A05_scanning_ID","7");//请求ID
//        mapValue.put("MES_confirmation_word","0");//MES发送字
//        mapValue.put("A09_glass_status","0");//A09玻璃状态
//        mapValue.put("A10_glass_status","0");//A09玻璃状态
//        mapValue.put("A09_prohibit_film_production","0");//A9禁止出片
//        mapValue.put("A10_prohibit_film_production","0");//A10禁止出片
        for (String key:mapParameter.keySet()){
            String value=S7object.getinstance().plccontrol.readString(mapParameter.get(key));
            mapValue.put(key,value);
        }
    }
    private void inTo(){
        List<GlassInfo> glassInfos=glassInfoService.selectId(mapValue.get("A05_scanning_ID"));
        if(glassInfos.size()<1){
            log.info("此玻璃编号不存在");
        }else if(glassInfos.size()==1){
            //添加进片任务  查找空格
            log.info("正常");
            List<EdgStorageCage> list=edgStorageCageService.selectCacheEmpty();
 
            if(list.size()>1){
                EdgStorageCageDetails edgStorageCageDetails=edgStorageCageDetailsMapper.selectOne(new MPJLambdaWrapper<EdgStorageCageDetails>()
                        .eq(EdgStorageCageDetails::getGlassId,glassInfos.get(0).getGlassId()));
                edgStorageCageDetails.setState(200);
 
                TaskCache taskCache=new TaskCache();
                EdgStorageCage edgStorageCage=list.get(0);
                taskCache.setGlassId(glassInfos.get(0).getGlassId());
                taskCache.setTaskStatus(0);
                taskCache.setStartCell(0);
                taskCache.setEndCell(edgStorageCage.getSlot());
                taskCache.setTaskType(1);
                taskCache.setCreateTime(new DateTime());
                edgStorageCageDetailsMapper.updateById(edgStorageCageDetails);
                taskCacheService.insertTaskCache(taskCache);
            }else{
                log.info("不存在空格");
            }
        }else{
            log.info("此玻璃编号存在多个");
        }
    }
    private void outTo(int line){
        int endcell=0;
        EdgStorageCageDetails outEdgStorageCageDetails=new EdgStorageCageDetails();
        TaskCache taskCacheA09=taskCacheService.selectLastOutCacheInfo("");
        TaskCache taskCacheA10=taskCacheService.selectLastOutCacheInfo("");
        //两线各自要出的玻璃
        EdgStorageCageDetails glassInfo09=edgStorageCageDetailsService.selectConformGlass(taskCacheA09.getGlassId(),(int)mapSettings.get("territoryPoor"));
        EdgStorageCageDetails glassInfo10=edgStorageCageDetailsService.selectConformGlass(taskCacheA10.getGlassId(),(int)mapSettings.get("territoryPoor"));
        //决定线路
        if(line==1){
            endcell=9000;
            outEdgStorageCageDetails=glassInfo09;
        }else if(line==2){
            endcell=1000;
            outEdgStorageCageDetails=glassInfo10;
        }else if(line==3){
            endcell=9000;//默认走一号线  优化方向可根据  对比两线速度/两线当前任务情况做
            outEdgStorageCageDetails=glassInfo09;
        }
        if(outEdgStorageCageDetails!=null&&endcell>0){
            TaskCache taskCache=new TaskCache();
            taskCache.setGlassId(outEdgStorageCageDetails.getGlassId());
            taskCache.setTaskStatus(0);
            taskCache.setStartCell(outEdgStorageCageDetails.getSlot());
            taskCache.setEndCell(endcell);
            taskCache.setTaskType(2);
            taskCache.setCreateTime(new DateTime());
            taskCacheService.insertTaskCache(taskCache);
        }
 
 
 
 
    }
    @Override
    public void run() {
        boolean start=true;
        while (this != null&&start) {
            JSONObject jsonObject = new JSONObject();
            try {
                Thread.sleep(1000);
                taskCacheService  = WebSocketServer.applicationContext.getBean(TaskCacheService.class);
                glassInfoService  = WebSocketServer.applicationContext.getBean(GlassInfoService.class);
                edgStorageCageService  = WebSocketServer.applicationContext.getBean(EdgStorageCageService.class);
                edgStorageCageDetailsMapper  = WebSocketServer.applicationContext.getBean(EdgStorageCageDetailsMapper.class);
                initialize();//初始化数据
                log.info("当前参数值:{}",mapValue);
                if("0".equals(mapValue.get("A06_request_word"))){
                    //清除
                    //S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"),(short) 0);
                }else if("1".equals(mapValue.get("A06_request_word"))&&
                         "0".equals(mapValue.get("MES_confirmation_word")))
                {
 
                    inTo();
                }else if("2".equals(mapValue.get("A06_request_word"))&&
                         "0".equals(mapValue.get("MES_confirmation_word"))&&
                        (
                         "0".equals(mapValue.get("A09_glass_status"))||
                         "0".equals(mapValue.get("A10_glass_status"))
                        )
                ){
 
                    outTo(3);
                }else if("3".equals(mapValue.get("A06_request_word"))&&
                         "0".equals(mapValue.get("MES_confirmation_word"))){
 
                    if("0".equals(mapValue.get("A09_glass_status"))||"0".equals(mapValue.get("A10_glass_status"))){
                        outTo(3);
                    }else{
                        inTo();
                    }
                }
 
 
//                List<String> address2=new ArrayList<String>();
//                address.add("");
//                List<String> list2= S7object.getinstance().plccontrol.readStrings(address);
//                PlcParameterObject plcmes=PLCAutoMes.PlcMesObject;
//                log.info("plcmes:{}",plcmes);
//                S7object.getinstance().plccontrol.WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(),(short) 1);
 
//                taskCacheMapper  = WebSocketServer.applicationContext.getBean(TaskCacheMapper.class);
//                List<TaskCache> list=taskCacheMapper.selectList(null);
//                log.info("数据{}",list);
                // 注入mapper
//                HomeService  = WebSocketServer.applicationContext.getBean(HomeService.class);
//                QueueMapper  = WebSocketServer.applicationContext.getBean(QueueMapper.class);
 
 
//                //读取DB105区文件
//                PlcParameterObject plcmes=PLCAutoMes.PlcMesObject;
//
//                String PlcRequest=plcmes.getPlcParameter("GaToMES").getValue();//请求
//                String MesSend=plcmes.getPlcParameter("MESToGaStatus").getValue();//发送
//                double width=Double.valueOf(plcmes.getPlcParameter("width").getValue());//宽
//                double height=Double.valueOf(plcmes.getPlcParameter("Height").getValue());//高
 
                //获取测量的长,宽
                 boolean istest = true;
                // String PlcRequest = "1";
                // String MesSend = "0";
                // double width = 516;
                // double height = 507;
                //System.out.println(111);
                // //查询当前订单任务
                //List<FlowCard> OrderTask = storageCageService.SelectOrderTask();
                //jsonObject.append("OrderTask", OrderTask);
 
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
//            log.info("推数据");
            // jsonObject.append("params", new short[] { 30, 40, });
            ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("Home");
            if (sendwServer != null) {
                for (WebSocketServer webserver : sendwServer) {
                    webserver.sendMessage(jsonObject.toString());
                    if (webserver != null) {
 
                        List<String> messages = webserver.getMessages();
 
                        if (!messages.isEmpty()) {
                            // // 将最后一个消息转换为整数类型的列表
                            webserver.clearMessages();
                        }
                    }
 
                }
            }
        }
    }
}