|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.qs.serve.modules.goods.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.qs.serve.common.util.Assert; |
|
|
@ -23,6 +24,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import com.qs.serve.modules.goods.service.GoodsAccreditService; |
|
|
|
import com.qs.serve.modules.goods.mapper.GoodsAccreditMapper; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
@ -60,9 +62,9 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go |
|
|
|
Assert.throwEx("参数异常 500B2 "); |
|
|
|
} |
|
|
|
|
|
|
|
boolean b1 = CollUtil.isNotEmpty(param.getNotInSaleRegionIds()); |
|
|
|
boolean b2 = CollUtil.isNotEmpty(param.getOnlySaleRegionIds()); |
|
|
|
boolean b3 = CollUtil.isNotEmpty(param.getNotInBizRegionIds()); |
|
|
|
boolean b1 = CollUtil.isNotEmpty(param.getOnlySaleRegionIds()); |
|
|
|
boolean b2 = CollUtil.isNotEmpty(param.getNotInSaleRegionIds()); |
|
|
|
boolean b3 = CollUtil.isNotEmpty(param.getOnlyBizRegionIds()); |
|
|
|
boolean b4 = CollUtil.isNotEmpty(param.getNotInBizRegionIds()); |
|
|
|
boolean b5 = CollUtil.isNotEmpty(param.getOnlySupplierIds()); |
|
|
|
boolean b6 = CollUtil.isNotEmpty(param.getNotInSupplierIds()); |
|
|
@ -184,14 +186,14 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go |
|
|
|
public GoodsAccreditVo getById(String cateId, String spuId, String skuId) { |
|
|
|
GoodsAccredit accredit = this.getGoodsAccredit(new GoodsAccreditBo(cateId,spuId,skuId)); |
|
|
|
GoodsAccreditVo accreditVo = new GoodsAccreditVo(); |
|
|
|
if(accredit!=null){ |
|
|
|
if(accredit!=null&&accredit.getId()!=null){ |
|
|
|
List<GoodsAccreditItem> accreditItemList = goodsAccreditItemService |
|
|
|
.list(new LambdaQueryWrapper<GoodsAccreditItem>().eq(GoodsAccreditItem::getAccId,accredit.getId())); |
|
|
|
Map<String,List<GoodsAccreditItem>> accMap = accreditItemList.stream() |
|
|
|
.collect(Collectors.groupingBy(GoodsAccreditItem::getTargetType)); |
|
|
|
List<GoodsAccreditItem> list1 = accMap.get("supplier"); |
|
|
|
List<GoodsAccreditItem> list2 = accMap.get("bizRegion"); |
|
|
|
List<GoodsAccreditItem> list3 = accMap.get("caleRegion"); |
|
|
|
List<GoodsAccreditItem> list3 = accMap.get("saleRegion"); |
|
|
|
|
|
|
|
if(CollUtil.isNotEmpty(list1)){ |
|
|
|
Map<Integer,List<GoodsAccreditItem>> listMap = list1.stream() |
|
|
@ -256,45 +258,89 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go |
|
|
|
.or(a->a.eq(GoodsAccreditItem::getTargetType,"bizRegion").in(GoodsAccreditItem::getTargetId,bizRegionIds)); |
|
|
|
} |
|
|
|
); |
|
|
|
List<Long> itemIds = goodsAccreditItemService.list(lqw).stream().map(GoodsAccreditItem::getId).collect(Collectors.toList()); |
|
|
|
List<Long> notInIds = goodsAccreditItemService.list(lqw).stream().map(GoodsAccreditItem::getId).collect(Collectors.toList()); |
|
|
|
|
|
|
|
//查询所有 in
|
|
|
|
//查询其它维度所有 in
|
|
|
|
LambdaQueryWrapper<GoodsAccreditItem> lqw2 = new LambdaQueryWrapper<>(); |
|
|
|
lqw2.select(GoodsAccreditItem::getId) |
|
|
|
lqw2 |
|
|
|
// 业务in
|
|
|
|
.eq(GoodsAccreditItem::getAccType,0) |
|
|
|
.and( |
|
|
|
qw->{ |
|
|
|
qw.or(a->a.eq(GoodsAccreditItem::getTargetType,"supplier").ne(GoodsAccreditItem::getTargetId,supplierId)) |
|
|
|
.or(a->a.eq(GoodsAccreditItem::getTargetType,"saleRegion").notIn(GoodsAccreditItem::getTargetId,saleRegionIds)) |
|
|
|
.or(a->a.eq(GoodsAccreditItem::getTargetType,"bizRegion").notIn(GoodsAccreditItem::getTargetId,bizRegionIds)); |
|
|
|
} |
|
|
|
); |
|
|
|
List<GoodsAccreditItem> list2 = goodsAccreditItemService.list(lqw2); |
|
|
|
|
|
|
|
|
|
|
|
// 排除本维度in关系
|
|
|
|
LambdaQueryWrapper<GoodsAccreditItem> lqw3 = new LambdaQueryWrapper<>(); |
|
|
|
lqw3 |
|
|
|
// 业务in
|
|
|
|
.eq(GoodsAccreditItem::getAccType,0) |
|
|
|
.and( |
|
|
|
qw->{ |
|
|
|
qw.or(a->a.eq(GoodsAccreditItem::getTargetType,"supplier").ne(GoodsAccreditItem::getTargetId,supplierId)) |
|
|
|
.or(a->a.eq(GoodsAccreditItem::getTargetType,"saleRegion").notIn(GoodsAccreditItem::getTargetId,saleRegionIds)) |
|
|
|
.or(a->a.eq(GoodsAccreditItem::getTargetType,"bizRegion").notIn(GoodsAccreditItem::getTargetId,bizRegionIds)); |
|
|
|
qw.or(a->a.eq(GoodsAccreditItem::getTargetType,"supplier").eq(GoodsAccreditItem::getTargetId,supplierId)) |
|
|
|
.or(a->a.eq(GoodsAccreditItem::getTargetType,"saleRegion").in(GoodsAccreditItem::getTargetId,saleRegionIds)) |
|
|
|
.or(a->a.eq(GoodsAccreditItem::getTargetType,"bizRegion").in(GoodsAccreditItem::getTargetId,bizRegionIds)); |
|
|
|
} |
|
|
|
); |
|
|
|
List<Long> itemIds2 = goodsAccreditItemService.list(lqw2).stream().map(GoodsAccreditItem::getId).collect(Collectors.toList()); |
|
|
|
); |
|
|
|
List<GoodsAccreditItem> list3 = goodsAccreditItemService.list(lqw3); |
|
|
|
|
|
|
|
itemIds.addAll(itemIds2); |
|
|
|
//移除交集 list3 与 list2交集,同品类支持上下级,解决选多用户情况,实现效果区域维度为并集
|
|
|
|
List<GoodsAccreditItem> listResult = list2; |
|
|
|
if(CollUtil.isNotEmpty(list2)&&CollUtil.isNotEmpty(list3)){ |
|
|
|
listResult = new ArrayList<>(); |
|
|
|
for (GoodsAccreditItem it2 : list2) { |
|
|
|
boolean mch = false; |
|
|
|
for (GoodsAccreditItem it3 : list3) { |
|
|
|
boolean b1 = it2.getAccId().equals(it3.getAccId()); |
|
|
|
if(b1){ |
|
|
|
mch =true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!mch){ |
|
|
|
listResult.add(it2); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//TODO 可拓展,支持品类上下级
|
|
|
|
|
|
|
|
//合并不同维度in结果
|
|
|
|
List<Long> itemIds2 = listResult.stream().map(GoodsAccreditItem::getId).collect(Collectors.toList()); |
|
|
|
notInIds.addAll(itemIds2); |
|
|
|
|
|
|
|
List<GoodsAccreditItem> itemList; |
|
|
|
if(itemIds.size()>0){ |
|
|
|
itemList = goodsAccreditItemService.list(new LambdaQueryWrapper<GoodsAccreditItem>().notIn(GoodsAccreditItem::getId,itemIds)); |
|
|
|
if(notInIds.size()>0){ |
|
|
|
itemList = goodsAccreditItemService.list(new LambdaQueryWrapper<GoodsAccreditItem>().in(GoodsAccreditItem::getId,notInIds)); |
|
|
|
}else { |
|
|
|
itemList = goodsAccreditItemService.list(); |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
Set<Long> accIds = itemList.stream().map(GoodsAccreditItem::getAccId).collect(Collectors.toSet()); |
|
|
|
if(CollUtil.isEmpty(accIds)){ |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
return this.listByIds(accIds); |
|
|
|
} |
|
|
|
|
|
|
|
private GoodsAccredit getGoodsAccredit(GoodsAccreditBo param){ |
|
|
|
GoodsAccredit accredit = null; |
|
|
|
if(param.getCategoryId()!=null){ |
|
|
|
GoodsCategory category = categoryMapper.selectById(param.getCategoryId()); |
|
|
|
if(category!=null){ |
|
|
|
accredit = this.getOne( new LambdaQueryWrapper<GoodsAccredit>() |
|
|
|
.eq(GoodsAccredit::getCategoryId,param.getCategoryId()),false); |
|
|
|
if(accredit==null){ |
|
|
|
GoodsCategory category = categoryMapper.selectById(param.getCategoryId()); |
|
|
|
accredit = new GoodsAccredit(); |
|
|
|
accredit.setCategoryId(category.getId().toString()); |
|
|
|
} |
|
|
|
}else if (param.getSpuId()!=null){ |
|
|
|
GoodsSpu spu = goodsSpuMapper.selectById(param.getSpuId()); |
|
|
|
if(spu!=null){ |
|
|
|
accredit = this.getOne( new LambdaQueryWrapper<GoodsAccredit>() |
|
|
|
.eq(GoodsAccredit::getSpuId,param.getSpuId()),false); |
|
|
|
if(accredit==null){ |
|
|
|
GoodsSpu spu = goodsSpuMapper.selectById(param.getSpuId()); |
|
|
|
accredit = new GoodsAccredit(); |
|
|
|
accredit.setSpuId(spu.getId()); |
|
|
|
} |
|
|
|