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