cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.EOP060.impl;
2
3
4 import cn.stylefeng.guns.modular.bs.collectionParamConf.model.params.CollectionParamConfParam;
5 import cn.stylefeng.guns.modular.bs.collectionParamConf.model.result.CollectionParamConfResult;
6 import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService;
7 import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam;
8 import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
9 import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
10 import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
11 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
12 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
13 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
14 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
15 import cn.stylefeng.guns.modular.dq.materialTraceability.model.result.MaterialTraceabilityResult;
16 import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
cf6bff 17 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
C 18 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
19 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
71e81e 20 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
21 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
22 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
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
27 import cn.stylefeng.guns.plcserver.server.EOP060.EOP060ServerInterface;
28 import cn.stylefeng.guns.plcserver.tool.DateTool;
29 import cn.stylefeng.guns.plcserver.tool.LogUtil;
30 import org.apache.log4j.Logger;
31 import org.openscada.opc.lib.da.Group;
32 import org.openscada.opc.lib.da.Item;
33
34 import java.util.Date;
35 import java.util.List;
36
37
38 public class EOP060ServerInterfaceImpl implements EOP060ServerInterface {
39
40     private static Logger logger;
41     LogUtil logUtil = new LogUtil();
42     static {
43         logger = Logger.getLogger(EOP060ServerInterfaceImpl.class);
44     }
45
46     private OPCComm opc = OPCComm.getInstance();
47     private static Date IN_TIME = null;
48     private static String S_ORDER_CODE = "";//工单编号
49     private static String S_PRODUCT_CODE = "";//产品编号
50     private static String S_PRODUCT_TYPE= "";//产品类型
51     private static String S_PRODUCT_CODE_OLD = "";//产品编号
52     private static String S_SFC_CODE = "";//总成编码
53     private static String S_RIGHT_CODE  = "";//右壳体编码
54     private static String PRODUCTION_LINE  = "EOP";//产线号
55     private static String LOCATION_CODE  = "EOP060";//工位号
56     private static String GROUP_NAME  = "EOP060_P";//组名
57     private static List list = null;
58     private static Group group = null;
cf6bff 59
C 60     private int count = 0;
61
62     /**
63      * 设置心跳标志位,保存到全局变量
64      */
65     public void setHeartbeat(String value) {
66         if ("false".equals(value)) {
67             OPCUnit.write(opc.getEOP060_F_HEART_BEAT(), "true");
68             GlobalVariable.EOP060_F_HEART_BEAT = true;
69             count = 0;
70         } else {
71             count++;
72         }
73         // 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时
74         if (count > GlobalVariable.HEART_MAX_COUNT) {
75             GlobalVariable.EOP060_F_HEART_BEAT = false;
76         }
77     }
78
71e81e 79     @Override
80     public synchronized void monitor() {
81         String ecpStr = "";//异常记录标记
82         try{
e0fac3 83           /*  String isHeartBeat = OPCUnit.read(opc.getEOP060_F_HEART_BEAT());
C 84             setHeartbeat(isHeartBeat);*/
cf6bff 85
71e81e 86             if(GlobalVariable.EOP060_F_HEART_BEAT) {
87                 //PC读工单
88                 String isPLCStart = OPCUnit.read(opc.getEOP060_J_PLC_START());//PLC开始
89                 if(isPLCStart.equals("true")){
90                     String isFinish = OPCUnit.read(opc.getEOP060_J_PC_WRITE_ORDER());//PC下发工单完成
91
92                     if(isFinish.equals("false")){
93                         String isRepair = OPCUnit.read(opc.getEOP060_P_REPAIR());//是否返修
94                         if(isRepair.equals("true")){
95                             handleRepair();
96                         }else{
97                             handleOrder();
98                         }
99                     }
100                 }
101
102
103                 //PC完成
104                 String isPLCFinish = OPCUnit.read(opc.getEOP060_J_PLC_FINISH());//PLC完成
105                 if(isPLCFinish.equals("true")){
106                     String isFinish = OPCUnit.read(opc.getEOP060_J_PC_FINISH());//PC操作完成
107                     if(isFinish.equals("false")){
108                         handleFinsh();
e0fac3 109                         handleInfo();
C 110                         handleMaterial();
71e81e 111                     }
112                 }
113
114             }else{
115                 logger.info("EOP060工位与PLC断开,请检查PLC或网络是否异常!");
116             }
117
118         }catch (Exception e) {
119             ecpStr ="出现异常:" + logUtil.getTrace(e);
120         }finally {
121             if(!"".equals(ecpStr)){
122                 logger.info(ecpStr+"\r\n");
123             }
124         }
125     }
126
127     public void handleRepair() {
128         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
129         repairManageInfoParam.setLocationCode(LOCATION_CODE);
130         repairManageInfoParam.setManageType("2");
131         repairManageInfoParam.setUpPlc("0");
132         RepairManageInfoService repairManageInfoService = opc.repairManageInfoService;
133         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
134         if(list.size()>0) {
135             RepairManageInfoResult result = list.get(0);
136
137             S_SFC_CODE = result.getSfc();
138
139             //查询sfc编码
140             MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
141             materialTraceabilityParam.setMaterialCode(result.getSfc());
142             MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
143             List<MaterialTraceabilityResult> materialTraceabilityResults = materialTraceabilityService.findListBySpec(materialTraceabilityParam);
144             if(materialTraceabilityResults.size()>0){
145                 MaterialTraceabilityResult materialTraceabilityResult = materialTraceabilityResults.get(0);
146                 S_SFC_CODE = materialTraceabilityResult.getProductNo();
147             }
148
149             S_ORDER_CODE = result.getWorkOrderNo();
150             S_PRODUCT_CODE = result.getProductCode();
151             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
152             String  repairLocation = result.getPoorLocationCode();//
153
154             //根据工位编码查询工位表中配置的返修工位号
155             LocationInfoParam param = new LocationInfoParam();
156             param.setLocationCode(repairLocation);
157             LocationInfoService locationInfoService = opc.locationInfoService;
158             List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
159             if(results.size()>0) {
160                 LocationInfoResult r = results.get(0);
161                 String repairLocationNo = r.getSpareField2();
162                 if(null != repairLocationNo && "" != repairLocationNo){
163                     OPCUnit.write(opc.getEOP060_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
164                     OPCUnit.write(opc.getEOP060_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
165                     OPCUnit.write(opc.getEOP060_S_SFC_CODE(), S_SFC_CODE); //总成编码
166                     OPCUnit.write(opc.getEOP060_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号
167                     OPCUnit.write(opc.getEOP060_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
168
169                     //更新为已经返修上线
170                     Long id = result.getId();
171                     repairManageInfoParam.setId(id);
172                     repairManageInfoParam.setUpPlc("1");
173                     repairManageInfoService.update(repairManageInfoParam);
174
175                 }else{
176                     logger.info("EOP060工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
177                 }
178             }else{
179                 logger.info("EOP060工位,handleRepair 无法查询到"+repairLocation+"工位!");
180             }
181         }
182     }
183
184     //PC读工单
185     public void handleOrder() {
186         IN_TIME = DateTool.getLocalTimeForDate();
187         S_ORDER_CODE = OPCUnit.read(opc.getEOP060_S_ORDER_CODE());//工单编号
188         S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP060_S_PRODUCT_CODE());//产品编号
189         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
190         S_SFC_CODE = OPCUnit.read(opc.getEOP060_S_SFC_CODE());//总成编码
191         OPCUnit.write(opc.getEOP060_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
192         logger.info("EOP060工位,handleOrder PC处理完成!");
193     }
194
195     //PC读参数信息
196     public void handleInfo() throws Exception {
197         logger.info("EOP060工位,handleInfo START!");
198
199         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
200             if(group != null){
201                 opc.getServer().removeGroup(group,true);
202             }
203             group = opc.getServer().addGroup(GROUP_NAME);
204
205             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
206             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
207             collectionParamConfParam.setLocationCode(LOCATION_CODE);
208             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
209             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
210
211
212             for(int i=0;i<list.size();i++){
213                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
214                 Item item = group.addItem(result.getGatherAddress());
215                 result.setItem(item);
216                 list.set(i,result);
217             }
218             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
219         }
220
221         if(null != list && list.size()>0) {
222             ParamCollectionService paramCollectionService = opc.paramCollectionService;
223             for (int i = 0; i < list.size(); i++) {
224                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
225                 Item item = result.getItem();
226                 String value = OPCUnit.read(item);//读参数值
227                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
228                 paramCollectionParam.setParamCode(result.getParamCode());
229                 paramCollectionParam.setParamName(result.getParamName());
230                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
231                 paramCollectionParam.setSfcCode(S_SFC_CODE);
232                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
233                 paramCollectionParam.setProductionLine(result.getProductionLine());
234                 paramCollectionParam.setLocationCode(result.getLocationCode());
235                 paramCollectionParam.setParamValue(value);
236                 paramCollectionParam.setParamLower(result.getParamLower());
237                 paramCollectionParam.setParamUpper(result.getParamUpper());
238                 paramCollectionParam.setParamStandard(result.getParamCentral());
239                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
240                 paramCollectionParam.setUnit(result.getUnit());
241                 paramCollectionService.add(paramCollectionParam);
242             }
243         }
244
245         logger.info("EOP060工位,handleInfo END!");
246     }
247
cf6bff 248     public void handleMaterial() {
e0fac3 249
cf6bff 250         //查询批次上料信息
C 251         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
252         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
253         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
254         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
255         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
256         for(int i=0;i<list1.size();i++){
257             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
258
259             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 260             if(remainingQuantity>0){
cf6bff 261                 //新增物料追溯
C 262                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
263                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
264                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
265                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
266                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
267                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
268                 materialTraceabilityParam.setAssemblyQty(1);
269                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
270                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
271                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
272
273                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
274                 materialTraceabilityService.add(materialTraceabilityParam);
275                 //更新剩余数量
276                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
277                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
278                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
279             }
280         }
281     }
282
283
71e81e 284     //PC完成
285     public void handleFinsh() {
286         if("".equals(S_ORDER_CODE)){
287             IN_TIME = DateTool.getLocalTimeForDate();
288             S_ORDER_CODE = OPCUnit.read(opc.getEOP060_S_ORDER_CODE());//工单编号
289             S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP060_S_PRODUCT_CODE());//产品编号
290             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
291             S_SFC_CODE = OPCUnit.read(opc.getEOP060_S_SFC_CODE());//总成编码
292         }
293         //处理过站信息
294         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getEOP060_S_PRODUCT_STATE_CODE());
295         PassingStationCollectionParam param = new PassingStationCollectionParam();
296         param.setWorkOrderNo(S_ORDER_CODE);
297         param.setProductCode(S_PRODUCT_CODE);
298         param.setSfcCode(S_SFC_CODE);
299         param.setProductionLine(PRODUCTION_LINE);
300         param.setLocationCode(LOCATION_CODE);
301         param.setInboundTime(IN_TIME);
302         param.setOutboundTime(DateTool.getLocalTimeForDate());
303         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
304         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
305         passingStationCollectionService.add(param);
306
307         OPCUnit.write(opc.getEOP060_J_PC_FINISH(), "true"); //PC完成
308
309         logger.info("EOP060工位,handleFinsh PC处理完成!");
310     }
311
312 }