|
|
@@ -1,6 +1,7 @@
|
|
|
package com.ruoyi.business.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
@@ -99,24 +100,25 @@ public class BusinessCategoryRelationServiceImpl implements IBusinessCategoryRel
|
|
|
/**
|
|
|
* 新增商家分类关联
|
|
|
*
|
|
|
- * @param bos 商家分类关联
|
|
|
+ * @param bo 商家分类关联
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public Boolean insertByBo(List<BusinessCategoryRelationBo> bos) {
|
|
|
- //判断是不是同一个商家
|
|
|
- Set<Long> businessIds = bos.stream()
|
|
|
- .map(BusinessCategoryRelationBo::getBusinessId)
|
|
|
- .collect(Collectors.toSet());
|
|
|
- if (businessIds.size() > 1) {
|
|
|
- throw new ServiceException("批量操作仅支持同一商家的分类关联");
|
|
|
- }
|
|
|
- Long businessId = businessIds.iterator().next();
|
|
|
+ public Boolean insertByBo(BusinessCategoryRelationBo bo) {
|
|
|
//先删除
|
|
|
- baseMapper.delete(new LambdaQueryWrapper<BusinessCategoryRelation>().eq(BusinessCategoryRelation::getBusinessId, businessId));
|
|
|
- //在添加
|
|
|
- return baseMapper.insertBatch(BeanCopyUtils.copyList(bos, BusinessCategoryRelation.class));
|
|
|
+ baseMapper.delete(new LambdaQueryWrapper<BusinessCategoryRelation>().eq(BusinessCategoryRelation::getBusinessId, bo.getBusinessId()));
|
|
|
+ if (CollUtil.isNotEmpty(bo.getCategoryIds())) {
|
|
|
+ List<BusinessCategoryRelation> list = bo.getCategoryIds().stream().map(categoryId -> {
|
|
|
+ BusinessCategoryRelation relation = new BusinessCategoryRelation();
|
|
|
+ relation.setBusinessId(bo.getBusinessId());
|
|
|
+ relation.setCategoryId(categoryId);
|
|
|
+ return relation;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ //在添加
|
|
|
+ return baseMapper.insertBatch(list);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|