!42 更新更改商品索引部分字段的方式。新增参数组名称修改后,同步到参数组下所有参数。
Merge pull request !42 from OceansDeep/feature/pg
This commit is contained in:
commit
2bf232b5fd
@ -1,9 +1,11 @@
|
||||
package cn.lili.listener;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||
import cn.lili.event.GoodsCommentCompleteEvent;
|
||||
import cn.lili.modules.distribution.entity.dos.DistributionGoods;
|
||||
import cn.lili.modules.distribution.entity.dos.DistributionSelectedGoods;
|
||||
@ -27,9 +29,11 @@ import cn.lili.modules.member.service.FootprintService;
|
||||
import cn.lili.modules.member.service.GoodsCollectionService;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.search.service.EsGoodsIndexService;
|
||||
import cn.lili.modules.search.utils.EsIndexUtil;
|
||||
import cn.lili.modules.store.entity.dos.StoreGoodsLabel;
|
||||
import cn.lili.modules.store.service.StoreGoodsLabelService;
|
||||
import cn.lili.modules.store.service.StoreService;
|
||||
import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
|
||||
import cn.lili.rocketmq.tags.GoodsTagsEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
@ -37,6 +41,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.common.message.MessageExt;
|
||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
||||
import org.apache.rocketmq.spring.core.RocketMQListener;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -117,6 +122,17 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
||||
@Autowired
|
||||
private StoreGoodsLabelService storeGoodsLabelService;
|
||||
|
||||
/**
|
||||
* rocketMq
|
||||
*/
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
/**
|
||||
* rocketMq配置
|
||||
*/
|
||||
@Autowired
|
||||
private RocketmqCustomProperties rocketmqCustomProperties;
|
||||
|
||||
@Override
|
||||
public void onMessage(MessageExt messageExt) {
|
||||
|
||||
@ -396,6 +412,13 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
||||
int buyCount = goodsSku.getBuyCount() + goodsCompleteMessage.getBuyNum();
|
||||
goodsSku.setBuyCount(buyCount);
|
||||
goodsSkuService.update(goodsSku);
|
||||
|
||||
//修改规格索引,发送mq消息
|
||||
Map<String, Object> updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap(
|
||||
MapUtil.builder().put("id", goodsCompleteMessage.getSkuId()).build(),
|
||||
MapUtil.builder().put("buyCount", buyCount).build());
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name();
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap), RocketmqSendCallbackBuilder.commonCallback());
|
||||
goodsIndexService.updateIndex(goodsCompleteMessage.getSkuId(), new EsGoodsIndex().setBuyCount(buyCount));
|
||||
} else {
|
||||
log.error("商品SkuId为[" + goodsCompleteMessage.getGoodsId() + "的商品不存在,更新商品失败!");
|
||||
|
@ -27,6 +27,14 @@ public interface GoodsService extends IService<Goods> {
|
||||
*/
|
||||
void underStoreGoods(String storeId);
|
||||
|
||||
/**
|
||||
* 更新商品参数
|
||||
*
|
||||
* @param goodsId 商品id
|
||||
* @param params 商品参数
|
||||
*/
|
||||
void updateGoodsParams(String goodsId, String params);
|
||||
|
||||
/**
|
||||
* 获取某分类下的商品数量
|
||||
*
|
||||
|
@ -3,8 +3,6 @@ package cn.lili.modules.goods.serviceimpl;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.modules.goods.service.CategoryService;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import cn.lili.modules.goods.entity.dos.Brand;
|
||||
import cn.lili.modules.goods.entity.dos.CategoryBrand;
|
||||
import cn.lili.modules.goods.entity.dto.BrandPageDTO;
|
||||
@ -12,6 +10,8 @@ import cn.lili.modules.goods.entity.vos.BrandVO;
|
||||
import cn.lili.modules.goods.mapper.BrandMapper;
|
||||
import cn.lili.modules.goods.service.BrandService;
|
||||
import cn.lili.modules.goods.service.CategoryBrandService;
|
||||
import cn.lili.modules.goods.service.CategoryService;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -96,9 +96,7 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements
|
||||
|
||||
@Override
|
||||
public void deleteBrands(List<String> ids) {
|
||||
ids.forEach(id -> {
|
||||
checkoutCategory(id);
|
||||
});
|
||||
ids.forEach(this::checkoutCategory);
|
||||
this.removeByIds(ids);
|
||||
}
|
||||
|
||||
@ -112,9 +110,7 @@ public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements
|
||||
//分了绑定关系查询
|
||||
List<CategoryBrand> categoryBrands = categoryBrandService.getCategoryBrandListByBrandId(brandId);
|
||||
if (!categoryBrands.isEmpty()) {
|
||||
List<String> brandIds = categoryBrands.stream().map(categoryBrand -> {
|
||||
return categoryBrand.getCategoryId();
|
||||
}).collect(Collectors.toList());
|
||||
List<String> brandIds = categoryBrands.stream().map(CategoryBrand::getCategoryId).collect(Collectors.toList());
|
||||
throw new ServiceException(ResultCode.BRAND_USE_DISABLE_ERROR,
|
||||
JSONUtil.toJsonStr(categoryService.getCategoryNameByIds(brandIds)));
|
||||
}
|
||||
|
@ -1,17 +1,23 @@
|
||||
package cn.lili.modules.goods.serviceimpl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.modules.goods.entity.dos.CategoryBrand;
|
||||
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||
import cn.lili.modules.goods.entity.dos.CategoryParameterGroup;
|
||||
import cn.lili.modules.goods.entity.dos.Goods;
|
||||
import cn.lili.modules.goods.entity.dos.Parameters;
|
||||
import cn.lili.modules.goods.entity.dto.GoodsParamsDTO;
|
||||
import cn.lili.modules.goods.entity.vos.ParameterGroupVO;
|
||||
import cn.lili.modules.goods.mapper.CategoryParameterGroupMapper;
|
||||
import cn.lili.modules.goods.service.CategoryParameterGroupService;
|
||||
import cn.lili.modules.goods.service.GoodsService;
|
||||
import cn.lili.modules.goods.service.ParametersService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -20,6 +26,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 分类绑定参数组接口实现
|
||||
@ -38,6 +45,15 @@ public class CategoryParameterGroupServiceImpl extends ServiceImpl<CategoryParam
|
||||
@Autowired
|
||||
private ParametersService parametersService;
|
||||
|
||||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
|
||||
@Autowired
|
||||
private RocketmqCustomProperties rocketmqCustomProperties;
|
||||
|
||||
@Autowired
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
@Override
|
||||
public List<ParameterGroupVO> getCategoryParams(String categoryId) {
|
||||
//根据id查询参数组
|
||||
@ -65,8 +81,22 @@ public class CategoryParameterGroupServiceImpl extends ServiceImpl<CategoryParam
|
||||
if (origin == null) {
|
||||
throw new ServiceException(ResultCode.CATEGORY_PARAMETER_NOT_EXIST);
|
||||
}
|
||||
LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(Goods::getId, Goods::getParams);
|
||||
queryWrapper.like(Goods::getParams, origin.getId());
|
||||
List<Map<String, Object>> goodsList = this.goodsService.listMaps(queryWrapper);
|
||||
|
||||
return false;
|
||||
for (Map<String, Object> goods : goodsList) {
|
||||
String params = (String) goods.get("params");
|
||||
List<GoodsParamsDTO> goodsParamsDTOS = JSONUtil.toList(params, GoodsParamsDTO.class);
|
||||
List<GoodsParamsDTO> goodsParamsDTOList = goodsParamsDTOS.stream().filter(i -> i.getGroupId() != null && i.getGroupId().equals(origin.getId())).collect(Collectors.toList());
|
||||
for (GoodsParamsDTO goodsParamsDTO : goodsParamsDTOList) {
|
||||
goodsParamsDTO.setGroupName(categoryParameterGroup.getGroupName());
|
||||
}
|
||||
this.goodsService.updateGoodsParams(goods.get("id").toString(), JSONUtil.toJsonStr(goodsParamsDTOS));
|
||||
}
|
||||
|
||||
return this.updateById(categoryParameterGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,7 +13,6 @@ 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.common.utils.StringUtils;
|
||||
import cn.lili.modules.goods.entity.dos.Category;
|
||||
import cn.lili.modules.goods.entity.dos.Goods;
|
||||
import cn.lili.modules.goods.entity.dos.GoodsGallery;
|
||||
@ -128,9 +127,23 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
||||
updateGoodsMarketAble(list, GoodsStatusEnum.DOWN, "店铺关闭");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品参数
|
||||
*
|
||||
* @param goodsId 商品id
|
||||
* @param params 商品参数
|
||||
*/
|
||||
@Override
|
||||
public void updateGoodsParams(String goodsId, String params) {
|
||||
LambdaUpdateWrapper<Goods> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(Goods::getId, goodsId);
|
||||
updateWrapper.set(Goods::getParams, params);
|
||||
this.update(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Integer getGoodsCountByCategory(String categoryId) {
|
||||
QueryWrapper queryWrapper = Wrappers.query();
|
||||
QueryWrapper<Goods> queryWrapper = Wrappers.query();
|
||||
queryWrapper.like("category_path", categoryId);
|
||||
queryWrapper.eq("delete_flag", false);
|
||||
return this.count(queryWrapper);
|
||||
@ -223,7 +236,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
||||
goodsVO.setCategoryName(categoryName);
|
||||
|
||||
//参数非空则填写参数
|
||||
if (StringUtils.isNotEmpty(goods.getParams())) {
|
||||
if (CharSequenceUtil.isNotEmpty(goods.getParams())) {
|
||||
goodsVO.setGoodsParamsDTOList(JSONUtil.toList(goods.getParams(), GoodsParamsDTO.class));
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.lili.modules.goods.serviceimpl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
@ -32,6 +33,7 @@ import cn.lili.modules.member.service.MemberEvaluationService;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsAttribute;
|
||||
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||
import cn.lili.modules.search.service.EsGoodsIndexService;
|
||||
import cn.lili.modules.search.utils.EsIndexUtil;
|
||||
import cn.lili.mybatis.util.PageUtil;
|
||||
import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
|
||||
import cn.lili.rocketmq.tags.GoodsTagsEnum;
|
||||
@ -476,8 +478,15 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
goodsSku.setGrade(grade);
|
||||
//修改规格
|
||||
this.update(goodsSku);
|
||||
//修改规格索引
|
||||
goodsIndexService.updateIndex(goodsSku.getId(), new EsGoodsIndex().setCommentNum(goodsSku.getCommentNum()).setHighPraiseNum(highPraiseNum).setGrade(grade));
|
||||
|
||||
|
||||
//修改规格索引,发送mq消息
|
||||
Map<String, Object> updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap(
|
||||
MapUtil.builder().put("id", goodsSku.getId()).build(),
|
||||
MapUtil.builder().put("commentNum", goodsSku.getCommentNum()).put("highPraiseNum", highPraiseNum)
|
||||
.put("grade", grade).build());
|
||||
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name();
|
||||
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap), RocketmqSendCallbackBuilder.commonCallback());
|
||||
|
||||
//修改商品的评价数量
|
||||
goodsService.updateGoodsCommentNum(goodsSku.getGoodsId());
|
||||
|
@ -15,7 +15,6 @@ import cn.lili.modules.goods.service.ParametersService;
|
||||
import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
|
||||
import cn.lili.rocketmq.tags.GoodsTagsEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -39,7 +38,6 @@ public class ParametersServiceImpl extends ServiceImpl<ParametersMapper, Paramet
|
||||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RocketmqCustomProperties rocketmqCustomProperties;
|
||||
|
||||
@ -70,10 +68,7 @@ public class ParametersServiceImpl extends ServiceImpl<ParametersMapper, Paramet
|
||||
List<GoodsParamsDTO> goodsParamsDTOS = JSONUtil.toList(params, GoodsParamsDTO.class);
|
||||
List<GoodsParamsDTO> goodsParamsDTOList = goodsParamsDTOS.stream().filter(i -> i.getGroupId() != null && i.getGroupId().equals(parameters.getGroupId())).collect(Collectors.toList());
|
||||
this.setGoodsItemDTOList(goodsParamsDTOList, parameters);
|
||||
LambdaUpdateWrapper<Goods> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(Goods::getId, goods.get("id"));
|
||||
updateWrapper.set(Goods::getParams, JSONUtil.toJsonStr(goodsParamsDTOS));
|
||||
this.goodsService.update(updateWrapper);
|
||||
this.goodsService.updateGoodsParams(goods.get("id").toString(), JSONUtil.toJsonStr(goodsParamsDTOS));
|
||||
goodsIds.add(goods.get("id").toString());
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
ReflectUtil.setFieldValue(goodsIndex, entry.getValue(), fieldValue);
|
||||
}
|
||||
}
|
||||
goodsIndexRepository.save(goods);
|
||||
goodsIndexRepository.save(goodsIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user