cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.BOP040.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.BOP040.BOP040ServerInterface;
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 BOP040ServerInterfaceImpl implements BOP040ServerInterface {
32
33     private static Logger logger;
34     LogUtil logUtil = new LogUtil();
35     static {
36         logger = Logger.getLogger(BOP040ServerInterfaceImpl.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  = "BOP040";//工位号
49     private static String GROUP_NAME  = "BOP040_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.getBOP040_F_HEART_BEAT(), "true");
61             GlobalVariable.BOP040_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.BOP040_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.getBOP040_F_HEART_BEAT());
cf6bff 78             assert isHeartBeat != null;
e0fac3 79             setHeartbeat(isHeartBeat);*/
cf6bff 80
71e81e 81             if(GlobalVariable.BOP040_F_HEART_BEAT) {
82                 //PC读工单
83                 String isPLCStart = OPCUnit.read(opc.getBOP040_J_PLC_START());//PLC开始
84                 if(isPLCStart.equals("true")){
85                     String isFinish = OPCUnit.read(opc.getBOP040_J_PC_WRITE_ORDER());//PC下发工单完成
86                     if(isFinish.equals("false")){
87                         handleOrder();
88                     }
89                 }
90
91
92                 //PC完成
93                 String isPLCFinish = OPCUnit.read(opc.getBOP040_J_PLC_FINISH());//PLC完成
94                 if(isPLCFinish.equals("true")){
95                     String isFinish = OPCUnit.read(opc.getBOP040_J_PC_FINISH());//PC操作完成
96                     if(isFinish.equals("false")){
97                         handleFinsh();
e0fac3 98                         handleInfo();
C 99                         handleMaterial();
71e81e 100                     }
101                 }
102
103             }else{
104                 logger.info("BOP040工位与PLC断开,请检查PLC或网络是否异常!");
105             }
106
107         }catch (Exception e) {
108             ecpStr ="出现异常:" + logUtil.getTrace(e);
109         }finally {
110             if(!"".equals(ecpStr)){
111                 logger.info(ecpStr+"\r\n");
112             }
113         }
114     }
115
116     //PC读工单
117     public void handleOrder() {
118         IN_TIME = DateTool.getLocalTimeForDate();
119         S_ORDER_CODE = OPCUnit.read(opc.getBOP040_S_ORDER_CODE());//工单编号
120         S_PRODUCT_TYPE = OPCUnit.read(opc.getBOP040_S_PRODUCT_CODE());//产品编号
121         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
122         S_SFC_CODE = OPCUnit.read(opc.getBOP040_S_SFC_CODE());//总成编码
123         OPCUnit.write(opc.getBOP040_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
124         logger.info("BOP040工位,handleOrder PC处理完成!");
125     }
126
127     //PC读参数信息
128     public void handleInfo() throws Exception {
129         logger.info("BOP040工位,handleInfo START!");
130
131         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
132             if(group != null){
133                 opc.getServer().removeGroup(group,true);
134             }
135             group = opc.getServer().addGroup(GROUP_NAME);
136
137             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
138             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
139             collectionParamConfParam.setLocationCode(LOCATION_CODE);
140             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
141             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
142
143
144             for(int i=0;i<list.size();i++){
145                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
146                 Item item = group.addItem(result.getGatherAddress());
147                 result.setItem(item);
148                 list.set(i,result);
149             }
150             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
151         }
152
153         if(null != list && list.size()>0) {
154             ParamCollectionService paramCollectionService = opc.paramCollectionService;
155             for (int i = 0; i < list.size(); i++) {
156                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
157                 Item item = result.getItem();
158                 String value = OPCUnit.read(item);//读参数值
159                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
160                 paramCollectionParam.setParamCode(result.getParamCode());
161                 paramCollectionParam.setParamName(result.getParamName());
162                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
163                 paramCollectionParam.setSfcCode(S_SFC_CODE);
164                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
165                 paramCollectionParam.setProductionLine(result.getProductionLine());
166                 paramCollectionParam.setLocationCode(result.getLocationCode());
167                 paramCollectionParam.setParamValue(value);
168                 paramCollectionParam.setParamLower(result.getParamLower());
169                 paramCollectionParam.setParamUpper(result.getParamUpper());
170                 paramCollectionParam.setParamStandard(result.getParamCentral());
171                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
172                 paramCollectionParam.setUnit(result.getUnit());
173                 paramCollectionService.add(paramCollectionParam);
174             }
175         }
176
177         logger.info("BOP040工位,handleInfo END!");
178     }
cf6bff 179     public void handleMaterial() {
e0fac3 180
cf6bff 181         //查询批次上料信息
C 182         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
183         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
184         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
185         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
186         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
187         for(int i=0;i<list1.size();i++){
188             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
189
190
191             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 192             if(remainingQuantity>0 ){
cf6bff 193                 //新增物料追溯
C 194                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
195                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
196                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
197                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
198                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
199                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
200                 materialTraceabilityParam.setAssemblyQty(1);
201                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
202                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
203                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
204
205                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
206                 materialTraceabilityService.add(materialTraceabilityParam);
207                 //更新剩余数量
208                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
209                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
210                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
211             }
212         }
213     }
71e81e 214
215     //PC完成
216     public void handleFinsh() {
217         if("".equals(S_ORDER_CODE)){
218             IN_TIME = DateTool.getLocalTimeForDate();
219             S_ORDER_CODE = OPCUnit.read(opc.getBOP040_S_ORDER_CODE());//工单编号
220             S_PRODUCT_TYPE = OPCUnit.read(opc.getBOP040_S_PRODUCT_CODE());//产品编号
221             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
222             S_SFC_CODE = OPCUnit.read(opc.getBOP040_S_SFC_CODE());//总成编码
223         }
224         //处理过站信息
225         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getBOP040_S_PRODUCT_STATE_CODE());
226         PassingStationCollectionParam param = new PassingStationCollectionParam();
227         param.setWorkOrderNo(S_ORDER_CODE);
228         param.setProductCode(S_PRODUCT_CODE);
229         param.setSfcCode(S_SFC_CODE);
230         param.setProductionLine(PRODUCTION_LINE);
231         param.setLocationCode(LOCATION_CODE);
232         param.setInboundTime(IN_TIME);
233         param.setOutboundTime(DateTool.getLocalTimeForDate());
234         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
235         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
236         passingStationCollectionService.add(param);
237
238         OPCUnit.write(opc.getBOP040_J_PC_FINISH(), "true"); //PC完成
239
240         logger.info("BOP040工位,handleFinsh PC处理完成!");
241     }
242
243 }