cl
2024-01-23 ff13e6159eab48d53bb528a10d0ab8850fdf7ad5
提交 | 用户 | 时间
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         //处理过站信息
ff13e6 201         Object object = miloService.
d43481 202                 readFromOpcUa(OPCElement.OP090_S_PRODUCT_STATE_CODE)
ff13e6 203                 .getValue();
C 204
205         String S_PRODUCT_STATE_CODE = "";
206         if(null != object){
207             S_PRODUCT_STATE_CODE = object.toString();
208         }
209
d43481 210         PassingStationCollectionParam param = new PassingStationCollectionParam();
C 211         param.setWorkOrderNo(S_ORDER_CODE);
212         param.setProductCode(S_PRODUCT_CODE);
213         param.setSfcCode(S_SFC_CODE);
214         param.setProductionLine(PRODUCTION_LINE);
215         param.setLocationCode(LOCATION_CODE);
216         param.setInboundTime(IN_TIME);
217         param.setOutboundTime(DateTool.getLocalTimeForDate());
218         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
219         passingStationCollectionService.add(param);
220
ff13e6 221         Object eopSfcCode = miloService.
d43481 222                 readFromOpcUa(OPCElement.OP090_S_SFC_CODE_EOP)
ff13e6 223                 .getValue();
d43481 224
ff13e6 225         if(null != eopSfcCode) {
C 226             //根据分总成编码,将EOP物料数据绑定关系修改为总成编码
227             materialTraceabilityService.updateSFC(S_SFC_CODE, eopSfcCode.toString());
d43481 228
ff13e6 229             //根据分总成编码,将EOP过站数据绑定关系修改为总成编码
C 230             passingStationCollectionService.updateSFC(S_SFC_CODE, eopSfcCode.toString());
d43481 231
ff13e6 232             //根据分总成编码,将EOP采集数据绑定关系修改为总成编码
C 233             paramCollectionService.updateSFC(S_SFC_CODE, eopSfcCode.toString());
d43481 234
ff13e6 235             logger.info("S_SFC_CODE:" + S_SFC_CODE);
C 236             logger.info("eopSfcCode:" + eopSfcCode);
237         }
d43481 238         //查询COP和BOP是否合格
C 239         PassingStationCollectionParam passingStationCollectionParam = new PassingStationCollectionParam();
240         passingStationCollectionParam.setSfcCode(S_SFC_CODE);
241         List<PassingStationCollectionResult> passingStationCollectionResultList =
242                 passingStationCollectionService.findListBySpec(passingStationCollectionParam);
243
244         String isProductState = "true";
245         for(int i=0;i<passingStationCollectionResultList.size();i++){
246             PassingStationCollectionResult passingStationCollectionResult = passingStationCollectionResultList.get(i);
247             if("false".equals(passingStationCollectionResult.getOutRsSign())){
248                 isProductState = "false";
249                 break;
250             }
251         }
252         //修改报工记录
ff13e6 253         if("2".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){
d43481 254             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
C 255             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
256             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
257
258             List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
259             if(list.size()>0){
260                 ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
261                 productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
ff13e6 262                 productionOrderRecordsParam.setWhetherPass("2");
d43481 263                 productionOrderRecordsService.update(productionOrderRecordsParam);
C 264             }
265         }
266
267         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_J_PC_FINISH,true);
268         miloService.writeToOpcUa(entity);//写PC完成
269         logger.info("handleFinsh PC处理完成!");
270     }
271     public void handleMaterial() {
272
273         //查询批次上料信息
274         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
275         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
276         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
277         List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
278         for(int i=0;i<list.size();i++){
279             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
280             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
281             if(remainingQuantity>0 ){
282                 //新增物料追溯
283                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
284                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
285                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
286                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
287                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
288                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
289                 materialTraceabilityParam.setAssemblyQty(1);
290                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
291                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
292                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
293
294                 materialTraceabilityService.add(materialTraceabilityParam);
295                 //更新剩余数量
296                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
297                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
298                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
299             }
300         }
301     }
302
303     //PC读参数信息
304     public void handleInfo() throws Exception {
305         logger.info("handleInfo START!");
306
307         if(null == list){
308             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
309             collectionParamConfParam.setLocationCode(LOCATION_CODE);
310             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
311         }
312         if(null != list && !list.isEmpty()) {
313             for (int i = 0; i < list.size(); i++) {
314                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
6dadf3 315                 Object value = miloService.
d43481 316                         readFromOpcUa(result.getGatherAddress())
6dadf3 317                         .getValue();//读参数值
C 318                 if(null != value) {
319                     ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
320                     paramCollectionParam.setParamCode(result.getParamCode());
321                     paramCollectionParam.setParamName(result.getParamName());
322                     paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
323                     paramCollectionParam.setSfcCode(S_SFC_CODE);
324                     paramCollectionParam.setProductCode(S_PRODUCT_CODE);
325                     paramCollectionParam.setProductionLine(result.getProductionLine());
326                     paramCollectionParam.setLocationCode(result.getLocationCode());
327                     paramCollectionParam.setParamValue(value.toString());
328                     paramCollectionParam.setParamLower(result.getParamLower());
329                     paramCollectionParam.setParamUpper(result.getParamUpper());
330                     paramCollectionParam.setParamStandard(result.getParamCentral());
331                     paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
332                     paramCollectionParam.setUnit(result.getUnit());
333                     paramCollectionService.add(paramCollectionParam);
334                 }
d43481 335             }
C 336         }
337
338         logger.info("handleInfo END!");
339     }
340
341 }