|
|
@@ -32,6 +32,8 @@ public class MerchantClassificationService {
|
|
|
添加商家自定义分类
|
|
|
*/
|
|
|
public MerchantClassification add(Long id, MerchantClassification classification) {
|
|
|
+
|
|
|
+
|
|
|
Long merchantId = merchantService.findMerchantId(id);
|
|
|
if (ObjectUtil.isNotNull(merchantClassificationRepo.findByMerchantIdAndName(merchantId, classification.getName()))) {
|
|
|
throw new BusinessException("该分类已存在");
|
|
|
@@ -59,7 +61,10 @@ public class MerchantClassificationService {
|
|
|
*/
|
|
|
public List<Goods> showGoods(Long classificationId) {
|
|
|
MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId).orElseThrow(new BusinessException("分类不存在"));
|
|
|
- List<Long> goodsIds = merchantClassification.getGoodsIds();
|
|
|
+ LongArrayConverter converter = new LongArrayConverter();
|
|
|
+ //List<Long> goodsIds = merchantClassification.getGoodsIds();
|
|
|
+ List<Long> goodsIds = converter.convertToEntityAttribute(merchantClassification.getGoodsIds());
|
|
|
+
|
|
|
List<Goods> goods = CollUtil.newArrayList();
|
|
|
goodsIds.forEach(s -> {
|
|
|
goods.add(goodsRepo.findById(s).orElseThrow(new BusinessException("商品不存在")));
|
|
|
@@ -78,13 +83,18 @@ public class MerchantClassificationService {
|
|
|
//查找分类
|
|
|
MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId).orElseThrow(new BusinessException("无分类"));
|
|
|
|
|
|
- List<Long> goodsIds = merchantClassification.getGoodsIds();
|
|
|
+ //List<Long> goodsIds = merchantClassification.getGoodsIds();
|
|
|
LongArrayConverter converter = new LongArrayConverter();
|
|
|
List<Long> longs = converter.convertToEntityAttribute(string);
|
|
|
+
|
|
|
+ List<Long> goodsIds = converter.convertToEntityAttribute(merchantClassification.getGoodsIds());
|
|
|
+
|
|
|
longs.stream().filter(l -> !goodsIds.contains(l)).forEach(goodsIds::add);
|
|
|
//goodsIds.addAll(longs);
|
|
|
|
|
|
- merchantClassification.setGoodsIds(goodsIds);
|
|
|
+ String ids = converter.convertToDatabaseColumn(goodsIds);
|
|
|
+
|
|
|
+ merchantClassification.setGoodsIds(ids);
|
|
|
|
|
|
return merchantClassificationRepo.save(merchantClassification);
|
|
|
}
|
|
|
@@ -96,11 +106,14 @@ public class MerchantClassificationService {
|
|
|
//查找分类
|
|
|
MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId).orElseThrow(new BusinessException("无分类"));
|
|
|
|
|
|
- List<Long> ids = merchantClassification.getGoodsIds();
|
|
|
+// List<Long> ids = merchantClassification.getGoodsIds();
|
|
|
+
|
|
|
+ LongArrayConverter converter = new LongArrayConverter();
|
|
|
+ List<Long> ids = converter.convertToEntityAttribute(merchantClassification.getGoodsIds());
|
|
|
|
|
|
if (!ids.contains(goodsId)) {
|
|
|
ids.add(goodsId);
|
|
|
- merchantClassification.setGoodsIds(ids);
|
|
|
+ merchantClassification.setGoodsIds(converter.convertToDatabaseColumn(ids));
|
|
|
merchantClassificationRepo.save(merchantClassification);
|
|
|
}
|
|
|
}
|
|
|
@@ -112,9 +125,13 @@ public class MerchantClassificationService {
|
|
|
//查找分类
|
|
|
MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId).orElseThrow(new BusinessException("无分类"));
|
|
|
|
|
|
- List<Long> goodsIds = merchantClassification.getGoodsIds();
|
|
|
+ LongArrayConverter converter = new LongArrayConverter();
|
|
|
+ List<Long> goodsIds = converter.convertToEntityAttribute(merchantClassification.getGoodsIds());
|
|
|
+
|
|
|
+ //List<Long> goodsIds = merchantClassification.getGoodsIds();
|
|
|
goodsIds.remove(goodId);
|
|
|
- merchantClassification.setGoodsIds(goodsIds);
|
|
|
+
|
|
|
+ merchantClassification.setGoodsIds(converter.convertToDatabaseColumn(goodsIds));
|
|
|
|
|
|
merchantClassificationRepo.save(merchantClassification);
|
|
|
}
|