Commit d00568a3 by tyfanchz

修改产品及类型获取逻辑

1 parent 3b6c073b
package com.glsx.smart.controller; package com.glsx.smart.controller;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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;
...@@ -77,6 +78,18 @@ public class ProductController { ...@@ -77,6 +78,18 @@ public class ProductController {
} }
/** /**
* 获取结构化的产品数据。
*
* @return 结果
*/
@RequestMapping(value = "/getProductAndCategory",
method = {RequestMethod.GET, RequestMethod.POST})
public JSONObject getProductAndCategory() {
log.info("$$$$ /product/getProductAndCategory...");
return productService.getProductAndCategory();
}
/**
* 保存产品。无则插入,有则更新。 * 保存产品。无则插入,有则更新。
* *
* @param product 产品 * @param product 产品
......
package com.glsx.smart.controller; package com.glsx.smart.controller;
import java.util.List;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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.service.SmartProductTypeService; import com.glsx.smart.service.SmartProductTypeService;
...@@ -12,8 +12,6 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -12,8 +12,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.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/** /**
* <p>Description: 产品类型业务 * <p>Description: 产品类型业务
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -64,17 +62,6 @@ public class ProductTypeController { ...@@ -64,17 +62,6 @@ public class ProductTypeController {
} }
/** /**
* 获取结构化的产品类型。
*
* @return 结果
*/
@RequestMapping(value = "/getTypeAndCategory", method = {RequestMethod.GET, RequestMethod.POST})
public JSONObject getProductTypeTree() {
log.info("$$$$ /productType/getTypeAndCategory...");
return productTypeService.getTypeAndCategory();
}
/**
* 保存产品类型。 * 保存产品类型。
* *
* @param productType 产品类型 * @param productType 产品类型
......
...@@ -23,4 +23,6 @@ public interface SmartProductMapper extends tk.mybatis.mapper.common.Mapper<Smar ...@@ -23,4 +23,6 @@ public interface SmartProductMapper extends tk.mybatis.mapper.common.Mapper<Smar
SmartProduct getById(Long id); SmartProduct getById(Long id);
int countByProductName(String productName); int countByProductName(String productName);
List<SmartProduct> getAllProductList();
} }
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 java.util.List;
/** /**
* <p>Description: * <p>Description:
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -21,8 +20,6 @@ public interface SmartProductTypeMapper extends tk.mybatis.mapper.common.Mapper< ...@@ -21,8 +20,6 @@ public interface SmartProductTypeMapper extends tk.mybatis.mapper.common.Mapper<
int countByProductTypeName(String typeName); int countByProductTypeName(String typeName);
List<SmartProductType> getAllList();
List<SmartProductType> getListAndContent(List<Long> list); List<SmartProductType> getListAndContent(List<Long> list);
List<SmartProductType> getListAndCondition(List<Long> list); List<SmartProductType> getListAndCondition(List<Long> list);
......
package com.glsx.smart.service; package com.glsx.smart.service;
import java.util.List; import java.util.List;
import com.alibaba.fastjson.JSONObject;
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;
...@@ -22,6 +23,8 @@ public interface SmartProductService { ...@@ -22,6 +23,8 @@ public interface SmartProductService {
SmartProduct getById(Long id); SmartProduct getById(Long id);
JSONObject getProductAndCategory();
Boolean save(SmartProduct product); Boolean save(SmartProduct product);
List<SmartDeviceOrder> getCommandSetById(Long id); List<SmartDeviceOrder> getCommandSetById(Long id);
......
package com.glsx.smart.service; package com.glsx.smart.service;
import com.alibaba.fastjson.JSONObject; 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
...@@ -21,8 +19,6 @@ public interface SmartProductTypeService { ...@@ -21,8 +19,6 @@ public interface SmartProductTypeService {
SmartProductType getById(Long id); SmartProductType getById(Long id);
JSONObject getTypeAndCategory();
Boolean save(SmartProductType productType); Boolean save(SmartProductType productType);
List<String> getShopTagList(); List<String> getShopTagList();
......
package com.glsx.smart.service.impl; package com.glsx.smart.service.impl;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
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;
...@@ -15,10 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -15,10 +23,6 @@ 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.Date;
import java.util.List;
/** /**
* <p>Description: 产品列表业务 * <p>Description: 产品列表业务
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -74,6 +78,45 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -74,6 +78,45 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
} }
/** /**
* 获取结构化的产品数据。
* 数据格式为:
* {
* "车智能": ["产品类型1-1", "产品类型1-2"],
* "产品类型1-1": ["产品名称1", "产品名称2"],
*
* "家智能": ["产品类型2-1"],
* "产品类型2-1": ["产品名称3", "产品名称4", "产品名称5"]
* }
*
* @return 结果
*/
@Override
public JSONObject getProductAndCategory() {
JSONObject result = new JSONObject();
List<SmartProduct> productList = productMapper.getAllProductList();
for (SmartProduct product : productList) {
// 产品的一二级分类放在 remark 中
String[] categories = product.getRemark().split(",");
String category1 = categories[0];
String category2 = categories[1];
// 按照一级分类给二级分类分组
if (!result.containsKey(category1)) {
result.put(category1, new HashSet<>());
}
Set<Object> set = result.getObject(category1, new TypeReference<Set<Object>>() {});
set.add(category2);
result.put(category1, set);
// 按照二级分类给产品分组
if (!result.containsKey(category2)) {
result.put(category2, new JSONArray());
}
result.getJSONArray(category2).add(product);
}
return result;
}
/**
* 保存产品。无则插入,有则更新。 * 保存产品。无则插入,有则更新。
* *
* @param product 产品 * @param product 产品
......
package com.glsx.smart.service.impl; package com.glsx.smart.service.impl;
import com.alibaba.fastjson.JSONArray; import javax.annotation.Resource;
import com.alibaba.fastjson.JSONObject; import java.util.Arrays;
import com.alibaba.fastjson.TypeReference; 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,9 +15,6 @@ import lombok.extern.slf4j.Slf4j; ...@@ -14,9 +15,6 @@ 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.*;
/** /**
* <p>Description: 产品类型业务 * <p>Description: 产品类型业务
* <p>Project: chejia-smart * <p>Project: chejia-smart
...@@ -70,47 +68,6 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -70,47 +68,6 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
} }
/** /**
* 获取结构化的产品类型。
* 数据格式为:
* {
* "车智能": ["产品类型1-1", "产品类型1-2"],
* "产品类型1-1": ["产品名称1", "产品名称2"],
*
* "家智能": ["产品类型2-1"],
* "产品类型2-1": ["产品名称3", "产品名称4", "产品名称5"]
* }
*
* @return 结果
*/
@Override
public JSONObject getTypeAndCategory() {
JSONObject result = new JSONObject();
List<SmartProductType> productTypeList = productTypeMapper.getAllList();
for (SmartProductType productType : productTypeList) {
// 一级分类放在备注字段中
String parentCategoryKey = productType.getRemark();
// 二级分类
String categoryKey = productType.getCategoryKey();
// 根据一级分类将二级分类分组
if (!result.containsKey(parentCategoryKey)) {
result.put(parentCategoryKey, new HashSet<>());
}
Set<Object> set = result.getObject(parentCategoryKey,
new TypeReference<Set<Object>>() {});
set.add(categoryKey);
result.put(parentCategoryKey, set);
// 根据二级分类将产品类型分组
if (!result.containsKey(categoryKey)) {
result.put(categoryKey, new JSONArray());
}
result.getJSONArray(categoryKey).add(productType);
}
return result;
}
/**
* 保存产品类型。 * 保存产品类型。
* *
* @param productType 产品类型 * @param productType 产品类型
......
...@@ -72,4 +72,18 @@ ...@@ -72,4 +72,18 @@
from smart_product from smart_product
where product_name = #{productName,jdbcType=VARCHAR} where product_name = #{productName,jdbcType=VARCHAR}
</select> </select>
<select id="getAllProductList" resultMap="BaseResultMap">
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.create_time,
sp.create_by, sp.update_time, sp.update_by,
concat(ssc.parent_key, ',', spt.category_key) remark,
ssf.url iconUrl,
spt.type_name typeName
from smart_product sp
left join smart_product_type spt on spt.id = sp.type_id
left join smart_sys_file ssf on ssf.id = sp.icon
left join smart_sys_code ssc on ssc.dict_key = spt.category_key
where sp.status = 1
</select>
</mapper> </mapper>
...@@ -73,12 +73,4 @@ ...@@ -73,12 +73,4 @@
from smart_product_type from smart_product_type
where type_name = #{typeName,jdbcType=VARCHAR} where type_name = #{typeName,jdbcType=VARCHAR}
</select> </select>
<select id="getAllList" resultMap="BaseResultMap">
select spt.id, spt.type_name, spt.category_key, spt.shop_tag,
ssc.parent_key remark
from smart_product_type spt
left join smart_sys_code ssc on ssc.dict_key = spt.category_key
order by ssc.sort
</select>
</mapper> </mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!