hdy
2023-12-28 53902f7927f4f7828381ea23843e2f8b816021ee
Merge remote-tracking branch 'origin/master'
已修改4个文件
已添加1个文件
122 ■■■■ 文件已修改
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/controller/DaOpcuaConfigController.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/BeanUtils.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/CustomRunner.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/TestCallback.java 60 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-ui/src/views/main/da/opcuaconfig/index.vue 2 ●●● 补丁 | 查看 | 原始文档 | 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"/>-->