wujian
2024-03-28 1e39c55183c1f54d1587bf3a86b4c2210bcd592e
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -16,15 +16,15 @@
import org.springframework.stereotype.Component;
import javax.websocket.Session;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Component
public class OPCUaSubscription implements SubscriptionCallback {
    //自动工位
    public List<String> automaticList = Arrays.asList("OP300","OP280", "OP320", "OP340", "OP350", "OP360","OP370", "OP390", "OP470", "OP530", "OP540");
    public static MiloService miloService;
@@ -32,9 +32,9 @@
    public IDaPassingStationCollectionService daPassingStationCollectionService;
    public IDaCollectionParamConfService collectionParamConfService;
    public static IDaCollectionParamConfService collectionParamConfService;
    public IDaParamCollectionService daParamCollectionService;
    public static IDaParamCollectionService daParamCollectionService;
    public OPCUaSubscription(MiloService miloService,
                             IDaPassingStationCollectionService daPassingStationCollectionService,
@@ -77,26 +77,32 @@
                    if("1".equals(tabVlaue)){
                        recordDataDoneValue = "11";
                        //校验入站是否可以工作
                        //进站保存数据
//                        inSaveDate(thoroughfare,device)
                        //记录数据完成
//                        String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
//                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(recordDataDoneValue).build());
                        String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build());
                        //给前端发工件到位信号
                        WebSocketUsers.sendMessageToUserByText(map.get(device), "IN");
                        if(automaticList.stream().noneMatch(s -> s.equals(device))){
                            //给前端发工件到位信号
                            WebSocketUsers.sendMessageToUserByText(map.get(device), "IN");
                        }
                        //请求工单
                    }else if("2".equals(tabVlaue)){
                        //出站保存数据
                        recordDataDoneValue = outSaveDate(thoroughfare,device);
                        //记录数据完成
                        String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(recordDataDoneValue).build());
                        if(automaticList.stream().anyMatch(s -> s.equals(device))){
                            //自动工位
                            //出站保存数据
                            recordDataDoneValue = outSaveDate(thoroughfare,device);
                            //记录数据完成
                            String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
                            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf(RecordDataDoneAddress)).build());
                        }else {
                            //手动工位
                            WebSocketUsers.sendMessageToUserByText(map.get(device), "END");
                        }
                    }else {
                        System.out.println("^");
                    }
@@ -104,15 +110,13 @@
                //保存拧紧数据
                else if (("AngleResult").equals(tab)) {
                    if("1".equals(tabVlaue)||"2".equals(tabVlaue)){
                        String Torque = thoroughfare + "." + device + ".Torque";
                        String Angle = thoroughfare + "." + device + ".Angle";
                        String Result = thoroughfare + "." + device + ".Result";
                        String Result1 = thoroughfare + "." + device + ".Result1";
                        List<String> list = new ArrayList();
                        list.add(Torque);
                        list.add(Angle);
                        list.add(Result);
                        list.add(Result1);
                        List<String> list = new ArrayList<>();
                        String[] suffixes = {"Torque", "Angle", "Result", "Result1"};
                        for (String suffix : suffixes) {
                            String string = thoroughfare + "." + device + "." + suffix;
                            list.add(string);
                        }
                        List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list);
                        List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList());
                        String joinedString = String.join(",", collect.toString());
@@ -143,18 +147,18 @@
        String result = "";
        try {
            //读取SNCode
            String SNCodeAddress = thoroughfare + "." + device + ".SNCode";
            Object SNCodeObject = miloService.readFromOpcUa(SNCodeAddress).getValue();
            if(null == SNCodeObject || "".equals(SNCodeObject)){
            String PACKCode = thoroughfare + "." + device + ".PACKCode";
            Object PACKCodeObject = miloService.readFromOpcUa(PACKCode).getValue();
            if(null == PACKCodeObject || "".equals(PACKCodeObject)){
               result = "22";
            }else{
                String SNCode = SNCodeObject.toString();
                String PACKCodeParam = PACKCodeObject.toString();
                //1、更新工单信息
                //updateOrderInfo();
                //2、保存过站采集数据
                saveStationInfo(SNCode,thoroughfare,device);
                saveStationInfo(PACKCodeParam,thoroughfare,device);
                //3、保存参数采集数据
                SaveParamData(SNCode,thoroughfare,device);
                SaveParamData(PACKCodeParam,thoroughfare,device,"","");
                result = "21";
@@ -169,16 +173,23 @@
    /**
     * 保存过站采集
     */
    public void saveStationInfo(String SNCode,String thoroughfare,String device){
    public void saveStationInfo(String packCode,String thoroughfare,String device) throws Exception {
        String prefix = thoroughfare+"."+device+".";
        String workOrderNo = miloService.readFromOpcUa(prefix + "WorkOrderNumber").getValue().toString();
        String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString();
        String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString();
        String stationStatus = miloService.readFromOpcUa(prefix + "StationStatus").getValue().toString();
        DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
        daPassingStationCollection.setSfcCode(SNCode);
        //daPassingStationCollection.setInboundTime();//入站时间
        daPassingStationCollection.setOutboundTime(new Date());//出站时间
        //daPassingStationCollection.setOutRsSign();//出站是否合格
        daPassingStationCollection.setSfcCode(packCode);
        daPassingStationCollection.setWorkOrderNo(workOrderNo);
//        daPassingStationCollection.setInboundTime(startTime);//入站时间
//        daPassingStationCollection.setOutboundTime(stopTime);//出站时间
        daPassingStationCollection.setOutRsSign(stationStatus);//出站是否合格
        daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection);
    }
    public void SaveParamData(String SNCode,String thoroughfare,String device) throws Exception {
    public static void SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception {
        List<DaCollectionParamConf> list;
        DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
        daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device);
@@ -193,12 +204,13 @@
            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]);
                    DaParamCollection ParamCollection = new DaParamCollection();
//                    ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]);
                    ParamCollection.setParamCode(list.get(i).getCollectParameterId());
                    ParamCollection.setLocationCode(device);
                    ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
                    ParamCollection.setSfcCode(SNCode);
                    ParamCollection.setSfcCode(packCode);
                    ParamCollection.setParamName(list.get(i).getCollectParameterName());
                    ParamCollection.setParamUpper(list.get(i).getParamUpper());
                    ParamCollection.setParamLower(list.get(i).getParamLower());
@@ -206,10 +218,13 @@
                    //ParamCollection.setState("合格");
                    ParamCollection.setType(list.get(i).getCollectParameterType());
                    ParamCollection.setCollectionTime(new Date());
                    ParamCollection.setWorkOrderNo(workOrderNo);
                    ParamCollection.setProductCode(productType);
                    daParamCollectionlist.add(ParamCollection);
//                    daParamCollectionService.insertDaParamCollection(ParamCollection);
                }
            }
            //daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
            daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
        }
    }