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