| | |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.dto.WrapResponseCommonFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.topic.IBaseTopic; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.topic.ICustomizeTopic; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.util.FrameUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | |
| | | * @param clz 内部帧响应实体类 如果不想自己解析 可带上 |
| | | * @return 返回的解码帧实体类 同时把内部帧解码之后也携带上 |
| | | */ |
| | | public abstract <T extends BaseResponseInnerFrame<T>> WrapResponseCommonFrame<T> sendRRPC(String deviceName, IRequestFrame iRequestFrame, Class<T> clz); |
| | | public <T extends BaseResponseInnerFrame<T>> WrapResponseCommonFrame<T> sendRRPC(String deviceName, IRequestFrame iRequestFrame, Class<T> clz){ |
| | | CommonFrame commonFrame = sendRRPC(deviceName, iRequestFrame); |
| | | if (commonFrame == null) { |
| | | throw new BusinessException("rrpc请求失败"); |
| | | } |
| | | WrapResponseCommonFrame<T> responseCommonFrame = new WrapResponseCommonFrame<>(); |
| | | BeanUtils.copyProperties(commonFrame, responseCommonFrame); |
| | | try { |
| | | responseCommonFrame.setResponseInnerFrame(clz.newInstance().transformFrame(responseCommonFrame.getPayload())); |
| | | } catch (InstantiationException | IllegalAccessException e) { |
| | | throw new BusinessException(String.format("找不到%s的构造函数", clz.getName())); |
| | | } |
| | | return responseCommonFrame; |
| | | } |
| | | |
| | | @Override |
| | | public CommonFrame sendRRPC(String deviceName, IRequestFrame iRequestFrame) { |
| | | InvokeParam param = new InvokeParam(); |
| | | param.setOperate("1001"); |
| | | param.setFrame(iRequestFrame.getEncodeFrame()); |
| | | InvokeThingServiceResponse.Data data = invokeThing(deviceName, param); |
| | | if (data == null) { |
| | | return null; |
| | | } |
| | | String result = data.getResult(); |
| | | result = result.replace("\\", ""); |
| | | Map map = JSON.parseObject(result, Map.class); |
| | | result = (String) map.get("msg"); |
| | | CommonFrame connectFrame = FrameUtils.transformMessageToFrame(result); |
| | | return connectFrame; |
| | | } |
| | | |
| | | /** |
| | | * 基础通信同步调用 |