Commit bc55c653 by wnb0128

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

1 parent 5ee56be2
......@@ -5,9 +5,6 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.HttpUtils;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.smart.constant.Constants;
import com.glsx.smart.dao.entity.SmartProduct;
import com.glsx.smart.dao.entity.SmartProductType;
import com.glsx.smart.dao.entity.SmartUserRelation;
import com.glsx.smart.service.SmartProductService;
import com.glsx.smart.service.SmartProductTypeService;
......@@ -19,9 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
* 远程产品服务controller
* 暂时只有涂鸦
......@@ -61,10 +55,11 @@ public class RemoteProductController {
if(user == null){
return null;
}
return this.getRemoteDevice(user.getThirdId());
Byte status = request.getStatus() != null ? request.getStatus() : -1;
return this.getRemoteDevice(user.getThirdId(), status);
}
private JSONArray getRemoteDevice(String thirdId) {
private JSONArray getRemoteDevice(String thirdId, Byte status) {
StringBuffer url = new StringBuffer(remoteUrl);
url.append("/device/").append(thirdId).append("/devices");
log.info("请求远程设备列表接口地址:{}", url.toString());
......@@ -78,81 +73,13 @@ public class RemoteProductController {
if(array == null || array.size() <= 0){
return array;
}
return this.remoteDataHandle(array);
return productTypeService.remoteDeviceHandler(array, status);
}
}
} catch (Exception e) {
log.error("获取用户设备列表数据失败:{}", e);
}
return null;
}
private JSONArray remoteDataHandle(JSONArray array){
int len = array.size();
List<String> prodIdList = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
prodIdList.add(array.getJSONObject(i).getString("product_id"));
}
List<SmartProduct> productList = productService.getByPlatProductIdList(prodIdList);
List<Long> typeIdList = new ArrayList<>(productList.size());
for (SmartProduct product : productList) {
typeIdList.add(product.getTypeId());
}
List<SmartProductType> productTypeList = new ArrayList<>();
if(!typeIdList.isEmpty()){
productTypeList = productTypeService.getByIdList(typeIdList);
}
JSONArray list = new JSONArray();
for (int i = 0; i < len; i++) {
JSONObject object = array.getJSONObject(i);
JSONObject val = new JSONObject();
String productId = object.getString("product_id");
val.put("productId", productId);
val.put("uuid", object.getString("id"));
val.put("productName", object.getString("product_name"));
SmartProduct product = this.compareProductId(productList, productId);
if(product != null){
val.put("iconUrl", product.getIconUrl());
val.put("flag", this.compareTypeId(productTypeList, product.getTypeId()));
}
list.add(val);
}
return list;
}
/**
* 比较获取产品
* @param list
* @param productId
* @return
*/
private SmartProduct compareProductId(List<SmartProduct> list, String productId){
int len = list.size();
for (int i = 0; i < len; i++) {
SmartProduct product = list.get(i);
if(productId.equals(product.getPlatformProductId())){
return product;
}
}
return null;
}
/**
* 比较是否产品类型为万能遥控器
* @param list
* @param id
* @return
*/
private boolean compareTypeId(List<SmartProductType> list, Long id){
int len = list.size();
for (int i = 0; i < len; i++) {
SmartProductType productType = list.get(i);
if(id == productType.getId()
&& productType.getTypeName().contains(Constants.DEFAULT_DEVICE)){
return true;
}
}
return false;
return new JSONArray();
}
/**
......
......@@ -26,6 +26,10 @@ public interface SmartProductTypeMapper extends tk.mybatis.mapper.common.Mapper<
List<SmartProductType> getByIdList(List<Long> list);
List<SmartProductType> getAllConditionList();
List<SmartProductType> getAllContentList();
List<SmartProductType> getListAndCondition(List<Long> list);
SmartProductType getByCategoryId(@Param("categoryId") Integer categoryId);
......
package com.glsx.smart.service;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo;
import com.glsx.smart.dao.entity.SmartProductType;
......@@ -29,4 +30,7 @@ public interface SmartProductTypeService {
List<SmartProductType> getListAndCondition(List<Long> list);
String findRemotesById(String infrared_id);
JSONArray remoteDeviceHandler(JSONArray array, Byte status);
}
......@@ -4,7 +4,10 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.glsx.smart.constant.Constants;
import com.glsx.smart.dao.entity.SmartProduct;
import com.glsx.smart.dao.entity.SmartProductType;
import com.glsx.smart.dao.mapper.SmartProductMapper;
import com.glsx.smart.dao.mapper.SmartProductTypeMapper;
import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum;
......@@ -12,15 +15,14 @@ import com.glsx.smart.service.BaseService;
import com.glsx.smart.service.SmartProductTypeService;
import com.glsx.smart.utils.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.*;
/**
* <p>Description: 产品类型业务
......@@ -36,6 +38,9 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
@Resource
private SmartProductTypeMapper productTypeMapper;
@Resource
private SmartProductMapper productMapper;
@Value("${findRemotesUrl}")
private String findRemotesUrl;
......@@ -151,4 +156,81 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
}
return JSONObject.toJSONString(json);
}
/**
* 过滤涂鸦远程设备
*
* @param array
* @param status 1触发条件 2执行内容 -1 全部
* @return
*/
@Override
public JSONArray remoteDeviceHandler(JSONArray array, Byte status) {
JSONArray arrayList = new JSONArray();
//获取平台产品id列表
int len = array.size();
List<String> prodIdList = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
prodIdList.add(array.getJSONObject(i).getString("product_id"));
}
List<SmartProduct> productList = productMapper.getByPlatProductIdList(prodIdList);
if(CollectionUtils.isEmpty(productList)){
return arrayList;
}
List<SmartProductType> list;
if(status == 1){
list = productTypeMapper.getAllConditionList();
} else if(status == 2){
list = productTypeMapper.getAllContentList();
} else {
//获取平台产品类型id列表
List<Long> typeIdList = new ArrayList<>(productList.size());
for (SmartProduct product : productList) {
typeIdList.add(product.getTypeId());
}
list = productTypeMapper.getByIdList(typeIdList);
}
Map<Long, SmartProductType> typeMap = new HashMap<>(list.size());
list.stream().forEach(index ->{
typeMap.put(index.getId(), index);
});
for (int i = 0; i < len; i++) {
JSONObject object = array.getJSONObject(i);
String productId = object.getString("product_id");
SmartProduct product = this.compareProductId(productList, productId);
if(product == null){
break;
}
SmartProductType productType = typeMap.get(product.getTypeId());
if(productType != null){
JSONObject val = new JSONObject();
val.put("productId", productId);
val.put("uuid", object.getString("id"));
val.put("productName", object.getString("product_name"));
val.put("iconUrl", product.getIconUrl());
boolean flag = productType.getTypeName().contains(Constants.DEFAULT_DEVICE) ? true : false;
val.put("flag", flag);
arrayList.add(val);
}
}
return arrayList;
}
/**
* 比较获取产品
* @param list
* @param productId
* @return
*/
private SmartProduct compareProductId(List<SmartProduct> list, String productId){
int len = list.size();
for (int i = 0; i < len; i++) {
SmartProduct product = list.get(i);
if(productId.equals(product.getPlatformProductId())){
return product;
}
}
return null;
}
}
......@@ -63,6 +63,16 @@
</foreach>
</select>
<select id="getAllConditionList" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from smart_product_type where id in (select distinct product_id from smart_scence_supstatus)
</select>
<select id="getAllContentList" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from smart_product_type where id in (select distinct product_id from smart_device_order)
</select>
<select id="getListAndCondition" parameterType="java.util.List" resultMap="BaseConditionMap">
select <include refid="Base_Column_List" />
from smart_product_type where id in
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!