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.model.params.ProductionOrdeInfoParam;
21 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
22 import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
23 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
24 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult;
25 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService;
26 import cn.stylefeng.guns.modular.om.productionOrderRecords.model.params.ProductionOrderRecordsParam;
27 import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult;
28 import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService;
29 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
30 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
31 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
32 import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam;
33 import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult;
34 import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
35 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
36 import cn.stylefeng.guns.plcserver.opc.OPCElement;
37 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
38 import cn.stylefeng.guns.plcserver.opc.unit.SFCCodeTool;
39 import cn.stylefeng.guns.plcserver.tool.DateTool;
40 import cn.stylefeng.guns.plcserver.tool.LogUtil;
41 import com.kangaroohy.milo.model.ReadWriteEntity;
42 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
43 import com.kangaroohy.milo.service.MiloService;
44 import org.apache.commons.lang3.StringUtils;
45 import org.apache.log4j.Logger;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.stereotype.Component;
48
49 import java.util.ArrayList;
50 import java.util.Calendar;
51 import java.util.Date;
52 import java.util.List;
53
54 @Component
73bc06 55 public class OP010Callback {
d43481 56
C 57     public MiloService miloService;
58
59     @Autowired
60     public ProductionOrdeInfoService productionOrdeInfoService;
61     @Autowired
62     public PassingStationCollectionService passingStationCollectionService;
63     @Autowired
64     public ParamCollectionService paramCollectionService;
65     @Autowired
66     public CollectionParamConfService collectionParamConfService;
67     @Autowired
68     public SerialNumbersConfService serialNumbersConfService;
69     @Autowired
70     private EquipmentStatusService equipmentStatusService;
71
72     @Autowired
73     private EquipmentAlarmService equipmentAlarmService;
74     @Autowired
75     private MaterialTraceabilityService materialTraceabilityService;
76     @Autowired
77     private EquipmentInfoService equipmentInfoService;
78     @Autowired
79     private RepairManageInfoService repairManageInfoService;
80
81     @Autowired
82     private LocationInfoService locationInfoService;
83
84     @Autowired
85     private GreaseManageService greaseManageService;
86
87     @Autowired
88     private ProductionOrderRecordsService productionOrderRecordsService;
89
90     @Autowired
91     private ProductionOrderBatchInfoService productionOrderBatchInfoService;
92
93     private static Logger logger;
94     LogUtil logUtil = new LogUtil();
95     static {
96         logger = Logger.getLogger(OP010Callback.class);
97     }
98     private static Date IN_TIME = null;
99     private static String S_ORDER_CODE = "";//工单编号
100     private static String S_PRODUCT_CODE = "";//产品编号
101     private static String S_PRODUCT_TYPE= "";//产品类型
102     private static String S_SFC_CODE = "";//总成编码
103     private static String PRODUCTION_LINE  = "OP";//产线号
104     private static String LOCATION_CODE  = "OP010";//工位号
105     private static List list = null;
106
107     private static Integer ACTUAL_ONLINE_QTY  = 0 ;//上线数量
108     public OP010Callback(MiloService miloService,
109                          ProductionOrdeInfoService productionOrdeInfoService,
110                          PassingStationCollectionService passingStationCollectionService,
111                          ParamCollectionService paramCollectionService,
112                          CollectionParamConfService collectionParamConfService,
113                          SerialNumbersConfService serialNumbersConfService,
114                          EquipmentStatusService equipmentStatusService,
115                          EquipmentAlarmService equipmentAlarmService,
116                          MaterialTraceabilityService materialTraceabilityService,
117                          EquipmentInfoService equipmentInfoService,
118                          RepairManageInfoService repairManageInfoService,
119                          LocationInfoService locationInfoService,
120                          GreaseManageService greaseManageService,
121                          ProductionOrderRecordsService productionOrderRecordsService,
122                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
123         this.miloService = miloService;
124         this.productionOrdeInfoService = productionOrdeInfoService;
125         this.passingStationCollectionService = passingStationCollectionService;
126         this.paramCollectionService = paramCollectionService;
127         this.collectionParamConfService = collectionParamConfService;
128         this.serialNumbersConfService = serialNumbersConfService;
129         this.equipmentStatusService = equipmentStatusService;
130         this.equipmentAlarmService = equipmentAlarmService;
131         this.materialTraceabilityService = materialTraceabilityService;
132         this.equipmentInfoService = equipmentInfoService;
133         this.repairManageInfoService = repairManageInfoService;
134         this.locationInfoService = locationInfoService;
135         this.greaseManageService = greaseManageService;
136         this.productionOrderRecordsService = productionOrderRecordsService;
137         this.productionOrderBatchInfoService = productionOrderBatchInfoService;
138     }
139
140     //PC读工单
141     public void handleOrder() throws Exception{
142
143         logger.info("OP010工位,handleOrder PC处理开始!");
144         IN_TIME = DateTool.getLocalTimeForDate();
145         ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
146         param.setProductionLine("");//产线
147         param.setOrderStatus("3");//工单状态
148         List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
149
150         if(!list.isEmpty()) {
151             ProductionOrdeInfoResult result = list.get(0);
152
153             String softwareVersionCode = result.getSoftwareVersionCode();//产品型号
154             String productCompanyCode = result.getProductCompanyCode();//班次
155
156             //序列号
157             String serialNumbers = "0000";
158             SerialNumbersConfParam serialNumbersConfParam = new SerialNumbersConfParam();
159             Calendar calendar = Calendar.getInstance();
160             String Years = String.valueOf(calendar.get(Calendar.YEAR)); //年份
161             String Months = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH) + 1),2, "0"); //月份
162             String Dates = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)),2, "0"); //日期
163             serialNumbersConfParam.setYears(Years+Months+Dates);//获取当前是哪一天
164             serialNumbersConfParam.setState("1");
165
166             List<SerialNumbersConfResult> serialNumberslist = serialNumbersConfService.findListBySpec(serialNumbersConfParam);
167             if(!serialNumberslist.isEmpty()){
168                 SerialNumbersConfResult serialNumbersConfResult = serialNumberslist.get(0);
169                 serialNumbers = serialNumbersConfResult.getSerialNumber();
170                 serialNumbersConfParam.setId(serialNumbersConfResult.getId());
171             }else{
172                 serialNumbersConfParam.setSerialNumber(serialNumbers);
173                 serialNumbersConfParam.setLengths("4");
174                 serialNumbersConfService.add(serialNumbersConfParam);
175                 List<SerialNumbersConfResult> serialNumberslist2 = serialNumbersConfService.findListBySpec(serialNumbersConfParam);
176                 if(!serialNumberslist2.isEmpty()){
177                     SerialNumbersConfResult serialNumbersConfResult = serialNumberslist2.get(0);
178                     //serialNumbers = serialNumbersConfResult.getSerialNumber();
179                     serialNumbersConfParam.setId(serialNumbersConfResult.getId());
180                 }
181             }
182
183             //更新序列号+1
184             int i = Integer.valueOf(serialNumbers)+1;
185             serialNumbers = StringUtils.leftPad(String.valueOf(i),4, "0");
186             serialNumbersConfParam.setSerialNumber(serialNumbers);
187             serialNumbersConfService.update(serialNumbersConfParam);
188
189             //生成总成编码
190             String sfcCode = SFCCodeTool.createCodingRulesSFC(softwareVersionCode,productCompanyCode,serialNumbers);//总成号
191             S_SFC_CODE = sfcCode;
192             S_ORDER_CODE = result.getWorkOrderNo();
193             S_PRODUCT_CODE = result.getMaterialCode();
194             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
195             ACTUAL_ONLINE_QTY = result.getActualOnlineQty();
196
197
198             //新增报工记录
199             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
200             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
201             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
202             productionOrderRecordsParam.setMaterialCode(S_PRODUCT_CODE);
203             productionOrderRecordsParam.setStartTime(DateTool.getLocalTimeForDate());
204             productionOrderRecordsParam.setWhetherPass("true");
205             productionOrderRecordsService.add(productionOrderRecordsParam);
206
207             List<ReadWriteEntity> lists = new ArrayList<>();
208             lists.add(new ReadWriteEntity(OPCElement.OP010_S_ORDER_CODE,S_ORDER_CODE));
314bc7 209             lists.add(new ReadWriteEntity(OPCElement.OP010_S_PRODUCT_CODE,Short.parseShort(S_PRODUCT_TYPE)));
d43481 210             lists.add(new ReadWriteEntity(OPCElement.OP010_S_SFC_CODE,S_SFC_CODE));
314bc7 211             lists.add(new ReadWriteEntity(OPCElement.OP010_S_NUMBER,Short.parseShort(result.getPlanQty().toString())));
d43481 212             lists.add(new ReadWriteEntity(OPCElement.OP010_J_PC_WRITE_ORDER,true));
C 213             miloService.writeToOpcUa(lists);
214             logger.info("OP010工位,handleOrder PC处理完成!^--------------------------------------------");
215         }else{
216             logger.info("OP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
217         }
218     }
219
220     public void handleFinsh() throws Exception {
221         logger.info("handleFinsh PC处理开始!");
222         String S_PRODUCT_STATE_CODE = miloService.
223                 readFromOpcUa(OPCElement.OP010_S_PRODUCT_STATE_CODE)
224                 .getValue().toString();
225
73bc06 226         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_J_PC_FINISH,true);
C 227         miloService.writeToOpcUa(entity);//写PC完成
228        /* if("2".equals(S_PRODUCT_STATE_CODE)){
d43481 229             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
C 230             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
231             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
232             List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
233             if(!list.isEmpty()){
234                 ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
235                 productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
236                 productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
237                 productionOrderRecordsService.update(productionOrderRecordsParam);
238             }
73bc06 239         }*/
d43481 240         //处理过站信息
C 241         PassingStationCollectionParam param = new PassingStationCollectionParam();
242         param.setWorkOrderNo(S_ORDER_CODE);
243         param.setProductCode(S_PRODUCT_CODE);
244         param.setSfcCode(S_SFC_CODE);
245         param.setProductionLine(PRODUCTION_LINE);
246         param.setLocationCode(LOCATION_CODE);
247         param.setInboundTime(IN_TIME);
248         param.setOutboundTime(DateTool.getLocalTimeForDate());
249         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
250         passingStationCollectionService.add(param);
251
73bc06 252
d43481 253         logger.info("handleFinsh PC处理完成!");
C 254     }
255
256
257     public void handleMaterial() {
258
259         //查询批次上料信息
260         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
261         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
262         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
263         List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
264         for(int i=0;i<list.size();i++){
265             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
266             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
267             if(remainingQuantity>0 ){
268                 //新增物料追溯
269                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
270                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
271                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
272                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
273                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
274                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
275                 materialTraceabilityParam.setAssemblyQty(1);
276                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
277                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
278                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
279
280                 materialTraceabilityService.add(materialTraceabilityParam);
281                 //更新剩余数量
282                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
283                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
284                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
285             }
286         }
287     }
288
289     public void handleRepair() throws Exception{
290         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
291         repairManageInfoParam.setLocationCode(LOCATION_CODE);
292         repairManageInfoParam.setManageType("2");
293         repairManageInfoParam.setUpPlc("0");
294
295         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
296         if(list.size()>0) {
297             RepairManageInfoResult result = list.get(0);
298
299             S_SFC_CODE = result.getSfc();
300             S_ORDER_CODE = result.getWorkOrderNo();
301             S_PRODUCT_CODE = result.getProductCode();
302             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
303             String  repairLocation = result.getPoorLocationCode();//
304
305             //根据工位编码查询工位表中配置的返修工位号
306             LocationInfoParam param = new LocationInfoParam();
307             param.setLocationCode(repairLocation);
308
309             List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
310             if(results.size()>0) {
311                 LocationInfoResult r = results.get(0);
312                 String repairLocationNo = r.getSpareField2();
313                 if(null != repairLocationNo && "" != repairLocationNo){
314
315                     List<ReadWriteEntity> lists = new ArrayList<>();
316                     lists.add(new ReadWriteEntity(OPCElement.OP010_S_ORDER_CODE,S_ORDER_CODE));
314bc7 317                     lists.add(new ReadWriteEntity(OPCElement.OP010_S_PRODUCT_CODE,Short.parseShort(S_PRODUCT_TYPE)));
d43481 318                     lists.add(new ReadWriteEntity(OPCElement.OP010_S_SFC_CODE,S_SFC_CODE));
C 319                     lists.add(new ReadWriteEntity(OPCElement.OP010_P_REPAIR_LOCATION,repairLocationNo));
320                     lists.add(new ReadWriteEntity(OPCElement.OP010_J_PC_WRITE_ORDER,true));
321                     miloService.writeToOpcUa(lists);
322
323                     //更新为已经返修上线
324                     Long id = result.getId();
325                     repairManageInfoParam.setId(id);
326                     repairManageInfoParam.setUpPlc("1");
327                     repairManageInfoService.update(repairManageInfoParam);
328
329                 }else{
330                     logger.info("OP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
331                 }
332             }else{
333                 logger.info("OP010工位,handleRepair 无法查询到"+repairLocation+"工位!");
334             }
335
336         }
337     }
338
339     //PC读参数信息
340     public void handleInfo() throws Exception {
341         logger.info("handleInfo START!");
342
343         if(null == list){
344             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
345             collectionParamConfParam.setLocationCode(LOCATION_CODE);
346             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
347         }
348         if(null != list && !list.isEmpty()) {
349             for (int i = 0; i < list.size(); i++) {
350                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
6dadf3 351                 Object value = miloService.
d43481 352                         readFromOpcUa(result.getGatherAddress())
6dadf3 353                         .getValue();//读参数值
C 354                 if(null != value) {
355                     ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
356                     paramCollectionParam.setParamCode(result.getParamCode());
357                     paramCollectionParam.setParamName(result.getParamName());
358                     paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
359                     paramCollectionParam.setSfcCode(S_SFC_CODE);
360                     paramCollectionParam.setProductCode(S_PRODUCT_CODE);
361                     paramCollectionParam.setProductionLine(result.getProductionLine());
362                     paramCollectionParam.setLocationCode(result.getLocationCode());
363                     paramCollectionParam.setParamValue(value.toString());
364                     paramCollectionParam.setParamLower(result.getParamLower());
365                     paramCollectionParam.setParamUpper(result.getParamUpper());
366                     paramCollectionParam.setParamStandard(result.getParamCentral());
367                     paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
368                     paramCollectionParam.setUnit(result.getUnit());
369                     paramCollectionService.add(paramCollectionParam);
370                 }
d43481 371             }
C 372         }
373
374         logger.info("handleInfo END!");
375     }
376
377 }