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 BOP030Callback {
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(BOP030Callback.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  = "BOP030";//工位号
91     private static List list = null;
92
93     public BOP030Callback(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.BOP030_S_ORDER_CODE);
132         lists.add(OPCElement.BOP030_S_PRODUCT_CODE);
133         lists.add(OPCElement.BOP030_S_SFC_CODE);
134         List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists);
135         returnLists.forEach(element->{
136             switch(element.getIdentifier()){
137                 case OPCElement.BOP030_S_ORDER_CODE:
138                     S_ORDER_CODE = element.getValue().toString();
139                     break;
140                 case OPCElement.BOP030_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.BOP030_S_SFC_CODE:
145                     S_SFC_CODE = element.getValue().toString();
146                     break;
147                 default:
148                     break;
149             }
150         });
151         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_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.BOP030_S_PRODUCT_STATE_CODE)
160                 .getValue().toString();
73bc06 161         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_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     public void handleMaterial() {
ba1a7a 180         if(S_ORDER_CODE.isEmpty()){
C 181             return;
182         }
d43481 183         //查询批次上料信息
C 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
214 }