Commit 0cf161da by wnb0128

车家智能移动端服务 用户第三方设备获取接口--think.wang

1 parent 7a6eb6ee
package com.glsx.api.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.glsx.api.exception.BusinessException;
import com.glsx.api.exception.ResultEnum;
import com.glsx.api.pojo.request.UserRelationReq;
import com.glsx.api.pojo.response.UserRelationResp;
import com.glsx.api.remote.UserFeignClient;
import com.glsx.plat.common.utils.HttpUtils;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
*
* 远程产品服务controller
* 暂时只有涂鸦
*
*/
@Slf4j
@RestController
@RequestMapping("/remoteDevice")
public class RemoteProductController {
@Value("${device_remote_url}")
private String remoteUrl;
@Autowired
private UserFeignClient userFeignClient;
/**
* 用户获取远程产品列表数据
*
* @return 结果
*/
@RequestMapping(value = "/getList", method = {RequestMethod.POST})
public R getList(@RequestBody UserRelationReq req) {
Long id = req.getId();
if(id == null || id <= 0L){
throw BusinessException.create(ResultEnum.PARAM_ERROR);
}
UserRelationResp user = userFeignClient.getSingle(req);
if(user == null){
throw BusinessException.create(ResultEnum.USER_NOT_EXIST);
}
return R.ok().data(this.getRemoteDevice(user.getThirdId()));
}
private JSONArray getRemoteDevice(String thirdId){
StringBuffer url = new StringBuffer(remoteUrl);
url.append("/device/").append(thirdId).append("/devices");
log.info("请求远程设备列表接口地址:{}", url.toString());
try{
String result = HttpUtils.get(url.toString());
log.info("获取用户设备列表数据返回结果:{}", result);
if (StringUtils.isNotEmpty(result)) {
JSONObject json = JSON.parseObject(result);
if (json.getInteger("code").equals(200)) {
JSONArray list = new JSONArray();
JSONArray array = json.getJSONArray("message");
int len = array.size();
for (int i = 0; i < len; i++) {
JSONObject object = array.getJSONObject(i);
JSONObject val = new JSONObject();
val.put("productId", object.getString("product_id"));
val.put("uuid", object.getString("uuid"));
val.put("productName", object.getString("product_name"));
list.add(val);
}
return list;
}
}
}catch (Exception e){
log.error("获取用户设备列表数据失败:{}", e);
}
return null;
}
}
...@@ -37,8 +37,11 @@ import java.util.Date; ...@@ -37,8 +37,11 @@ import java.util.Date;
@RequestMapping("/user") @RequestMapping("/user")
public class UserController extends BaseController{ public class UserController extends BaseController{
@Value("${tu_ya_sync_interface}") @Value("${device_remote_url}")
private String syncUserUrl; private String remoteUrl;
@Value("${tuya_user_sync}")
private String syncUser;
@Autowired @Autowired
private UserFeignClient userFeignClient; private UserFeignClient userFeignClient;
...@@ -81,13 +84,15 @@ public class UserController extends BaseController{ ...@@ -81,13 +84,15 @@ public class UserController extends BaseController{
object.put("username_type", 1); object.put("username_type", 1);
object.put("password", password); object.put("password", password);
try { try {
log.info("请求注册涂鸦平台接口地址:{},参数:{}", syncUserUrl, object.toJSONString()); StringBuffer syncUserUrl = new StringBuffer(remoteUrl);
String result = HttpUtils.post(syncUserUrl, object.toJSONString()); syncUserUrl.append(syncUser);
log.info("请求注册涂鸦平台接口地址:{},参数:{}", syncUserUrl.toString(), object.toJSONString());
String result = HttpUtils.post(syncUserUrl.toString(), object.toJSONString());
log.info("注册涂鸦平台返回结果:{}", result); log.info("注册涂鸦平台返回结果:{}", result);
if (StringUtils.isNotEmpty(result)) { if (StringUtils.isNotEmpty(result)) {
JSONObject json = JSON.parseObject(result); JSONObject json = JSON.parseObject(result);
if (json.getInteger("code").equals(200)) { if (json.getInteger("code").equals(200)) {
return json.getString("message"); return json.getJSONObject("message").getString("uid");
} }
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -13,6 +13,7 @@ public enum ResultEnum { ...@@ -13,6 +13,7 @@ public enum ResultEnum {
PARAM_ERROR(1001, "参数错误"), PARAM_ERROR(1001, "参数错误"),
ID_NOT_FOUND(1002, "ID不存在"), ID_NOT_FOUND(1002, "ID不存在"),
USER_NOT_EXIST(1002, "用户不存在"),
PRODUCT_NOT_FOUND(2001, "产品ID未找到"), PRODUCT_NOT_FOUND(2001, "产品ID未找到"),
PRODUCT_NAME_DUPLICATE(2002, "产品名称重复"), PRODUCT_NAME_DUPLICATE(2002, "产品名称重复"),
......
...@@ -21,6 +21,8 @@ feign.server.url=http://localhost:8209/smartService ...@@ -21,6 +21,8 @@ feign.server.url=http://localhost:8209/smartService
dubbo.registry.address=zookeeper://192.168.1.36:2181?init.timeout=60000 dubbo.registry.address=zookeeper://192.168.1.36:2181?init.timeout=60000
dubbo.registry.timeout=10000 dubbo.registry.timeout=10000
#\u6D82\u9E26\u540C\u6B65\u7528\u6237\u63A5\u53E3 #\u8BBE\u5907\u8FDC\u7A0B\u8BBF\u95EEurl
tu_ya_sync_interface=http://192.168.3.137:8091/smartApi/sync_user device_remote_url=http://192.168.3.222:8099/smartDevices-platform-service
#\u6D82\u9E26\u7528\u6237\u6CE8\u518C\u63A5\u53E3
tuya_user_sync=/user/registerUser
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!