cl
2024-05-23 ba1a7a9ef126296e2798e313dc5b43f775a1123c
提交 | 用户 | 时间
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 EOP010Callback {
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(EOP010Callback.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  = "EOP010";//工位号
91     private static List list = null;
92
93     public EOP010Callback(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     }
124
125     //PC读工单
126     public void handleOrder() throws Exception {
127         logger.info("handleOrder PC处理开始!");
128         IN_TIME = DateTool.getLocalTimeForDate();
129         List<String> lists = new ArrayList<>();
130         lists.add(OPCElement.EOP010_S_ORDER_CODE);
131         lists.add(OPCElement.EOP010_S_PRODUCT_CODE);
132         lists.add(OPCElement.EOP010_S_SFC_CODE);
133         List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
134         returnLists.forEach(element->{
135             switch(element.getIdentifier()){
136                 case OPCElement.EOP010_S_ORDER_CODE:
137                     S_ORDER_CODE = element.getValue().toString();
138                     break;
139                 case OPCElement.EOP010_S_PRODUCT_CODE:
140                     S_PRODUCT_TYPE = element.getValue().toString();
141                     S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
142                     break;
143                 case OPCElement.EOP010_S_SFC_CODE:
144                     S_SFC_CODE = element.getValue().toString();
145                     break;
146                 default:
147                     break;
148             }
149         });
150         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP010_J_PC_WRITE_ORDER,true);
151         miloService.writeToOpcUa(entity);
152         logger.info("handleOrder PC处理完成!");
153     }
154
155     public void handleFinsh() throws Exception {
156         logger.info("handleFinsh PC处理开始!");
157         String S_PRODUCT_STATE_CODE = miloService.
158                 readFromOpcUa(OPCElement.EOP010_S_PRODUCT_STATE_CODE)
159                 .getValue().toString();
73bc06 160         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP010_J_PC_FINISH,true);
C 161         miloService.writeToOpcUa(entity);//写PC完成
d43481 162         //处理过站信息
C 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
73bc06 174
d43481 175         logger.info("handleFinsh PC处理完成!");
C 176     }
177
178
179     public void handleMaterial() throws Exception{
ba1a7a 180         if(S_ORDER_CODE.isEmpty()){
C 181             return;
182         }
d43481 183         String materialCode = miloService.
C 184                 readFromOpcUa(OPCElement.EOP010_S_MATERIAL_CODE)
185                 .getValue().toString();
186         MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
187         materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
188         materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
189         materialTraceabilityParam.setProductNo(S_SFC_CODE);
190         materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
191         materialTraceabilityParam.setLocationCode(LOCATION_CODE);
192         materialTraceabilityParam.setMaterialCode(materialCode);
193         materialTraceabilityParam.setAssemblyQty(1);
194         materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
195         materialTraceabilityService.add(materialTraceabilityParam);
196
197         //查询批次上料信息
198         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
199         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
200         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
201         List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
202         for(int i=0;i<list1.size();i++){
203             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i);
204
205             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
206             if(remainingQuantity>0 ){
207                 //新增物料追溯
208                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
209                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
210                 materialTraceabilityService.add(materialTraceabilityParam);
211
212                 //更新剩余数量
213                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
214                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
215                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
216             }
217         }
218
219     }
220
221 }