vince
2024-05-20 75bdadc0c4e468217b93142d965cd92ee52838ec
src/main/java/com/fzzy/gateway/controller/GatewayDeviceController.java
@@ -55,7 +55,9 @@
        if ("testGrain".equals(param.getBizType())) {
            return testGrain(param);
        }
        if ("testGrain".equals(param.getBizType())) {
            return testGrain(param);
        }
        if ("ajaxTestKafkaGrain".equals(param.getBizType())) {
            return ajaxTestKafkaGrain(param);
        }
@@ -68,6 +70,143 @@
            return ajaxTestLpr(param);
        }
        return "SUCCESS";
    }
    /**
     * 下行分机测试入口
     *
     * @param param
     * @return
     */
    @PostMapping("/test/IDE")
    public @ResponseBody
    String testIDE(@RequestBody GateWayParam param) throws Exception {
        if (StringUtils.isEmpty(param.getBizType())) {
            return "ERROR:没有获取到业务类型,执行失败";
        }
        //获取分机配置
        if ("syncConf".equals(param.getBizType())) {
            return syncConf(param);
        }
        if ("writeConf".equals(param.getBizType())) {
            return writeConf(param);
        }
        if ("initParam".equals(param.getBizType())) {
            return initCable(param);
        }
        if ("disconnect".equals(param.getBizType())) {
            return disconnect(param);
        }
        if ("transparent".equals(param.getBizType())) {
            return transparent(param);
        }
        return "SUCCESS";
    }
    private String transparent(GateWayParam param) {
        String deviceId = param.getDeviceId();
        GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
        BaseReqData reqData = new BaseReqData();
        reqData.setDeviceId(device.getDeviceId());
        reqData.setProductId(device.getProductId());
        reqData.setDeviceName(device.getDeviceName());
        reqData.setDevice(device);
        reqData.setAutoReplay(false);
        BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).transparent(reqData);
        if (BaseResp.CODE_200 != resp.getCode()) {
            return "ERROR:" + resp.getMsg();
        }
        return "SUCCESS";
    }
    private String disconnect(GateWayParam param) {
        String deviceId = param.getDeviceId();
        GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
        BaseReqData reqData = new BaseReqData();
        reqData.setDeviceId(device.getDeviceId());
        reqData.setProductId(device.getProductId());
        reqData.setDeviceName(device.getDeviceName());
        reqData.setDevice(device);
        reqData.setAutoReplay(false);
        BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).disconnect(reqData);
        if (BaseResp.CODE_200 != resp.getCode()) {
            return "ERROR:" + resp.getMsg();
        }
        return "SUCCESS";
    }
    private String initCable(GateWayParam param) {
        String deviceId = param.getDeviceId();
        GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
        BaseReqData reqData = new BaseReqData();
        reqData.setDeviceId(device.getDeviceId());
        reqData.setProductId(device.getProductId());
        reqData.setDeviceName(device.getDeviceName());
        reqData.setDevice(device);
        reqData.setAutoReplay(false);
        BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).initCable(reqData);
        if (BaseResp.CODE_200 != resp.getCode()) {
            return "ERROR:" + resp.getMsg();
        }
        return "SUCCESS";
    }
    private String syncConf(GateWayParam param) {
        String deviceId = param.getDeviceId();
        GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
        BaseReqData reqData = new BaseReqData();
        reqData.setDeviceId(device.getDeviceId());
        reqData.setProductId(device.getProductId());
        reqData.setDeviceName(device.getDeviceName());
        reqData.setDevice(device);
        reqData.setAutoReplay(false);
        BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncConf(reqData);
        if (BaseResp.CODE_200 != resp.getCode()) {
            return "ERROR:" + resp.getMsg();
        }
        return "SUCCESS";
    }
    private String writeConf(GateWayParam param) {
        String deviceId = param.getDeviceId();
        GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
        BaseReqData reqData = new BaseReqData();
        reqData.setDeviceId(device.getDeviceId());
        reqData.setProductId(device.getProductId());
        reqData.setDeviceName(device.getDeviceName());
        reqData.setDevice(device);
        reqData.setAutoReplay(false);
        BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).writeConf(reqData);
        if (BaseResp.CODE_200 != resp.getCode()) {
            return "ERROR:" + resp.getMsg();
        }
        return "SUCCESS";
    }
@@ -98,7 +237,7 @@
            reqData = new BaseReqData(device);
            reqData.setIndex(i);
            syncLprService = gatewayRemoteManager.getSyncLprService(device.getSyncProtocol());
            if(null == syncLprService) continue;
            if (null == syncLprService) continue;
            syncLprService.initLpr(reqData);
            i++;
        }
@@ -126,10 +265,10 @@
            return "ERROR:当前设备没有配置布线规则,无法执行";
        }
        BaseResp resp =null;
        if(GatewayDeviceProtocol.DEVICE_TEST.getCode().equals(device.getSyncProtocol())){
        BaseResp resp;
        if (GatewayDeviceProtocol.DEVICE_TEST.getCode().equals(device.getSyncProtocol())) {
            resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrain(reqData);
        }else{
        } else {
            reqData.setAutoReplay(false);
            resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain(reqData);
        }
@@ -159,17 +298,25 @@
        BaseReqData reqData;
        BaseResp resp;
        for (GatewayDevice device : list) {
            //如果不是粮情分机跳过
            if (!GatewayDeviceType.TYPE_07.getCode().equals(device.getType())) {
                continue;
            }
            reqData = new BaseReqData();
            reqData.setProductId(device.getProductId());
            reqData.setDeviceName(device.getDeviceName());
            reqData.setDeviceId(param.getDeviceId());
            reqData.setDayTime(param.getDayTime());
            reqData.setDevice(device);
            //获取到
            resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrainKafka(reqData);
            log.info("resp = "+resp.toString());
            //自动推送
            if (BaseResp.CODE_200 == resp.getCode()) {
                reqData.setData(resp.getData());
                gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainDataByKafka(reqData);
                gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainDataByHand(reqData);
            }
        }