Price 价格服务的编写
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
package cn.iocoder.mall.promotion.api.rpc.activity.dto;
|
||||
package cn.iocoder.mall.promotion.api.rpc.activity;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface PromotionActivityRpc {
|
||||
|
||||
List<PromotionActivityRespDTO> getPromotionActivityListBySpuId(Integer spuId,
|
||||
Collection<Integer> activityStatuses);
|
||||
// List<PromotionActivityRespDTO> getPromotionActivityListBySpuId(Integer spuId,
|
||||
// Collection<Integer> activityStatuses);
|
||||
//
|
||||
// List<PromotionActivityRespDTO> getPromotionActivityListBySpuIds(Collection<Integer> spuIds,
|
||||
// Collection<Integer> activityStatuses);
|
||||
//
|
||||
// PromotionActivityPageReqDTO getPromotionActivityPage(PromotionActivityPageRespDTO promotionActivityPageDTO);
|
||||
|
||||
List<PromotionActivityRespDTO> getPromotionActivityListBySpuIds(Collection<Integer> spuIds,
|
||||
Collection<Integer> activityStatuses);
|
||||
|
||||
PromotionActivityPageReqDTO getPromotionActivityPage(PromotionActivityPageRespDTO promotionActivityPageDTO);
|
||||
CommonResult<List<PromotionActivityRespDTO>> listPromotionActivities(PromotionActivityListReqDTO listReqDTO);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.mall.promotion.api.rpc.activity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 促销活动列表查询的 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class PromotionActivityListReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 活动编号数组
|
||||
*/
|
||||
private Collection<Integer> activeIds;
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 促销伙伴 Response DTO
|
||||
* 促销活动 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
|
||||
@@ -41,18 +41,26 @@ public class PriceProductCalcReqDTO implements Serializable {
|
||||
/**
|
||||
* SKU 编号
|
||||
*/
|
||||
@NotNull(message = "商品 SKU 编号不能为空")
|
||||
private Integer skuId;
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
@NotNull(message = "商品 SKU 数量不能为空")
|
||||
private Integer quantity;
|
||||
/**
|
||||
* 是否选中
|
||||
*/
|
||||
@NotNull(message = "是否选中不能为空")
|
||||
private Boolean selected;
|
||||
|
||||
public Item() {
|
||||
}
|
||||
|
||||
public Item(Integer skuId, Integer quantity) {
|
||||
public Item(Integer skuId, Integer quantity, Boolean selected) {
|
||||
this.skuId = skuId;
|
||||
this.quantity = quantity;
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cn.iocoder.mall.promotion.api.rpc.price.dto;
|
||||
|
||||
import cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -57,7 +56,7 @@ public class PriceProductCalcRespDTO implements Serializable {
|
||||
*
|
||||
* // TODO 芋艿,目前只会有【满减送】的情况,未来有新的促销方式,可能需要改成数组
|
||||
*/
|
||||
private PromotionActivityRespDTO activity;
|
||||
private Integer activityId;
|
||||
/**
|
||||
* 促销减少的金额
|
||||
*
|
||||
@@ -94,6 +93,13 @@ public class PriceProductCalcRespDTO implements Serializable {
|
||||
* 商品 Category 编号
|
||||
*/
|
||||
private Integer cid;
|
||||
|
||||
// 非 SKU 自带信息
|
||||
|
||||
/**
|
||||
* 是否选中
|
||||
*/
|
||||
private Boolean selected;
|
||||
/**
|
||||
* 购买数量
|
||||
*/
|
||||
@@ -103,7 +109,7 @@ public class PriceProductCalcRespDTO implements Serializable {
|
||||
*
|
||||
* 目前会有限时折扣 {@link PromotionActivityTypeEnum#TIME_LIMITED_DISCOUNT} 类型的活动
|
||||
*/
|
||||
private PromotionActivityRespDTO activity;
|
||||
private Integer activityId;
|
||||
/**
|
||||
* 原始单价,单位:分。
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.iocoder.mall.promotionservice.dal.mysql.mapper.activity;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
|
||||
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity.PromotionActivityDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@@ -26,4 +28,8 @@ public interface PromotionActivityMapper extends BaseMapper<PromotionActivityDO>
|
||||
@Param("activityType") Integer activityType,
|
||||
@Param("statuses") Collection<Integer> statuses);
|
||||
|
||||
default List<PromotionActivityDO> selectList(PromotionActivityListReqDTO listReqDTO) {
|
||||
return selectList(new QueryWrapperX<PromotionActivityDO>().inIfPresent("id", listReqDTO.getActiveIds()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.promotionservice.manager.activity;
|
||||
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
|
||||
import cn.iocoder.mall.promotionservice.service.activity.PromotionActivityService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 促销活动 Manager
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class PromotionActivityManager {
|
||||
|
||||
@Autowired
|
||||
private PromotionActivityService promotionActivityService;
|
||||
|
||||
public List<PromotionActivityRespDTO> listPromotionActivities(PromotionActivityListReqDTO listReqDTO) {
|
||||
return promotionActivityService.listPromotionActivities(listReqDTO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.manager;
|
||||
@@ -134,7 +134,7 @@ public class PriceManager {
|
||||
continue;
|
||||
}
|
||||
// 设置优惠
|
||||
item.setActivity(timeLimitedDiscount);
|
||||
item.setActivityId(timeLimitedDiscount.getId());
|
||||
// 设置价格
|
||||
item.setBuyPrice(newBuyPrice);
|
||||
item.setBuyTotal(newBuyPrice * item.getBuyQuantity());
|
||||
@@ -186,7 +186,7 @@ public class PriceManager {
|
||||
for (PromotionActivityRespDTO fullPrivilege : fullPrivileges) {
|
||||
// 创建 fullPrivilege 对应的分组
|
||||
PriceProductCalcRespDTO.ItemGroup itemGroup = new PriceProductCalcRespDTO.ItemGroup()
|
||||
.setActivity(fullPrivilege)
|
||||
.setActivityId(fullPrivilege.getId())
|
||||
.setItems(new ArrayList<>());
|
||||
// 筛选商品到分组中
|
||||
for (Iterator<PriceProductCalcRespDTO.Item> iterator = items.iterator(); iterator.hasNext(); ) {
|
||||
@@ -208,8 +208,9 @@ public class PriceManager {
|
||||
itemGroups.add(new PriceProductCalcRespDTO.ItemGroup().setItems(items));
|
||||
}
|
||||
// 计算每个分组的价格
|
||||
Map<Integer, PromotionActivityRespDTO> activityMap = CollectionUtils.convertMap(activityList, PromotionActivityRespDTO::getId);
|
||||
for (PriceProductCalcRespDTO.ItemGroup itemGroup : itemGroups) {
|
||||
itemGroup.setActivityDiscountTotal(calcSkuPriceByFullPrivilege(itemGroup));
|
||||
itemGroup.setActivityDiscountTotal(calcSkuPriceByFullPrivilege(itemGroup, activityMap.get(itemGroup.getActivityId())));
|
||||
}
|
||||
// 返回结果
|
||||
return itemGroups;
|
||||
@@ -227,11 +228,10 @@ public class PriceManager {
|
||||
throw new IllegalArgumentException(String.format("促销活动(%s) 可用范围的类型是不正确", activity.toString()));
|
||||
}
|
||||
|
||||
private Integer calcSkuPriceByFullPrivilege(PriceProductCalcRespDTO.ItemGroup itemGroup) {
|
||||
if (itemGroup.getActivity() == null) {
|
||||
private Integer calcSkuPriceByFullPrivilege(PriceProductCalcRespDTO.ItemGroup itemGroup, PromotionActivityRespDTO activity) {
|
||||
if (itemGroup.getActivityId() == null) {
|
||||
return null;
|
||||
}
|
||||
PromotionActivityRespDTO activity = itemGroup.getActivity();
|
||||
Assert.isTrue(PromotionActivityTypeEnum.FULL_PRIVILEGE.getValue().equals(activity.getActivityType()),
|
||||
"传入的必须的满减送活动必须是满减送");
|
||||
// 获得优惠信息
|
||||
@@ -246,7 +246,8 @@ public class PriceManager {
|
||||
if (MeetTypeEnum.QUANTITY.getValue().equals(privilege.getMeetType())) {
|
||||
return itemCnt >= privilege.getMeetValue();
|
||||
}
|
||||
throw new IllegalArgumentException(String.format("满减送活动(%s) 的匹配(%s)不正确", itemGroup.getActivity().toString(), privilege.toString()));
|
||||
throw new IllegalArgumentException(String.format("满减送活动(%s) 的匹配(%s)不正确",
|
||||
activity.toString(), privilege.toString()));
|
||||
}).collect(Collectors.toList());
|
||||
// 获得不到优惠信息,返回原始价格
|
||||
if (privileges.isEmpty()) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.promotionservice.rpc.activity;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityRpc;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
|
||||
import cn.iocoder.mall.promotionservice.manager.activity.PromotionActivityManager;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@DubboService
|
||||
public class PromotionActivityRpcImpl implements PromotionActivityRpc {
|
||||
|
||||
@Autowired
|
||||
private PromotionActivityManager promotionActivityManager;
|
||||
|
||||
@Override
|
||||
public CommonResult<List<PromotionActivityRespDTO>> listPromotionActivities(PromotionActivityListReqDTO listReqDTO) {
|
||||
return success(promotionActivityManager.listPromotionActivities(listReqDTO));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.rpc;
|
||||
@@ -2,6 +2,7 @@ package cn.iocoder.mall.promotionservice.service.activity;
|
||||
|
||||
import cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
|
||||
import cn.iocoder.mall.promotionservice.convert.activity.PromotionActivityConvert;
|
||||
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity.PromotionActivityDO;
|
||||
@@ -25,24 +26,15 @@ public class PromotionActivityService {
|
||||
@Autowired
|
||||
private PromotionActivityMapper promotionActivityMapper;
|
||||
|
||||
/**
|
||||
* 获取指定商品
|
||||
*
|
||||
* @param spuId
|
||||
* @param activityStatuses
|
||||
* @return
|
||||
*/
|
||||
public List<PromotionActivityRespDTO> listPromotionActivities(PromotionActivityListReqDTO listReqDTO) {
|
||||
List<PromotionActivityDO> activityList = promotionActivityMapper.selectList(listReqDTO);
|
||||
return PromotionActivityConvert.INSTANCE.convertList(activityList);
|
||||
}
|
||||
|
||||
public List<PromotionActivityRespDTO> listPromotionActivitiesBySpuId(Integer spuId, Collection<Integer> activityStatuses) {
|
||||
return this.listPromotionActivitiesBySpuIds(Collections.singleton(spuId), activityStatuses);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param spuIds
|
||||
* @param activityStatuses
|
||||
* @return
|
||||
*/
|
||||
public List<PromotionActivityRespDTO> listPromotionActivitiesBySpuIds(Collection<Integer> spuIds, Collection<Integer> activityStatuses) {
|
||||
if (spuIds.isEmpty() || activityStatuses.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -13,7 +13,7 @@ import cn.iocoder.mall.promotionservice.dal.mysql.mapper.recommend.ProductRecomm
|
||||
import cn.iocoder.mall.promotionservice.service.recommend.bo.ProductRecommendAddBO;
|
||||
import cn.iocoder.mall.promotionservice.service.recommend.bo.ProductRecommendBO;
|
||||
import cn.iocoder.mall.promotionservice.service.recommend.bo.ProductRecommendUpdateBO;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
@Validated
|
||||
public class ProductRecommendService {
|
||||
|
||||
@Reference(validation = "true", version = "${dubbo.consumer.ProductSpuService.version}")
|
||||
@DubboReference(validation = "true", version = "${dubbo.consumer.ProductSpuRpc.version}")
|
||||
private ProductSpuRpc productSpuRpc;
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user