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 BOP040BCallback{
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(BOP040BCallback.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  = "BOP";//产线号
90     private static String LOCATION_CODE  = "BOP040B";//工位号
91     private static List list = null;
92
93     public BOP040BCallback(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.BOP040B_S_ORDER_CODE);
131         lists.add(OPCElement.BOP040B_S_PRODUCT_CODE);
132         lists.add(OPCElement.BOP040B_S_SFC_CODE);
133         List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
134         returnLists.forEach(element->{
135             switch(element.getIdentifier()){
136                 case OPCElement.BOP040B_S_ORDER_CODE:
137                     S_ORDER_CODE = element.getValue().toString();
138                     break;
139                 case OPCElement.BOP040B_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.BOP040B_S_SFC_CODE:
144                     S_SFC_CODE = element.getValue().toString();
145                     break;
146                 default:
147                     break;
148             }
149         });
150         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040B_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.BOP040B_S_PRODUCT_STATE_CODE)
159                 .getValue().toString();
160
73bc06 161         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040B_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
175         logger.info("handleFinsh PC处理完成!");
176     }
177
178     public void handleMaterial() {
179
180         //查询批次上料信息
181         ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
182         productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);
183         productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE);
184         List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam);
185         for(int i=0;i<list.size();i++){
186             ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i);
187             int remainingQuantity =  productionOrderBatchInfoResult.getResidueQuantity();//剩余数量
188             if(remainingQuantity>0 ){
189                 //新增物料追溯
190                 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
191                 materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE);
192                 materialTraceabilityParam.setProductCode(S_PRODUCT_CODE);
193                 materialTraceabilityParam.setProductNo(S_SFC_CODE);
194                 materialTraceabilityParam.setLineCode(PRODUCTION_LINE);
195                 materialTraceabilityParam.setLocationCode(LOCATION_CODE);
196                 materialTraceabilityParam.setAssemblyQty(1);
197                 materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate());
198                 materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码
199                 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次
200
201                 materialTraceabilityService.add(materialTraceabilityParam);
202                 //更新剩余数量
203                 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId());
204                 productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量
205                 productionOrderBatchInfoService.update(productionOrderBatchInfoParam);
206             }
207         }
208     }
209
210
211
212 }