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