| | |
| | | package com.fzzy.gateway.service; |
| | | |
| | | import com.bstek.dorado.annotation.DataResolver; |
| | | import com.bstek.dorado.annotation.Expose; |
| | | import com.fzzy.api.data.GatewayDeviceType; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.api.GatewayRemoteManager; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.hx2023.data.SyncReqData; |
| | | import com.fzzy.gateway.service.repository.GatewayDeviceRep; |
| | | import com.fzzy.mqtt.MqttProviderConfig; |
| | | import com.fzzy.mqtt.MqttPublishService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class GatewayDeviceService2 { |
| | | |
| | | @Resource |
| | | private GatewayDeviceRep gatewayDeviceRep; |
| | | |
| | | @Resource |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | @Resource |
| | | private MqttPublishService publishService; |
| | | |
| | | public List<GatewayDevice> listAll() { |
| | | Sort sort = new Sort(Sort.Direction.ASC, "deviceId"); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 测试MQTT粮情检测 |
| | | * gatewayDeviceService#ajaxTestGrain2 |
| | | * 粮情推送测试 |
| | | * |
| | | * @param data |
| | | * @return |
| | | */ |
| | | @Expose |
| | | public String ajaxTestGrain2(GatewayDevice data) { |
| | | |
| | | SyncReqData reqData = new SyncReqData(); |
| | | reqData.setDevice(data); |
| | | reqData.setAutoReplay(true); |
| | | reqData.setMessageType(ScConstant.MESSAGE_TYPE_INVOKE_FUNCTION); |
| | | reqData.setMessageId(ScConstant.getMessageId()); |
| | | reqData.setFunctionId(ScConstant.FUNCTION_getTAndRHInfo); |
| | | |
| | | |
| | | if (!GatewayDeviceType.TYPE_07.getCode().equals(data.getType())) { |
| | | return "ERROR:当前设备非粮情设备不支持当前操作"; |
| | | } |
| | | |
| | | BaseResp resp = gatewayRemoteManager.getSyncGrainService(data.getSyncProtocol()).syncGrain2(reqData); |
| | | |
| | | //自动推送 |
| | | if (200 == resp.getCode() && reqData.isAutoReplay()) { |
| | | String topic = ScConstant.TOPIC_REPORT; |
| | | topic = topic.replace("${productId}", data.getProductId()).replace("${deviceId}", data.getDeviceId()); |
| | | |
| | | publishService.publishMsg(topic, resp.getData()); |
| | | } |
| | | |
| | | log.info("=======手动测试粮情推送==========={}", resp.getData()); |
| | | |
| | | return "SUCCESS:执行完成"; |
| | | } |
| | | |
| | | } |