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