Commit 69d413c1 by 111-PC\111

[+]代码提交

1 parent e0d685f1
...@@ -12,6 +12,7 @@ import io.swagger.annotations.ApiOperation; ...@@ -12,6 +12,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
...@@ -52,8 +53,7 @@ public class DeviceController { ...@@ -52,8 +53,7 @@ public class DeviceController {
@ResponseBody @ResponseBody
@ApiOperation(value = "根据id获取设备") @ApiOperation(value = "根据id获取设备")
public R getDevicesById(@PathVariable String device_id){ public R getDevicesById(@PathVariable String device_id){
BaseDeviceService tuya = BussinessFactory.getInstance("tuya", BaseDeviceService.class); DeviceInfo deviceInfo=deviceService.getDevicesById(device_id);
DeviceInfo deviceInfo=tuya.getDevicesById(device_id);
return R.ok(JSONObject.toJSONString(deviceInfo)); return R.ok(JSONObject.toJSONString(deviceInfo));
} }
...@@ -83,4 +83,17 @@ public class DeviceController { ...@@ -83,4 +83,17 @@ public class DeviceController {
Function function =deviceService.getFunctionsByCat(category); Function function =deviceService.getFunctionsByCat(category);
return R.ok(JSONObject.toJSONString(function)); return R.ok(JSONObject.toJSONString(function));
} }
/**
* 根据设备下发指令
*
* @return
*/
@RequestMapping(value = "/devices/{device_id}/commands", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "根据设备下发指令")
public R instructionIssue(@PathVariable String device_id,@RequestBody String insjson){
String message = deviceService.instructionIssue(device_id, insjson);
return R.ok(JSONObject.toJSONString(message));
}
} }
package cn.com.glsx.modules.model.param;
import lombok.Data;
@Data
public class HomeInfo {
/** 家庭名字,必填*/
private String name;
/** 家庭地理位置*/
private String geo_name;
/** 经度*/
private Double lon;
/** 纬度*/
private Double lat;
}
...@@ -11,6 +11,6 @@ public class UserBo { ...@@ -11,6 +11,6 @@ public class UserBo {
private String username; private String username;
private String password; private String password;
private String username_type; private int username_type;
private String country_code; private String country_code;
} }
package cn.com.glsx.modules.model.param;
import lombok.Data;
@Data
public class memberInfo {
/** 国家码*/
private String country_code;
/** 成员账号*/
private String member_account;
/** 是否为管理员*/
private boolean admin;
/** 成员名字*/
private String name;
}
...@@ -3,11 +3,8 @@ package cn.com.glsx.modules.service; ...@@ -3,11 +3,8 @@ package cn.com.glsx.modules.service;
import cn.com.glsx.common.Constants; import cn.com.glsx.common.Constants;
import cn.com.glsx.common.redis.AccessTokenRedis; import cn.com.glsx.common.redis.AccessTokenRedis;
import cn.com.glsx.modules.model.param.AccessToken; import cn.com.glsx.modules.model.param.AccessToken;
import cn.com.glsx.modules.model.param.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
......
...@@ -32,6 +32,9 @@ public class DeviceService extends BaseDeviceService { ...@@ -32,6 +32,9 @@ public class DeviceService extends BaseDeviceService {
@Value("${tuya.getFunctionsByCatUrl}") @Value("${tuya.getFunctionsByCatUrl}")
private String getFunctionsByCatUrl; private String getFunctionsByCatUrl;
@Value("${tuya.instructionIssue}")
private String instructionIssue;
@Autowired @Autowired
private SendRequestService sendRequestService; private SendRequestService sendRequestService;
...@@ -40,7 +43,7 @@ public class DeviceService extends BaseDeviceService { ...@@ -40,7 +43,7 @@ public class DeviceService extends BaseDeviceService {
List<DeviceInfo> userInfo = null; List<DeviceInfo> userInfo = null;
ResponseBody responseBody = sendRequestService.sendRequestGet(getAllDevicesByUserUrl.replace("{uid}", uid)); ResponseBody responseBody = sendRequestService.sendRequestGet(getAllDevicesByUserUrl.replace("{uid}", uid));
if (responseBody != null && responseBody.isSuccess()) { if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult(); String result = responseBody.getResult();
userInfo = JSONObject.parseArray(result, DeviceInfo.class); userInfo = JSONObject.parseArray(result, DeviceInfo.class);
} else { } else {
log.info("调用涂鸦获取用户设备接口失败"); log.info("调用涂鸦获取用户设备接口失败");
...@@ -79,7 +82,7 @@ public class DeviceService extends BaseDeviceService { ...@@ -79,7 +82,7 @@ public class DeviceService extends BaseDeviceService {
Function function = null; Function function = null;
ResponseBody responseBody = sendRequestService.sendRequestGet(getFunctionsByCatUrl.replace("{category}", category)); ResponseBody responseBody = sendRequestService.sendRequestGet(getFunctionsByCatUrl.replace("{category}", category));
if (responseBody != null && responseBody.isSuccess()) { if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult(); String result = responseBody.getResult();
function = JSONObject.parseObject(result, Function.class); function = JSONObject.parseObject(result, Function.class);
} else { } else {
log.info("调用涂鸦获取用户设备接口失败"); log.info("调用涂鸦获取用户设备接口失败");
...@@ -87,4 +90,16 @@ public class DeviceService extends BaseDeviceService { ...@@ -87,4 +90,16 @@ public class DeviceService extends BaseDeviceService {
return function; return function;
} }
@Override
public String instructionIssue(String device_id, String insjson) {
String message = null;
ResponseBody responseBody = sendRequestService.sendRequestPost(instructionIssue.replace("{device_id}", device_id), insjson);
if (responseBody != null && responseBody.isSuccess()) {
message = "下发成功";
} else {
message = "下发失败";
}
return message;
}
} }
package cn.com.glsx.modules.service;
import cn.com.glsx.modules.model.param.HomeInfo;
import cn.com.glsx.modules.model.param.ResponseBody;
import cn.com.glsx.modules.model.param.memberInfo;
import com.alibaba.fastjson.JSONObject;
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.stereotype.Service;
import java.util.HashMap;
import java.util.List;
/**
* @author fengzhi
* @date 2021/3/5 09:26
* @description 涂鸦api,全屋管理
*/
@Service
@Slf4j
public class HomeService {
/********************************创建默认家庭,默认成员,设置成员权限********************************/
@Value("${tuya.baseUrl}")
private String baseUrl;
@Autowired
private SendRequestService requestService;
/**
* POST /v1.0/home/create-home
* 添加家庭,给⽤户添加⼀个家庭以及家庭下的房间。
* 说明:可以只添加家庭,房间留空。
*
* @param uid 涂鸦用户
* @param home 家庭
* @param rooms 房间
*
* @return 家庭 ID,即 home_id
*/
public R addHome(String uid, HomeInfo home, List<String> rooms) {
HashMap<String, Object> params = new HashMap<>();
params.put("uid", uid);
params.put("home", home);
params.put("rooms", null == rooms ? "" : rooms);
ResponseBody responseBody = requestService.sendRequestPost(baseUrl + "/home/create-home", JSONObject.toJSONString(params));
if(responseBody.isSuccess()){
return R.ok().data(Long.valueOf(responseBody.getResult())) ;
}else {
return R.error(responseBody.getCode(),responseBody.getMessage());
}
}
/**
* POST /v1.0/homes/{home_id}/members
* 添加家庭成员
* 说明:给某个家庭添加家庭成员
*
* @param home_id 家庭 ID
* @param app_schema 账号标识
* @param member 成员对象
*
*
*/
public R addHomeMember(String home_id, String app_schema,memberInfo member) {
HashMap<String, Object> params = new HashMap<>();
params.put("app_schema", app_schema);
params.put("member", member);
ResponseBody responseBody = requestService.sendRequestPost(baseUrl + "/homes/"+home_id+"/members", JSONObject.toJSONString(params));
if(responseBody.isSuccess()){
return R.ok().data(Boolean.parseBoolean(responseBody.getResult())) ;
}else {
return R.error(responseBody.getCode(),responseBody.getMessage());
}
}
/**
* PUT /v1.0/homes/{home_id}/members/{uid}
* 设置成员权限
* 说明:为家庭成员设置管理员和非管理员的角色权限,修改家庭成员的名字
*
* @param home_id 家庭 ID
* @param uid 涂鸦用户 ID
* @param admin 家庭管理员标示。
* true:管理员
* false:非管理员
*/
public R editMemberPermission(String home_id, String uid,boolean admin) {
HashMap<String, Object> params = new HashMap<>();
params.put("admin", admin);
ResponseBody responseBody = requestService.sendRequestPut(baseUrl + "/homes/"+home_id+"/members/"+uid, JSONObject.toJSONString(params));
if(responseBody.isSuccess()){
return R.ok().data(Boolean.parseBoolean(responseBody.getResult())) ;
}else {
return R.error(responseBody.getCode(),responseBody.getMessage());
}
}
}
...@@ -49,7 +49,7 @@ public class SendRequestService { ...@@ -49,7 +49,7 @@ public class SendRequestService {
} }
Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret, accessToken); Map<String, String> headerParams = HeaderParamUtils.buildHeaderParams(client_id, secret, accessToken);
try { try {
JSONObject jsonObject = HttpUtil.sendPost(requesturl, JSONObject.toJSONString(requestBody), headerParams); JSONObject jsonObject = HttpUtil.sendPost(requesturl, requestBody, headerParams);
responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class); responseBody = JSON.toJavaObject(jsonObject, ResponseBody.class);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -2,6 +2,7 @@ package cn.com.glsx.modules.service.abs; ...@@ -2,6 +2,7 @@ package cn.com.glsx.modules.service.abs;
import cn.com.glsx.modules.model.param.DeviceInfo; import cn.com.glsx.modules.model.param.DeviceInfo;
import cn.com.glsx.modules.model.param.Function; import cn.com.glsx.modules.model.param.Function;
import cn.com.glsx.modules.model.param.ResponseBody;
import java.util.List; import java.util.List;
...@@ -18,4 +19,6 @@ public abstract class BaseDeviceService { ...@@ -18,4 +19,6 @@ public abstract class BaseDeviceService {
public abstract Function getFunctionsById(String uid); public abstract Function getFunctionsById(String uid);
public abstract Function getFunctionsByCat(String cat); public abstract Function getFunctionsByCat(String cat);
public abstract String instructionIssue(String device_id, String insjson);
} }
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
</javaClientGenerator> </javaClientGenerator>
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 --> <!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 -->
<table tableName="tuya_user" domainObjectName="TuyaUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="smart_devide_status" domainObjectName="SmartDevideStatus" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"/>
</context> </context>
</generatorConfiguration> </generatorConfiguration>
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.modules.service; package cn.com.glsx.modules.service;
import cn.com.glsx.modules.model.param.HomeInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!