懒羊羊
2023-11-14 1f34866e4697920d4d9d2c59830b450136393d54
提交 | 用户 | 时间
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;
15 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
16 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
17 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
18 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
19 import cn.stylefeng.guns.plcserver.opc.OPCComm;
20 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
21 import cn.stylefeng.guns.plcserver.server.COP010.COP010ServerInterface;
22 import cn.stylefeng.guns.plcserver.server.DOP010.DOP010ServerInterface;
23 import cn.stylefeng.guns.plcserver.tool.DateTool;
24 import cn.stylefeng.guns.plcserver.tool.LogUtil;
25 import org.apache.log4j.Logger;
26 import org.openscada.opc.lib.da.Group;
27
28 import java.util.Date;
29 import java.util.List;
30 import java.util.Random;
31
32
33 public class DOP010ServerInterfaceImpl implements DOP010ServerInterface {
34
35     private static Logger logger;
36     LogUtil logUtil = new LogUtil();
37     static {
38         logger = Logger.getLogger(DOP010ServerInterfaceImpl.class);
39     }
40
41     private OPCComm opc = OPCComm.getInstance();
42     private static Date IN_TIME = null;
43     private static String S_ORDER_CODE = "";//工单编号
44     private static String S_PRODUCT_CODE = "";//产品编号
45     private static String S_PRODUCT_TYPE= "";//产品类型
46     private static String S_PRODUCT_CODE_OLD = "";//产品编号
47     private static String S_SFC_CODE = "";//总成编码
48     private static String S_RIGHT_CODE  = "";//右壳体编码
49     private static String PRODUCTION_LINE  = "EOP";//产线号
50     private static String LOCATION_CODE  = "DOP010";//工位号
51     private static String GROUP_NAME  = "DOP010_P";//工位号
52     private static List list = null;
53     private static Group group = null;
54
55
56
57
58     @Override
59     public void monitor() {
60         String ecpStr = "";//异常记录标记
61         try{
62
63             if(GlobalVariable.DOP010_F_HEART_BEAT) {
64
65                 //PC读工单
66                 String isPLCStart = OPCUnit.read(opc.getDOP010_J_PLC_START());//PLC开始
67                 if(isPLCStart.equals("true")){
68                     String isFinish = OPCUnit.read(opc.getDOP010_J_PC_WRITE_ORDER());//PC下发工单完成
69
70                     if(isFinish.equals("false")){
71                         String isRepair = OPCUnit.read(opc.getDOP010_P_REPAIR());//是否返修
72                         if(isRepair.equals("true")){
73                             handleRepair();
74                         }else{
75                             handleOrder();
76                         }
77                     }
78                 }
79
80
81                 //PC完成
82                 String isPLCFinish = OPCUnit.read(opc.getDOP010_J_PLC_FINISH());//PLC完成
83                 if(isPLCFinish.equals("true")){
84                     String isFinish = OPCUnit.read(opc.getDOP010_J_PC_FINISH());//PC操作完成
85                     if(isFinish.equals("false")){
86                         handleFinsh();
87                     }
88                 }
89
90             }else{
91                 logger.info("DOP010工位与PLC断开,请检查PLC或网络是否异常!");
92             }
93
94         }catch (Exception e) {
95             ecpStr ="出现异常:" + logUtil.getTrace(e);
96         }finally {
97             if(!"".equals(ecpStr)){
98                 logger.info(ecpStr+"\r\n");
99             }
100         }
101     }
102
103     public void handleRepair() {
104         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
105         repairManageInfoParam.setLocationCode(LOCATION_CODE);
106         repairManageInfoParam.setManageType("2");
107         repairManageInfoParam.setUpPlc("0");
108         RepairManageInfoService repairManageInfoService = opc.repairManageInfoService;
109         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
110         if(list.size()>0) {
111             RepairManageInfoResult result = list.get(0);
112
113             S_SFC_CODE = result.getSfc();
114
115             //查询sfc编码
116             MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
117             materialTraceabilityParam.setMaterialCode(result.getSfc());
118             MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
119             List<MaterialTraceabilityResult> materialTraceabilityResults = materialTraceabilityService.findListBySpec(materialTraceabilityParam);
120             if(materialTraceabilityResults.size()>0){
121                 MaterialTraceabilityResult materialTraceabilityResult = materialTraceabilityResults.get(0);
122                 S_SFC_CODE = materialTraceabilityResult.getProductNo();
123             }
124
125             S_ORDER_CODE = result.getWorkOrderNo();
126             S_PRODUCT_CODE = result.getProductCode();
127             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
128             String  repairLocation = result.getPoorLocationCode();//
129
130             //根据工位编码查询工位表中配置的返修工位号
131             LocationInfoParam param = new LocationInfoParam();
132             param.setLocationCode(repairLocation);
133             LocationInfoService locationInfoService = opc.locationInfoService;
134             List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
135             if(results.size()>0) {
136                 LocationInfoResult r = results.get(0);
137                 String repairLocationNo = r.getSpareField2();
138                 if(null != repairLocationNo && "" != repairLocationNo){
139                     OPCUnit.write(opc.getDOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
140                     OPCUnit.write(opc.getDOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
141                     OPCUnit.write(opc.getDOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
142                     OPCUnit.write(opc.getDOP010_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号
143                     OPCUnit.write(opc.getDOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
144
145                     //更新为已经返修上线
146                     Long id = result.getId();
147                     repairManageInfoParam.setId(id);
148                     repairManageInfoParam.setUpPlc("1");
149                     repairManageInfoService.update(repairManageInfoParam);
150
151                 }else{
152                     logger.info("DOP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
153                 }
154             }else{
155                 logger.info("DOP010工位,handleRepair 无法查询到"+repairLocation+"工位!");
156             }
157         }
158     }
159
160     //PC下发工单
161     public void handleOrder() {
162         IN_TIME = DateTool.getLocalTimeForDate();
163         ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
164         param.setProductionLine("");//产线
165         param.setOrderStatus("3");//工单状态
166
167         ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
168         List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
169
170         if(list.size()>0) {
171             ProductionOrdeInfoResult result = list.get(0);
172
173             S_ORDER_CODE = result.getWorkOrderNo();
174             S_PRODUCT_CODE = result.getMaterialCode();
175
176             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
177
178             //ACTUAL_ONLINE_QTY = result.getActualOnlineQty();
179             //S_SFC_CODE = qrCode.unitNoRetrospect();
180             //S_RIGHT_CODE = qrCode.SerialNumbers;
181
182             //自动生成唯一码
183             Random random = new Random(System.currentTimeMillis());
184             S_SFC_CODE = "EOP"+ random.nextLong();
185
186
187             OPCUnit.write(opc.getDOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
188             OPCUnit.write(opc.getDOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品类型
189             OPCUnit.write(opc.getDOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
190            // OPCUnit.write(opc.getDOP010_S_RIGHT_CODE(), S_RIGHT_CODE); //右壳体编码
191             OPCUnit.write(opc.getDOP010_S_NUMBER(), result.getPlanQty().toString()); //计划数量
192             OPCUnit.write(opc.getDOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
193             logger.info("DOP010工位,handleOrder PC处理完成!");
194         }else{
195             logger.info("DOP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
196         }
197     }
198
199
200
201     //PC完成
202     public void handleFinsh() {
203
204         if("".equals(S_ORDER_CODE)){
205             IN_TIME = DateTool.getLocalTimeForDate();
206             S_ORDER_CODE = OPCUnit.read(opc.getDOP010_S_ORDER_CODE());//工单编号
207             S_PRODUCT_TYPE = OPCUnit.read(opc.getDOP010_S_PRODUCT_CODE());//产品编号
208             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
209             S_SFC_CODE = OPCUnit.read(opc.getDOP010_S_SFC_CODE());//总成编码
210         }
211
212         //处理过站信息
213         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getDOP010_S_PRODUCT_STATE_CODE());
214         PassingStationCollectionParam param = new PassingStationCollectionParam();
215         param.setWorkOrderNo(S_ORDER_CODE);
216         param.setProductCode(S_PRODUCT_CODE);
217         param.setSfcCode(S_SFC_CODE);
218         param.setProductionLine(PRODUCTION_LINE);
219         param.setLocationCode(LOCATION_CODE);
220         param.setInboundTime(IN_TIME);
221         param.setOutboundTime(DateTool.getLocalTimeForDate());
222         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
223         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
224         passingStationCollectionService.add(param);
225
226         //上线数量加1    根据工单号,更新 ACTUAL_ONLINE_QTY +1
227        /* ProductionOrdeInfoParam orderParam = new ProductionOrdeInfoParam();
228         orderParam.setWorkOrderNo(S_ORDER_CODE);
229         orderParam.setActualOnlineQty(ACTUAL_ONLINE_QTY+1);
230         ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
231         productionOrdeInfoService.updateOrderOnlineQry(orderParam);*/
232
233         //写完成
234         OPCUnit.write(opc.getDOP010_J_PC_FINISH(), "true"); //PC完成
235
236         logger.info("DOP010工位,handleFinsh PC处理完成!");
237     }
238
239
240 }