cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.OP150.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;
16 import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
17 import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
18 import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
71e81e 19 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
20 import cn.stylefeng.guns.plcserver.opc.OPCComm;
21 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
22 import cn.stylefeng.guns.plcserver.server.OP150.OP150ServerInterface;
23 import cn.stylefeng.guns.plcserver.server.OP170.OP170ServerInterface;
24 import cn.stylefeng.guns.plcserver.tool.DateTool;
25 import cn.stylefeng.guns.plcserver.tool.LogUtil;
26 import org.apache.log4j.Logger;
27 import org.openscada.opc.lib.da.Group;
28 import org.openscada.opc.lib.da.Item;
29
30 import java.util.Date;
31 import java.util.List;
32
33
34 public class OP150ServerInterfaceImpl implements OP150ServerInterface {
35
36     private static Logger logger;
37     LogUtil logUtil = new LogUtil();
38     static {
39         logger = Logger.getLogger(OP150ServerInterfaceImpl.class);
40     }
41
42     private OPCComm opc = OPCComm.getInstance();
43     private static Date IN_TIME = null;
44     private static String S_ORDER_CODE = "";//工单编号
45     private static String S_PRODUCT_CODE = "";//产品编号
46     private static String S_PRODUCT_TYPE= "";//产品类型
47     private static String S_PRODUCT_CODE_OLD = "";//产品编号
48     private static String S_SFC_CODE = "";//总成编码
49     private static String S_RIGHT_CODE  = "";//右壳体编码
50     private static String PRODUCTION_LINE  = "OP";//产线号
51     private static String LOCATION_CODE  = "OP150";//工位号
52     private static String GROUP_NAME  = "OP150_P";//工位号
53     private static List list = null;
54     private static Group group = null;
cf6bff 55
C 56     private int count = 0;
57
58     /**
59      * 设置心跳标志位,保存到全局变量
60      */
61     public void setHeartbeat(String value) {
62         if ("false".equals(value)) {
63             OPCUnit.write(opc.getOP150_F_HEART_BEAT(), "true");
64             GlobalVariable.OP150_F_HEART_BEAT = true;
65             count = 0;
66         } else {
67             count++;
68         }
69         // 循环读取频率是:500ms一次,如果超过6次,也就是3s认定超时
70         if (count > GlobalVariable.HEART_MAX_COUNT) {
71             GlobalVariable.OP150_F_HEART_BEAT = false;
72         }
73     }
74
71e81e 75     @Override
76     public synchronized void monitor() {
77         String ecpStr = "";//异常记录标记
78         try{
cf6bff 79
e0fac3 80            /* String isHeartBeat = OPCUnit.read(opc.getOP150_F_HEART_BEAT());
C 81             setHeartbeat(isHeartBeat);*/
cf6bff 82
71e81e 83             if(GlobalVariable.OP150_F_HEART_BEAT) {
84                 //PC读工单
85                 String isPLCStart = OPCUnit.read(opc.getOP150_J_PLC_START());//PLC开始
86                 if(isPLCStart.equals("true")){
87                     String isFinish = OPCUnit.read(opc.getOP150_J_PC_WRITE_ORDER());//PC下发工单完成
88                     if(isFinish.equals("false")){
89                         handleOrder();
90                     }
91                 }
92
93
94                 //PC完成
95                 String isPLCFinish = OPCUnit.read(opc.getOP150_J_PLC_FINISH());//PLC完成
96                 if(isPLCFinish.equals("true")){
97                     String isFinish = OPCUnit.read(opc.getOP150_J_PC_FINISH());//PC操作完成
98                     if(isFinish.equals("false")){
99                         handleFinsh();
e0fac3 100                         //handleInfo();
C 101                         handleMaterial();
102
71e81e 103                     }
104                 }
105
106             }else{
107                 logger.info("OP150工位与PLC断开,请检查PLC或网络是否异常!");
108             }
109
110         }catch (Exception e) {
111             ecpStr ="出现异常:" + logUtil.getTrace(e);
112         }finally {
113             if(!"".equals(ecpStr)){
114                 logger.info(ecpStr+"\r\n");
115             }
116         }
117     }
118
119     //PC读工单
120     public void handleOrder() {
121         IN_TIME = DateTool.getLocalTimeForDate();
122         S_ORDER_CODE = OPCUnit.read(opc.getOP150_S_ORDER_CODE());//工单编号
123         S_PRODUCT_TYPE = OPCUnit.read(opc.getOP150_S_PRODUCT_CODE());//产品编号
124         S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
125         S_SFC_CODE = OPCUnit.read(opc.getOP150_S_SFC_CODE());//总成编码
126         OPCUnit.write(opc.getOP150_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
127         logger.info("OP150工位,handleOrder PC处理完成!");
cf6bff 128     }
C 129
130     public void handleMaterial() {
e0fac3 131
cf6bff 132         //查询批次上料信息
C 133         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
134         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
135         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
136         ProductionOrderBatchInfoService productionOrderBatchInfoService = opc.productionOrderBatchInfoService;
137         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
138         for(int i=0;i<list1.size();i++){
139             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
140
141             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
e0fac3 142             if(remainingQuantity>0){
cf6bff 143                 //新增物料追溯
C 144                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
145                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
146                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
147                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
148                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
149                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
150                 materialTraceabilityParam.setAssemblyQty(1);
151                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
152                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
153                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
154
155                 MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
156                 materialTraceabilityService.add(materialTraceabilityParam);
157                 //更新剩余数量
158                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
159                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
160                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
161             }
162         }
71e81e 163     }
164
165     //PC读参数信息
166     public void handleInfo() throws Exception {
167         logger.info("OP150工位,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("OP150工位,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.getOP150_S_ORDER_CODE());//工单编号
223             S_PRODUCT_TYPE = OPCUnit.read(opc.getOP150_S_PRODUCT_CODE());//产品编号
224             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
225             S_SFC_CODE = OPCUnit.read(opc.getOP150_S_SFC_CODE());//总成编码
226         }
227         //处理过站信息
228         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP150_S_PRODUCT_STATE_CODE());
cf6bff 229
C 230         //修改报工记录
231         if("false".equals(S_PRODUCT_STATE_CODE)){
232             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
233             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
234             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
235             ProductionOrderRecordsService productionOrderRecordsService = opc.productionOrderRecordsService;
236
237             List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
238             if(list.size()>0){
239                 ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
240                 productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
241                 productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
242                 productionOrderRecordsService.update(productionOrderRecordsParam);
243             }
244         }
245
246
71e81e 247         PassingStationCollectionParam param = new PassingStationCollectionParam();
248         param.setWorkOrderNo(S_ORDER_CODE);
249         param.setProductCode(S_PRODUCT_CODE);
250         param.setSfcCode(S_SFC_CODE);
251         param.setProductionLine(PRODUCTION_LINE);
252         param.setLocationCode(LOCATION_CODE);
253         param.setInboundTime(IN_TIME);
254         param.setOutboundTime(DateTool.getLocalTimeForDate());
255         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
256         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
257         passingStationCollectionService.add(param);
258
259         OPCUnit.write(opc.getOP150_J_PC_FINISH(), "true"); //PC完成
260
261         logger.info("OP150工位,handleFinsh PC处理完成!");
262     }
263
264 }