long
2023-09-08 85b11cfb0f3ffc8a2fbdc2f6fbd26770b1346913
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.OP090.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.service.MaterialTraceabilityService;
12 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
13 import cn.stylefeng.guns.plcserver.opc.OPCComm;
14 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
15
16 import cn.stylefeng.guns.plcserver.server.OP090.OP090ServerInterface;
17 import cn.stylefeng.guns.plcserver.tool.DateTool;
18 import cn.stylefeng.guns.plcserver.tool.LogUtil;
19 import org.apache.log4j.Logger;
20 import org.openscada.opc.lib.da.Group;
21 import org.openscada.opc.lib.da.Item;
22
23 import java.util.Date;
24 import java.util.List;
25
26
27 public class OP090ServerInterfaceImpl implements OP090ServerInterface {
28
29     private static Logger logger;
30     LogUtil logUtil = new LogUtil();
31     static {
32         logger = Logger.getLogger(OP090ServerInterfaceImpl.class);
33     }
34
35     private OPCComm opc = OPCComm.getInstance();
36     private static Date IN_TIME = null;
37     private static String S_ORDER_CODE = "";//工单编号
38     private static String S_PRODUCT_CODE = "";//产品编号
39     private static String S_PRODUCT_TYPE= "";//产品类型
40     private static String S_PRODUCT_CODE_OLD = "";//产品编号
41     private static String S_SFC_CODE = "";//总成编码
42     private static String S_RIGHT_CODE  = "";//右壳体编码
43     private static String PRODUCTION_LINE  = "OP";//产线号
44     private static String LOCATION_CODE  = "OP090";//工位号
45     private static String GROUP_NAME  = "OP090_P";//组名
46     private static List list = null;
47     private static Group group = null;
48     @Override
49     public synchronized void monitor() {
50         String ecpStr = "";//异常记录标记
51         try{
52             if(GlobalVariable.OP090_F_HEART_BEAT) {
53                 //PC读工单
54                 String isPLCStart = OPCUnit.read(opc.getOP090_J_PLC_START());//PLC开始
55                 if(isPLCStart.equals("true")){
56                     String isFinish = OPCUnit.read(opc.getOP090_J_PC_WRITE_ORDER());//PC下发工单完成
57                     if(isFinish.equals("false")){
58                         handleOrder();
59                     }
60                 }
61
62
63                 //PC完成
64                 String isPLCFinish = OPCUnit.read(opc.getOP090_J_PLC_FINISH());//PLC完成
65                 if(isPLCFinish.equals("true")){
66                     String isFinish = OPCUnit.read(opc.getOP090_J_PC_FINISH());//PC操作完成
67                     if(isFinish.equals("false")){
68                         handleInfo();
69                         handleFinsh();
70                     }
71                 }
72
73             }else{
74                 logger.info("OP090工位与PLC断开,请检查PLC或网络是否异常!");
75             }
76
77         }catch (Exception e) {
78             ecpStr ="出现异常:" + logUtil.getTrace(e);
79         }finally {
80             if(!"".equals(ecpStr)){
81                 logger.info(ecpStr+"\r\n");
82             }
83         }
84     }
85
86     //PC读工单
87     public void handleOrder() {
88         IN_TIME = DateTool.getLocalTimeForDate();
89         S_ORDER_CODE = OPCUnit.read(opc.getOP090_S_ORDER_CODE());//工单编号
90         S_PRODUCT_TYPE = OPCUnit.read(opc.getOP090_S_PRODUCT_CODE());//产品编号
91         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
92         S_SFC_CODE = OPCUnit.read(opc.getOP090_S_SFC_CODE());//总成编码
93         OPCUnit.write(opc.getOP090_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
94         logger.info("OP090工位,handleOrder PC处理完成!");
95     }
96
97     //PC读参数信息
98     public void handleInfo() throws Exception {
99         logger.info("OP090工位,handleInfo START!");
100
101         if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
102             if(group != null){
103                 opc.getServer().removeGroup(group,true);
104             }
105             group = opc.getServer().addGroup(GROUP_NAME);
106
107             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
108             //collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
109             collectionParamConfParam.setLocationCode(LOCATION_CODE);
110             CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
111             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
112
113
114             for(int i=0;i<list.size();i++){
115                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
116                 Item item = group.addItem(result.getGatherAddress());
117                 result.setItem(item);
118                 list.set(i,result);
119             }
120             //S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
121         }
122
123         if(null != list && list.size()>0) {
124             ParamCollectionService paramCollectionService = opc.paramCollectionService;
125             for (int i = 0; i < list.size(); i++) {
126                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
127                 Item item = result.getItem();
128                 String value = OPCUnit.read(item);//读参数值
129                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
130                 paramCollectionParam.setParamCode(result.getParamCode());
131                 paramCollectionParam.setParamName(result.getParamName());
132                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
133                 paramCollectionParam.setSfcCode(S_SFC_CODE);
134                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
135                 paramCollectionParam.setProductionLine(result.getProductionLine());
136                 paramCollectionParam.setLocationCode(result.getLocationCode());
137                 paramCollectionParam.setParamValue(value);
138                 paramCollectionParam.setParamLower(result.getParamLower());
139                 paramCollectionParam.setParamUpper(result.getParamUpper());
140                 paramCollectionParam.setParamStandard(result.getParamCentral());
141                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
142                 paramCollectionParam.setUnit(result.getUnit());
143                 paramCollectionService.add(paramCollectionParam);
144             }
145         }
146
147         logger.info("OP090工位,handleInfo END!");
148     }
149
150     //PC完成
151     public void handleFinsh() {
152         if("".equals(S_ORDER_CODE)){
153             IN_TIME = DateTool.getLocalTimeForDate();
154             S_ORDER_CODE = OPCUnit.read(opc.getOP090_S_ORDER_CODE());//工单编号
155             S_PRODUCT_TYPE = OPCUnit.read(opc.getOP090_S_PRODUCT_CODE());//产品编号
156             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
157             S_SFC_CODE = OPCUnit.read(opc.getOP090_S_SFC_CODE());//总成编码
158         }
159         //处理过站信息
160         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP090_S_PRODUCT_STATE_CODE());
161         PassingStationCollectionParam param = new PassingStationCollectionParam();
162         param.setWorkOrderNo(S_ORDER_CODE);
163         param.setProductCode(S_PRODUCT_CODE);
164         param.setSfcCode(S_SFC_CODE);
165         param.setProductionLine(PRODUCTION_LINE);
166         param.setLocationCode(LOCATION_CODE);
167         param.setInboundTime(IN_TIME);
168         param.setOutboundTime(DateTool.getLocalTimeForDate());
169         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
170         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
171         passingStationCollectionService.add(param);
172
173
174         String  eopSfcCode = OPCUnit.read(opc.getOP090_S_SFC_CODE_EOP());//EOP分总成
175
176         //根据分总成编码,将EOP物料数据绑定关系修改为总成编码
177         MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
178         materialTraceabilityService.updateSFC(S_SFC_CODE,eopSfcCode);
179
180         //根据分总成编码,将EOP过站数据绑定关系修改为总成编码
181         passingStationCollectionService.updateSFC(S_SFC_CODE,eopSfcCode);
182
183         //根据分总成编码,将EOP采集数据绑定关系修改为总成编码
184         ParamCollectionService paramCollectionService = opc.paramCollectionService;
185         paramCollectionService.updateSFC(S_SFC_CODE,eopSfcCode);
186
187         OPCUnit.write(opc.getOP090_J_PC_FINISH(), "true"); //PC完成
188
189         logger.info("OP090工位,handleFinsh PC处理完成!");
190     }
191
192 }