-
admin
2024-06-05 16714e1a824acd878b105e6ac433866cfc50ed89
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -27,6 +27,9 @@
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -35,9 +38,11 @@
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Component
public class OPCUaSubscription implements SubscriptionCallback {
    private static final Logger logger = LoggerFactory.getLogger("sys-user");
    public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -98,6 +103,7 @@
    @Override
    public void onSubscribe(String identifier, Object value) {
        logger.info("地址:"+identifier+"值:"+value);
        try {
            if(null != value && Integer.valueOf(value.toString())!= 0) {
                String[] nodes = identifier.split("[.]");
@@ -198,6 +204,7 @@
//                            }
                            if(testList.stream().anyMatch(s -> s.equals(device))){
                                String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
                                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
//                                Object packCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
//                                DaTestDeviceInterface deviceInterfaceOne = null;
//
@@ -214,7 +221,6 @@
//                                    writeToOpc(RecordDataDoneAddress, (short) 22);
//                                }
//                                writeToOpc(RecordDataDoneAddress, (short) 21);
                                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
                            }
@@ -237,11 +243,15 @@
                        List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList());
                        String joinedString = String.join(",", collect.toString());
                        WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString));
                        if(device.contains("270") || device.contains("260")){
                            logger.info("读取到工位{}的Scaner数据:{}",device,TightenTheConversionOkNg(joinedString));
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.info("订阅方法报错:{}"+e.getMessage());
            logger.error("订阅方法报错",e);
        }
    }
@@ -269,51 +279,53 @@
                    read = read + "ModuleCode";
                    if(device.equals("OP365")){
                        try {
                            saveStationInfo365(thoroughfare,device);
                            result = saveStationInfo365(thoroughfare,device);
                            return result;
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }else {
                    read = read + "PACKCode";
                    snCode = miloService.readFromOpcUa(read).getValue().toString();
                    if(null == snCode || "".equals(snCode)){
                        result = "22";
                    }else{
                        String workOrderNo = "";
                        String productCode = "";
                        //2、保存过站采集数据
                        Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue();
                        if(orderNumberObject!=null){
                            workOrderNo = orderNumberObject.toString();
                        }
                        Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue();
                        if(productCodeObject!=null){
                            productCode = productCodeObject.toString();
                        }
                        saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode);
                        //3、保存参数采集数据
                        SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode);
                        //如果是末尾工站要报工
                        if(device.equals("OP500")){
                            RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date()));
                            //1、更新工单信息
                            updateOrderInfo(snCode);
                        }
                        try{
                            daParamCollectionService.pushGeelycvMesFeedback(snCode,device);
                        }catch (Exception e){
                        }
                        result = "21";
                    }
                }
            }
            snCode = miloService.readFromOpcUa(read).getValue().toString();
            if(null == snCode || "".equals(snCode)){
                result = "22";
            }else{
                String workOrderNo = "";
                String productCode = "";
                //2、保存过站采集数据
                Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue();
                if(orderNumberObject!=null){
                    workOrderNo = orderNumberObject.toString();
                }
                Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue();
                if(productCodeObject!=null){
                    productCode = productCodeObject.toString();
                }
                saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode);
                //3、保存参数采集数据
                SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode);
                //如果是末尾工站要报工
                if(device.equals("OP500")){
                    RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date()));
                    //1、更新工单信息
                    updateOrderInfo(snCode);
                }
                try{
                    daParamCollectionService.pushGeelycvMesFeedback(snCode,device);
                }catch (Exception e){
                }
                result = "21";
            }
        }catch (Exception e) {
            System.out.println(e.getMessage());
@@ -541,7 +553,7 @@
    /**
     * 保存过站采集
     */
    public void saveStationInfo365(String thoroughfare,String device) throws Exception {
    public String saveStationInfo365(String thoroughfare,String device) throws Exception {
        String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
        String prefix = thoroughfare+"."+device+".";
        List<DaPassingStationCollection> passingStationCollections = new ArrayList<>();
@@ -578,11 +590,11 @@
                passingStationCollections.add(daPassingStationCollection);
            }
            daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections);
            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
            return;
            //miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
            return "21";
        }else {
            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build());
            return;
            //miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build());
            return "22";
        }
    }