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