cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.BOP010.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.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam;
22 import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult;
23 import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
24 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
25 import cn.stylefeng.guns.plcserver.opc.OPCComm;
26 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
27 import cn.stylefeng.guns.plcserver.opc.unit.qrCode;
28 import cn.stylefeng.guns.plcserver.server.BOP010.BOP010ServerInterface;
29 import cn.stylefeng.guns.plcserver.tool.DateTool;
30 import cn.stylefeng.guns.plcserver.tool.LogUtil;
31 import org.apache.commons.lang3.StringUtils;
32 import org.apache.log4j.Logger;
33 import org.openscada.opc.lib.da.Group;
34
35 import java.util.Date;
36 import java.util.List;
37 import java.util.Random;
38
39
40 public class BOP010ServerInterfaceImpl implements BOP010ServerInterface {
41
42     private static Logger logger;
43     LogUtil logUtil = new LogUtil();
44     static {
45         logger = Logger.getLogger(BOP010ServerInterfaceImpl.class);
46     }
47
48     private OPCComm opc = OPCComm.getInstance();
49     private static Date IN_TIME = null;
50     private static String S_ORDER_CODE = "";//工单编号
51     private static String S_PRODUCT_CODE = "";//产品编号
52     private static String S_PRODUCT_TYPE= "";//产品类型
53     private static String S_PRODUCT_CODE_OLD = "";//产品编号
54     private static String S_SFC_CODE = "";//总成编码
55     private static String S_RIGHT_CODE  = "";//右壳体编码
56     private static String PRODUCTION_LINE  = "BOP";//产线号
57     private static String LOCATION_CODE  = "BOP010";//工位号
58     private static String GROUP_NAME  = "BOP010_P";//工位号
59     private static List list = null;
60     private static Group group = null;
61
cf6bff 62     private int count = 0;
71e81e 63
cf6bff 64     /**
C 65      * 设置心跳标志位,保存到全局变量
66      */
67     public void setHeartbeat(String value) {
68         if (value.equals("false")) {
69             OPCUnit.write(opc.getBOP010_F_HEART_BEAT(), "true");
70             GlobalVariable.BOP010_F_HEART_BEAT = true;
71             count = 0;
72         } else {
73             count++;
74         }
75         // 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时
76         if (count > GlobalVariable.HEART_MAX_COUNT) {
77             GlobalVariable.BOP010_F_HEART_BEAT = false;
78         }
79     }
71e81e 80
81     @Override
cf6bff 82     public synchronized void monitor() {
71e81e 83         String ecpStr = "";//异常记录标记
84         try{
cf6bff 85
e0fac3 86             /*String isHeartBeat = OPCUnit.read(opc.getBOP010_F_HEART_BEAT());
C 87             setHeartbeat(isHeartBeat);*/
71e81e 88
89             if(GlobalVariable.BOP010_F_HEART_BEAT) {
90
91                 //PC读工单
92                 String isPLCStart = OPCUnit.read(opc.getBOP010_J_PLC_START());//PLC开始
93                 if(isPLCStart.equals("true")){
94
95                     String isFinish = OPCUnit.read(opc.getBOP010_J_PC_WRITE_ORDER());//PC下发工单完成
96
97                     if(isFinish.equals("false")){
98                         String isRepair = OPCUnit.read(opc.getBOP010_P_REPAIR());//是否返修
99                         if(isRepair.equals("true")){
100                             handleRepair();
101                         }else{
102                             handleOrder();
103                         }
104                     }
105                 }
106
107
108                 //PC完成
109                 String isPLCFinish = OPCUnit.read(opc.getBOP010_J_PLC_FINISH());//PLC完成
110                 if(isPLCFinish.equals("true")){
111                     String isFinish = OPCUnit.read(opc.getBOP010_J_PC_FINISH());//PC操作完成
112                     if(isFinish.equals("false")){
113                         handleFinsh();
e0fac3 114                         handleMaterial();
71e81e 115                     }
116                 }
117
118
119             }else{
120                 logger.info("BOP010工位与PLC断开,请检查PLC或网络是否异常!");
121             }
122
123         }catch (Exception e) {
124             ecpStr ="出现异常:" + logUtil.getTrace(e);
125         }finally {
126             if(!"".equals(ecpStr)){
127                 logger.info(ecpStr+"\r\n");
128             }
129         }
130     }
131
132     public void handleRepair() {
133         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
134         repairManageInfoParam.setLocationCode(LOCATION_CODE);
135         repairManageInfoParam.setManageType("2");
136         repairManageInfoParam.setUpPlc("0");
137         RepairManageInfoService repairManageInfoService = opc.repairManageInfoService;
138         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
139         if(list.size()>0) {
140             RepairManageInfoResult result = list.get(0);
141
142             //自动生成唯一码
143             Random random = new Random(System.currentTimeMillis());
144             S_SFC_CODE = "BOP" + random.nextLong();
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.getBOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
162                     OPCUnit.write(opc.getBOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
163                     OPCUnit.write(opc.getBOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
164                     OPCUnit.write(opc.getBOP010_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号
165                     OPCUnit.write(opc.getBOP010_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("BOP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
175                 }
176             }else{
177                 logger.info("BOP010工位,handleRepair 无法查询到"+repairLocation+"工位!");
178             }
179         }
180     }
181     //PC下发工单
182     public void handleOrder() {
183
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             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
198
199             //自动生成唯一码
200             Random random = new Random(System.currentTimeMillis());
201             S_SFC_CODE = "BOP" + random.nextLong();
202
203
204             OPCUnit.write(opc.getBOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
205             OPCUnit.write(opc.getBOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品类型
206             OPCUnit.write(opc.getBOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
207             // OPCUnit.write(opc.getBOP010_S_RIGHT_CODE(), S_RIGHT_CODE); //右壳体编码
208             OPCUnit.write(opc.getBOP010_S_NUMBER(), result.getPlanQty().toString()); //计划数量
209
210             OPCUnit.write(opc.getBOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
211             logger.info("BOP010工位,handleOrder PC处理完成!2");
212         }else{
213             logger.info("BOP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
214         }
215     }
216
cf6bff 217     public void handleMaterial() {
e0fac3 218
cf6bff 219         //查询批次上料信息
C 220         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
221         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
222         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
223         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
224         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
225         for(int i=0;i<list1.size();i++){
226             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
227
e0fac3 228
cf6bff 229
C 230             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 231             if(remainingQuantity>0 ){
cf6bff 232                 //新增物料追溯
C 233                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
234                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
235                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
236                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
237                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
238                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
239                 materialTraceabilityParam.setAssemblyQty(1);
240                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
241                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
242                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
243
244                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
245                 materialTraceabilityService.add(materialTraceabilityParam);
246                 //更新剩余数量
247                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
248                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
249                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
250             }
251         }
252     }
71e81e 253
254     //PC完成
255     public void handleFinsh() {
256
257         if("".equals(S_ORDER_CODE)){
258             IN_TIME = DateTool.getLocalTimeForDate();
259             S_ORDER_CODE = OPCUnit.read(opc.getBOP010_S_ORDER_CODE());//工单编号
260             S_PRODUCT_TYPE = OPCUnit.read(opc.getBOP010_S_PRODUCT_CODE());//产品编号
261             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
262             S_SFC_CODE = OPCUnit.read(opc.getBOP010_S_SFC_CODE());//总成编码
263         }
264
265         //处理过站信息
266         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getBOP010_S_PRODUCT_STATE_CODE());
267         PassingStationCollectionParam param = new PassingStationCollectionParam();
268         param.setWorkOrderNo(S_ORDER_CODE);
269         param.setProductCode(S_PRODUCT_CODE);
270         param.setSfcCode(S_SFC_CODE);
271         param.setProductionLine(PRODUCTION_LINE);
272         param.setLocationCode(LOCATION_CODE);
273         param.setInboundTime(IN_TIME);
274         param.setOutboundTime(DateTool.getLocalTimeForDate());
275         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
276         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
277         passingStationCollectionService.add(param);
278
279         //写完成
280         OPCUnit.write(opc.getBOP010_J_PC_FINISH(), "true"); //PC完成
281
282         logger.info("BOP010工位,handleFinsh PC处理完成!");
283     }
284
285
286 }