package cn.stylefeng.guns.plcserver.callback; import cn.stylefeng.guns.modular.bs.collectionParamConf.model.params.CollectionParamConfParam; import cn.stylefeng.guns.modular.bs.collectionParamConf.model.result.CollectionParamConfResult; import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService; import cn.stylefeng.guns.modular.bs.equipmentInfo.service.EquipmentInfoService; import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService; import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam; import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService; import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam; import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService; import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam; import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService; import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService; import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService; import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService; import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService; import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam; import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.result.ProductionOrderBatchInfoResult; import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.service.ProductionOrderBatchInfoService; import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService; import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService; import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService; import cn.stylefeng.guns.plcserver.opc.GlobalVariable; import cn.stylefeng.guns.plcserver.opc.OPCElement; import cn.stylefeng.guns.plcserver.tool.DateTool; import cn.stylefeng.guns.plcserver.tool.LogUtil; import com.kangaroohy.milo.model.ReadWriteEntity; import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; import com.kangaroohy.milo.service.MiloService; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; @Component public class EOP090BCallback { public MiloService miloService; @Autowired public ProductionOrdeInfoService productionOrdeInfoService; @Autowired public PassingStationCollectionService passingStationCollectionService; @Autowired public ParamCollectionService paramCollectionService; @Autowired public CollectionParamConfService collectionParamConfService; @Autowired public SerialNumbersConfService serialNumbersConfService; @Autowired private EquipmentStatusService equipmentStatusService; @Autowired private EquipmentAlarmService equipmentAlarmService; @Autowired private MaterialTraceabilityService materialTraceabilityService; @Autowired private EquipmentInfoService equipmentInfoService; @Autowired private RepairManageInfoService repairManageInfoService; @Autowired private LocationInfoService locationInfoService; @Autowired private GreaseManageService greaseManageService; @Autowired private ProductionOrderRecordsService productionOrderRecordsService; @Autowired private ProductionOrderBatchInfoService productionOrderBatchInfoService; private static Logger logger; LogUtil logUtil = new LogUtil(); static { logger = Logger.getLogger(EOP090BCallback.class); } private static Date IN_TIME = null; private static String S_ORDER_CODE = "";//工单编号 private static String S_PRODUCT_CODE = "";//产品编号 private static String S_PRODUCT_TYPE= "";//产品类型 private static String S_SFC_CODE = "";//总成编码 private static String PRODUCTION_LINE = "EOP";//产线号 private static String LOCATION_CODE = "EOP090B";//工位号 private static List list = null; public EOP090BCallback(MiloService miloService, ProductionOrdeInfoService productionOrdeInfoService, PassingStationCollectionService passingStationCollectionService, ParamCollectionService paramCollectionService, CollectionParamConfService collectionParamConfService, SerialNumbersConfService serialNumbersConfService, EquipmentStatusService equipmentStatusService, EquipmentAlarmService equipmentAlarmService, MaterialTraceabilityService materialTraceabilityService, EquipmentInfoService equipmentInfoService, RepairManageInfoService repairManageInfoService, LocationInfoService locationInfoService, GreaseManageService greaseManageService, ProductionOrderRecordsService productionOrderRecordsService, ProductionOrderBatchInfoService productionOrderBatchInfoService) { this.miloService = miloService; this.productionOrdeInfoService = productionOrdeInfoService; this.passingStationCollectionService = passingStationCollectionService; this.paramCollectionService = paramCollectionService; this.collectionParamConfService = collectionParamConfService; this.serialNumbersConfService = serialNumbersConfService; this.equipmentStatusService = equipmentStatusService; this.equipmentAlarmService = equipmentAlarmService; this.materialTraceabilityService = materialTraceabilityService; this.equipmentInfoService = equipmentInfoService; this.repairManageInfoService = repairManageInfoService; this.locationInfoService = locationInfoService; this.greaseManageService = greaseManageService; this.productionOrderRecordsService = productionOrderRecordsService; this.productionOrderBatchInfoService = productionOrderBatchInfoService; } //PC读工单 public void handleOrder() throws Exception { logger.info("handleOrder PC处理开始!"); IN_TIME = DateTool.getLocalTimeForDate(); List lists = new ArrayList<>(); lists.add(OPCElement.EOP090B_S_ORDER_CODE); lists.add(OPCElement.EOP090B_S_PRODUCT_CODE); lists.add(OPCElement.EOP090B_S_SFC_CODE); List returnLists= miloService.readFromOpcUa(lists); returnLists.forEach(element->{ switch(element.getIdentifier()){ case OPCElement.EOP090B_S_ORDER_CODE: S_ORDER_CODE = element.getValue().toString(); break; case OPCElement.EOP090B_S_PRODUCT_CODE: S_PRODUCT_TYPE = element.getValue().toString(); S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); break; case OPCElement.EOP090B_S_SFC_CODE: S_SFC_CODE = element.getValue().toString(); break; default: break; } }); ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090B_J_PC_WRITE_ORDER,true); miloService.writeToOpcUa(entity); logger.info("handleOrder PC处理完成!"); } public void handleFinsh() throws Exception { logger.info("handleFinsh PC处理开始!"); String S_PRODUCT_STATE_CODE = miloService. readFromOpcUa(OPCElement.EOP090B_S_PRODUCT_STATE_CODE) .getValue().toString(); //处理过站信息 PassingStationCollectionParam param = new PassingStationCollectionParam(); param.setWorkOrderNo(S_ORDER_CODE); param.setProductCode(S_PRODUCT_CODE); param.setSfcCode(S_SFC_CODE); param.setProductionLine(PRODUCTION_LINE); param.setLocationCode(LOCATION_CODE); param.setInboundTime(IN_TIME); param.setOutboundTime(DateTool.getLocalTimeForDate()); param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格 passingStationCollectionService.add(param); ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090B_J_PC_FINISH,true); miloService.writeToOpcUa(entity);//写PC完成 logger.info("handleFinsh PC处理完成!"); } public void handleMaterial() { //查询批次上料信息 ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); List list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); for(int i=0;i0 ){ //新增物料追溯 MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam(); materialTraceabilityParam.setWorkOrderNo(S_ORDER_CODE); materialTraceabilityParam.setProductCode(S_PRODUCT_CODE); materialTraceabilityParam.setProductNo(S_SFC_CODE); materialTraceabilityParam.setLineCode(PRODUCTION_LINE); materialTraceabilityParam.setLocationCode(LOCATION_CODE); materialTraceabilityParam.setAssemblyQty(1); materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate()); materialTraceabilityParam.setMaterialCode(productionOrderBatchInfoResult.getMaterialCode());//物料编码 materialTraceabilityParam.setMaterialBatchNo(productionOrderBatchInfoResult.getBatch());//物料批次 materialTraceabilityService.add(materialTraceabilityParam); //更新剩余数量 productionOrderBatchInfoParam.setId(productionOrderBatchInfoResult.getId()); productionOrderBatchInfoParam.setResidueQuantity(remainingQuantity-1);//剩余数量 productionOrderBatchInfoService.update(productionOrderBatchInfoParam); } } } }