cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
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{
e0fac3 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")){
107                         handleFinsh();
e0fac3 108                         handleMaterial();
71e81e 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() {
e0fac3 222
cf6bff 223         //查询批次上料信息
C 224         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
225         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
226         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
227         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
228         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
229         for(int i=0;i<list1.size();i++){
230             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
231
e0fac3 232
cf6bff 233
C 234             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 235             if(remainingQuantity>0 ){
cf6bff 236                 //新增物料追溯
C 237                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
238                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
239                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
240                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
241                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
242                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
243                 materialTraceabilityParam.setAssemblyQty(1);
244                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
245                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
246                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
247
248                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
249                 materialTraceabilityService.add(materialTraceabilityParam);
250                 //更新剩余数量
251                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
252                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
253                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
254             }
255         }
256     }
71e81e 257
258
259     //PC完成
260     public void handleFinsh() {
261
262         if("".equals(S_ORDER_CODE)){
263             IN_TIME = DateTool.getLocalTimeForDate();
264             S_ORDER_CODE = OPCUnit.read(opc.getDOP010_S_ORDER_CODE());//工单编号
265             S_PRODUCT_TYPE = OPCUnit.read(opc.getDOP010_S_PRODUCT_CODE());//产品编号
266             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
267             S_SFC_CODE = OPCUnit.read(opc.getDOP010_S_SFC_CODE());//总成编码
268         }
269
270         //处理过站信息
271         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getDOP010_S_PRODUCT_STATE_CODE());
272         PassingStationCollectionParam param = new PassingStationCollectionParam();
273         param.setWorkOrderNo(S_ORDER_CODE);
274         param.setProductCode(S_PRODUCT_CODE);
275         param.setSfcCode(S_SFC_CODE);
276         param.setProductionLine(PRODUCTION_LINE);
277         param.setLocationCode(LOCATION_CODE);
278         param.setInboundTime(IN_TIME);
279         param.setOutboundTime(DateTool.getLocalTimeForDate());
280         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
281         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
282         passingStationCollectionService.add(param);
283
284         //上线数量加1    根据工单号,更新 ACTUAL_ONLINE_QTY +1
285        /* ProductionOrdeInfoParam orderParam = new ProductionOrdeInfoParam();
286         orderParam.setWorkOrderNo(S_ORDER_CODE);
287         orderParam.setActualOnlineQty(ACTUAL_ONLINE_QTY+1);
288         ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
289         productionOrdeInfoService.updateOrderOnlineQry(orderParam);*/
290
291         //写完成
292         OPCUnit.write(opc.getDOP010_J_PC_FINISH(), "true"); //PC完成
293
294         logger.info("DOP010工位,handleFinsh PC处理完成!");
295     }
296
297
298 }