|
@ -3,8 +3,13 @@ package com.qs.serve.modules.goods.service.impl; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
|
import com.qs.serve.common.model.dto.PageVo; |
|
|
|
|
|
import com.qs.serve.common.model.dto.R; |
|
|
import com.qs.serve.common.util.Assert; |
|
|
import com.qs.serve.common.util.Assert; |
|
|
|
|
|
import com.qs.serve.common.util.PageUtil; |
|
|
|
|
|
import com.qs.serve.common.util.StringUtils; |
|
|
import com.qs.serve.modules.bms.entity.BmsRegion; |
|
|
import com.qs.serve.modules.bms.entity.BmsRegion; |
|
|
import com.qs.serve.modules.bms.entity.BmsRegion2; |
|
|
import com.qs.serve.modules.bms.entity.BmsRegion2; |
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
@ -14,6 +19,9 @@ import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
import com.qs.serve.modules.goods.entity.*; |
|
|
import com.qs.serve.modules.goods.entity.*; |
|
|
import com.qs.serve.modules.goods.entity.bo.GoodsAccreditBo; |
|
|
import com.qs.serve.modules.goods.entity.bo.GoodsAccreditBo; |
|
|
import com.qs.serve.modules.goods.entity.dto.GoodsAccrIdsDto; |
|
|
import com.qs.serve.modules.goods.entity.dto.GoodsAccrIdsDto; |
|
|
|
|
|
import com.qs.serve.modules.goods.entity.dto.GoodsAccreditExt; |
|
|
|
|
|
import com.qs.serve.modules.goods.entity.dto.GoodsAccreditQuery; |
|
|
|
|
|
import com.qs.serve.modules.goods.entity.vo.GoodsAccreditResult; |
|
|
import com.qs.serve.modules.goods.entity.vo.GoodsAccreditVo; |
|
|
import com.qs.serve.modules.goods.entity.vo.GoodsAccreditVo; |
|
|
import com.qs.serve.modules.goods.mapper.*; |
|
|
import com.qs.serve.modules.goods.mapper.*; |
|
|
import com.qs.serve.modules.goods.service.GoodsAccreditItemService; |
|
|
import com.qs.serve.modules.goods.service.GoodsAccreditItemService; |
|
@ -42,10 +50,173 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go |
|
|
private final BmsRegionMapper regionMapper; |
|
|
private final BmsRegionMapper regionMapper; |
|
|
private final BmsRegion2Mapper region2Mapper; |
|
|
private final BmsRegion2Mapper region2Mapper; |
|
|
private final BmsSupplierMapper supplierMapper; |
|
|
private final BmsSupplierMapper supplierMapper; |
|
|
private final GoodsSpuMapper spuMapper; |
|
|
|
|
|
|
|
|
|
|
|
private final GoodsAccreditItemService goodsAccreditItemService; |
|
|
private final GoodsAccreditItemService goodsAccreditItemService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<GoodsAccreditResult> queryPage(GoodsAccreditQuery query) { |
|
|
|
|
|
String productCode = query.getCode(); |
|
|
|
|
|
String productName = query.getName(); |
|
|
|
|
|
String targetCode = query.getTargetCode(); |
|
|
|
|
|
String targetName = query.getTargetName(); |
|
|
|
|
|
if(StringUtils.hasText(productCode)||StringUtils.hasText(productName)){ |
|
|
|
|
|
//向上维度查询
|
|
|
|
|
|
Set<String> codes = new HashSet<>(); |
|
|
|
|
|
List<GoodsSku> skuList = goodsSkuMapper.selectList(new LambdaQueryWrapper<GoodsSku>() |
|
|
|
|
|
.eq(GoodsSku::getSkuCode,productCode) |
|
|
|
|
|
.or() |
|
|
|
|
|
.eq(GoodsSku::getSkuName,productName)); |
|
|
|
|
|
List<GoodsSpu> spuList = goodsSpuMapper.selectList(new LambdaQueryWrapper<GoodsSpu>() |
|
|
|
|
|
.eq(GoodsSpu::getSpuCode,productCode) |
|
|
|
|
|
.or() |
|
|
|
|
|
.eq(GoodsSpu::getName,productName)); |
|
|
|
|
|
if(skuList.size()>0){ |
|
|
|
|
|
codes.add(productCode); |
|
|
|
|
|
spuList.addAll(goodsSpuMapper.selectBatchIds(skuList.stream().map(GoodsSku::getSpuId).collect(Collectors.toSet()))); |
|
|
|
|
|
} |
|
|
|
|
|
if(spuList.size()>0){ |
|
|
|
|
|
Set<String> cateIds = new HashSet<>(); |
|
|
|
|
|
for (GoodsSpu spu : spuList) { |
|
|
|
|
|
//向上查询添加skuCode
|
|
|
|
|
|
codes.add(spu.getSpuCode()); |
|
|
|
|
|
cateIds.addAll(spu.listCategoryIds()); |
|
|
|
|
|
} |
|
|
|
|
|
List<GoodsCategory> categoryList = categoryMapper.selectBatchIds(cateIds); |
|
|
|
|
|
for (GoodsCategory category : categoryList) { |
|
|
|
|
|
//向上查询添加CategoryCode
|
|
|
|
|
|
codes.add(category.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
List<GoodsCategory> categoryList = categoryMapper.selectList(new LambdaQueryWrapper<GoodsCategory>().eq(GoodsCategory::getCode,productCode)); |
|
|
|
|
|
for (GoodsCategory category : categoryList) { |
|
|
|
|
|
codes.add(category.getCode()); |
|
|
|
|
|
if(!category.getParentId().equals(0L)){ |
|
|
|
|
|
GoodsCategory lastLevel = categoryMapper.selectById(category.getParentId()); |
|
|
|
|
|
if(lastLevel!=null){ |
|
|
|
|
|
codes.add(lastLevel.getCode()); |
|
|
|
|
|
if(!lastLevel.getParentId().equals(0L)){ |
|
|
|
|
|
GoodsCategory lastLevel2 = categoryMapper.selectById(category.getParentId()); |
|
|
|
|
|
if(lastLevel2!=null){ |
|
|
|
|
|
codes.add(lastLevel.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
query.setCodeList(codes); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(StringUtils.hasText(targetCode)||StringUtils.hasText(targetName)){ |
|
|
|
|
|
Set<String> targetCodes = new HashSet<>(); |
|
|
|
|
|
List<BmsSupplier> supplierList = supplierMapper.selectList(new LambdaQueryWrapper<BmsSupplier>() |
|
|
|
|
|
.eq(BmsSupplier::getCode,targetCode) |
|
|
|
|
|
.or() |
|
|
|
|
|
.eq(BmsSupplier::getName,targetName)); |
|
|
|
|
|
if(supplierList.size()>0){ |
|
|
|
|
|
targetCodes.add(targetCode); |
|
|
|
|
|
for (BmsSupplier supplier : supplierList) { |
|
|
|
|
|
List<String> bizIds = supplier.listBizRegionIds(); |
|
|
|
|
|
List<String> saleIds = supplier.listSaleRegionIds(); |
|
|
|
|
|
List<BmsRegion> regionList = regionMapper.selectBatchIds(saleIds); |
|
|
|
|
|
for (BmsRegion region : regionList) { |
|
|
|
|
|
targetCodes.add(region.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
List<BmsRegion2> region2List = region2Mapper.selectBatchIds(bizIds); |
|
|
|
|
|
for (BmsRegion2 region2 : region2List) { |
|
|
|
|
|
targetCodes.add(region2.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<BmsRegion> regionList = regionMapper.selectList(new LambdaQueryWrapper<BmsRegion>() |
|
|
|
|
|
.eq(BmsRegion::getName,targetName) |
|
|
|
|
|
.or() |
|
|
|
|
|
.eq(BmsRegion::getCode,targetCode)); |
|
|
|
|
|
if (regionList.size()>0){ |
|
|
|
|
|
Set<String> regIds = new HashSet<>(); |
|
|
|
|
|
for (BmsRegion region : regionList) { |
|
|
|
|
|
String[] ids = region.getPathIds().split("_"); |
|
|
|
|
|
regIds.addAll(Arrays.asList(ids)); |
|
|
|
|
|
} |
|
|
|
|
|
regionList = regionMapper.selectBatchIds(regIds); |
|
|
|
|
|
targetCodes.addAll(regionList.stream().map(BmsRegion::getCode).collect(Collectors.toSet())); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<BmsRegion2> region2List = region2Mapper.selectList(new LambdaQueryWrapper<BmsRegion2>() |
|
|
|
|
|
.eq(BmsRegion2::getName,targetName) |
|
|
|
|
|
.or() |
|
|
|
|
|
.eq(BmsRegion2::getCode,targetCode)); |
|
|
|
|
|
if (region2List.size()>0){ |
|
|
|
|
|
Set<String> regIds = new HashSet<>(); |
|
|
|
|
|
for (BmsRegion2 region : region2List) { |
|
|
|
|
|
String[] ids = region.getPathIds().split("_"); |
|
|
|
|
|
regIds.addAll(Arrays.asList(ids)); |
|
|
|
|
|
} |
|
|
|
|
|
region2List = region2Mapper.selectBatchIds(regIds); |
|
|
|
|
|
targetCodes.addAll(region2List.stream().map(BmsRegion2::getCode).collect(Collectors.toSet())); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
query.setTargetCodeList(targetCodes); |
|
|
|
|
|
} |
|
|
|
|
|
List<GoodsAccreditExt> list = super.baseMapper.queryPage(query); |
|
|
|
|
|
List<GoodsAccreditResult> results = list.stream().map(ext->{ |
|
|
|
|
|
GoodsAccreditResult result = new GoodsAccreditResult(); |
|
|
|
|
|
result.setId("goods"+ext.getId()); |
|
|
|
|
|
result.setRuleType("goods"); |
|
|
|
|
|
if(ext.getCategoryId()!=null){ |
|
|
|
|
|
result.setGoodType("category"); |
|
|
|
|
|
}else if (ext.getSpuId()!=null){ |
|
|
|
|
|
result.setGoodType("spu"); |
|
|
|
|
|
}else { |
|
|
|
|
|
result.setGoodType("sku"); |
|
|
|
|
|
} |
|
|
|
|
|
result.setCode(ext.getCode()); |
|
|
|
|
|
result.setName(ext.getName()); |
|
|
|
|
|
result.setAccType(ext.getAccType().equals(0)?"in":"notIn"); |
|
|
|
|
|
result.setTargetType(ext.getTargetType()); |
|
|
|
|
|
result.setTargetCode(ext.getTargetCode()); |
|
|
|
|
|
result.setTargetName(ext.getTargetName()); |
|
|
|
|
|
result.setTargetId(ext.getTargetId()); |
|
|
|
|
|
return result; |
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<GoodsAccreditExt> list2 = super.baseMapper.queryPage2(query); |
|
|
|
|
|
for (GoodsAccreditExt ext : list2) { |
|
|
|
|
|
GoodsAccreditResult result = new GoodsAccreditResult(); |
|
|
|
|
|
result.setId("supplier"+ext.getId()); |
|
|
|
|
|
result.setRuleType("supplier"); |
|
|
|
|
|
if(ext.getSaleRegionId()!=null){ |
|
|
|
|
|
result.setTargetType("saleRegion"); |
|
|
|
|
|
}else if (ext.getBizRegionId()!=null){ |
|
|
|
|
|
result.setTargetType("bizRegion"); |
|
|
|
|
|
}else { |
|
|
|
|
|
result.setTargetType("supplier"); |
|
|
|
|
|
} |
|
|
|
|
|
result.setCode(ext.getCode()); |
|
|
|
|
|
result.setName(ext.getName()); |
|
|
|
|
|
if(ext.getTargetType().equals("1")){ |
|
|
|
|
|
result.setAccType("in"); |
|
|
|
|
|
result.setGoodType("category"); |
|
|
|
|
|
}else if (ext.getTargetType().equals("2")){ |
|
|
|
|
|
result.setAccType("notIn"); |
|
|
|
|
|
result.setGoodType("category"); |
|
|
|
|
|
}else if (ext.getTargetType().equals("3")){ |
|
|
|
|
|
result.setAccType("in"); |
|
|
|
|
|
result.setGoodType("spu"); |
|
|
|
|
|
}else { |
|
|
|
|
|
result.setAccType("notIn"); |
|
|
|
|
|
result.setGoodType("spu"); |
|
|
|
|
|
} |
|
|
|
|
|
result.setTargetType(ext.getTargetType()); |
|
|
|
|
|
result.setTargetCode(ext.getTargetCode()); |
|
|
|
|
|
result.setTargetName(ext.getTargetName()); |
|
|
|
|
|
result.setTargetId(ext.getTargetId()); |
|
|
|
|
|
results.add(result); |
|
|
|
|
|
} |
|
|
|
|
|
return results; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void modify(GoodsAccreditBo param) { |
|
|
public void modify(GoodsAccreditBo param) { |
|
|
GoodsAccredit goodsAccredit = null; |
|
|
GoodsAccredit goodsAccredit = null; |
|
@ -387,7 +558,15 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go |
|
|
spuNotInIds.addAll(spuIds3); |
|
|
spuNotInIds.addAll(spuIds3); |
|
|
cateNotInIds.addAll(cateIds3); |
|
|
cateNotInIds.addAll(cateIds3); |
|
|
} |
|
|
} |
|
|
|
|
|
//无新值,直接返回空
|
|
|
|
|
|
if(skuIds.size()==1 |
|
|
|
|
|
&&spuIds.size()==1 |
|
|
|
|
|
&&cateIds.size()==1 |
|
|
|
|
|
&&skuNotInIds.size()==1 |
|
|
|
|
|
&&spuNotInIds.size()==1 |
|
|
|
|
|
&&cateNotInIds.size()==1){ |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
return new GoodsAccrIdsDto(skuIds,spuIds,cateIds,skuNotInIds,spuNotInIds,cateNotInIds); |
|
|
return new GoodsAccrIdsDto(skuIds,spuIds,cateIds,skuNotInIds,spuNotInIds,cateNotInIds); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -396,7 +575,7 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go |
|
|
if(CollUtil.isEmpty(spuIds)){ |
|
|
if(CollUtil.isEmpty(spuIds)){ |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
List<GoodsSpu> spuList = spuMapper.selectBatchIds(spuIds); |
|
|
List<GoodsSpu> spuList = goodsSpuMapper.selectBatchIds(spuIds); |
|
|
for (GoodsAccredit accredit : accreditList) { |
|
|
for (GoodsAccredit accredit : accreditList) { |
|
|
if(accredit.getSpuId()!=null){ |
|
|
if(accredit.getSpuId()!=null){ |
|
|
for (GoodsSpu spu : spuList) { |
|
|
for (GoodsSpu spu : spuList) { |
|
@ -432,6 +611,8 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go |
|
|
GoodsCategory category = categoryMapper.selectById(param.getCategoryId()); |
|
|
GoodsCategory category = categoryMapper.selectById(param.getCategoryId()); |
|
|
accredit = new GoodsAccredit(); |
|
|
accredit = new GoodsAccredit(); |
|
|
accredit.setCategoryId(category.getId().toString()); |
|
|
accredit.setCategoryId(category.getId().toString()); |
|
|
|
|
|
accredit.setCode(category.getCode()); |
|
|
|
|
|
accredit.setName(category.getName()); |
|
|
} |
|
|
} |
|
|
}else if (param.getSpuId()!=null){ |
|
|
}else if (param.getSpuId()!=null){ |
|
|
accredit = this.getOne( new LambdaQueryWrapper<GoodsAccredit>() |
|
|
accredit = this.getOne( new LambdaQueryWrapper<GoodsAccredit>() |
|
@ -440,6 +621,8 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go |
|
|
GoodsSpu spu = goodsSpuMapper.selectById(param.getSpuId()); |
|
|
GoodsSpu spu = goodsSpuMapper.selectById(param.getSpuId()); |
|
|
accredit = new GoodsAccredit(); |
|
|
accredit = new GoodsAccredit(); |
|
|
accredit.setSpuId(spu.getId()); |
|
|
accredit.setSpuId(spu.getId()); |
|
|
|
|
|
accredit.setCode(spu.getSpuCode()); |
|
|
|
|
|
accredit.setName(spu.getName()); |
|
|
} |
|
|
} |
|
|
}else if (param.getSkuId()!=null){ |
|
|
}else if (param.getSkuId()!=null){ |
|
|
accredit = this.getOne( new LambdaQueryWrapper<GoodsAccredit>() |
|
|
accredit = this.getOne( new LambdaQueryWrapper<GoodsAccredit>() |
|
@ -448,6 +631,8 @@ public class GoodsAccreditServiceImpl extends ServiceImpl<GoodsAccreditMapper,Go |
|
|
GoodsSku sku = goodsSkuMapper.selectById(param.getSkuId()); |
|
|
GoodsSku sku = goodsSkuMapper.selectById(param.getSkuId()); |
|
|
accredit = new GoodsAccredit(); |
|
|
accredit = new GoodsAccredit(); |
|
|
accredit.setSkuId(sku.getId()); |
|
|
accredit.setSkuId(sku.getId()); |
|
|
|
|
|
accredit.setCode(sku.getSkuCode()); |
|
|
|
|
|
accredit.setName(sku.getSkuName()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return accredit; |
|
|
return accredit; |
|
|