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