cl
2024-01-22 314bc7a1733856bd82c9d99bdfa27b34a4a762c3
提交 | 用户 | 时间
d43481 1 package cn.stylefeng.guns.plcserver.callback;
C 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.bs.equipmentInfo.service.EquipmentInfoService;
8 import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
9 import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
10 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
11 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
12 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.result.PassingStationCollectionResult;
13 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
14 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
15 import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
16 import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService;
17 import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService;
18 import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
19 import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
20 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
21 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
22 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
23 import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
24 import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
25 import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
26 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
27 import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
28 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
29 import cn.stylefeng.guns.plcserver.opc.OPCElement;
30
31 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
32 import cn.stylefeng.guns.plcserver.tool.DateTool;
33 import cn.stylefeng.guns.plcserver.tool.LogUtil;
34 import com.kangaroohy.milo.model.ReadWriteEntity;
35 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
36 import com.kangaroohy.milo.service.MiloService;
37 import org.apache.log4j.Logger;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.stereotype.Component;
40
41 import java.util.ArrayList;
42 import java.util.Date;
43 import java.util.List;
44
45 @Component
46 public class OP090Callback implements SubscriptionCallback {
47
48     public MiloService miloService;
49
50     @Autowired
51     public ProductionOrdeInfoService productionOrdeInfoService;
52     @Autowired
53     public PassingStationCollectionService passingStationCollectionService;
54     @Autowired
55     public ParamCollectionService paramCollectionService;
56     @Autowired
57     public CollectionParamConfService collectionParamConfService;
58     @Autowired
59     public SerialNumbersConfService serialNumbersConfService;
60     @Autowired
61     private EquipmentStatusService equipmentStatusService;
62
63     @Autowired
64     private EquipmentAlarmService equipmentAlarmService;
65     @Autowired
66     private MaterialTraceabilityService materialTraceabilityService;
67     @Autowired
68     private EquipmentInfoService equipmentInfoService;
69     @Autowired
70     private RepairManageInfoService repairManageInfoService;
71
72     @Autowired
73     private LocationInfoService locationInfoService;
74
75     @Autowired
76     private GreaseManageService greaseManageService;
77
78     @Autowired
79     private ProductionOrderRecordsService productionOrderRecordsService;
80
81     @Autowired
82     private ProductionOrderBatchInfoService productionOrderBatchInfoService;
83
84     private static Logger logger;
85     LogUtil logUtil = new LogUtil();
86     static {
87         logger = Logger.getLogger(OP090Callback.class);
88     }
89     private static Date IN_TIME = null;
90     private static String S_ORDER_CODE = "";//工单编号
91     private static String S_PRODUCT_CODE = "";//产品编号
92     private static String S_PRODUCT_TYPE= "";//产品类型
93     private static String S_SFC_CODE = "";//总成编码
94     private static String PRODUCTION_LINE  = "OP";//产线号
95     private static String LOCATION_CODE  = "OP090";//工位号
96     private static List list = null;
97
98     public OP090Callback(MiloService miloService,
99                          ProductionOrdeInfoService productionOrdeInfoService,
100                          PassingStationCollectionService passingStationCollectionService,
101                          ParamCollectionService paramCollectionService,
102                          CollectionParamConfService collectionParamConfService,
103                          SerialNumbersConfService serialNumbersConfService,
104                          EquipmentStatusService equipmentStatusService,
105                          EquipmentAlarmService equipmentAlarmService,
106                          MaterialTraceabilityService materialTraceabilityService,
107                          EquipmentInfoService equipmentInfoService,
108                          RepairManageInfoService repairManageInfoService,
109                          LocationInfoService locationInfoService,
110                          GreaseManageService greaseManageService,
111                          ProductionOrderRecordsService productionOrderRecordsService,
112                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
113         this.miloService = miloService;
114         this.productionOrdeInfoService = productionOrdeInfoService;
115         this.passingStationCollectionService = passingStationCollectionService;
116         this.paramCollectionService = paramCollectionService;
117         this.collectionParamConfService = collectionParamConfService;
118         this.serialNumbersConfService = serialNumbersConfService;
119         this.equipmentStatusService = equipmentStatusService;
120         this.equipmentAlarmService = equipmentAlarmService;
121         this.materialTraceabilityService = materialTraceabilityService;
122         this.equipmentInfoService = equipmentInfoService;
123         this.repairManageInfoService = repairManageInfoService;
124         this.locationInfoService = locationInfoService;
125         this.greaseManageService = greaseManageService;
126         this.productionOrderRecordsService = productionOrderRecordsService;
127         this.productionOrderBatchInfoService = productionOrderBatchInfoService;
128     }
129
130     @Override
131     public void onSubscribe(String identifier, Object value) {
132         String ecpStr = "";//异常记录标记
133         try {
134             //心跳
135             if(null != value && identifier.equals(OPCElement.OP090_F_HEART_BEAT)){
136                 if( "false".equals(value.toString()))
137                 {
138                     ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_F_HEART_BEAT,true);
139                     miloService.writeToOpcUa(entity);
140                 }
141             }
142             //PLC进站
143             else if(null != value && identifier.equals(OPCElement.OP090_J_PLC_START)){
144                 if("true".equals(value.toString())){
145                     handleOrder();
146                 }
147             }
148             //PLC出站
149             else if(null != value && identifier.equals(OPCElement.OP090_J_PLC_FINISH)){
150                 if("true".equals(value.toString())){
151                     handleMaterial();
152                     handleFinsh();
153                     handleInfo();
154
155                 }
156             }else{
157                 System.out.println("值没有变");
158             }
159         } catch (Exception e) {
160             ecpStr ="出现异常:" + logUtil.getTrace(e);
161         }finally {
162             if(!"".equals(ecpStr)){
163                 logger.info(ecpStr+"\r\n");
164             }
165         }
166     }
167
168     //PC读工单
169     public void handleOrder() throws Exception {
170         logger.info("handleOrder PC处理开始!");
171         IN_TIME = DateTool.getLocalTimeForDate();
172         List<String> lists = new ArrayList<>();
173         lists.add(OPCElement.OP090_S_ORDER_CODE);
174         lists.add(OPCElement.OP090_S_PRODUCT_CODE);
175         lists.add(OPCElement.OP090_S_SFC_CODE);
176         List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
177         returnLists.forEach(element->{
178             switch(element.getIdentifier()){
179                 case OPCElement.OP090_S_ORDER_CODE:
180                     S_ORDER_CODE = element.getValue().toString();
181                     break;
182                 case OPCElement.OP090_S_PRODUCT_CODE:
183                     S_PRODUCT_TYPE = element.getValue().toString();
184                     S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
185                     break;
186                 case OPCElement.OP090_S_SFC_CODE:
187                     S_SFC_CODE = element.getValue().toString();
188                     break;
189                 default:
190                     break;
191             }
192         });
193         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_J_PC_WRITE_ORDER,true);
194         miloService.writeToOpcUa(entity);
195         logger.info("handleOrder PC处理完成!");
196     }
197
198     public void handleFinsh() throws Exception {
199         logger.info("handleFinsh PC处理开始!");
200         //处理过站信息
201         String S_PRODUCT_STATE_CODE = miloService.
202                 readFromOpcUa(OPCElement.OP090_S_PRODUCT_STATE_CODE)
203                 .getValue().toString();
204         PassingStationCollectionParam param = new PassingStationCollectionParam();
205         param.setWorkOrderNo(S_ORDER_CODE);
206         param.setProductCode(S_PRODUCT_CODE);
207         param.setSfcCode(S_SFC_CODE);
208         param.setProductionLine(PRODUCTION_LINE);
209         param.setLocationCode(LOCATION_CODE);
210         param.setInboundTime(IN_TIME);
211         param.setOutboundTime(DateTool.getLocalTimeForDate());
212         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
213         passingStationCollectionService.add(param);
214
215         String eopSfcCode = miloService.
216                 readFromOpcUa(OPCElement.OP090_S_SFC_CODE_EOP)
217                 .getValue().toString();
218
219         //根据分总成编码,将EOP物料数据绑定关系修改为总成编码
220         materialTraceabilityService.updateSFC(S_SFC_CODE,eopSfcCode);
221
222         //根据分总成编码,将EOP过站数据绑定关系修改为总成编码
223         passingStationCollectionService.updateSFC(S_SFC_CODE,eopSfcCode);
224
225         //根据分总成编码,将EOP采集数据绑定关系修改为总成编码
226         paramCollectionService.updateSFC(S_SFC_CODE,eopSfcCode);
227
228         logger.info("S_SFC_CODE:"+S_SFC_CODE);
229         logger.info("eopSfcCode:"+eopSfcCode);
230
231         //查询COP和BOP是否合格
232         PassingStationCollectionParam passingStationCollectionParam = new PassingStationCollectionParam();
233         passingStationCollectionParam.setSfcCode(S_SFC_CODE);
234         List<PassingStationCollectionResult> passingStationCollectionResultList =
235                 passingStationCollectionService.findListBySpec(passingStationCollectionParam);
236
237         String isProductState = "true";
238         for(int i=0;i<passingStationCollectionResultList.size();i++){
239             PassingStationCollectionResult passingStationCollectionResult = passingStationCollectionResultList.get(i);
240             if("false".equals(passingStationCollectionResult.getOutRsSign())){
241                 isProductState = "false";
242                 break;
243             }
244         }
245         //修改报工记录
246         if("false".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){
247             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
248             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
249             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
250
251             List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
252             if(list.size()>0){
253                 ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
254                 productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
255                 productionOrderRecordsParam.setWhetherPass("false");
256                 productionOrderRecordsService.update(productionOrderRecordsParam);
257             }
258         }
259
260         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_J_PC_FINISH,true);
261         miloService.writeToOpcUa(entity);//写PC完成
262         logger.info("handleFinsh PC处理完成!");
263     }
264     public void handleMaterial() {
265
266         //查询批次上料信息
267         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
268         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
269         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
270         List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
271         for(int i=0;i<list.size();i++){
272             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
273             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
274             if(remainingQuantity>0 ){
275                 //新增物料追溯
276                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
277                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
278                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
279                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
280                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
281                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
282                 materialTraceabilityParam.setAssemblyQty(1);
283                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
284                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
285                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
286
287                 materialTraceabilityService.add(materialTraceabilityParam);
288                 //更新剩余数量
289                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
290                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
291                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
292             }
293         }
294     }
295
296     //PC读参数信息
297     public void handleInfo() throws Exception {
298         logger.info("handleInfo START!");
299
300         if(null == list){
301             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
302             collectionParamConfParam.setLocationCode(LOCATION_CODE);
303             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
304         }
305         if(null != list && !list.isEmpty()) {
306             for (int i = 0; i < list.size(); i++) {
307                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
308                 String value = miloService.
309                         readFromOpcUa(result.getGatherAddress())
310                         .getValue().toString();//读参数值
311                 ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
312                 paramCollectionParam.setParamCode(result.getParamCode());
313                 paramCollectionParam.setParamName(result.getParamName());
314                 paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
315                 paramCollectionParam.setSfcCode(S_SFC_CODE);
316                 paramCollectionParam.setProductCode(S_PRODUCT_CODE);
317                 paramCollectionParam.setProductionLine(result.getProductionLine());
318                 paramCollectionParam.setLocationCode(result.getLocationCode());
319                 paramCollectionParam.setParamValue(value);
320                 paramCollectionParam.setParamLower(result.getParamLower());
321                 paramCollectionParam.setParamUpper(result.getParamUpper());
322                 paramCollectionParam.setParamStandard(result.getParamCentral());
323                 paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
324                 paramCollectionParam.setUnit(result.getUnit());
325                 paramCollectionService.add(paramCollectionParam);
326             }
327         }
328
329         logger.info("handleInfo END!");
330     }
331
332 }