Commit 559f325b by 111-PC\111

[+]列表展示

1 parent 1ddc864a
...@@ -84,7 +84,7 @@ public class ProductController { ...@@ -84,7 +84,7 @@ public class ProductController {
*/ */
@RequestMapping(value = "/getProductAndCategory", @RequestMapping(value = "/getProductAndCategory",
method = {RequestMethod.GET, RequestMethod.POST}) method = {RequestMethod.GET, RequestMethod.POST})
public JSONObject getProductAndCategory() { public String getProductAndCategory() {
log.info("$$$$ /product/getProductAndCategory..."); log.info("$$$$ /product/getProductAndCategory...");
return productService.getProductAndCategory(); return productService.getProductAndCategory();
} }
......
...@@ -6,6 +6,7 @@ import javax.persistence.Id; ...@@ -6,6 +6,7 @@ import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import java.util.Date; import java.util.Date;
import com.glsx.smart.pojo.BaseDTO; import com.glsx.smart.pojo.BaseDTO;
import lombok.Data; import lombok.Data;
...@@ -31,6 +32,12 @@ public class SmartProduct extends BaseDTO { ...@@ -31,6 +32,12 @@ public class SmartProduct extends BaseDTO {
private String iconUrl; private String iconUrl;
/** /**
* 图标 url
*/
@Transient
private String categoryKey;
/**
* 产品类型名称 * 产品类型名称
*/ */
@Transient @Transient
......
...@@ -7,6 +7,7 @@ import javax.persistence.GeneratedValue; ...@@ -7,6 +7,7 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -73,6 +74,12 @@ public class SmartProductType extends BaseDTO { ...@@ -73,6 +74,12 @@ public class SmartProductType extends BaseDTO {
private Long updateBy; private Long updateBy;
/** /**
* 图标 url
*/
@Transient
private String iconUrl;
/**
* 内容列表 * 内容列表
*/ */
private List<SmartDeviceOrder> contentList; private List<SmartDeviceOrder> contentList;
......
...@@ -23,7 +23,7 @@ public interface SmartProductService { ...@@ -23,7 +23,7 @@ public interface SmartProductService {
SmartProduct getById(Long id); SmartProduct getById(Long id);
JSONObject getProductAndCategory(); String getProductAndCategory();
Boolean save(SmartProduct product); Boolean save(SmartProduct product);
......
package com.glsx.smart.service.impl; package com.glsx.smart.service.impl;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; 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;
import com.glsx.smart.dao.entity.SmartSysCode;
import com.glsx.smart.dao.mapper.SmartDeviceOrderMapper; import com.glsx.smart.dao.mapper.SmartDeviceOrderMapper;
import com.glsx.smart.dao.mapper.SmartProductMapper; 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.BusinessException;
import com.glsx.smart.exception.ResultEnum; import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.pojo.DjApiDTO; import com.glsx.smart.pojo.DjApiDTO;
...@@ -22,6 +24,7 @@ import com.glsx.smart.service.BaseService; ...@@ -22,6 +24,7 @@ import com.glsx.smart.service.BaseService;
import com.glsx.smart.service.SmartProductService; import com.glsx.smart.service.SmartProductService;
import com.glsx.smart.utils.DjApiInvoker; import com.glsx.smart.utils.DjApiInvoker;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; 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;
...@@ -43,6 +46,9 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -43,6 +46,9 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
private SmartDeviceOrderMapper deviceOrderMapper; private SmartDeviceOrderMapper deviceOrderMapper;
@Autowired @Autowired
private SmartSysCodeMapper smartSysCodeMapper;
@Autowired
private DjApiInvoker djApiInvoker; private DjApiInvoker djApiInvoker;
/** /**
...@@ -97,29 +103,39 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -97,29 +103,39 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
* @return 结果 * @return 结果
*/ */
@Override @Override
public JSONObject getProductAndCategory() { public String getProductAndCategory() {
JSONObject result = new JSONObject(); SmartSysCode smartSysCode=new SmartSysCode();
List<SmartProduct> productList = productMapper.getAllProductList(); smartSysCode.setDictType("smart_device");
for (SmartProduct product : productList) { List<SmartSysCode> list = smartSysCodeMapper.getList(smartSysCode);
// 产品的一二级分类放在 remark 中 List<SmartProduct> allProductList = productMapper.getAllProductList();
String[] categories = product.getRemark().split(","); List<Map<String,Object>> objectMap=new ArrayList<>();
String category1 = categories[0]; if(CollectionUtils.isNotEmpty(list)) {
String category2 = categories[1]; 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());
if (!result.containsKey(category1)) { firstlist.forEach(index->{
result.put(category1, new HashSet<>()); Map<String,Object> map=new HashMap<>();
} map.put("title",index.getDictValue());
Set<Object> set = result.getObject(category1, new TypeReference<Set<Object>>() {}); List<Map<String,Object>> mapArrayList=new ArrayList<>();
set.add(category2); List<SmartSysCode> collect = twolist.stream().filter(inx -> inx.getParentKey().equals(index.getDictKey())).collect(Collectors.toList());
result.put(category1, set); collect.forEach(in->{
Map<String,Object> stringObjectMap=new HashMap<>();
// 按照二级分类给产品分组 stringObjectMap.put("title",in.getDictValue());
if (!result.containsKey(category2)) { List<SmartProduct> smartProducts = allProductList.stream().filter(pro -> pro.getCategoryKey().equals(in.getDictKey())).collect(Collectors.toList());
result.put(category2, new JSONArray()); List<Map<String, Object>> converlist = smartProducts.stream().map(sma -> {
} Map<String, Object> converMap = new HashMap<>();
result.getJSONArray(category2).add(product); converMap.put("name", sma.getProductName());
} converMap.put("icon", sma.getIconUrl());
return result; 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 JSONObject.toJSONString(objectMap);
} }
/** /**
......
...@@ -84,6 +84,7 @@ ...@@ -84,6 +84,7 @@
sp.create_by, sp.update_time, sp.update_by, sp.create_by, sp.update_time, sp.update_by,
concat(ssc.parent_key, ',', spt.category_key) remark, concat(ssc.parent_key, ',', spt.category_key) remark,
ssf.url iconUrl, ssf.url iconUrl,
spt.category_key as categoryKey,
spt.type_name typeName spt.type_name typeName
from smart_product sp from smart_product sp
left join smart_product_type spt on spt.id = sp.type_id 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!