廖井涛
2025-06-16 6067c5e5e7e568caa915f5124c71f39fbd2dc1b9
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
package com.northglass.service.identifymachine;
 
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.swing.text.html.HTML;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import com.northglass.Globel.mes;
import com.northglass.SqlHelper.DBSession;
import com.northglass.constants.StateConstants.ConnectState;
import com.northglass.constants.StateConstants.GaoliweiMachineState;
import com.northglass.constants.StateConstants.GlassArrangeState;
import com.northglass.constants.StateConstants.GlassState;
import com.northglass.constants.StateConstants.sendGlassState;
import com.northglass.entity.GalssTask;
import com.northglass.entity.IdentifyError;
import com.northglass.entity.LoadRack;
import com.northglass.entity.Password;
import com.northglass.entity.PatternTask;
import com.northglass.entity.PreprocessingGlass;
import com.northglass.entity.Rank;
import com.northglass.entity.RawPackage;
import com.northglass.entity.ShelfRack;
import com.northglass.entity.ShelfTask;
import com.northglass.entity.Slicecage;
import com.northglass.entity.SlicecagePattern;
import com.northglass.repository.GalssTaskDao;
import com.northglass.repository.IdentifyErrorDao;
import com.northglass.repository.PasswordDao;
import com.northglass.repository.PatternTaskDao;
import com.northglass.repository.PreprocessingGlassDao;
 
 
@Component
@Transactional
public class IdentifyMachineService {
 
    @Autowired
    private GalssTaskDao galssTaskDao;
    
    @Autowired
    private PatternTaskDao patternTaskDao;
    
    @Autowired
    private PasswordDao passwordDao;
    
    @Autowired
    private IdentifyErrorDao identifyErrorDao;
    
    @Autowired
    private PreprocessingGlassDao preprocessingGlassDao;
 
    private static final Logger LOGGER = LoggerFactory.getLogger(IdentifyMachineService.class);
    
    public Map<String, Object> getCeliangManageData(String groups) {
 
        // Long machineId = Long.valueOf(groups);
        PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findBygroup(Integer.parseInt(groups));
        Map<String, Object> param = new HashMap<String, Object>();
        if(preprocessingGlass!=null){
            param.put("actuallength", preprocessingGlass.getActualLength());
            param.put("actualwidth", preprocessingGlass.getActualWidth());
            param.put("color", preprocessingGlass.getColor());
            param.put("thickness", preprocessingGlass.getThickness());
            param.put("status", preprocessingGlass.getStatu());
            if (preprocessingGlass.getGlassId() != 0) {
                param.put("width", preprocessingGlass.getWidth());
                param.put("length", preprocessingGlass.getLength());
                param.put("glassid", preprocessingGlass.getGlassId());
            }
            if (preprocessingGlass.getStatu().equals("匹配失败")) {
                param.put("img", "quxiao.png");
                param.put("mesgess", "玻璃匹配失败");
            }else if(preprocessingGlass.getStatu().equals("匹配失败1")){
                param.put("img", "quxiao.png");
                param.put("mesgess", "玻璃摆放不正确");
            }else if(preprocessingGlass.getStatu().equals("多数据匹配")){
                param.put("img", "quxiao.png");
                param.put("mesgess", "玻璃多数据匹配失败");
            }else {
                param.put("img", "zhengque.png");
            }
            /*int totalPieces = 0;
            int completePieces = 0;
            if (preprocessingGlass.getRawPackageTxt()!=null) {
                List<Glass> glasses = glassDao.findByRaw(preprocessingGlass.getRawPackageTxt().getId());
                if (glasses.size()>0) {
                    for (Glass glass : glasses) {
                        completePieces = completePieces + glass.getCompletePieces();
                        totalPieces = totalPieces + glass.getPieces();
                    }
                }
            }
            param.put("totalPieces", totalPieces);
            param.put("completePieces", completePieces);
            param.put("leftPieces", totalPieces - completePieces);
            param.put("progress", ((double) completePieces / (double) totalPieces * 100) + "%");*/
            // 测量结果显示。
            // - 若找到匹配玻璃,则显示结果为匹配成功,不需要人工处理,自动执行送片;
            // - 若没有找到识别玻璃,则显示两个按钮
            // - 一个是重新匹配,允许用户校正并重新测量;
            // - 另一个是匹配失败,需要用户自己将玻璃移除,并确认;
            StringBuffer html = new StringBuffer();
            param.put("identifyResultHtml", html.toString());
        }
        return param;
 
    }
    
    public List<GalssTask> getGlass(Long groups) {
        PreprocessingGlass preprocessingGlass=preprocessingGlassDao.findBygroup(Integer.parseInt(String.valueOf(groups)));
        if(preprocessingGlass.getStatu().equals("多数据匹配")){
            IdentifyError identifyError=identifyErrorDao.findBygroup(Integer.parseInt(String.valueOf(groups)));
            List<GalssTask> glass=new ArrayList<GalssTask>();
            double minwidth=preprocessingGlass.getActualWidth()-identifyError.getHeigtherror();
            double maxwidth=preprocessingGlass.getActualWidth()+identifyError.getHeigtherror();
            double minheigth=preprocessingGlass.getActualLength()-identifyError.getWidtherror();
            double maxheigth=preprocessingGlass.getActualLength()+identifyError.getWidtherror();
 
            glass=galssTaskDao.findByidentify2(groups,minwidth,maxwidth,minheigth,maxheigth);
            return glass;
        }else{
            List<GalssTask> glass=new ArrayList<GalssTask>();
            glass=galssTaskDao.findByidentify1(groups,preprocessingGlass.getMinwidths());
            return glass;
        }
        
    }
    
    public List<GalssTask> getGlass2(Long groups) {
        PatternTask patternTask =patternTaskDao.findbygroups2(groups);
        PreprocessingGlass preprocessingGlass=preprocessingGlassDao.findBygroup(Integer.parseInt(String.valueOf(groups)));
        List<GalssTask> glass;
        if(patternTask!=null){
             glass=galssTaskDao.findpattern2(groups,preprocessingGlass.getMinwidths());
             /*glass=galssTaskDao.findByidentify1(groups);*/
             glass.addAll(galssTaskDao.findpattern1(patternTask.getId(),preprocessingGlass.getMinwidths()));
        }else if(preprocessingGlass.getStatu().equals("多数据匹配")){
            IdentifyError identifyError=identifyErrorDao.findBygroup(Integer.parseInt(String.valueOf(groups)));
            double minwidth=preprocessingGlass.getActualWidth()-identifyError.getHeigtherror();
            double maxwidth=preprocessingGlass.getActualWidth()+identifyError.getHeigtherror();
            double minheigth=preprocessingGlass.getActualLength()-identifyError.getWidtherror();
            double maxheigth=preprocessingGlass.getActualLength()+identifyError.getWidtherror();
 
            glass=galssTaskDao.findByidentify2(groups,minwidth,maxwidth,minheigth,maxheigth);
            return glass;
        }else{
             glass=galssTaskDao.findByidentify1(groups,preprocessingGlass.getMinwidths());
        }
        
        return glass;
 
        
    }
    
    public String rankhtml(Long groups){
        /*PatternTask patternTask =patternTaskDao.findbygroups2(groups);
        if(patternTask!=null){            
            return patternTask.getRank().toString();
        }else{
            return "";
        }*/
        /*
        Long galssTask=galssTaskDao.findBypatternTask(groups);
        List<GalssTask> g=galssTaskDao.findBypatternTask(groups,galssTask);
        System.out.println(galssTask+":"+g.size());*/
        try {
            DBSession sn=mes.getMesDBHelper().createSession(false);
            sn.createSql("select * from y_Len_CeLiang where Mode_State=1 and groups=? limit 0,1");
            ResultSet r= sn.query(groups).getCurrentResult();
            String minpattern="";
            while (r.next()) {
                minpattern=r.getString("minpattern");
            }    
            sn.createSql(minpattern);
            ResultSet r2= sn.query(groups).getCurrentResult();
            while (r2.next()) {
                return r2.getString(1);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return "";
    }
    
    public String buttonhmtl(int groups){
        StringBuffer html = new StringBuffer();
        PreprocessingGlass preprocessingGlass=preprocessingGlassDao.findBygroup(groups);
        if (preprocessingGlass.getMarking()==1){
            html.append("<button style='background-color: red' type='button' onclick='onchecks(1)' class='btn btn-primary '>打标模式</button>&nbsp;&nbsp;");
            html.append("<button type='button' onclick='onchecks(0)' class='btn btn-primary '>不打标模式</button>");
        }else if (preprocessingGlass.getMarking()==0){
            html.append("<button type='button' onclick='onchecks(1)' class='btn btn-primary '>打标模式</button>&nbsp;&nbsp;");
            html.append("<button style='background-color: red' type='button' onclick='onchecks(0)' class='btn btn-primary '>不打标模式</button>");
        }
        return html.toString();
    }
    
    public String buttonhmtl2(Long groups){
        StringBuffer html = new StringBuffer();
        List<PatternTask> patternTask =patternTaskDao.findbygroups3(groups);
        if (patternTask.size()>0){
            html.append("<button style='background-color: red' type='button' onclick='onchecks3()' class='btn btn-primary '>全单模式</button>&nbsp;&nbsp;");
        }
        return html.toString();
    }
    public String buttonhmthtml(Long groups){
        StringBuffer html = new StringBuffer();
        PreprocessingGlass preprocessingGlass=preprocessingGlassDao.findBygroup(Integer.parseInt(groups+""));
        try {
            DBSession sn=mes.getMesDBHelper().createSession(false);
            sn.createSql("select * from y_Len_CeLiang where Mode_State=1 and groups=? limit 0,1");
            ResultSet r= sn.query(groups).getCurrentResult();
            String Fx_Content="";
            while (r.next()) {
                Fx_Content=r.getString("Fx_Content");
            }    
            sn.createSql(Fx_Content);
            ResultSet r2= sn.query(groups).getCurrentResult();
            while (r2.next()) {
                String work_procedure=r2.getString("work_procedure");
                String work_state=r2.getString("work_state");
                Long id=Long.valueOf(r2.getString("id"));
                String width=r2.getString("width");
                String height=r2.getString("height");
                String edgwidth=r2.getString("edg_width");
                String edgheight=r2.getString("edg_height");
                if("测量".equals(work_procedure)){
                    if(Double.parseDouble(width)<preprocessingGlass.getMinwidths() ||Double.parseDouble(height)<preprocessingGlass.getMinwidths() ){
                        html.append("<button id='button' onclick='onchecks1("+id+")' style='width:"+(Double.parseDouble(edgheight)/5)+"px;")
                        .append("height:"+(Double.parseDouble(edgwidth)/5)+"px;' type='button'  class='btn btn-primary2'>"+width+"x"+height+"</button>");
                    }else if("破损".equals(work_state) ){
                        html.append("<button id='button' onclick='onchecks2("+id+")' style='width:"+(Double.parseDouble(edgheight)/5)+"px;")
                        .append("height:"+(Double.parseDouble(edgwidth)/5)+"px;' type='button'  class='btn btn-primary1'>"+width+"x"+height+"</button>");
                    }else{
                        html.append("<button id='button' onclick='onchecks2("+id+")' style='width:"+(Double.parseDouble(edgheight)/5)+"px;")
                        .append("height:"+(Double.parseDouble(edgwidth)/5)+"px;' type='button'  class='btn btn-primary'>"+width+"x"+height+"</button>");
                    }                    
                }else{
                    html.append("<button id='button' style='width:"+(Double.parseDouble(edgheight)/5)+"px;")
                    .append("height:"+(Double.parseDouble(edgwidth)/5)+"px;' type='button'  class='btn btn-primary3'>"+width+"x"+height+"</button>");
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("异常:冷加工测量 -  线路:"+groups);
        }
        
        
        return html.toString();
    }
/*    public String buttonhmthtml(Long groups){
        StringBuffer html = new StringBuffer();
        PreprocessingGlass preprocessingGlass=preprocessingGlassDao.findBygroup(Integer.parseInt(groups+""));
        PatternTask patternTask =patternTaskDao.findbygroups2(groups);
        if(patternTask!=null){
            if(patternTask.getRank()!=0){
                List<GalssTask> galssTasklist=galssTaskDao.findpattern(patternTask.getId());
                
                if(galssTasklist!=null){
                    for (GalssTask galssTask : galssTasklist) {
                        if(galssTask.getWorkProcedure().equals("测量")){
                            if(galssTask.getWidth()<preprocessingGlass.getMinwidths() ||galssTask.getHeight()<preprocessingGlass.getMinwidths() ){
                                html.append("<button id='button' onclick='onchecks1("+galssTask.getId()+")' style='width:"+(Double.parseDouble(galssTask.getEdgHeight())/5)+"px;")
                                .append("height:"+(Double.parseDouble(galssTask.getEdgWidth())/5)+"px;' type='button'  class='btn btn-primary2'>"+galssTask.getWidth()+"x"+galssTask.getHeight()+"</button>");
                            }else if(galssTask.getWorkState().equals("破损") ){
                                html.append("<button id='button' onclick='onchecks2("+galssTask.getId()+")' style='width:"+(Double.parseDouble(galssTask.getEdgHeight())/5)+"px;")
                                .append("height:"+(Double.parseDouble(galssTask.getEdgWidth())/5)+"px;' type='button'  class='btn btn-primary1'>"+galssTask.getWidth()+"x"+galssTask.getHeight()+"</button>");
                            }else{
                                html.append("<button id='button' onclick='onchecks2("+galssTask.getId()+")' style='width:"+(Double.parseDouble(galssTask.getEdgHeight())/5)+"px;")
                                .append("height:"+(Double.parseDouble(galssTask.getEdgWidth())/5)+"px;' type='button'  class='btn btn-primary'>"+galssTask.getWidth()+"x"+galssTask.getHeight()+"</button>");
                            }
                            
                        }else{
                            html.append("<button id='button' style='width:"+(Double.parseDouble(galssTask.getEdgHeight())/5)+"px;")
                            .append("height:"+(Double.parseDouble(galssTask.getEdgWidth())/5)+"px;' type='button'  class='btn btn-primary3'>"+galssTask.getWidth()+"x"+galssTask.getHeight()+"</button>");
                        }
                    }
                }
            }
        }
        
        
        return html.toString();
    }*/
    
    public void Deleteglalls(String groups, String glassid) {
        //破损
        PreprocessingGlass gs = preprocessingGlassDao.findBygroup(Integer.parseInt(groups));
        if(gs.getFlag()==0){
            GalssTask glass=galssTaskDao.findOne(Integer.valueOf(glassid).longValue());
            gs.setFlag(3);
            glass.setWorkState("破损");
            preprocessingGlassDao.save(gs);
            galssTaskDao.save(glass);
        }
    }
    
    public void updatestate(Long id) {
            GalssTask glass=galssTaskDao.findOne(id);
            glass.setWorkState("破损");
            galssTaskDao.save(glass);
        
    }
    
    
    public void updatepatternstate(Long groups,String id) {
        
        if(id.equals("上")){
            PatternTask patternTask = patternTaskDao.findbygroupsfalg(groups);
            if(patternTask!=null){
                patternTask.setFlag(0);
                patternTaskDao.save(patternTask);
            }
            
        }else if(id.equals("下")){
            PatternTask patternTask = patternTaskDao.findbygroups2(groups);
            if(patternTask!=null){
                patternTask.setFlag(1);
                patternTaskDao.save(patternTask);
            }
        }
        
        
    
    }
    public void updatepatternstates(Long groups) {
        
            List<PatternTask> patternTask = patternTaskDao.findIdGroup(groups);
            for (PatternTask patternTask2 : patternTask) {
                if(patternTask2!=null){
                    patternTask2.setFlag(1);
                    patternTaskDao.save(patternTask2);
                }
            }
    
    }
    
    public void yichu(String groups) {
        //移除
        PreprocessingGlass gs = preprocessingGlassDao.findBygroup(Integer.parseInt(groups));
        gs.setFlag(-1);
        preprocessingGlassDao.save(gs);
    }
    public void modify(String groups, String glassid) {
        PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findBygroup(Integer.parseInt(groups));
        //找出当前的玻璃,并修改指认
        if(preprocessingGlass.getFlag()==0){
            
            preprocessingGlass.setFlag(Long.parseLong(glassid));
            
            preprocessingGlassDao.save(preprocessingGlass);
        }
        
    }
    
    public void updatemarking(String type,int groups) {
        PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findBygroup(groups);
        preprocessingGlass.setMarking(Integer.parseInt(type));
        preprocessingGlassDao.save(preprocessingGlass);
    }
    
    public IdentifyError getfloor(String groups) {
 
        return identifyErrorDao.findBygroup(Integer.parseInt(groups));
    }
    
    public double getminwidth(String groups) {
        PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findBygroup(Integer.parseInt(groups));
        return preprocessingGlass.getMinwidths();
    }
    
    
    public void modifyErrorRange(String groups, String floor, String ceiling) {
        IdentifyError identifyError = identifyErrorDao.findBygroup(Integer.parseInt(groups));
        if (identifyError != null) {
            identifyError.setWidtherror(Double.parseDouble(floor));
            identifyError.setHeigtherror(Double.parseDouble(ceiling));
            identifyErrorDao.save(identifyError);
        }
    }
    
    public void modifyErrorRange2(String groups, String floor) {
        PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findBygroup(Integer.parseInt(groups));
        if (preprocessingGlass != null) {
            preprocessingGlass.setMinwidths(Double.parseDouble(floor));
            preprocessingGlassDao.save(preprocessingGlass);
        }
    }
    
    public String BupianForHtml() {
        StringBuffer html = new StringBuffer();
         List<GalssTask> glassLists=galssTaskDao.findByidentify();
          for (GalssTask glass : glassLists) {
                  html.append("<tr><td style='text-align:center;'>").append(glass.getId()).append("</td>");
                html.append("<td style='text-align:center;'>").append(glass.getHeight()).append("</td>");
                html.append("<td style='text-align:center;'>").append(glass.getWidth()).append("</td>");
                html.append("<td style='text-align:center;'>").append(glass.getThickness()).append("</td>");
                html.append("<td style='text-align:center;'>").append(glass.getColor()).append("</td>");
                html.append("<td style='text-align:center;'>").append(glass.getWorkState()).append("</td>");
                html.append("</tr>");  
          } 
          
             
        
        return html.toString();
    }
    
    
    public void addgalsstask(HttpServletRequest request) {
        GalssTask galssTask=new GalssTask();
        galssTask.setGalssId(Long.valueOf(request.getParameter("galssid")));
        galssTask.setWidth(Double.valueOf(request.getParameter("width")));
        galssTask.setHeight(Double.valueOf(request.getParameter("heigth")));
        galssTask.setThickness(Double.valueOf(request.getParameter("thickness")));
        galssTask.setColor(request.getParameter("color"));
        galssTask.setEdgHeight(request.getParameter("edgwidth"));
        galssTask.setEdgWidth(request.getParameter("edgheight"));
        galssTask.setEdgSpeed1(request.getParameter("edgspeed1"));
        galssTask.setEdgSpeed2(request.getParameter("edgspeed2"));
        galssTask.setDropFrame(request.getParameter("dropframe"));
        galssTask.setFineThrowing(Integer.parseInt(request.getParameter("finethrowing")));
        galssTask.setWorkProcedure(request.getParameter("workprocedure"));
        galssTask.setWorkState(request.getParameter("workstart"));
        galssTask.setSlicecageFlag("0");
        galssTask.setStartTime(new Date());
        galssTaskDao.save(galssTask);
    }
    
    
    public boolean modifypassword(String password1,String password2) {
        System.out.println(password2);
        Password password =passwordDao.findpassword(password1);
        if(password!=null){
            password.setPassword(password2);
            passwordDao.save(password);
            return true;
        }else{
            return false;
        }
        
    }
}