Commit c5ee3633 by wnb0128

车家智能数据服务开发 万能遥控器情况处理--think.wang

1 parent 7aa87f54
...@@ -11,4 +11,6 @@ public class Constants { ...@@ -11,4 +11,6 @@ public class Constants {
public final static String DEFAULT_PASSWORD = "123456"; public final static String DEFAULT_PASSWORD = "123456";
public final static String DEFAULT_DEVICE = "万能遥控器";
} }
...@@ -5,9 +5,12 @@ import com.alibaba.fastjson.JSONArray; ...@@ -5,9 +5,12 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; 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.constant.Constants;
import com.glsx.smart.dao.entity.SmartProduct; 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.dao.entity.SmartUserRelation;
import com.glsx.smart.service.SmartProductService; import com.glsx.smart.service.SmartProductService;
import com.glsx.smart.service.SmartProductTypeService;
import com.glsx.smart.service.SmartUserRelationService; import com.glsx.smart.service.SmartUserRelationService;
import com.glsx.smart.utils.HttpUtil; import com.glsx.smart.utils.HttpUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -18,6 +21,7 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -18,6 +21,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -41,6 +45,9 @@ public class RemoteProductController { ...@@ -41,6 +45,9 @@ public class RemoteProductController {
private SmartProductService productService; private SmartProductService productService;
@Autowired @Autowired
private SmartProductTypeService productTypeService;
@Autowired
private SmartUserRelationService userRelationService; private SmartUserRelationService userRelationService;
/** /**
...@@ -67,20 +74,8 @@ public class RemoteProductController { ...@@ -67,20 +74,8 @@ public class RemoteProductController {
if (StringUtils.isNotEmpty(result)) { if (StringUtils.isNotEmpty(result)) {
JSONObject json = JSON.parseObject(result); JSONObject json = JSON.parseObject(result);
if (json.getInteger("code").equals(200)) { if (json.getInteger("code").equals(200)) {
JSONArray list = new JSONArray();
JSONArray array = json.getJSONArray("message"); JSONArray array = json.getJSONArray("message");
int len = array.size(); return this.remoteDataHandle(array);
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("uuid"));
val.put("productName", object.getString("product_name"));
val.put("iconUrl", this.getProductIcon(productId));
list.add(val);
}
return list;
} }
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -89,22 +84,73 @@ public class RemoteProductController { ...@@ -89,22 +84,73 @@ public class RemoteProductController {
return null; 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("uuid"));
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;
}
/** /**
* 通过平台产品id获取产品图片 * 比较获取产品
* * @param list
* @param productId * @param productId
* @return * @return
*/ */
private String getProductIcon(String productId) { private SmartProduct compareProductId(List<SmartProduct> list, String productId){
SmartProduct req = new SmartProduct(); int len = list.size();
req.setPlatformProductId(productId); for (int i = 0; i < len; i++) {
List<SmartProduct> list = productService.getListByCondition(req); SmartProduct product = list.get(i);
if (!list.isEmpty()) { if(productId.equals(product.getPlatformProductId())){
return list.get(0).getIconUrl(); return product;
}
} }
return null; 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;
}
/** /**
* 查询红外设备下的遥控器 * 查询红外设备下的遥控器
......
package com.glsx.smart.dao.entity; package com.glsx.smart.dao.entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;
import java.util.List;
import com.glsx.smart.pojo.BaseDTO; import com.glsx.smart.pojo.BaseDTO;
import lombok.Data; import lombok.Data;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
/** /**
* <p>Description: * <p>Description:
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -66,6 +63,12 @@ public class SmartProductType extends BaseDTO { ...@@ -66,6 +63,12 @@ public class SmartProductType extends BaseDTO {
*/ */
private String shopTag; private String shopTag;
/**
* 关联涂鸦的产品类型
*/
private Integer tuyaCategoryId;
/** /**
* 备注 * 备注
*/ */
...@@ -90,4 +93,5 @@ public class SmartProductType extends BaseDTO { ...@@ -90,4 +93,5 @@ public class SmartProductType extends BaseDTO {
* 更新人 * 更新人
*/ */
private Long updateBy; private Long updateBy;
} }
...@@ -20,6 +20,8 @@ public interface SmartProductMapper extends tk.mybatis.mapper.common.Mapper<Smar ...@@ -20,6 +20,8 @@ public interface SmartProductMapper extends tk.mybatis.mapper.common.Mapper<Smar
List<SmartProduct> getByCondition(SmartProduct product); List<SmartProduct> getByCondition(SmartProduct product);
List<SmartProduct> getByPlatProductIdList(List<String> list);
SmartProduct getById(Long id); SmartProduct getById(Long id);
int countByProductName(String productName); int countByProductName(String productName);
......
package com.glsx.smart.dao.mapper; package com.glsx.smart.dao.mapper;
import java.util.List;
import com.glsx.smart.dao.entity.SmartProductType; import com.glsx.smart.dao.entity.SmartProductType;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* <p>Description: * <p>Description:
...@@ -22,6 +24,10 @@ public interface SmartProductTypeMapper extends tk.mybatis.mapper.common.Mapper< ...@@ -22,6 +24,10 @@ public interface SmartProductTypeMapper extends tk.mybatis.mapper.common.Mapper<
List<SmartProductType> getListAndContent(List<Long> list); List<SmartProductType> getListAndContent(List<Long> list);
List<SmartProductType> getByIdList(List<Long> list);
List<SmartProductType> getListAndCondition(List<Long> list); List<SmartProductType> getListAndCondition(List<Long> list);
SmartProductType getByCategoryId(@Param("categoryId") Integer categoryId);
} }
package com.glsx.smart.service; package com.glsx.smart.service;
import java.util.List;
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.SmartDeviceOrder; import com.glsx.smart.dao.entity.SmartDeviceOrder;
import com.glsx.smart.dao.entity.SmartProduct; import com.glsx.smart.dao.entity.SmartProduct;
import java.util.List;
/** /**
* <p>Description: * <p>Description:
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -19,6 +20,8 @@ public interface SmartProductService { ...@@ -19,6 +20,8 @@ public interface SmartProductService {
List<SmartProduct> getList(SmartProduct product); List<SmartProduct> getList(SmartProduct product);
List<SmartProduct> getByPlatProductIdList(List<String> list);
List<SmartProduct> getListByCondition(SmartProduct product); List<SmartProduct> getListByCondition(SmartProduct product);
SmartProduct getById(Long id); SmartProduct getById(Long id);
......
package com.glsx.smart.service; package com.glsx.smart.service;
import java.util.List;
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 java.util.List;
/** /**
* <p>Description: * <p>Description:
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -17,6 +18,8 @@ public interface SmartProductTypeService { ...@@ -17,6 +18,8 @@ public interface SmartProductTypeService {
List<SmartProductType> getList(SmartProductType productType); List<SmartProductType> getList(SmartProductType productType);
List<SmartProductType> getByIdList(List<Long> list);
SmartProductType getById(Long id); SmartProductType getById(Long id);
Boolean save(SmartProductType productType); Boolean save(SmartProductType productType);
......
package com.glsx.smart.service.impl; package com.glsx.smart.service.impl;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -24,6 +19,12 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -24,6 +19,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* <p>Description: 产品列表业务 * <p>Description: 产品列表业务
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -66,6 +67,11 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -66,6 +67,11 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
return productMapper.getByCondition(product); return productMapper.getByCondition(product);
} }
@Override
public List<SmartProduct> getByPlatProductIdList(List<String> list) {
return productMapper.getByPlatProductIdList(list);
}
/** /**
* 根据 id 查询产品详情。 * 根据 id 查询产品详情。
* *
......
package com.glsx.smart.service.impl; package com.glsx.smart.service.impl;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
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.dao.mapper.SmartProductTypeMapper; import com.glsx.smart.dao.mapper.SmartProductTypeMapper;
...@@ -14,6 +11,10 @@ import lombok.extern.slf4j.Slf4j; ...@@ -14,6 +11,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/** /**
* <p>Description: 产品类型业务 * <p>Description: 产品类型业务
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -47,8 +48,12 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -47,8 +48,12 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
*/ */
@Override @Override
public List<SmartProductType> getList(SmartProductType productType) { public List<SmartProductType> getList(SmartProductType productType) {
List<SmartProductType> productTypeList = productTypeMapper.getList(productType); return productTypeMapper.getList(productType);
return productTypeList; }
@Override
public List<SmartProductType> getByIdList(List<Long> list) {
return productTypeMapper.getByIdList(list);
} }
/** /**
......
...@@ -63,6 +63,14 @@ ...@@ -63,6 +63,14 @@
</where> </where>
</select> </select>
<select id="getByPlatProductIdList" parameterType="java.util.List" resultMap="DetailResultMap">
select <include refid="Base_Column_List" />
from smart_product where `status` = 1 and platform_product_id in
<foreach collection="list" open="(" close=")" separator="," index="index" item="item">
#{item,jdbcType=VARCHAR}
</foreach>
</select>
<select id="getById" resultMap="BaseResultMap"> <select id="getById" resultMap="BaseResultMap">
select sp.id, sp.product_name, sp.icon, sp.type_id, sp.shop_product_id, sp.platform_key, select sp.id, sp.product_name, sp.icon, sp.type_id, sp.shop_product_id, sp.platform_key,
sp.platform_product_id, sp.network_key, sp.status, sp.remark, sp.create_time, sp.platform_product_id, sp.network_key, sp.status, sp.remark, sp.create_time,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<result column="create_by" jdbcType="BIGINT" property="createBy"/> <result column="create_by" jdbcType="BIGINT" property="createBy"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
<result column="update_by" jdbcType="BIGINT" property="updateBy"/> <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
<result column="tuya_category_id" jdbcType="INTEGER" property="tuyaCategoryId"/>
</resultMap> </resultMap>
<resultMap id="BaseConditionMap" type="com.glsx.smart.dao.entity.SmartProductType" extends="BaseResultMap"> <resultMap id="BaseConditionMap" type="com.glsx.smart.dao.entity.SmartProductType" extends="BaseResultMap">
<collection property="conditionList" column="id" ofType="com.glsx.smart.dao.entity.SmartProductType" fetchType="eager" <collection property="conditionList" column="id" ofType="com.glsx.smart.dao.entity.SmartProductType" fetchType="eager"
...@@ -28,7 +29,7 @@ ...@@ -28,7 +29,7 @@
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!--@mbg.generated--> <!--@mbg.generated-->
id, type_name, category_key, shop_tag, remark, create_time, create_by, update_time, id, type_name, category_key, shop_tag, remark, create_time, create_by, update_time,
update_by update_by, tuya_category_id
</sql> </sql>
<select id="getList" resultMap="BaseResultMap"> <select id="getList" resultMap="BaseResultMap">
...@@ -54,6 +55,14 @@ ...@@ -54,6 +55,14 @@
order by create_time desc order by create_time desc
</select> </select>
<select id="getByIdList" parameterType="java.util.List" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from smart_product_type where id in
<foreach collection="list" open="(" close=")" separator="," index="index" item="item">
#{item,jdbcType=BIGINT}
</foreach>
</select>
<select id="getListAndCondition" parameterType="java.util.List" resultMap="BaseConditionMap"> <select id="getListAndCondition" parameterType="java.util.List" resultMap="BaseConditionMap">
select <include refid="Base_Column_List" /> select <include refid="Base_Column_List" />
from smart_product_type where id in from smart_product_type where id in
...@@ -63,6 +72,12 @@ ...@@ -63,6 +72,12 @@
order by create_time desc order by create_time desc
</select> </select>
<select id="getByCategoryId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from smart_product_type
where tuya_category_id = #{categoryId,jdbcType=INTEGER} limit 1
</select>
<select id="getById" resultMap="BaseResultMap"> <select id="getById" resultMap="BaseResultMap">
select spt.id, spt.type_name, spt.category_key, spt.shop_tag, spt.remark, spt.create_time, select spt.id, spt.type_name, spt.category_key, spt.shop_tag, spt.remark, spt.create_time,
spt.create_by, spt.update_time, spt.update_by spt.create_by, spt.update_time, spt.update_by
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!