|
@@ -1,6 +1,5 @@
|
|
|
package com.qs.mp.web.controller.api.admin;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -19,16 +18,14 @@ import com.qs.mp.common.enums.GoodsStatusEnum;
|
|
|
import com.qs.mp.web.controller.common.BaseApiController;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import ma.glasnost.orika.MapperFacade;
|
|
|
-
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
-
|
|
|
+import ma.glasnost.orika.MapperFacade;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -230,53 +227,35 @@ public class GoodsMgrController extends BaseApiController {
|
|
|
|
|
|
// 获取商品的sku
|
|
|
public String getSkuProp(List<GoodsSku> skuList) {
|
|
|
- List<Map<String,Object>> skuMapList = new ArrayList<Map<String,Object>>();
|
|
|
- if(null != skuList && skuList.size() > 0) {
|
|
|
- for(GoodsSku sku : skuList) {
|
|
|
- if(null != sku && StringUtils.isNotBlank(sku.getProperties())) {
|
|
|
- String[] skuAry = sku.getProperties().split(";");
|
|
|
- if(null != skuAry && skuAry.length > 0) {
|
|
|
- for (int i = 0; i < skuAry.length; i++) {
|
|
|
- String item = skuAry[i];
|
|
|
- String[] itemAry = item.split(":");
|
|
|
- if(null != itemAry && itemAry.length > 1) {
|
|
|
- String key = itemAry[0];
|
|
|
- Object value = itemAry[1];
|
|
|
- Map<String,Object> map = new HashMap<String,Object>();
|
|
|
- map.put(key,value);
|
|
|
- skuMapList.add(map);
|
|
|
- }
|
|
|
- }
|
|
|
+ LinkedHashMap<String, HashSet<String>> skuProp = new LinkedHashMap<>();
|
|
|
+ for (GoodsSku sku : skuList) {
|
|
|
+ if (StringUtils.isNotBlank(sku.getProperties())) {
|
|
|
+ String[] skuAry = sku.getProperties().split(";");
|
|
|
+ for (int i = 0; i < skuAry.length; i++) {
|
|
|
+ String item = skuAry[i];
|
|
|
+ String[] itemAry = item.split(":");
|
|
|
+ String key = itemAry[0];
|
|
|
+ String value = itemAry[1];
|
|
|
+ HashSet<String> valueSet = skuProp.get(key);
|
|
|
+ if (null == valueSet) {
|
|
|
+ valueSet = new HashSet<>();
|
|
|
+ skuProp.put(key, valueSet);
|
|
|
}
|
|
|
+ valueSet.add(value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(null != skuMapList && skuMapList.size() > 0) {
|
|
|
- // 合并key相同的Map
|
|
|
- Map<String,Object> map = skuMapList.stream().flatMap(m -> m.entrySet().stream())
|
|
|
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> getObjValue(a,b)));
|
|
|
-
|
|
|
- List<Map<String,Object>> mapList=new ArrayList<>();
|
|
|
- for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
- String key = entry.getKey();
|
|
|
- Object value = entry.getValue();
|
|
|
- Map<String, Object> mapObj = new HashMap<String, Object>();
|
|
|
- mapObj.put("name", key);
|
|
|
- if (value instanceof List<?>) {
|
|
|
- mapObj.put("value", value);
|
|
|
- } else {
|
|
|
- List<Object> list = new ArrayList<>();
|
|
|
- list.add(value + "");
|
|
|
- mapObj.put("value", list);
|
|
|
- }
|
|
|
- mapList.add(mapObj);
|
|
|
- }
|
|
|
- return JSONArray.toJSONString(mapList);
|
|
|
+ List<JSONObject> skuPropList = new ArrayList<>();
|
|
|
+ for (String key : skuProp.keySet()) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("name", key);
|
|
|
+ jsonObject.put("value", JSONObject.toJSONString(skuProp.get(key)));
|
|
|
+ skuPropList.add(jsonObject);
|
|
|
}
|
|
|
- return null;
|
|
|
+ return JSONObject.toJSONString(skuPropList);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
private Object getObjValue(Object a, Object b){
|
|
|
boolean isa = (a instanceof List<?>);
|
|
|
boolean isb = (b instanceof List<?>);
|