Commit 00b222e9 by 111-PC\111

[+]代码整改

1 parent 2cc9d4c6
package cn.com.glsx.modules.controller; 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.DeviceInfo;
import cn.com.glsx.modules.model.param.Function; import cn.com.glsx.modules.model.param.Function;
import cn.com.glsx.modules.service.DeviceService; import cn.com.glsx.modules.service.DeviceService;
import cn.com.glsx.modules.service.abs.BaseDeviceService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -17,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -17,7 +15,6 @@ 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;
import java.util.List;
/** /**
* @author zhouhaibao * @author zhouhaibao
...@@ -40,8 +37,7 @@ public class DeviceController { ...@@ -40,8 +37,7 @@ public class DeviceController {
@ResponseBody @ResponseBody
@ApiOperation(value = "获取用户下的设备列表") @ApiOperation(value = "获取用户下的设备列表")
public R getAllDevicesByUser(@PathVariable String uid) { public R getAllDevicesByUser(@PathVariable String uid) {
List<DeviceInfo> list = deviceService.getAllDevicesByUser(uid); return deviceService.getAllDevicesByUser(uid);
return R.ok(JSONObject.toJSONString(list));
} }
/** /**
...@@ -53,8 +49,7 @@ public class DeviceController { ...@@ -53,8 +49,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) {
DeviceInfo deviceInfo = deviceService.getDevicesById(device_id); return deviceService.getDevicesById(device_id);
return R.ok(JSONObject.toJSONString(deviceInfo));
} }
...@@ -67,8 +62,7 @@ public class DeviceController { ...@@ -67,8 +62,7 @@ public class DeviceController {
@ResponseBody @ResponseBody
@ApiOperation(value = "根据id获取指令集") @ApiOperation(value = "根据id获取指令集")
public R getFunctionsById(@PathVariable String device_id) { public R getFunctionsById(@PathVariable String device_id) {
Function function = deviceService.getFunctionsById(device_id); return deviceService.getFunctionsById(device_id);
return R.ok(JSONObject.toJSONString(function));
} }
/** /**
...@@ -80,8 +74,7 @@ public class DeviceController { ...@@ -80,8 +74,7 @@ public class DeviceController {
@ResponseBody @ResponseBody
@ApiOperation(value = "根据品类获取指令集") @ApiOperation(value = "根据品类获取指令集")
public R getFunctionsByCat(@PathVariable String category) { public R getFunctionsByCat(@PathVariable String category) {
Function function = deviceService.getFunctionsByCat(category); return deviceService.getFunctionsByCat(category);
return R.ok(JSONObject.toJSONString(function));
} }
/** /**
...@@ -93,10 +86,6 @@ public class DeviceController { ...@@ -93,10 +86,6 @@ public class DeviceController {
@ResponseBody @ResponseBody
@ApiOperation(value = "根据设备下发指令") @ApiOperation(value = "根据设备下发指令")
public R instructionIssue(@PathVariable String device_id, @RequestBody String insjson) { public R instructionIssue(@PathVariable String device_id, @RequestBody String insjson) {
String message = deviceService.instructionIssue(device_id, insjson); return deviceService.instructionIssue(device_id, insjson);
if (("下发成功").equals(message)) {
return R.ok(message);
}
return R.error(message);
} }
} }
...@@ -36,11 +36,7 @@ public class UserController { ...@@ -36,11 +36,7 @@ public class UserController {
@ResponseBody @ResponseBody
@ApiOperation(value = "注册用户") @ApiOperation(value = "注册用户")
public R registerUser(@RequestBody UserBo userBo) { public R registerUser(@RequestBody UserBo userBo) {
String uid = userService.registerUser(userBo); return userService.registerUser(userBo);
if(StringUtils.isNotBlank(uid)){
return R.ok(uid);
}
return R.error();
} }
...@@ -54,7 +50,6 @@ public class UserController { ...@@ -54,7 +50,6 @@ public class UserController {
@ResponseBody @ResponseBody
@ApiOperation(value = "查询用户") @ApiOperation(value = "查询用户")
public R getUserInfo(@PathVariable String id) { public R getUserInfo(@PathVariable String id) {
UserInfo userInfo = userService.getUserInfo(id); return userService.getUserInfo(id);
return R.ok(JSONObject.toJSONString(userInfo));
} }
} }
...@@ -5,6 +5,7 @@ import cn.com.glsx.modules.model.param.Function; ...@@ -5,6 +5,7 @@ import cn.com.glsx.modules.model.param.Function;
import cn.com.glsx.modules.model.param.ResponseBody; import cn.com.glsx.modules.model.param.ResponseBody;
import cn.com.glsx.modules.service.abs.BaseDeviceService; import cn.com.glsx.modules.service.abs.BaseDeviceService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
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.beans.factory.annotation.Value;
...@@ -18,7 +19,7 @@ import java.util.List; ...@@ -18,7 +19,7 @@ import java.util.List;
*/ */
@Service @Service
@Slf4j @Slf4j
public class DeviceService extends BaseDeviceService { public class DeviceService {
@Value("${tuya.getAllDevicesByUserUrl}") @Value("${tuya.getAllDevicesByUserUrl}")
private String getAllDevicesByUserUrl; private String getAllDevicesByUserUrl;
...@@ -38,68 +39,54 @@ public class DeviceService extends BaseDeviceService { ...@@ -38,68 +39,54 @@ public class DeviceService extends BaseDeviceService {
@Autowired @Autowired
private SendRequestService sendRequestService; private SendRequestService sendRequestService;
@Override public R getAllDevicesByUser(String uid) {
public List<DeviceInfo> getAllDevicesByUser(String uid) {
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); return R.ok(result);
} else {
log.info("调用涂鸦获取用户设备接口失败");
} }
return userInfo; String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
} }
@Override public R getDevicesById(String device_id) {
public DeviceInfo getDevicesById(String device_id) {
DeviceInfo deviceInfo = null;
ResponseBody responseBody = sendRequestService.sendRequestGet(getDevicesByIdUrl.replace("{device_id}", device_id)); ResponseBody responseBody = sendRequestService.sendRequestGet(getDevicesByIdUrl.replace("{device_id}", device_id));
if (responseBody != null && responseBody.isSuccess()) { if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult(); String result = responseBody.getResult();
deviceInfo = JSONObject.parseObject(result, DeviceInfo.class); return R.ok(result);
} else {
log.info("调用涂鸦获取设备接口失败");
} }
return deviceInfo; String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
} }
@Override public R getFunctionsById(String device_id) {
public Function getFunctionsById(String device_id) {
Function function = null;
ResponseBody responseBody = sendRequestService.sendRequestGet(getFunctionsByIdUrl.replace("{device_id}", device_id)); ResponseBody responseBody = sendRequestService.sendRequestGet(getFunctionsByIdUrl.replace("{device_id}", device_id));
if (responseBody != null && responseBody.isSuccess()) { if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult(); String result = responseBody.getResult();
function = JSONObject.parseObject(result, Function.class); return R.ok(result);
} else {
log.info("调用涂鸦获取用户设备接口失败");
} }
return function; String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
} }
@Override public R getFunctionsByCat(String category) {
public Function getFunctionsByCat(String category) {
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); return R.ok(result);
} else {
log.info("调用涂鸦获取用户设备接口失败");
} }
return function; String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
} }
@Override public R instructionIssue(String device_id, String insjson) {
public String instructionIssue(String device_id, String insjson) {
String message = null;
ResponseBody responseBody = sendRequestService.sendRequestPost(instructionIssue.replace("{device_id}", device_id), insjson); ResponseBody responseBody = sendRequestService.sendRequestPost(instructionIssue.replace("{device_id}", device_id), insjson);
if (responseBody != null && responseBody.isSuccess()) { if (responseBody != null && responseBody.isSuccess()) {
message = "下发成功"; return R.ok();
} else {
message = responseBody.getMsg();
} }
return message; String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
} }
} }
...@@ -4,7 +4,9 @@ import cn.com.glsx.modules.model.param.ResponseBody; ...@@ -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.UserBo;
import cn.com.glsx.modules.model.param.UserInfo; import cn.com.glsx.modules.model.param.UserInfo;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -32,18 +34,15 @@ public class UserService { ...@@ -32,18 +34,15 @@ public class UserService {
* *
* @param userBo 用户 * @param userBo 用户
*/ */
public String registerUser(UserBo userBo) { public R registerUser(UserBo userBo) {
//获取令牌 //获取令牌
String uid = null;
ResponseBody responseBody = sendRequestService.sendRequestPost(registerUserUrl, JSONObject.toJSONString(userBo)); ResponseBody responseBody = sendRequestService.sendRequestPost(registerUserUrl, JSONObject.toJSONString(userBo));
if (responseBody != null && responseBody.isSuccess()) { if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult(); String result = responseBody.getResult();
JSONObject jsonObject = JSONObject.parseObject(result); return R.ok(result);
uid = jsonObject.getString("uid");
} else {
log.info("调用涂鸦失败");
} }
return uid; String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMessage();
return R.error(errorMessage);
} }
/** /**
...@@ -51,16 +50,14 @@ public class UserService { ...@@ -51,16 +50,14 @@ public class UserService {
* *
* @param id 用户 ID * @param id 用户 ID
*/ */
public UserInfo getUserInfo(String id) { public R getUserInfo(String id) {
UserInfo userInfo = null;
ResponseBody responseBody = sendRequestService.sendRequestGet(getUserInfoUrl.replace("{uid}", id)); ResponseBody responseBody = sendRequestService.sendRequestGet(getUserInfoUrl.replace("{uid}", id));
if (responseBody != null && responseBody.isSuccess()) { if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult() + ""; String result = responseBody.getResult() + "";
userInfo = JSONObject.parseObject(result, UserInfo.class); return R.ok(result);
} else {
log.info("调用涂鸦用户信息接口失败");
} }
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!