From d434812c124e2dab22487f8d40d8ad6c3b8ad19c Mon Sep 17 00:00:00 2001 From: cl <418351270@qq.com> Date: 星期六, 20 一月 2024 11:54:37 +0800 Subject: [PATCH] 修改数据采集 --- guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP020Callback.java | 298 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP040Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP070Callback.java | 298 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP150Callback.java | 298 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/opc/GlobalVariable.java | 4 guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP010Callback.java | 347 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP090Callback.java | 332 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP020Callback.java | 284 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120BCallback.java | 298 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP010Callback.java | 290 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130Callback.java | 298 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/InitCallback.java | 1162 ++++ guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP050Callback.java | 338 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/init/CustomRunner.java | 817 +++ guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP070Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP030Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP030Callback.java | 297 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP110Callback.java | 298 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130BCallback.java | 297 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP020Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP050Callback.java | 282 + guns-vip-main/pom.xml | 17 guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP160Callback.java | 298 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP010Callback.java | 420 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP010Callback.java | 351 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090BCallback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/StateCallback.java | 293 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP030Callback.java | 284 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP080Callback.java | 349 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030BCallback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP140Callback.java | 298 + guns-vip-main/src/main/resources/application.yml | 12 guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP020Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP080Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP020Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120Callback.java | 298 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP060Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040Callback.java | 282 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP010Callback.java | 343 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP170Callback.java | 315 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP040Callback.java | 297 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP100Callback.java | 298 + guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040BCallback.java | 282 + 45 files changed, 14,056 insertions(+), 3 deletions(-) diff --git a/guns-vip-main/pom.xml b/guns-vip-main/pom.xml index ed76981..cff8f13 100644 --- a/guns-vip-main/pom.xml +++ b/guns-vip-main/pom.xml @@ -135,6 +135,23 @@ <artifactId>spring-boot-starter-websocket</artifactId> </dependency> + <dependency> + <groupId>com.kangaroohy</groupId> + <artifactId>milo-spring-boot-starter</artifactId> + <version>3.0.5</version> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-pool2</artifactId> + <version>2.12.0</version> + </dependency> + + <!-- https://mvnrepository.com/artifact/com.google.guava/guava --> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>33.0.0-jre</version> + </dependency> </dependencies> <build> diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP010Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP010Callback.java new file mode 100644 index 0000000..9975968 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP010Callback.java @@ -0,0 +1,347 @@ +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.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.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.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; +import java.util.Random; + +@Component +public class BOP010Callback implements SubscriptionCallback { + + 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(BOP010Callback.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 = "BOP";//浜х嚎鍙� + private static String LOCATION_CODE = "BOP010";//宸ヤ綅鍙� + private static List list = null; + + public BOP010Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.COP010_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP010_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.BOP010_J_PLC_START)){ + if("true".equals(value.toString())){ + String isRepair = miloService. + readFromOpcUa(OPCElement.BOP010_P_REPAIR) + .getValue().toString();//鏄惁杩斾慨 + if(isRepair.equals("true")){ + handleRepair(); + }else{ + handleOrder(); + } + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.BOP010_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("BOP010鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + public void handleOrder() throws Exception{ + + IN_TIME = DateTool.getLocalTimeForDate(); + ProductionOrdeInfoParam param = new ProductionOrdeInfoParam(); + param.setProductionLine("");//浜х嚎 + param.setOrderStatus("3");//宸ュ崟鐘舵�� + List<ProductionOrdeInfoResult> 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 = "BOP"+random.nextLong(); + + List<ReadWriteEntity> lists = new ArrayList<>(); + lists.add(new ReadWriteEntity(OPCElement.BOP010_S_ORDER_CODE,S_ORDER_CODE)); + lists.add(new ReadWriteEntity(OPCElement.BOP010_S_PRODUCT_CODE,S_PRODUCT_TYPE)); + lists.add(new ReadWriteEntity(OPCElement.BOP010_S_SFC_CODE,S_SFC_CODE)); + lists.add(new ReadWriteEntity(OPCElement.BOP010_S_NUMBER,result.getPlanQty().toString())); + lists.add(new ReadWriteEntity(OPCElement.BOP010_J_PC_WRITE_ORDER,true)); + miloService.writeToOpcUa(lists); + + logger.info("BOP010宸ヤ綅,handleOrder PC澶勭悊瀹屾垚锛�2"); + }else{ + logger.info("BOP010宸ヤ綅娌℃湁鍙墽琛岀殑宸ュ崟,璇疯仈绯诲伐鍗曠鐞嗗憳涓嬪彂璇ヤ骇绾跨殑宸ュ崟锛�"); + } + } + + public void handleFinsh() throws Exception { + logger.info("handleFinsh PC澶勭悊寮�濮嬶紒"); + String S_PRODUCT_STATE_CODE = miloService. + readFromOpcUa(OPCElement.BOP010_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.BOP010_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam); + if(list.size()>0) { + RepairManageInfoResult result = list.get(0); + + //鑷姩鐢熸垚鍞竴鐮� + Random random = new Random(System.currentTimeMillis()); + S_SFC_CODE = "BOP" + 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<LocationInfoResult> results = locationInfoService.findListBySpec(param); + if(results.size()>0) { + LocationInfoResult r = results.get(0); + String repairLocationNo = r.getSpareField2(); + if(null != repairLocationNo && "" != repairLocationNo){ + List<ReadWriteEntity> lists = new ArrayList<>(); + lists.add(new ReadWriteEntity(OPCElement.BOP010_S_ORDER_CODE,S_ORDER_CODE)); + lists.add(new ReadWriteEntity(OPCElement.BOP010_S_PRODUCT_CODE,S_PRODUCT_TYPE)); + lists.add(new ReadWriteEntity(OPCElement.BOP010_S_SFC_CODE,S_SFC_CODE)); + lists.add(new ReadWriteEntity(OPCElement.BOP010_P_REPAIR_LOCATION,repairLocationNo)); + lists.add(new ReadWriteEntity(OPCElement.BOP010_J_PC_WRITE_ORDER,true)); + miloService.writeToOpcUa(lists); + //鏇存柊涓哄凡缁忚繑淇笂绾� + Long id = result.getId(); + repairManageInfoParam.setId(id); + repairManageInfoParam.setUpPlc("1"); + repairManageInfoService.update(repairManageInfoParam); + + }else{ + logger.info("BOP010宸ヤ綅,handleRepair 璇锋煡璇�"+repairLocation+"宸ヤ綅鏄惁閰嶇疆杩斾慨宸ヤ綅鍙凤紒"); + } + }else{ + logger.info("BOP010宸ヤ綅,handleRepair 鏃犳硶鏌ヨ鍒�"+repairLocation+"宸ヤ綅锛�"); + } + } + } +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP020Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP020Callback.java new file mode 100644 index 0000000..4a3ff29 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP020Callback.java @@ -0,0 +1,282 @@ +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 BOP020Callback implements SubscriptionCallback { + + 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(BOP020Callback.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 = "BOP";//浜х嚎鍙� + private static String LOCATION_CODE = "BOP020";//宸ヤ綅鍙� + private static List list = null; + + public BOP020Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.BOP020_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP020_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.BOP020_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.BOP020_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("BOP020鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP020_S_ORDER_CODE); + lists.add(OPCElement.BOP020_S_PRODUCT_CODE); + lists.add(OPCElement.BOP020_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.BOP020_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.BOP020_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.BOP020_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP020_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.BOP020_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.BOP020_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030BCallback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030BCallback.java new file mode 100644 index 0000000..5466ba2 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030BCallback.java @@ -0,0 +1,282 @@ +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 BOP030BCallback implements SubscriptionCallback { + + 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(BOP030BCallback.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 = "BOP";//浜х嚎鍙� + private static String LOCATION_CODE = "BOP030B";//宸ヤ綅鍙� + private static List list = null; + + public BOP030BCallback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.BOP030B_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030B_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.BOP030B_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.BOP030B_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("BOP030B鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP030B_S_ORDER_CODE); + lists.add(OPCElement.BOP030B_S_PRODUCT_CODE); + lists.add(OPCElement.BOP030B_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.BOP030B_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.BOP030B_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.BOP030B_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030B_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.BOP030B_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.BOP030B_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030Callback.java new file mode 100644 index 0000000..bb4d2d4 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP030Callback.java @@ -0,0 +1,282 @@ +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 BOP030Callback implements SubscriptionCallback { + + 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(BOP030Callback.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 = "BOP";//浜х嚎鍙� + private static String LOCATION_CODE = "BOP030";//宸ヤ綅鍙� + private static List list = null; + + public BOP030Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.BOP030_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.BOP030_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.BOP030_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("BOP030鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP030_S_ORDER_CODE); + lists.add(OPCElement.BOP030_S_PRODUCT_CODE); + lists.add(OPCElement.BOP030_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.BOP030_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.BOP030_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.BOP030_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_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.BOP030_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.BOP030_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040BCallback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040BCallback.java new file mode 100644 index 0000000..12ea71e --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040BCallback.java @@ -0,0 +1,282 @@ +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 BOP040BCallback implements SubscriptionCallback { + + 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(BOP040BCallback.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 = "BOP";//浜х嚎鍙� + private static String LOCATION_CODE = "BOP040B";//宸ヤ綅鍙� + private static List list = null; + + public BOP040BCallback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.BOP040B_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040B_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.BOP040B_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.BOP040B_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("BOP040B鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP040B_S_ORDER_CODE); + lists.add(OPCElement.BOP040B_S_PRODUCT_CODE); + lists.add(OPCElement.BOP040B_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.BOP040B_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.BOP040B_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.BOP040B_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040B_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.BOP040B_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.BOP040B_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040Callback.java new file mode 100644 index 0000000..8bc3cfe --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/BOP040Callback.java @@ -0,0 +1,282 @@ +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 BOP040Callback implements SubscriptionCallback { + + 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(BOP040Callback.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 = "BOP";//浜х嚎鍙� + private static String LOCATION_CODE = "BOP040";//宸ヤ綅鍙� + private static List list = null; + + public BOP040Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.BOP040_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.BOP040_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.BOP040_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("BOP040鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP040_S_ORDER_CODE); + lists.add(OPCElement.BOP040_S_PRODUCT_CODE); + lists.add(OPCElement.BOP040_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.BOP040_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.BOP040_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.BOP040_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040_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.BOP040_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.BOP040_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP010Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP010Callback.java new file mode 100644 index 0000000..e71259b --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP010Callback.java @@ -0,0 +1,351 @@ +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 implements SubscriptionCallback { + + 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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.COP010_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP010_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.COP010_J_PLC_START)){ + if("true".equals(value.toString())){ + String isRepair = miloService. + readFromOpcUa(OPCElement.COP010_P_REPAIR) + .getValue().toString();//鏄惁杩斾慨 + if(isRepair.equals("true")){ + handleRepair(); + }else{ + handleOrder(); + } + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.COP010_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("COP010鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + System.out.println("finally" +ecpStr); + } + } + + public void handleOrder() throws Exception{ + + IN_TIME = DateTool.getLocalTimeForDate(); + ProductionOrdeInfoParam param = new ProductionOrdeInfoParam(); + param.setProductionLine("");//浜х嚎 + param.setOrderStatus("3");//宸ュ崟鐘舵�� + List<ProductionOrdeInfoResult> 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<ReadWriteEntity> lists = new ArrayList<>(); + lists.add(new ReadWriteEntity(OPCElement.COP010_S_ORDER_CODE,S_ORDER_CODE)); + lists.add(new ReadWriteEntity(OPCElement.COP010_S_PRODUCT_CODE,S_PRODUCT_TYPE)); + lists.add(new ReadWriteEntity(OPCElement.COP010_S_SFC_CODE,S_SFC_CODE)); + lists.add(new ReadWriteEntity(OPCElement.COP010_S_NUMBER,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(); + + //澶勭悊杩囩珯淇℃伅 + 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.COP010_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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<RepairManageInfoResult> 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<LocationInfoResult> results = locationInfoService.findListBySpec(param); + if(results.size()>0) { + LocationInfoResult r = results.get(0); + String repairLocationNo = r.getSpareField2(); + if(null != repairLocationNo && "" != repairLocationNo){ + List<ReadWriteEntity> lists = new ArrayList<>(); + lists.add(new ReadWriteEntity(OPCElement.COP010_S_ORDER_CODE,S_ORDER_CODE)); + lists.add(new ReadWriteEntity(OPCElement.COP010_S_PRODUCT_CODE,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+"宸ヤ綅锛�"); + } + } + } +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP020Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP020Callback.java new file mode 100644 index 0000000..f6647c9 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP020Callback.java @@ -0,0 +1,284 @@ +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.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.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 COP020Callback implements SubscriptionCallback { + + 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(COP020Callback.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 = "COP020";//宸ヤ綅鍙� + private static List list = null; + + public COP020Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.COP020_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP020_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.COP020_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.COP020_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.COP020_S_ORDER_CODE); + lists.add(OPCElement.COP020_S_PRODUCT_CODE); + lists.add(OPCElement.COP020_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.COP020_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.COP020_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.COP020_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP020_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.COP020_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.COP020_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP030Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP030Callback.java new file mode 100644 index 0000000..b3c5781 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/COP030Callback.java @@ -0,0 +1,284 @@ +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.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.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 COP030Callback implements SubscriptionCallback { + + 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(COP020Callback.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 = "COP030";//宸ヤ綅鍙� + private static List list = null; + + public COP030Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.COP030_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP030_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.COP030_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.COP030_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.COP030_S_ORDER_CODE); + lists.add(OPCElement.COP030_S_PRODUCT_CODE); + lists.add(OPCElement.COP030_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.COP030_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.COP030_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.COP030_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP030_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.COP030_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.COP030_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP010Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP010Callback.java new file mode 100644 index 0000000..81a7e56 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP010Callback.java @@ -0,0 +1,343 @@ +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.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.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.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; +import java.util.Random; + +@Component +public class DOP010Callback implements SubscriptionCallback { + + 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(DOP010Callback.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 = "BOP";//浜х嚎鍙� + private static String LOCATION_CODE = "DOP010";//宸ヤ綅鍙� + private static List list = null; + + public DOP010Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.COP010_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP010_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.DOP010_J_PLC_START)){ + if("true".equals(value.toString())){ + String isRepair = miloService. + readFromOpcUa(OPCElement.DOP010_P_REPAIR) + .getValue().toString();//鏄惁杩斾慨 + if(isRepair.equals("true")){ + handleRepair(); + }else{ + handleOrder(); + } + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.DOP010_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + //handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + public void handleOrder() throws Exception{ + IN_TIME = DateTool.getLocalTimeForDate(); + ProductionOrdeInfoParam param = new ProductionOrdeInfoParam(); + param.setProductionLine("");//浜х嚎 + param.setOrderStatus("3");//宸ュ崟鐘舵�� + List<ProductionOrdeInfoResult> 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 = "EOP"+ random.nextLong(); + + List<ReadWriteEntity> lists = new ArrayList<>(); + lists.add(new ReadWriteEntity(OPCElement.DOP010_S_ORDER_CODE,S_ORDER_CODE)); + lists.add(new ReadWriteEntity(OPCElement.DOP010_S_PRODUCT_CODE,S_PRODUCT_TYPE)); + lists.add(new ReadWriteEntity(OPCElement.DOP010_S_SFC_CODE,S_SFC_CODE)); + lists.add(new ReadWriteEntity(OPCElement.DOP010_S_NUMBER,result.getPlanQty().toString())); + lists.add(new ReadWriteEntity(OPCElement.DOP010_J_PC_WRITE_ORDER,true)); + miloService.writeToOpcUa(lists); + logger.info("DOP010宸ヤ綅,handleOrder PC澶勭悊瀹屾垚锛�"); + }else{ + logger.info("DOP010宸ヤ綅娌℃湁鍙墽琛岀殑宸ュ崟,璇疯仈绯诲伐鍗曠鐞嗗憳涓嬪彂璇ヤ骇绾跨殑宸ュ崟锛�"); + } + } + + public void handleFinsh() throws Exception { + logger.info("handleFinsh PC澶勭悊寮�濮嬶紒"); + String S_PRODUCT_STATE_CODE = miloService. + readFromOpcUa(OPCElement.DOP010_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.DOP010_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam); + if(list.size()>0) { + RepairManageInfoResult result = list.get(0); + + //鑷姩鐢熸垚鍞竴鐮� + Random random = new Random(System.currentTimeMillis()); + S_SFC_CODE = "BOP" + 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<LocationInfoResult> results = locationInfoService.findListBySpec(param); + if(results.size()>0) { + LocationInfoResult r = results.get(0); + String repairLocationNo = r.getSpareField2(); + if(null != repairLocationNo && "" != repairLocationNo){ + List<ReadWriteEntity> lists = new ArrayList<>(); + lists.add(new ReadWriteEntity(OPCElement.DOP010_S_ORDER_CODE,S_ORDER_CODE)); + lists.add(new ReadWriteEntity(OPCElement.DOP010_S_PRODUCT_CODE,S_PRODUCT_TYPE)); + lists.add(new ReadWriteEntity(OPCElement.DOP010_S_SFC_CODE,S_SFC_CODE)); + lists.add(new ReadWriteEntity(OPCElement.DOP010_P_REPAIR_LOCATION,repairLocationNo)); + lists.add(new ReadWriteEntity(OPCElement.DOP010_J_PC_WRITE_ORDER,true)); + miloService.writeToOpcUa(lists); + //鏇存柊涓哄凡缁忚繑淇笂绾� + Long id = result.getId(); + repairManageInfoParam.setId(id); + repairManageInfoParam.setUpPlc("1"); + repairManageInfoService.update(repairManageInfoParam); + + }else{ + logger.info("DOP010宸ヤ綅,handleRepair 璇锋煡璇�"+repairLocation+"宸ヤ綅鏄惁閰嶇疆杩斾慨宸ヤ綅鍙凤紒"); + } + }else{ + logger.info("DOP010宸ヤ綅,handleRepair 鏃犳硶鏌ヨ鍒�"+repairLocation+"宸ヤ綅锛�"); + } + } + } +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP020Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP020Callback.java new file mode 100644 index 0000000..37a6f52 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/DOP020Callback.java @@ -0,0 +1,282 @@ +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 DOP020Callback implements SubscriptionCallback { + + 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(DOP020Callback.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 = "DOP020";//宸ヤ綅鍙� + private static List list = null; + + public DOP020Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.DOP020_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.DOP020_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.DOP020_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.DOP020_S_ORDER_CODE); + lists.add(OPCElement.DOP020_S_PRODUCT_CODE); + lists.add(OPCElement.DOP020_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.DOP020_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.DOP020_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.DOP020_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_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.DOP020_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.DOP020_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP010Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP010Callback.java new file mode 100644 index 0000000..642a826 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP010Callback.java @@ -0,0 +1,290 @@ +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.opc.unit.OPCUnit; +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 EOP010Callback implements SubscriptionCallback { + + 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(EOP010Callback.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 = "EOP010";//宸ヤ綅鍙� + private static List list = null; + + public EOP010Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.EOP010_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP010_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.EOP010_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.EOP010_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP010_S_ORDER_CODE); + lists.add(OPCElement.EOP010_S_PRODUCT_CODE); + lists.add(OPCElement.EOP010_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.EOP010_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.EOP010_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.EOP010_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP010_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.EOP010_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.EOP010_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + + public void handleMaterial() throws Exception{ + String materialCode = miloService. + readFromOpcUa(OPCElement.EOP010_S_MATERIAL_CODE) + .getValue().toString(); + 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.setMaterialCode(materialCode); + materialTraceabilityParam.setAssemblyQty(1); + materialTraceabilityParam.setAssemblyTime(DateTool.getLocalTimeForDate()); + materialTraceabilityService.add(materialTraceabilityParam); + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list1 = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list1.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list1.get(i); + + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP020Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP020Callback.java new file mode 100644 index 0000000..ec43b50 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP020Callback.java @@ -0,0 +1,282 @@ +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 EOP020Callback implements SubscriptionCallback { + + 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(EOP020Callback.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 = "EOP020";//宸ヤ綅鍙� + private static List list = null; + + public EOP020Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.EOP020_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP020_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.EOP020_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.EOP020_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP020_S_ORDER_CODE); + lists.add(OPCElement.EOP020_S_PRODUCT_CODE); + lists.add(OPCElement.EOP020_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.EOP020_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.EOP020_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.EOP020_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP020_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.EOP020_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.EOP020_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP030Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP030Callback.java new file mode 100644 index 0000000..7ef650b --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP030Callback.java @@ -0,0 +1,282 @@ +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 EOP030Callback implements SubscriptionCallback { + + 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(EOP030Callback.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 = "EOP030";//宸ヤ綅鍙� + private static List list = null; + + public EOP030Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.EOP030_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP030_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.EOP030_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.EOP030_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP030_S_ORDER_CODE); + lists.add(OPCElement.EOP030_S_PRODUCT_CODE); + lists.add(OPCElement.EOP030_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.EOP030_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.EOP030_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.EOP030_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP030_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.EOP030_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.EOP030_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP040Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP040Callback.java new file mode 100644 index 0000000..7c1dfb8 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP040Callback.java @@ -0,0 +1,282 @@ +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 EOP040Callback implements SubscriptionCallback { + + 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(EOP040Callback.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 = "EOP040";//宸ヤ綅鍙� + private static List list = null; + + public EOP040Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.EOP040_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP040_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.EOP040_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.EOP040_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP040_S_ORDER_CODE); + lists.add(OPCElement.EOP040_S_PRODUCT_CODE); + lists.add(OPCElement.EOP040_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.EOP040_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.EOP040_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.EOP040_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP040_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.EOP040_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.EOP040_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP050Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP050Callback.java new file mode 100644 index 0000000..24c39e1 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP050Callback.java @@ -0,0 +1,282 @@ +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 EOP050Callback implements SubscriptionCallback { + + 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(EOP050Callback.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 = "EOP050";//宸ヤ綅鍙� + private static List list = null; + + public EOP050Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.EOP050_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP050_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.EOP050_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.EOP050_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP050_S_ORDER_CODE); + lists.add(OPCElement.EOP050_S_PRODUCT_CODE); + lists.add(OPCElement.EOP050_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.EOP050_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.EOP050_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.EOP050_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP050_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.EOP050_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.EOP050_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP060Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP060Callback.java new file mode 100644 index 0000000..e126fcf --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP060Callback.java @@ -0,0 +1,282 @@ +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 EOP060Callback implements SubscriptionCallback { + + 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(EOP060Callback.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 = "EOP060";//宸ヤ綅鍙� + private static List list = null; + + public EOP060Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.EOP060_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP060_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.EOP060_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.EOP060_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP060_S_ORDER_CODE); + lists.add(OPCElement.EOP060_S_PRODUCT_CODE); + lists.add(OPCElement.EOP060_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.EOP060_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.EOP060_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.EOP060_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP060_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.EOP060_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.EOP060_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP070Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP070Callback.java new file mode 100644 index 0000000..92f0d53 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP070Callback.java @@ -0,0 +1,282 @@ +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 EOP070Callback implements SubscriptionCallback { + + 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(EOP070Callback.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 = "EOP070";//宸ヤ綅鍙� + private static List list = null; + + public EOP070Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.EOP070_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP070_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.EOP070_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.EOP070_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP070_S_ORDER_CODE); + lists.add(OPCElement.EOP070_S_PRODUCT_CODE); + lists.add(OPCElement.EOP070_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.EOP070_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.EOP070_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.EOP070_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP070_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.EOP070_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.EOP070_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP080Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP080Callback.java new file mode 100644 index 0000000..bea56b9 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP080Callback.java @@ -0,0 +1,282 @@ +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 EOP080Callback implements SubscriptionCallback { + + 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(EOP080Callback.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 = "EOP080";//宸ヤ綅鍙� + private static List list = null; + + public EOP080Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.EOP080_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP080_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.EOP080_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.EOP080_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP080_S_ORDER_CODE); + lists.add(OPCElement.EOP080_S_PRODUCT_CODE); + lists.add(OPCElement.EOP080_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.EOP080_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.EOP080_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.EOP080_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP080_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.EOP080_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.EOP080_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090BCallback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090BCallback.java new file mode 100644 index 0000000..3a56563 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090BCallback.java @@ -0,0 +1,282 @@ +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 implements SubscriptionCallback { + + 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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.EOP090B_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090B_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.EOP090B_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.EOP090B_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> 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<ReadWriteEntity> 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);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090Callback.java new file mode 100644 index 0000000..38ef32d --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/EOP090Callback.java @@ -0,0 +1,282 @@ +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 EOP090Callback implements SubscriptionCallback { + + 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(EOP090Callback.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 = "EOP090";//宸ヤ綅鍙� + private static List list = null; + + public EOP090Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.EOP090_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.EOP090_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.EOP090_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP090_S_ORDER_CODE); + lists.add(OPCElement.EOP090_S_PRODUCT_CODE); + lists.add(OPCElement.EOP090_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.EOP090_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.EOP090_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.EOP090_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090_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.EOP090_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.EOP090_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/InitCallback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/InitCallback.java new file mode 100644 index 0000000..50da06a --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/InitCallback.java @@ -0,0 +1,1162 @@ +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.model.params.EquipmentInfoParam; +import cn.stylefeng.guns.modular.bs.equipmentInfo.model.result.EquipmentInfoResult; +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.model.params.EquipmentAlarmParam; +import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService; +import cn.stylefeng.guns.modular.em.equipmentStatus.model.params.EquipmentStatusParam; +import cn.stylefeng.guns.modular.em.equipmentStatus.model.result.EquipmentStatusResult; +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.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.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +@Component +public class InitCallback implements SubscriptionCallback { + + 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(InitCallback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP010";//宸ヤ綅鍙� + private static List list = null; + + private static Integer ACTUAL_ONLINE_QTY = 0 ;//涓婄嚎鏁伴噺 + + OP010Callback OP010Callback; + OP020Callback OP020Callback; + OP030Callback OP030Callback; + OP040Callback OP040Callback; + OP050Callback OP050Callback; + OP070Callback OP070Callback; + OP080Callback OP080Callback; + OP090Callback OP090Callback; + OP100Callback OP100Callback; + OP110Callback OP110Callback; + OP120Callback OP120Callback; + OP120BCallback OP120BCallback; + OP130Callback OP130Callback; + OP130BCallback OP130BCallback; + OP140Callback OP140Callback; + OP150Callback OP150Callback; + OP160Callback OP160Callback; + OP170Callback OP170Callback; + BOP010Callback BOP010Callback; + BOP020Callback BOP020Callback; + BOP030Callback BOP030Callback; + BOP030BCallback BOP030BCallback; + BOP040Callback BOP040Callback; + BOP040BCallback BOP040BCallback; + COP010Callback COP010Callback; + COP020Callback COP020Callback; + COP030Callback COP030Callback; + DOP010Callback DOP010Callback; + DOP020Callback DOP020Callback; + EOP010Callback EOP010Callback; + EOP020Callback EOP020Callback; + EOP030Callback EOP030Callback; + EOP040Callback EOP040Callback; + EOP050Callback EOP050Callback; + EOP060Callback EOP060Callback; + EOP070Callback EOP070Callback; + EOP080Callback EOP080Callback; + EOP090Callback EOP090Callback; + EOP090BCallback EOP090BCallback; + + StateCallback StateCallback; + + + public InitCallback(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; + + OP010Callback = new OP010Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP020Callback = new OP020Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP030Callback = new OP030Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP040Callback = new OP040Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP050Callback = new OP050Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + /* OP060Callback = new OP060Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService);*/ + OP070Callback = new OP070Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP080Callback = new OP080Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP090Callback = new OP090Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP100Callback = new OP100Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP110Callback = new OP110Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP120Callback = new OP120Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP120BCallback = new OP120BCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP130Callback = new OP130Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP130BCallback = new OP130BCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP140Callback = new OP140Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP150Callback = new OP150Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP160Callback = new OP160Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + OP170Callback = new OP170Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + COP010Callback = new COP010Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + COP020Callback = new COP020Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + COP030Callback = new COP030Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + BOP010Callback = new BOP010Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + BOP020Callback = new BOP020Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + BOP030Callback = new BOP030Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + BOP030BCallback = new BOP030BCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + BOP040Callback = new BOP040Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + BOP040BCallback = new BOP040BCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + DOP010Callback = new DOP010Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + DOP020Callback = new DOP020Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + EOP010Callback = new EOP010Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + EOP020Callback = new EOP020Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + EOP030Callback = new EOP030Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + EOP040Callback = new EOP040Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + EOP050Callback = new EOP050Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + EOP060Callback = new EOP060Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + EOP070Callback = new EOP070Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + EOP080Callback = new EOP080Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + EOP090Callback = new EOP090Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + EOP090BCallback = new EOP090BCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + + StateCallback = new StateCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + } + + + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + + if(null != value) { + //OP010 + //蹇冭烦 + if (identifier.equals(OPCElement.OP010_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP010_J_PLC_START) && null != value && "true".equals(value.toString())) { + String isRepair = miloService.readFromOpcUa(OPCElement.OP010_P_REPAIR).getValue().toString();//鏄惁杩斾慨 + if (isRepair.equals("true")) { + OP010Callback.handleRepair(); + } else { + OP010Callback.handleOrder(); + } + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP010_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP010Callback.handleFinsh(); + OP010Callback.handleMaterial(); + } + + //OP020 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP020_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP020_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP020_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP020Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP020_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP020Callback.handleFinsh(); + OP020Callback.handleMaterial(); + OP020Callback.handleInfo(); + } + + //OP030 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP030_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP030_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP030_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP030Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP030_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP030Callback.handleFinsh(); + OP030Callback.handleMaterial(); + OP030Callback.handleInfo(); + } + + //OP040 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP040_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP040_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP040_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP040Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP040_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP040Callback.handleFinsh(); + OP040Callback.handleMaterial(); + OP040Callback.handleInfo(); + } + + //OP050 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP050_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP050_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP050Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP050_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP050Callback.handleMaterial(); + OP050Callback.handleInfo(); + OP050Callback.handleFinsh(); + } + + //OP070 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP070_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP070_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP070_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP070Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP070_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP070Callback.handleFinsh(); + OP070Callback.handleMaterial(); + OP070Callback.handleInfo(); + } + + //OP080 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP080_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP080_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP080_J_PLC_START) && null != value && "true".equals(value.toString())) { + String isRepair = miloService.readFromOpcUa(OPCElement.OP080_P_REPAIR).getValue().toString();//鏄惁杩斾慨 + if (isRepair.equals("true")) { + OP080Callback.handleRepair(); + } else { + OP080Callback.handleOrder(); + } + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP080_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP080Callback.handleFinsh(); + OP080Callback.handleMaterial(); + OP080Callback.handleInfo(); + } + + //OP090 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP090_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP090_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP090Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP100_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP100Callback.handleMaterial(); + OP100Callback.handleInfo(); + OP100Callback.handleFinsh(); + } + + //OP110 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP110_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP110_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP110_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP110Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP110_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP110Callback.handleFinsh(); + OP110Callback.handleMaterial(); + OP110Callback.handleInfo(); + } + + //OP120 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP120_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP120_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP120Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP120_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP120Callback.handleFinsh(); + OP120Callback.handleMaterial(); + OP120Callback.handleInfo(); + } + + //OP120B + //蹇冭烦 + else if (identifier.equals(OPCElement.OP120B_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120B_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP120B_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP120BCallback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP120B_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP120BCallback.handleFinsh(); + OP120BCallback.handleMaterial(); + OP120BCallback.handleInfo(); + } + + //OP130 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP130_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP130_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP130Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP130_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP130Callback.handleFinsh(); + OP130Callback.handleMaterial(); + OP130Callback.handleInfo(); + } + + //OP130B + //蹇冭烦 + else if (identifier.equals(OPCElement.OP130B_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130B_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP130B_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP130BCallback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP130B_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP130BCallback.handleFinsh(); + OP130BCallback.handleMaterial(); + OP130BCallback.handleInfo(); + } + + //OP140 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP140_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP140_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP140_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP140Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP140_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP140Callback.handleFinsh(); + OP140Callback.handleMaterial(); + OP140Callback.handleInfo(); + } + + //OP150 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP150_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP150_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP150_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP150Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP150_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP150Callback.handleFinsh(); + OP150Callback.handleMaterial(); + OP150Callback.handleInfo(); + } + + //OP160 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP160_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP160_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP160_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP160Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP160_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP160Callback.handleFinsh(); + OP160Callback.handleMaterial(); + OP160Callback.handleInfo(); + } + + //OP170 + //蹇冭烦 + else if (identifier.equals(OPCElement.OP170_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP170_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.OP170_J_PLC_START) && null != value && "true".equals(value.toString())) { + OP170Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.OP170_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + OP170Callback.handleFinsh(); + OP170Callback.handleMaterial(); + //OP170Callback.handleInfo(); + } + + //BOP010 + //蹇冭烦 + else if (identifier.equals(OPCElement.BOP010_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP010_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.BOP010_J_PLC_START) && null != value && "true".equals(value.toString())) { + String isRepair = miloService.readFromOpcUa(OPCElement.BOP010_P_REPAIR).getValue().toString();//鏄惁杩斾慨 + if (isRepair.equals("true")) { + BOP010Callback.handleRepair(); + } else { + BOP010Callback.handleOrder(); + } + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.BOP010_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + BOP010Callback.handleFinsh(); + BOP010Callback.handleMaterial(); + //BOP010Callback.handleInfo(); + } + + + //BOP020 + //蹇冭烦 + else if (identifier.equals(OPCElement.BOP020_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP020_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.BOP020_J_PLC_START) && null != value && "true".equals(value.toString())) { + BOP020Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.BOP020_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + BOP020Callback.handleFinsh(); + BOP020Callback.handleMaterial(); + BOP020Callback.handleInfo(); + } + + + //BOP030 + //蹇冭烦 + else if (identifier.equals(OPCElement.BOP030_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.BOP030_J_PLC_START) && null != value && "true".equals(value.toString())) { + BOP030Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.BOP030_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + BOP030Callback.handleFinsh(); + BOP030Callback.handleMaterial(); + BOP030Callback.handleInfo(); + } + + //BOP030B + //蹇冭烦 + else if (identifier.equals(OPCElement.BOP030B_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030B_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.BOP030B_J_PLC_START) && null != value && "true".equals(value.toString())) { + BOP030BCallback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.BOP030B_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + BOP030BCallback.handleFinsh(); + //BOP030BCallback.handleMaterial(); + //BOP030BCallback.handleInfo(); + } + + //BOP040 + //蹇冭烦 + else if (identifier.equals(OPCElement.BOP040_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.BOP040_J_PLC_START) && null != value && "true".equals(value.toString())) { + BOP040Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.BOP040_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + BOP040Callback.handleFinsh(); + BOP040Callback.handleMaterial(); + BOP040Callback.handleInfo(); + } + + //BOP040B + //蹇冭烦 + else if (identifier.equals(OPCElement.BOP040B_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP040B_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.BOP040B_J_PLC_START) && null != value && "true".equals(value.toString())) { + BOP040BCallback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.BOP040B_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + BOP040BCallback.handleFinsh(); + // BOP040BCallback.handleMaterial(); + //BOP040BCallback.handleInfo(); + } + + + //COP010 + //蹇冭烦 + else if (identifier.equals(OPCElement.COP010_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP010_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.COP010_J_PLC_START) && null != value && "true".equals(value.toString())) { + String isRepair = miloService.readFromOpcUa(OPCElement.COP010_P_REPAIR).getValue().toString();//鏄惁杩斾慨 + if (isRepair.equals("true")) { + COP010Callback.handleRepair(); + } else { + COP010Callback.handleOrder(); + } + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.COP010_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + COP010Callback.handleFinsh(); + COP010Callback.handleMaterial(); + //COP010Callback.handleInfo(); + } + + + //COP020 + //蹇冭烦 + else if (identifier.equals(OPCElement.COP020_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP020_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.COP020_J_PLC_START) && null != value && "true".equals(value.toString())) { + COP020Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.COP020_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + COP020Callback.handleFinsh(); + COP020Callback.handleMaterial(); + COP020Callback.handleInfo(); + } + + + //COP030 + //蹇冭烦 + else if (identifier.equals(OPCElement.COP030_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.COP030_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.COP030_J_PLC_START) && null != value && "true".equals(value.toString())) { + COP030Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.COP030_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + COP030Callback.handleFinsh(); + COP030Callback.handleMaterial(); + COP030Callback.handleInfo(); + } + + + //DOP010 + //蹇冭烦 + else if (identifier.equals(OPCElement.DOP010_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP010_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.DOP010_J_PLC_START) && null != value && "true".equals(value.toString())) { + String isRepair = miloService.readFromOpcUa(OPCElement.DOP010_P_REPAIR).getValue().toString();//鏄惁杩斾慨 + if (isRepair.equals("true")) { + DOP010Callback.handleRepair(); + } else { + DOP010Callback.handleOrder(); + } + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.DOP010_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + DOP010Callback.handleFinsh(); + DOP010Callback.handleMaterial(); + //DOP010Callback.handleInfo(); + } + + + //DOP020 + //蹇冭烦 + else if (identifier.equals(OPCElement.DOP020_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.DOP020_J_PLC_START) && null != value && "true".equals(value.toString())) { + DOP020Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.DOP020_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + DOP020Callback.handleFinsh(); + DOP020Callback.handleMaterial(); + DOP020Callback.handleInfo(); + } + + //EOP010 + //蹇冭烦 + else if (identifier.equals(OPCElement.EOP010_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP010_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.EOP010_J_PLC_START) && null != value && "true".equals(value.toString())) { + EOP010Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.EOP010_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + EOP010Callback.handleFinsh(); + EOP010Callback.handleMaterial(); + EOP010Callback.handleInfo(); + } + //EOP020 + //蹇冭烦 + else if (identifier.equals(OPCElement.EOP020_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP020_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.EOP020_J_PLC_START) && null != value && "true".equals(value.toString())) { + EOP020Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.EOP020_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + EOP020Callback.handleFinsh(); + EOP020Callback.handleMaterial(); + EOP020Callback.handleInfo(); + } + + //EOP030 + //蹇冭烦 + else if (identifier.equals(OPCElement.EOP030_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP030_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.EOP030_J_PLC_START) && null != value && "true".equals(value.toString())) { + EOP030Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.EOP030_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + EOP030Callback.handleFinsh(); + EOP030Callback.handleMaterial(); + EOP030Callback.handleInfo(); + } + + //EOP040 + //蹇冭烦 + else if (identifier.equals(OPCElement.EOP040_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP040_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.EOP040_J_PLC_START) && null != value && "true".equals(value.toString())) { + EOP040Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.EOP040_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + EOP040Callback.handleFinsh(); + EOP040Callback.handleMaterial(); + EOP040Callback.handleInfo(); + } + + //EOP050 + //蹇冭烦 + else if (identifier.equals(OPCElement.EOP050_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP050_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.EOP050_J_PLC_START) && null != value && "true".equals(value.toString())) { + EOP050Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.EOP050_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + EOP050Callback.handleFinsh(); + EOP050Callback.handleMaterial(); + EOP050Callback.handleInfo(); + } + + //EOP060 + //蹇冭烦 + else if (identifier.equals(OPCElement.EOP060_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP060_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.EOP060_J_PLC_START) && null != value && "true".equals(value.toString())) { + EOP060Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.EOP060_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + EOP060Callback.handleFinsh(); + EOP060Callback.handleMaterial(); + EOP060Callback.handleInfo(); + } + + //EOP070 + //蹇冭烦 + else if (identifier.equals(OPCElement.EOP070_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP070_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.EOP070_J_PLC_START) && null != value && "true".equals(value.toString())) { + EOP070Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.EOP070_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + EOP070Callback.handleFinsh(); + EOP070Callback.handleMaterial(); + EOP070Callback.handleInfo(); + } + + //EOP080 + //蹇冭烦 + else if (identifier.equals(OPCElement.EOP080_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP080_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.EOP080_J_PLC_START) && null != value && "true".equals(value.toString())) { + EOP080Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.EOP080_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + EOP080Callback.handleFinsh(); + EOP080Callback.handleMaterial(); + EOP080Callback.handleInfo(); + } + + //EOP090 + //蹇冭烦 + else if (identifier.equals(OPCElement.EOP090_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.EOP090_J_PLC_START) && null != value && "true".equals(value.toString())) { + EOP090Callback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.EOP090_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + EOP090Callback.handleFinsh(); + EOP090Callback.handleMaterial(); + EOP090Callback.handleInfo(); + } + + //EOP090B + //蹇冭烦 + else if (identifier.equals(OPCElement.EOP090B_F_HEART_BEAT) && null != value && "false".equals(value.toString())) { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.EOP090B_F_HEART_BEAT, true); + miloService.writeToOpcUa(entity); + } + //PLC杩涚珯 + else if (identifier.equals(OPCElement.EOP090B_J_PLC_START) && null != value && "true".equals(value.toString())) { + EOP090BCallback.handleOrder(); + } + //PLC鍑虹珯 + else if (identifier.equals(OPCElement.EOP090B_J_PLC_FINISH) && null != value && "true".equals(value.toString())) { + EOP090BCallback.handleFinsh(); + EOP090BCallback.handleMaterial(); + EOP090BCallback.handleInfo(); + } + + else if (identifier.contains("STATE") && null != value && "true".equals(value.toString())) { + EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam(); + equipmentInfoParam.setSpareField1(identifier); + List<EquipmentInfoResult> lists = equipmentInfoService.findListBySpec(equipmentInfoParam); + if(!lists.isEmpty()){ + EquipmentInfoResult result = (EquipmentInfoResult) list.get(0); + String equipmentNo = result.getEquipmentNo(); + EquipmentStatusParam equipmentStatusParam = new EquipmentStatusParam(); + equipmentStatusParam.setEquipmentNo(equipmentNo); + List statuslist = equipmentStatusService.findListBySpec(equipmentStatusParam); + if(statuslist.size()>0){ + EquipmentStatusResult equipmentStatusResult = (EquipmentStatusResult) statuslist.get(0); + if(!value.equals(equipmentStatusResult.getStatus())){ + equipmentStatusParam.setId(equipmentStatusResult.getId()); + equipmentStatusParam.setStatus(value.toString()); + equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate()); + equipmentStatusService.update(equipmentStatusParam);//鏇存柊璁惧鐘舵�� + + //娣诲姞璁惧鎶ヨ + if("3".equals(value)){ + EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam(); + equipmentAlarmParam.setEquipmentNo(equipmentNo); + equipmentAlarmParam.setEquipmentName(result.getEquipmentName()); + equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode()); + equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode()); + equipmentAlarmParam.setLocationCode(result.getLocationCode()); + equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"鎶ヨ锛�"); + equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate()); + equipmentAlarmService.add(equipmentAlarmParam); + } + } + + }else{ + equipmentStatusParam.setEquipmentName(result.getEquipmentName()); + equipmentStatusParam.setWorkshopCode(result.getWorkshopCode()); + equipmentStatusParam.setProductionLineCode(result.getProductionLineCode()); + equipmentStatusParam.setLocationCode(result.getLocationCode()); + equipmentStatusParam.setStatus(value.toString()); + equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate()); + equipmentStatusService.add(equipmentStatusParam); + + //娣诲姞璁惧鎶ヨ + if("3".equals(value)){ + EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam(); + equipmentAlarmParam.setEquipmentNo(equipmentNo); + equipmentAlarmParam.setEquipmentName(result.getEquipmentName()); + equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode()); + equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode()); + equipmentAlarmParam.setLocationCode(result.getLocationCode()); + equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"鎶ヨ锛�"); + equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate()); + equipmentAlarmService.add(equipmentAlarmParam); + } + } + } + + + // handleOilState("DOP020"); + StateCallback.handleOilStateOP050("OP050"); + StateCallback.handleOilStateBOP030("BOP030"); + } + + else { + System.out.println("鍊兼病鏈夊彉"); + } + + + }else { + System.out.println("鍊间负绌�"); + } + + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + System.out.println(ecpStr+"\r\n"); + logger.info(ecpStr+"\r\n"); + } + } + } + + + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP010Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP010Callback.java new file mode 100644 index 0000000..5ad2729 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP010Callback.java @@ -0,0 +1,420 @@ +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.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +@Component +public class OP010Callback implements SubscriptionCallback { + + 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(OP010Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP010";//宸ヤ綅鍙� + private static List list = null; + + private static Integer ACTUAL_ONLINE_QTY = 0 ;//涓婄嚎鏁伴噺 + public OP010Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP010_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP010_J_PLC_START)){ + if("true".equals(value.toString())){ + + String isRepair = miloService. + readFromOpcUa(OPCElement.OP010_P_REPAIR) + .getValue().toString();//鏄惁杩斾慨 + if(isRepair.equals("true")){ + handleRepair(); + }else{ + handleOrder(); + } + + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP010_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + System.out.println("finally" +ecpStr); + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception{ + + logger.info("OP010宸ヤ綅,handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + ProductionOrdeInfoParam param = new ProductionOrdeInfoParam(); + param.setProductionLine("");//浜х嚎 + param.setOrderStatus("3");//宸ュ崟鐘舵�� + List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param); + + if(!list.isEmpty()) { + ProductionOrdeInfoResult result = list.get(0); + + String softwareVersionCode = result.getSoftwareVersionCode();//浜у搧鍨嬪彿 + String productCompanyCode = result.getProductCompanyCode();//鐝 + + //搴忓垪鍙� + String serialNumbers = "0000"; + SerialNumbersConfParam serialNumbersConfParam = new SerialNumbersConfParam(); + Calendar calendar = Calendar.getInstance(); + String Years = String.valueOf(calendar.get(Calendar.YEAR)); //骞翠唤 + String Months = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH) + 1),2, "0"); //鏈堜唤 + String Dates = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)),2, "0"); //鏃ユ湡 + serialNumbersConfParam.setYears(Years+Months+Dates);//鑾峰彇褰撳墠鏄摢涓�澶� + serialNumbersConfParam.setState("1"); + + List<SerialNumbersConfResult> serialNumberslist = serialNumbersConfService.findListBySpec(serialNumbersConfParam); + if(!serialNumberslist.isEmpty()){ + SerialNumbersConfResult serialNumbersConfResult = serialNumberslist.get(0); + serialNumbers = serialNumbersConfResult.getSerialNumber(); + serialNumbersConfParam.setId(serialNumbersConfResult.getId()); + }else{ + serialNumbersConfParam.setSerialNumber(serialNumbers); + serialNumbersConfParam.setLengths("4"); + serialNumbersConfService.add(serialNumbersConfParam); + List<SerialNumbersConfResult> serialNumberslist2 = serialNumbersConfService.findListBySpec(serialNumbersConfParam); + if(!serialNumberslist2.isEmpty()){ + SerialNumbersConfResult serialNumbersConfResult = serialNumberslist2.get(0); + //serialNumbers = serialNumbersConfResult.getSerialNumber(); + serialNumbersConfParam.setId(serialNumbersConfResult.getId()); + } + } + + //鏇存柊搴忓垪鍙�+1 + int i = Integer.valueOf(serialNumbers)+1; + serialNumbers = StringUtils.leftPad(String.valueOf(i),4, "0"); + serialNumbersConfParam.setSerialNumber(serialNumbers); + serialNumbersConfService.update(serialNumbersConfParam); + + //鐢熸垚鎬绘垚缂栫爜 + String sfcCode = SFCCodeTool.createCodingRulesSFC(softwareVersionCode,productCompanyCode,serialNumbers);//鎬绘垚鍙� + S_SFC_CODE = sfcCode; + S_ORDER_CODE = result.getWorkOrderNo(); + S_PRODUCT_CODE = result.getMaterialCode(); + S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE); + ACTUAL_ONLINE_QTY = result.getActualOnlineQty(); + + + //鏂板鎶ュ伐璁板綍 + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + productionOrderRecordsParam.setMaterialCode(S_PRODUCT_CODE); + productionOrderRecordsParam.setStartTime(DateTool.getLocalTimeForDate()); + productionOrderRecordsParam.setWhetherPass("true"); + productionOrderRecordsService.add(productionOrderRecordsParam); + + List<ReadWriteEntity> lists = new ArrayList<>(); + lists.add(new ReadWriteEntity(OPCElement.OP010_S_ORDER_CODE,S_ORDER_CODE)); + lists.add(new ReadWriteEntity(OPCElement.OP010_S_PRODUCT_CODE,S_PRODUCT_TYPE)); + lists.add(new ReadWriteEntity(OPCElement.OP010_S_SFC_CODE,S_SFC_CODE)); + lists.add(new ReadWriteEntity(OPCElement.OP010_S_NUMBER,result.getPlanQty().toString())); + lists.add(new ReadWriteEntity(OPCElement.OP010_J_PC_WRITE_ORDER,true)); + miloService.writeToOpcUa(lists); + logger.info("OP010宸ヤ綅,handleOrder PC澶勭悊瀹屾垚锛乛--------------------------------------------"); + }else{ + logger.info("OP010宸ヤ綅娌℃湁鍙墽琛岀殑宸ュ崟,璇疯仈绯诲伐鍗曠鐞嗗憳涓嬪彂璇ヤ骇绾跨殑宸ュ崟锛�"); + } + } + + public void handleFinsh() throws Exception { + logger.info("handleFinsh PC澶勭悊寮�濮嬶紒"); + String S_PRODUCT_STATE_CODE = miloService. + readFromOpcUa(OPCElement.OP010_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP010_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + } + } + } + + public void handleRepair() throws Exception{ + RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam(); + repairManageInfoParam.setLocationCode(LOCATION_CODE); + repairManageInfoParam.setManageType("2"); + repairManageInfoParam.setUpPlc("0"); + + List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam); + if(list.size()>0) { + RepairManageInfoResult result = list.get(0); + + S_SFC_CODE = result.getSfc(); + 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<LocationInfoResult> results = locationInfoService.findListBySpec(param); + if(results.size()>0) { + LocationInfoResult r = results.get(0); + String repairLocationNo = r.getSpareField2(); + if(null != repairLocationNo && "" != repairLocationNo){ + + List<ReadWriteEntity> lists = new ArrayList<>(); + lists.add(new ReadWriteEntity(OPCElement.OP010_S_ORDER_CODE,S_ORDER_CODE)); + lists.add(new ReadWriteEntity(OPCElement.OP010_S_PRODUCT_CODE,S_PRODUCT_TYPE)); + lists.add(new ReadWriteEntity(OPCElement.OP010_S_SFC_CODE,S_SFC_CODE)); + lists.add(new ReadWriteEntity(OPCElement.OP010_P_REPAIR_LOCATION,repairLocationNo)); + lists.add(new ReadWriteEntity(OPCElement.OP010_J_PC_WRITE_ORDER,true)); + miloService.writeToOpcUa(lists); + + //鏇存柊涓哄凡缁忚繑淇笂绾� + Long id = result.getId(); + repairManageInfoParam.setId(id); + repairManageInfoParam.setUpPlc("1"); + repairManageInfoService.update(repairManageInfoParam); + + }else{ + logger.info("OP010宸ヤ綅,handleRepair 璇锋煡璇�"+repairLocation+"宸ヤ綅鏄惁閰嶇疆杩斾慨宸ヤ綅鍙凤紒"); + } + }else{ + logger.info("OP010宸ヤ綅,handleRepair 鏃犳硶鏌ヨ鍒�"+repairLocation+"宸ヤ綅锛�"); + } + + } + } + + //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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP020Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP020Callback.java new file mode 100644 index 0000000..33f2a70 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP020Callback.java @@ -0,0 +1,298 @@ +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.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.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 OP020Callback implements SubscriptionCallback { + + 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(OP020Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP020";//宸ヤ綅鍙� + private static List list = null; + + public OP020Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP020_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP020_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP020_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP020_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP020_S_ORDER_CODE); + lists.add(OPCElement.OP020_S_PRODUCT_CODE); + lists.add(OPCElement.OP020_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP020_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP020_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP020_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP020_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.OP020_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP020_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP030Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP030Callback.java new file mode 100644 index 0000000..a74c62e --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP030Callback.java @@ -0,0 +1,297 @@ +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.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.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 OP030Callback implements SubscriptionCallback { + + 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(OP030Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP030";//宸ヤ綅鍙� + private static List list = null; + + public OP030Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP030_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP030_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP030_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP030_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP030_S_ORDER_CODE); + lists.add(OPCElement.OP030_S_PRODUCT_CODE); + lists.add(OPCElement.OP030_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP030_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP030_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP030_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP030_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.OP030_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP030_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP040Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP040Callback.java new file mode 100644 index 0000000..d89772c --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP040Callback.java @@ -0,0 +1,297 @@ +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.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.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 OP040Callback implements SubscriptionCallback { + + 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(OP040Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP040";//宸ヤ綅鍙� + private static List list = null; + + public OP040Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP040_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP040_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP040_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP040_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP040_S_ORDER_CODE); + lists.add(OPCElement.OP040_S_PRODUCT_CODE); + lists.add(OPCElement.OP040_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP040_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP040_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP040_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP040_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.OP040_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP040_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP050Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP050Callback.java new file mode 100644 index 0000000..d9cf208 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP050Callback.java @@ -0,0 +1,338 @@ +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.model.result.PassingStationCollectionResult; +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.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.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.opc.unit.OPCUnit; +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 OP050Callback implements SubscriptionCallback { + + 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(OP050Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP050";//宸ヤ綅鍙� + private static List list = null; + + public OP050Callback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP050_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP050_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP050_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleMaterial(); + handleFinsh(); + handleInfo(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP050_S_ORDER_CODE); + lists.add(OPCElement.OP050_S_PRODUCT_CODE); + lists.add(OPCElement.OP050_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP050_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP050_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP050_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_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.OP050_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); + + + String copSfcCode = miloService. + readFromOpcUa(OPCElement.OP050_S_SFC_CODE_COP) + .getValue().toString(); + String bopSfcCode = miloService. + readFromOpcUa(OPCElement.OP050_S_SFC_CODE_BOP) + .getValue().toString(); + + //鏍规嵁鍒嗘�绘垚缂栫爜锛屽皢EOP鐗╂枡鏁版嵁缁戝畾鍏崇郴淇敼涓烘�绘垚缂栫爜 + materialTraceabilityService.updateSFC(S_SFC_CODE,copSfcCode); + materialTraceabilityService.updateSFC(S_SFC_CODE,bopSfcCode); + + //鏍规嵁鍒嗘�绘垚缂栫爜锛屽皢EOP杩囩珯鏁版嵁缁戝畾鍏崇郴淇敼涓烘�绘垚缂栫爜 + passingStationCollectionService.updateSFC(S_SFC_CODE,copSfcCode); + passingStationCollectionService.updateSFC(S_SFC_CODE,bopSfcCode); + + + //鏍规嵁鍒嗘�绘垚缂栫爜锛屽皢EOP閲囬泦鏁版嵁缁戝畾鍏崇郴淇敼涓烘�绘垚缂栫爜 + paramCollectionService.updateSFC(S_SFC_CODE,copSfcCode); + paramCollectionService.updateSFC(S_SFC_CODE,bopSfcCode); + + logger.info("S_SFC_CODE:"+S_SFC_CODE); + logger.info("copSfcCode:"+copSfcCode); + logger.info("bopSfcCode:"+bopSfcCode); + + //鏌ヨCOP鍜孊OP鏄惁鍚堟牸 + PassingStationCollectionParam passingStationCollectionParam = new PassingStationCollectionParam(); + passingStationCollectionParam.setSfcCode(S_SFC_CODE); + List<PassingStationCollectionResult> passingStationCollectionResultList = + passingStationCollectionService.findListBySpec(passingStationCollectionParam); + + String isProductState = "true"; + for(int i=0;i<passingStationCollectionResultList.size();i++){ + PassingStationCollectionResult passingStationCollectionResult = passingStationCollectionResultList.get(i); + if("false".equals(passingStationCollectionResult.getOutRsSign())){ + isProductState = "false"; + break; + } + } + //淇敼鎶ュ伐璁板綍 + if("false".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(list.size()>0){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass("false"); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP070Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP070Callback.java new file mode 100644 index 0000000..e7f740b --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP070Callback.java @@ -0,0 +1,298 @@ +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.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.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 OP070Callback implements SubscriptionCallback { + + 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(OP070Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP070";//宸ヤ綅鍙� + private static List list = null; + + public OP070Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP070_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP070_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP070_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP070_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP070_S_ORDER_CODE); + lists.add(OPCElement.OP070_S_PRODUCT_CODE); + lists.add(OPCElement.OP070_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP070_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP070_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP070_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP070_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.OP070_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP070_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP080Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP080Callback.java new file mode 100644 index 0000000..53fc7a5 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP080Callback.java @@ -0,0 +1,349 @@ +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.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.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.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 OP080Callback implements SubscriptionCallback { + + 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(OP080Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP080";//宸ヤ綅鍙� + private static List list = null; + + public OP080Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP080_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP080_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP080_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP080_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + public void handleRepair() throws Exception{ + RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam(); + repairManageInfoParam.setLocationCode(LOCATION_CODE); + repairManageInfoParam.setManageType("2"); + repairManageInfoParam.setUpPlc("0"); + List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam); + if(list.size()>0) { + RepairManageInfoResult result = list.get(0); + + S_SFC_CODE = result.getSfc(); + 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<LocationInfoResult> results = locationInfoService.findListBySpec(param); + if(results.size()>0) { + LocationInfoResult r = results.get(0); + String repairLocationNo = r.getSpareField2(); + if(null != repairLocationNo && "" != repairLocationNo){ + List<ReadWriteEntity> lists = new ArrayList<>(); + lists.add(new ReadWriteEntity(OPCElement.OP080_S_ORDER_CODE,S_ORDER_CODE)); + lists.add(new ReadWriteEntity(OPCElement.OP080_S_PRODUCT_CODE,S_PRODUCT_TYPE)); + lists.add(new ReadWriteEntity(OPCElement.OP080_S_SFC_CODE,S_SFC_CODE)); + lists.add(new ReadWriteEntity(OPCElement.OP080_P_REPAIR_LOCATION,repairLocationNo)); + lists.add(new ReadWriteEntity(OPCElement.OP080_J_PC_WRITE_ORDER,true)); + miloService.writeToOpcUa(lists); + + //鏇存柊涓哄凡缁忚繑淇笂绾� + Long id = result.getId(); + repairManageInfoParam.setId(id); + repairManageInfoParam.setUpPlc("1"); + repairManageInfoService.update(repairManageInfoParam); + + }else{ + logger.info("OP080宸ヤ綅,handleRepair 璇锋煡璇�"+repairLocation+"宸ヤ綅鏄惁閰嶇疆杩斾慨宸ヤ綅鍙凤紒"); + } + }else{ + logger.info("OP080宸ヤ綅,handleRepair 鏃犳硶鏌ヨ鍒�"+repairLocation+"宸ヤ綅锛�"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP080_S_ORDER_CODE); + lists.add(OPCElement.OP080_S_PRODUCT_CODE); + lists.add(OPCElement.OP080_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP080_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP080_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP080_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP080_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.OP080_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP080_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP090Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP090Callback.java new file mode 100644 index 0000000..7524446 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP090Callback.java @@ -0,0 +1,332 @@ +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.model.result.PassingStationCollectionResult; +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.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.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.opc.unit.OPCUnit; +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 OP090Callback implements SubscriptionCallback { + + 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(OP090Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP090";//宸ヤ綅鍙� + private static List list = null; + + public OP090Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP090_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP090_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP090_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleMaterial(); + handleFinsh(); + handleInfo(); + + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP090_S_ORDER_CODE); + lists.add(OPCElement.OP090_S_PRODUCT_CODE); + lists.add(OPCElement.OP090_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP090_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP090_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP090_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_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.OP090_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); + + String eopSfcCode = miloService. + readFromOpcUa(OPCElement.OP090_S_SFC_CODE_EOP) + .getValue().toString(); + + //鏍规嵁鍒嗘�绘垚缂栫爜锛屽皢EOP鐗╂枡鏁版嵁缁戝畾鍏崇郴淇敼涓烘�绘垚缂栫爜 + materialTraceabilityService.updateSFC(S_SFC_CODE,eopSfcCode); + + //鏍规嵁鍒嗘�绘垚缂栫爜锛屽皢EOP杩囩珯鏁版嵁缁戝畾鍏崇郴淇敼涓烘�绘垚缂栫爜 + passingStationCollectionService.updateSFC(S_SFC_CODE,eopSfcCode); + + //鏍规嵁鍒嗘�绘垚缂栫爜锛屽皢EOP閲囬泦鏁版嵁缁戝畾鍏崇郴淇敼涓烘�绘垚缂栫爜 + paramCollectionService.updateSFC(S_SFC_CODE,eopSfcCode); + + logger.info("S_SFC_CODE:"+S_SFC_CODE); + logger.info("eopSfcCode:"+eopSfcCode); + + //鏌ヨCOP鍜孊OP鏄惁鍚堟牸 + PassingStationCollectionParam passingStationCollectionParam = new PassingStationCollectionParam(); + passingStationCollectionParam.setSfcCode(S_SFC_CODE); + List<PassingStationCollectionResult> passingStationCollectionResultList = + passingStationCollectionService.findListBySpec(passingStationCollectionParam); + + String isProductState = "true"; + for(int i=0;i<passingStationCollectionResultList.size();i++){ + PassingStationCollectionResult passingStationCollectionResult = passingStationCollectionResultList.get(i); + if("false".equals(passingStationCollectionResult.getOutRsSign())){ + isProductState = "false"; + break; + } + } + //淇敼鎶ュ伐璁板綍 + if("false".equals(S_PRODUCT_STATE_CODE) || "false".equals(isProductState)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(list.size()>0){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass("false"); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP090_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP100Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP100Callback.java new file mode 100644 index 0000000..4d5e051 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP100Callback.java @@ -0,0 +1,298 @@ +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.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.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 OP100Callback implements SubscriptionCallback { + + 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(OP100Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP100";//宸ヤ綅鍙� + private static List list = null; + + public OP100Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP100_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP100_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP100_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP100_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP100_S_ORDER_CODE); + lists.add(OPCElement.OP100_S_PRODUCT_CODE); + lists.add(OPCElement.OP100_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP100_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP100_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP100_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP100_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.OP100_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP100_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP110Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP110Callback.java new file mode 100644 index 0000000..26cf411 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP110Callback.java @@ -0,0 +1,298 @@ +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.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.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 OP110Callback implements SubscriptionCallback { + + 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(OP110Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP110";//宸ヤ綅鍙� + private static List list = null; + + public OP110Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP110_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP110_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP110_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP110_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP110_S_ORDER_CODE); + lists.add(OPCElement.OP110_S_PRODUCT_CODE); + lists.add(OPCElement.OP110_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP110_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP110_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP110_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP110_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.OP110_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP110_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120BCallback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120BCallback.java new file mode 100644 index 0000000..d4f278a --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120BCallback.java @@ -0,0 +1,298 @@ +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.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.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 OP120BCallback implements SubscriptionCallback { + + 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(OP120BCallback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP120B";//宸ヤ綅鍙� + private static List list = null; + + public OP120BCallback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP120B_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120B_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP120B_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP120B_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP120B_S_ORDER_CODE); + lists.add(OPCElement.OP120B_S_PRODUCT_CODE); + lists.add(OPCElement.OP120B_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP120B_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP120B_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP120B_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120B_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.OP120B_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP120B_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120Callback.java new file mode 100644 index 0000000..703f212 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP120Callback.java @@ -0,0 +1,298 @@ +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.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.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 OP120Callback implements SubscriptionCallback { + + 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(OP120Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP120";//宸ヤ綅鍙� + private static List list = null; + + public OP120Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP120_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP120_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP120_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP120_S_ORDER_CODE); + lists.add(OPCElement.OP120_S_PRODUCT_CODE); + lists.add(OPCElement.OP120_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP120_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP120_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP120_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP120_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.OP120_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP120_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130BCallback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130BCallback.java new file mode 100644 index 0000000..2a9cf92 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130BCallback.java @@ -0,0 +1,297 @@ +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.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.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 OP130BCallback implements SubscriptionCallback { + + 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(OP130BCallback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP130B";//宸ヤ綅鍙� + private static List list = null; + + public OP130BCallback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP130B_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130B_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP130B_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP130B_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP130B_S_ORDER_CODE); + lists.add(OPCElement.OP130B_S_PRODUCT_CODE); + lists.add(OPCElement.OP130B_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP130B_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP130B_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP130B_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130B_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.OP130B_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP130B_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130Callback.java new file mode 100644 index 0000000..f01ef3d --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP130Callback.java @@ -0,0 +1,298 @@ +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.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.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 OP130Callback implements SubscriptionCallback { + + 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(OP130Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP130";//宸ヤ綅鍙� + private static List list = null; + + public OP130Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP130_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP130_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP130_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP130_S_ORDER_CODE); + lists.add(OPCElement.OP130_S_PRODUCT_CODE); + lists.add(OPCElement.OP130_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP130_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP130_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP130_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP130_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.OP130_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP130_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP140Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP140Callback.java new file mode 100644 index 0000000..8b438f4 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP140Callback.java @@ -0,0 +1,298 @@ +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.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.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 OP140Callback implements SubscriptionCallback { + + 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(OP140Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP140";//宸ヤ綅鍙� + private static List list = null; + + public OP140Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP140_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP140_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP140_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP140_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP140_S_ORDER_CODE); + lists.add(OPCElement.OP140_S_PRODUCT_CODE); + lists.add(OPCElement.OP140_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP140_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP140_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP140_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP140_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.OP140_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP140_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP150Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP150Callback.java new file mode 100644 index 0000000..f856bb3 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP150Callback.java @@ -0,0 +1,298 @@ +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.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.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 OP150Callback implements SubscriptionCallback { + + 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(OP150Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP150";//宸ヤ綅鍙� + private static List list = null; + + public OP150Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP150_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP150_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP150_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP150_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP150_S_ORDER_CODE); + lists.add(OPCElement.OP150_S_PRODUCT_CODE); + lists.add(OPCElement.OP150_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP150_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP150_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP150_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP150_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.OP150_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP150_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP160Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP160Callback.java new file mode 100644 index 0000000..4154255 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP160Callback.java @@ -0,0 +1,298 @@ +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.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.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 OP160Callback implements SubscriptionCallback { + + 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(OP160Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP160";//宸ヤ綅鍙� + private static List list = null; + + public OP160Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP160_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP160_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP160_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP160_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP160_S_ORDER_CODE); + lists.add(OPCElement.OP160_S_PRODUCT_CODE); + lists.add(OPCElement.OP160_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP160_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP160_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP160_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP160_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.OP160_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + if("2".equals(S_PRODUCT_STATE_CODE)){ + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + } + //澶勭悊杩囩珯淇℃伅 + 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.OP160_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("handleFinsh PC澶勭悊瀹屾垚锛�"); + } + + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP170Callback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP170Callback.java new file mode 100644 index 0000000..06b9b76 --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP170Callback.java @@ -0,0 +1,315 @@ +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.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.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.opc.unit.OPCUnit; +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 OP170Callback implements SubscriptionCallback { + + 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(OP170Callback.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 = "OP";//浜х嚎鍙� + private static String LOCATION_CODE = "OP170";//宸ヤ綅鍙� + private static List list = null; + + public OP170Callback(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; + } + + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + //蹇冭烦 + if(null != value && identifier.equals(OPCElement.OP170_F_HEART_BEAT)){ + if( "false".equals(value.toString())) + { + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP170_F_HEART_BEAT,true); + miloService.writeToOpcUa(entity); + } + } + //PLC杩涚珯 + else if(null != value && identifier.equals(OPCElement.OP170_J_PLC_START)){ + if("true".equals(value.toString())){ + handleOrder(); + } + } + //PLC鍑虹珯 + else if(null != value && identifier.equals(OPCElement.OP170_J_PLC_FINISH)){ + if("true".equals(value.toString())){ + handleFinsh(); + handleInfo(); + handleMaterial(); + } + }else{ + System.out.println("鍊兼病鏈夊彉"); + } + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + + //PC璇诲伐鍗� + public void handleOrder() throws Exception { + logger.info("handleOrder PC澶勭悊寮�濮嬶紒"); + IN_TIME = DateTool.getLocalTimeForDate(); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP170_S_ORDER_CODE); + lists.add(OPCElement.OP170_S_PRODUCT_CODE); + lists.add(OPCElement.OP170_S_SFC_CODE); + List<ReadWriteEntity> returnLists= miloService.readFromOpcUa(lists); + returnLists.forEach(element->{ + switch(element.getIdentifier()){ + case OPCElement.OP170_S_ORDER_CODE: + S_ORDER_CODE = element.getValue().toString(); + break; + case OPCElement.OP170_S_PRODUCT_CODE: + S_PRODUCT_TYPE = element.getValue().toString(); + S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); + break; + case OPCElement.OP170_S_SFC_CODE: + S_SFC_CODE = element.getValue().toString(); + break; + default: + break; + } + }); + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP170_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.OP170_S_PRODUCT_STATE_CODE) + .getValue().toString(); + + //淇敼鎶ュ伐璁板綍 + ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam(); + productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderRecordsParam.setProductNo(S_SFC_CODE); + List<ProductionOrderRecordsResult> list2 = productionOrderRecordsService.findListBySpec(productionOrderRecordsParam); + if(!list2.isEmpty()){ + ProductionOrderRecordsResult productionOrderRecordsResult = list2.get(0); + productionOrderRecordsParam.setId(productionOrderRecordsResult.getId()); + productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE); + productionOrderRecordsParam.setEndTime(DateTool.getLocalTimeForDate()); + productionOrderRecordsService.update(productionOrderRecordsParam); + } + + 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); + + //鏇存柊宸ュ崟瀹屾垚鏁伴噺 + ProductionOrdeInfoParam orderParam = new ProductionOrdeInfoParam(); + orderParam.setWorkOrderNo(S_ORDER_CODE); + if(!"".equals(S_ORDER_CODE)&&null!=S_ORDER_CODE){ + List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(orderParam); + if(list.size()>0) { + ProductionOrdeInfoResult result = list.get(0); + orderParam.setId(result.getId()); + if (null == result.getActualQty() || "".equals(result.getActualQty())){ + result.setActualQty(0); + } + orderParam.setActualQty(result.getActualQty()+1); + productionOrdeInfoService.update(orderParam); + } + } + + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP170_J_PC_FINISH,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + logger.info("OP170宸ヤ綅,handleFinsh PC澶勭悊瀹屾垚锛�"); + } + public void handleMaterial() { + + //鏌ヨ鎵规涓婃枡淇℃伅 + ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam(); + productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE); + productionOrderBatchInfoParam.setLocationCode(LOCATION_CODE); + List<ProductionOrderBatchInfoResult> list = productionOrderBatchInfoService.findListBySpec(productionOrderBatchInfoParam); + for(int i=0;i<list.size();i++){ + ProductionOrderBatchInfoResult productionOrderBatchInfoResult = list.get(i); + int remainingQuantity = productionOrderBatchInfoResult.getResidueQuantity();//鍓╀綑鏁伴噺 + if(remainingQuantity>0 ){ + //鏂板鐗╂枡杩芥函 + 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); + String value = miloService. + readFromOpcUa(result.getGatherAddress()) + .getValue().toString();//璇诲弬鏁板�� + 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); + 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锛�"); + } + +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/StateCallback.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/StateCallback.java new file mode 100644 index 0000000..97bec3a --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/StateCallback.java @@ -0,0 +1,293 @@ +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.model.params.EquipmentInfoParam; +import cn.stylefeng.guns.modular.bs.equipmentInfo.model.result.EquipmentInfoResult; +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.model.params.EquipmentAlarmParam; +import cn.stylefeng.guns.modular.em.equipmentAlarm.service.EquipmentAlarmService; +import cn.stylefeng.guns.modular.em.equipmentStatus.model.params.EquipmentStatusParam; +import cn.stylefeng.guns.modular.em.equipmentStatus.model.result.EquipmentStatusResult; +import cn.stylefeng.guns.modular.em.equipmentStatus.service.EquipmentStatusService; +import cn.stylefeng.guns.modular.gm.greaseManage.model.params.GreaseManageParam; +import cn.stylefeng.guns.modular.gm.greaseManage.model.result.GreaseManageResult; +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.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.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.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.openscada.opc.lib.da.Item; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Random; + +@Component +public class StateCallback implements SubscriptionCallback { + + 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(StateCallback.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 = "BOP";//浜х嚎鍙� + private static String LOCATION_CODE = "BOP010";//宸ヤ綅鍙� + private static List list = null; + + public StateCallback(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; + } + @Override + public void onSubscribe(String identifier, Object value) { + String ecpStr = "";//寮傚父璁板綍鏍囪 + try { + handleInfo(); + } catch (Exception e) { + ecpStr ="鍑虹幇寮傚父锛�" + logUtil.getTrace(e); + }finally { + if(!"".equals(ecpStr)){ + logger.info(ecpStr+"\r\n"); + } + } + } + public void handleInfo() throws Exception { + logger.info("OP100宸ヤ綅,handleInfo START锛�"); + + if(null == list ){ + EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam(); + list = equipmentInfoService.findListBySpec(equipmentInfoParam); + } + if(null != list && list.size()>0) { + for (int i = 0; i < list.size(); i++) { + EquipmentInfoResult result = (EquipmentInfoResult) list.get(i); + Item item = result.getItem(); + String value = OPCUnit.read(item);//璇诲弬鏁板�� 璁惧鐘舵�� + String equipmentNo = result.getEquipmentNo(); + + EquipmentStatusParam equipmentStatusParam = new EquipmentStatusParam(); + equipmentStatusParam.setEquipmentNo(equipmentNo); + List statuslist = equipmentStatusService.findListBySpec(equipmentStatusParam); + if(statuslist.size()>0){ + EquipmentStatusResult equipmentStatusResult = (EquipmentStatusResult) statuslist.get(0); + if(!value.equals(equipmentStatusResult.getStatus())){ + equipmentStatusParam.setId(equipmentStatusResult.getId()); + equipmentStatusParam.setStatus(value); + equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate()); + equipmentStatusService.update(equipmentStatusParam);//鏇存柊璁惧鐘舵�� + + //娣诲姞璁惧鎶ヨ + if("3".equals(value)){ + EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam(); + equipmentAlarmParam.setEquipmentNo(equipmentNo); + equipmentAlarmParam.setEquipmentName(result.getEquipmentName()); + equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode()); + equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode()); + equipmentAlarmParam.setLocationCode(result.getLocationCode()); + equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"鎶ヨ锛�"); + equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate()); + equipmentAlarmService.add(equipmentAlarmParam); + } + } + + }else{ + equipmentStatusParam.setEquipmentName(result.getEquipmentName()); + equipmentStatusParam.setWorkshopCode(result.getWorkshopCode()); + equipmentStatusParam.setProductionLineCode(result.getProductionLineCode()); + equipmentStatusParam.setLocationCode(result.getLocationCode()); + equipmentStatusParam.setStatus(value); + equipmentStatusParam.setUpdateTime(DateTool.getLocalTimeForDate()); + equipmentStatusService.add(equipmentStatusParam); + + //娣诲姞璁惧鎶ヨ + if("3".equals(value)){ + EquipmentAlarmParam equipmentAlarmParam = new EquipmentAlarmParam(); + equipmentAlarmParam.setEquipmentNo(equipmentNo); + equipmentAlarmParam.setEquipmentName(result.getEquipmentName()); + equipmentAlarmParam.setWorkshopCode(result.getWorkshopCode()); + equipmentAlarmParam.setProductionLineCode(result.getProductionLineCode()); + equipmentAlarmParam.setLocationCode(result.getLocationCode()); + equipmentAlarmParam.setErrorDesc(result.getEquipmentName()+"鎶ヨ锛�"); + equipmentAlarmParam.setAlarmTime(DateTool.getLocalTimeForDate()); + equipmentAlarmService.add(equipmentAlarmParam); + } + } + + } + } + + + Thread.sleep(60*1000); + } + + public void handleOilStateDOP020(String LOCATION_CODE) throws Exception { + GreaseManageParam param = new GreaseManageParam(); + param.setLocationCode(LOCATION_CODE); + List<GreaseManageResult> list = greaseManageService.findListBySpec(param); + if(!list.isEmpty()) { + String duaDate = list.get(0).getDuaDate(); + + SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); + String currentDate = format.format(new Date()); + long daysBetween = getRemainder(currentDate,duaDate); + if(daysBetween>0){ + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_OIL_STATE,false); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + }else{ + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.DOP020_OIL_STATE,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + } + } + } + + public void handleOilStateOP050(String LOCATION_CODE) throws Exception { + GreaseManageParam param = new GreaseManageParam(); + param.setLocationCode(LOCATION_CODE); + List<GreaseManageResult> list = greaseManageService.findListBySpec(param); + if(!list.isEmpty()) { + String duaDate = list.get(0).getDuaDate(); + + SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); + String currentDate = format.format(new Date()); + long daysBetween = getRemainder(currentDate,duaDate); + if(daysBetween>0){ + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_OIL_STATE,false); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + }else{ + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP050_OIL_STATE,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + } + } + } + + public void handleOilStateBOP030(String LOCATION_CODE) throws Exception { + GreaseManageParam param = new GreaseManageParam(); + param.setLocationCode(LOCATION_CODE); + List<GreaseManageResult> list = greaseManageService.findListBySpec(param); + if(!list.isEmpty()) { + String duaDate = list.get(0).getDuaDate(); + + SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); + String currentDate = format.format(new Date()); + long daysBetween = getRemainder(currentDate,duaDate); + if(daysBetween>0){ + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_OIL_STATE,false); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + }else{ + ReadWriteEntity entity = new ReadWriteEntity(OPCElement.BOP030_OIL_STATE,true); + miloService.writeToOpcUa(entity);//鍐橮C瀹屾垚 + } + } + } + + public static long getRemainder(String currentDate,String tableDate){ + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + LocalDate localDate1 = LocalDate.parse(currentDate, dateFormatter); + LocalDate localDate2 = LocalDate.parse(tableDate, dateFormatter); + long days = ChronoUnit.DAYS.between(localDate1, localDate2); + return days; + } +} diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/init/CustomRunner.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/init/CustomRunner.java new file mode 100644 index 0000000..ce017dd --- /dev/null +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/init/CustomRunner.java @@ -0,0 +1,817 @@ +package cn.stylefeng.guns.plcserver.init; + +import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService; +import cn.stylefeng.guns.modular.bs.equipmentInfo.model.params.EquipmentInfoParam; +import cn.stylefeng.guns.modular.bs.equipmentInfo.model.result.EquipmentInfoResult; +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.service.ParamCollectionService; +import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService; +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.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.callback.*; +import cn.stylefeng.guns.plcserver.opc.GlobalVariable; +import cn.stylefeng.guns.plcserver.opc.OPCElement; +import cn.stylefeng.guns.plcserver.server.OP010.OP010ServerInterface; +import cn.stylefeng.guns.plcserver.server.OP010.impl.OP010ServerInterfaceImpl; +import com.kangaroohy.milo.service.MiloService; +import lombok.extern.slf4j.Slf4j; +import org.openscada.opc.lib.da.Item; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +@Component +@Slf4j +public class CustomRunner implements ApplicationRunner { + + @Autowired + 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 List stateLists = null; + @Override + public void run(ApplicationArguments args) throws Exception { + + GlobalVariable.PRODUCT_TYPE_MAP.put("12980500000198","1");//C1 36V + GlobalVariable.PRODUCT_TYPE_MAP.put("12980500000174","2");//C1 48V + GlobalVariable.PRODUCT_TYPE_MAP.put("12980500000194","3");//T1 36V + GlobalVariable.PRODUCT_TYPE_MAP.put("12980500000201","4");//T1 48V + + GlobalVariable.PRODUCT_CODE_MAP.put("1","12980500000198"); + GlobalVariable.PRODUCT_CODE_MAP.put("2","12980500000174"); + GlobalVariable.PRODUCT_CODE_MAP.put("3","12980500000194"); + GlobalVariable.PRODUCT_CODE_MAP.put("4","12980500000201"); + + EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam(); + List list = equipmentInfoService.findListBySpec(equipmentInfoParam); + + /* state();*/ + init(); +/* COP010(); + COP020(); + COP030(); + + BOP010(); + BOP020(); + BOP030(); + BOP030B(); + BOP040(); + BOP040B(); + + DOP010(); + //DOP020(); + + EOP010(); + EOP020(); + EOP030(); + EOP040(); + EOP050(); + EOP060(); + EOP070(); + EOP080(); + EOP090(); + EOP090B(); + + OP010(); + OP020(); + OP030(); + OP040(); + OP050(); + + OP070(); + OP080(); + OP090(); + OP100(); + OP110(); + OP120(); + OP120B(); + OP130(); + OP130B(); + OP140(); + //OP150(); + OP160(); + OP170(); + + state();*/ + } + + + + private void init() throws Exception { + InitCallback InitCallback = new InitCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + + List<String> lists = getList(); + miloService.subscriptionFromOpcUa(lists,InitCallback); + } + + private void state() throws Exception { + StateCallback StateCallback = new StateCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + StateCallback.handleInfo(); + // handleOilState("DOP020"); + StateCallback.handleOilStateOP050("OP050"); + StateCallback.handleOilStateBOP030("BOP030"); + } + private void COP010() throws Exception { + COP010Callback COP010Callback = new COP010Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.COP010_F_HEART_BEAT); + lists.add(OPCElement.COP010_J_PLC_START); + lists.add(OPCElement.COP010_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,COP010Callback); + System.out.println("1"); + } + private void COP020() throws Exception { + COP020Callback COP020Callback = new COP020Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.COP020_F_HEART_BEAT); + lists.add(OPCElement.COP020_J_PLC_START); + lists.add(OPCElement.COP020_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,COP020Callback); + } + private void COP030() throws Exception { + COP030Callback COP030Callback = new COP030Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.COP030_F_HEART_BEAT); + lists.add(OPCElement.COP030_J_PLC_START); + lists.add(OPCElement.COP030_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,COP030Callback); + } + private void BOP010() throws Exception { + BOP010Callback BOP010Callback = new BOP010Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP010_F_HEART_BEAT); + lists.add(OPCElement.BOP010_J_PLC_START); + lists.add(OPCElement.BOP010_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,BOP010Callback); + } + private void BOP020() throws Exception { + BOP020Callback BOP020Callback = new BOP020Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP020_F_HEART_BEAT); + lists.add(OPCElement.BOP020_J_PLC_START); + lists.add(OPCElement.BOP020_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,BOP020Callback); + } + private void BOP030() throws Exception { + BOP030Callback BOP030Callback = new BOP030Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP030_F_HEART_BEAT); + lists.add(OPCElement.BOP030_J_PLC_START); + lists.add(OPCElement.BOP030_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,BOP030Callback); + } + private void BOP030B() throws Exception { + BOP030BCallback BOP030BCallback = new BOP030BCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP030B_F_HEART_BEAT); + lists.add(OPCElement.BOP030B_J_PLC_START); + lists.add(OPCElement.BOP030B_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,BOP030BCallback); + } + private void BOP040() throws Exception { + BOP040Callback BOP040Callback = new BOP040Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP040_F_HEART_BEAT); + lists.add(OPCElement.BOP040_J_PLC_START); + lists.add(OPCElement.BOP040_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,BOP040Callback); + } + private void BOP040B() throws Exception { + BOP040BCallback BOP040BCallback = new BOP040BCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.BOP040B_F_HEART_BEAT); + lists.add(OPCElement.BOP040B_J_PLC_START); + lists.add(OPCElement.BOP040B_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,BOP040BCallback); + } + private void DOP010() throws Exception { + DOP010Callback DOP010Callback = new DOP010Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.DOP010_F_HEART_BEAT); + lists.add(OPCElement.DOP010_J_PLC_START); + lists.add(OPCElement.DOP010_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,DOP010Callback); + } + private void DOP020() throws Exception { + DOP020Callback DOP020Callback = new DOP020Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.DOP020_F_HEART_BEAT); + lists.add(OPCElement.DOP020_J_PLC_START); + lists.add(OPCElement.DOP020_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,DOP020Callback); + } + private void EOP010() throws Exception { + EOP010Callback EOP010Callback = new EOP010Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP010_F_HEART_BEAT); + lists.add(OPCElement.EOP010_J_PLC_START); + lists.add(OPCElement.EOP010_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,EOP010Callback); + } + private void EOP020() throws Exception { + EOP020Callback EOP020Callback = new EOP020Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP020_F_HEART_BEAT); + lists.add(OPCElement.EOP020_J_PLC_START); + lists.add(OPCElement.EOP020_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,EOP020Callback); + } + private void EOP030() throws Exception { + EOP030Callback EOP030Callback = new EOP030Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP030_F_HEART_BEAT); + lists.add(OPCElement.EOP030_J_PLC_START); + lists.add(OPCElement.EOP030_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,EOP030Callback); + } + private void EOP040() throws Exception { + EOP040Callback EOP040Callback = new EOP040Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP040_F_HEART_BEAT); + lists.add(OPCElement.EOP040_J_PLC_START); + lists.add(OPCElement.EOP040_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,EOP040Callback); + } + + private void EOP050() throws Exception { + EOP050Callback EOP050Callback = new EOP050Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP050_F_HEART_BEAT); + lists.add(OPCElement.EOP050_J_PLC_START); + lists.add(OPCElement.EOP050_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,EOP050Callback); + } + private void EOP060() throws Exception { + EOP060Callback EOP060Callback = new EOP060Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP060_F_HEART_BEAT); + lists.add(OPCElement.EOP060_J_PLC_START); + lists.add(OPCElement.EOP060_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,EOP060Callback); + } + private void EOP070() throws Exception { + EOP070Callback EOP070Callback = new EOP070Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP070_F_HEART_BEAT); + lists.add(OPCElement.EOP070_J_PLC_START); + lists.add(OPCElement.EOP070_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,EOP070Callback); + } + private void EOP080() throws Exception { + EOP080Callback EOP080Callback = new EOP080Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP080_F_HEART_BEAT); + lists.add(OPCElement.EOP080_J_PLC_START); + lists.add(OPCElement.EOP080_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,EOP080Callback); + } + private void EOP090() throws Exception { + EOP090Callback EOP090Callback = new EOP090Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP090_F_HEART_BEAT); + lists.add(OPCElement.EOP090_J_PLC_START); + lists.add(OPCElement.EOP090_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,EOP090Callback); + } + private void EOP090B() throws Exception { + EOP090BCallback EOP090BCallback = new EOP090BCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.EOP090B_F_HEART_BEAT); + lists.add(OPCElement.EOP090B_J_PLC_START); + lists.add(OPCElement.EOP090B_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,EOP090BCallback); + } + private void OP010() throws Exception { + OP010Callback OP010Callback = new OP010Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP010_F_HEART_BEAT); + lists.add(OPCElement.OP010_J_PLC_START); + lists.add(OPCElement.OP010_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP010Callback); + } + private void OP020() throws Exception { + OP020Callback OP020Callback = new OP020Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP020_F_HEART_BEAT); + lists.add(OPCElement.OP020_J_PLC_START); + lists.add(OPCElement.OP020_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP020Callback); + } + private void OP030() throws Exception { + OP030Callback OP030Callback = new OP030Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP030_F_HEART_BEAT); + lists.add(OPCElement.OP030_J_PLC_START); + lists.add(OPCElement.OP030_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP030Callback); + } + private void OP040() throws Exception { + OP040Callback OP040Callback = new OP040Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP040_F_HEART_BEAT); + lists.add(OPCElement.OP040_J_PLC_START); + lists.add(OPCElement.OP040_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP040Callback); + } + private void OP050() throws Exception { + OP050Callback OP050Callback = new OP050Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP050_F_HEART_BEAT); + lists.add(OPCElement.OP050_J_PLC_START); + lists.add(OPCElement.OP050_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP050Callback); + } + private void OP070() throws Exception { + OP070Callback OP070Callback = new OP070Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP070_F_HEART_BEAT); + lists.add(OPCElement.OP070_J_PLC_START); + lists.add(OPCElement.OP070_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP070Callback); + } + private void OP080() throws Exception { + OP080Callback OP080Callback = new OP080Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP080_F_HEART_BEAT); + lists.add(OPCElement.OP080_J_PLC_START); + lists.add(OPCElement.OP080_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP080Callback); + } + private void OP090() throws Exception { + OP090Callback OP090Callback = new OP090Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP090_F_HEART_BEAT); + lists.add(OPCElement.OP090_J_PLC_START); + lists.add(OPCElement.OP090_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP090Callback); + } + private void OP100() throws Exception { + OP100Callback OP100Callback = new OP100Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP100_F_HEART_BEAT); + lists.add(OPCElement.OP100_J_PLC_START); + lists.add(OPCElement.OP100_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP100Callback); + } + private void OP110() throws Exception { + OP110Callback OP110Callback = new OP110Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP110_F_HEART_BEAT); + lists.add(OPCElement.OP110_J_PLC_START); + lists.add(OPCElement.OP110_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP110Callback); + } + private void OP120() throws Exception { + OP120Callback OP120Callback = new OP120Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP120_F_HEART_BEAT); + lists.add(OPCElement.OP120_J_PLC_START); + lists.add(OPCElement.OP120_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP120Callback); + } + private void OP120B() throws Exception { + OP120BCallback OP120BCallback = new OP120BCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP120B_F_HEART_BEAT); + lists.add(OPCElement.OP120B_J_PLC_START); + lists.add(OPCElement.OP120B_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP120BCallback); + } + private void OP130() throws Exception { + OP130Callback OP130Callback = new OP130Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP130_F_HEART_BEAT); + lists.add(OPCElement.OP130_J_PLC_START); + lists.add(OPCElement.OP130_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP130Callback); + } + private void OP130B() throws Exception { + OP130BCallback OP130BCallback = new OP130BCallback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP130B_F_HEART_BEAT); + lists.add(OPCElement.OP130B_J_PLC_START); + lists.add(OPCElement.OP130B_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP130BCallback); + } + private void OP140() throws Exception { + OP140Callback OP140Callback = new OP140Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP140_F_HEART_BEAT); + lists.add(OPCElement.OP140_J_PLC_START); + lists.add(OPCElement.OP140_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP140Callback); + } + private void OP150() throws Exception { + OP150Callback OP150Callback = new OP150Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP150_F_HEART_BEAT); + lists.add(OPCElement.OP150_J_PLC_START); + lists.add(OPCElement.OP150_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP150Callback); + } + private void OP160() throws Exception { + OP160Callback OP160Callback = new OP160Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP160_F_HEART_BEAT); + lists.add(OPCElement.OP160_J_PLC_START); + lists.add(OPCElement.OP160_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP160Callback); + } + private void OP170() throws Exception { + OP170Callback OP170Callback = new OP170Callback(miloService,productionOrdeInfoService, + passingStationCollectionService,paramCollectionService,collectionParamConfService,serialNumbersConfService, + equipmentStatusService,equipmentAlarmService,materialTraceabilityService,equipmentInfoService, + repairManageInfoService,locationInfoService,greaseManageService,productionOrderRecordsService, + productionOrderBatchInfoService); + List<String> lists = new ArrayList<>(); + lists.add(OPCElement.OP170_F_HEART_BEAT); + lists.add(OPCElement.OP170_J_PLC_START); + lists.add(OPCElement.OP170_J_PLC_FINISH); + miloService.subscriptionFromOpcUa(lists,OP170Callback); + } + + + public List<String> getList(){ + List<String> lists = new ArrayList<>(); + + lists.add(OPCElement.COP010_F_HEART_BEAT); + lists.add(OPCElement.COP010_J_PLC_START); + lists.add(OPCElement.COP010_J_PLC_FINISH); + + lists.add(OPCElement.COP020_F_HEART_BEAT); + lists.add(OPCElement.COP020_J_PLC_START); + lists.add(OPCElement.COP020_J_PLC_FINISH); + + lists.add(OPCElement.COP030_F_HEART_BEAT); + lists.add(OPCElement.COP030_J_PLC_START); + lists.add(OPCElement.COP030_J_PLC_FINISH); + + lists.add(OPCElement.BOP010_F_HEART_BEAT); + lists.add(OPCElement.BOP010_J_PLC_START); + lists.add(OPCElement.BOP010_J_PLC_FINISH); + + lists.add(OPCElement.BOP020_F_HEART_BEAT); + lists.add(OPCElement.BOP020_J_PLC_START); + lists.add(OPCElement.BOP020_J_PLC_FINISH); + + lists.add(OPCElement.BOP030_F_HEART_BEAT); + lists.add(OPCElement.BOP030_J_PLC_START); + lists.add(OPCElement.BOP030_J_PLC_FINISH); + + lists.add(OPCElement.BOP030B_F_HEART_BEAT); + lists.add(OPCElement.BOP030B_J_PLC_START); + lists.add(OPCElement.BOP030B_J_PLC_FINISH); + + lists.add(OPCElement.BOP040_F_HEART_BEAT); + lists.add(OPCElement.BOP040_J_PLC_START); + lists.add(OPCElement.BOP040_J_PLC_FINISH); + + lists.add(OPCElement.BOP040B_F_HEART_BEAT); + lists.add(OPCElement.BOP040B_J_PLC_START); + lists.add(OPCElement.BOP040B_J_PLC_FINISH); + + lists.add(OPCElement.DOP010_F_HEART_BEAT); + lists.add(OPCElement.DOP010_J_PLC_START); + lists.add(OPCElement.DOP010_J_PLC_FINISH); + + /* lists.add(OPCElement.DOP020_F_HEART_BEAT); + lists.add(OPCElement.DOP020_J_PLC_START); + lists.add(OPCElement.DOP020_J_PLC_FINISH);*/ + + lists.add(OPCElement.EOP010_F_HEART_BEAT); + lists.add(OPCElement.EOP010_J_PLC_START); + lists.add(OPCElement.EOP010_J_PLC_FINISH); + + lists.add(OPCElement.EOP020_F_HEART_BEAT); + lists.add(OPCElement.EOP020_J_PLC_START); + lists.add(OPCElement.EOP020_J_PLC_FINISH); + + lists.add(OPCElement.EOP030_F_HEART_BEAT); + lists.add(OPCElement.EOP030_J_PLC_START); + lists.add(OPCElement.EOP030_J_PLC_FINISH); + + lists.add(OPCElement.EOP040_F_HEART_BEAT); + lists.add(OPCElement.EOP040_J_PLC_START); + lists.add(OPCElement.EOP040_J_PLC_FINISH); + + lists.add(OPCElement.EOP050_F_HEART_BEAT); + lists.add(OPCElement.EOP050_J_PLC_START); + lists.add(OPCElement.EOP050_J_PLC_FINISH); + + lists.add(OPCElement.EOP060_F_HEART_BEAT); + lists.add(OPCElement.EOP060_J_PLC_START); + lists.add(OPCElement.EOP060_J_PLC_FINISH); + + lists.add(OPCElement.EOP070_F_HEART_BEAT); + lists.add(OPCElement.EOP070_J_PLC_START); + lists.add(OPCElement.EOP070_J_PLC_FINISH); + + lists.add(OPCElement.EOP070_F_HEART_BEAT); + lists.add(OPCElement.EOP070_J_PLC_START); + lists.add(OPCElement.EOP070_J_PLC_FINISH); + + lists.add(OPCElement.EOP090_F_HEART_BEAT); + lists.add(OPCElement.EOP090_J_PLC_START); + lists.add(OPCElement.EOP090_J_PLC_FINISH); + + lists.add(OPCElement.EOP090B_F_HEART_BEAT); + lists.add(OPCElement.EOP090B_J_PLC_START); + lists.add(OPCElement.EOP090B_J_PLC_FINISH); + + lists.add(OPCElement.OP010_F_HEART_BEAT); + lists.add(OPCElement.OP010_J_PLC_START); + lists.add(OPCElement.OP010_J_PLC_FINISH); + + lists.add(OPCElement.OP020_F_HEART_BEAT); + lists.add(OPCElement.OP020_J_PLC_START); + lists.add(OPCElement.OP020_J_PLC_FINISH); + + lists.add(OPCElement.OP030_F_HEART_BEAT); + lists.add(OPCElement.OP030_J_PLC_START); + lists.add(OPCElement.OP030_J_PLC_FINISH); + + lists.add(OPCElement.OP040_F_HEART_BEAT); + lists.add(OPCElement.OP040_J_PLC_START); + lists.add(OPCElement.OP040_J_PLC_FINISH); + + lists.add(OPCElement.OP050_F_HEART_BEAT); + lists.add(OPCElement.OP050_J_PLC_START); + lists.add(OPCElement.OP050_J_PLC_FINISH); + + lists.add(OPCElement.OP070_F_HEART_BEAT); + lists.add(OPCElement.OP070_J_PLC_START); + lists.add(OPCElement.OP070_J_PLC_FINISH); + + lists.add(OPCElement.OP080_F_HEART_BEAT); + lists.add(OPCElement.OP080_J_PLC_START); + lists.add(OPCElement.OP080_J_PLC_FINISH); + + lists.add(OPCElement.OP090_F_HEART_BEAT); + lists.add(OPCElement.OP090_J_PLC_START); + lists.add(OPCElement.OP090_J_PLC_FINISH); + + lists.add(OPCElement.OP100_F_HEART_BEAT); + lists.add(OPCElement.OP100_J_PLC_START); + lists.add(OPCElement.OP100_J_PLC_FINISH); + + lists.add(OPCElement.OP110_F_HEART_BEAT); + lists.add(OPCElement.OP110_J_PLC_START); + lists.add(OPCElement.OP110_J_PLC_FINISH); + + lists.add(OPCElement.OP120_F_HEART_BEAT); + lists.add(OPCElement.OP120_J_PLC_START); + lists.add(OPCElement.OP120_J_PLC_FINISH); + + lists.add(OPCElement.OP120B_F_HEART_BEAT); + lists.add(OPCElement.OP120B_J_PLC_START); + lists.add(OPCElement.OP120B_J_PLC_FINISH); + + lists.add(OPCElement.OP130_F_HEART_BEAT); + lists.add(OPCElement.OP130_J_PLC_START); + lists.add(OPCElement.OP130_J_PLC_FINISH); + + lists.add(OPCElement.OP130B_F_HEART_BEAT); + lists.add(OPCElement.OP130B_J_PLC_START); + lists.add(OPCElement.OP130B_J_PLC_FINISH); + + lists.add(OPCElement.OP140_F_HEART_BEAT); + lists.add(OPCElement.OP140_J_PLC_START); + lists.add(OPCElement.OP140_J_PLC_FINISH); + + /* lists.add(OPCElement.OP150_F_HEART_BEAT); + lists.add(OPCElement.OP150_J_PLC_START); + lists.add(OPCElement.OP150_J_PLC_FINISH);*/ + + lists.add(OPCElement.OP160_F_HEART_BEAT); + lists.add(OPCElement.OP160_J_PLC_START); + lists.add(OPCElement.OP160_J_PLC_FINISH); + + lists.add(OPCElement.OP170_F_HEART_BEAT); + lists.add(OPCElement.OP170_J_PLC_START); + lists.add(OPCElement.OP170_J_PLC_FINISH); + + if(null == stateLists ){ + EquipmentInfoParam equipmentInfoParam = new EquipmentInfoParam(); + stateLists = equipmentInfoService.findListBySpec(equipmentInfoParam); + } + + if(!stateLists.isEmpty()){ + for(int i=0;i<stateLists.size();i++) { + EquipmentInfoResult result = (EquipmentInfoResult) stateLists.get(i); + if(null != result.getSpareField1()){ + lists.add(result.getSpareField1()); + } + } + } + return lists; + } +} + diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/opc/GlobalVariable.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/opc/GlobalVariable.java index 2a20a7c..1b7d5a4 100644 --- a/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/opc/GlobalVariable.java +++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/opc/GlobalVariable.java @@ -5,9 +5,9 @@ public class GlobalVariable { -// public static boolean TERMINATED = false; + public static boolean TERMINATED = false; - public static boolean TERMINATED = true; +// public static boolean TERMINATED = true; public static int SLEEP_TIME = 1000; diff --git a/guns-vip-main/src/main/resources/application.yml b/guns-vip-main/src/main/resources/application.yml index d834a83..d0cf5c4 100644 --- a/guns-vip-main/src/main/resources/application.yml +++ b/guns-vip-main/src/main/resources/application.yml @@ -34,5 +34,15 @@ id-type: assign_id table-underline: true +kangaroohy: + milo: + enabled: true + primary: default + config: + default: + endpoint: opc.tcp://127.0.0.1:49320 + security-policy: none + log: - path: _app_logs \ No newline at end of file + path: _app_logs + -- Gitblit v1.9.3