Commit c33297e4 by 111-PC\111

[+]下发指令代码修改

1 parent 484d1786
......@@ -9,27 +9,34 @@ import com.glsx.smart.dao.entity.SmartProduct;
import com.glsx.smart.dao.entity.SmartUserRelation;
import com.glsx.smart.service.SmartProductService;
import com.glsx.smart.service.SmartUserRelationService;
import com.glsx.smart.utils.HttpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
/**
*
* 远程产品服务controller
* 暂时只有涂鸦
*
*/
@Slf4j
@RestController
@RequestMapping("/remoteProduct")
@Api(value = "设备管理", tags = {"设备管理"})
public class RemoteProductController {
@Value("${device_remote_url}")
private String remoteUrl;
@Value("${findRemotesUrl}")
private String findRemotesUrl;
@Autowired
private SmartProductService productService;
......@@ -44,17 +51,17 @@ public class RemoteProductController {
@ResponseBody
@RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST})
public JSONArray getList(@RequestBody SmartUserRelation request) {
log.info("用户参数:{}",request);
log.info("用户参数:{}", request);
request.setUserId(91712228L);
SmartUserRelation user = userRelationService.getSingle(request);
return this.getRemoteDevice(user.getThirdId());
}
private JSONArray getRemoteDevice(String thirdId){
private JSONArray getRemoteDevice(String thirdId) {
StringBuffer url = new StringBuffer(remoteUrl);
url.append("/device/").append(thirdId).append("/devices");
log.info("请求远程设备列表接口地址:{}", url.toString());
try{
try {
String result = HttpUtils.get(url.toString());
log.info("获取用户设备列表数据返回结果:{}", result);
if (StringUtils.isNotEmpty(result)) {
......@@ -76,7 +83,7 @@ public class RemoteProductController {
return list;
}
}
}catch (Exception e){
} catch (Exception e) {
log.error("获取用户设备列表数据失败:{}", e);
}
return null;
......@@ -84,17 +91,40 @@ public class RemoteProductController {
/**
* 通过平台产品id获取产品图片
*
* @param productId
* @return
*/
private String getProductIcon(String productId){
private String getProductIcon(String productId) {
SmartProduct req = new SmartProduct();
req.setPlatformProductId(productId);
List<SmartProduct> list = productService.getListByCondition(req);
if(!list.isEmpty()){
return list.get(0).getIconUrl();
if (!list.isEmpty()) {
return list.get(0).getIconUrl();
}
return null;
}
/**
* 查询红外设备下的遥控器
*
* @return 结果
*/
@ResponseBody
@RequestMapping(value = "/findRemotes", method = {RequestMethod.GET, RequestMethod.POST})
@ApiOperation(value = "查询红外设备下的遥控器")
public String findRemotes(@RequestParam String infrared_id) {
return findRemotesById(infrared_id);
}
private String findRemotesById(String infrared_id) {
String responseResult=null;
try {
responseResult = HttpUtil.sendGet(findRemotesUrl.replace("{infrared_id}", infrared_id), null, new HashMap<>());
} catch (IOException e) {
e.printStackTrace();
}
return responseResult;
}
}
......@@ -77,4 +77,5 @@ public class SceneController {
public List<OrderResponse> issueOrder(@RequestBody SmartScene scene) {
return sceneService.issueOrder(scene);
}
}
......@@ -394,12 +394,9 @@ public class HttpUtil {
* @return
* @throws IOException
*/
public static JSONObject sendGet(String url, Map<String, String> params, Map<String, String> headerParams) throws IOException {
public static String sendGet(String url, Map<String, String> params, Map<String, String> headerParams) throws IOException {
String retData = getData(url, params, Consts.UTF_8, headerParams);
if (StringUtils.isNotBlank(retData)) {
return JSONObject.parseObject(retData);
}
return new JSONObject();
return retData;
}
/**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!