|
@@ -203,20 +203,27 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
|
|
|
if (StringUtils.notEmpty(param.getMainBusiness())){
|
|
|
business.add(param.getMainBusiness());
|
|
|
}
|
|
|
-// this.categoryService.removeByIds(business);
|
|
|
if (!CollectionUtils.isEmpty(business)){
|
|
|
- this.categoryService.deleteByMerchantId(merchant.getId());
|
|
|
- List<Category> categories = this.categoryService.getCategories(business);
|
|
|
- if (!CollectionUtils.isEmpty(categories)){
|
|
|
- categories.forEach(item ->{
|
|
|
- item.setSourceId(item.getId());
|
|
|
- item.setId(null);
|
|
|
- item.setMerchantId(merchant.getId());
|
|
|
- item.setType("1");
|
|
|
- item.setParentId(0L);
|
|
|
-// this.categoryService.save(item);
|
|
|
- });
|
|
|
- this.categoryService.saveBatchCategories(categories);
|
|
|
+// this.categoryService.deleteByMerchantId(merchant.getId());
|
|
|
+ List<CategoryDTO> lists = this.categoryService.getCategoriesByMerchant(id);
|
|
|
+ List<Long> sources = lists.stream().map(CategoryDTO::getSourceId).collect(Collectors.toList());
|
|
|
+ List<Long> deletes = sources.stream().filter(item -> !business.contains(item)).collect(Collectors.toList());
|
|
|
+ List<Long> adds = business.stream().filter(item ->!sources.contains(item)).collect(Collectors.toList());
|
|
|
+ if (!CollectionUtils.isEmpty(adds)){
|
|
|
+ List<Category> categories = this.categoryService.getCategories(adds);
|
|
|
+ if (!CollectionUtils.isEmpty(categories)){
|
|
|
+ categories.forEach(item ->{
|
|
|
+ item.setSourceId(item.getId());
|
|
|
+ item.setId(null);
|
|
|
+ item.setMerchantId(merchant.getId());
|
|
|
+ item.setType("1");
|
|
|
+ item.setParentId(0L);
|
|
|
+ });
|
|
|
+ this.categoryService.saveBatchCategories(categories);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(deletes)){
|
|
|
+ this.categoryService.deleteBySourceId(deletes);
|
|
|
}
|
|
|
}
|
|
|
}
|