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