!314 fix & improve

Merge pull request !314 from OceansDeep/pg
This commit is contained in:
OceansDeep 2023-10-24 06:42:40 +00:00 committed by Gitee
commit e6fe055cd5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 41 additions and 44 deletions

View File

@ -6,6 +6,7 @@ import cn.lili.common.exception.ServiceException;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.goods.entity.dos.Goods;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
import cn.lili.modules.goods.entity.vos.GoodsVO;
import cn.lili.modules.goods.service.GoodsService;
@ -101,6 +102,12 @@ public class GoodsBuyerController {
return ResultUtil.data(goodsService.queryByParams(goodsSearchParams));
}
@ApiOperation(value = "获取商品sku列表")
@GetMapping("/sku")
public ResultMessage<List<GoodsSku>> getSkuByPage(GoodsSearchParams goodsSearchParams) {
return ResultUtil.data(goodsSkuService.getGoodsSkuByList(goodsSearchParams));
}
@ApiOperation(value = "从ES中获取商品信息")
@GetMapping("/es")
public ResultMessage<Page<EsGoodsIndex>> getGoodsByPageFromEs(EsGoodsSearchDTO goodsSearchParams, PageVO pageVO) {

View File

@ -7,6 +7,7 @@ import cn.lili.event.GoodsCommentCompleteEvent;
import cn.lili.event.StoreSettingChangeEvent;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
import cn.lili.modules.goods.service.GoodsService;
import cn.lili.modules.goods.service.GoodsSkuService;
import cn.lili.modules.member.entity.dos.MemberEvaluation;
import cn.lili.modules.store.entity.dos.Store;
@ -31,12 +32,15 @@ public class GoodsSkuExecute implements GoodsCommentCompleteEvent, StoreSettingC
@Autowired
private GoodsSkuService goodsSkuService;
@Autowired
private GoodsService goodsService;
@Autowired
private Cache cache;
@Override
public void goodsComment(MemberEvaluation memberEvaluation) {
goodsSkuService.updateGoodsSkuCommentNum(memberEvaluation.getSkuId());
goodsService.updateGoodsCommentNum(memberEvaluation.getGoodsId(), memberEvaluation.getSkuId());
}
@Override

View File

@ -101,6 +101,9 @@ public class GoodsSearchParams extends PageVO {
if (CharSequenceUtil.isNotEmpty(id)) {
queryWrapper.in("id", Arrays.asList(id.split(",")));
}
if (CollUtil.isNotEmpty(ids)) {
queryWrapper.in("id", ids);
}
if (CharSequenceUtil.isNotEmpty(storeId)) {
queryWrapper.eq("store_id", storeId);
}

View File

@ -211,13 +211,6 @@ public interface GoodsSkuService extends IService<GoodsSku> {
*/
void updateGoodsStock(List<GoodsSku> goodsSkus);
/**
* 更新SKU评价数量
*
* @param skuId SKUId
*/
void updateGoodsSkuCommentNum(String skuId);
/**
* 根据商品id获取全部skuId的集合
*
@ -261,9 +254,10 @@ public interface GoodsSkuService extends IService<GoodsSku> {
/**
* 更新商品sku评分
*
* @param goodsId goodsId
* @param skuId skuId
* @param grade 评分
* @param commentNum 评论数量
*/
void updateGoodsSkuGrade(String skuId, double grade,int commentNum);
void updateGoodsSkuGrade(String goodsId, String skuId, double grade,int commentNum);
}

View File

@ -14,10 +14,7 @@ import cn.lili.common.properties.RocketmqCustomProperties;
import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.security.enums.UserEnums;
import cn.lili.modules.goods.entity.dos.Category;
import cn.lili.modules.goods.entity.dos.Goods;
import cn.lili.modules.goods.entity.dos.GoodsGallery;
import cn.lili.modules.goods.entity.dos.Wholesale;
import cn.lili.modules.goods.entity.dos.*;
import cn.lili.modules.goods.entity.dto.GoodsOperationDTO;
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
@ -444,11 +441,20 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateGoodsCommentNum(String goodsId, String skuId) {
GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(skuId);
if (goodsSku == null) {
return;
}
//获取商品信息
Goods goods = this.getById(goodsId);
if (goods == null) {
return;
}
//修改商品评价数量
long commentNum = memberEvaluationService.getEvaluationCount(EvaluationQueryParams.builder().goodsId(goodsId).status("OPEN").build());
goods.setCommentNum((int) (commentNum));
@ -458,10 +464,18 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
//好评率
double grade = NumberUtil.mul(NumberUtil.div(highPraiseNum, goods.getCommentNum().doubleValue(), 2), 100);
goods.setGrade(grade);
this.updateById(goods);
LambdaUpdateWrapper<Goods> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(Goods::getId, goodsId);
updateWrapper.set(Goods::getCommentNum, goods.getCommentNum());
updateWrapper.set(Goods::getGrade, goods.getGrade());
this.update(updateWrapper);
cache.remove(CachePrefix.GOODS.getPrefix() + goodsId);
// 修改商品sku评价数量
this.goodsSkuService.updateGoodsSkuGrade(goodsId, skuId, grade, goods.getCommentNum());
Map<String, Object> updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap(MapUtil.builder(new HashMap<String, Object>()).put("id", skuId).build(), MapUtil.builder(new HashMap<String, Object>()).put("commentNum", goods.getCommentNum()).put("highPraiseNum", highPraiseNum).put("grade", grade).build());
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("更新商品索引信息", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name(), JSONUtil.toJsonStr(updateIndexFieldsMap)));
}

View File

@ -1,7 +1,6 @@
package cn.lili.modules.goods.serviceimpl;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.lili.cache.Cache;
@ -36,8 +35,6 @@ import cn.lili.modules.goods.service.WholesaleService;
import cn.lili.modules.goods.sku.GoodsSkuBuilder;
import cn.lili.modules.goods.sku.render.SalesModelRender;
import cn.lili.modules.member.entity.dos.FootPrint;
import cn.lili.modules.member.entity.dto.EvaluationQueryParams;
import cn.lili.modules.member.entity.enums.EvaluationGradeEnum;
import cn.lili.modules.member.service.MemberEvaluationService;
import cn.lili.modules.promotion.entity.dos.Coupon;
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
@ -604,30 +601,6 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateGoodsSkuCommentNum(String skuId) {
//获取商品信息
GoodsSku goodsSku = this.getGoodsSkuByIdFromCache(skuId);
//好评数量
long highPraiseNum = memberEvaluationService.getEvaluationCount(EvaluationQueryParams.builder().status("OPEN").grade(EvaluationGradeEnum.GOOD.name()).skuId(skuId).build());
//更新商品评价数量
long commentNum = memberEvaluationService.getEvaluationCount(EvaluationQueryParams.builder().status("OPEN").skuId(skuId).build());
goodsSku.setCommentNum((int) commentNum);
//好评率
double grade = NumberUtil.mul(NumberUtil.div(highPraiseNum, goodsSku.getCommentNum().doubleValue(), 2), 100);
goodsSku.setGrade(grade);
//修改规格
this.updateGoodsSkuGrade(skuId, grade, goodsSku.getCommentNum());
//修改商品的评价数量
goodsService.updateGoodsCommentNum(goodsSku.getGoodsId(), skuId);
clearCache(skuId);
}
/**
* 根据商品id获取全部skuId的集合
*
@ -686,12 +659,13 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
}
@Override
public void updateGoodsSkuGrade(String skuId, double grade, int commentNum) {
public void updateGoodsSkuGrade(String goodsId, String skuId, double grade, int commentNum) {
LambdaUpdateWrapper<GoodsSku> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(GoodsSku::getId, skuId);
updateWrapper.eq(GoodsSku::getGoodsId, goodsId);
updateWrapper.set(GoodsSku::getGrade, grade);
updateWrapper.set(GoodsSku::getCommentNum, commentNum);
this.update(updateWrapper);
clearCache(skuId);
}
/**

View File

@ -1,5 +1,6 @@
package cn.lili.modules.promotion.serviceimpl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.json.JSONObject;
@ -109,7 +110,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl<PromotionGoodsMapper,
queryWrapper.and(i -> i.or(j -> j.in(SKU_ID_COLUMN, skuIds))
.or(n -> n.eq("scope_type", PromotionsScopeTypeEnum.ALL.name()))
.or(n -> n.and(k -> k.eq("scope_type", PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name())
.and(l -> l.in("scope_id", categoriesPath)))));
.and(l -> l.in(CollUtil.isNotEmpty(categoriesPath), "scope_id", categoriesPath)))));
queryWrapper.and(i -> i.or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)).or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.NEW)));
return this.list(queryWrapper);
}