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