cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.BOP020.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.cm.paramCollection.model.params.ParamCollectionParam;
8 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
9 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
10 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
cf6bff 11 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
C 12 import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
13 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
14 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
15 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
71e81e 16 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
17 import cn.stylefeng.guns.plcserver.opc.OPCComm;
18 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
19
20 import cn.stylefeng.guns.plcserver.server.BOP020.BOP020ServerInterface;
21 import cn.stylefeng.guns.plcserver.tool.DateTool;
22 import cn.stylefeng.guns.plcserver.tool.LogUtil;
23 import org.apache.log4j.Logger;
24 import org.openscada.opc.lib.da.Group;
25 import org.openscada.opc.lib.da.Item;
26
27 import java.util.Date;
28 import java.util.List;
29
30
31 public class BOP020ServerInterfaceImpl implements BOP020ServerInterface {
32
33     private static Logger logger;
34     LogUtil logUtil = new LogUtil();
35     static {
36         logger = Logger.getLogger(BOP020ServerInterfaceImpl.class);
37     }
38
39     private OPCComm opc = OPCComm.getInstance();
40     private static Date IN_TIME = null;
41     private static String S_ORDER_CODE = "";//工单编号
42     private static String S_PRODUCT_CODE = "";//产品编号
43     private static String S_PRODUCT_TYPE= "";//产品类型
44     private static String S_PRODUCT_CODE_OLD = "";//产品编号
45     private static String S_SFC_CODE = "";//总成编码
46     private static String S_RIGHT_CODE  = "";//右壳体编码
47     private static String PRODUCTION_LINE  = "BOP";//产线号
48     private static String LOCATION_CODE  = "BOP020";//工位号
49     private static String GROUP_NAME  = "BOP020_P";//组名
50     private static List list = null;
51     private static Group group = null;
cf6bff 52
C 53     private int count = 0;
54
55     /**
56      * 设置心跳标志位,保存到全局变量
57      */
58     public void setHeartbeat(String value) {
59         if (value.equals("false")) {
60             OPCUnit.write(opc.getBOP020_F_HEART_BEAT(), "true");
61             GlobalVariable.BOP020_F_HEART_BEAT = true;
62             count = 0;
63         } else {
64             count++;
65         }
66         // 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时
67         if (count > GlobalVariable.HEART_MAX_COUNT) {
68             GlobalVariable.BOP020_F_HEART_BEAT = false;
69         }
70     }
71
71e81e 72     @Override
73     public synchronized void monitor() {
74         String ecpStr = "";//异常记录标记
75         try{
cf6bff 76
e0fac3 77             /*String isHeartBeat = OPCUnit.read(opc.getBOP020_F_HEART_BEAT());
C 78             setHeartbeat(isHeartBeat);*/
cf6bff 79
71e81e 80             if(GlobalVariable.BOP020_F_HEART_BEAT) {
81                 //PC读工单
82                 String isPLCStart = OPCUnit.read(opc.getBOP020_J_PLC_START());//PLC开始
83                 if(isPLCStart.equals("true")){
84                     String isFinish = OPCUnit.read(opc.getBOP020_J_PC_WRITE_ORDER());//PC下发工单完成
85                     if(isFinish.equals("false")){
86                         handleOrder();
87                     }
88                 }
89
90
91                 //PC完成
92                 String isPLCFinish = OPCUnit.read(opc.getBOP020_J_PLC_FINISH());//PLC完成
93                 if(isPLCFinish.equals("true")){
94                     String isFinish = OPCUnit.read(opc.getBOP020_J_PC_FINISH());//PC操作完成
95                     if(isFinish.equals("false")){
96                         handleFinsh();
e0fac3 97                         handleInfo();
C 98                         handleMaterial();
99
100
71e81e 101                     }
102                 }
103
104             }else{
105                 logger.info("BOP020工位与PLC断开,请检查PLC或网络是否异常!");
106             }
107
108         }catch (Exception e) {
109             ecpStr ="出现异常:" + logUtil.getTrace(e);
110         }finally {
111             if(!"".equals(ecpStr)){
112                 logger.info(ecpStr+"\r\n");
113             }
114         }
115     }
116
117     //PC读工单
118     public void handleOrder() {
119         IN_TIME = DateTool.getLocalTimeForDate();
120         S_ORDER_CODE = OPCUnit.read(opc.getBOP020_S_ORDER_CODE());//工单编号
121         S_PRODUCT_TYPE = OPCUnit.read(opc.getBOP020_S_PRODUCT_CODE());//产品编号
122         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
123         S_SFC_CODE = OPCUnit.read(opc.getBOP020_S_SFC_CODE());//总成编码
124         OPCUnit.write(opc.getBOP020_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
125         logger.info("BOP020工位,handleOrder PC处理完成!");
126     }
127
128     //PC读参数信息
129     public void handleInfo() throws Exception {
130         logger.info("BOP020工位,handleInfo START!");
131
132         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
133             if(group != null){
134                 opc.getServer().removeGroup(group,true);
135             }
136             group = opc.getServer().addGroup(GROUP_NAME);
137
138             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
139             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
140             collectionParamConfParam.setLocationCode(LOCATION_CODE);
141             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
142             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
143
144
145             for(int i=0;i<list.size();i++){
146                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
147                 Item item = group.addItem(result.getGatherAddress());
148                 result.setItem(item);
149                 list.set(i,result);
150             }
151             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
152         }
153
154         if(null != list && list.size()>0) {
155             ParamCollectionService paramCollectionService = opc.paramCollectionService;
156             for (int i = 0; i < list.size(); i++) {
157                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
158                 Item item = result.getItem();
159                 String value = OPCUnit.read(item);//读参数值
160                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
161                 paramCollectionParam.setParamCode(result.getParamCode());
162                 paramCollectionParam.setParamName(result.getParamName());
163                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
164                 paramCollectionParam.setSfcCode(S_SFC_CODE);
165                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
166                 paramCollectionParam.setProductionLine(result.getProductionLine());
167                 paramCollectionParam.setLocationCode(result.getLocationCode());
168                 paramCollectionParam.setParamValue(value);
169                 paramCollectionParam.setParamLower(result.getParamLower());
170                 paramCollectionParam.setParamUpper(result.getParamUpper());
171                 paramCollectionParam.setParamStandard(result.getParamCentral());
172                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
173                 paramCollectionParam.setUnit(result.getUnit());
174                 paramCollectionService.add(paramCollectionParam);
175             }
176         }
177
178         logger.info("BOP020工位,handleInfo END!");
179     }
cf6bff 180     public void handleMaterial() {
e0fac3 181
cf6bff 182         //查询批次上料信息
C 183         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
184         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
185         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
186         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
187         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
188         for(int i=0;i<list1.size();i++){
189             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
190
191
192             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 193             if(remainingQuantity>0 ){
cf6bff 194                 //新增物料追溯
C 195                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
196                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
197                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
198                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
199                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
200                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
201                 materialTraceabilityParam.setAssemblyQty(1);
202                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
203                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
204                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
205
206                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
207                 materialTraceabilityService.add(materialTraceabilityParam);
208                 //更新剩余数量
209                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
210                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
211                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
212             }
213         }
214     }
71e81e 215
216     //PC完成
217     public void handleFinsh() {
218         if("".equals(S_ORDER_CODE)){
219             IN_TIME = DateTool.getLocalTimeForDate();
220             S_ORDER_CODE = OPCUnit.read(opc.getBOP020_S_ORDER_CODE());//工单编号
221             S_PRODUCT_TYPE = OPCUnit.read(opc.getBOP020_S_PRODUCT_CODE());//产品编号
222             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
223             S_SFC_CODE = OPCUnit.read(opc.getBOP020_S_SFC_CODE());//总成编码
224         }
225         //处理过站信息
226         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getBOP020_S_PRODUCT_STATE_CODE());
227         PassingStationCollectionParam param = new PassingStationCollectionParam();
228         param.setWorkOrderNo(S_ORDER_CODE);
229         param.setProductCode(S_PRODUCT_CODE);
230         param.setSfcCode(S_SFC_CODE);
231         param.setProductionLine(PRODUCTION_LINE);
232         param.setLocationCode(LOCATION_CODE);
233         param.setInboundTime(IN_TIME);
234         param.setOutboundTime(DateTool.getLocalTimeForDate());
235         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
236         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
237         passingStationCollectionService.add(param);
238
239         OPCUnit.write(opc.getBOP020_J_PC_FINISH(), "true"); //PC完成
240
241         logger.info("BOP020工位,handleFinsh PC处理完成!");
242     }
243
244 }