cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.OP010.impl;
2
3
4 import cn.stylefeng.guns.GunsApplication;
5 import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam;
6 import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
7 import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
8 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
9 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
cf6bff 10 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
C 11 import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
71e81e 12 import cn.stylefeng.guns.modular.om.productionOrdeInfo.entity.ProductionOrdeInfo;
13 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
14 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
15 import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
cf6bff 16 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
C 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.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam;
26 import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult;
27 import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
28 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
29 import cn.stylefeng.guns.plcserver.opc.OPCComm;
30 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
31 import cn.stylefeng.guns.plcserver.opc.unit.SFCCodeTool;
32 import cn.stylefeng.guns.plcserver.server.OP010.OP010ServerInterface;
33 import cn.stylefeng.guns.plcserver.tool.DateTool;
34 import cn.stylefeng.guns.plcserver.tool.LogUtil;
35 import cn.stylefeng.roses.core.util.ToolUtil;
36 import lombok.Synchronized;
37 import org.apache.commons.lang3.StringUtils;
38 import org.apache.log4j.Logger;
39 import org.springframework.boot.SpringApplication;
40
e37994 41 import java.util.Calendar;
71e81e 42 import java.util.Date;
43 import java.util.List;
44
45
46
47 public class OP010ServerInterfaceImpl implements OP010ServerInterface {
48
49     private static Logger logger;
50     LogUtil logUtil = new LogUtil();
51     static {
52         logger = Logger.getLogger(OP010ServerInterfaceImpl.class);
53     }
54
55     private OPCComm opc = OPCComm.getInstance();
56
57     private static String S_ORDER_CODE = "";//工单编号
58     private static String S_PRODUCT_CODE = "";//产品编号
59     private static String S_PRODUCT_TYPE= "";//产品类型
60     private static String S_SFC_CODE = "test222";//总成编码
61     private static String S_RIGHT_CODE  = "test333";//右壳体编码
62     private static String PRODUCTION_LINE  = "OP";//产线号
63     private static String LOCATION_CODE  = "OP010";//工位号
64     private static Date IN_TIME = null;//进站时间
65
66     private static Integer ACTUAL_ONLINE_QTY  = 0 ;//上线数量
67
cf6bff 68     private int count = 0;
71e81e 69
cf6bff 70     /**
C 71      * 设置心跳标志位,保存到全局变量
72      */
73     public void setHeartbeat(String value) {
74         if ("false".equals(value)) {
75             OPCUnit.write(opc.getOP010_F_HEART_BEAT(), "true");
76             GlobalVariable.OP010_F_HEART_BEAT = true;
77             count = 0;
78         } else {
79             count++;
80         }
81         // 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时
82         if (count > GlobalVariable.HEART_MAX_COUNT) {
83             GlobalVariable.OP010_F_HEART_BEAT = false;
84         }
85     }
71e81e 86
87     @Override
88     public synchronized void monitor() {
89         String ecpStr = "";//异常记录标记
90         try{
cf6bff 91
e0fac3 92            /* String isHeartBeat = OPCUnit.read(opc.getOP010_F_HEART_BEAT());
C 93             setHeartbeat(isHeartBeat);*/
71e81e 94
95             if(GlobalVariable.OP010_F_HEART_BEAT) {
96
97                 //PC读工单
98                 String isPLCStart = OPCUnit.read(opc.getOP010_J_PLC_START());//PLC开始
99                 if(isPLCStart.equals("true")){
100                     String isFinish = OPCUnit.read(opc.getOP010_J_PC_WRITE_ORDER());//PC下发工单完成
101                     if(isFinish.equals("false")){
102
103                         String isRepair = OPCUnit.read(opc.getOP010_P_REPAIR());//是否返修
104                         if(isRepair.equals("true")){
105                             handleRepair();
106                         }else{
107                             handleOrder();
108                         }
109
110                     }
111                 }
112
113
114                 //PC完成
115                 String isPLCFinish = OPCUnit.read(opc.getOP010_J_PLC_FINISH());//PLC完成
116                 if(isPLCFinish.equals("true")){
117                     String isFinish = OPCUnit.read(opc.getOP010_J_PC_FINISH());//PC操作完成
118                     if(isFinish.equals("false")){
e0fac3 119                         logger.info("handleFinsh开始时间:"+new Date());
71e81e 120                         handleFinsh();
e0fac3 121                         logger.info("handleFinsh完成时间:"+new Date());
C 122
123                         logger.info("handleMaterial开始时间:"+new Date());
124                         handleMaterial();
125                         logger.info("handleMaterial完成时间:"+new Date());
71e81e 126                     }
127                 }
128
129             }else{
130                 logger.info("OP010工位与PLC断开,请检查PLC或网络是否异常!");
131             }
132
133         }catch (Exception e) {
134             ecpStr ="出现异常:" + logUtil.getTrace(e);
135         }finally {
136             if(!"".equals(ecpStr)){
137                 logger.info(ecpStr+"\r\n");
138             }
139         }
140     }
141
142     public void handleRepair() {
143         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
144         repairManageInfoParam.setLocationCode(LOCATION_CODE);
145         repairManageInfoParam.setManageType("2");
146         repairManageInfoParam.setUpPlc("0");
147         RepairManageInfoService repairManageInfoService = opc.repairManageInfoService;
148         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
149         if(list.size()>0) {
150             RepairManageInfoResult result = list.get(0);
151
152             S_SFC_CODE = result.getSfc();
153             S_ORDER_CODE = result.getWorkOrderNo();
154             S_PRODUCT_CODE = result.getProductCode();
155             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
156             String  repairLocation = result.getPoorLocationCode();//
157
158             //根据工位编码查询工位表中配置的返修工位号
159             LocationInfoParam param = new LocationInfoParam();
160             param.setLocationCode(repairLocation);
161             LocationInfoService locationInfoService = opc.locationInfoService;
162             List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
163             if(results.size()>0) {
164                 LocationInfoResult r = results.get(0);
165                 String repairLocationNo = r.getSpareField2();
166                 if(null != repairLocationNo && "" != repairLocationNo){
167                     OPCUnit.write(opc.getOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
168                     OPCUnit.write(opc.getOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
169                     OPCUnit.write(opc.getOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
170                     OPCUnit.write(opc.getOP010_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号
171                     OPCUnit.write(opc.getOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
172
173                     //更新为已经返修上线
174                     Long id = result.getId();
175                     repairManageInfoParam.setId(id);
176                     repairManageInfoParam.setUpPlc("1");
177                     repairManageInfoService.update(repairManageInfoParam);
178
179                 }else{
180                     logger.info("OP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
181                 }
182             }else{
183                 logger.info("OP010工位,handleRepair 无法查询到"+repairLocation+"工位!");
184             }
185
186
187
188         }
189     }
190     //PC下发工单
191     public void handleOrder() {
cf6bff 192
71e81e 193         logger.info("OP010工位,handleOrder PC处理开始!");
194         IN_TIME = DateTool.getLocalTimeForDate();
195         ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
196         param.setProductionLine("");//产线
197         param.setOrderStatus("3");//工单状态
198
199         ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
200         List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
201
202         if(list.size()>0) {
203             ProductionOrdeInfoResult result = list.get(0);
204
205             String customerCode = result.getCustom();//客户编码
206             String productCode = result.getMaterialCode();//产品编码
207             String softwareVersionCode = result.getSoftwareVersionCode();//产品型号
208             String productCompanyCode = result.getProductCompanyCode();//班次
209
210             //序列号
211             String serialNumbers = "0000";
212             SerialNumbersConfParam serialNumbersConfParam = new SerialNumbersConfParam();
e37994 213             Calendar calendar = Calendar.getInstance();
L 214             String Years = String.valueOf(calendar.get(Calendar.YEAR)); //年份
215             String Months = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH) + 1),2, "0"); //月份
216             String Dates = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)),2, "0"); //日期
217             serialNumbersConfParam.setYears(Years+Months+Dates);//获取当前是哪一天
71e81e 218             serialNumbersConfParam.setState("1");
219             SerialNumbersConfService serialNumbersConfService = opc.serialNumbersConfService;
220             List<SerialNumbersConfResult> serialNumberslist = serialNumbersConfService.findListBySpec(serialNumbersConfParam);
221             if(serialNumberslist.size()>0){
222                 SerialNumbersConfResult serialNumbersConfResult = serialNumberslist.get(0);
223                 serialNumbers = serialNumbersConfResult.getSerialNumber();
224                 serialNumbersConfParam.setId(serialNumbersConfResult.getId());
225             }else{
226                 serialNumbersConfParam.setSerialNumber(serialNumbers);
227                 serialNumbersConfParam.setLengths("4");
228                 serialNumbersConfService.add(serialNumbersConfParam);
229                 List<SerialNumbersConfResult> serialNumberslist2 = serialNumbersConfService.findListBySpec(serialNumbersConfParam);
230                 if(serialNumberslist2.size()>0){
231                     SerialNumbersConfResult serialNumbersConfResult = serialNumberslist2.get(0);
232                     //serialNumbers = serialNumbersConfResult.getSerialNumber();
233                     serialNumbersConfParam.setId(serialNumbersConfResult.getId());
234                 }
235                 //logger.info("序列号没有配置,请找管理员进行配置!");
236             }
237
238             //更新序列号+1
239             int i = Integer.valueOf(serialNumbers)+1;
240             serialNumbers = StringUtils.leftPad(String.valueOf(i),4, "0");
241             serialNumbersConfParam.setSerialNumber(serialNumbers);
242             serialNumbersConfService.update(serialNumbersConfParam);
243
244             //生成总成编码
245             String sfcCode = SFCCodeTool.createCodingRulesSFC(softwareVersionCode,productCompanyCode,serialNumbers);//总成号
246             S_SFC_CODE = sfcCode;
247
248             S_ORDER_CODE = result.getWorkOrderNo();
249             S_PRODUCT_CODE = result.getMaterialCode();
250             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
251             ACTUAL_ONLINE_QTY = result.getActualOnlineQty();
252
cf6bff 253
C 254             //新增报工记录
255             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
256             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
257             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
258             productionOrderRecordsParam.setMaterialCode(S_PRODUCT_CODE);
259             productionOrderRecordsParam.setStartTime(DateTool.getLocalTimeForDate());
260             productionOrderRecordsParam.setWhetherPass("true");
261             ProductionOrderRecordsService productionOrderRecordsService = opc.productionOrderRecordsService;
262             productionOrderRecordsService.add(productionOrderRecordsParam);
263
264
71e81e 265             OPCUnit.write(opc.getOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
266             OPCUnit.write(opc.getOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
267             OPCUnit.write(opc.getOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
268            //OPCUnit.write(opc.getOP010_S_RIGHT_CODE(), S_RIGHT_CODE); //右壳体编码
269             OPCUnit.write(opc.getOP010_S_NUMBER(), result.getPlanQty().toString()); //计划数量
270             OPCUnit.write(opc.getOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
271             logger.info("OP010工位,handleOrder PC处理完成!^--------------------------------------------");
272         }else{
273             logger.info("OP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
274         }
275     }
276
277
cf6bff 278     public void handleMaterial() {
e0fac3 279
cf6bff 280         //查询批次上料信息
C 281         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
282         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
283         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
284         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
285         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
286         for(int i=0;i<list1.size();i++){
287             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
288
289             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 290             if(remainingQuantity>0 ){
cf6bff 291                 //新增物料追溯
C 292                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
293                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
294                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
295                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
296                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
297                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
298                 materialTraceabilityParam.setAssemblyQty(1);
299                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
300                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
301                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
302
303                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
304                 materialTraceabilityService.add(materialTraceabilityParam);
305                 //更新剩余数量
306                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
307                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
308                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
309             }
310         }
311     }
312
71e81e 313     //PC完成
314     public void handleFinsh() {
315         logger.info("OP010工位,handleFinsh PC处理开始!");
316         if("".equals(S_ORDER_CODE)){
317             IN_TIME = DateTool.getLocalTimeForDate();
318             S_ORDER_CODE = OPCUnit.read(opc.getOP010_S_ORDER_CODE());//工单编号
319             S_PRODUCT_TYPE = OPCUnit.read(opc.getOP010_S_PRODUCT_CODE());//产品编号
320             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
321             S_SFC_CODE = OPCUnit.read(opc.getOP010_S_SFC_CODE());//总成编码
322         }
cf6bff 323
71e81e 324         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP010_S_PRODUCT_STATE_CODE());
cf6bff 325
C 326         //修改报工记录
327         if("false".equals(S_PRODUCT_STATE_CODE)){
328             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
329             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
330             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
331             ProductionOrderRecordsService productionOrderRecordsService = opc.productionOrderRecordsService;
332
333             List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
334             if(list.size()>0){
335                 ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
336                 productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
337                 productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
338                 productionOrderRecordsService.update(productionOrderRecordsParam);
339             }
340         }
341
342         //处理过站信息
71e81e 343         PassingStationCollectionParam param = new PassingStationCollectionParam();
344         param.setWorkOrderNo(S_ORDER_CODE);
345         param.setProductCode(S_PRODUCT_CODE);
346         param.setSfcCode(S_SFC_CODE);
347         param.setProductionLine(PRODUCTION_LINE);
348         param.setLocationCode(LOCATION_CODE);
349         param.setInboundTime(IN_TIME);
350         param.setOutboundTime(DateTool.getLocalTimeForDate());
351         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
352         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
353         passingStationCollectionService.add(param);
354         //上线数量加1    根据工单号,更新 ACTUAL_ONLINE_QTY +1
355        /* ProductionOrdeInfoParam orderParam = new ProductionOrdeInfoParam();
356         orderParam.setWorkOrderNo(S_ORDER_CODE);
357         orderParam.setActualOnlineQty(ACTUAL_ONLINE_QTY+1);
358         ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
359         productionOrdeInfoService.updateOrderOnlineQry(orderParam);*/
360         //写完成
361         OPCUnit.write(opc.getOP010_J_PC_FINISH(), "true"); //PC完成
362         logger.info("OP010工位,handleFinsh PC处理完成!-------------------------------");
363     }
364
365
366 }