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