cl
2024-01-16 cf6bff3922bbd0624b98834f6ea85c8e619e564f
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.COP010.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;
cf6bff 9 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
C 10 import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
71e81e 11 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
12 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
13 import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
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;
71e81e 17 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
18 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
19 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
20 import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam;
21 import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult;
22 import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
23 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
24 import cn.stylefeng.guns.plcserver.opc.OPCComm;
25 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
26 import cn.stylefeng.guns.plcserver.opc.unit.qrCode;
27 import cn.stylefeng.guns.plcserver.server.COP010.COP010ServerInterface;
28 import cn.stylefeng.guns.plcserver.tool.DateTool;
29 import cn.stylefeng.guns.plcserver.tool.LogUtil;
30 import org.apache.commons.lang3.StringUtils;
31 import org.apache.log4j.Logger;
32 import org.openscada.opc.lib.da.Group;
33
34 import java.util.Date;
35 import java.util.List;
36 import java.util.Random;
37
38
39 public class COP010ServerInterfaceImpl implements COP010ServerInterface {
40
41     private static Logger logger;
42     LogUtil logUtil = new LogUtil();
43     static {
44         logger = Logger.getLogger(COP010ServerInterfaceImpl.class);
45     }
46
47     private OPCComm opc = OPCComm.getInstance();
48     private static Date IN_TIME = null;
49     private static String S_ORDER_CODE = "";//工单编号
50     private static String S_PRODUCT_CODE = "";//产品编号
51     private static String S_PRODUCT_TYPE= "";//产品类型
52     private static String S_PRODUCT_CODE_OLD = "";//产品编号
53     private static String S_SFC_CODE = "";//总成编码
54     private static String S_RIGHT_CODE  = "";//右壳体编码
55     private static String PRODUCTION_LINE  = "COP";//产线号
56     private static String LOCATION_CODE  = "COP010";//工位号
57     private static String GROUP_NAME  = "COP010_P";//工位号
58     private static List list = null;
59     private static Group group = null;
60
cf6bff 61     private int count = 0;
71e81e 62
cf6bff 63     /**
C 64      * 设置心跳标志位,保存到全局变量
65      */
66     public void setHeartbeat(String value) {
67         if ("false".equals(value)) {
68             OPCUnit.write(opc.getCOP010_F_HEART_BEAT(), "true");
69             GlobalVariable.COP010_F_HEART_BEAT = true;
70             count = 0;
71         } else {
72             count++;
73         }
74         // 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时
75         if (count > GlobalVariable.HEART_MAX_COUNT) {
76             GlobalVariable.COP010_F_HEART_BEAT = false;
77         }
78     }
71e81e 79
80     @Override
cf6bff 81     public synchronized void monitor() {
71e81e 82         String ecpStr = "";//异常记录标记
83         try{
cf6bff 84             String isHeartBeat = OPCUnit.read(opc.getCOP010_F_HEART_BEAT());
C 85             setHeartbeat(isHeartBeat);
86
71e81e 87
88             if(GlobalVariable.COP010_F_HEART_BEAT) {
89
90                 //PC读工单
91                 String isPLCStart = OPCUnit.read(opc.getCOP010_J_PLC_START());//PLC开始
92                 if(isPLCStart.equals("true")){
93                     String isFinish = OPCUnit.read(opc.getCOP010_J_PC_WRITE_ORDER());//PC下发工单完成
94                     if(isFinish.equals("false")){
95                         String isRepair = OPCUnit.read(opc.getCOP010_P_REPAIR());//是否返修
96                         if(isRepair.equals("true")){
97                             handleRepair();
98                         }else{
99                             handleOrder();
100                         }
101                     }
102                 }
103
104
105                 //PC完成
106                 String isPLCFinish = OPCUnit.read(opc.getCOP010_J_PLC_FINISH());//PLC完成
107                 if(isPLCFinish.equals("true")){
108                     String isFinish = OPCUnit.read(opc.getCOP010_J_PC_FINISH());//PC操作完成
109                     if(isFinish.equals("false")){
cf6bff 110                         handleMaterial();
71e81e 111                         handleFinsh();
112                     }
113                 }
114
115
116             }else{
117                 logger.info("COP010工位与PLC断开,请检查PLC或网络是否异常!");
118             }
119
120         }catch (Exception e) {
121             ecpStr ="出现异常:" + logUtil.getTrace(e);
122         }finally {
123             if(!"".equals(ecpStr)){
124                 logger.info(ecpStr+"\r\n");
125             }
126         }
127     }
128
129     public void handleRepair() {
130         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
131         repairManageInfoParam.setLocationCode(LOCATION_CODE);
132         repairManageInfoParam.setManageType("2");
133         repairManageInfoParam.setUpPlc("0");
134         RepairManageInfoService repairManageInfoService = opc.repairManageInfoService;
135         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
136         if(list.size()>0) {
137             RepairManageInfoResult result = list.get(0);
138
139             //自动生成唯一码
140             Random random = new Random(System.currentTimeMillis());
141             S_SFC_CODE = "COP" + random.nextLong();
142
143
144             S_ORDER_CODE = result.getWorkOrderNo();
145             S_PRODUCT_CODE = result.getProductCode();
146             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
147             String  repairLocation = result.getPoorLocationCode();//
148
149             //根据工位编码查询工位表中配置的返修工位号
150             LocationInfoParam param = new LocationInfoParam();
151             param.setLocationCode(repairLocation);
152             LocationInfoService locationInfoService = opc.locationInfoService;
153             List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
154             if(results.size()>0) {
155                 LocationInfoResult r = results.get(0);
156                 String repairLocationNo = r.getSpareField2();
157                 if(null != repairLocationNo && "" != repairLocationNo){
158                     OPCUnit.write(opc.getCOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
159                     OPCUnit.write(opc.getCOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
160                     OPCUnit.write(opc.getCOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
161                     OPCUnit.write(opc.getCOP010_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号
162                     OPCUnit.write(opc.getCOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
163
164                     //更新为已经返修上线
165                     Long id = result.getId();
166                     repairManageInfoParam.setId(id);
167                     repairManageInfoParam.setUpPlc("1");
168                     repairManageInfoService.update(repairManageInfoParam);
169
170                 }else{
171                     logger.info("COP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
172                 }
173             }else{
174                 logger.info("COP010工位,handleRepair 无法查询到"+repairLocation+"工位!");
175             }
176         }
177     }
178
179     //PC下发工单
180     public void handleOrder() {
181
182         IN_TIME = DateTool.getLocalTimeForDate();
183         ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
184         param.setProductionLine("");//产线
185         param.setOrderStatus("3");//工单状态
186
187         ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
188         List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
189
190         if(list.size()>0) {
191             ProductionOrdeInfoResult result = list.get(0);
192
193             S_ORDER_CODE = result.getWorkOrderNo();
194             S_PRODUCT_CODE = result.getMaterialCode();
195             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
196
197             //自动生成唯一码
198             Random random = new Random(System.currentTimeMillis());
199             S_SFC_CODE = "COP"+ random.nextLong();
200
201
202             OPCUnit.write(opc.getCOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
203             OPCUnit.write(opc.getCOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品类型
204             OPCUnit.write(opc.getCOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
205            // OPCUnit.write(opc.getCOP010_S_RIGHT_CODE(), S_RIGHT_CODE); //右壳体编码
206             OPCUnit.write(opc.getCOP010_S_NUMBER(), result.getPlanQty().toString()); //计划数量
207
208             OPCUnit.write(opc.getCOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
209             logger.info("COP010工位,handleOrder PC处理完成!2");
210         }else{
211             logger.info("COP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
212         }
213     }
214
cf6bff 215     public void handleMaterial() {
C 216         if("".equals(S_ORDER_CODE)){
217             IN_TIME = DateTool.getLocalTimeForDate();
218             S_ORDER_CODE = OPCUnit.read(opc.getCOP010_S_ORDER_CODE());//工单编号
219             S_PRODUCT_TYPE = OPCUnit.read(opc.getCOP010_S_PRODUCT_CODE());//产品编号
220             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
221             S_SFC_CODE = OPCUnit.read(opc.getCOP010_S_SFC_CODE());//总成编码
222         }
223         //查询批次上料信息
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
232             //判断是否有该工位
233             String[] locationCodes = productionOrderBatchInfoResult.getLocationCode().split("/");
234             logger.info("当前工位:"+locationCodes.toString());
235             boolean isLocationCode = false;
236             if(locationCodes.length>0)
237             {
238                 for (int j=0;j<locationCodes.length;j++){
239                     String location = locationCodes[j];
240                     if(location.equals(LOCATION_CODE)){
241                         isLocationCode = true;
242                     }
243                 }
244             }
245
246             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
247             if(remainingQuantity>0 && isLocationCode){
248                 //新增物料追溯
249                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
250                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
251                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
252                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
253                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
254                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
255                 materialTraceabilityParam.setAssemblyQty(1);
256                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
257                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
258                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
259
260                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
261                 materialTraceabilityService.add(materialTraceabilityParam);
262                 //更新剩余数量
263                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
264                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
265                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
266             }
267         }
268     }
71e81e 269
270     //PC完成
271     public void handleFinsh() {
272         if("".equals(S_ORDER_CODE)){
273             IN_TIME = DateTool.getLocalTimeForDate();
274             S_ORDER_CODE = OPCUnit.read(opc.getCOP010_S_ORDER_CODE());//工单编号
275             S_PRODUCT_TYPE = OPCUnit.read(opc.getCOP010_S_PRODUCT_CODE());//产品编号
276             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
277             S_SFC_CODE = OPCUnit.read(opc.getCOP010_S_SFC_CODE());//总成编码
278         }
279         //处理过站信息
280         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getCOP010_S_PRODUCT_STATE_CODE());
281         PassingStationCollectionParam param = new PassingStationCollectionParam();
282         param.setWorkOrderNo(S_ORDER_CODE);
283         param.setProductCode(S_PRODUCT_CODE);
284         param.setSfcCode(S_SFC_CODE);
285         param.setProductionLine(PRODUCTION_LINE);
286         param.setLocationCode(LOCATION_CODE);
287         param.setInboundTime(IN_TIME);
288         param.setOutboundTime(DateTool.getLocalTimeForDate());
289         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
290         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
291         passingStationCollectionService.add(param);
292
293         //写完成
294         OPCUnit.write(opc.getCOP010_J_PC_FINISH(), "true"); //PC完成
295
296         logger.info("COP010工位,handleFinsh PC处理完成!");
297     }
298
299
300 }