|
|
@@ -0,0 +1,103 @@
|
|
|
+package org.springblade.third.iotdevice.feign;
|
|
|
+
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.ctg.ag.sdk.biz.AepDeviceManagementClient;
|
|
|
+import com.ctg.ag.sdk.biz.aep_device_management.CreateDeviceRequest;
|
|
|
+import com.ctg.ag.sdk.biz.aep_device_management.QueryDeviceListRequest;
|
|
|
+import com.ctg.ag.sdk.biz.aep_device_management.QueryDeviceListResponse;
|
|
|
+import org.springblade.common.constant.AepConstant;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.device.entity.IotDevice;
|
|
|
+import org.springblade.third.iotdevice.dto.AepIotDeviceQueryDto;
|
|
|
+import org.springblade.third.iotdevice.entity.AepIotDeviceEntity;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author lidexi
|
|
|
+ * @date 2021/5/29 16:35
|
|
|
+ */
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/feign/third/aep")
|
|
|
+public class AepDeviceManageClient implements IAepDeviceManageClient {
|
|
|
+ @Override
|
|
|
+ @PostMapping("/addDevice")
|
|
|
+ public R createDevice(@RequestBody IotDevice iotDevice) {
|
|
|
+ AepDeviceManagementClient client = AepDeviceManagementClient.newClient()
|
|
|
+ .appKey(AepConstant.APPKEY).appSecret(AepConstant.APPSECRET)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ CreateDeviceRequest request = new CreateDeviceRequest();
|
|
|
+// request.addParamMasterKey()
|
|
|
+// request.setParamMasterKey(MasterKey); // single value
|
|
|
+// request.addParamMasterKey(MasterKey); // or multi values
|
|
|
+// request.setBody([BINARY DATA]); //具体格式见前面请求body说明
|
|
|
+ try {
|
|
|
+ System.out.println(client.CreateDevice(request));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+// more requests
|
|
|
+
|
|
|
+ client.shutdown();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @PostMapping("/deleteDevice")
|
|
|
+ public R deleteDevice() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @PostMapping("/queryDevice")
|
|
|
+ public R queryDevice(@RequestBody AepIotDeviceQueryDto aepIotDeviceQueryDto) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @PostMapping("/queryDeviceList")
|
|
|
+ public R queryDeviceList(@RequestBody AepIotDeviceQueryDto aepIotDeviceQueryDto) {
|
|
|
+ AepDeviceManagementClient client = AepDeviceManagementClient.newClient()
|
|
|
+ .appKey(AepConstant.APPKEY).appSecret(AepConstant.APPSECRET)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ QueryDeviceListRequest request = new QueryDeviceListRequest();
|
|
|
+ request.setParamMasterKey(aepIotDeviceQueryDto.getMasterKey());
|
|
|
+ request.setParamProductId(aepIotDeviceQueryDto.getProductId());
|
|
|
+ request.setParamPageNow(aepIotDeviceQueryDto.getPageNow());
|
|
|
+ request.setParamPageSize(aepIotDeviceQueryDto.getPageSize());
|
|
|
+
|
|
|
+ List<AepIotDeviceEntity> aepIotDeviceEntities = null;
|
|
|
+ try {
|
|
|
+ QueryDeviceListResponse queryDeviceListResponse = client.QueryDeviceList(request);
|
|
|
+ JSONObject body = JSONUtil.parseObj(new String(queryDeviceListResponse.getBody()));
|
|
|
+ JSONObject result = JSONUtil.parseObj(body.get("result"));
|
|
|
+ JSONArray list = JSONUtil.parseArray(result.get("list"));
|
|
|
+ aepIotDeviceEntities = com.alibaba.fastjson.JSONObject.parseArray(list.toString(), AepIotDeviceEntity.class);
|
|
|
+
|
|
|
+ System.out.println();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+// more requests
|
|
|
+
|
|
|
+ client.shutdown();
|
|
|
+ return R.data(aepIotDeviceEntities);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @PostMapping("/updateDevice")
|
|
|
+ public R updateDevice() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|