Commit ca1b1cdb by 周海宝

Merge branch 'dev' into 'master'

Dev

See merge request !4
2 parents d106981f f9f48f50
package cn.com.glsx.modules.controller;
import cn.com.glsx.common.BussinessFactory.BussinessFactory;
import cn.com.glsx.modules.model.param.DeviceInfo;
import cn.com.glsx.modules.model.param.Function;
import cn.com.glsx.modules.service.DeviceService;
import cn.com.glsx.modules.service.abs.BaseDeviceService;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api;
......@@ -17,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* @author zhouhaibao
......@@ -39,9 +36,8 @@ public class DeviceController {
@RequestMapping(value = "/{uid}/devices", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取用户下的设备列表")
public R getAllDevicesByUser(@PathVariable String uid){
List<DeviceInfo> list=deviceService.getAllDevicesByUser(uid);
return R.ok(JSONObject.toJSONString(list));
public R getAllDevicesByUser(@PathVariable String uid) {
return deviceService.getAllDevicesByUser(uid);
}
/**
......@@ -52,9 +48,8 @@ public class DeviceController {
@RequestMapping(value = "/devices/{device_id}", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据id获取设备")
public R getDevicesById(@PathVariable String device_id){
DeviceInfo deviceInfo=deviceService.getDevicesById(device_id);
return R.ok(JSONObject.toJSONString(deviceInfo));
public R getDevicesById(@PathVariable String device_id) {
return deviceService.getDevicesById(device_id);
}
......@@ -66,9 +61,8 @@ public class DeviceController {
@RequestMapping(value = "/devices/{device_id}/functions", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据id获取指令集")
public R getFunctionsById(@PathVariable String device_id){
Function function =deviceService.getFunctionsById(device_id);
return R.ok(JSONObject.toJSONString(function));
public R getFunctionsById(@PathVariable String device_id) {
return deviceService.getFunctionsById(device_id);
}
/**
......@@ -79,9 +73,8 @@ public class DeviceController {
@RequestMapping(value = "/functions/{category}", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据品类获取指令集")
public R getFunctionsByCat(@PathVariable String category){
Function function =deviceService.getFunctionsByCat(category);
return R.ok(JSONObject.toJSONString(function));
public R getFunctionsByCat(@PathVariable String category) {
return deviceService.getFunctionsByCat(category);
}
/**
......@@ -92,8 +85,7 @@ public class DeviceController {
@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));
public R instructionIssue(@PathVariable String device_id, @RequestBody String insjson) {
return deviceService.instructionIssue(device_id, insjson);
}
}
......@@ -36,11 +36,7 @@ public class UserController {
@ResponseBody
@ApiOperation(value = "注册用户")
public R registerUser(@RequestBody UserBo userBo) {
String uid = userService.registerUser(userBo);
if(StringUtils.isNotBlank(uid)){
return R.ok(uid);
}
return R.error();
return userService.registerUser(userBo);
}
......@@ -54,7 +50,6 @@ public class UserController {
@ResponseBody
@ApiOperation(value = "查询用户")
public R getUserInfo(@PathVariable String id) {
UserInfo userInfo = userService.getUserInfo(id);
return R.ok(JSONObject.toJSONString(userInfo));
return userService.getUserInfo(id);
}
}
......@@ -26,4 +26,6 @@ public class ResponseBody {
* 返回message
*/
private String message;
private String msg;
}
package cn.com.glsx.modules.service;
import cn.com.glsx.modules.model.param.DeviceInfo;
import cn.com.glsx.modules.model.param.Function;
import cn.com.glsx.modules.model.param.ResponseBody;
import cn.com.glsx.modules.service.abs.BaseDeviceService;
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.List;
/**
* @author zhouhaibao
* @date 2021/3/5 10:17
*/
@Service
@Slf4j
public class DeviceService extends BaseDeviceService {
public class DeviceService {
@Value("${tuya.getAllDevicesByUserUrl}")
private String getAllDevicesByUserUrl;
......@@ -38,68 +33,53 @@ public class DeviceService extends BaseDeviceService {
@Autowired
private SendRequestService sendRequestService;
@Override
public List<DeviceInfo> getAllDevicesByUser(String uid) {
List<DeviceInfo> userInfo = null;
public R getAllDevicesByUser(String uid) {
ResponseBody responseBody = sendRequestService.sendRequestGet(getAllDevicesByUserUrl.replace("{uid}", uid));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
userInfo = JSONObject.parseArray(result, DeviceInfo.class);
} else {
log.info("调用涂鸦获取用户设备接口失败");
return R.ok(result);
}
return userInfo;
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
}
@Override
public DeviceInfo getDevicesById(String device_id) {
DeviceInfo deviceInfo = null;
public R getDevicesById(String device_id) {
ResponseBody responseBody = sendRequestService.sendRequestGet(getDevicesByIdUrl.replace("{device_id}", device_id));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
deviceInfo = JSONObject.parseObject(result, DeviceInfo.class);
} else {
log.info("调用涂鸦获取设备接口失败");
return R.ok(result);
}
return deviceInfo;
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
}
@Override
public Function getFunctionsById(String device_id) {
Function function = null;
public R getFunctionsById(String device_id) {
ResponseBody responseBody = sendRequestService.sendRequestGet(getFunctionsByIdUrl.replace("{device_id}", device_id));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
function = JSONObject.parseObject(result, Function.class);
} else {
log.info("调用涂鸦获取用户设备接口失败");
return R.ok(result);
}
return function;
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
}
@Override
public Function getFunctionsByCat(String category) {
Function function = null;
public R getFunctionsByCat(String category) {
ResponseBody responseBody = sendRequestService.sendRequestGet(getFunctionsByCatUrl.replace("{category}", category));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
function = JSONObject.parseObject(result, Function.class);
} else {
log.info("调用涂鸦获取用户设备接口失败");
return R.ok(result);
}
return function;
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
}
@Override
public String instructionIssue(String device_id, String insjson) {
String message = null;
public R instructionIssue(String device_id, String insjson) {
ResponseBody responseBody = sendRequestService.sendRequestPost(instructionIssue.replace("{device_id}", device_id), insjson);
if (responseBody != null && responseBody.isSuccess()) {
message = "下发成功";
} else {
message = "下发失败";
return R.ok();
}
return message;
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
}
}
......@@ -4,7 +4,9 @@ import cn.com.glsx.modules.model.param.ResponseBody;
import cn.com.glsx.modules.model.param.UserBo;
import cn.com.glsx.modules.model.param.UserInfo;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
......@@ -32,19 +34,15 @@ public class UserService {
*
* @param userBo 用户
*/
public String registerUser(UserBo userBo) {
public R registerUser(UserBo userBo) {
//获取令牌
String uid = null;
ResponseBody responseBody = sendRequestService.sendRequestPost(registerUserUrl, JSONObject.toJSONString(userBo));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
JSONObject jsonObject = JSONObject.parseObject(result);
uid = jsonObject.getString("uid");
} else {
log.info("调用涂鸦失败");
return R.ok(result);
}
return uid;
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
}
/**
......@@ -52,16 +50,14 @@ public class UserService {
*
* @param id 用户 ID
*/
public UserInfo getUserInfo(String id) {
UserInfo userInfo = null;
public R getUserInfo(String id) {
ResponseBody responseBody = sendRequestService.sendRequestGet(getUserInfoUrl.replace("{uid}", id));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult() + "";
userInfo = JSONObject.parseObject(result, UserInfo.class);
} else {
log.info("调用涂鸦用户信息接口失败");
return R.ok(result);
}
return userInfo;
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!