|
@@ -204,22 +204,22 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void addGoods(List<GoodsWrapper.Goods> goodsList, Integer operatorId) {
|
|
|
- List<String> snList = goodsList.stream().map(GoodsWrapper.Goods::getSn).collect(Collectors.toList());
|
|
|
- if (snList.size() != new HashSet<>(snList).size()) {
|
|
|
- throw new BizException("商品货号重复");
|
|
|
- }
|
|
|
- List<Goods> bySns = goodsDao.findBySns(snList);
|
|
|
- if (!CollectionUtils.isEmpty(bySns)) {
|
|
|
- throw new BizException("商品货号重复");
|
|
|
- }
|
|
|
+// List<String> snList = goodsList.stream().map(GoodsWrapper.Goods::getSn).collect(Collectors.toList());
|
|
|
+// if (snList.size() != new HashSet<>(snList).size()) {
|
|
|
+// throw new BizException("商品货号重复");
|
|
|
+// }
|
|
|
+// List<Goods> bySns = goodsDao.findBySns(snList);
|
|
|
+// if (!CollectionUtils.isEmpty(bySns)) {
|
|
|
+// throw new BizException("商品货号重复");
|
|
|
+// }
|
|
|
for (GoodsWrapper.Goods goods : goodsList) {
|
|
|
if (StringUtils.isBlank(goods.getSn())) {
|
|
|
throw new BizException("请指定商品货号");
|
|
|
}
|
|
|
- Goods existsGood = goodsDao.lockBySn(goods.getSn());
|
|
|
- if (Objects.nonNull(existsGood)) {
|
|
|
- throw new BizException("商品货号重复");
|
|
|
- }
|
|
|
+// Goods existsGood = goodsDao.lockBySn(goods.getSn());
|
|
|
+// if (Objects.nonNull(existsGood)) {
|
|
|
+// throw new BizException("商品货号重复");
|
|
|
+// }
|
|
|
List<GoodsWrapper.GoodsSub> goodsSubList = goods.getGoodsSubList();
|
|
|
//获取最小的库存数
|
|
|
String skuIds = goodsSubList.stream().map(e -> e.getSku().toString()).collect(Collectors.joining(","));
|
|
@@ -614,6 +614,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
List<String> errList = new ArrayList<>();
|
|
|
// Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
|
|
|
Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(excel, 2);
|
|
|
+ excel.deleteOnExit();
|
|
|
if (sheetsListMap.values().isEmpty()) {
|
|
|
errList.add("excel未解析到数据");
|
|
|
return getExportErrLogFile(errList);
|
|
@@ -665,12 +666,12 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
});
|
|
|
|
|
|
// excel中所有的sn
|
|
|
- List<String> snSet = firstSheet.stream().map(next -> next.get("组合商品货号").toString()).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
|
|
+// List<String> snSet = firstSheet.stream().map(next -> next.get("组合商品货号").toString()).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
|
|
// 获取重复的货号
|
|
|
- List<String> repeatSnList = snSet.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting()))
|
|
|
- .entrySet().stream().filter(e -> e.getValue() > 1)
|
|
|
- .map(Map.Entry::getKey).collect(Collectors.toList());
|
|
|
- List<String> existSnList = goodsDao.findBySns(snSet.stream().distinct().collect(Collectors.toList())).stream().map(Goods::getSn).distinct().collect(Collectors.toList());
|
|
|
+// List<String> repeatSnList = snSet.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting()))
|
|
|
+// .entrySet().stream().filter(e -> e.getValue() > 1)
|
|
|
+// .map(Map.Entry::getKey).collect(Collectors.toList());
|
|
|
+// List<String> existSnList = goodsDao.findBySns(snSet.stream().distinct().collect(Collectors.toList())).stream().map(Goods::getSn).distinct().collect(Collectors.toList());
|
|
|
|
|
|
Map<String, Long> brandNameIdMap = mallFeignService.getList().stream().collect(Collectors.toMap(BrandDto::getName, BrandDto::getId));
|
|
|
|
|
@@ -704,6 +705,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
String sn = row.get("组合商品货号").toString();
|
|
|
if (StringUtils.isNotEmpty(sn)) {
|
|
|
beforeGoods.clear();
|
|
|
+ snSubGoodsMap.clear();
|
|
|
}
|
|
|
String subGoodsName = null;
|
|
|
String subGoodsSku = null;
|
|
@@ -748,16 +750,17 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
beforeGoods.put(fieldCode, value);
|
|
|
}
|
|
|
- if ("sn".equals(fieldCode)) {
|
|
|
- if (existSnList.contains(value.toString())) {
|
|
|
- lineErrList.add("货号[" + value + "]已存在");
|
|
|
- } else {
|
|
|
- if (repeatSnList.contains(value.toString())) {
|
|
|
- lineErrList.add("货号[" + value + "]重复");
|
|
|
- }
|
|
|
- }
|
|
|
- objectMap.put(fieldCode, value);
|
|
|
- } else if ("marketPrice".equals(fieldCode)
|
|
|
+// if ("sn".equals(fieldCode)) {
|
|
|
+// if (existSnList.contains(value.toString())) {
|
|
|
+// lineErrList.add("货号[" + value + "]已存在");
|
|
|
+// } else {
|
|
|
+// if (repeatSnList.contains(value.toString())) {
|
|
|
+// lineErrList.add("货号[" + value + "]重复");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// objectMap.put(fieldCode, value);
|
|
|
+// } else
|
|
|
+ if ("marketPrice".equals(fieldCode)
|
|
|
|| "discountPrice".equals(fieldCode)
|
|
|
|| "groupPurchasePrice".equals(fieldCode)) {
|
|
|
if (NumberUtils.isNumber(value.toString())) {
|
|
@@ -857,17 +860,19 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
lineErrList.add("可售分部至少需要填写一个");
|
|
|
}
|
|
|
// 校验子商品sku是否重复
|
|
|
- String tempSn = objectMap.get("sn").toString();
|
|
|
- String tempSku = objectMap.get("sku").toString();
|
|
|
- byte[] images = objectMap.getBytes("image");
|
|
|
- snImageMap.put(tempSn, images);
|
|
|
- if (StringUtils.isNotEmpty(tempSn) && StringUtils.isNotEmpty(tempSku)) {
|
|
|
- Set<String> set = snSubGoodsMap.getOrDefault(tempSn, new HashSet<>());
|
|
|
- if (set.contains(tempSku)) {
|
|
|
- lineErrList.add("子商品SKU重复");
|
|
|
- } else {
|
|
|
- set.add(tempSku);
|
|
|
- snSubGoodsMap.put(tempSn, set);
|
|
|
+ String tempSn = objectMap.getOrDefault("sn", "").toString();
|
|
|
+ String tempSku = objectMap.getOrDefault("sku", "").toString();
|
|
|
+ if (StringUtils.isNotEmpty(tempSn)) {
|
|
|
+ byte[] images = objectMap.getBytes("image");
|
|
|
+ snImageMap.put(tempSn, images);
|
|
|
+ if (StringUtils.isNotEmpty(tempSku)) {
|
|
|
+ Set<String> set = snSubGoodsMap.getOrDefault(tempSn, new HashSet<>());
|
|
|
+ if (set.contains(tempSku)) {
|
|
|
+ lineErrList.add("子商品SKU重复");
|
|
|
+ } else {
|
|
|
+ set.add(tempSku);
|
|
|
+ snSubGoodsMap.put(tempSn, set);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -926,6 +931,7 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
Goods goods = JSON.parseObject(JSON.toJSONString(good), Goods.class);
|
|
|
goods.setStatus(YesOrNoEnum.NO);
|
|
|
goods.setStockCount(stock);
|
|
|
+ goods.setGroupGoods(true);
|
|
|
this.insert(goods);
|
|
|
|
|
|
List<GoodsSub> subList = goodsSubList.stream().map(next -> {
|
|
@@ -1267,6 +1273,11 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
GoodsWrapper.Goods detail = JSON.parseObject(JSON.toJSONString(goods), GoodsWrapper.Goods.class);
|
|
|
detail.setGoodsSubList(queryGoodsSubByGoodId(goodsId));
|
|
|
+ String brand = detail.getBrand();
|
|
|
+ if (StringUtils.isNotEmpty(brand) && NumberUtils.isNumber(brand)) {
|
|
|
+ Map<Long, String> brandIdNameMap = queryGoodsBrandList().stream().collect(Collectors.toMap(BrandDto::getId, BrandDto::getName));
|
|
|
+ detail.setBrandName(brandIdNameMap.getOrDefault(Long.valueOf(brand), ""));
|
|
|
+ }
|
|
|
return detail;
|
|
|
}
|
|
|
|
|
@@ -1295,15 +1306,6 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
goodsInfo = JSON.parseObject(JSON.toJSONString(goods), Goods.class);
|
|
|
goodsInfo.setStatus(null);
|
|
|
if (!goodsSubList.isEmpty()) {
|
|
|
- goodsInfo.setComplementGoodsIdList(null);
|
|
|
- UpdateWrapper<GoodsSub> delWrapper = new UpdateWrapper<>();
|
|
|
- delWrapper.eq("goods_id_", goods.getId());
|
|
|
- goodsSubService.getBaseMapper().delete(delWrapper);
|
|
|
-
|
|
|
- List<GoodsSub> goodsSubs = JSON.parseArray(JSON.toJSONString(goodsSubList), GoodsSub.class);
|
|
|
- goodsSubs.forEach(next -> next.setGoodsId(goods.getId()));
|
|
|
- goodsSubService.saveBatch(goodsSubs);
|
|
|
-
|
|
|
BigDecimal organCostPrice = goodsSubList.stream().map(GoodsWrapper.GoodsSub::getGoodsPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
goodsInfo.setOrganCostPrice(organCostPrice);
|
|
|
|
|
@@ -1318,6 +1320,24 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
if(CollectionUtils.isEmpty(productList)){
|
|
|
throw new BizException("子商品不存在");
|
|
|
}
|
|
|
+ Map<Integer, Long> skuIdGoodIdMap = productList.stream().collect(Collectors.toMap(PmsProductDto::getSkuStockId, PmsProductDto::getGoodsId));
|
|
|
+
|
|
|
+ List<GoodsSub> goodsSubs = JSON.parseArray(JSON.toJSONString(goodsSubList), GoodsSub.class);
|
|
|
+ for (GoodsSub next : goodsSubs) {
|
|
|
+ next.setGoodsId(goods.getId());
|
|
|
+ if (skuIdGoodIdMap.containsKey(next.getSku())) {
|
|
|
+ next.setMallGoodsId(skuIdGoodIdMap.get(next.getSku()).intValue());
|
|
|
+ } else {
|
|
|
+ throw new BizException("存在删除的子商品");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateWrapper<GoodsSub> delWrapper = new UpdateWrapper<>();
|
|
|
+ delWrapper.eq("goods_id_", goods.getId());
|
|
|
+ goodsSubService.getBaseMapper().delete(delWrapper);
|
|
|
+ goodsSubService.saveBatch(goodsSubs);
|
|
|
+
|
|
|
+ goodsInfo.setComplementGoodsIdList(null);
|
|
|
//获取最小库存数量
|
|
|
Integer stock = productList.stream().map(PmsProductDto::getStock).min(Integer::compareTo).get();
|
|
|
goodsInfo.setStockCount(stock);
|