cl
2024-01-16 cf6bff3922bbd0624b98834f6ea85c8e619e564f
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.DOP010.impl;
2
3
4 import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam;
5 import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
6 import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
7 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
8 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
9 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
10 import cn.stylefeng.guns.modular.dq.materialTraceability.model.result.MaterialTraceabilityResult;
11 import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
12 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
13 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
14 import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
cf6bff 15 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
C 16 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
17 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
71e81e 18 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
19 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
20 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
21 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
22 import cn.stylefeng.guns.plcserver.opc.OPCComm;
23 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
24 import cn.stylefeng.guns.plcserver.server.COP010.COP010ServerInterface;
25 import cn.stylefeng.guns.plcserver.server.DOP010.DOP010ServerInterface;
26 import cn.stylefeng.guns.plcserver.tool.DateTool;
27 import cn.stylefeng.guns.plcserver.tool.LogUtil;
28 import org.apache.log4j.Logger;
29 import org.openscada.opc.lib.da.Group;
30
31 import java.util.Date;
32 import java.util.List;
33 import java.util.Random;
34
35
36 public class DOP010ServerInterfaceImpl implements DOP010ServerInterface {
37
38     private static Logger logger;
39     LogUtil logUtil = new LogUtil();
40     static {
41         logger = Logger.getLogger(DOP010ServerInterfaceImpl.class);
42     }
43
44     private OPCComm opc = OPCComm.getInstance();
45     private static Date IN_TIME = null;
46     private static String S_ORDER_CODE = "";//工单编号
47     private static String S_PRODUCT_CODE = "";//产品编号
48     private static String S_PRODUCT_TYPE= "";//产品类型
49     private static String S_PRODUCT_CODE_OLD = "";//产品编号
50     private static String S_SFC_CODE = "";//总成编码
51     private static String S_RIGHT_CODE  = "";//右壳体编码
52     private static String PRODUCTION_LINE  = "EOP";//产线号
53     private static String LOCATION_CODE  = "DOP010";//工位号
54     private static String GROUP_NAME  = "DOP010_P";//工位号
55     private static List list = null;
56     private static Group group = null;
57
cf6bff 58     private int count = 0;
71e81e 59
cf6bff 60     /**
C 61      * 设置心跳标志位,保存到全局变量
62      */
63     public void setHeartbeat(String value) {
64         if ("false".equals(value)) {
65             OPCUnit.write(opc.getDOP010_F_HEART_BEAT(), "true");
66             GlobalVariable.DOP010_F_HEART_BEAT = true;
67             count = 0;
68         } else {
69             count++;
70         }
71         // 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时
72         if (count > GlobalVariable.HEART_MAX_COUNT) {
73             GlobalVariable.DOP010_F_HEART_BEAT = false;
74         }
75     }
71e81e 76
77     @Override
cf6bff 78     public synchronized void monitor() {
71e81e 79         String ecpStr = "";//异常记录标记
80         try{
cf6bff 81             String isHeartBeat = OPCUnit.read(opc.getDOP010_F_HEART_BEAT());
C 82             setHeartbeat(isHeartBeat);
71e81e 83
84             if(GlobalVariable.DOP010_F_HEART_BEAT) {
85
86                 //PC读工单
87                 String isPLCStart = OPCUnit.read(opc.getDOP010_J_PLC_START());//PLC开始
88                 if(isPLCStart.equals("true")){
89                     String isFinish = OPCUnit.read(opc.getDOP010_J_PC_WRITE_ORDER());//PC下发工单完成
90
91                     if(isFinish.equals("false")){
92                         String isRepair = OPCUnit.read(opc.getDOP010_P_REPAIR());//是否返修
93                         if(isRepair.equals("true")){
94                             handleRepair();
95                         }else{
96                             handleOrder();
97                         }
98                     }
99                 }
100
101
102                 //PC完成
103                 String isPLCFinish = OPCUnit.read(opc.getDOP010_J_PLC_FINISH());//PLC完成
104                 if(isPLCFinish.equals("true")){
105                     String isFinish = OPCUnit.read(opc.getDOP010_J_PC_FINISH());//PC操作完成
106                     if(isFinish.equals("false")){
cf6bff 107                         handleMaterial();
71e81e 108                         handleFinsh();
109                     }
110                 }
111
112             }else{
113                 logger.info("DOP010工位与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     public void handleRepair() {
126         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
127         repairManageInfoParam.setLocationCode(LOCATION_CODE);
128         repairManageInfoParam.setManageType("2");
129         repairManageInfoParam.setUpPlc("0");
130         RepairManageInfoService repairManageInfoService = opc.repairManageInfoService;
131         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
132         if(list.size()>0) {
133             RepairManageInfoResult result = list.get(0);
134
135             S_SFC_CODE = result.getSfc();
136
137             //查询sfc编码
138             MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
139             materialTraceabilityParam.setMaterialCode(result.getSfc());
140             MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
141             List<MaterialTraceabilityResult> materialTraceabilityResults = materialTraceabilityService.findListBySpec(materialTraceabilityParam);
142             if(materialTraceabilityResults.size()>0){
143                 MaterialTraceabilityResult materialTraceabilityResult = materialTraceabilityResults.get(0);
144                 S_SFC_CODE = materialTraceabilityResult.getProductNo();
145             }
146
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.getDOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
162                     OPCUnit.write(opc.getDOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
163                     OPCUnit.write(opc.getDOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
164                     OPCUnit.write(opc.getDOP010_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号
165                     OPCUnit.write(opc.getDOP010_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("DOP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
175                 }
176             }else{
177                 logger.info("DOP010工位,handleRepair 无法查询到"+repairLocation+"工位!");
178             }
179         }
180     }
181
182     //PC下发工单
183     public void handleOrder() {
184         IN_TIME = DateTool.getLocalTimeForDate();
185         ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
186         param.setProductionLine("");//产线
187         param.setOrderStatus("3");//工单状态
188
189         ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
190         List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
191
192         if(list.size()>0) {
193             ProductionOrdeInfoResult result = list.get(0);
194
195             S_ORDER_CODE = result.getWorkOrderNo();
196             S_PRODUCT_CODE = result.getMaterialCode();
197
198             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
199
200             //ACTUAL_ONLINE_QTY = result.getActualOnlineQty();
201             //S_SFC_CODE = qrCode.unitNoRetrospect();
202             //S_RIGHT_CODE = qrCode.SerialNumbers;
203
204             //自动生成唯一码
205             Random random = new Random(System.currentTimeMillis());
206             S_SFC_CODE = "EOP"+ random.nextLong();
207
208
209             OPCUnit.write(opc.getDOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
210             OPCUnit.write(opc.getDOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品类型
211             OPCUnit.write(opc.getDOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
212            // OPCUnit.write(opc.getDOP010_S_RIGHT_CODE(), S_RIGHT_CODE); //右壳体编码
213             OPCUnit.write(opc.getDOP010_S_NUMBER(), result.getPlanQty().toString()); //计划数量
214             OPCUnit.write(opc.getDOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
215             logger.info("DOP010工位,handleOrder PC处理完成!");
216         }else{
217             logger.info("DOP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
218         }
219     }
220
cf6bff 221     public void handleMaterial() {
C 222         if("".equals(S_ORDER_CODE)){
223             IN_TIME = DateTool.getLocalTimeForDate();
224             S_ORDER_CODE = OPCUnit.read(opc.getDOP010_S_ORDER_CODE());//工单编号
225             S_PRODUCT_TYPE = OPCUnit.read(opc.getDOP010_S_PRODUCT_CODE());//产品编号
226             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
227             S_SFC_CODE = OPCUnit.read(opc.getDOP010_S_SFC_CODE());//总成编码
228         }
229         //查询批次上料信息
230         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
231         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
232         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
233         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
234         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
235         for(int i=0;i<list1.size();i++){
236             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
237
238             //判断是否有该工位
239             String[] locationCodes = productionOrderBatchInfoResult.getLocationCode().split("/");
240             logger.info("当前工位:"+locationCodes.toString());
241             boolean isLocationCode = false;
242             if(locationCodes.length>0)
243             {
244                 for (int j=0;j<locationCodes.length;j++){
245                     String location = locationCodes[j];
246                     if(location.equals(LOCATION_CODE)){
247                         isLocationCode = true;
248                     }
249                 }
250             }
251
252             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
253             if(remainingQuantity>0 && isLocationCode){
254                 //新增物料追溯
255                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
256                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
257                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
258                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
259                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
260                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
261                 materialTraceabilityParam.setAssemblyQty(1);
262                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
263                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
264                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
265
266                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
267                 materialTraceabilityService.add(materialTraceabilityParam);
268                 //更新剩余数量
269                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
270                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
271                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
272             }
273         }
274     }
71e81e 275
276
277     //PC完成
278     public void handleFinsh() {
279
280         if("".equals(S_ORDER_CODE)){
281             IN_TIME = DateTool.getLocalTimeForDate();
282             S_ORDER_CODE = OPCUnit.read(opc.getDOP010_S_ORDER_CODE());//工单编号
283             S_PRODUCT_TYPE = OPCUnit.read(opc.getDOP010_S_PRODUCT_CODE());//产品编号
284             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
285             S_SFC_CODE = OPCUnit.read(opc.getDOP010_S_SFC_CODE());//总成编码
286         }
287
288         //处理过站信息
289         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getDOP010_S_PRODUCT_STATE_CODE());
290         PassingStationCollectionParam param = new PassingStationCollectionParam();
291         param.setWorkOrderNo(S_ORDER_CODE);
292         param.setProductCode(S_PRODUCT_CODE);
293         param.setSfcCode(S_SFC_CODE);
294         param.setProductionLine(PRODUCTION_LINE);
295         param.setLocationCode(LOCATION_CODE);
296         param.setInboundTime(IN_TIME);
297         param.setOutboundTime(DateTool.getLocalTimeForDate());
298         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
299         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
300         passingStationCollectionService.add(param);
301
302         //上线数量加1    根据工单号,更新 ACTUAL_ONLINE_QTY +1
303        /* ProductionOrdeInfoParam orderParam = new ProductionOrdeInfoParam();
304         orderParam.setWorkOrderNo(S_ORDER_CODE);
305         orderParam.setActualOnlineQty(ACTUAL_ONLINE_QTY+1);
306         ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
307         productionOrdeInfoService.updateOrderOnlineQry(orderParam);*/
308
309         //写完成
310         OPCUnit.write(opc.getDOP010_J_PC_FINISH(), "true"); //PC完成
311
312         logger.info("DOP010工位,handleFinsh PC处理完成!");
313     }
314
315
316 }