| | |
| | | package com.sandu.ximon.admin.manager.iot.rrpc.mainboard; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.aliyuncs.DefaultAcsClient; |
| | | import com.aliyuncs.iot.model.v20180120.InvokeThingServiceResponse; |
| | | import com.aliyuncs.profile.DefaultProfile; |
| | | import com.aliyuncs.profile.IClientProfile; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.ximon.admin.manager.iot.amqp.MqttMainBoardConfig; |
| | | import com.sandu.ximon.admin.manager.iot.frame.IRequestFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.BaseResponseInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.BaseInvokeSyncService; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.dto.InvokeParam; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.dto.WrapResponseCommonFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.util.FrameUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | |
| | | public class MainBoardInvokeSyncService extends BaseInvokeSyncService { |
| | | private static volatile DefaultAcsClient client = null; |
| | | |
| | | private final static String PRODUCT_KEY = "a1JsfPG4iKW"; |
| | | private final static String PRODUCT_KEY = "a1JsfPG4iKW"; //todo 提取到配置文件 |
| | | |
| | | @Override |
| | | public String getProductKey() { |
| | | return PRODUCT_KEY; |
| | | } |
| | | |
| | | @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; |
| | | } |
| | | // @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; |
| | | // } |
| | | // |
| | | // @Override |
| | | // 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 <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; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String s = "FEA581000BFE010003FFFF004597147735AB2D28"; |
| | | System.out.println(FrameUtils.decodeReportMessage(s)); |
| | | } |
| | | |
| | | private static class SingletonClassInstance { |
| | | private static final MainBoardInvokeSyncService INSTANCE = new MainBoardInvokeSyncService(); |
| | | } |
| | | |
| | | private MainBoardInvokeSyncService() { |
| | | protected MainBoardInvokeSyncService() { |
| | | } |
| | | |
| | | public static MainBoardInvokeSyncService getInstance() { |