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.model.params.LocationInfoParam; import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult; 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.model.params.ProductionOrdeInfoParam; import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult; 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.model.params.ProductionOrderRecordsParam; import cn.stylefeng.guns.modular.om.productionOrderRecords.model.result.ProductionOrderRecordsResult; import cn.stylefeng.guns.modular.om.productionOrderRecords.service.ProductionOrderRecordsService; import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam; import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult; import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService; import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam; import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult; 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.opc.unit.OPCUnit; import cn.stylefeng.guns.plcserver.opc.unit.SFCCodeTool; 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.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.*; @Component public class COP010Callback { 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(COP010Callback.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 = "COP";//产线号 private static String LOCATION_CODE = "COP010";//工位号 private static List list = null; public COP010Callback(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; } public void handleOrder() throws Exception{ IN_TIME = DateTool.getLocalTimeForDate(); ProductionOrdeInfoParam param = new ProductionOrdeInfoParam(); param.setProductionLine("");//产线 param.setOrderStatus("3");//工单状态 List list = productionOrdeInfoService.findListBySpec(param); if(list.size()>0) { ProductionOrdeInfoResult result = list.get(0); S_ORDER_CODE = result.getWorkOrderNo(); S_PRODUCT_CODE = result.getMaterialCode(); S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE); //自动生成唯一码 Random random = new Random(System.currentTimeMillis()); S_SFC_CODE = "COP"+random.nextLong(); List lists = new ArrayList<>(); lists.add(new ReadWriteEntity(OPCElement.COP010_S_ORDER_CODE,S_ORDER_CODE)); lists.add(new ReadWriteEntity(OPCElement.COP010_S_PRODUCT_CODE,Short.parseShort(S_PRODUCT_TYPE))); lists.add(new ReadWriteEntity(OPCElement.COP010_S_SFC_CODE,S_SFC_CODE)); lists.add(new ReadWriteEntity(OPCElement.COP010_S_NUMBER,Short.parseShort(result.getPlanQty().toString()))); lists.add(new ReadWriteEntity(OPCElement.COP010_J_PC_WRITE_ORDER,true)); miloService.writeToOpcUa(lists); logger.info("COP010工位,handleOrder PC处理完成!2"); }else{ logger.info("COP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!"); } } public void handleFinsh() throws Exception { logger.info("handleFinsh PC处理开始!"); String S_PRODUCT_STATE_CODE = miloService. readFromOpcUa(OPCElement.COP010_S_PRODUCT_STATE_CODE) .getValue().toString(); ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP010_J_PC_FINISH,true); miloService.writeToOpcUa(entity);//写PC完成 //处理过站信息 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); 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); } } } //PC读参数信息 public void handleInfo() throws Exception { logger.info("handleInfo START!"); if(null == list){ CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam(); collectionParamConfParam.setLocationCode(LOCATION_CODE); list = collectionParamConfService.findListBySpec(collectionParamConfParam); } if(null != list && !list.isEmpty()) { for (int i = 0; i < list.size(); i++) { CollectionParamConfResult result = (CollectionParamConfResult) list.get(i); Object value = miloService. readFromOpcUa(result.getGatherAddress()) .getValue();//读参数值 if(null != value) { ParamCollectionParam paramCollectionParam = new ParamCollectionParam(); paramCollectionParam.setParamCode(result.getParamCode()); paramCollectionParam.setParamName(result.getParamName()); paramCollectionParam.setWorkOrderNo(S_ORDER_CODE); paramCollectionParam.setSfcCode(S_SFC_CODE); paramCollectionParam.setProductCode(S_PRODUCT_CODE); paramCollectionParam.setProductionLine(result.getProductionLine()); paramCollectionParam.setLocationCode(result.getLocationCode()); paramCollectionParam.setParamValue(value.toString()); paramCollectionParam.setParamLower(result.getParamLower()); paramCollectionParam.setParamUpper(result.getParamUpper()); paramCollectionParam.setParamStandard(result.getParamCentral()); paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate()); paramCollectionParam.setUnit(result.getUnit()); paramCollectionService.add(paramCollectionParam); } } } logger.info("handleInfo END!"); } public void handleRepair() throws Exception{ RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam(); repairManageInfoParam.setLocationCode(LOCATION_CODE); repairManageInfoParam.setManageType("2"); repairManageInfoParam.setUpPlc("0"); List list = repairManageInfoService.findListBySpec(repairManageInfoParam); if(list.size()>0) { RepairManageInfoResult result = list.get(0); //自动生成唯一码 Random random = new Random(System.currentTimeMillis()); S_SFC_CODE = "COP" + random.nextLong(); S_ORDER_CODE = result.getWorkOrderNo(); S_PRODUCT_CODE = result.getProductCode(); S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE); String repairLocation = result.getPoorLocationCode();// //根据工位编码查询工位表中配置的返修工位号 LocationInfoParam param = new LocationInfoParam(); param.setLocationCode(repairLocation); List results = locationInfoService.findListBySpec(param); if(results.size()>0) { LocationInfoResult r = results.get(0); String repairLocationNo = r.getSpareField2(); if(null != repairLocationNo && "" != repairLocationNo){ List lists = new ArrayList<>(); lists.add(new ReadWriteEntity(OPCElement.COP010_S_ORDER_CODE,S_ORDER_CODE)); lists.add(new ReadWriteEntity(OPCElement.COP010_S_PRODUCT_CODE,Short.parseShort(S_PRODUCT_TYPE))); lists.add(new ReadWriteEntity(OPCElement.COP010_S_SFC_CODE,S_SFC_CODE)); lists.add(new ReadWriteEntity(OPCElement.COP010_P_REPAIR_LOCATION,repairLocationNo)); lists.add(new ReadWriteEntity(OPCElement.COP010_J_PC_WRITE_ORDER,true)); miloService.writeToOpcUa(lists); //更新为已经返修上线 Long id = result.getId(); repairManageInfoParam.setId(id); repairManageInfoParam.setUpPlc("1"); repairManageInfoService.update(repairManageInfoParam); }else{ logger.info("COP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!"); } }else{ logger.info("COP010工位,handleRepair 无法查询到"+repairLocation+"工位!"); } } } }