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