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