cl
2024-05-23 ba1a7a9ef126296e2798e313dc5b43f775a1123c
guns-vip-main/src/main/java/cn/stylefeng/guns/plcserver/callback/OP160Callback.java
@@ -41,7 +41,7 @@
import java.util.List;
@Component
public class OP160Callback implements SubscriptionCallback {
public class OP160Callback {
    public MiloService miloService;
@@ -125,42 +125,6 @@
        this.productionOrderBatchInfoService = productionOrderBatchInfoService;
    }
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            //心跳
            if(null != value && identifier.equals(OPCElement.OP160_F_HEART_BEAT)){
                if( "false".equals(value.toString()))
                {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP160_F_HEART_BEAT,true);
                    miloService.writeToOpcUa(entity);
                }
            }
            //PLC进站
            else if(null != value && identifier.equals(OPCElement.OP160_J_PLC_START)){
                if("true".equals(value.toString())){
                    handleOrder();
                }
            }
            //PLC出站
            else if(null != value && identifier.equals(OPCElement.OP160_J_PLC_FINISH)){
                if("true".equals(value.toString())){
                    handleFinsh();
                    handleInfo();
                    handleMaterial();
                }
            }else{
                System.out.println("值没有变");
            }
        } catch (Exception e) {
            ecpStr ="出现异常:" + logUtil.getTrace(e);
        }finally {
            if(!"".equals(ecpStr)){
                logger.info(ecpStr+"\r\n");
            }
        }
    }
    //PC读工单
    public void handleOrder() throws Exception {
@@ -197,7 +161,8 @@
        String S_PRODUCT_STATE_CODE = miloService.
                readFromOpcUa(OPCElement.OP160_S_PRODUCT_STATE_CODE)
                .getValue().toString();
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP160_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        if("2".equals(S_PRODUCT_STATE_CODE)){
            ProductionOrderRecordsParam productionOrderRecordsParam = new ProductionOrderRecordsParam();
            productionOrderRecordsParam.setWorkOrderNo(S_ORDER_CODE);
@@ -206,7 +171,8 @@
            if(!list.isEmpty()){
                ProductionOrderRecordsResult productionOrderRecordsResult = list.get(0);
                productionOrderRecordsParam.setId(productionOrderRecordsResult.getId());
                productionOrderRecordsParam.setWhetherPass(S_PRODUCT_STATE_CODE);
                productionOrderRecordsParam.setWhetherPass("不合格");
                productionOrderRecordsParam.setEndTime(DateTool.getLocalTimeForDate());
                productionOrderRecordsService.update(productionOrderRecordsParam);
            }
        }
@@ -222,13 +188,14 @@
        param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
        passingStationCollectionService.add(param);
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP160_J_PC_FINISH,true);
        miloService.writeToOpcUa(entity);//写PC完成
        logger.info("handleFinsh PC处理完成!");
    }
    public void handleMaterial() {
        if(S_ORDER_CODE.isEmpty()){
            return;
        }
        //查询批次上料信息
        ProductionOrderBatchInfoParam productionOrderBatchInfoParam = new ProductionOrderBatchInfoParam();
        productionOrderBatchInfoParam.setWorkOrderNo(S_ORDER_CODE);