Browse Source

feat: 添加下单商品规则,查询拦截

checkBack
Yen 1 year ago
parent
commit
cf8af5352a
  1. 7
      src/main/java/com/qs/serve/Application.java
  2. 6
      src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java
  3. 88
      src/main/java/com/qs/serve/modules/goods/service/impl/GoodsAccreditServiceImpl.java
  4. 7
      src/main/java/com/qs/serve/modules/oms/service/impl/OmsOrderServiceImpl.java

7
src/main/java/com/qs/serve/Application.java

@ -42,7 +42,12 @@ public class Application extends SpringBootServletInitializer {
SpringApplication.run(Application.class,args);
long end = System.currentTimeMillis();
double diff = (end-start)/1000.0;
System.out.println("启动时间:"+diff);
System.out.println("启动时间:"+diff+"\n ____ _ _ __ _ _ \n" +
" / ___| | |_ __ _ _ __ | |_ _ _ _ __ ___ _ _ ___ ___ ___ ___ ___ / _| _ _ | || |\n" +
" \\___ \\ | __|/ _` || '__|| __| | | | || '_ \\ / __|| | | | / __|/ __|/ _ \\/ __|/ __|| |_ | | | || || |\n" +
" ___) || |_| (_| || | | |_ | |_| || |_) | \\__ \\| |_| || (__| (__| __/\\__ \\\\__ \\| _|| |_| || ||_|\n" +
" |____/ \\__|\\__,_||_| \\__| \\__,_|| .__/ |___/ \\__,_| \\___|\\___|\\___||___/|___/|_| \\__,_||_|(_)\n" +
" |_| \n");
}
@Override

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

@ -156,9 +156,10 @@ public class GoodsSpuController {
private void tiSetSpuParam2(GoodsSpu param, BmsSupplier supplier) {
List<GoodsAccredit> goodsAccreditList = goodsAccreditService
.listIgnoreAcc(supplier.getId(), supplier.listBizRegionIds(), supplier.listSaleRegionIds());
Set<Long> spuIds = goodsAccreditList.stream().map(GoodsAccredit::getSpuId).collect(Collectors.toSet());
Set<String> cateIds = goodsAccreditList.stream().map(GoodsAccredit::getCategoryId).collect(Collectors.toSet());
Set<Long> spuIds = goodsAccreditList.stream().map(GoodsAccredit::getSpuId).filter(Objects::nonNull).collect(Collectors.toSet());
Set<String> cateIds = goodsAccreditList.stream().map(GoodsAccredit::getCategoryId).filter(Objects::nonNull).collect(Collectors.toSet());
if(CollUtil.isNotEmpty(cateIds)){
log.debug("SelectNotIntCateIds() {}",JsonUtil.objectToJson(cateIds));
if(CollUtil.isEmpty(param.getSelectNotIntCateIds())){
param.setSelectNotIntCateIds(new ArrayList<>(cateIds));
}else{
@ -166,6 +167,7 @@ public class GoodsSpuController {
}
}
if(CollUtil.isNotEmpty(spuIds)){
log.debug("getSelectNotInIds() {}",JsonUtil.objectToJson(spuIds));
if (CollUtil.isEmpty(param.getSelectNotInIds())){
param.setSelectNotInIds(new ArrayList<>(spuIds));
}else{

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

@ -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());
}

7
src/main/java/com/qs/serve/modules/oms/service/impl/OmsOrderServiceImpl.java

@ -239,8 +239,9 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
if(categoryRule!=null){
order.setBrandRuleName(categoryRule.getLabel());
}
BmsSupplier supplier = null;
if(param.getSupplierId()!=null && !param.getSupplierId().equals(order.getSupplierId())){
BmsSupplier supplier = bmsSupplierMapper.selectById(param.getSupplierId());
supplier = bmsSupplierMapper.selectById(param.getSupplierId());
order.setSupplierId(param.getSupplierId());
order.setSupplierName(supplier.getSupplierName());
order.setSupplierCode(supplier.getSupplierCode());
@ -328,7 +329,9 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
List<String> skuCodes = newOrderItemList.stream().map(OmsOrderItem::getSkuCode).collect(Collectors.toList());
//拦截商品授权维度规则
//goodsAccreditService.listAcc()
if(supplier!=null){
goodsAccreditService.listIgnoreAcc(supplier.getId(),supplier.getSelectBizRegionIds(),supplier.getSelectSaleRegionIds());
}
//拦截客户维度规则
goodsRuleService.checkSkuCode(skuCodes,goodsRuleService.listBySupplierId(order.getSupplierId().toString()),true);

Loading…
Cancel
Save