Commit a6a686c9 by wnb0128

车家智能数据服务 远程设备条件处理优化--think.wang

1 parent ac15dc6d
...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.HttpUtils; import com.glsx.plat.common.utils.HttpUtils;
import com.glsx.plat.common.utils.StringUtils; import com.glsx.plat.common.utils.StringUtils;
import com.glsx.smart.dao.entity.SmartUserRelation; import com.glsx.smart.dao.entity.SmartUserRelation;
import com.glsx.smart.pojo.response.RemoteDeviceResp;
import com.glsx.smart.service.SmartProductService; import com.glsx.smart.service.SmartProductService;
import com.glsx.smart.service.SmartProductTypeService; import com.glsx.smart.service.SmartProductTypeService;
import com.glsx.smart.service.SmartUserRelationService; import com.glsx.smart.service.SmartUserRelationService;
...@@ -16,6 +17,9 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,6 +17,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/** /**
* 远程产品服务controller * 远程产品服务controller
* 暂时只有涂鸦 * 暂时只有涂鸦
...@@ -48,7 +52,7 @@ public class RemoteProductController { ...@@ -48,7 +52,7 @@ public class RemoteProductController {
*/ */
@ResponseBody @ResponseBody
@RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST})
public JSONArray getList(@RequestBody SmartUserRelation request) { public List<RemoteDeviceResp> getList(@RequestBody SmartUserRelation request) {
log.info("用户参数:{}", request); log.info("用户参数:{}", request);
// request.setUserId(91712228L); // request.setUserId(91712228L);
SmartUserRelation user = userRelationService.getSingle(request); SmartUserRelation user = userRelationService.getSingle(request);
...@@ -59,7 +63,8 @@ public class RemoteProductController { ...@@ -59,7 +63,8 @@ public class RemoteProductController {
return this.getRemoteDevice(user.getThirdId(), status); return this.getRemoteDevice(user.getThirdId(), status);
} }
private JSONArray getRemoteDevice(String thirdId, Byte status) { private List<RemoteDeviceResp> getRemoteDevice(String thirdId, Byte status) {
List<RemoteDeviceResp> deviceRespList = new ArrayList<>();
StringBuffer url = new StringBuffer(remoteUrl); StringBuffer url = new StringBuffer(remoteUrl);
url.append("/device/").append(thirdId).append("/devices"); url.append("/device/").append(thirdId).append("/devices");
log.info("请求远程设备列表接口地址:{}", url.toString()); log.info("请求远程设备列表接口地址:{}", url.toString());
...@@ -71,7 +76,7 @@ public class RemoteProductController { ...@@ -71,7 +76,7 @@ public class RemoteProductController {
if (json.getInteger("code").equals(200)) { if (json.getInteger("code").equals(200)) {
JSONArray array = json.getJSONArray("message"); JSONArray array = json.getJSONArray("message");
if(array == null || array.size() <= 0){ if(array == null || array.size() <= 0){
return array; return deviceRespList;
} }
return productTypeService.remoteDeviceHandler(array, status); return productTypeService.remoteDeviceHandler(array, status);
} }
...@@ -79,7 +84,7 @@ public class RemoteProductController { ...@@ -79,7 +84,7 @@ public class RemoteProductController {
} catch (Exception e) { } catch (Exception e) {
log.error("获取用户设备列表数据失败:{}", e); log.error("获取用户设备列表数据失败:{}", e);
} }
return new JSONArray(); return deviceRespList;
} }
/** /**
......
package com.glsx.smart.pojo.response;
import lombok.Data;
/**
* @author think.wang
* @version 1.0.0
* @Title RemoteDeviceResp
* @Package com.glsx.smart.pojo.response
* @Description 远程设备返回数据
* @date 2021/4/12
*/
@Data
public class RemoteDeviceResp {
private String productId; //产品id
private String uuid; //设备id
private String productName; //产品名称
private String iconUrl; //产品图片url
private boolean flag; //是否万能遥控器 true是 false否
}
...@@ -3,6 +3,7 @@ package com.glsx.smart.service; ...@@ -3,6 +3,7 @@ package com.glsx.smart.service;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.glsx.smart.dao.entity.SmartProductType; import com.glsx.smart.dao.entity.SmartProductType;
import com.glsx.smart.pojo.response.RemoteDeviceResp;
import java.util.List; import java.util.List;
...@@ -31,6 +32,6 @@ public interface SmartProductTypeService { ...@@ -31,6 +32,6 @@ public interface SmartProductTypeService {
String findRemotesById(String infrared_id); String findRemotesById(String infrared_id);
JSONArray remoteDeviceHandler(JSONArray array, Byte status); List<RemoteDeviceResp> remoteDeviceHandler(JSONArray array, Byte status);
} }
...@@ -11,6 +11,7 @@ import com.glsx.smart.dao.mapper.SmartProductMapper; ...@@ -11,6 +11,7 @@ import com.glsx.smart.dao.mapper.SmartProductMapper;
import com.glsx.smart.dao.mapper.SmartProductTypeMapper; import com.glsx.smart.dao.mapper.SmartProductTypeMapper;
import com.glsx.smart.exception.BusinessException; import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum; import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.pojo.response.RemoteDeviceResp;
import com.glsx.smart.service.BaseService; import com.glsx.smart.service.BaseService;
import com.glsx.smart.service.SmartProductTypeService; import com.glsx.smart.service.SmartProductTypeService;
import com.glsx.smart.utils.HttpUtil; import com.glsx.smart.utils.HttpUtil;
...@@ -165,8 +166,8 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -165,8 +166,8 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
* @return * @return
*/ */
@Override @Override
public JSONArray remoteDeviceHandler(JSONArray array, Byte status) { public List<RemoteDeviceResp> remoteDeviceHandler(JSONArray array, Byte status) {
JSONArray arrayList = new JSONArray(); List<RemoteDeviceResp> deviceRespList = new ArrayList<>();
//获取平台产品id列表 //获取平台产品id列表
int len = array.size(); int len = array.size();
List<String> prodIdList = new ArrayList<>(len); List<String> prodIdList = new ArrayList<>(len);
...@@ -175,7 +176,7 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -175,7 +176,7 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
} }
List<SmartProduct> productList = productMapper.getByPlatProductIdList(prodIdList); List<SmartProduct> productList = productMapper.getByPlatProductIdList(prodIdList);
if(CollectionUtils.isEmpty(productList)){ if(CollectionUtils.isEmpty(productList)){
return arrayList; return deviceRespList;
} }
//获取设备类型列表 //获取设备类型列表
List<SmartProductType> list; List<SmartProductType> list;
...@@ -205,17 +206,17 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -205,17 +206,17 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
} }
SmartProductType productType = typeMap.get(product.getTypeId()); SmartProductType productType = typeMap.get(product.getTypeId());
if(productType != null){ if(productType != null){
JSONObject val = new JSONObject(); RemoteDeviceResp resp = new RemoteDeviceResp();
val.put("productId", productId); resp.setProductId(productId);
val.put("uuid", object.getString("id")); resp.setUuid(object.getString("id"));
val.put("productName", object.getString("product_name")); resp.setProductName(object.getString("product_name"));
val.put("iconUrl", product.getIconUrl()); resp.setIconUrl(product.getIconUrl());
boolean flag = productType.getTypeName().contains(Constants.DEFAULT_DEVICE) ? true : false; boolean flag = productType.getTypeName().contains(Constants.DEFAULT_DEVICE) ? true : false;
val.put("flag", flag); resp.setFlag(flag);
arrayList.add(val); deviceRespList.add(resp);
} }
} }
return arrayList; return deviceRespList;
} }
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!