|
@@ -1,5 +1,6 @@
|
|
package com.qs.mp.web.controller.api.admin;
|
|
package com.qs.mp.web.controller.api.admin;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -26,6 +27,7 @@ import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -160,6 +162,7 @@ public class GoodsMgrController extends BaseApiController {
|
|
}
|
|
}
|
|
// 3.插入数据
|
|
// 3.插入数据
|
|
try {
|
|
try {
|
|
|
|
+ goods.setSkuProp(getSkuProp(skuList));
|
|
goodsService.saveGoods(goods, skuList);
|
|
goodsService.saveGoods(goods, skuList);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
return AjaxResult.error("商品'" + goods.getTitle() + "'新增失败" + e.getMessage());
|
|
return AjaxResult.error("商品'" + goods.getTitle() + "'新增失败" + e.getMessage());
|
|
@@ -251,10 +254,42 @@ public class GoodsMgrController extends BaseApiController {
|
|
}
|
|
}
|
|
if(null != skuMapList && skuMapList.size() > 0) {
|
|
if(null != skuMapList && skuMapList.size() > 0) {
|
|
// 合并key相同的Map
|
|
// 合并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);
|
|
|
|
+ mapObj.put("value", value);
|
|
|
|
+ mapList.add(mapObj);
|
|
|
|
+ }
|
|
|
|
+ return JSONArray.toJSONString(mapList);
|
|
}
|
|
}
|
|
return goosSku;
|
|
return goosSku;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private Object getObjValue(Object a, Object b){
|
|
|
|
+ boolean isa = (a instanceof List<?>);
|
|
|
|
+ boolean isb = (b instanceof List<?>);
|
|
|
|
+ System.out.println("isa == " + isa);
|
|
|
|
+ System.out.println("isb == " + isb);
|
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
|
+ if (isa) {
|
|
|
|
+ list.addAll((List<Object>) a);
|
|
|
|
+ } else {
|
|
|
|
+ list.add(a+"");
|
|
|
|
+ }
|
|
|
|
+ if (isb) {
|
|
|
|
+ list.addAll((List<Object>) b);
|
|
|
|
+ } else {
|
|
|
|
+ list.add(b+"");
|
|
|
|
+ }
|
|
|
|
+ return list.stream().distinct().collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|