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