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