Browse Source

opt: 修改商品维度规则查询,更变为子查询

checkBack
Yen 1 year ago
parent
commit
f2f76fd3bc
  1. 19
      src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java
  2. 4
      src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java
  3. 23
      src/main/java/com/qs/serve/modules/goods/service/impl/GoodsAccreditServiceImpl.java
  4. 6
      src/main/resources/mapper/goods/GoodsSkuMapper.xml
  5. 58
      src/main/resources/mapper/goods/GoodsSpuMapper.xml

19
src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java

@ -158,15 +158,16 @@ public class GoodsSpuController {
private void tiSetSpuParam2(GoodsSpu param, BmsSupplier supplier) { private void tiSetSpuParam2(GoodsSpu param, BmsSupplier supplier) {
GoodsAccrIdsDto accrIdsDto = goodsAccreditService GoodsAccrIdsDto accrIdsDto = goodsAccreditService
.listIgnoreAcc2(supplier.getId(), supplier.listBizRegionIds(), supplier.listSaleRegionIds()); .listIgnoreAcc2(supplier.getId(), supplier.listBizRegionIds(), supplier.listSaleRegionIds());
List<Long> ids = goodsSkuMapper.listByOtherIds( param.setSubAccInfo(accrIdsDto);
accrIdsDto.getCateIds(), // List<Long> ids = goodsSkuMapper.listByOtherIds(
accrIdsDto.getSpuIds(), // accrIdsDto.getCateIds(),
accrIdsDto.getSkuIds(), // accrIdsDto.getSpuIds(),
accrIdsDto.getNotInCateIds(), // accrIdsDto.getSkuIds(),
accrIdsDto.getNotInSpuIds(), // accrIdsDto.getNotInCateIds(),
accrIdsDto.getNotInSkuIds() // accrIdsDto.getNotInSpuIds(),
); // accrIdsDto.getNotInSkuIds()
param.setNotInSkuIds(ids); // );
// param.setNotInSkuIds(ids);
} }

4
src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java

@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.qs.serve.common.framework.mybatis.handler.meta.SplitStringTypeHandler; import com.qs.serve.common.framework.mybatis.handler.meta.SplitStringTypeHandler;
import com.qs.serve.modules.goods.entity.dto.GoodsAccrIdsDto;
import lombok.Data; import lombok.Data;
import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.JdbcType;
import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.Length;
@ -225,6 +226,9 @@ public class GoodsSpu implements Serializable {
@TableField(exist = false) @TableField(exist = false)
private String searchCateRuleId; private String searchCateRuleId;
@TableField(exist = false)
private GoodsAccrIdsDto subAccInfo;
public List<String> listCategoryIds(){ public List<String> listCategoryIds(){
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
list.add(this.getCategoryFirst()); list.add(this.getCategoryFirst());

23
src/main/java/com/qs/serve/modules/goods/service/impl/GoodsAccreditServiceImpl.java

@ -327,20 +327,20 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go
public GoodsAccrIdsDto listIgnoreAcc2(String supplierId, List<String> bizRegionIds, List<String> saleRegionIds) { public GoodsAccrIdsDto listIgnoreAcc2(String supplierId, List<String> bizRegionIds, List<String> saleRegionIds) {
//查询自身所有 //查询自身所有
LambdaQueryWrapper<GoodsAccreditItem> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GoodsAccreditItem> lqw = new LambdaQueryWrapper<>();
lqw.select(GoodsAccreditItem::getId,GoodsAccreditItem::getAccType) lqw.select(GoodsAccreditItem::getId,GoodsAccreditItem::getAccType,GoodsAccreditItem::getAccId)
.or(a->a.eq(GoodsAccreditItem::getTargetType,"supplier").eq(GoodsAccreditItem::getTargetId,supplierId)) .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,"saleRegion").in(GoodsAccreditItem::getTargetId,saleRegionIds))
.or(a->a.eq(GoodsAccreditItem::getTargetType,"bizRegion").in(GoodsAccreditItem::getTargetId,bizRegionIds)); .or(a->a.eq(GoodsAccreditItem::getTargetType,"bizRegion").in(GoodsAccreditItem::getTargetId,bizRegionIds));
List<Long> selfNotInIds = goodsAccreditItemService.list(lqw).stream() List<Long> selfNotInIds = goodsAccreditItemService.list(lqw).stream()
.filter(a->a.getAccType().equals(1)).map(GoodsAccreditItem::getId).collect(Collectors.toList()); .filter(a->a.getAccType().equals(1)).map(GoodsAccreditItem::getAccId).collect(Collectors.toList());
List<Long> selfInIds = goodsAccreditItemService.list(lqw).stream() List<Long> selfInIds = goodsAccreditItemService.list(lqw).stream()
.filter(a->a.getAccType().equals(0)).map(GoodsAccreditItem::getId).collect(Collectors.toList()); .filter(a->a.getAccType().equals(0)).map(GoodsAccreditItem::getAccId).collect(Collectors.toList());
//查询其它维度所有in //查询其它维度所有in
LambdaQueryWrapper<GoodsAccreditItem> lqw2 = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GoodsAccreditItem> lqw2 = new LambdaQueryWrapper<>();
lqw2.select(GoodsAccreditItem::getId) lqw2.select(GoodsAccreditItem::getAccId)
.eq(GoodsAccreditItem::getAccType,0).and( .eq(GoodsAccreditItem::getAccType,0).and(
qw->{ qw->{
qw.or(a->a.eq(GoodsAccreditItem::getTargetType,"supplier").ne(GoodsAccreditItem::getTargetId,supplierId)) qw.or(a->a.eq(GoodsAccreditItem::getTargetType,"supplier").ne(GoodsAccreditItem::getTargetId,supplierId))
@ -349,7 +349,7 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go
} }
); );
List<Long> otherInIds = goodsAccreditItemService.list(lqw2) List<Long> otherInIds = goodsAccreditItemService.list(lqw2)
.stream().map(GoodsAccreditItem::getId).collect(Collectors.toList()); .stream().map(GoodsAccreditItem::getAccId).collect(Collectors.toList());
selfNotInIds.addAll(otherInIds); selfNotInIds.addAll(otherInIds);
List<Long> skuIds = new ArrayList<>(); List<Long> skuIds = new ArrayList<>();
@ -380,13 +380,14 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go
if(CollUtil.isNotEmpty(selfInIds)){ if(CollUtil.isNotEmpty(selfInIds)){
List<GoodsAccredit> inList = this.listByIds(selfInIds); List<GoodsAccredit> inList = this.listByIds(selfInIds);
Set<Long> spuIds2 = inList.stream().map(GoodsAccredit::getSpuId).filter(Objects::nonNull).collect(Collectors.toSet()); Set<Long> spuIds3 = inList.stream().map(GoodsAccredit::getSpuId).filter(Objects::nonNull).collect(Collectors.toSet());
Set<Long> skuIds2 = inList.stream().map(GoodsAccredit::getSkuId).filter(Objects::nonNull).collect(Collectors.toSet()); Set<Long> skuIds3 = inList.stream().map(GoodsAccredit::getSkuId).filter(Objects::nonNull).collect(Collectors.toSet());
Set<String> cateIds2 = inList.stream().map(GoodsAccredit::getCategoryId).filter(Objects::nonNull).collect(Collectors.toSet()); Set<String> cateIds3 = inList.stream().map(GoodsAccredit::getCategoryId).filter(Objects::nonNull).collect(Collectors.toSet());
skuNotInIds.addAll(skuIds2); skuNotInIds.addAll(skuIds3);
spuNotInIds.addAll(spuIds2); spuNotInIds.addAll(spuIds3);
cateNotInIds.addAll(cateIds2); cateNotInIds.addAll(cateIds3);
} }
return new GoodsAccrIdsDto(skuIds,spuIds,cateIds,skuNotInIds,spuNotInIds,cateNotInIds); return new GoodsAccrIdsDto(skuIds,spuIds,cateIds,skuNotInIds,spuNotInIds,cateNotInIds);
} }

6
src/main/resources/mapper/goods/GoodsSkuMapper.xml

@ -246,17 +246,17 @@
</foreach> </foreach>
and and
cate1.id not in cate1.id not in
<foreach collection="cateIds" item ="selectId" index="i" open="(" close=")" separator=","> <foreach collection="notInCateIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId} #{selectId}
</foreach> </foreach>
and and
cate2.id not in cate2.id not in
<foreach collection="cateIds" item ="selectId" index="i" open="(" close=")" separator=","> <foreach collection="notInCateIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId} #{selectId}
</foreach> </foreach>
and and
cate3.id not in cate3.id not in
<foreach collection="cateIds" item ="selectId" index="i" open="(" close=")" separator=","> <foreach collection="notInCateIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId} #{selectId}
</foreach> </foreach>
</select> </select>

58
src/main/resources/mapper/goods/GoodsSpuMapper.xml

@ -90,11 +90,67 @@
) )
</if> </if>
<if test="query.notInSkuIds!=null and query.notInSkuIds.size > 0"> <if test="query.notInSkuIds!=null and query.notInSkuIds.size > 0">
and `goods_spu`.`id` in and `goods_sku`.`id` not in
<foreach collection="query.notInSkuIds" item ="selectId" index="i" open="(" close=")" separator=","> <foreach collection="query.notInSkuIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId} #{selectId}
</foreach> </foreach>
</if> </if>
<if test="query.subAccInfo!=null">
and `goods_sku`.`id` not in(
select sku.id FROM goods_sku sku
left join goods_spu spu on sku.spu_id = spu.id
left join goods_category cate1 on cate1.id = spu.category_first
left join goods_category cate2 on cate2.id = spu.category_second
left join goods_category cate3 on cate3.id = spu.category_third
where
(
sku.id in
<foreach collection="query.subAccInfo.skuIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
or spu.id in
<foreach collection="query.subAccInfo.spuIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
or cate1.id in
<foreach collection="query.subAccInfo.cateIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
or cate2.id in
<foreach collection="query.subAccInfo.cateIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
or cate3.id in
<foreach collection="query.subAccInfo.cateIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
) and
sku.id not in
<foreach collection="query.subAccInfo.notInSkuIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
and
spu.id not in
<foreach collection="query.subAccInfo.notInSpuIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
and
cate1.id not in
<foreach collection="query.subAccInfo.notInCateIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
and
cate2.id not in
<foreach collection="query.subAccInfo.notInCateIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
and
cate3.id not in
<foreach collection="query.subAccInfo.notInCateIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
)
</if>
</sql> </sql>
<sql id="spuWherePart"> <sql id="spuWherePart">

Loading…
Cancel
Save