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