cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
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
e0fac3 81            /* String isHeartBeat = OPCUnit.read(opc.getOP090_F_HEART_BEAT());
C 82             setHeartbeat(isHeartBeat);*/
cf6bff 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")){
e0fac3 100                         logger.info("handleFinsh开始时间:"+new Date());
71e81e 101                         handleFinsh();
e0fac3 102                         logger.info("handleFinsh完成时间:"+new Date());
C 103                         logger.info("handleInfo开始时间:"+new Date());
104                         handleInfo();
105                         logger.info("handleInfo完成时间:"+new Date());
106                         logger.info("handleMaterial开始时间:"+new Date());
107                         handleMaterial();
108                         logger.info("handleMaterial完成时间:"+new Date());
71e81e 109                     }
110                 }
111
112             }else{
113                 logger.info("OP090工位与PLC断开,请检查PLC或网络是否异常!");
114             }
115
116         }catch (Exception e) {
117             ecpStr ="出现异常:" + logUtil.getTrace(e);
118         }finally {
119             if(!"".equals(ecpStr)){
120                 logger.info(ecpStr+"\r\n");
121             }
122         }
123     }
124
125     //PC读工单
126     public void handleOrder() {
127         IN_TIME = DateTool.getLocalTimeForDate();
128         S_ORDER_CODE = OPCUnit.read(opc.getOP090_S_ORDER_CODE());//工单编号
129         S_PRODUCT_TYPE = OPCUnit.read(opc.getOP090_S_PRODUCT_CODE());//产品编号
130         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
131         S_SFC_CODE = OPCUnit.read(opc.getOP090_S_SFC_CODE());//总成编码
132         OPCUnit.write(opc.getOP090_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
133         logger.info("OP090工位,handleOrder PC处理完成!");
cf6bff 134     }
C 135
136     public void handleMaterial() {
e0fac3 137
cf6bff 138         //查询批次上料信息
C 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             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 148             if(remainingQuantity>0 ){
cf6bff 149                 //新增物料追溯
C 150                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
151                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
152                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
153                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
154                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
155                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
156                 materialTraceabilityParam.setAssemblyQty(1);
157                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
158                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
159                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
160
161                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
162                 materialTraceabilityService.add(materialTraceabilityParam);
163                 //更新剩余数量
164                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
165                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
166                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
167             }
168         }
71e81e 169     }
170
171     //PC读参数信息
172     public void handleInfo() throws Exception {
173         logger.info("OP090工位,handleInfo START!");
174
175         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
176             if(group != null){
177                 opc.getServer().removeGroup(group,true);
178             }
179             group = opc.getServer().addGroup(GROUP_NAME);
180
181             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
182             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
183             collectionParamConfParam.setLocationCode(LOCATION_CODE);
184             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
185             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
186
187
188             for(int i=0;i<list.size();i++){
189                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
190                 Item item = group.addItem(result.getGatherAddress());
191                 result.setItem(item);
192                 list.set(i,result);
193             }
194             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
195         }
196
197         if(null != list && list.size()>0) {
198             ParamCollectionService paramCollectionService = opc.paramCollectionService;
199             for (int i = 0; i < list.size(); i++) {
200                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
201                 Item item = result.getItem();
202                 String value = OPCUnit.read(item);//读参数值
203                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
204                 paramCollectionParam.setParamCode(result.getParamCode());
205                 paramCollectionParam.setParamName(result.getParamName());
206                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
207                 paramCollectionParam.setSfcCode(S_SFC_CODE);
208                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
209                 paramCollectionParam.setProductionLine(result.getProductionLine());
210                 paramCollectionParam.setLocationCode(result.getLocationCode());
211                 paramCollectionParam.setParamValue(value);
212                 paramCollectionParam.setParamLower(result.getParamLower());
213                 paramCollectionParam.setParamUpper(result.getParamUpper());
214                 paramCollectionParam.setParamStandard(result.getParamCentral());
215                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
216                 paramCollectionParam.setUnit(result.getUnit());
217                 paramCollectionService.add(paramCollectionParam);
218             }
219         }
220
221         logger.info("OP090工位,handleInfo END!");
222     }
223
224     //PC完成
225     public void handleFinsh() {
226         if("".equals(S_ORDER_CODE)){
227             IN_TIME = DateTool.getLocalTimeForDate();
228             S_ORDER_CODE = OPCUnit.read(opc.getOP090_S_ORDER_CODE());//工单编号
229             S_PRODUCT_TYPE = OPCUnit.read(opc.getOP090_S_PRODUCT_CODE());//产品编号
230             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
231             S_SFC_CODE = OPCUnit.read(opc.getOP090_S_SFC_CODE());//总成编码
232         }
233         //处理过站信息
234         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP090_S_PRODUCT_STATE_CODE());
235         PassingStationCollectionParam param = new PassingStationCollectionParam();
236         param.setWorkOrderNo(S_ORDER_CODE);
237         param.setProductCode(S_PRODUCT_CODE);
238         param.setSfcCode(S_SFC_CODE);
239         param.setProductionLine(PRODUCTION_LINE);
240         param.setLocationCode(LOCATION_CODE);
241         param.setInboundTime(IN_TIME);
242         param.setOutboundTime(DateTool.getLocalTimeForDate());
243         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
244         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
245         passingStationCollectionService.add(param);
246
247
248         String  eopSfcCode = OPCUnit.read(opc.getOP090_S_SFC_CODE_EOP());//EOP分总成
249
250         //根据分总成编码,将EOP物料数据绑定关系修改为总成编码
251         MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
252         materialTraceabilityService.updateSFC(S_SFC_CODE,eopSfcCode);
253
254         //根据分总成编码,将EOP过站数据绑定关系修改为总成编码
255         passingStationCollectionService.updateSFC(S_SFC_CODE,eopSfcCode);
256
257         //根据分总成编码,将EOP采集数据绑定关系修改为总成编码
258         ParamCollectionService paramCollectionService = opc.paramCollectionService;
259         paramCollectionService.updateSFC(S_SFC_CODE,eopSfcCode);
260
cf6bff 261         logger.info("S_SFC_CODE:"+S_SFC_CODE);
C 262         logger.info("eopSfcCode:"+eopSfcCode);
263
264         //查询COP和BOP是否合格
265         PassingStationCollectionParam passingStationCollectionParam = new PassingStationCollectionParam();
266         passingStationCollectionParam.setSfcCode(S_SFC_CODE);
267         List<PassingStationCollectionResult> passingStationCollectionResultList =
268                 opc.passingStationCollectionService.findListBySpec(passingStationCollectionParam);
269
270         String isProductState = "true";
271         for(int i=0;i<passingStationCollectionResultList.size();i++){
272             PassingStationCollectionResult passingStationCollectionResult = passingStationCollectionResultList.get(i);
273             if("false".equals(passingStationCollectionResult.getOutRsSign())){
274                 isProductState = "false";
275                 break;
276             }
277         }
278         //修改报工记录
279         if("false".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){
280             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
281             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
282             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
283             ProductionOrderRecordsService productionOrderRecordsService = opc.productionOrderRecordsService;
284
285             List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
286             if(list.size()>0){
287                 ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
288                 productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
289                 productionOrderRecordsParam.setWhetherPass("false");
290                 productionOrderRecordsService.update(productionOrderRecordsParam);
291             }
292         }
293
71e81e 294         OPCUnit.write(opc.getOP090_J_PC_FINISH(), "true"); //PC完成
295
296         logger.info("OP090工位,handleFinsh PC处理完成!");
297     }
298
299 }