cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
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{
e0fac3 84         /*    String isHeartBeat = OPCUnit.read(opc.getCOP010_F_HEART_BEAT());
C 85             setHeartbeat(isHeartBeat);*/
cf6bff 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")){
110                         handleFinsh();
e0fac3 111                         handleMaterial();
71e81e 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() {
e0fac3 216
cf6bff 217         //查询批次上料信息
C 218         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
219         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
220         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
221         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
222         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
223         for(int i=0;i<list1.size();i++){
224             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
225
226
227             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 228             if(remainingQuantity>0 ){
cf6bff 229                 //新增物料追溯
C 230                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
231                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
232                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
233                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
234                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
235                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
236                 materialTraceabilityParam.setAssemblyQty(1);
237                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
238                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
239                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
240
241                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
242                 materialTraceabilityService.add(materialTraceabilityParam);
243                 //更新剩余数量
244                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
245                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
246                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
247             }
248         }
249     }
71e81e 250
251     //PC完成
252     public void handleFinsh() {
253         if("".equals(S_ORDER_CODE)){
254             IN_TIME = DateTool.getLocalTimeForDate();
255             S_ORDER_CODE = OPCUnit.read(opc.getCOP010_S_ORDER_CODE());//工单编号
256             S_PRODUCT_TYPE = OPCUnit.read(opc.getCOP010_S_PRODUCT_CODE());//产品编号
257             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
258             S_SFC_CODE = OPCUnit.read(opc.getCOP010_S_SFC_CODE());//总成编码
259         }
260         //处理过站信息
261         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getCOP010_S_PRODUCT_STATE_CODE());
262         PassingStationCollectionParam param = new PassingStationCollectionParam();
263         param.setWorkOrderNo(S_ORDER_CODE);
264         param.setProductCode(S_PRODUCT_CODE);
265         param.setSfcCode(S_SFC_CODE);
266         param.setProductionLine(PRODUCTION_LINE);
267         param.setLocationCode(LOCATION_CODE);
268         param.setInboundTime(IN_TIME);
269         param.setOutboundTime(DateTool.getLocalTimeForDate());
270         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
271         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
272         passingStationCollectionService.add(param);
273
274         //写完成
275         OPCUnit.write(opc.getCOP010_J_PC_FINISH(), "true"); //PC完成
276
277         logger.info("COP010工位,handleFinsh PC处理完成!");
278     }
279
280
281 }