提交 | 用户 | 时间
|
1e2ff5
|
1 |
package com.billion.main.plcServer.sub; |
H |
2 |
|
a2cd0f
|
3 |
import com.billion.main.bs.domain.BsBomChildInfo; |
H |
4 |
import com.billion.main.bs.service.IBsBomChildInfoService; |
|
5 |
import com.billion.main.constant.Constants; |
1e2ff5
|
6 |
import com.billion.main.da.service.IDaParamCollectionService; |
a2cd0f
|
7 |
import com.billion.main.da.service.IDaStationCollectionService; |
H |
8 |
import com.billion.main.om.domain.OmOrderScheduling; |
|
9 |
import com.billion.main.om.domain.OmProductionOrderInfo; |
|
10 |
import com.billion.main.om.service.IOmOrderSchedulingService; |
|
11 |
import com.billion.main.om.service.IOmProductionOrderInfoService; |
|
12 |
import com.kangaroohy.milo.model.ReadWriteEntity; |
1e2ff5
|
13 |
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
H |
14 |
import com.kangaroohy.milo.service.MiloService; |
|
15 |
import lombok.extern.slf4j.Slf4j; |
|
16 |
import org.springframework.stereotype.Component; |
|
17 |
|
a2cd0f
|
18 |
import java.time.LocalDateTime; |
H |
19 |
import java.util.ArrayList; |
|
20 |
import java.util.List; |
|
21 |
import java.util.concurrent.CompletableFuture; |
1e2ff5
|
22 |
@Slf4j |
H |
23 |
@Component |
|
24 |
public class OPCUaSubscription implements SubscriptionCallback { |
|
25 |
public static MiloService miloService; |
|
26 |
public IDaParamCollectionService daParamCollectionService; |
a2cd0f
|
27 |
public IDaStationCollectionService daStationCollectionService; |
H |
28 |
public IOmProductionOrderInfoService omProductionOrderInfoService; |
|
29 |
public IOmOrderSchedulingService omOrderSchedulingService; |
|
30 |
public IBsBomChildInfoService bomChildInfoService; |
1e2ff5
|
31 |
|
H |
32 |
public OPCUaSubscription(MiloService miloService, |
a2cd0f
|
33 |
IDaParamCollectionService daParamCollectionService, |
H |
34 |
IDaStationCollectionService daStationCollectionService, |
|
35 |
IOmProductionOrderInfoService omProductionOrderInfoService, |
|
36 |
IOmOrderSchedulingService omOrderSchedulingService, |
|
37 |
IBsBomChildInfoService bomChildInfoService |
|
38 |
) { |
1e2ff5
|
39 |
OPCUaSubscription.miloService = miloService; |
H |
40 |
this.daParamCollectionService = daParamCollectionService; |
a2cd0f
|
41 |
this.daStationCollectionService = daStationCollectionService; |
H |
42 |
this.omProductionOrderInfoService = omProductionOrderInfoService; |
|
43 |
this.omOrderSchedulingService = omOrderSchedulingService; |
|
44 |
this.bomChildInfoService = bomChildInfoService; |
1e2ff5
|
45 |
} |
H |
46 |
@Override |
|
47 |
public void onSubscribe(String identifier, Object value) { |
a2cd0f
|
48 |
log.info("地址:"+identifier+"值:"+value); |
H |
49 |
try { |
|
50 |
if(null != value ) { |
|
51 |
String[] nodes = identifier.split("[.]"); |
|
52 |
String thoroughfare = nodes[0];//通道 |
|
53 |
String device = nodes[1];//设备 |
|
54 |
String tab = nodes[2];//标记 |
|
55 |
String valueString = value.toString();//地址值 |
|
56 |
CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { |
|
57 |
onSubscribe(thoroughfare,device,tab,valueString); |
|
58 |
plackWorkOrder(thoroughfare,device,tab,valueString); |
|
59 |
}); |
|
60 |
} |
|
61 |
} catch (Exception e) { |
|
62 |
log.error(e.getMessage()); |
|
63 |
} |
|
64 |
} |
1e2ff5
|
65 |
|
a2cd0f
|
66 |
public void onSubscribe(String thoroughfare,String device,String tab,String valueString) { |
H |
67 |
try { |
|
68 |
if (Constants.RecordData.equals(tab)){ |
|
69 |
//工站交互初始化 |
|
70 |
if (Constants.ZERO.equals(valueString)){ |
|
71 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("0").build()); |
|
72 |
//请求进站 |
|
73 |
} else if (Constants.ONE.equals(valueString)){ |
|
74 |
//首工站 |
|
75 |
if(Constants.C005.equals(device)){ |
|
76 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("11").build()); |
|
77 |
} |
|
78 |
//除首工站所有工站 |
|
79 |
else if(Constants.PLC.contains(device) && Constants.OP310.contains(device)){ |
|
80 |
//校验SFCCode是否存在 |
|
81 |
Object SFCCode = miloService.readFromOpcUa(thoroughfare + "." + device + ".SFCCode").getValue(); |
|
82 |
Object PalletID = miloService.readFromOpcUa(thoroughfare + "." + device + ".PalletID").getValue(); |
|
83 |
if (SFCCode == null ) { |
|
84 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("23").build()); |
|
85 |
} else { |
|
86 |
OmOrderScheduling omOrderScheduling = new OmOrderScheduling(); |
|
87 |
omOrderScheduling.setRemarks(PalletID.toString()); |
|
88 |
List<OmOrderScheduling> resultList = omOrderSchedulingService.selectOmOrderSchedulingList(omOrderScheduling); |
|
89 |
log.info("查询结果数量: {}", resultList); |
|
90 |
BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
|
91 |
bsbomChildInfo.setLocationCode(device); |
|
92 |
bsbomChildInfo.setBomCode(resultList.get(0).getWorkOrderNo()); |
|
93 |
//下发配方 |
|
94 |
formula(thoroughfare, device, bsbomChildInfo); |
|
95 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("11").build()); |
|
96 |
} |
|
97 |
} |
|
98 |
// |
|
99 |
// |
|
100 |
//出站保存数据 |
|
101 |
} else if (Constants.TWO.equals(valueString)) { |
|
102 |
//首功站 |
|
103 |
if(Constants.C005.equals(device)){ |
|
104 |
// 判断接单是否成功 |
|
105 |
OmOrderScheduling omOrderScheduling = new OmOrderScheduling(); |
|
106 |
List<OmOrderScheduling> omOrderSchedulinglist = new ArrayList<>(); |
|
107 |
Object workOrderNumber = miloService.readFromOpcUa(thoroughfare + "." + device + ".WorkOrderNumber").getValue(); |
|
108 |
Object PalletID = miloService.readFromOpcUa(thoroughfare + "." + device + ".PalletID").getValue(); |
|
109 |
Object SFCCode = miloService.readFromOpcUa(thoroughfare + "." + device + ".SFCCode").getValue(); |
|
110 |
//托盘绑定SFCCode和工单 |
|
111 |
omOrderScheduling.setWorkOrderNo(workOrderNumber.toString()); |
|
112 |
omOrderScheduling.setRemarks(PalletID.toString()); |
|
113 |
omOrderScheduling.setSfcCode(SFCCode.toString()); |
|
114 |
omOrderSchedulinglist.add(omOrderScheduling); |
|
115 |
omOrderSchedulingService.saveBatch(omOrderSchedulinglist); |
|
116 |
// 缺少保存数据的方法 |
|
117 |
|
|
118 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value("21").build()); |
|
119 |
}else if(Constants.PLC.contains(device) && Constants.OP310.contains(device)){ |
|
120 |
|
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
} |
|
125 |
catch (Exception e) { |
|
126 |
log.error(e.getMessage()); |
|
127 |
} |
|
128 |
} |
|
129 |
//首工站下发工单,并生成SN码 |
|
130 |
private static final String[] MONTH = {"A","B","C","D","E","F","G","H","I","J","K","L"}; |
|
131 |
public void plackWorkOrder(String thoroughfare, String device, String tab, String valueString) { |
|
132 |
try { |
|
133 |
if (Constants.WorkOrderRequest.equals(tab)) { |
|
134 |
if (Constants.ZERO.equals(valueString)) { |
|
135 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("0").build()); |
|
136 |
} else if (Constants.ONE.equals(valueString)) { |
|
137 |
// 查询数据库获取符合条件的订单信息 |
|
138 |
OmProductionOrderInfo getEarliestOrder = omProductionOrderInfoService.getEarliestOrder(); |
|
139 |
if (getEarliestOrder != null) { |
|
140 |
//判断当前下发数量 |
|
141 |
if(getEarliestOrder.getRemarks() >= getEarliestOrder.getPlanQty()){ |
|
142 |
//更新工单状态 |
|
143 |
omProductionOrderInfoService.updateOrderStatus5(); |
|
144 |
//查询新满足的工单 |
|
145 |
OmProductionOrderInfo getEarliestOrder2 = omProductionOrderInfoService.getEarliestOrder(); |
|
146 |
if (getEarliestOrder2 != null) { |
|
147 |
// 将数据写入到地址块中 |
|
148 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(getEarliestOrder2.getWorkOrderNo()).build()); |
|
149 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ProductionPlan").value(String.valueOf(getEarliestOrder2.getPlanQty())).build()); |
|
150 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(getEarliestOrder2.getEngineType()).build()); |
|
151 |
//生成sn码 |
|
152 |
OmProductionOrderInfo serialNumber = omProductionOrderInfoService.getSerialNumber(); |
|
153 |
String A3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
|
154 |
if(A3.equals(String.valueOf(serialNumber.getRemarks()))){ |
|
155 |
String A1 = getEarliestOrder2.getEngineType();//获取产品型号 |
|
156 |
String A2 = "3"; |
|
157 |
String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
|
158 |
String A5 = String.format("%05d", serialNumber.getPlanQty()); |
|
159 |
String SFCCode = A1 + A2 + A3+ A4 + A5; |
|
160 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
|
161 |
omProductionOrderInfoService.updateSerialNumber(); |
|
162 |
}else{ |
|
163 |
OmProductionOrderInfo newNumber = omProductionOrderInfoService.updateYear(); |
|
164 |
String A1 = getEarliestOrder2.getEngineType();//获取产品型号 |
|
165 |
String A2 = "3"; |
|
166 |
String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
|
167 |
String A5 = String.format("%05d", newNumber.getPlanQty()); |
|
168 |
String SFCCode = A1 + A2 + A3+ A4 + A5; |
|
169 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
|
170 |
omProductionOrderInfoService.updateSerialNumber(); |
|
171 |
} |
|
172 |
// 更新 WorkOrderRequestDone 地址块 |
|
173 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("11").build()); |
|
174 |
BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
|
175 |
bsbomChildInfo.setLocationCode(device); |
|
176 |
bsbomChildInfo.setBomCode(getEarliestOrder2.getWorkOrderNo()); |
|
177 |
//发下工艺配方 |
|
178 |
formula(thoroughfare, device, bsbomChildInfo); |
|
179 |
omProductionOrderInfoService.updateOrderStatus2(); |
|
180 |
|
|
181 |
} |
|
182 |
} else if (getEarliestOrder.getRemarks() < getEarliestOrder.getPlanQty()) { |
|
183 |
//更新工单状态 |
|
184 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(getEarliestOrder.getWorkOrderNo()).build()); |
|
185 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ProductionPlan").value(String.valueOf(getEarliestOrder.getPlanQty())).build()); |
|
186 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".EngineType").value(getEarliestOrder.getEngineType()).build()); |
|
187 |
//生成sn码 |
|
188 |
OmProductionOrderInfo serialNumber = omProductionOrderInfoService.getSerialNumber(); |
|
189 |
String A3 = String.valueOf(LocalDateTime.now().getYear()).substring(2); |
|
190 |
if(A3.equals(String.valueOf(serialNumber.getRemarks()))){ |
|
191 |
String A1 = getEarliestOrder.getEngineType();//获取产品型号 |
|
192 |
String A2 = "3"; |
|
193 |
String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
|
194 |
String A5 = String.format("%05d", serialNumber.getPlanQty()); |
|
195 |
String SFCCode = A1 + A2 + A3+ A4 + A5; |
|
196 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
|
197 |
omProductionOrderInfoService.updateSerialNumber(); |
|
198 |
}else{ |
|
199 |
OmProductionOrderInfo newNumber = omProductionOrderInfoService.updateYear(); |
|
200 |
String A1 = getEarliestOrder.getEngineType();//获取产品型号 |
|
201 |
String A2 = "3"; |
|
202 |
String A4 = MONTH[LocalDateTime.now().getMonthValue() - 1];// 获取当前月份(1-12) |
|
203 |
String A5 = String.format("%05d", newNumber.getPlanQty()); |
|
204 |
String SFCCode = A1 + A2 + A3+ A4 + A5; |
|
205 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SFCCode").value(SFCCode).build()); |
|
206 |
omProductionOrderInfoService.updateSerialNumber(); |
|
207 |
} |
|
208 |
// 更新 WorkOrderRequestDone 地址块 |
|
209 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderRequestDone").value("11").build()); |
|
210 |
BsBomChildInfo bsbomChildInfo= new BsBomChildInfo(); |
|
211 |
bsbomChildInfo.setLocationCode(device); |
|
212 |
bsbomChildInfo.setBomCode(getEarliestOrder.getWorkOrderNo()); |
|
213 |
//发下工艺配方 |
|
214 |
formula(thoroughfare, device, bsbomChildInfo); |
|
215 |
omProductionOrderInfoService.updateOrderStatus2(); |
|
216 |
} |
|
217 |
} |
|
218 |
} |
|
219 |
} |
|
220 |
} catch (Exception e) { |
|
221 |
log.error(e.getMessage()); |
1e2ff5
|
222 |
} |
H |
223 |
} |
a2cd0f
|
224 |
|
H |
225 |
//发下工艺配方方法 |
|
226 |
private void formula(String thoroughfare, String device, BsBomChildInfo bsbomChildInfo) throws Exception { |
|
227 |
List<BsBomChildInfo> bomChildList = bomChildInfoService.selectBsBomChildInfoList(bsbomChildInfo); |
|
228 |
for (int i = 1; i <= bomChildList.size(); i++) { |
|
229 |
// 生成 MaterialCode 节点 |
|
230 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".Material1Code"+ i).value(bomChildList.get(i-1).getMaterialCode()).build()); |
|
231 |
// 生成 MaterialNumber 节点 |
|
232 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".Material1Number"+ i).value(bomChildList.get(i-1).getCostQty()).build()); |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
236 |
} |
|
237 |
// |
|
238 |
|