Commit 559f325b by 111-PC\111

[+]列表展示

1 parent 1ddc864a
......@@ -84,7 +84,7 @@ public class ProductController {
*/
@RequestMapping(value = "/getProductAndCategory",
method = {RequestMethod.GET, RequestMethod.POST})
public JSONObject getProductAndCategory() {
public String getProductAndCategory() {
log.info("$$$$ /product/getProductAndCategory...");
return productService.getProductAndCategory();
}
......
......@@ -6,6 +6,7 @@ import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;
import com.glsx.smart.pojo.BaseDTO;
import lombok.Data;
......@@ -31,6 +32,12 @@ public class SmartProduct extends BaseDTO {
private String iconUrl;
/**
* 图标 url
*/
@Transient
private String categoryKey;
/**
* 产品类型名称
*/
@Transient
......
......@@ -7,6 +7,7 @@ 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;
......@@ -73,6 +74,12 @@ public class SmartProductType extends BaseDTO {
private Long updateBy;
/**
* 图标 url
*/
@Transient
private String iconUrl;
/**
* 内容列表
*/
private List<SmartDeviceOrder> contentList;
......
......@@ -23,7 +23,7 @@ public interface SmartProductService {
SmartProduct getById(Long id);
JSONObject getProductAndCategory();
String getProductAndCategory();
Boolean save(SmartProduct product);
......
package com.glsx.smart.service.impl;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.alibaba.fastjson.JSONArray;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.github.pagehelper.PageInfo;
import com.glsx.smart.dao.entity.SmartDeviceOrder;
import com.glsx.smart.dao.entity.SmartProduct;
import com.glsx.smart.dao.entity.SmartSysCode;
import com.glsx.smart.dao.mapper.SmartDeviceOrderMapper;
import com.glsx.smart.dao.mapper.SmartProductMapper;
import com.glsx.smart.dao.mapper.SmartProductTypeMapper;
import com.glsx.smart.dao.mapper.SmartSysCodeMapper;
import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.pojo.DjApiDTO;
......@@ -22,6 +24,7 @@ import com.glsx.smart.service.BaseService;
import com.glsx.smart.service.SmartProductService;
import com.glsx.smart.utils.DjApiInvoker;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -43,6 +46,9 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
private SmartDeviceOrderMapper deviceOrderMapper;
@Autowired
private SmartSysCodeMapper smartSysCodeMapper;
@Autowired
private DjApiInvoker djApiInvoker;
/**
......@@ -97,29 +103,39 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
* @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);
public String getProductAndCategory() {
SmartSysCode smartSysCode=new SmartSysCode();
smartSysCode.setDictType("smart_device");
List<SmartSysCode> list = smartSysCodeMapper.getList(smartSysCode);
List<SmartProduct> allProductList = productMapper.getAllProductList();
List<Map<String,Object>> objectMap=new ArrayList<>();
if(CollectionUtils.isNotEmpty(list)) {
List<SmartSysCode> firstlist = list.stream().filter(index -> index.getLevel() == 0).collect(Collectors.toList());
List<SmartSysCode> twolist = list.stream().filter(index -> index.getLevel() == 1).collect(Collectors.toList());
firstlist.forEach(index->{
Map<String,Object> map=new HashMap<>();
map.put("title",index.getDictValue());
List<Map<String,Object>> mapArrayList=new ArrayList<>();
List<SmartSysCode> collect = twolist.stream().filter(inx -> inx.getParentKey().equals(index.getDictKey())).collect(Collectors.toList());
collect.forEach(in->{
Map<String,Object> stringObjectMap=new HashMap<>();
stringObjectMap.put("title",in.getDictValue());
List<SmartProduct> smartProducts = allProductList.stream().filter(pro -> pro.getCategoryKey().equals(in.getDictKey())).collect(Collectors.toList());
List<Map<String, Object>> converlist = smartProducts.stream().map(sma -> {
Map<String, Object> converMap = new HashMap<>();
converMap.put("name", sma.getProductName());
converMap.put("icon", sma.getIconUrl());
converMap.put("typeId", sma.getTypeId());
return converMap;
}).collect(Collectors.toList());
stringObjectMap.put("list", converlist);
mapArrayList.add(stringObjectMap);
});
map.put("list",mapArrayList);
objectMap.add(map);
});
}
return result;
return JSONObject.toJSONString(objectMap);
}
/**
......
......@@ -84,6 +84,7 @@
sp.create_by, sp.update_time, sp.update_by,
concat(ssc.parent_key, ',', spt.category_key) remark,
ssf.url iconUrl,
spt.category_key as categoryKey,
spt.type_name typeName
from smart_product sp
left join smart_product_type spt on spt.id = sp.type_id
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!