| | |
| | | * @throws Exception |
| | | */ |
| | | @PostMapping("/push-grain") |
| | | public @ResponseBody BaseResp pushGrain(@RequestBody Fz40Grain grainData) throws Exception { |
| | | public @ResponseBody |
| | | BaseResp pushGrain(@RequestBody Fz40Grain grainData) { |
| | | |
| | | BaseResp resp = new BaseResp(); |
| | | try { |
| | | |
| | | //根据系统仓库编码获取配置设备信息 |
| | | GatewayDevice device = GatewayUtils.getCacheByDepotSysId(grainData.getDepotId()); |
| | | log.info("----------主动推送粮情接口执行----{}",grainData); |
| | | |
| | | if (null == device) { |
| | | resp.setMsg("网关中没有获取到配置的终端设备信息,无法执行。仓库编码=" + grainData.getDepotId()); |
| | | //根据系统仓库编码获取配置设备信息 |
| | | GatewayDevice device = GatewayUtils.getCacheByDepotSysId(grainData.getDepotId()); |
| | | |
| | | if (null == device) { |
| | | resp.setMsg("网关中没有获取到配置的终端设备信息,无法执行。仓库编码=" + grainData.getDepotId()); |
| | | resp.setCode(BaseResp.CODE_500); |
| | | return resp; |
| | | } |
| | | |
| | | //数据封装转换 |
| | | GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()); |
| | | if (null == reportService) { |
| | | log.error("------------粮情推送失败,系统不存在当前协议执行类----{}", device.getDeviceName()); |
| | | resp.setMsg("粮情推送失败,系统不存在当前协议执行类,网关设备=" + device.getDeviceName()); |
| | | resp.setCode(BaseResp.CODE_500); |
| | | return resp; |
| | | } |
| | | |
| | | //数据封装 |
| | | resp = reportService.grainData2GatewayApiInfo(grainData, device); |
| | | |
| | | BaseReqData reqData = new BaseReqData(); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | |
| | | reqData.setDevice(device); |
| | | reqData.setData(resp.getData()); |
| | | |
| | | //手动推送到平台 |
| | | resp = reportService.reportGrainDataByHand(reqData); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("-----------手动推送粮情数据执行异常---{}", e); |
| | | resp.setCode(BaseResp.CODE_500); |
| | | return resp; |
| | | resp.setMsg("执行异常:" + e.getMessage()); |
| | | } |
| | | |
| | | //数据封装转换 |
| | | GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()); |
| | | if (null == reportService) { |
| | | log.error("------------粮情推送失败,系统不存在当前协议执行类----{}", device.getDeviceName()); |
| | | resp.setMsg("粮情推送失败,系统不存在当前协议执行类,网关设备=" + device.getDeviceName()); |
| | | resp.setCode(BaseResp.CODE_500); |
| | | return resp; |
| | | } |
| | | |
| | | //数据封装 |
| | | resp = reportService.grainData2GatewayApiInfo(grainData, device); |
| | | |
| | | BaseReqData reqData = new BaseReqData(); |
| | | reqData.setProductId(device.getProductId()); |
| | | reqData.setDeviceName(device.getDeviceName()); |
| | | reqData.setDeviceId(device.getDeviceId()); |
| | | |
| | | reqData.setDevice(device); |
| | | |
| | | //手动推送到平台 |
| | | resp = reportService.reportGrainDataByHand(reqData); |
| | | |
| | | |
| | | return resp; |
| | | } |
| | | |
| | | } |