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 OP130BCallback{
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(OP130BCallback.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  = "OP130B";//工位号
97     private static List list = null;
ba1a7a 98     private static String PRODUCT_STATE = "合格";
d43481 99     public OP130BCallback(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     //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.OP130B_S_ORDER_CODE);
137         lists.add(OPCElement.OP130B_S_PRODUCT_CODE);
138         lists.add(OPCElement.OP130B_S_SFC_CODE);
139         List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
140         returnLists.forEach(element->{
141             switch(element.getIdentifier()){
142                 case OPCElement.OP130B_S_ORDER_CODE:
143                     S_ORDER_CODE = element.getValue().toString();
144                     break;
145                 case OPCElement.OP130B_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.OP130B_S_SFC_CODE:
150                     S_SFC_CODE = element.getValue().toString();
151                     break;
152                 default:
153                     break;
154             }
155         });
156         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130B_J_PC_WRITE_ORDER,true);
157         miloService.writeToOpcUa(entity);
158         logger.info("handleOrder PC处理完成!");
159     }
160
161     public void handleFinsh() throws Exception {
162         logger.info("handleFinsh PC处理开始!");
163         String S_PRODUCT_STATE_CODE = miloService.
164                 readFromOpcUa(OPCElement.OP130B_S_PRODUCT_STATE_CODE)
165                 .getValue().toString();
ba1a7a 166         if("2".equals(S_PRODUCT_STATE_CODE)){
C 167             PRODUCT_STATE = "不合格";
168         }
73bc06 169         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130B_J_PC_FINISH,true);
C 170         miloService.writeToOpcUa(entity);//写PC完成
171
ba1a7a 172         if("2".equals(S_PRODUCT_STATE_CODE)){
d43481 173             ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
C 174             productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
175             productionOrderRecordsParam.setProductNo(S_SFC_CODE);
176             List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam);
177             if(!list.isEmpty()){
178                 ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
179                 productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
ba1a7a 180                 productionOrderRecordsParam.setWhetherPass("不合格");
d43481 181                 productionOrderRecordsService.update(productionOrderRecordsParam);
C 182             }
ba1a7a 183         }
d43481 184         //处理过站信息
C 185         PassingStationCollectionParam param = new PassingStationCollectionParam();
186         param.setWorkOrderNo(S_ORDER_CODE);
187         param.setProductCode(S_PRODUCT_CODE);
188         param.setSfcCode(S_SFC_CODE);
189         param.setProductionLine(PRODUCTION_LINE);
190         param.setLocationCode(LOCATION_CODE);
191         param.setInboundTime(IN_TIME);
192         param.setOutboundTime(DateTool.getLocalTimeForDate());
193         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
194         passingStationCollectionService.add(param);
195
73bc06 196
d43481 197         logger.info("handleFinsh PC处理完成!");
C 198     }
199
200     public void handleMaterial() {
201
202         //查询批次上料信息
203         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
204         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
205         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
206         List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
207         for(int i=0;i<list.size();i++){
208             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
209             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
210             if(remainingQuantity>0 ){
211                 //新增物料追溯
212                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
213                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
214                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
215                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
216                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
217                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
218                 materialTraceabilityParam.setAssemblyQty(1);
219                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
220                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
221                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
222
223                 materialTraceabilityService.add(materialTraceabilityParam);
224                 //更新剩余数量
225                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
226                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
227                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
228             }
229         }
230     }
231
232     //PC读参数信息
233     public void handleInfo() throws Exception {
234         logger.info("handleInfo START!");
235
236         if(null == list){
237             CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
238             collectionParamConfParam.setLocationCode(LOCATION_CODE);
239             list = collectionParamConfService.findListBySpec(collectionParamConfParam);
240         }
241         if(null != list && !list.isEmpty()) {
ba1a7a 242
C 243             List<String> nodeIdList = new ArrayList<>();
d43481 244             for (int i = 0; i < list.size(); i++) {
C 245                 CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
ba1a7a 246                 nodeIdList.add(result.getGatherAddress());
C 247             }
248
249             List<ReadWriteEntity> readWriteEntityList = new ArrayList<>();
250             if(CollUtil.isNotEmpty(nodeIdList)){
251                 readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
252             }
253
254             List<ParamCollection> paramCollectionlist = new ArrayList<>();
255             if (CollUtil.isNotEmpty(nodeIdList)){
256                 for(int i=0;i<nodeIdList.size();i++){
257                     if(ObjectUtil.isNotEmpty(readWriteEntityList.get(i).getValue())){
258                         CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
259
260                         String value = "0";
261                         if (readWriteEntityList.get(i).getValue() != null){
262                             value = readWriteEntityList.get(i).getValue().toString();
263                         }
264                         if(result.getParamName() != null && result.getParamName().contains("状态")){
265                             if("2".equals(value)){
266                                 value = "不合格";
267                             }else {
268                                 value = "合格";
269                             }
270                         }
271                         ParamCollection paramCollectionParam = new ParamCollection();
272                         paramCollectionParam.setParamCode(result.getParamCode());
273                         paramCollectionParam.setParamName(result.getParamName());
274                         paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
275                         paramCollectionParam.setSfcCode(S_SFC_CODE);
276                         paramCollectionParam.setProductCode(S_PRODUCT_CODE);
277                         paramCollectionParam.setProductionLine(result.getProductionLine());
278                         paramCollectionParam.setLocationCode(result.getLocationCode());
279                         paramCollectionParam.setParamValue(value.toString());
280                         paramCollectionParam.setParamLower(result.getParamLower());
281                         paramCollectionParam.setParamUpper(result.getParamUpper());
282                         paramCollectionParam.setParamStandard(result.getParamCentral());
283                         paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
284                         paramCollectionParam.setUnit(result.getUnit());
285                         paramCollectionParam.setSpareField2(PRODUCT_STATE);
286                         paramCollectionlist.add(paramCollectionParam);
287                     }
6dadf3 288                 }
ba1a7a 289                 paramCollectionService.saveBatch(paramCollectionlist);
d43481 290             }
C 291         }
292
293         logger.info("handleInfo END!");
294     }
295
296 }