| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.api.GatewayRemoteManager; |
| | | import com.fzzy.gateway.hx2023.data.CloudSendData; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | | import com.fzzy.gateway.hx2023.data.SyncReqData; |
| | | import com.fzzy.mqtt.MqttProviderConfig; |
| | | import com.fzzy.gateway.hx2023.data.CloudSendData; |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.mqtt.MqttGatewayService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Resource |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | @Resource |
| | | private MqttProviderConfig providerClient; |
| | | private MqttGatewayService mqttGatewayService; |
| | | |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param message |
| | | */ |
| | | public void onReceiveMessage(String message) { |
| | | public void onReceiveMessage(String topic,String message) { |
| | | |
| | | try { |
| | | CloudSendData cloudSendData = JSONObject.parseObject(message, CloudSendData.class); |
| | | |
| | | |
| | | String functionId = cloudSendData.getFunctionId(); |
| | | |
| | | //粮情采集 |
| | | if (ScConstant.FUNCTION_getTAndRHInfo.equals(functionId)) { |
| | | getTAndRHInfo(cloudSendData); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | |
| | | log.error("--------执行异常-----{}",e); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId); |
| | | |
| | | SyncReqData syncReqData = new SyncReqData(); |
| | | BaseReqData syncReqData = new BaseReqData(); |
| | | syncReqData.setDeviceId(deviceId); |
| | | syncReqData.setMessageId(cloudSendData.getMessageId()); |
| | | syncReqData.setMessageType(cloudSendData.getMessageType()); |
| | |
| | | syncReqData.setAutoReplay(true); |
| | | syncReqData.setDevice(device); |
| | | |
| | | BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain2(syncReqData); |
| | | |
| | | //TODO --->>暂时返回测试数据 |
| | | |
| | | //BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain(syncReqData); |
| | | |
| | | BaseResp resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrain(syncReqData); |
| | | |
| | | //自动推送 |
| | | if (200 == resp.getCode() && syncReqData.isAutoReplay()) { |
| | | String topic = "/${productId}/${deviceId}/properties/report"; |
| | | |
| | | topic = topic.replace("${productId}", device.getProductId()).replace("${deviceId}", device.getDeviceId()); |
| | | |
| | | providerClient.publish(topic, resp.getData()); |
| | | |
| | | log.info("=======粮情推送==========={}", resp.getData()); |
| | | syncReqData.setData(resp.getData()); |
| | | gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainData(syncReqData); |
| | | } |
| | | } |
| | | } |