|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.zhongzheng.common.core.redis.RedisCache;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.common.utils.ServletUtils;
|
|
@@ -49,6 +50,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -85,6 +87,8 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
private IDistributionRebateService iDistributionRebateService;
|
|
|
@Autowired
|
|
|
private IDistributionSellerService iDistributionSellerService;
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
|
|
|
@Override
|
|
|
public DistributionActivityVo queryById(Long distributionId) {
|
|
@@ -329,72 +333,44 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean pullGoods(Long distributionId) {
|
|
|
- DistributionActivity activity = getById(distributionId);
|
|
|
- if (ObjectUtils.isNull(activity.getTempId())) {
|
|
|
- //不是总平台下发的活动
|
|
|
- return true;
|
|
|
- }
|
|
|
- //总平台下发活动对比商品是否缺失
|
|
|
- List<DistributionActivityGoods> activityGoods = iDistributionActivityGoodsService
|
|
|
- .list(new LambdaQueryWrapper<DistributionActivityGoods>()
|
|
|
- .eq(DistributionActivityGoods::getDistributionId, activity.getDistributionId())
|
|
|
- .eq(DistributionActivityGoods::getStatus, 1));
|
|
|
- List<DistributionActivityTemplateGoods> templateGoods = iDistributionActivityTemplateGoodsService.getListEntity(activity.getTempId());
|
|
|
- if (activityGoods.size() == templateGoods.size()) {
|
|
|
- //不缺失商品信息
|
|
|
- return true;
|
|
|
+ String key = "GOODS_PULL";
|
|
|
+ Object object = redisCache.getCacheObject(key);
|
|
|
+ if (ObjectUtils.isNotNull(object)) {
|
|
|
+ throw new CustomException("存在商品正在拉取中,请稍后重试!");
|
|
|
}
|
|
|
- if (CollectionUtils.isEmpty(templateGoods)) {
|
|
|
- //总平台活动商品没有
|
|
|
- return true;
|
|
|
- }
|
|
|
- DistributionActivityTemplate activityTemplate = iDistributionActivityTemplateService.getEntityById(activity.getTempId());
|
|
|
- Long tenantId = Long.valueOf(ServletUtils.getRequest().getHeader("TenantId"));
|
|
|
- if (CollectionUtils.isEmpty(activityGoods)) {
|
|
|
- //全部缺失
|
|
|
- List<TopGoods> topGoods = iTopGoodsService.listEntityByIds(templateGoods.stream().map(DistributionActivityTemplateGoods::getGoodsId).collect(Collectors.toList()));
|
|
|
- GoodsPullTenantBo bo = new GoodsPullTenantBo();
|
|
|
- bo.setGoodsList(topGoods);
|
|
|
- bo.setTenantId(tenantId);
|
|
|
- List<GoodsPullResultBo> result = iDistributionActivityGoodsService.pullGoods(bo);
|
|
|
- //添加关联关系
|
|
|
- List<ActivityGoodsPrice> goodsPriceList = new ArrayList<>();
|
|
|
- List<DistributionActivityGoods> distributionActivityGo = templateGoods.stream().map(item -> {
|
|
|
- DistributionActivityGoods activityGo = BeanUtil.toBean(item, DistributionActivityGoods.class);
|
|
|
- activityGo.setTenantId(tenantId);
|
|
|
- activityGo.setDistributionId(distributionId);
|
|
|
- GoodsPullResultBo pul = result.stream().filter(x -> x.getOldGoodsId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
- if (ObjectUtils.isNotNull(pul)) {
|
|
|
- activityGo.setGoodsId(pul.getNewGoodsId());
|
|
|
- //商品活动价格
|
|
|
- TopActivityGoodsPrice topGoodsPrice = iTopActivityGoodsPriceService.getEntity(item.getGoodsId(), activityTemplate.getCode());
|
|
|
- if (ObjectUtils.isNotNull(topGoodsPrice)) {
|
|
|
- ActivityGoodsPrice goodsPrice = BeanUtil.toBean(topGoodsPrice, ActivityGoodsPrice.class);
|
|
|
- goodsPrice.setGoodsId(pul.getNewGoodsId());
|
|
|
- goodsPrice.setTenantId(tenantId);
|
|
|
- goodsPriceList.add(goodsPrice);
|
|
|
- }
|
|
|
- }
|
|
|
- return activityGo;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- iDistributionActivityGoodsService.saveBatch(distributionActivityGo);
|
|
|
- iActivityGoodsPriceService.saveBatch(goodsPriceList);
|
|
|
- } else {
|
|
|
- //部分缺失
|
|
|
- List<Goods> goodsList = iGoodsService.listByIds(activityGoods.stream().map(DistributionActivityGoods::getGoodsId).collect(Collectors.toList()));
|
|
|
- List<TopGoods> topGoods = iTopGoodsService.listEntityByIds(templateGoods.stream().map(DistributionActivityTemplateGoods::getGoodsId).collect(Collectors.toList()));
|
|
|
- List<String> codes = goodsList.stream().map(Goods::getCode).collect(Collectors.toList());
|
|
|
- List<TopGoods> goods = topGoods.stream().filter(item -> !codes.contains(item.getCode())).collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isNotEmpty(goods)) {
|
|
|
+ try {
|
|
|
+ redisCache.setCacheObject(key, DateUtils.getNowTime(), 30, TimeUnit.MINUTES);
|
|
|
+ DistributionActivity activity = getById(distributionId);
|
|
|
+ if (ObjectUtils.isNull(activity.getTempId())) {
|
|
|
+ //不是总平台下发的活动
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ //总平台下发活动对比商品是否缺失
|
|
|
+ List<DistributionActivityGoods> activityGoods = iDistributionActivityGoodsService
|
|
|
+ .list(new LambdaQueryWrapper<DistributionActivityGoods>()
|
|
|
+ .eq(DistributionActivityGoods::getDistributionId, activity.getDistributionId())
|
|
|
+ .eq(DistributionActivityGoods::getStatus, 1));
|
|
|
+ List<DistributionActivityTemplateGoods> templateGoods = iDistributionActivityTemplateGoodsService.getListEntity(activity.getTempId());
|
|
|
+ if (activityGoods.size() == templateGoods.size()) {
|
|
|
+ //不缺失商品信息
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(templateGoods)) {
|
|
|
+ //总平台活动商品没有
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ DistributionActivityTemplate activityTemplate = iDistributionActivityTemplateService.getEntityById(activity.getTempId());
|
|
|
+ Long tenantId = Long.valueOf(ServletUtils.getRequest().getHeader("TenantId"));
|
|
|
+ if (CollectionUtils.isEmpty(activityGoods)) {
|
|
|
+ //全部缺失
|
|
|
+ List<TopGoods> topGoods = iTopGoodsService.listEntityByIds(templateGoods.stream().map(DistributionActivityTemplateGoods::getGoodsId).collect(Collectors.toList()));
|
|
|
GoodsPullTenantBo bo = new GoodsPullTenantBo();
|
|
|
- bo.setGoodsList(goods);
|
|
|
+ bo.setGoodsList(topGoods);
|
|
|
bo.setTenantId(tenantId);
|
|
|
List<GoodsPullResultBo> result = iDistributionActivityGoodsService.pullGoods(bo);
|
|
|
- List<Long> ids = goods.stream().map(TopGoods::getGoodsId).collect(Collectors.toList());
|
|
|
//添加关联关系
|
|
|
List<ActivityGoodsPrice> goodsPriceList = new ArrayList<>();
|
|
|
- List<DistributionActivityTemplateGoods> collect = templateGoods.stream().filter(x -> ids.contains(x.getGoodsId())).collect(Collectors.toList());
|
|
|
- List<DistributionActivityGoods> distributionActivityGo = collect.stream().map(item -> {
|
|
|
+ List<DistributionActivityGoods> distributionActivityGo = templateGoods.stream().map(item -> {
|
|
|
DistributionActivityGoods activityGo = BeanUtil.toBean(item, DistributionActivityGoods.class);
|
|
|
activityGo.setTenantId(tenantId);
|
|
|
activityGo.setDistributionId(distributionId);
|
|
@@ -414,7 +390,49 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
}).collect(Collectors.toList());
|
|
|
iDistributionActivityGoodsService.saveBatch(distributionActivityGo);
|
|
|
iActivityGoodsPriceService.saveBatch(goodsPriceList);
|
|
|
+ } else {
|
|
|
+ //部分缺失
|
|
|
+ List<Goods> goodsList = iGoodsService.listByIds(activityGoods.stream().map(DistributionActivityGoods::getGoodsId).collect(Collectors.toList()));
|
|
|
+ List<TopGoods> topGoods = iTopGoodsService.listEntityByIds(templateGoods.stream().map(DistributionActivityTemplateGoods::getGoodsId).collect(Collectors.toList()));
|
|
|
+ List<String> codes = goodsList.stream().map(Goods::getCode).collect(Collectors.toList());
|
|
|
+ List<TopGoods> goods = topGoods.stream().filter(item -> !codes.contains(item.getCode())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(goods)) {
|
|
|
+ GoodsPullTenantBo bo = new GoodsPullTenantBo();
|
|
|
+ bo.setGoodsList(goods);
|
|
|
+ bo.setTenantId(tenantId);
|
|
|
+ List<GoodsPullResultBo> result = iDistributionActivityGoodsService.pullGoods(bo);
|
|
|
+ List<Long> ids = goods.stream().map(TopGoods::getGoodsId).collect(Collectors.toList());
|
|
|
+ //添加关联关系
|
|
|
+ List<ActivityGoodsPrice> goodsPriceList = new ArrayList<>();
|
|
|
+ List<DistributionActivityTemplateGoods> collect = templateGoods.stream().filter(x -> ids.contains(x.getGoodsId())).collect(Collectors.toList());
|
|
|
+ List<DistributionActivityGoods> distributionActivityGo = collect.stream().map(item -> {
|
|
|
+ DistributionActivityGoods activityGo = BeanUtil.toBean(item, DistributionActivityGoods.class);
|
|
|
+ activityGo.setTenantId(tenantId);
|
|
|
+ activityGo.setDistributionId(distributionId);
|
|
|
+ GoodsPullResultBo pul = result.stream().filter(x -> x.getOldGoodsId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtils.isNotNull(pul)) {
|
|
|
+ activityGo.setGoodsId(pul.getNewGoodsId());
|
|
|
+ //商品活动价格
|
|
|
+ TopActivityGoodsPrice topGoodsPrice = iTopActivityGoodsPriceService.getEntity(item.getGoodsId(), activityTemplate.getCode());
|
|
|
+ if (ObjectUtils.isNotNull(topGoodsPrice)) {
|
|
|
+ ActivityGoodsPrice goodsPrice = BeanUtil.toBean(topGoodsPrice, ActivityGoodsPrice.class);
|
|
|
+ goodsPrice.setGoodsId(pul.getNewGoodsId());
|
|
|
+ goodsPrice.setTenantId(tenantId);
|
|
|
+ goodsPriceList.add(goodsPrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return activityGo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ iDistributionActivityGoodsService.saveBatch(distributionActivityGo);
|
|
|
+ iActivityGoodsPriceService.saveBatch(goodsPriceList);
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("商品增量报错:" + e.getMessage());
|
|
|
+ }finally {
|
|
|
+ //释放
|
|
|
+ redisCache.deleteObject(key);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -468,7 +486,7 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
orderVos.forEach(item -> {
|
|
|
- if (item.getCashType() == 1){
|
|
|
+ if (item.getCashType() == 1) {
|
|
|
//百分比
|
|
|
item.setCashRatio(item.getCashRatio().multiply(new BigDecimal("100.00")));
|
|
|
}
|
|
@@ -478,7 +496,7 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
.eq(DistributionCashLog::getSellerId, item.getSellerId())
|
|
|
.eq(DistributionCashLog::getRelatedSn, item.getOrderSn())
|
|
|
.last("limit 1"));
|
|
|
- if (ObjectUtils.isNotNull(cashLog) && item.getCashStatus() == 3 ) {
|
|
|
+ if (ObjectUtils.isNotNull(cashLog) && item.getCashStatus() == 3) {
|
|
|
item.setCashStatus(cashLog.getType() > 1 ? 2 : 1);
|
|
|
}
|
|
|
});
|
|
@@ -510,10 +528,10 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
cashVo.setCashStatus(rebate.getCashStatus());
|
|
|
cashVo.setCashTime(rebate.getCreateTime());
|
|
|
cashVo.setCashType(rebate.getProfitType());
|
|
|
- if (rebate.getProfitType() == 1){
|
|
|
+ if (rebate.getProfitType() == 1) {
|
|
|
//百分比
|
|
|
cashVo.setCashRatio(rebate.getProfit().multiply(new BigDecimal("100.00")));
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
cashVo.setCashRatio(rebate.getProfit());
|
|
|
}
|
|
|
DistributionSeller seller = iDistributionSellerService.getById(rebate.getSellerId());
|
|
@@ -532,7 +550,7 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
if (ObjectUtils.isNull(orderVo)) {
|
|
|
return null;
|
|
|
}
|
|
|
- if (orderVo.getCashType() == 1){
|
|
|
+ if (orderVo.getCashType() == 1) {
|
|
|
//百分比
|
|
|
orderVo.setCashRatio(orderVo.getCash().multiply(new BigDecimal("100.00")));
|
|
|
}
|
|
@@ -543,7 +561,7 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
.eq(DistributionCashLog::getRelatedSn, orderVo.getOrderSn())
|
|
|
.last("limit 1"));
|
|
|
if (ObjectUtils.isNotNull(cashLog) &&
|
|
|
- orderVo.getCashStatus() == 3 ) {
|
|
|
+ orderVo.getCashStatus() == 3) {
|
|
|
orderVo.setCashStatus(cashLog.getType() > 1 ? 2 : 1);
|
|
|
}
|
|
|
return orderVo;
|
|
@@ -552,22 +570,22 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
@Override
|
|
|
public List<DistributionCashVo> getCashList(DistributionCashQueryBo bo) {
|
|
|
List<DistributionCashVo> cashVoList = baseMapper.getCashList(bo);
|
|
|
- if (CollectionUtils.isEmpty(cashVoList)){
|
|
|
+ if (CollectionUtils.isEmpty(cashVoList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
- if (ObjectUtils.isNotNull(bo.getStartTime()) && ObjectUtils.isNotNull(bo.getEndTime())){
|
|
|
+ if (ObjectUtils.isNotNull(bo.getStartTime()) && ObjectUtils.isNotNull(bo.getEndTime())) {
|
|
|
cashVoList.forEach(item -> {
|
|
|
//总佣金
|
|
|
List<DistributionRebate> list = iDistributionRebateService
|
|
|
.list(new LambdaQueryWrapper<DistributionRebate>()
|
|
|
- .eq(DistributionRebate::getSellerId, item.getSellerId())
|
|
|
- .ne(DistributionRebate::getCashStatus, 3)
|
|
|
- .ge(DistributionRebate::getCreateTime, bo.getStartTime())
|
|
|
- .le(DistributionRebate::getCreateTime, bo.getEndTime()));
|
|
|
- if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ .eq(DistributionRebate::getSellerId, item.getSellerId())
|
|
|
+ .ne(DistributionRebate::getCashStatus, 3)
|
|
|
+ .ge(DistributionRebate::getCreateTime, bo.getStartTime())
|
|
|
+ .le(DistributionRebate::getCreateTime, bo.getEndTime()));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
BigDecimal reduce = list.stream().map(DistributionRebate::getCash).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
item.setCashTotal(reduce);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
item.setCashTotal(new BigDecimal("0.00"));
|
|
|
}
|
|
|
});
|
|
@@ -614,10 +632,10 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
@Override
|
|
|
public List<DistributionCashTopVo> getOrgCashList(DistributionCashTopQueryBo bo) {
|
|
|
List<DistributionCashTopVo> cashVoList = baseMapper.getOrgCashList(bo);
|
|
|
- if (CollectionUtils.isEmpty(cashVoList)){
|
|
|
+ if (CollectionUtils.isEmpty(cashVoList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
- if (ObjectUtils.isNotNull(bo.getStartTime()) && ObjectUtils.isNotNull(bo.getEndTime())){
|
|
|
+ if (ObjectUtils.isNotNull(bo.getStartTime()) && ObjectUtils.isNotNull(bo.getEndTime())) {
|
|
|
cashVoList.forEach(item -> {
|
|
|
//总佣金
|
|
|
List<DistributionRebate> list = iDistributionRebateService
|
|
@@ -626,10 +644,10 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
.ne(DistributionRebate::getCashStatus, 3)
|
|
|
.ge(DistributionRebate::getCreateTime, bo.getStartTime())
|
|
|
.le(DistributionRebate::getCreateTime, bo.getEndTime()));
|
|
|
- if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
BigDecimal reduce = list.stream().map(DistributionRebate::getCash).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
item.setCashTotal(reduce);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
item.setCashTotal(new BigDecimal("0.00"));
|
|
|
}
|
|
|
});
|
|
@@ -644,7 +662,7 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
orderVos.forEach(item -> {
|
|
|
- if (item.getCashType() == 1){
|
|
|
+ if (item.getCashType() == 1) {
|
|
|
//百分比
|
|
|
item.setCashRatio(item.getCashRatio().multiply(new BigDecimal("100.00")));
|
|
|
}
|
|
@@ -654,7 +672,7 @@ public class DistributionActivityServiceImpl extends ServiceImpl<DistributionAct
|
|
|
.eq(DistributionCashLog::getSellerId, item.getSellerId())
|
|
|
.eq(DistributionCashLog::getRelatedSn, item.getOrderSn())
|
|
|
.last("limit 1"));
|
|
|
- if (ObjectUtils.isNotNull(cashLog) && item.getCashStatus() == 3 ) {
|
|
|
+ if (ObjectUtils.isNotNull(cashLog) && item.getCashStatus() == 3) {
|
|
|
item.setCashStatus(cashLog.getType() > 1 ? 2 : 1);
|
|
|
}
|
|
|
});
|