wu
2024-01-05 b709b0fd40283dd285eff470257b1b8dc0a42ad3
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
package com.example.springboot.component;
 
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.springboot.service.JdbcConnections;
import com.example.springboot.service.SpianService;
import com.example.springboot.entity.north_glass_buffer1;
import com.example.springboot.mapper.AlarmMapper;
import com.example.springboot.mapper.SpianMapper;
 
public class PlcHold extends Thread {
 
  private AlarmMapper alarmMapper;
 
  @Autowired
  private JdbcConnections jdbcConnections;
  private SpianMapper spianMapper;
  private SpianService spianService;
  int aaa;
 
  @Override
  public void run() {
 
    while (this != null) {
      try {
 
        Thread.sleep(100);
      } catch (InterruptedException e) {
        // \\ TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (S7control.getinstance().CheckConnected() == true) {
        spianService = WebSocketServer.applicationContext.getBean(SpianService.class);
        spianMapper = WebSocketServer.applicationContext.getBean(SpianMapper.class);
        jdbcConnections = WebSocketServer.applicationContext.getBean(JdbcConnections.class);
        // 根据玻璃id获取订单号,单独数据源
        // try {
        // north_glass_buffer1 glass = jdbcConnections.selectGlass(112);
        // // System.out.println(glass.getOrderId());
        // } catch (SQLException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }
        // spianService.selectAll("X12345610402GV");
        // 出片任务////////////////////////////////
        List<Short> outlist = S7control.getinstance().ReadWord("DB106.20", 1); // 出片车状态
        List<Short> outlist1 = S7control.getinstance().ReadWord("DB105.18", 1); // 出片任务是否启动
        // StringBuilder writedstrIdOut = new StringBuilder();
        // 获取已下发的出片id
        byte[] writedglassidbytesOut = S7control.getinstance().ReadByte("DB105.30", 14);
        String writedstrIdOut = new String(writedglassidbytesOut);
 
        boolean outstate = false;// 出片车空闲判断
        boolean outstate1 = false;// 出片车任务是否启动
        if (outlist != null && outlist1 != null) {
 
          outstate = outlist.contains((short) 0);// 出片车空闲判断 当出片车空闲时为true
          outstate1 = outlist1.contains((short) 1);// 出片车任务是否启动 当出片车任务启动时为true
 
          // 判断当前是否有未执行的任务
          int outnum = spianMapper.SelectOutSliceshu();
          int cageoutsum = spianMapper.Selectcageout(3);
          // 当没有任务执行并且出片车空闲时
          if (outnum == 0 && outstate == true && Plchome.isAllowQueue == true && cageoutsum == 0) {
            // 判断铝框出片队列表是否有待出片的玻璃
            String outglassid = spianMapper.SelectOutSlice();
            // 当有待出片的玻璃时
            if (outglassid != null) {
              // 获取该玻璃是否被禁用
              int glassdisabled = spianMapper.SelectCageGlassState(outglassid);
              //未禁用下发任务
              if (glassdisabled == 0) {
                spianService.selectout2(outglassid);
                Plchome.isQueueWarning = false;
                outstate = false;
              } else { //禁用更改状态弹出提示
                Plchome.isQueueWarning = true;
              }
 
            }
          }
          if (outstate == true) {// 当出片车空闲时,且出片启动为1时,任务启动改为0
            if (outstate1 == true) {
              S7control.getinstance().WriteWord("DB105.18", (short) 0);// 出片任务启动改为0
            }
          }
        }
 
        ///////////// 进片任务
        List<Short> datas1List = S7control.getinstance().ReadWord("DB106.24", 1);// 获取prc进片请求数据
        List<Short> datas1ListState = S7control.getinstance().ReadWord("DB106.8", 1);// 获取进片车状态
        List<Short> datas1ListState2 = S7control.getinstance().ReadWord("DB105.16", 1);// 获取进片车任务是否启动
 
        boolean B01backs = spianService.listbool("DB106.60");// b01汇报
 
        boolean B02backs = spianService.listbool("DB106.62");// b02汇报
        StringBuilder B01glassid = spianService.queGlassid("DB103.184", 14);// BO1的玻璃id
        StringBuilder B02glassid = spianService.queGlassid("DB103.212", 14);// B02的玻璃id
 
        // 当进片小车完成任务时
        if (B01backs == true) {
          // 当B01小车汇报完成时更改玻璃状态 为1
          spianService.overtask(B01glassid.toString());// 完成任务
          S7control.getinstance().WriteWord("DB106.60", (short) 0);// 恢复B01小车应答改为0
          boolean yingda = spianService.listbool("DB106.60");// b01汇报
          System.out.println("汇报时B01|第" + aaa + "次" + B01glassid + "应答" + yingda);
          aaa += 1;
        }
 
        // 当出片小车完成任务时
        if (B02backs == true) {
          // 当B02小车汇报完成时更改玻璃状态为0
          spianService.overtask(B02glassid.toString());// 完成任务
          S7control.getinstance().WriteWord("DB106.62", (short) 0);// 恢复B02小车应答改为0
          System.out.println("汇报时B02|" + B02glassid);
          boolean yingda = spianService.listbool("DB106.62");// b02汇报
          System.out.println("汇报时B02|第" + aaa + "次" + B02glassid + "应答" + yingda);
        }
 
        // 获取DO1数据
        StringBuilder queueid1 = spianService.queGlassid("DB106.26", 14);// 获取请求的id跟DO1同时清
        // 获取DO2数据
        StringBuilder queueid2 = spianService.queGlassid("DB103.58", 14);
 
        int questate = spianMapper.Selectquecount(queueid1.toString());// 判断扫码位是否有玻璃已确认
        // queueid1.toString().isEmpty()
        north_glass_buffer1 glass1 = spianMapper.selectGlass(queueid1.toString());// D01的玻璃信息
        north_glass_buffer1 glass2 = spianMapper.selectGlass(queueid2.toString());// D02玻璃信息
        // 当扫码位玻璃id为空时 宽度为0
        if (queueid1 != null && questate == 0) {
          // 写入D01的数据到上片队列表
          if (glass1 == null) { // 当没有值时传空
            spianMapper.Updatequeue(null, null, null, null, 0, null, null, null, null, 1);
          } else {
 
            spianMapper.Updatequeue(queueid1.toString(), glass1.getordernumber(), glass1.getlistnumber(),
                glass1.getboxnumber(), 0, glass1.getglasslengthmm().toString(), glass1.getglassheightmm().toString(),
                glass1.getglasslength().toString(), glass1.getglassheight().toString(), 1);
          }
 
        }
        if (queueid2 != null) {
          // 写入D02的数据到上片队列表
          if (glass2 == null) {
            spianMapper.Updatequeue(null, null, null, null, 0, null, null, null, null, 2);
          } else {
            spianMapper.Updatequeue(queueid2.toString(), glass2.getordernumber(), glass2.getlistnumber(),
                glass2.getboxnumber(), 0, glass2.getglasslengthmm().toString(), glass2.getglassheightmm().toString(),
                glass2.getglasslength().toString(), glass2.getglassheight().toString(), 2);
            spianMapper.overqueue2(queueid2.toString(), 0, 1);// 更改扫码位任务表的状态为0
            S7control.getinstance().WriteWord("DB105.16", (short) 0);// 关闭任务启动
          }
 
        }
 
        // if (outstate == true) { // 出片车状态空闲时
        // Integer state = spianMapper.Selectoutstate();
        // String orderid = spianMapper.SelectOrderout();
 
        // if (orderid != null && state == 0) {
        // spianService.selectout(orderid);
        // }
        // }
 
        // 查询数据库
        // 推送到前端
 
      }
    }
  }
 
}