commit
ead6a72dec
@ -2,6 +2,7 @@ package cn.lili.listener;
|
|||||||
|
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import cn.lili.event.GoodsCommentCompleteEvent;
|
import cn.lili.event.GoodsCommentCompleteEvent;
|
||||||
import cn.lili.modules.distribution.entity.dos.DistributionGoods;
|
import cn.lili.modules.distribution.entity.dos.DistributionGoods;
|
||||||
@ -42,6 +43,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品消息
|
* 商品消息
|
||||||
@ -137,16 +139,25 @@ public class GoodsMessageListener implements RocketMQListener<MessageExt> {
|
|||||||
case UPDATE_GOODS_INDEX:
|
case UPDATE_GOODS_INDEX:
|
||||||
try {
|
try {
|
||||||
String goodsIdsJsonStr = new String(messageExt.getBody());
|
String goodsIdsJsonStr = new String(messageExt.getBody());
|
||||||
List<Goods> goodsList = new ArrayList<>();
|
List<Goods> goodsList = goodsService.list(new LambdaQueryWrapper<Goods>().in(Goods::getId, JSONUtil.toList(goodsIdsJsonStr, String.class)));
|
||||||
for (String goodsId : JSONUtil.toList(goodsIdsJsonStr, String.class)) {
|
|
||||||
Goods goods = goodsService.getById(goodsId);
|
|
||||||
goodsList.add(goods);
|
|
||||||
}
|
|
||||||
this.updateGoodsIndex(goodsList);
|
this.updateGoodsIndex(goodsList);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("更新商品索引事件执行异常,商品信息 {}", new String(messageExt.getBody()));
|
log.error("更新商品索引事件执行异常,商品信息 {}", new String(messageExt.getBody()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case UPDATE_GOODS_INDEX_FIELD:
|
||||||
|
try {
|
||||||
|
String updateIndexFieldsJsonStr = new String(messageExt.getBody());
|
||||||
|
JSONObject updateIndexFields = JSONUtil.parseObj(updateIndexFieldsJsonStr);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> queryFields = updateIndexFields.get("queryFields", Map.class);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> updateFields = updateIndexFields.get("updateFields", Map.class);
|
||||||
|
goodsIndexService.updateIndex(queryFields, updateFields);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("更新商品索引事件执行异常,商品信息 {}", new String(messageExt.getBody()));
|
||||||
|
}
|
||||||
|
break;
|
||||||
case RESET_GOODS_INDEX:
|
case RESET_GOODS_INDEX:
|
||||||
try {
|
try {
|
||||||
String goodsIdsJsonStr = new String(messageExt.getBody());
|
String goodsIdsJsonStr = new String(messageExt.getBody());
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.lili.modules.order.cart.render.impl;
|
package cn.lili.modules.order.cart.render.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.lili.common.enums.PromotionTypeEnum;
|
import cn.lili.common.enums.PromotionTypeEnum;
|
||||||
import cn.lili.common.utils.CurrencyUtil;
|
import cn.lili.common.utils.CurrencyUtil;
|
||||||
import cn.lili.common.utils.StringUtils;
|
import cn.lili.common.utils.StringUtils;
|
||||||
@ -18,6 +19,8 @@ import cn.lili.modules.promotion.service.MemberCouponService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -31,22 +34,21 @@ import java.util.stream.Collectors;
|
|||||||
@Service
|
@Service
|
||||||
public class CouponRender implements CartRenderStep {
|
public class CouponRender implements CartRenderStep {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PromotionPriceUtil promotionPriceUtil;
|
||||||
|
@Autowired
|
||||||
|
private MemberCouponService memberCouponService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderStepEnums step() {
|
public RenderStepEnums step() {
|
||||||
return RenderStepEnums.COUPON;
|
return RenderStepEnums.COUPON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PromotionPriceUtil promotionPriceUtil;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MemberCouponService memberCouponService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(TradeDTO tradeDTO) {
|
public void render(TradeDTO tradeDTO) {
|
||||||
|
|
||||||
//优惠券列表
|
//优惠券列表
|
||||||
renderCouponRule(tradeDTO);
|
this.renderCouponRule(tradeDTO);
|
||||||
//主要渲染各个优惠的价格
|
//主要渲染各个优惠的价格
|
||||||
this.renderCoupon(tradeDTO);
|
this.renderCoupon(tradeDTO);
|
||||||
}
|
}
|
||||||
@ -54,27 +56,55 @@ public class CouponRender implements CartRenderStep {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染优惠券规则
|
* 渲染优惠券规则
|
||||||
|
*
|
||||||
|
* @param tradeDTO 交易dto
|
||||||
*/
|
*/
|
||||||
private void renderCouponRule(TradeDTO tradeDTO) {
|
private void renderCouponRule(TradeDTO tradeDTO) {
|
||||||
List<MemberCoupon> memberCouponList = memberCouponService.getMemberCoupons();
|
List<MemberCoupon> memberCouponList = memberCouponService.getMemberCoupons();
|
||||||
|
|
||||||
memberCouponList.forEach(memberCoupon -> {
|
if (!memberCouponList.isEmpty()) {
|
||||||
available(tradeDTO, memberCoupon);
|
this.checkMemberExistCoupon(tradeDTO, memberCouponList);
|
||||||
});
|
} else {
|
||||||
|
tradeDTO.setPlatformCoupon(null);
|
||||||
|
tradeDTO.setStoreCoupons(new HashMap<>());
|
||||||
|
}
|
||||||
|
memberCouponList.forEach(memberCoupon -> available(tradeDTO, memberCoupon));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查使用中的优惠券是否存在与用户的优惠券中
|
||||||
|
*
|
||||||
|
* @param tradeDTO 交易dto
|
||||||
|
* @param memberCouponList 会员优惠券列表
|
||||||
|
*/
|
||||||
|
private void checkMemberExistCoupon(TradeDTO tradeDTO, List<MemberCoupon> memberCouponList) {
|
||||||
|
if (tradeDTO.getPlatformCoupon() != null && tradeDTO.getPlatformCoupon().getMemberCoupon() != null) {
|
||||||
|
boolean b = memberCouponList.parallelStream().anyMatch(i -> i.getId().equals(tradeDTO.getPlatformCoupon().getMemberCoupon().getId()));
|
||||||
|
if (!b) {
|
||||||
|
tradeDTO.setPlatformCoupon(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!tradeDTO.getStoreCoupons().isEmpty()) {
|
||||||
|
for (Map.Entry<String, MemberCouponDTO> entry : tradeDTO.getStoreCoupons().entrySet()) {
|
||||||
|
if (entry.getValue().getMemberCoupon() != null && memberCouponList.parallelStream().noneMatch(i -> i.getId().equals(entry.getValue().getMemberCoupon().getId()))) {
|
||||||
|
tradeDTO.getStoreCoupons().remove(entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判定优惠券是否可用
|
* 判定优惠券是否可用
|
||||||
*
|
*
|
||||||
* @param tradeDTO
|
* @param tradeDTO 交易dto
|
||||||
* @param memberCoupon
|
* @param memberCoupon 会员优惠券
|
||||||
*/
|
*/
|
||||||
private void available(TradeDTO tradeDTO, MemberCoupon memberCoupon) {
|
private void available(TradeDTO tradeDTO, MemberCoupon memberCoupon) {
|
||||||
if (memberCoupon == null) {
|
if (memberCoupon == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<CartSkuVO> filterSku = filterSkuVo(tradeDTO.getSkuList(), memberCoupon);
|
List<CartSkuVO> filterSku = filterSkuVo(tradeDTO.getSkuList(), memberCoupon);
|
||||||
if (filterSku == null || filterSku.size() == 0) {
|
if (filterSku == null || filterSku.isEmpty()) {
|
||||||
tradeDTO.getCantUseCoupons().add(new MemberCouponVO(memberCoupon,
|
tradeDTO.getCantUseCoupons().add(new MemberCouponVO(memberCoupon,
|
||||||
"购物车中没有满足优惠券使用范围的优惠券"));
|
"购物车中没有满足优惠券使用范围的优惠券"));
|
||||||
return;
|
return;
|
||||||
@ -100,23 +130,21 @@ public class CouponRender implements CartRenderStep {
|
|||||||
/**
|
/**
|
||||||
* 过滤购物车商品信息,按照优惠券的适用范围过滤
|
* 过滤购物车商品信息,按照优惠券的适用范围过滤
|
||||||
*
|
*
|
||||||
* @param cartSkuVOS
|
* @param cartSkuVOS 购物车中的产品列表
|
||||||
* @param memberCoupon
|
* @param memberCoupon 会员优惠券
|
||||||
* @return
|
* @return 按照优惠券的适用范围过滤的购物车商品信息
|
||||||
*/
|
*/
|
||||||
private List<CartSkuVO> filterSkuVo(List<CartSkuVO> cartSkuVOS, MemberCoupon memberCoupon) {
|
private List<CartSkuVO> filterSkuVo(List<CartSkuVO> cartSkuVOS, MemberCoupon memberCoupon) {
|
||||||
|
|
||||||
List<CartSkuVO> filterSku;
|
List<CartSkuVO> filterSku;
|
||||||
//平台店铺过滤
|
//平台店铺过滤
|
||||||
if (memberCoupon.getIsPlatform()) {
|
if (Boolean.TRUE.equals(memberCoupon.getIsPlatform())) {
|
||||||
filterSku = cartSkuVOS;
|
filterSku = cartSkuVOS;
|
||||||
} else {
|
} else {
|
||||||
filterSku = cartSkuVOS.stream().filter(cartSkuVO -> {
|
filterSku = cartSkuVOS.stream().filter(cartSkuVO -> cartSkuVO.getStoreId().equals(memberCoupon.getStoreId())).collect(Collectors.toList());
|
||||||
return cartSkuVO.getStoreId().equals(memberCoupon.getStoreId());
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
if (filterSku == null || filterSku.size() == 0) {
|
if (filterSku == null || filterSku.isEmpty()) {
|
||||||
return null;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
//优惠券类型判定
|
//优惠券类型判定
|
||||||
switch (CouponScopeTypeEnum.valueOf(memberCoupon.getScopeType())) {
|
switch (CouponScopeTypeEnum.valueOf(memberCoupon.getScopeType())) {
|
||||||
@ -124,28 +152,12 @@ public class CouponRender implements CartRenderStep {
|
|||||||
return filterSku;
|
return filterSku;
|
||||||
case PORTION_GOODS:
|
case PORTION_GOODS:
|
||||||
//按照商品过滤
|
//按照商品过滤
|
||||||
filterSku = filterSku.stream().filter(cartSkuVO -> {
|
filterSku = filterSku.stream().filter(cartSkuVO -> memberCoupon.getScopeId().contains(cartSkuVO.getGoodsSku().getId())).collect(Collectors.toList());
|
||||||
return memberCoupon.getScopeId().indexOf(cartSkuVO.getGoodsSku().getId()) > 0;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PORTION_SHOP_CATEGORY:
|
case PORTION_SHOP_CATEGORY:
|
||||||
//按照店铺分类过滤
|
//按照店铺分类过滤
|
||||||
filterSku = filterSku.stream().filter(cartSkuVO -> {
|
filterSku = this.filterPromotionShopCategory(filterSku, memberCoupon);
|
||||||
if (StringUtils.isNotEmpty(cartSkuVO.getGoodsSku().getStoreCategoryPath())) {
|
|
||||||
//获取店铺分类
|
|
||||||
String[] storeCategoryPath = cartSkuVO.getGoodsSku().getStoreCategoryPath().split(",");
|
|
||||||
for (String category : storeCategoryPath) {
|
|
||||||
//店铺分类只要有一项吻合,即可返回true
|
|
||||||
if (memberCoupon.getScopeId().indexOf(category) > 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PORTION_GOODS_CATEGORY:
|
case PORTION_GOODS_CATEGORY:
|
||||||
@ -156,18 +168,37 @@ public class CouponRender implements CartRenderStep {
|
|||||||
String[] categoryPath = cartSkuVO.getGoodsSku().getCategoryPath().split(",");
|
String[] categoryPath = cartSkuVO.getGoodsSku().getCategoryPath().split(",");
|
||||||
//平台三级分类
|
//平台三级分类
|
||||||
String categoryId = categoryPath[categoryPath.length - 1];
|
String categoryId = categoryPath[categoryPath.length - 1];
|
||||||
if (memberCoupon.getScopeId().indexOf(categoryId) > 0) {
|
return memberCoupon.getScopeId().contains(categoryId);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return null;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return filterSku;
|
return filterSku;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券按照店铺分类过滤
|
||||||
|
*
|
||||||
|
* @param filterSku 过滤的购物车商品信息
|
||||||
|
* @param memberCoupon 会员优惠
|
||||||
|
* @return 优惠券按照店铺分类过滤的购物车商品信息
|
||||||
|
*/
|
||||||
|
private List<CartSkuVO> filterPromotionShopCategory(List<CartSkuVO> filterSku, MemberCoupon memberCoupon) {
|
||||||
|
return filterSku.stream().filter(cartSkuVO -> {
|
||||||
|
if (CharSequenceUtil.isNotEmpty(cartSkuVO.getGoodsSku().getStoreCategoryPath())) {
|
||||||
|
//获取店铺分类
|
||||||
|
String[] storeCategoryPath = cartSkuVO.getGoodsSku().getStoreCategoryPath().split(",");
|
||||||
|
for (String category : storeCategoryPath) {
|
||||||
|
//店铺分类只要有一项吻合,即可返回true
|
||||||
|
if (memberCoupon.getScopeId().contains(category)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染优惠券
|
* 渲染优惠券
|
||||||
@ -212,14 +243,30 @@ public class CouponRender implements CartRenderStep {
|
|||||||
coupon.setPrice(countPrice);
|
coupon.setPrice(countPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
//减免现金,则按照商品价格计算 需要通过工具类进行优惠金额的分发,分发给每个商品
|
|
||||||
if (coupon.getCouponType().equals(CouponTypeEnum.PRICE.name())) {
|
if (coupon.getCouponType().equals(CouponTypeEnum.PRICE.name())) {
|
||||||
|
//减免现金,则按照商品价格计算 需要通过工具类进行优惠金额的分发,分发给每个商品
|
||||||
|
this.renderCouponPrice(couponMap, tradeDTO, coupon, memberCouponDTO);
|
||||||
|
} else {
|
||||||
|
//打折券 直接计算
|
||||||
|
this.renderCouponDiscount(couponMap, tradeDTO, coupon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 减免现金,则按照商品价格计算 需要通过工具类进行优惠金额的分发,分发给每个商品
|
||||||
|
*
|
||||||
|
* @param couponMap 优惠券结算信息
|
||||||
|
* @param tradeDTO 交易dto
|
||||||
|
* @param coupon 优惠券信息
|
||||||
|
* @param memberCouponDTO 用于计算优惠券结算详情
|
||||||
|
*/
|
||||||
|
private void renderCouponPrice(Map<String, Double> couponMap, TradeDTO tradeDTO, MemberCoupon coupon, MemberCouponDTO memberCouponDTO) {
|
||||||
//分发优惠券
|
//分发优惠券
|
||||||
promotionPriceUtil.recountPrice(tradeDTO, memberCouponDTO.getSkuDetail(), memberCouponDTO.getMemberCoupon().getPrice(),
|
promotionPriceUtil.recountPrice(tradeDTO, memberCouponDTO.getSkuDetail(), memberCouponDTO.getMemberCoupon().getPrice(),
|
||||||
coupon.getIsPlatform() ?
|
Boolean.TRUE.equals(coupon.getIsPlatform()) ?
|
||||||
PromotionTypeEnum.PLATFORM_COUPON : PromotionTypeEnum.COUPON);
|
PromotionTypeEnum.PLATFORM_COUPON : PromotionTypeEnum.COUPON);
|
||||||
//如果是平台券 则需要计算商家承担比例
|
//如果是平台券 则需要计算商家承担比例
|
||||||
if (coupon.getIsPlatform() && coupon.getStoreCommission() > 0) {
|
if (Boolean.TRUE.equals(coupon.getIsPlatform()) && coupon.getStoreCommission() > 0) {
|
||||||
|
|
||||||
//循环所有优惠券
|
//循环所有优惠券
|
||||||
for (String skuId : couponMap.keySet()) {
|
for (String skuId : couponMap.keySet()) {
|
||||||
@ -234,8 +281,16 @@ public class CouponRender implements CartRenderStep {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//打折券 直接计算
|
|
||||||
else {
|
|
||||||
|
/**
|
||||||
|
* 打折券计算
|
||||||
|
*
|
||||||
|
* @param couponMap 优惠券结算信息
|
||||||
|
* @param tradeDTO 交易dto
|
||||||
|
* @param coupon 优惠券信息
|
||||||
|
*/
|
||||||
|
private void renderCouponDiscount(Map<String, Double> couponMap, TradeDTO tradeDTO, MemberCoupon coupon) {
|
||||||
//循环所有优惠券
|
//循环所有优惠券
|
||||||
for (String skuId : couponMap.keySet()) {
|
for (String skuId : couponMap.keySet()) {
|
||||||
|
|
||||||
@ -251,7 +306,7 @@ public class CouponRender implements CartRenderStep {
|
|||||||
CurrencyUtil.sub(1, CurrencyUtil.div(coupon.getDiscount(), 10, 3)));
|
CurrencyUtil.sub(1, CurrencyUtil.div(coupon.getDiscount(), 10, 3)));
|
||||||
|
|
||||||
//平台券则写入店铺承担优惠券比例
|
//平台券则写入店铺承担优惠券比例
|
||||||
if (coupon.getIsPlatform()) {
|
if (Boolean.TRUE.equals(coupon.getIsPlatform())) {
|
||||||
priceDetailDTO.setSiteCouponPrice(discountCouponPrice);
|
priceDetailDTO.setSiteCouponPrice(discountCouponPrice);
|
||||||
priceDetailDTO.setSiteCouponPoint(coupon.getStoreCommission());
|
priceDetailDTO.setSiteCouponPoint(coupon.getStoreCommission());
|
||||||
}
|
}
|
||||||
@ -262,5 +317,4 @@ public class CouponRender implements CartRenderStep {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class CouponActivityServiceImpl extends ServiceImpl<CouponActivityMapper,
|
|||||||
//检测优惠券活动是否可以添加
|
//检测优惠券活动是否可以添加
|
||||||
this.checkParam(couponActivityDTO);
|
this.checkParam(couponActivityDTO);
|
||||||
//如果有会员,则写入会员信息
|
//如果有会员,则写入会员信息
|
||||||
if (couponActivityDTO.getMemberDTOS() != null && couponActivityDTO.getMemberDTOS().size() != 0) {
|
if (couponActivityDTO.getMemberDTOS() != null && !couponActivityDTO.getMemberDTOS().isEmpty()) {
|
||||||
couponActivityDTO.setActivityScopeInfo(JSONUtil.toJsonStr(couponActivityDTO.getMemberDTOS()));
|
couponActivityDTO.setActivityScopeInfo(JSONUtil.toJsonStr(couponActivityDTO.getMemberDTOS()));
|
||||||
}
|
}
|
||||||
//添加优惠券活动
|
//添加优惠券活动
|
||||||
@ -106,8 +106,7 @@ public class CouponActivityServiceImpl extends ServiceImpl<CouponActivityMapper,
|
|||||||
@Override
|
@Override
|
||||||
public CouponActivityVO getCouponActivityVO(String couponActivityId) {
|
public CouponActivityVO getCouponActivityVO(String couponActivityId) {
|
||||||
CouponActivity couponActivity = this.getById(couponActivityId);
|
CouponActivity couponActivity = this.getById(couponActivityId);
|
||||||
CouponActivityVO couponActivityVO = new CouponActivityVO(couponActivity, couponActivityItemService.getCouponActivityItemListVO(couponActivityId));
|
return new CouponActivityVO(couponActivity, couponActivityItemService.getCouponActivityItemListVO(couponActivityId));
|
||||||
return couponActivityVO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -217,13 +216,11 @@ public class CouponActivityServiceImpl extends ServiceImpl<CouponActivityMapper,
|
|||||||
//活动时间需超过当前时间
|
//活动时间需超过当前时间
|
||||||
PromotionTools.checkPromotionTime(couponActivity.getStartTime().getTime(), couponActivity.getEndTime().getTime());
|
PromotionTools.checkPromotionTime(couponActivity.getStartTime().getTime(), couponActivity.getEndTime().getTime());
|
||||||
//指定会员判定
|
//指定会员判定
|
||||||
if (couponActivity.getActivityScope().equals(CouponActivitySendTypeEnum.DESIGNATED.name())) {
|
if (couponActivity.getActivityScope().equals(CouponActivitySendTypeEnum.DESIGNATED.name()) && couponActivity.getMemberDTOS().isEmpty()) {
|
||||||
if (couponActivity.getMemberDTOS().size() == 0) {
|
|
||||||
throw new ServiceException(ResultCode.COUPON_ACTIVITY_MEMBER_ERROR);
|
throw new ServiceException(ResultCode.COUPON_ACTIVITY_MEMBER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//优惠券数量判定
|
//优惠券数量判定
|
||||||
if (couponActivity.getCouponActivityItems().size() == 0) {
|
if (couponActivity.getCouponActivityItems().isEmpty()) {
|
||||||
throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_ERROR);
|
throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_ERROR);
|
||||||
} else if (couponActivity.getCouponActivityItems().size() > 10) {
|
} else if (couponActivity.getCouponActivityItems().size() > 10) {
|
||||||
throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_MUST_NUM_ERROR);
|
throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_MUST_NUM_ERROR);
|
||||||
|
@ -40,6 +40,14 @@ public interface EsGoodsIndexService {
|
|||||||
*/
|
*/
|
||||||
void updateIndex(String id, EsGoodsIndex goods);
|
void updateIndex(String id, EsGoodsIndex goods);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新商品索引的的部分属性
|
||||||
|
*
|
||||||
|
* @param queryFields 查询字段
|
||||||
|
* @param updateFields 更新字段
|
||||||
|
*/
|
||||||
|
void updateIndex(Map<String, Object> queryFields, Map<String, Object> updateFields);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量商品索引的的属性(ID 必填, 其他字段只填写更新的字段,不需要更新的字段不要填写。)
|
* 批量商品索引的的属性(ID 必填, 其他字段只填写更新的字段,不需要更新的字段不要填写。)
|
||||||
*
|
*
|
||||||
@ -105,10 +113,12 @@ public interface EsGoodsIndexService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除索引中指定的促销活动id的促销活动
|
* 删除索引中指定的促销活动id的促销活动
|
||||||
|
*
|
||||||
* @param skuId 商品skuId
|
* @param skuId 商品skuId
|
||||||
* @param promotionId 促销活动Id
|
* @param promotionId 促销活动Id
|
||||||
*/
|
*/
|
||||||
void deleteEsGoodsPromotionByPromotionId(String skuId, String promotionId);
|
void deleteEsGoodsPromotionByPromotionId(String skuId, String promotionId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除所以商品索引的无效促销活动
|
* 清除所以商品索引的无效促销活动
|
||||||
*/
|
*/
|
||||||
|
@ -30,11 +30,18 @@ import cn.lili.modules.search.service.EsGoodsSearchService;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.assertj.core.util.IterableUtil;
|
import org.assertj.core.util.IterableUtil;
|
||||||
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.bulk.BulkRequest;
|
import org.elasticsearch.action.bulk.BulkRequest;
|
||||||
import org.elasticsearch.action.update.UpdateRequest;
|
import org.elasticsearch.action.update.UpdateRequest;
|
||||||
import org.elasticsearch.client.RequestOptions;
|
import org.elasticsearch.client.RequestOptions;
|
||||||
import org.elasticsearch.client.indices.AnalyzeRequest;
|
import org.elasticsearch.client.indices.AnalyzeRequest;
|
||||||
import org.elasticsearch.client.indices.AnalyzeResponse;
|
import org.elasticsearch.client.indices.AnalyzeResponse;
|
||||||
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
|
import org.elasticsearch.index.query.TermQueryBuilder;
|
||||||
|
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||||
|
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
||||||
|
import org.elasticsearch.script.Script;
|
||||||
import org.mybatis.spring.MyBatisSystemException;
|
import org.mybatis.spring.MyBatisSystemException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||||
@ -76,11 +83,9 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addIndex(EsGoodsIndex goods) {
|
public void addIndex(EsGoodsIndex goods) {
|
||||||
//索引名称拼接
|
|
||||||
String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME;
|
|
||||||
try {
|
try {
|
||||||
//分词器分词
|
//分词器分词
|
||||||
AnalyzeRequest analyzeRequest = AnalyzeRequest.withIndexAnalyzer(indexName, "ik_max_word", goods.getGoodsName());
|
AnalyzeRequest analyzeRequest = AnalyzeRequest.withIndexAnalyzer(getIndexName(), "ik_max_word", goods.getGoodsName());
|
||||||
AnalyzeResponse analyze = client.indices().analyze(analyzeRequest, RequestOptions.DEFAULT);
|
AnalyzeResponse analyze = client.indices().analyze(analyzeRequest, RequestOptions.DEFAULT);
|
||||||
List<AnalyzeResponse.AnalyzeToken> tokens = analyze.getTokens();
|
List<AnalyzeResponse.AnalyzeToken> tokens = analyze.getTokens();
|
||||||
|
|
||||||
@ -126,6 +131,29 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
goodsIndexRepository.save(goods);
|
goodsIndexRepository.save(goods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新商品索引的的部分属性(只填写更新的字段,不需要更新的字段不要填写)
|
||||||
|
*
|
||||||
|
* @param queryFields 查询字段
|
||||||
|
* @param updateFields 更新字段
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateIndex(Map<String, Object> queryFields, Map<String, Object> updateFields) {
|
||||||
|
UpdateByQueryRequest update = new UpdateByQueryRequest(getIndexName());
|
||||||
|
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
|
||||||
|
for (Map.Entry<String, Object> entry : queryFields.entrySet()) {
|
||||||
|
TermQueryBuilder termQueryBuilder = new TermQueryBuilder(entry.getKey(), entry.getValue());
|
||||||
|
queryBuilder.filter(termQueryBuilder);
|
||||||
|
}
|
||||||
|
update.setQuery(queryBuilder);
|
||||||
|
StringBuilder script = new StringBuilder();
|
||||||
|
for (Map.Entry<String, Object> entry : updateFields.entrySet()) {
|
||||||
|
script.append("ctx._source.").append(entry.getKey()).append("=").append("'").append(entry.getValue()).append("'").append(";");
|
||||||
|
}
|
||||||
|
update.setScript(new Script(script.toString()));
|
||||||
|
client.updateByQueryAsync(update, RequestOptions.DEFAULT, this.actionListener());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量商品索引的的属性(ID 必填, 其他字段只填写更新的字段,不需要更新的字段不要填写。)
|
* 批量商品索引的的属性(ID 必填, 其他字段只填写更新的字段,不需要更新的字段不要填写。)
|
||||||
*
|
*
|
||||||
@ -135,7 +163,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
public void updateBulkIndex(List<EsGoodsIndex> goodsIndices) {
|
public void updateBulkIndex(List<EsGoodsIndex> goodsIndices) {
|
||||||
try {
|
try {
|
||||||
//索引名称拼接
|
//索引名称拼接
|
||||||
String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME;
|
String indexName = getIndexName();
|
||||||
|
|
||||||
BulkRequest request = new BulkRequest();
|
BulkRequest request = new BulkRequest();
|
||||||
|
|
||||||
@ -178,7 +206,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//索引名称拼接
|
//索引名称拼接
|
||||||
String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME;
|
String indexName = this.getIndexName();
|
||||||
|
|
||||||
//索引初始化,因为mapping结构问题:
|
//索引初始化,因为mapping结构问题:
|
||||||
//但是如果索引已经自动生成过,这里就不会创建索引,设置mapping,所以这里决定在初始化索引的同时,将已有索引删除,重新创建
|
//但是如果索引已经自动生成过,这里就不会创建索引,设置mapping,所以这里决定在初始化索引的同时,将已有索引删除,重新创建
|
||||||
@ -383,7 +411,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
}
|
}
|
||||||
return promotionMap;
|
return promotionMap;
|
||||||
}
|
}
|
||||||
return null;
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -519,4 +547,22 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getIndexName() {
|
||||||
|
//索引名称拼接
|
||||||
|
return elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionListener<BulkByScrollResponse> actionListener() {
|
||||||
|
return new ActionListener<BulkByScrollResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(BulkByScrollResponse bulkByScrollResponse) {
|
||||||
|
log.debug("UpdateByQueryResponse: {}", bulkByScrollResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Exception e) {
|
||||||
|
log.error("UpdateByQueryRequestFailure: ", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package cn.lili.modules.search.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author paulG
|
||||||
|
* @since 2021/10/11
|
||||||
|
**/
|
||||||
|
public class EsIndexUtil {
|
||||||
|
|
||||||
|
private static final String IGNORE_FIELD = "serialVersionUID,promotionMap,id,goodsId";
|
||||||
|
|
||||||
|
public static Map<String, Object> getUpdateIndexFieldsMap(EsGoodsIndex queryGoodsIndex, EsGoodsIndex updateGoodsIndex) {
|
||||||
|
Map<Object, Object> queryFieldsMap = new HashMap<>();
|
||||||
|
Map<Object, Object> updateFieldsMap = new HashMap<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Field> entry : ReflectUtil.getFieldMap(EsGoodsIndex.class).entrySet()) {
|
||||||
|
Object queryFieldValue = ReflectUtil.getFieldValue(queryGoodsIndex, entry.getValue());
|
||||||
|
Object updateFieldValue = ReflectUtil.getFieldValue(updateGoodsIndex, entry.getValue());
|
||||||
|
if (queryFieldValue != null && !IGNORE_FIELD.contains(entry.getKey())) {
|
||||||
|
ReflectUtil.setFieldValue(queryFieldsMap, entry.getValue(), queryFieldValue);
|
||||||
|
}
|
||||||
|
if (updateFieldValue != null && !IGNORE_FIELD.contains(entry.getKey())) {
|
||||||
|
ReflectUtil.setFieldValue(updateFieldsMap, entry.getValue(), updateFieldValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return getUpdateIndexFieldsMap(queryFieldsMap, updateFieldsMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, Object> getUpdateIndexFieldsMap(Map<Object, Object> queryFieldsMap, Map<Object, Object> updateFieldsMap) {
|
||||||
|
Map<String, Object> updateIndexMap = new HashMap<>();
|
||||||
|
|
||||||
|
updateIndexMap.put("queryFields", queryFieldsMap);
|
||||||
|
updateIndexMap.put("updateFields", updateFieldsMap);
|
||||||
|
return updateIndexMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
package cn.lili.modules.store.service;
|
package cn.lili.modules.store.service;
|
||||||
|
|
||||||
|
import cn.lili.modules.store.entity.dos.Store;
|
||||||
import cn.lili.modules.store.entity.dos.StoreDetail;
|
import cn.lili.modules.store.entity.dos.StoreDetail;
|
||||||
import cn.lili.modules.store.entity.dto.StoreAfterSaleAddressDTO;
|
import cn.lili.modules.store.entity.dto.StoreAfterSaleAddressDTO;
|
||||||
import cn.lili.modules.store.entity.dto.StoreSettingDTO;
|
import cn.lili.modules.store.entity.dto.StoreSettingDTO;
|
||||||
import cn.lili.modules.store.entity.vos.StoreBasicInfoVO;
|
import cn.lili.modules.store.entity.vos.StoreBasicInfoVO;
|
||||||
import cn.lili.modules.store.entity.vos.StoreDetailVO;
|
import cn.lili.modules.store.entity.vos.StoreDetailVO;
|
||||||
|
import cn.lili.modules.store.entity.vos.StoreManagementCategoryVO;
|
||||||
import cn.lili.modules.store.entity.vos.StoreOtherVO;
|
import cn.lili.modules.store.entity.vos.StoreOtherVO;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
@ -95,7 +97,7 @@ public interface StoreDetailService extends IService<StoreDetail> {
|
|||||||
* @param storeId 店铺ID
|
* @param storeId 店铺ID
|
||||||
* @return 店铺经营范围
|
* @return 店铺经营范围
|
||||||
*/
|
*/
|
||||||
List goodsManagementCategory(String storeId);
|
List<StoreManagementCategoryVO> goodsManagementCategory(String storeId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取店铺其他信息
|
* 获取店铺其他信息
|
||||||
@ -104,4 +106,11 @@ public interface StoreDetailService extends IService<StoreDetail> {
|
|||||||
* @return 店铺其他信息
|
* @return 店铺其他信息
|
||||||
*/
|
*/
|
||||||
StoreOtherVO getStoreOtherVO(String storeId);
|
StoreOtherVO getStoreOtherVO(String storeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新店铺内所有商品信息
|
||||||
|
*
|
||||||
|
* @param store 店铺信息
|
||||||
|
*/
|
||||||
|
void updateStoreGoodsInfo(Store store);
|
||||||
}
|
}
|
@ -1,10 +1,18 @@
|
|||||||
package cn.lili.modules.store.serviceimpl;
|
package cn.lili.modules.store.serviceimpl;
|
||||||
|
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import cn.lili.common.properties.RocketmqCustomProperties;
|
||||||
import cn.lili.common.security.AuthUser;
|
import cn.lili.common.security.AuthUser;
|
||||||
import cn.lili.common.security.context.UserContext;
|
import cn.lili.common.security.context.UserContext;
|
||||||
import cn.lili.common.utils.BeanUtil;
|
import cn.lili.common.utils.BeanUtil;
|
||||||
import cn.lili.modules.goods.entity.dos.Category;
|
import cn.lili.modules.goods.entity.dos.Category;
|
||||||
|
import cn.lili.modules.goods.entity.dos.Goods;
|
||||||
|
import cn.lili.modules.goods.entity.dos.GoodsSku;
|
||||||
import cn.lili.modules.goods.service.CategoryService;
|
import cn.lili.modules.goods.service.CategoryService;
|
||||||
|
import cn.lili.modules.goods.service.GoodsService;
|
||||||
|
import cn.lili.modules.goods.service.GoodsSkuService;
|
||||||
|
import cn.lili.modules.search.utils.EsIndexUtil;
|
||||||
import cn.lili.modules.store.entity.dos.Store;
|
import cn.lili.modules.store.entity.dos.Store;
|
||||||
import cn.lili.modules.store.entity.dos.StoreDetail;
|
import cn.lili.modules.store.entity.dos.StoreDetail;
|
||||||
import cn.lili.modules.store.entity.dto.StoreAfterSaleAddressDTO;
|
import cn.lili.modules.store.entity.dto.StoreAfterSaleAddressDTO;
|
||||||
@ -16,16 +24,20 @@ import cn.lili.modules.store.entity.vos.StoreOtherVO;
|
|||||||
import cn.lili.modules.store.mapper.StoreDetailMapper;
|
import cn.lili.modules.store.mapper.StoreDetailMapper;
|
||||||
import cn.lili.modules.store.service.StoreDetailService;
|
import cn.lili.modules.store.service.StoreDetailService;
|
||||||
import cn.lili.modules.store.service.StoreService;
|
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.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,6 +61,18 @@ public class StoreDetailServiceImpl extends ServiceImpl<StoreDetailMapper, Store
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CategoryService categoryService;
|
private CategoryService categoryService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GoodsService goodsService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GoodsSkuService goodsSkuService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RocketmqCustomProperties rocketmqCustomProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RocketMQTemplate rocketMQTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StoreDetailVO getStoreDetailVO(String storeId) {
|
public StoreDetailVO getStoreDetailVO(String storeId) {
|
||||||
return this.baseMapper.getStoreDetail(storeId);
|
return this.baseMapper.getStoreDetail(storeId);
|
||||||
@ -72,7 +96,30 @@ public class StoreDetailServiceImpl extends ServiceImpl<StoreDetailMapper, Store
|
|||||||
//修改店铺
|
//修改店铺
|
||||||
Store store = storeService.getById(tokenUser.getStoreId());
|
Store store = storeService.getById(tokenUser.getStoreId());
|
||||||
BeanUtil.copyProperties(storeSettingDTO, store);
|
BeanUtil.copyProperties(storeSettingDTO, store);
|
||||||
return storeService.updateById(store);
|
boolean result = storeService.updateById(store);
|
||||||
|
if (result) {
|
||||||
|
this.updateStoreGoodsInfo(store);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateStoreGoodsInfo(Store store) {
|
||||||
|
|
||||||
|
goodsService.update(new LambdaUpdateWrapper<Goods>()
|
||||||
|
.eq(Goods::getStoreId, store.getId())
|
||||||
|
.set(Goods::getStoreName, store.getStoreName())
|
||||||
|
.set(Goods::getSelfOperated, store.getSelfOperated()));
|
||||||
|
goodsSkuService.update(new LambdaUpdateWrapper<GoodsSku>()
|
||||||
|
.eq(GoodsSku::getStoreId, store.getId())
|
||||||
|
.set(GoodsSku::getStoreName, store.getStoreName())
|
||||||
|
.set(GoodsSku::getSelfOperated, store.getSelfOperated()));
|
||||||
|
|
||||||
|
Map<String, Object> updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap(
|
||||||
|
MapUtil.builder().put("storeId", store.getId()).build(),
|
||||||
|
MapUtil.builder().put("storeName", store.getStoreName()).put("selfOperated", store.getSelfOperated()).build());
|
||||||
|
String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name();
|
||||||
|
//发送mq消息
|
||||||
|
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap), RocketmqSendCallbackBuilder.commonCallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -118,7 +165,7 @@ public class StoreDetailServiceImpl extends ServiceImpl<StoreDetailMapper, Store
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List goodsManagementCategory(String storeId) {
|
public List<StoreManagementCategoryVO> goodsManagementCategory(String storeId) {
|
||||||
|
|
||||||
//获取顶部分类列表
|
//获取顶部分类列表
|
||||||
List<Category> categoryList = categoryService.firstCategory();
|
List<Category> categoryList = categoryService.firstCategory();
|
||||||
|
@ -2,12 +2,12 @@ package cn.lili.modules.store.serviceimpl;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
import cn.lili.common.enums.ResultCode;
|
import cn.lili.common.enums.ResultCode;
|
||||||
import cn.lili.common.exception.ServiceException;
|
import cn.lili.common.exception.ServiceException;
|
||||||
import cn.lili.common.security.AuthUser;
|
import cn.lili.common.security.AuthUser;
|
||||||
import cn.lili.common.security.context.UserContext;
|
import cn.lili.common.security.context.UserContext;
|
||||||
import cn.lili.common.utils.BeanUtil;
|
import cn.lili.common.utils.BeanUtil;
|
||||||
import cn.lili.common.utils.StringUtils;
|
|
||||||
import cn.lili.common.vo.PageVO;
|
import cn.lili.common.vo.PageVO;
|
||||||
import cn.lili.modules.goods.entity.dos.Goods;
|
import cn.lili.modules.goods.entity.dos.Goods;
|
||||||
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
|
||||||
@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +90,7 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StoreVO getStoreDetail() {
|
public StoreVO getStoreDetail() {
|
||||||
AuthUser currentUser = UserContext.getCurrentUser();
|
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
|
||||||
StoreVO storeVO = this.baseMapper.getStoreDetail(currentUser.getStoreId());
|
StoreVO storeVO = this.baseMapper.getStoreDetail(currentUser.getStoreId());
|
||||||
storeVO.setNickName(currentUser.getNickName());
|
storeVO.setNickName(currentUser.getNickName());
|
||||||
return storeVO;
|
return storeVO;
|
||||||
@ -99,7 +100,7 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
|||||||
public Store add(AdminStoreApplyDTO adminStoreApplyDTO) {
|
public Store add(AdminStoreApplyDTO adminStoreApplyDTO) {
|
||||||
|
|
||||||
//判断店铺名称是否存在
|
//判断店铺名称是否存在
|
||||||
QueryWrapper queryWrapper = Wrappers.query();
|
QueryWrapper<Store> queryWrapper = Wrappers.query();
|
||||||
queryWrapper.eq("store_name", adminStoreApplyDTO.getStoreName());
|
queryWrapper.eq("store_name", adminStoreApplyDTO.getStoreName());
|
||||||
if (this.getOne(queryWrapper) != null) {
|
if (this.getOne(queryWrapper) != null) {
|
||||||
throw new ServiceException(ResultCode.STORE_NAME_EXIST_ERROR);
|
throw new ServiceException(ResultCode.STORE_NAME_EXIST_ERROR);
|
||||||
@ -111,7 +112,7 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
|||||||
throw new ServiceException(ResultCode.USER_NOT_EXIST);
|
throw new ServiceException(ResultCode.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
//判断是否拥有店铺
|
//判断是否拥有店铺
|
||||||
if (member.getHaveStore()) {
|
if (Boolean.TRUE.equals(member.getHaveStore())) {
|
||||||
throw new ServiceException(ResultCode.STORE_APPLY_DOUBLE_ERROR);
|
throw new ServiceException(ResultCode.STORE_APPLY_DOUBLE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +139,7 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
|||||||
if (storeEditDTO != null) {
|
if (storeEditDTO != null) {
|
||||||
//判断店铺名是否唯一
|
//判断店铺名是否唯一
|
||||||
Store storeTmp = getOne(new QueryWrapper<Store>().eq("store_name", storeEditDTO.getStoreName()));
|
Store storeTmp = getOne(new QueryWrapper<Store>().eq("store_name", storeEditDTO.getStoreName()));
|
||||||
if (storeTmp != null && !StringUtils.equals(storeTmp.getId(), storeEditDTO.getStoreId())) {
|
if (storeTmp != null && !CharSequenceUtil.equals(storeTmp.getId(), storeEditDTO.getStoreId())) {
|
||||||
throw new ServiceException(ResultCode.STORE_NAME_EXIST_ERROR);
|
throw new ServiceException(ResultCode.STORE_NAME_EXIST_ERROR);
|
||||||
}
|
}
|
||||||
//修改店铺详细信息
|
//修改店铺详细信息
|
||||||
@ -160,7 +161,10 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
|||||||
if (store != null) {
|
if (store != null) {
|
||||||
BeanUtil.copyProperties(storeEditDTO, store);
|
BeanUtil.copyProperties(storeEditDTO, store);
|
||||||
store.setId(storeEditDTO.getStoreId());
|
store.setId(storeEditDTO.getStoreId());
|
||||||
this.updateById(store);
|
boolean result = this.updateById(store);
|
||||||
|
if (result) {
|
||||||
|
storeDetailService.updateStoreGoodsInfo(store);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
@ -232,7 +236,8 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
|||||||
Store store = getStoreByMember();
|
Store store = getStoreByMember();
|
||||||
//如果没有申请过店铺,新增店铺
|
//如果没有申请过店铺,新增店铺
|
||||||
if (!Optional.ofNullable(store).isPresent()) {
|
if (!Optional.ofNullable(store).isPresent()) {
|
||||||
Member member = memberService.getById(UserContext.getCurrentUser().getId());
|
AuthUser authUser = Objects.requireNonNull(UserContext.getCurrentUser());
|
||||||
|
Member member = memberService.getById(authUser.getId());
|
||||||
store = new Store(member);
|
store = new Store(member);
|
||||||
BeanUtil.copyProperties(storeCompanyDTO, store);
|
BeanUtil.copyProperties(storeCompanyDTO, store);
|
||||||
this.save(store);
|
this.save(store);
|
||||||
@ -336,11 +341,12 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
|
|||||||
/**
|
/**
|
||||||
* 获取当前登录操作的店铺
|
* 获取当前登录操作的店铺
|
||||||
*
|
*
|
||||||
* @return
|
* @return 店铺信息
|
||||||
*/
|
*/
|
||||||
private Store getStoreByMember() {
|
private Store getStoreByMember() {
|
||||||
|
AuthUser authUser = Objects.requireNonNull(UserContext.getCurrentUser());
|
||||||
LambdaQueryWrapper<Store> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<Store> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
||||||
lambdaQueryWrapper.eq(Store::getMemberId, UserContext.getCurrentUser().getId());
|
lambdaQueryWrapper.eq(Store::getMemberId, authUser.getId());
|
||||||
return this.getOne(lambdaQueryWrapper);
|
return this.getOne(lambdaQueryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,11 @@ public enum GoodsTagsEnum {
|
|||||||
* "更新商品索引"
|
* "更新商品索引"
|
||||||
*/
|
*/
|
||||||
UPDATE_GOODS_INDEX("更新商品索引"),
|
UPDATE_GOODS_INDEX("更新商品索引"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "更新商品索引部分字段"
|
||||||
|
*/
|
||||||
|
UPDATE_GOODS_INDEX_FIELD("更新商品索引部分字段"),
|
||||||
/**
|
/**
|
||||||
* "重置商品索引"
|
* "重置商品索引"
|
||||||
*/
|
*/
|
||||||
|
@ -90,6 +90,7 @@ public class ElasticsearchController {
|
|||||||
cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null);
|
cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null);
|
||||||
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), true);
|
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), true);
|
||||||
ThreadUtil.execAsync(() -> {
|
ThreadUtil.execAsync(() -> {
|
||||||
|
try {
|
||||||
//查询商品信息
|
//查询商品信息
|
||||||
LambdaQueryWrapper<GoodsSku> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<GoodsSku> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(GoodsSku::getIsAuth, GoodsAuthEnum.PASS.name());
|
queryWrapper.eq(GoodsSku::getIsAuth, GoodsAuthEnum.PASS.name());
|
||||||
@ -129,6 +130,10 @@ public class ElasticsearchController {
|
|||||||
}
|
}
|
||||||
//初始化商品索引
|
//初始化商品索引
|
||||||
esGoodsIndexService.initIndex(esGoodsIndices);
|
esGoodsIndexService.initIndex(esGoodsIndices);
|
||||||
|
} catch (Exception e) {
|
||||||
|
cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null);
|
||||||
|
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@ package cn.lili.controller.store;
|
|||||||
import cn.lili.common.enums.ResultUtil;
|
import cn.lili.common.enums.ResultUtil;
|
||||||
import cn.lili.common.vo.PageVO;
|
import cn.lili.common.vo.PageVO;
|
||||||
import cn.lili.common.vo.ResultMessage;
|
import cn.lili.common.vo.ResultMessage;
|
||||||
import cn.lili.modules.goods.entity.vos.CategoryVO;
|
|
||||||
import cn.lili.modules.store.entity.dos.Store;
|
import cn.lili.modules.store.entity.dos.Store;
|
||||||
import cn.lili.modules.store.entity.dto.AdminStoreApplyDTO;
|
import cn.lili.modules.store.entity.dto.AdminStoreApplyDTO;
|
||||||
import cn.lili.modules.store.entity.dto.StoreEditDTO;
|
import cn.lili.modules.store.entity.dto.StoreEditDTO;
|
||||||
import cn.lili.modules.store.entity.vos.StoreDetailVO;
|
import cn.lili.modules.store.entity.vos.StoreDetailVO;
|
||||||
|
import cn.lili.modules.store.entity.vos.StoreManagementCategoryVO;
|
||||||
import cn.lili.modules.store.entity.vos.StoreSearchParams;
|
import cn.lili.modules.store.entity.vos.StoreSearchParams;
|
||||||
import cn.lili.modules.store.entity.vos.StoreVO;
|
import cn.lili.modules.store.entity.vos.StoreVO;
|
||||||
import cn.lili.modules.store.service.StoreDetailService;
|
import cn.lili.modules.store.service.StoreDetailService;
|
||||||
@ -112,7 +112,7 @@ public class StoreManagerController {
|
|||||||
@ApiOperation(value = "查询一级分类列表")
|
@ApiOperation(value = "查询一级分类列表")
|
||||||
@ApiImplicitParam(name = "storeId", value = "店铺id", required = true, dataType = "String", paramType = "path")
|
@ApiImplicitParam(name = "storeId", value = "店铺id", required = true, dataType = "String", paramType = "path")
|
||||||
@GetMapping(value = "/managementCategory/{storeId}")
|
@GetMapping(value = "/managementCategory/{storeId}")
|
||||||
public ResultMessage<List<CategoryVO>> firstCategory(@PathVariable String storeId) {
|
public ResultMessage<List<StoreManagementCategoryVO>> firstCategory(@PathVariable String storeId) {
|
||||||
return ResultUtil.data(this.storeDetailService.goodsManagementCategory(storeId));
|
return ResultUtil.data(this.storeDetailService.goodsManagementCategory(storeId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user