cl
2024-05-23 ba1a7a9ef126296e2798e313dc5b43f775a1123c
提交 | 用户 | 时间
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.SFCCodeTool;
38 import cn.stylefeng.guns.plcserver.tool.DateTool;
39 import cn.stylefeng.guns.plcserver.tool.LogUtil;
40 import com.kangaroohy.milo.model.ReadWriteEntity;
41 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
42 import com.kangaroohy.milo.service.MiloService;
43 import org.apache.commons.lang3.StringUtils;
44 import org.apache.log4j.Logger;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.stereotype.Component;
47
48 import java.util.ArrayList;
49 import java.util.Calendar;
50 import java.util.Date;
51 import java.util.List;
52
53 @Component
73bc06 54 public class OP010Callback {
d43481 55
C 56     public MiloService miloService;
57
58     @Autowired
59     public ProductionOrdeInfoService productionOrdeInfoService;
60     @Autowired
61     public PassingStationCollectionService passingStationCollectionService;
62     @Autowired
63     public ParamCollectionService paramCollectionService;
64     @Autowired
65     public CollectionParamConfService collectionParamConfService;
66     @Autowired
67     public SerialNumbersConfService serialNumbersConfService;
68     @Autowired
69     private EquipmentStatusService equipmentStatusService;
70
71     @Autowired
72     private EquipmentAlarmService equipmentAlarmService;
73     @Autowired
74     private MaterialTraceabilityService materialTraceabilityService;
75     @Autowired
76     private EquipmentInfoService equipmentInfoService;
77     @Autowired
78     private RepairManageInfoService repairManageInfoService;
79
80     @Autowired
81     private LocationInfoService locationInfoService;
82
83     @Autowired
84     private GreaseManageService greaseManageService;
85
86     @Autowired
87     private ProductionOrderRecordsService productionOrderRecordsService;
88
89     @Autowired
90     private ProductionOrderBatchInfoService productionOrderBatchInfoService;
91
92     private static Logger logger;
93     LogUtil logUtil = new LogUtil();
94     static {
95         logger = Logger.getLogger(OP010Callback.class);
96     }
97     private static Date IN_TIME = null;
98     private static String S_ORDER_CODE = "";//工单编号
99     private static String S_PRODUCT_CODE = "";//产品编号
100     private static String S_PRODUCT_TYPE= "";//产品类型
101     private static String S_SFC_CODE = "";//总成编码
102     private static String PRODUCTION_LINE  = "OP";//产线号
103     private static String LOCATION_CODE  = "OP010";//工位号
104     private static List list = null;
105
106     private static Integer ACTUAL_ONLINE_QTY  = 0 ;//上线数量
107     public OP010Callback(MiloService miloService,
108                          ProductionOrdeInfoService productionOrdeInfoService,
109                          PassingStationCollectionService passingStationCollectionService,
110                          ParamCollectionService paramCollectionService,
111                          CollectionParamConfService collectionParamConfService,
112                          SerialNumbersConfService serialNumbersConfService,
113                          EquipmentStatusService equipmentStatusService,
114                          EquipmentAlarmService equipmentAlarmService,
115                          MaterialTraceabilityService materialTraceabilityService,
116                          EquipmentInfoService equipmentInfoService,
117                          RepairManageInfoService repairManageInfoService,
118                          LocationInfoService locationInfoService,
119                          GreaseManageService greaseManageService,
120                          ProductionOrderRecordsService productionOrderRecordsService,
121                          ProductionOrderBatchInfoService productionOrderBatchInfoService) {
122         this.miloService = miloService;
123         this.productionOrdeInfoService = productionOrdeInfoService;
124         this.passingStationCollectionService = passingStationCollectionService;
125         this.paramCollectionService = paramCollectionService;
126         this.collectionParamConfService = collectionParamConfService;
127         this.serialNumbersConfService = serialNumbersConfService;
128         this.equipmentStatusService = equipmentStatusService;
129         this.equipmentAlarmService = equipmentAlarmService;
130         this.materialTraceabilityService = materialTraceabilityService;
131         this.equipmentInfoService = equipmentInfoService;
132         this.repairManageInfoService = repairManageInfoService;
133         this.locationInfoService = locationInfoService;
134         this.greaseManageService = greaseManageService;
135         this.productionOrderRecordsService = productionOrderRecordsService;
136         this.productionOrderBatchInfoService = productionOrderBatchInfoService;
137     }
138
139     //PC读工单
140     public void handleOrder() throws Exception{
141
142         logger.info("OP010工位,handleOrder PC处理开始!");
143         IN_TIME = DateTool.getLocalTimeForDate();
144         ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
145         param.setProductionLine("");//产线
146         param.setOrderStatus("3");//工单状态
147         List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
148
149         if(!list.isEmpty()) {
150             ProductionOrdeInfoResult result = list.get(0);
151
152             String softwareVersionCode = result.getSoftwareVersionCode();//产品型号
153             String productCompanyCode = result.getProductCompanyCode();//班次
154
155             //序列号
156             String serialNumbers = "0000";
157             SerialNumbersConfParam serialNumbersConfParam = new SerialNumbersConfParam();
158             Calendar calendar = Calendar.getInstance();
159             String Years = String.valueOf(calendar.get(Calendar.YEAR)); //年份
160             String Months = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH) + 1),2, "0"); //月份
161             String Dates = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)),2, "0"); //日期
162             serialNumbersConfParam.setYears(Years+Months+Dates);//获取当前是哪一天
163             serialNumbersConfParam.setState("1");
164
165             List<SerialNumbersConfResult> serialNumberslist = serialNumbersConfService.findListBySpec(serialNumbersConfParam);
166             if(!serialNumberslist.isEmpty()){
167                 SerialNumbersConfResult serialNumbersConfResult = serialNumberslist.get(0);
168                 serialNumbers = serialNumbersConfResult.getSerialNumber();
169                 serialNumbersConfParam.setId(serialNumbersConfResult.getId());
170             }else{
171                 serialNumbersConfParam.setSerialNumber(serialNumbers);
172                 serialNumbersConfParam.setLengths("4");
173                 serialNumbersConfService.add(serialNumbersConfParam);
174                 List<SerialNumbersConfResult> serialNumberslist2 = serialNumbersConfService.findListBySpec(serialNumbersConfParam);
175                 if(!serialNumberslist2.isEmpty()){
176                     SerialNumbersConfResult serialNumbersConfResult = serialNumberslist2.get(0);
177                     //serialNumbers = serialNumbersConfResult.getSerialNumber();
178                     serialNumbersConfParam.setId(serialNumbersConfResult.getId());
179                 }
180             }
181
182             //更新序列号+1
183             int i = Integer.valueOf(serialNumbers)+1;
184             serialNumbers = StringUtils.leftPad(String.valueOf(i),4, "0");
185             serialNumbersConfParam.setSerialNumber(serialNumbers);
186             serialNumbersConfService.update(serialNumbersConfParam);
187
188             //生成总成编码
189             String sfcCode = SFCCodeTool.createCodingRulesSFC(softwareVersionCode,productCompanyCode,serialNumbers);//总成号
190             S_SFC_CODE = sfcCode;
191             S_ORDER_CODE = result.getWorkOrderNo();
192             S_PRODUCT_CODE = result.getMaterialCode();
193             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
194             ACTUAL_ONLINE_QTY = result.getActualOnlineQty();
195
196
197             //新增报工记录
198             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
199             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
200             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
201             productionOrderRecordsParam.setMaterialCode(S_PRODUCT_CODE);
202             productionOrderRecordsParam.setStartTime(DateTool.getLocalTimeForDate());
ba1a7a 203             productionOrderRecordsParam.setMaterialName(result.getMaterialName());
C 204             productionOrderRecordsParam.setWhetherPass("合格");
d43481 205             productionOrderRecordsService.add(productionOrderRecordsParam);
C 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完成
ba1a7a 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());
ba1a7a 236                 productionOrderRecordsParam.setWhetherPass("不合格");
d43481 237                 productionOrderRecordsService.update(productionOrderRecordsParam);
C 238             }
ba1a7a 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
ba1a7a 259         if(S_ORDER_CODE.isEmpty()){
C 260             return;
261         }
d43481 262         //查询批次上料信息
C 263         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
264         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
265         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
266         List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
267         for(int i=0;i<list.size();i++){
268             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
269             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
270             if(remainingQuantity>0 ){
271                 //新增物料追溯
272                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
273                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
274                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
275                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
276                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
277                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
278                 materialTraceabilityParam.setAssemblyQty(1);
279                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
280                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
281                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
282
283                 materialTraceabilityService.add(materialTraceabilityParam);
284                 //更新剩余数量
285                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
286                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
287                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
288             }
289         }
290     }
291
292     public void handleRepair() throws Exception{
293         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
294         repairManageInfoParam.setLocationCode(LOCATION_CODE);
295         repairManageInfoParam.setManageType("2");
296         repairManageInfoParam.setUpPlc("0");
297
298         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
299         if(list.size()>0) {
300             RepairManageInfoResult result = list.get(0);
301
302             S_SFC_CODE = result.getSfc();
303             S_ORDER_CODE = result.getWorkOrderNo();
304             S_PRODUCT_CODE = result.getProductCode();
305             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
306             String  repairLocation = result.getPoorLocationCode();//
307
308             //根据工位编码查询工位表中配置的返修工位号
309             LocationInfoParam param = new LocationInfoParam();
310             param.setLocationCode(repairLocation);
311
312             List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
313             if(results.size()>0) {
314                 LocationInfoResult r = results.get(0);
315                 String repairLocationNo = r.getSpareField2();
316                 if(null != repairLocationNo && "" != repairLocationNo){
317
318                     List<ReadWriteEntity> lists = new ArrayList<>();
319                     lists.add(new ReadWriteEntity(OPCElement.OP010_S_ORDER_CODE,S_ORDER_CODE));
314bc7 320                     lists.add(new ReadWriteEntity(OPCElement.OP010_S_PRODUCT_CODE,Short.parseShort(S_PRODUCT_TYPE)));
d43481 321                     lists.add(new ReadWriteEntity(OPCElement.OP010_S_SFC_CODE,S_SFC_CODE));
C 322                     lists.add(new ReadWriteEntity(OPCElement.OP010_P_REPAIR_LOCATION,repairLocationNo));
323                     lists.add(new ReadWriteEntity(OPCElement.OP010_J_PC_WRITE_ORDER,true));
324                     miloService.writeToOpcUa(lists);
325
326                     //更新为已经返修上线
327                     Long id = result.getId();
328                     repairManageInfoParam.setId(id);
329                     repairManageInfoParam.setUpPlc("1");
330                     repairManageInfoService.update(repairManageInfoParam);
331
332                 }else{
333                     logger.info("OP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
334                 }
335             }else{
336                 logger.info("OP010工位,handleRepair 无法查询到"+repairLocation+"工位!");
337             }
338
339         }
340     }
341
342 }