cl
2024-03-07 a5b351156c343e707cf977b9e76ac2cfc9e64259
更新OPC
已删除5个文件
已修改2个文件
已添加3个文件
1134 ■■■■ 文件已修改
jcdm-admin/src/main/resources/application.yml 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/pom.xml 40 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/KeyStoreLoader.java 127 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java 197 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientHandler.java 295 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientRunner.java 146 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/OpcusConfigInit.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/plcserver/conf/OPCElement.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java 190 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-admin/src/main/resources/application.yml
@@ -130,3 +130,11 @@
  excludes: /system/notice
  # åŒ¹é…é“¾æŽ¥
  urlPatterns: /system/*,/monitor/*,/tool/*
kangaroohy:
  milo:
    primary: default
    config:
      default:
        endpoint: opc.tcp://127.0.0.1:49320
        security-policy: none
jcdm-main/pom.xml
@@ -59,43 +59,19 @@
            <version>2.10.1</version>
        </dependency>
        <!--Server SDK依赖-->
        <dependency>
            <groupId>org.eclipse.milo</groupId>
            <artifactId>sdk-server</artifactId>
            <version>0.3.6</version>
        </dependency>
        <!--Client SDK依赖-->
        <dependency>
            <groupId>org.eclipse.milo</groupId>
            <artifactId>sdk-client</artifactId>
            <version>0.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.milo</groupId>
            <artifactId>stack-client</artifactId>
            <version>0.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.milo</groupId>
            <artifactId>stack-client</artifactId>
            <version>0.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.milo</groupId>
            <artifactId>stack-server</artifactId>
            <version>0.3.6</version>
        </dependency>
        <!-- ç³»ç»Ÿæ¨¡å—-->
        <dependency>
            <groupId>com.jcdm</groupId>
            <artifactId>jcdm-framework</artifactId>
        </dependency>
        <!-- opc start-->
        <dependency>
            <groupId>com.kangaroohy</groupId>
            <artifactId>milo-spring-boot-starter</artifactId>
            <version>3.0.5</version>
        </dependency>
        <!-- opc end-->
    </dependencies>
</project>
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/KeyStoreLoader.java
ÎļþÒÑɾ³ý
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java
ÎļþÒÑɾ³ý
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientHandler.java
ÎļþÒÑɾ³ý
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientRunner.java
ÎļþÒÑɾ³ý
jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/OpcusConfigInit.java
ÎļþÒÑɾ³ý
jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,58 @@
package com.jcdm.main.plcserver;
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
import com.jcdm.main.plcserver.conf.OPCElement;
import com.jcdm.main.plcserver.sub.OPCUaSubscription;
import com.kangaroohy.milo.service.MiloService;
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;
@Component
public class CustomRunner implements ApplicationRunner {
    @Autowired
    private MiloService miloService;
    @Autowired
    private IDaPassingStationCollectionService daPassingStationCollectionService;
    @Autowired
    private IDaCollectionParamConfService collectionParamConfService;
    @Autowired
    private IDaParamCollectionService daParamCollectionService;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        OPCUaSubscription opcUaSubscription = new OPCUaSubscription(
                miloService,
                daPassingStationCollectionService,
                collectionParamConfService,
                daParamCollectionService);
        List<String> lists = getSubList();
        miloService.subscriptionFromOpcUa(lists,opcUaSubscription);
    }
    /**
     * è®¢é˜…内容
     */
    public List<String> getSubList(){
        List<String> lists = new ArrayList<>();
        lists.add(OPCElement.OP_OP010_RecordSN);//请求下发SN号
        lists.add(OPCElement.OP_OP010_RecordData);//请求记录数据
        lists.add(OPCElement.OP_OP020_RecordData);//请求记录数据
        return lists;
    }
}
jcdm-main/src/main/java/com/jcdm/main/plcserver/conf/OPCElement.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,25 @@
package com.jcdm.main.plcserver.conf;
/**
 * @ClassName: OPCElement
 * @Description: PC和PLC通信使用的OPCserver上的标记名称列表
 */
public class OPCElement {
    /**
     * OP010
     */
    public static final String OP_OP010_RecordSN = "OP.OP010.RecordSN";//请求下发SN号
    public static final String OP_OP010_RecordData = "OP.OP010.RecordData";//请求记录数据
    /**
     * OP020
     */
    public static final String OP_OP020_RecordData = "OP.OP020.RecordData";//请求记录数据
}
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,190 @@
package com.jcdm.main.plcserver.sub;
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
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.jcdm.main.plcserver.conf.OPCElement;
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 java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class OPCUaSubscription implements SubscriptionCallback {
    public static MiloService miloService;
    public IDaPassingStationCollectionService daPassingStationCollectionService;
    public IDaCollectionParamConfService collectionParamConfService;
    public IDaParamCollectionService daParamCollectionService;
    public OPCUaSubscription(MiloService miloService,
                             IDaPassingStationCollectionService daPassingStationCollectionService,
                             IDaCollectionParamConfService collectionParamConfService,
                             IDaParamCollectionService daParamCollectionService) {
        OPCUaSubscription.miloService = miloService;
        this.daPassingStationCollectionService = daPassingStationCollectionService;
        this.collectionParamConfService = collectionParamConfService;
        this.daParamCollectionService = daParamCollectionService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        try {
            if(null != value) {
                String[] nodes = identifier.split("[.]");
                String thoroughfare = nodes[0];//通道
                String device = nodes[1];//设备
                String tab = nodes[2];//标记
                String tabVlaue = value.toString();//地址值
                //请求下发SN号
                if (("RecordSN").equals(tab) && "1".equals(tabVlaue)) {
                    //获取SN号方法
                    String SNCode = getSNCode();
                    //下发SN
                    String SNCodeAddress = thoroughfare + "." + device + ".SNCode";
                    miloService.writeToOpcChar(ReadWriteEntity.builder().identifier(SNCodeAddress).value(SNCode).build());
                    //下发SN完成
                    String recordSNDoneAddress = thoroughfare + "." + device + ".RecordSNDone";
                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(recordSNDoneAddress).value(1).build());
                }
                //请求记录数据
                else if (("RecordData").equals(tab)) {
                    String recordDataDoneValue = "";
                    if("1".equals(tabVlaue)){
                        recordDataDoneValue = "11";
                        //进站保存数据
                        //inSaveDate(thoroughfare,device)
                        //记录数据完成
                        String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(recordDataDoneValue).build());
                    }else if("2".equals(tabVlaue)){
                        //出站保存数据
                        recordDataDoneValue = outSaveDate(thoroughfare,device);
                        //记录数据完成
                        String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(recordDataDoneValue).build());
                    }else{
                        System.out.println("^");
                    }
                }
            }
        } catch (Exception e) {
        }
    }
    /**
     * èŽ·å–SNCode
     */
    public String getSNCode(){
        String SNCode = "";
        return SNCode;
    }
    /**
     * å‡ºç«™ä¿å­˜æ•°æ®
     */
    public String outSaveDate(String thoroughfare,String device) {
        String result = "";
        try {
            //读取SNCode
            String SNCodeAddress = thoroughfare + "." + device + ".SNCode";
            Object SNCodeObject = miloService.readFromOpcUa(SNCodeAddress).getValue();
            if(null == SNCodeObject || "".equals(SNCodeObject)){
               result = "22";
            }else{
                String SNCode = SNCodeObject.toString();
                //1、更新工单信息
                //updateOrderInfo();
                //2、保存过站采集数据
                saveStationInfo(SNCode,thoroughfare,device);
                //3、保存参数采集数据
                SaveParamData(SNCode,thoroughfare,device);
                result = "21";
            }
        }catch (Exception e) {
        }
        return result;
    }
    /**
     * ä¿å­˜è¿‡ç«™é‡‡é›†
     */
    public void saveStationInfo(String SNCode,String thoroughfare,String device){
        DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
        daPassingStationCollection.setSfcCode(SNCode);
        //daPassingStationCollection.setInboundTime();//入站时间
        daPassingStationCollection.setOutboundTime(new Date());//出站时间
        //daPassingStationCollection.setOutRsSign();//出站是否合格
        daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection);
    }
    public void SaveParamData(String SNCode,String thoroughfare,String device) throws Exception {
        List<DaCollectionParamConf> list;
        DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
        daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device);
        list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
        List<String> nodeIdList = list.stream().map(info -> {
            String nodeid = info.getGatherAddress();
            return nodeid;
        }).collect(Collectors.toList());
        if(!nodeIdList.isEmpty()){
            List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
            List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
            for(int i=0;i<nodeIdList.size();i++){
                DaParamCollection ParamCollection = new DaParamCollection();
                if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){
                    ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]);
                    ParamCollection.setLocationCode(device);
                    ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
                    ParamCollection.setSfcCode(SNCode);
                    ParamCollection.setParamName(list.get(i).getCollectParameterName());
                    ParamCollection.setParamUpper(list.get(i).getParamUpper());
                    ParamCollection.setParamLower(list.get(i).getParamLower());
                    ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
                    //ParamCollection.setState("合格");
                    ParamCollection.setType(list.get(i).getCollectParameterType());
                    ParamCollection.setCollectionTime(new Date());
                    daParamCollectionlist.add(ParamCollection);
                }
            }
            //daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
        }
    }
}