jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/controller/DaOpcuaConfigController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/BeanUtils.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/CustomRunner.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/TestCallback.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
jcdm-ui/src/views/main/da/opcuaconfig/index.vue | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/controller/DaOpcuaConfigController.java
@@ -1,10 +1,15 @@ package com.jcdm.main.da.opcuaconfig.controller; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig; import com.jcdm.main.da.opcuaconfig.service.IDaOpcuaConfigService; import com.jcdm.main.da.paramCollection.domain.DaParamCollection; import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; import com.kangaroohy.milo.model.ReadWriteEntity; import com.kangaroohy.milo.service.MiloService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -34,6 +39,10 @@ { @Autowired private IDaOpcuaConfigService daOpcuaConfigService; @Autowired private MiloService miloService; @Autowired private IDaParamCollectionService daParamCollectionService; /** * æ¥è¯¢OPCUAåæ°è®¾ç½®å表 jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/BeanUtils.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,30 @@ package com.jcdm.main.da.opcuaconfig.init; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; @Component public class BeanUtils implements ApplicationContextAware { protected static ApplicationContext applicationContext ; @Override public void setApplicationContext(ApplicationContext arg0) throws BeansException { if (applicationContext == null) { applicationContext = arg0; } } public static Object getBean(String name) { //nameè¡¨ç¤ºå ¶ä»è¦æ³¨å ¥ç注解nameå return applicationContext.getBean(name); } /** * æ¿å°ApplicationContext对象å®ä¾åå°±å¯ä»¥æå¨è·åBeançæ³¨å ¥å®ä¾å¯¹è±¡ */ public static <T> T getBean(Class<T> clazz) { return applicationContext.getBean(clazz); } } jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/CustomRunner.java
@@ -2,13 +2,18 @@ import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig; import com.jcdm.main.da.opcuaconfig.service.IDaOpcuaConfigService; import com.kangaroohy.milo.configuration.MiloProperties; import com.kangaroohy.milo.model.ReadWriteEntity; import com.kangaroohy.milo.pool.MiloConnectPool; import com.kangaroohy.milo.service.MiloService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -16,20 +21,10 @@ @Slf4j public class CustomRunner implements ApplicationRunner { @Autowired private MiloService miloService; @Autowired protected IDaOpcuaConfigService daOpcuaConfigService; private static CustomRunner customRunner; public MiloService miloService; private IDaOpcuaConfigService daOpcuaConfigService = BeanUtils.getBean(IDaOpcuaConfigService.class); private List<DaOpcuaConfig> b=null; //å¨èªå®ä¹ç±»ä¸è°ç¨serviceå±çSpringå ¶ä»å± @PostConstruct public void init() { customRunner = this; customRunner.daOpcuaConfigService = this.daOpcuaConfigService; // å使åæ¶å°å·²éæåçtestServiceå®ä¾å } @Override public void run(ApplicationArguments args) throws Exception { sub(); @@ -37,7 +32,7 @@ private void sub() throws Exception { DaOpcuaConfig daOpcuaConfig=new DaOpcuaConfig(); daOpcuaConfig.setSubscribe(1L); b=customRunner.daOpcuaConfigService.selectDaOpcuaConfigList(daOpcuaConfig); b=daOpcuaConfigService.selectDaOpcuaConfigList(daOpcuaConfig); List<String> ids = b.stream().map(e -> e.getNode()).collect(Collectors.toList()); TestCallback testCallback = new TestCallback(); miloService.subscriptionFromOpcUa(ids,testCallback); jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/TestCallback.java
@@ -1,34 +1,39 @@ package com.jcdm.main.da.opcuaconfig.init; import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig; import com.jcdm.main.da.opcuaconfig.service.IDaOpcuaConfigService; import com.jcdm.main.da.paramCollection.domain.DaParamCollection; import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; import com.kangaroohy.milo.model.ReadWriteEntity; import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; import com.kangaroohy.milo.service.MiloService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @Component public class TestCallback implements SubscriptionCallback { @Autowired protected IDaOpcuaConfigService daOpcuaConfigService; private static TestCallback testCallback; private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class); private IDaOpcuaConfigService daOpcuaConfigService = BeanUtils.getBean(IDaOpcuaConfigService.class); private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class); private MiloService miloService = BeanUtils.getBean(MiloService.class); private List<DaOpcuaConfig> b=null; //å¨èªå®ä¹ç±»ä¸è°ç¨serviceå±çSpringå ¶ä»å± @PostConstruct public void init() { testCallback = this; testCallback.daOpcuaConfigService = this.daOpcuaConfigService; // å使åæ¶å°å·²éæåçtestServiceå®ä¾å } // private CustomRunner customRunner; @Override public void onSubscribe(String identifier, Object value) { if (b == null || 0 > b.size()) { DaOpcuaConfig daOpcuaConfig=new DaOpcuaConfig(); daOpcuaConfig.setSubscribe(1L); b=testCallback.daOpcuaConfigService.selectDaOpcuaConfigList(daOpcuaConfig); b=daOpcuaConfigService.selectDaOpcuaConfigList(daOpcuaConfig); } //使ç¨Stream APIå¨List<T>ä¸æ¥æ¾å ç´ DaOpcuaConfig opcuaConf = b.stream() @@ -44,7 +49,36 @@ e.printStackTrace(); } } public void getSn(String Node, String value) { System.out.println("订é åè°æå"); public void SiteCollection(String Node, String value) throws Exception { String[] parts = Node.split("[.]"); switch (value) { case "0": //åå§ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(parts[0]+"."+parts[1]+".RecordDataDone").value(0).build()); break; case "1": //请æ±ä¸åè¿ç«ç¶æ miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(parts[0]+"."+parts[1]+".RecordDataDone").value(11).build()); break; case "2": //请æ±è®°å½å·¥ä½æ°æ® List<DaCollectionParamConf> b; DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf(); daCollectionParamConf.setCollectParameterId(parts[0]+"."+parts[1]); b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); List<String> ids = b.stream().map(e -> e.getCollectParameterId()).collect(Collectors.toList()); List<ReadWriteEntity> s=miloService.readFromOpcUa(ids); s.forEach(element->{ DaParamCollection Config=new DaParamCollection(); String[] q = element.getIdentifier().split("[.]"); Config.setParamCode(q[2]); Config.setLocationCode(q[1]); Config.setParamValue(element.getValue().toString()); daParamCollectionService.insertDaParamCollection(Config); }); miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(parts[0]+"."+parts[1]+".RecordDataDone").value(21).build()); break; default: break; } } } jcdm-ui/src/views/main/da/opcuaconfig/index.vue
@@ -123,7 +123,7 @@ <el-table v-loading="loading" :data="opcuaconfigList" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55" align="center" /> <el-table-column label="ID" align="center" prop="id" /> <!-- <el-table-column label="ID" align="center" prop="id" />--> <el-table-column label="æå±æ¨¡å" align="center" prop="module"> <!-- <template slot-scope="scope">--> <!-- <dict-tag :options="dict.type.${column.dictType}" :value="scope.row.module"/>-->