cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
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
e0fac3 86           /*  String isHeartBeat = OPCUnit.read(opc.getOP080_F_HEART_BEAT());
C 87             setHeartbeat(isHeartBeat);*/
cf6bff 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")){
e0fac3 111                         logger.info("handleFinsh开始时间:"+new Date());
71e81e 112                         handleFinsh();
e0fac3 113                         logger.info("handleFinsh完成时间:"+new Date());
C 114                         logger.info("handleInfo开始时间:"+new Date());
115                         handleInfo();
116                         logger.info("handleInfo完成时间:"+new Date());
117                         logger.info("handleMaterial开始时间:"+new Date());
118                         handleMaterial();
119                         logger.info("handleMaterial完成时间:"+new Date());
71e81e 120                     }
121                 }
122
123             }else{
124                 logger.info("OP080工位与PLC断开,请检查PLC或网络是否异常!");
125             }
126
127         }catch (Exception e) {
128             ecpStr ="出现异常:" + logUtil.getTrace(e);
129         }finally {
130             if(!"".equals(ecpStr)){
131                 logger.info(ecpStr+"\r\n");
132             }
133         }
134     }
135
136     public void handleRepair() {
137         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
138         repairManageInfoParam.setLocationCode(LOCATION_CODE);
139         repairManageInfoParam.setManageType("2");
140         repairManageInfoParam.setUpPlc("0");
141         RepairManageInfoService repairManageInfoService = opc.repairManageInfoService;
142         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
143         if(list.size()>0) {
144             RepairManageInfoResult result = list.get(0);
145
146             S_SFC_CODE = result.getSfc();
147             S_ORDER_CODE = result.getWorkOrderNo();
148             S_PRODUCT_CODE = result.getProductCode();
149             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
150             String  repairLocation = result.getPoorLocationCode();//
151
152             //根据工位编码查询工位表中配置的返修工位号
153             LocationInfoParam param = new LocationInfoParam();
154             param.setLocationCode(repairLocation);
155             LocationInfoService locationInfoService = opc.locationInfoService;
156             List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
157             if(results.size()>0) {
158                 LocationInfoResult r = results.get(0);
159                 String repairLocationNo = r.getSpareField2();
160                 if(null != repairLocationNo && "" != repairLocationNo){
161                     OPCUnit.write(opc.getOP080_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
162                     OPCUnit.write(opc.getOP080_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
163                     OPCUnit.write(opc.getOP080_S_SFC_CODE(), S_SFC_CODE); //总成编码
164                     OPCUnit.write(opc.getOP080_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号
165                     OPCUnit.write(opc.getOP080_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
166
167                     //更新为已经返修上线
168                     Long id = result.getId();
169                     repairManageInfoParam.setId(id);
170                     repairManageInfoParam.setUpPlc("1");
171                     repairManageInfoService.update(repairManageInfoParam);
172
173                 }else{
174                     logger.info("OP080工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
175                 }
176             }else{
177                 logger.info("OP080工位,handleRepair 无法查询到"+repairLocation+"工位!");
178             }
179         }
180     }
181
182     //PC读工单
183     public void handleOrder() {
184         IN_TIME = DateTool.getLocalTimeForDate();
185         S_ORDER_CODE = OPCUnit.read(opc.getOP080_S_ORDER_CODE());//工单编号
186         S_PRODUCT_TYPE = OPCUnit.read(opc.getOP080_S_PRODUCT_CODE());//产品编号
187         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
188         S_SFC_CODE = OPCUnit.read(opc.getOP080_S_SFC_CODE());//总成编码
189         OPCUnit.write(opc.getOP080_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
190         logger.info("OP080工位,handleOrder PC处理完成!");
191     }
192
cf6bff 193     public void handleMaterial() {
e0fac3 194
cf6bff 195         //查询批次上料信息
C 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             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 206             if(remainingQuantity>0 ){
cf6bff 207                 //新增物料追溯
C 208                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
209                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
210                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
211                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
212                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
213                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
214                 materialTraceabilityParam.setAssemblyQty(1);
215                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
216                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
217                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
218
219                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
220                 materialTraceabilityService.add(materialTraceabilityParam);
221                 //更新剩余数量
222                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
223                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
224                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
225             }
226         }
227     }
228
71e81e 229     //PC读参数信息
230     public void handleInfo() throws Exception {
231         logger.info("OP080工位,handleInfo START!");
232
233         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
234             if(group != null){
235                 opc.getServer().removeGroup(group,true);
236             }
237             group = opc.getServer().addGroup(GROUP_NAME);
238
239             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
240             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
241             collectionParamConfParam.setLocationCode(LOCATION_CODE);
242             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
243             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
244
245
246             for(int i=0;i<list.size();i++){
247                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
248                 Item item = group.addItem(result.getGatherAddress());
249                 result.setItem(item);
250                 list.set(i,result);
251             }
252             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
253         }
254
255         if(null != list && list.size()>0) {
256             ParamCollectionService paramCollectionService = opc.paramCollectionService;
257             for (int i = 0; i < list.size(); i++) {
258                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
259                 Item item = result.getItem();
260                 String value = OPCUnit.read(item);//读参数值
261                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
262                 paramCollectionParam.setParamCode(result.getParamCode());
263                 paramCollectionParam.setParamName(result.getParamName());
264                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
265                 paramCollectionParam.setSfcCode(S_SFC_CODE);
266                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
267                 paramCollectionParam.setProductionLine(result.getProductionLine());
268                 paramCollectionParam.setLocationCode(result.getLocationCode());
269                 paramCollectionParam.setParamValue(value);
270                 paramCollectionParam.setParamLower(result.getParamLower());
271                 paramCollectionParam.setParamUpper(result.getParamUpper());
272                 paramCollectionParam.setParamStandard(result.getParamCentral());
273                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
274                 paramCollectionParam.setUnit(result.getUnit());
275                 paramCollectionService.add(paramCollectionParam);
276             }
277         }
278
279         logger.info("OP080工位,handleInfo END!");
280     }
281
282     //PC完成
283     public void handleFinsh() {
284         if("".equals(S_ORDER_CODE)){
285             IN_TIME = DateTool.getLocalTimeForDate();
286             S_ORDER_CODE = OPCUnit.read(opc.getOP080_S_ORDER_CODE());//工单编号
287             S_PRODUCT_TYPE = OPCUnit.read(opc.getOP080_S_PRODUCT_CODE());//产品编号
288             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
289             S_SFC_CODE = OPCUnit.read(opc.getOP080_S_SFC_CODE());//总成编码
290         }
291         //处理过站信息
292         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP080_S_PRODUCT_STATE_CODE());
cf6bff 293
C 294         //修改报工记录
295         if("false".equals(S_PRODUCT_STATE_CODE)){
296             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
297             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
298             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
299             ProductionOrderRecordsService productionOrderRecordsService = opc.productionOrderRecordsService;
300
301             List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
302             if(list.size()>0){
303                 ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
304                 productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
305                 productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
306                 productionOrderRecordsService.update(productionOrderRecordsParam);
307             }
308         }
309
310
71e81e 311         PassingStationCollectionParam param = new PassingStationCollectionParam();
312         param.setWorkOrderNo(S_ORDER_CODE);
313         param.setProductCode(S_PRODUCT_CODE);
314         param.setSfcCode(S_SFC_CODE);
315         param.setProductionLine(PRODUCTION_LINE);
316         param.setLocationCode(LOCATION_CODE);
317         param.setInboundTime(IN_TIME);
318         param.setOutboundTime(DateTool.getLocalTimeForDate());
319         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
320         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
321         passingStationCollectionService.add(param);
322
323         OPCUnit.write(opc.getOP080_J_PC_FINISH(), "true"); //PC完成
324
325         logger.info("OP080工位,handleFinsh PC处理完成!");
326     }
327
328 }