提交 | 用户 | 时间
|
71e81e
|
1 |
package cn.stylefeng.guns.plcserver.server.OP080.impl; |
懒 |
2 |
|
|
3 |
|
|
4 |
import cn.stylefeng.guns.modular.bs.collectionParamConf.model.params.CollectionParamConfParam; |
|
5 |
import cn.stylefeng.guns.modular.bs.collectionParamConf.model.result.CollectionParamConfResult; |
|
6 |
import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService; |
|
7 |
import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam; |
|
8 |
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult; |
|
9 |
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService; |
|
10 |
import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam; |
|
11 |
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService; |
|
12 |
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam; |
|
13 |
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService; |
cf6bff
|
14 |
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam; |
C |
15 |
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService; |
|
16 |
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam; |
|
17 |
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult; |
|
18 |
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService; |
|
19 |
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam; |
|
20 |
import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult; |
|
21 |
import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService; |
71e81e
|
22 |
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam; |
懒 |
23 |
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult; |
|
24 |
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService; |
|
25 |
import cn.stylefeng.guns.plcserver.opc.GlobalVariable; |
|
26 |
import cn.stylefeng.guns.plcserver.opc.OPCComm; |
|
27 |
import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit; |
|
28 |
|
|
29 |
import cn.stylefeng.guns.plcserver.server.OP080.OP080ServerInterface; |
|
30 |
import cn.stylefeng.guns.plcserver.tool.DateTool; |
|
31 |
import cn.stylefeng.guns.plcserver.tool.LogUtil; |
|
32 |
import org.apache.log4j.Logger; |
|
33 |
import org.openscada.opc.lib.da.Group; |
|
34 |
import org.openscada.opc.lib.da.Item; |
|
35 |
|
|
36 |
import java.util.Date; |
|
37 |
import java.util.List; |
|
38 |
|
|
39 |
|
|
40 |
public class OP080ServerInterfaceImpl implements OP080ServerInterface { |
|
41 |
|
|
42 |
private static Logger logger; |
|
43 |
LogUtil logUtil = new LogUtil(); |
|
44 |
static { |
|
45 |
logger = Logger.getLogger(OP080ServerInterfaceImpl.class); |
|
46 |
} |
|
47 |
|
|
48 |
private OPCComm opc = OPCComm.getInstance(); |
|
49 |
private static Date IN_TIME = null; |
|
50 |
private static String S_ORDER_CODE = "";//工单编号 |
|
51 |
private static String S_PRODUCT_CODE = "";//产品编号 |
|
52 |
private static String S_PRODUCT_TYPE= "";//产品类型 |
|
53 |
private static String S_PRODUCT_CODE_OLD = "";//产品编号 |
|
54 |
private static String S_SFC_CODE = "";//总成编码 |
|
55 |
private static String S_RIGHT_CODE = "";//右壳体编码 |
|
56 |
private static String PRODUCTION_LINE = "OP";//产线号 |
|
57 |
private static String LOCATION_CODE = "OP080";//工位号 |
|
58 |
private static String GROUP_NAME = "OP080_P";//组名 |
|
59 |
private static List list = null; |
|
60 |
private static Group group = null; |
cf6bff
|
61 |
|
C |
62 |
private int count = 0; |
|
63 |
|
|
64 |
/** |
|
65 |
* 设置心跳标志位,保存到全局变量 |
|
66 |
*/ |
|
67 |
public void setHeartbeat(String value) { |
|
68 |
if ("false".equals(value)) { |
|
69 |
OPCUnit.write(opc.getOP080_F_HEART_BEAT(), "true"); |
|
70 |
GlobalVariable.OP080_F_HEART_BEAT = true; |
|
71 |
count = 0; |
|
72 |
} else { |
|
73 |
count++; |
|
74 |
} |
|
75 |
// 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时 |
|
76 |
if (count > GlobalVariable.HEART_MAX_COUNT) { |
|
77 |
GlobalVariable.OP080_F_HEART_BEAT = false; |
|
78 |
} |
|
79 |
} |
|
80 |
|
71e81e
|
81 |
@Override |
懒 |
82 |
public synchronized void monitor() { |
|
83 |
String ecpStr = "";//异常记录标记 |
|
84 |
try{ |
cf6bff
|
85 |
|
C |
86 |
String isHeartBeat = OPCUnit.read(opc.getOP080_F_HEART_BEAT()); |
|
87 |
setHeartbeat(isHeartBeat); |
|
88 |
|
71e81e
|
89 |
if(GlobalVariable.OP080_F_HEART_BEAT) { |
懒 |
90 |
//PC读工单 |
|
91 |
String isPLCStart = OPCUnit.read(opc.getOP080_J_PLC_START());//PLC开始 |
|
92 |
if(isPLCStart.equals("true")){ |
|
93 |
String isFinish = OPCUnit.read(opc.getOP080_J_PC_WRITE_ORDER());//PC下发工单完成 |
|
94 |
if(isFinish.equals("false")){ |
|
95 |
|
|
96 |
String isRepair = OPCUnit.read(opc.getOP080_P_REPAIR());//是否返修 |
|
97 |
if(isRepair.equals("true")){ |
|
98 |
handleRepair(); |
|
99 |
}else{ |
|
100 |
handleOrder(); |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
|
|
106 |
//PC完成 |
|
107 |
String isPLCFinish = OPCUnit.read(opc.getOP080_J_PLC_FINISH());//PLC完成 |
|
108 |
if(isPLCFinish.equals("true")){ |
|
109 |
String isFinish = OPCUnit.read(opc.getOP080_J_PC_FINISH());//PC操作完成 |
|
110 |
if(isFinish.equals("false")){ |
cf6bff
|
111 |
handleMaterial(); |
71e81e
|
112 |
handleInfo(); |
懒 |
113 |
handleFinsh(); |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
}else{ |
|
118 |
logger.info("OP080工位与PLC断开,请检查PLC或网络是否异常!"); |
|
119 |
} |
|
120 |
|
|
121 |
}catch (Exception e) { |
|
122 |
ecpStr ="出现异常:" + logUtil.getTrace(e); |
|
123 |
}finally { |
|
124 |
if(!"".equals(ecpStr)){ |
|
125 |
logger.info(ecpStr+"\r\n"); |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
public void handleRepair() { |
|
131 |
RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam(); |
|
132 |
repairManageInfoParam.setLocationCode(LOCATION_CODE); |
|
133 |
repairManageInfoParam.setManageType("2"); |
|
134 |
repairManageInfoParam.setUpPlc("0"); |
|
135 |
RepairManageInfoService repairManageInfoService = opc.repairManageInfoService; |
|
136 |
List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam); |
|
137 |
if(list.size()>0) { |
|
138 |
RepairManageInfoResult result = list.get(0); |
|
139 |
|
|
140 |
S_SFC_CODE = result.getSfc(); |
|
141 |
S_ORDER_CODE = result.getWorkOrderNo(); |
|
142 |
S_PRODUCT_CODE = result.getProductCode(); |
|
143 |
S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE); |
|
144 |
String repairLocation = result.getPoorLocationCode();// |
|
145 |
|
|
146 |
//根据工位编码查询工位表中配置的返修工位号 |
|
147 |
LocationInfoParam param = new LocationInfoParam(); |
|
148 |
param.setLocationCode(repairLocation); |
|
149 |
LocationInfoService locationInfoService = opc.locationInfoService; |
|
150 |
List<LocationInfoResult> results = locationInfoService.findListBySpec(param); |
|
151 |
if(results.size()>0) { |
|
152 |
LocationInfoResult r = results.get(0); |
|
153 |
String repairLocationNo = r.getSpareField2(); |
|
154 |
if(null != repairLocationNo && "" != repairLocationNo){ |
|
155 |
OPCUnit.write(opc.getOP080_S_ORDER_CODE(),S_ORDER_CODE); //工单编号 |
|
156 |
OPCUnit.write(opc.getOP080_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号 |
|
157 |
OPCUnit.write(opc.getOP080_S_SFC_CODE(), S_SFC_CODE); //总成编码 |
|
158 |
OPCUnit.write(opc.getOP080_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号 |
|
159 |
OPCUnit.write(opc.getOP080_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成 |
|
160 |
|
|
161 |
//更新为已经返修上线 |
|
162 |
Long id = result.getId(); |
|
163 |
repairManageInfoParam.setId(id); |
|
164 |
repairManageInfoParam.setUpPlc("1"); |
|
165 |
repairManageInfoService.update(repairManageInfoParam); |
|
166 |
|
|
167 |
}else{ |
|
168 |
logger.info("OP080工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!"); |
|
169 |
} |
|
170 |
}else{ |
|
171 |
logger.info("OP080工位,handleRepair 无法查询到"+repairLocation+"工位!"); |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
//PC读工单 |
|
177 |
public void handleOrder() { |
|
178 |
IN_TIME = DateTool.getLocalTimeForDate(); |
|
179 |
S_ORDER_CODE = OPCUnit.read(opc.getOP080_S_ORDER_CODE());//工单编号 |
|
180 |
S_PRODUCT_TYPE = OPCUnit.read(opc.getOP080_S_PRODUCT_CODE());//产品编号 |
|
181 |
S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); |
|
182 |
S_SFC_CODE = OPCUnit.read(opc.getOP080_S_SFC_CODE());//总成编码 |
|
183 |
OPCUnit.write(opc.getOP080_J_PC_WRITE_ORDER(), "true"); //PC读工单完成 |
|
184 |
logger.info("OP080工位,handleOrder PC处理完成!"); |
|
185 |
} |
|
186 |
|
cf6bff
|
187 |
public void handleMaterial() { |
C |
188 |
if("".equals(S_ORDER_CODE)){ |
|
189 |
IN_TIME = DateTool.getLocalTimeForDate(); |
|
190 |
S_ORDER_CODE = OPCUnit.read(opc.getOP080_S_ORDER_CODE());//工单编号 |
|
191 |
S_PRODUCT_TYPE = OPCUnit.read(opc.getOP080_S_PRODUCT_CODE());//产品编号 |
|
192 |
S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); |
|
193 |
S_SFC_CODE = OPCUnit.read(opc.getOP080_S_SFC_CODE());//总成编码 |
|
194 |
} |
|
195 |
//查询批次上料信息 |
|
196 |
ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); |
|
197 |
productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); |
|
198 |
productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); |
|
199 |
ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService; |
|
200 |
List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); |
|
201 |
for(int i=0;i<list1.size();i++){ |
|
202 |
ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i); |
|
203 |
|
|
204 |
//判断是否有该工位 |
|
205 |
String[] locationCodes = productionOrderBatchInfoResult.getLocationCode().split("/"); |
|
206 |
logger.info("当前工位:"+locationCodes.toString()); |
|
207 |
boolean isLocationCode = false; |
|
208 |
if(locationCodes.length>0) |
|
209 |
{ |
|
210 |
for (int j=0;j<locationCodes.length;j++){ |
|
211 |
String location = locationCodes[j]; |
|
212 |
if(location.equals(LOCATION_CODE)){ |
|
213 |
isLocationCode = true; |
|
214 |
} |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//剩余数量 |
|
219 |
if(remainingQuantity>0 && isLocationCode){ |
|
220 |
//新增物料追溯 |
|
221 |
MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam(); |
|
222 |
materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE); |
|
223 |
materialTraceabilityParam.setProductCode(S_PRODUCT_CODE); |
|
224 |
materialTraceabilityParam.setProductNo(S_SFC_CODE); |
|
225 |
materialTraceabilityParam.setLineCode(PRODUCTION_LINE); |
|
226 |
materialTraceabilityParam.setLocationCode(LOCATION_CODE); |
|
227 |
materialTraceabilityParam.setAssemblyQty(1); |
|
228 |
materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate()); |
|
229 |
materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码 |
|
230 |
materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次 |
|
231 |
|
|
232 |
MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService; |
|
233 |
materialTraceabilityService.add(materialTraceabilityParam); |
|
234 |
//更新剩余数量 |
|
235 |
productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId()); |
|
236 |
productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量 |
|
237 |
productionOrderBatchInfoService.update(productionOrderBatchInfoParam); |
|
238 |
} |
|
239 |
} |
|
240 |
} |
|
241 |
|
71e81e
|
242 |
//PC读参数信息 |
懒 |
243 |
public void handleInfo() throws Exception { |
|
244 |
logger.info("OP080工位,handleInfo START!"); |
|
245 |
|
|
246 |
if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){ |
|
247 |
if(group != null){ |
|
248 |
opc.getServer().removeGroup(group,true); |
|
249 |
} |
|
250 |
group = opc.getServer().addGroup(GROUP_NAME); |
|
251 |
|
|
252 |
CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam(); |
|
253 |
//collectionParamConfParam.setProductCode(S_PRODUCT_CODE); |
|
254 |
collectionParamConfParam.setLocationCode(LOCATION_CODE); |
|
255 |
CollectionParamConfService collectionParamConfService = opc.collectionParamConfService; |
|
256 |
list = collectionParamConfService.findListBySpec(collectionParamConfParam); |
|
257 |
|
|
258 |
|
|
259 |
for(int i=0;i<list.size();i++){ |
|
260 |
CollectionParamConfResult result = (CollectionParamConfResult) list.get(i); |
|
261 |
Item item = group.addItem(result.getGatherAddress()); |
|
262 |
result.setItem(item); |
|
263 |
list.set(i,result); |
|
264 |
} |
|
265 |
//S_PRODUCT_CODE_OLD = S_PRODUCT_CODE; |
|
266 |
} |
|
267 |
|
|
268 |
if(null != list && list.size()>0) { |
|
269 |
ParamCollectionService paramCollectionService = opc.paramCollectionService; |
|
270 |
for (int i = 0; i < list.size(); i++) { |
|
271 |
CollectionParamConfResult result = (CollectionParamConfResult) list.get(i); |
|
272 |
Item item = result.getItem(); |
|
273 |
String value = OPCUnit.read(item);//读参数值 |
|
274 |
ParamCollectionParam paramCollectionParam = new ParamCollectionParam(); |
|
275 |
paramCollectionParam.setParamCode(result.getParamCode()); |
|
276 |
paramCollectionParam.setParamName(result.getParamName()); |
|
277 |
paramCollectionParam.setWorkOrderNo(S_ORDER_CODE); |
|
278 |
paramCollectionParam.setSfcCode(S_SFC_CODE); |
|
279 |
paramCollectionParam.setProductCode(S_PRODUCT_CODE); |
|
280 |
paramCollectionParam.setProductionLine(result.getProductionLine()); |
|
281 |
paramCollectionParam.setLocationCode(result.getLocationCode()); |
|
282 |
paramCollectionParam.setParamValue(value); |
|
283 |
paramCollectionParam.setParamLower(result.getParamLower()); |
|
284 |
paramCollectionParam.setParamUpper(result.getParamUpper()); |
|
285 |
paramCollectionParam.setParamStandard(result.getParamCentral()); |
|
286 |
paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate()); |
|
287 |
paramCollectionParam.setUnit(result.getUnit()); |
|
288 |
paramCollectionService.add(paramCollectionParam); |
|
289 |
} |
|
290 |
} |
|
291 |
|
|
292 |
logger.info("OP080工位,handleInfo END!"); |
|
293 |
} |
|
294 |
|
|
295 |
//PC完成 |
|
296 |
public void handleFinsh() { |
|
297 |
if("".equals(S_ORDER_CODE)){ |
|
298 |
IN_TIME = DateTool.getLocalTimeForDate(); |
|
299 |
S_ORDER_CODE = OPCUnit.read(opc.getOP080_S_ORDER_CODE());//工单编号 |
|
300 |
S_PRODUCT_TYPE = OPCUnit.read(opc.getOP080_S_PRODUCT_CODE());//产品编号 |
|
301 |
S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); |
|
302 |
S_SFC_CODE = OPCUnit.read(opc.getOP080_S_SFC_CODE());//总成编码 |
|
303 |
} |
|
304 |
//处理过站信息 |
|
305 |
String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP080_S_PRODUCT_STATE_CODE()); |
cf6bff
|
306 |
|
C |
307 |
//修改报工记录 |
|
308 |
if("false".equals(S_PRODUCT_STATE_CODE)){ |
|
309 |
ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); |
|
310 |
productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); |
|
311 |
productionOrderRecordsParam.setProductNo(S_SFC_CODE); |
|
312 |
ProductionOrderRecordsService productionOrderRecordsService = opc.productionOrderRecordsService; |
|
313 |
|
|
314 |
List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); |
|
315 |
if(list.size()>0){ |
|
316 |
ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); |
|
317 |
productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); |
|
318 |
productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); |
|
319 |
productionOrderRecordsService.update(productionOrderRecordsParam); |
|
320 |
} |
|
321 |
} |
|
322 |
|
|
323 |
|
71e81e
|
324 |
PassingStationCollectionParam param = new PassingStationCollectionParam(); |
懒 |
325 |
param.setWorkOrderNo(S_ORDER_CODE); |
|
326 |
param.setProductCode(S_PRODUCT_CODE); |
|
327 |
param.setSfcCode(S_SFC_CODE); |
|
328 |
param.setProductionLine(PRODUCTION_LINE); |
|
329 |
param.setLocationCode(LOCATION_CODE); |
|
330 |
param.setInboundTime(IN_TIME); |
|
331 |
param.setOutboundTime(DateTool.getLocalTimeForDate()); |
|
332 |
param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格 |
|
333 |
PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService; |
|
334 |
passingStationCollectionService.add(param); |
|
335 |
|
|
336 |
OPCUnit.write(opc.getOP080_J_PC_FINISH(), "true"); //PC完成 |
|
337 |
|
|
338 |
logger.info("OP080工位,handleFinsh PC处理完成!"); |
|
339 |
} |
|
340 |
|
|
341 |
} |