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