修复首次发布商品不会生成商品索引问题;代码优化;修复bug;

This commit is contained in:
paulGao 2021-12-24 14:59:38 +08:00
parent eb25827937
commit b648aa94b3
14 changed files with 152 additions and 27 deletions

View File

@ -8,7 +8,7 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.lili.event.GoodsCommentCompleteEvent;
import cn.lili.modules.distribution.entity.dos.DistributionGoods;
import cn.lili.modules.distribution.entity.dos.DistributionSelectedGoods;
import cn.lili.modules.distribution.entity.dto.DistributionGoodsSearchParams;
import cn.lili.modules.distribution.service.DistributionGoodsService;
import cn.lili.modules.distribution.service.DistributionSelectedGoodsService;
import cn.lili.modules.goods.entity.dos.*;
@ -31,8 +31,6 @@ import cn.lili.modules.search.entity.dos.EsGoodsIndex;
import cn.lili.modules.search.service.EsGoodsIndexService;
import cn.lili.modules.store.service.StoreService;
import cn.lili.rocketmq.tags.GoodsTagsEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
@ -258,7 +256,10 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
List<EsGoodsIndex> goodsIndices = new ArrayList<>();
for (Goods goods : goodsList) {
//如果商品通过审核&&并且已上架
List<GoodsSku> goodsSkuList = this.goodsSkuService.list(new LambdaQueryWrapper<GoodsSku>().eq(GoodsSku::getGoodsId, goods.getId()).gt(GoodsSku::getQuantity, 0));
GoodsSearchParams searchParams = new GoodsSearchParams();
searchParams.setGoodsId(goods.getId());
searchParams.setGeQuantity(0);
List<GoodsSku> goodsSkuList = this.goodsSkuService.getGoodsSkuByList(searchParams);
if (goods.getAuthFlag().equals(GoodsAuthEnum.PASS.name())
&& goods.getMarketEnable().equals(GoodsStatusEnum.UPPER.name())
&& Boolean.FALSE.equals(goods.getDeleteFlag())) {
@ -287,7 +288,9 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
*/
private void updateGoodsIndex(Goods goods) {
//如果商品通过审核&&并且已上架
List<GoodsSku> goodsSkuList = this.goodsSkuService.list(new LambdaQueryWrapper<GoodsSku>().eq(GoodsSku::getGoodsId, goods.getId()));
GoodsSearchParams searchParams = new GoodsSearchParams();
searchParams.setGoodsId(goods.getId());
List<GoodsSku> goodsSkuList = this.goodsSkuService.getGoodsSkuByList(searchParams);
if (goods.getAuthFlag().equals(GoodsAuthEnum.PASS.name())
&& goods.getMarketEnable().equals(GoodsStatusEnum.UPPER.name())
&& Boolean.FALSE.equals(goods.getDeleteFlag())) {
@ -373,16 +376,19 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
private void deleteGoods(MessageExt messageExt) {
Goods goods = JSONUtil.toBean(new String(messageExt.getBody()), Goods.class);
DistributionGoodsSearchParams searchParams = new DistributionGoodsSearchParams();
searchParams.setGoodsId(goods.getId());
//删除获取分销商品
DistributionGoods distributionGoods = distributionGoodsService.getOne(new LambdaQueryWrapper<DistributionGoods>()
.eq(DistributionGoods::getGoodsId, goods.getId()));
DistributionGoods distributionGoods = distributionGoodsService.getDistributionGoods(searchParams);
//删除分销商品绑定关系
distributionSelectedGoodsService.remove(new LambdaQueryWrapper<DistributionSelectedGoods>()
.eq(DistributionSelectedGoods::getDistributionGoodsId, distributionGoods.getId()));
if (distributionGoods != null) {
//删除分销商品
distributionGoodsService.removeById(distributionGoods.getId());
//删除分销商品绑定关系
distributionSelectedGoodsService.deleteByDistributionGoodsId(distributionGoods.getId());
//删除分销商品
distributionGoodsService.removeById(distributionGoods.getId());
}
}
/**
@ -421,9 +427,7 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
goods.setBuyCount(0);
}
int buyCount = goods.getBuyCount() + goodsCompleteMessage.getBuyNum();
goodsService.update(new LambdaUpdateWrapper<Goods>()
.eq(Goods::getId, goodsCompleteMessage.getGoodsId())
.set(Goods::getBuyCount, buyCount));
this.goodsService.updateGoodsBuyCount(goodsCompleteMessage.getGoodsId(), buyCount);
} else {
log.error("商品Id为[" + goodsCompleteMessage.getGoodsId() + "的商品不存在,更新商品失败!");
}

View File

@ -1,11 +1,13 @@
package cn.lili.modules.distribution.entity.dto;
import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.StringUtils;
import cn.lili.common.vo.PageVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 分销员商品查询条件
@ -13,15 +15,25 @@ import lombok.Data;
* @author pikachu
* @since 2020-03-14 23:04:56
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class DistributionGoodsSearchParams extends PageVO {
@ApiModelProperty(value = "商品ID")
private String goodsId;
@ApiModelProperty(value = "商品名称")
private String goodsName;
@ApiModelProperty(value = "是否已选择")
private boolean isChecked;
public <T> QueryWrapper<T> queryWrapper() {
QueryWrapper<T> queryWrapper = this.distributionQueryWrapper();
queryWrapper.eq(CharSequenceUtil.isNotEmpty(goodsId), "goods_id", goodsId);
queryWrapper.eq(CharSequenceUtil.isNotEmpty(goodsName), "goods_name", goodsId);
return queryWrapper;
}
public <T> QueryWrapper<T> storeQueryWrapper() {
QueryWrapper<T> queryWrapper = this.distributionQueryWrapper();

View File

@ -21,10 +21,34 @@ public interface DistributionGoodsService extends IService<DistributionGoods> {
* 根据条件分页查询分销商品信息
*
* @param distributionGoodsSearchParams 商品条件
* @return
* @return 分页分销商品信息
*/
IPage<DistributionGoodsVO> goodsPage(DistributionGoodsSearchParams distributionGoodsSearchParams);
/**
* 根据条件查询分销商品信息列表
*
* @param distributionGoodsSearchParams 条件
* @return 分销商品信息列表
*/
List<DistributionGoods> getDistributionGoodsList(DistributionGoodsSearchParams distributionGoodsSearchParams);
/**
* 根据条件查询分销商品信息
*
* @param distributionGoodsSearchParams 条件
* @return 分销商品信息
*/
DistributionGoods getDistributionGoods(DistributionGoodsSearchParams distributionGoodsSearchParams);
/**
* 根据条件删除分销商品
*
* @param distributionGoodsSearchParams 条件
*/
boolean deleteDistributionGoods(DistributionGoodsSearchParams distributionGoodsSearchParams);
/**
* 获取分销商品
*

View File

@ -23,4 +23,11 @@ public interface DistributionSelectedGoodsService extends IService<DistributionS
* @return
*/
boolean delete(String distributionGoodsId);
/**
* 分销员添加分销商品
* @param distributionGoodsId 分销商品ID
* @return
*/
boolean deleteByDistributionGoodsId(String distributionGoodsId);
}

View File

@ -70,6 +70,38 @@ public class DistributionGoodsServiceImpl extends ServiceImpl<DistributionGoodsM
return this.baseMapper.getDistributionGoodsVO(PageUtil.initPage(searchParams), searchParams.distributionQueryWrapper());
}
/**
* 根据条件查询分销商品信息列表
*
* @param distributionGoodsSearchParams 商品条件
* @return 分销商品信息列表
*/
@Override
public List<DistributionGoods> getDistributionGoodsList(DistributionGoodsSearchParams distributionGoodsSearchParams) {
return this.list(distributionGoodsSearchParams.queryWrapper());
}
/**
* 根据条件查询分销商品信息
*
* @param distributionGoodsSearchParams 条件
* @return 分销商品信息
*/
@Override
public DistributionGoods getDistributionGoods(DistributionGoodsSearchParams distributionGoodsSearchParams) {
return this.getOne(distributionGoodsSearchParams.queryWrapper(), false);
}
/**
* 根据条件删除分销商品
*
* @param distributionGoodsSearchParams 条件
*/
@Override
public boolean deleteDistributionGoods(DistributionGoodsSearchParams distributionGoodsSearchParams) {
return this.remove(distributionGoodsSearchParams.queryWrapper());
}
@Override
public DistributionGoods distributionGoodsVO(String id) {

View File

@ -46,4 +46,16 @@ public class DistributionSelectedGoodsServiceImpl extends ServiceImpl<Distributi
.eq(DistributionSelectedGoods::getDistributionGoodsId, distributionGoodsId)
.eq(DistributionSelectedGoods::getDistributionId, distributionId));
}
/**
* 分销员添加分销商品
*
* @param distributionGoodsId 商品ID
* @return
*/
@Override
public boolean deleteByDistributionGoodsId(String distributionGoodsId) {
return this.remove(new LambdaQueryWrapper<DistributionSelectedGoods>()
.eq(DistributionSelectedGoods::getDistributionGoodsId, distributionGoodsId));
}
}

View File

@ -63,7 +63,10 @@ public class GoodsSearchParams extends PageVO {
private String authFlag;
@ApiModelProperty(value = "库存数量")
private Integer quantity;
private Integer leQuantity;
@ApiModelProperty(value = "库存数量")
private Integer geQuantity;
@ApiModelProperty(value = "是否为推荐商品")
private Boolean recommend;
@ -106,8 +109,11 @@ public class GoodsSearchParams extends PageVO {
if (CharSequenceUtil.isNotEmpty(authFlag)) {
queryWrapper.eq("auth_flag", authFlag);
}
if (quantity != null) {
queryWrapper.le("quantity", quantity);
if (leQuantity != null) {
queryWrapper.le("quantity", leQuantity);
}
if (geQuantity != null) {
queryWrapper.ge("quantity", geQuantity);
}
if (recommend != null) {
queryWrapper.le("recommend", recommend);

View File

@ -147,12 +147,20 @@ public interface GoodsService extends IService<Goods> {
void updateStock(String goodsId, Integer quantity);
/**
* 更新SKU评价数量
* 更新商品评价数量
*
* @param goodsId 商品ID
*/
void updateGoodsCommentNum(String goodsId);
/**
* 更新商品的购买数量
*
* @param goodsId 商品ID
* @param buyCount 购买数量
*/
void updateGoodsBuyCount(String goodsId, int buyCount);
/**
* 批量更新商品的店铺信息
* @param store

View File

@ -406,6 +406,19 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
this.updateById(goods);
}
/**
* 更新商品的购买数量
*
* @param goodsId 商品ID
* @param buyCount 购买数量
*/
@Override
public void updateGoodsBuyCount(String goodsId, int buyCount) {
this.update(new LambdaUpdateWrapper<Goods>()
.eq(Goods::getId, goodsId)
.set(Goods::getBuyCount, buyCount));
}
@Override
public void updateStoreDetail(Store store) {
UpdateWrapper updateWrapper = new UpdateWrapper<>()

View File

@ -2,6 +2,7 @@ package cn.lili.modules.goods.serviceimpl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
@ -538,9 +539,18 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
*/
@Override
public void generateEs(Goods goods) {
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
//发送mq消息
rocketMQTemplate.asyncSend(destination, goods.getId(), RocketmqSendCallbackBuilder.commonCallback());
ThreadUtil.execAsync(() -> {
try {
// 延时执行防止商品未保存完成就去生成商品索引导致生成索引时找不到商品问题
Thread.sleep(2000);
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GENERATOR_GOODS_INDEX.name();
//发送mq消息
rocketMQTemplate.asyncSend(destination, goods.getId(), RocketmqSendCallbackBuilder.commonCallback());
} catch (InterruptedException e) {
log.error("发送商品索引信息失败!", e);
Thread.currentThread().interrupt();
}
});
}
/**

View File

@ -92,7 +92,6 @@ public class StoreDetail extends BaseIdEntity {
@ApiModelProperty(value = "营业执照号")
private String licenseNum;
@Size(min = 1, max = 200, message = "法定经营范围长度为1-200位字符")
@ApiModelProperty(value = "法定经营范围")
private String scope;

View File

@ -99,7 +99,6 @@ public class AdminStoreApplyDTO {
@ApiModelProperty(value = "营业执照号")
private String licenseNum;
@Size(min = 1, max = 200, message = "法定经营范围长度为1-200位字符")
@ApiModelProperty(value = "法定经营范围")
private String scope;

View File

@ -78,7 +78,6 @@ public class StoreEditDTO {
@ApiModelProperty(value = "营业执照号")
private String licenseNum;
@Size(min = 1, max = 200, message = "法定经营范围长度为1-200位字符")
@ApiModelProperty(value = "法定经营范围")
private String scope;

View File

@ -84,7 +84,7 @@ public class GoodsStoreController {
StoreDetail storeDetail = OperationalJudgment.judgment(storeDetailService.getStoreDetail(storeId));
Integer stockWarnNum = storeDetail.getStockWarning();
goodsSearchParams.setStoreId(storeId);
goodsSearchParams.setQuantity(stockWarnNum);
goodsSearchParams.setLeQuantity(stockWarnNum);
goodsSearchParams.setMarketEnable(GoodsStatusEnum.UPPER.name());
IPage<GoodsSku> goodsSku = goodsSkuService.getGoodsSkuByPage(goodsSearchParams);
StockWarningVO stockWarning = new StockWarningVO(stockWarnNum, goodsSku);