wu
2024-04-23 2a3c60f0712c3039accf3be35cc8a97e499d09fd
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
package com.example.springboot.service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.example.springboot.common.Result;
import com.example.springboot.component.Plchome;
import com.example.springboot.component.S7control;
import com.example.springboot.entity.Queue;
import com.example.springboot.entity.StorageCage;
import com.example.springboot.entity.StorageTask;
import com.example.springboot.mapper.HomeMapper;
 
@Service
public class StorageCageService {
    @Autowired
    private HomeMapper homeMapper;
 
    @Autowired
    private OutSliceServive outSliceServive;
 
    @Autowired
    private SpianService spianService;
 
    public void EndTask(int types) {
        String A01glassid1 = spianService.queGlassid("DB103.128", 14).toString();
        String A01glassid2 = spianService.queGlassid("DB103.142", 14).toString();
        String A02glassid1 = spianService.queGlassid("DB103.156", 14).toString();
        String B01glassid = spianService.queGlassid("DB103.184", 14).toString();
        String B02glassid = spianService.queGlassid("DB103.212", 14).toString();
        List<Short> DeviceList = S7control.getinstance().ReadWord("DB103.0", 10);
        if (types == 0) {// 终止进片任务
            List<StorageTask> cageList = homeMapper.SelectTaskByState(types);
            for (StorageTask storageTask : cageList) {
                // 判断出片任务位置并清除对应玻璃id
                if ((storageTask.getGlassId().equals(A01glassid1) || storageTask.getGlassId().equals(A01glassid2))
                        && DeviceList.get(4) == 0) {
                    outSliceServive.StopTask(storageTask.getGlassId(), types);
                    ClearGlassId("DB101.10.0");
                }
                if (storageTask.getGlassId().equals(B01glassid) && DeviceList.get(2) == 0) {
                    outSliceServive.StopTask(storageTask.getGlassId(), types);
                    ClearGlassId("DB101.10.2");
                }
                if (storageTask.getGlassId().equals(B02glassid) && DeviceList.get(3) == 0) {
                    ClearGlassId("DB101.10.3");
                    outSliceServive.StopTask(storageTask.getGlassId(), types);
                }
            }
            // 发送终止进片任务信号
        } else {// 终止出片任务
            List<StorageTask> cageLists = homeMapper.SelectTaskByState(types);
            List<StorageTask> cageList2 = homeMapper.SelectTaskByState(2);
            if (cageList2.size() > 0) {
                cageLists.add(cageList2.get(0));
            }
            for (StorageTask cageList : cageLists) {
                if (cageList.getTaskType().equals("1")) {
                    System.out.println(DeviceList.get(5));
                    if (cageList.getGlassId().equals(A02glassid1) && DeviceList.get(5) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), types);
                        ClearGlassId("DB101.10.1");
                    }
                    if (cageList.getGlassId().equals(B01glassid) && DeviceList.get(2) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), types);
                        ClearGlassId("DB101.10.2");
                    }
                    if (cageList.getGlassId().equals(B02glassid) && DeviceList.get(3) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), types);
                        ClearGlassId("DB101.10.3");
                    }
                } else if (cageList.getTaskType().equals("2")) {
                    if (cageList.getGlassId().equals(A02glassid1) && DeviceList.get(5) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), 2);
                        ClearGlassId("DB101.10.1");
                    }
                    if (cageList.getGlassId().equals(B01glassid) && DeviceList.get(2) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), 2);
                        ClearGlassId("DB101.10.2");
                    }
                    if (cageList.getGlassId().equals(B02glassid) && DeviceList.get(3) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), 2);
                        ClearGlassId("DB101.10.3");
                    }
                }
            }
 
            // List<StorageCage> storageCages = homeMapper.selectinout(3);
            // for (StorageCage storageCage : storageCages) {
            // List<StorageCage> storageCagess =
            // homeMapper.SelectStoragesGlassById(storageCage.getGlassId());
 
            // for (StorageCage storageCagez : storageCagess) {
 
            // if (storageCagez.getState().equals("2")) {// 调拨进片
            // outSliceServive.StopTask(storageCagez.getGlassId(), 0);
            // } else {// 出片
            // outSliceServive.StopTask(storageCagez.getGlassId(), types);
            // }
 
            // // 判断出片任务位置并清除对应玻璃id
            // if (storageCagez.getGlassId() == A02glassid1&&DeviceList.get(5)==0) {
            // outSliceServive.StopTask(storageCagez.getGlassId(), types);
            // ClearGlassId("DB101.10.1");
            // } else if (storageCagez.getGlassId() == B01glassid&&DeviceList.get(2)==0) {
            // outSliceServive.StopTask(storageCagez.getGlassId(), types);
            // ClearGlassId("DB101.10.2");
            // } else if (storageCagez.getGlassId() == B02glassid&&DeviceList.get(3)==0) {
            // ClearGlassId("DB101.10.3");
            // outSliceServive.StopTask(storageCagez.getGlassId(), types);
            // }
            // }
            // }
        }
    }
 
    // 手动完成任务
    public void UpdateTask(Integer types, Integer shelfrack, String glassid) {
        if (types == 0) {// 完成进片
            spianService.overtask(glassid);
        } else if (types == 1) {// 完成出片
            spianService.overtask(glassid);
        }
        // else if (types == 2) {// 终止进片任务
        // outSliceServive.StopTask(glassid, 0);
        // // 发送终止进片任务信号
        // } else {// 终止出片任务
        // outSliceServive.StopTask(glassid, 1);
        // }
    }
 
    // 判断任务类型后清除对应玻璃id
    public Result ClearGlassId(String position, String glassid) {
        Map<String, Object> map = new HashMap<>();
        if (S7control.getinstance().CheckConnected() == true) {
            // 判断进出还是出片任务
            Short type = homeMapper.SelectTaskByGlassId(glassid);
            if (type != null) {
                if (type == 0) {
                    // 进片
                    outSliceServive.StopTask(glassid, 0);
                } else if (type == 1) {
                    // 出片
                    outSliceServive.StopTask(glassid, 1);
                } else {
                    // 调拨
                    outSliceServive.StopTask(glassid, 0);
                    outSliceServive.StopTask(glassid, 1);
                }
            }
            ClearGlassId(position);
            map.put("message", "200");
        } else {
            map.put("message", "300");
        }
        return Result.success(map);
    }
 
    // 清除玻璃id
    public Result ClearGlassId(String position) {
        Map<String, Object> map = new HashMap<>();
        if (S7control.getinstance().CheckConnected() == true) {
            S7control.getinstance().WriteBit(position, true);
            try {
                TimeUnit.MILLISECONDS.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            S7control.getinstance().WriteBit(position, false);
            map.put("message", "200");
        } else {
            map.put("message", "300");
        }
        return Result.success(map);
    }
 
    public Result InsertQueueGlassId(Short id, Queue queue) {
        Map<String, Object> map = new HashMap<>();
 
        Short zhi = 200;
        short result = homeMapper.SelectStorageByGlassId(queue.getglassId());
        if (result > 0) {
            map.put("message", "300");
        } else {
            if (id == 1) {
                // 调用伍存储过程
                zhi = spianService.selectAll(queue.getglassId());
                if (zhi == 200) {
                    homeMapper.InsertQueueGlassId(queue, id);
                }
            }
            map.put("message", zhi);
        }
        if (zhi != 200) {
            Plchome.FeedState = true;
        }
        return Result.success(map);
    }
 
}