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