fix promotion优惠券工程继续迁移,未完成,再提交下

pull/4/MERGE
wuwenbin 2020-07-26 17:45:01 +08:00
parent ac5ab0b70b
commit 67f8b61f47
24 changed files with 1219 additions and 6 deletions

View File

@ -3,7 +3,7 @@ package cn.iocoder.mall.promotion.api.rpc.activity.dto;
import java.util.Collection;
import java.util.List;
public interface PromotionActivityService {
public interface PromotionActivityRpc {
List<PromotionActivityRespDTO> getPromotionActivityListBySpuId(Integer spuId,
Collection<Integer> activityStatuses);

View File

@ -10,7 +10,7 @@ import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerUpdateReqDTO;
import java.util.List;
public interface BannerService {
public interface BannerRpc {
List<BannerRespDTO> getBannerListByStatus(Integer status);

View File

@ -7,7 +7,7 @@ import cn.iocoder.mall.promotion.api.rpc.coupon.dto.*;
import javax.validation.constraints.NotNull;
import java.util.List;
public interface CouponService {
public interface CouponRpc {
// ========== 优惠劵(码)模板 ==========

View File

@ -1,6 +1,6 @@
package cn.iocoder.mall.promotion.api.rpc.coupon.dto;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponService;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponRpc;
import lombok.Data;
import lombok.experimental.Accessors;
@ -10,7 +10,7 @@ import java.util.List;
/**
* DTO
*
* {@link CouponService#getCouponCardList(Integer, List)}
* {@link CouponRpc#getCouponCardList(Integer, List)}
*/
@Data
@Accessors(chain = true)

View File

@ -6,7 +6,7 @@ import cn.iocoder.common.framework.validator.InEnum;
import java.util.List;
public interface ProductRecommendService {
public interface ProductRecommendRpc {
List<ProductRecommendRespDTO> getProductRecommendList(Integer type, Integer status);

View File

@ -12,10 +12,40 @@
<artifactId>promotion-service-app</artifactId>
<dependencies>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-dubbo</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-service-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-mybatis</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,14 @@
package cn.iocoder.mall.promotionservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class PromotionServiceApplication {
public static void main(String[] args) {
SpringApplication.run(PromotionServiceApplication.class, args);
}
}

View File

@ -0,0 +1,9 @@
package cn.iocoder.mall.promotionservice.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
@Configuration
@EnableAsync(proxyTargetClass = true) // 开启 Spring Async 异步的功能
public class AsyncConfiguration {
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.mall.promotionservice.config;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@MapperScan("cn.iocoder.mall.promotionservice.dal.mysql.mapper") // 扫描对应的 Mapper 接口
@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。
public class DatabaseConfiguration {
// 数据库连接池 Druid
@Bean
public ISqlInjector sqlInjector() {
return new DefaultSqlInjector(); // MyBatis Plus 逻辑删除
}
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor(); // MyBatis Plus 分页插件
}
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.mall.promotionservice.convert.activity;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity.PromotionActivityDO;
import cn.iocoder.mall.promotionservice.service.activity.bo.PromotionActivityBO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface PromotionActivityConvert {
PromotionActivityConvert INSTANCE = Mappers.getMapper(PromotionActivityConvert.class);
@Mappings({})
PromotionActivityBO convertToBO(PromotionActivityDO activity);
@Mappings({})
List<PromotionActivityBO> convertToBO(List<PromotionActivityDO> activityList);
@Mappings({})
List<PromotionActivityDO> convertToDO(List<PromotionActivityBO> activityList);
@Mappings({})
List<PromotionActivityRespDTO> convertToRespDTO(List<PromotionActivityDO> activityList);
// @Mappings({})
// PromotionActivityDO convert(PromotionActivityAddDTO activityAddDTO);
//
// @Mappings({})
// PromotionActivityDO convert(PromotionActivityUpdateDTO activityUpdateDTO);
}

View File

@ -0,0 +1,188 @@
package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity;
import cn.iocoder.mall.mybatis.core.dataobject.BaseDO;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
import java.util.List;
/**
* DO
*/
@Data
@Accessors(chain = true)
public class PromotionActivityDO extends DeletableDO {
/**
*
*/
private Integer id;
/**
*
*/
private String title;
/**
*
*
* {@link cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum}
*/
private Integer activityType;
// /**
// * 促销类型
// * // TODO 芋艿 https://jos.jd.com/api/complexTemplate.htm?webPamer=promotion_v_o&groupName=%E4%BF%83%E9%94%80API&id=54&restName=jingdong.seller.promotion.list&isMulti=false 促销类型可选值单品促销1赠品促销4套装促销6总价促销10
// */
// private Integer promotionType;
/**
*
*
* {@link cn.iocoder.mall.promotion.api.enums.PromotionActivityStatusEnum}
*/
private Integer status;
/**
*
*/
private Date startTime;
/**
*
*/
private Date endTime;
/**
*
*/
private Date invalidTime;
/**
*
*/
private Date deleteTime;
/**
* 使 JSON
*/
private TimeLimitedDiscount timeLimitedDiscount;
/**
* 使 JSON
*/
private FullPrivilege fullPrivilege;
/**
*
*/
@Data
@Accessors(chain = true)
public static class TimeLimitedDiscount {
/**
*
*/
@Data
@Accessors(chain = true)
public static class Item {
/**
* SPU
*/
private Integer spuId;
/**
*
*/
private Integer preferentialType;
/**
*
*/
private Integer preferentialValue;
}
/**
*
*
* quota = 0
*/
private Integer quota;
/**
*
*/
private List<Item> items;
}
/**
*
*/
@Data
@Accessors(chain = true)
public static class FullPrivilege {
/**
*
*/
@Data
@Accessors(chain = true)
public static class Privilege {
/**
*
*
* 1 -
* 2 -
*/
private Integer meetType;
/**
*
*/
private Integer meetValue;
/**
*
*/
private Integer preferentialType;
/**
*
*/
private Integer preferentialValue;
// /**
// * 是否包邮
// */
// private Boolean isPostage;
// /**
// * 积分
// */
// private Integer score;
// /**
// * 优惠劵(码)分组编号
// */
// private Integer couponTemplateId;
// /**
// * 优惠劵(码)数量
// */
// private Integer couponNum;
// /**
// * 赠品编号
// */
// private Integer presentId;
}
/**
*
*
* {@link cn.iocoder.mall.promotion.api.enums.RangeTypeEnum}
* + PRODUCT_INCLUDE_PRT
*/
private Integer rangeType;
/**
*
*/
private List<Integer> rangeValues;
/**
*
*/
private Boolean cycled;
/**
*
*/
private List<Privilege> privileges;
}
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.banner;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* Banner 广
*/
@Data
@Accessors(chain = true)
public class BannerDO extends DeletableDO {
/**
*
*/
private Integer id;
/**
*
*/
private String title;
/**
*
*/
private String url;
/**
*
*/
private String picUrl;
/**
*
*/
private Integer sort;
/**
*
*
* {@link cn.iocoder.common.framework.enums.CommonStatusEnum}
*/
private Integer status;
/**
*
*/
private String memo;
// TODO 芋艿 点击次数。&& 其他数据相关
}

View File

@ -0,0 +1,119 @@
package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon;
import cn.iocoder.mall.mybatis.core.dataobject.BaseDO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* DO
*/
@Data
@Accessors(chain = true)
public class CouponCardDO extends BaseDO {
// ========== 基本信息 BEGIN ==========
/**
*
*/
private Integer id;
/**
* {@link CouponTemplateDO} id
*/
private Integer templateId;
/**
*
*
* {@link CouponTemplateDO} title
*
* TODO
*/
private String title;
// /**
// * 核销码
// */
// private String verifyCode;
/**
*
*
* 1-使
* 2-使
* 3-
*/
private Integer status;
// ========== 基本信息 END ==========
// ========== 领取情况 BEGIN ==========
/**
*
*/
private Integer userId;
/**
*
*
* 1 -
* 2 -
*/
private Integer takeType;
// ========== 领取情况 END ==========
// ========== 使用规则 BEGIN ==========
/**
*
*/
private Integer priceAvailable;
/**
*
*/
private Date validStartTime;
/**
*
*/
private Date validEndTime;
// ========== 使用规则 END ==========
// ========== 使用效果 BEGIN ==========
/**
*
*
* 1-
* 2-
*/
private Integer preferentialType;
/**
*
*/
private Integer percentOff;
/**
*
*/
private Integer priceOff;
/**
* {@link #preferentialType} 2
*
* 20 使 8 1000 20 80
*/
private Integer discountPriceLimit;
// ========== 使用效果 END ==========
// ========== 使用情况 BEGIN ==========
// /**
// * 使用订单号
// */
// private Integer usedOrderId; // TODO 芋艿,暂时不考虑这个字段
// /**
// * 订单中优惠面值,单位:分
// */
// private Integer usedPrice; // TODO 芋艿,暂时不考虑这个字段
/**
* 使
*/
private Date usedTime;
// TODO 芋艿,后续要加优惠劵的使用日志,因为下单后,可能会取消。
// ========== 使用情况 END ==========
}

View File

@ -0,0 +1,43 @@
package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon;
import cn.iocoder.mall.mybatis.core.dataobject.BaseDO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
*
*/
@Data
@Accessors(chain = true)
public class CouponCodeDO extends BaseDO {
/**
*
*/
private Integer id;
/**
* {@link CouponTemplateDO} id
*/
private Integer templateId;
/**
*
*/
private Integer code;
/**
*
*/
private Date takeTime;
/**
*
*/
private Integer userId;
/**
*
*/
private Integer couponId;
// TODO 芋艿,后续要考虑状态的追踪
}

View File

@ -0,0 +1,220 @@
package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon;
import cn.iocoder.mall.mybatis.core.dataobject.BaseDO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* DO
*
* {@link CouponCardDO}
*/
@Data
@Accessors(chain = true)
public class CouponTemplateDO extends BaseDO {
// ========== 基本信息 BEGIN ==========
/**
*
*/
private Integer id;
/**
*
*/
private String title;
/**
* 使
*/
private String description;
/**
*
*
* 1-
* 2-
*/
private Integer type;
/**
*
*
* {@link cn.iocoder.mall.promotion.api.enums.CouponTemplateStatusEnum}
*
*
*/
private Integer status;
// /**
// * 是否可分享领取链接
// */
// private Boolean isShare;
// /**
// * 设置为失效时间
// */
// private Date invalidTime;
// /**
// * 删除时间
// */
// private Date deleteTime;
// ========== 基本信息 END ==========
// ========== 领取规则 BEGIN ==========
// /**
// * 是否限制领用者的等级
// *
// * 0-不限制
// * 大于0-领用者必须是这个等级编号
// *
// * 【优惠劵独有】
// */
// private Integer needUserLevel;
/**
*
*
* null -
*/
private Integer quota;
/**
*
*/
private Integer total;
// ========== 领取规则 END ==========
// ========== 使用规则 BEGIN ==========
// /**
// * 是否仅原价购买商品时可用
// *
// * true-是
// * false-否
// */
// private Boolean isForbidPreference;
/**
*
*
* 0-
* 0-
*/
private Integer priceAvailable;
/**
*
*
* 10-ALL
* 20-PART
* 21-PART
* 30-PART
* 31-PART
*/
private Integer rangeType;
/**
* / 使
*/
private String rangeValues;
/**
*
*
* 1-
* 2- {@link #fixedStartTerm} N
*/
private Integer dateType;
/**
* -
*/
private Date validStartTime;
/**
* -
*/
private Date validEndTime;
/**
* -
*
* 0-1-
*/
private Integer fixedStartTerm;
/**
* -
*/
private Integer fixedEndTerm;
// /**
// * 是否到期前4天发送提醒
// *
// * true-发送
// * false-不发送
// */
// private Boolean expireNotice;
// ========== 使用规则 END ==========
// ========== 使用效果 BEGIN ==========
/**
*
*
* 1-
* 2-
*/
private Integer preferentialType;
/**
*
*
* 80% 80
* 100% 100
*/
private Integer percentOff;
// /**
// * 是否是随机优惠券
// *
// * true-随机
// * false-不随机
// *
// * 【优惠劵独有】
// */
// private Boolean isRandom;
/**
*
*/
// * 当 {@link #isRandom} 为 true 时,代表随机优惠金额的下限
private Integer priceOff;
// /**
// * 优惠金额上限
// *
// * 【优惠劵独有】
// */
// private Integer valueRandomTo;
/**
* {@link #preferentialType} 2
*
* 20 使 8 1000 20 80
*/
private Integer discountPriceLimit;
// ========== 使用效果 END ==========
// ========== 统计信息 BEGIN ==========
// /**
// * 领取优惠券的人数
// */
// private Integer statFetchUserNum;
/**
*
*/
private Integer statFetchNum;
// /**
// * 使用优惠券的次数
// */
// private Integer statUseNum;
// ========== 统计信息 END ==========
// ========== 优惠码 BEGIN ==========
/**
*
*
* 1-UNIQUE
* 2-GENERAL
*
* @see CouponCodeDO
*/
private Integer codeType;
/**
*
*/
private String commonCode;
// ========== 优惠码 BEGIN ==========
}

View File

@ -0,0 +1,46 @@
package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import cn.iocoder.mall.promotion.api.enums.ProductRecommendTypeEnum;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* DO
*/
@Data
@Accessors(chain = true)
public class ProductRecommendDO extends DeletableDO {
/**
*
*/
private Integer id;
/**
*
*
* {@link ProductRecommendTypeEnum}
*/
private Integer type;
/**
* Spu
*/
private Integer productSpuId;
// TODO 芋艿,商品 spu 名
/**
*
*/
private Integer sort;
/**
*
*
* {@link cn.iocoder.common.framework.enums.CommonStatusEnum}
*/
private Integer status;
/**
*
*/
private String memo;
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.mall.promotionservice.dal.mysql.mapper.activity;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity.PromotionActivityDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
@Repository
public interface PromotionActivityMapper {
PromotionActivityDO selectById(@Param("id") Integer id);
List<PromotionActivityDO> selectListByStatus(@Param("statuses") Collection<Integer> statuses);
void insert(PromotionActivityDO activity);
List<PromotionActivityDO> selectListByPage(@Param("title") String title,
@Param("activityType") Integer activityType,
@Param("statuses") Collection<Integer> statuses,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByPage(@Param("title") String title,
@Param("activityType") Integer activityType,
@Param("statuses") Collection<Integer> statuses);
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.mall.promotionservice.dal.mysql.mapper.banner;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.banner.BannerDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface BannerMapper {
BannerDO selectById(@Param("id") Integer id);
List<BannerDO> selectListByStatus(@Param("status") Integer status);
List<BannerDO> selectListByTitleLike(@Param("title") String title,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByTitleLike(@Param("title") String title);
void insert(BannerDO bannerDO);
int update(BannerDO bannerDO);
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponCardDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface CouponCardMapper {
CouponCardDO selectById(@Param("id") Integer id);
List<CouponCardDO> selectListByUserIdAndStatus(@Param("userId") Integer userId,
@Param("status") Integer status);
List<CouponCardDO> selectListByPage(@Param("userId") Integer userId,
@Param("status") Integer status,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByPage(@Param("userId") Integer userId,
@Param("status") Integer status);
int selectCountByUserIdAndTemplateId(@Param("userId") Integer userId,
@Param("templateId") Integer templateId);
void insert(CouponCardDO couponCardDO);
int update(CouponCardDO couponCardDO);
int updateByIdAndStatus(@Param("id") Integer id,
@Param("status") Integer status,
@Param("updateObj") CouponCardDO updateObj);
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponTemplateDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
@Repository
public interface CouponTemplateMapper {
CouponTemplateDO selectById(@Param("id") Integer id);
List<CouponTemplateDO> selectListByIds(@Param("ids") Collection<Integer> ids);
List<CouponTemplateDO> selectListByPage(@Param("type") Integer type,
@Param("title") String title,
@Param("status") Integer status,
@Param("preferentialType") Integer preferentialType,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByPage(@Param("type") Integer type,
@Param("title") String title,
@Param("status") Integer status,
@Param("preferentialType") Integer preferentialType);
void insert(CouponTemplateDO couponTemplate);
int update(CouponTemplateDO couponTemplate);
int updateStatFetchNumIncr(@Param("id") Integer id);
}

View File

@ -0,0 +1,30 @@
package cn.iocoder.mall.promotionservice.dal.mysql.mapper.recommend;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend.ProductRecommendDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ProductRecommendMapper {
ProductRecommendDO selectById(@Param("id") Integer id);
ProductRecommendDO selectByProductSpuIdAndType(@Param("productSpuId") Integer productSpuId,
@Param("type") Integer type);
List<ProductRecommendDO> selectListByTypeAndStatus(@Param("type") Integer type,
@Param("status") Integer status);
List<ProductRecommendDO> selectPageByType(@Param("type") Integer type,
@Param("offset") Integer offset,
@Param("limit") Integer limit);
Integer selectCountByType(@Param("type") Integer type);
void insert(ProductRecommendDO bannerDO);
int update(ProductRecommendDO bannerDO);
}

View File

@ -0,0 +1,102 @@
package cn.iocoder.mall.promotionservice.service.activity;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
import cn.iocoder.mall.promotionservice.convert.activity.PromotionActivityConvert;
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity.PromotionActivityDO;
import cn.iocoder.mall.promotionservice.dal.mysql.mapper.activity.PromotionActivityMapper;
import cn.iocoder.mall.promotionservice.service.activity.bo.PromotionActivityPageBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@Service
@Validated
public class PromotionActivityService {
@Autowired
private PromotionActivityMapper promotionActivityMapper;
public List<PromotionActivityDO> getPromotionActivityListBySpuId(Integer spuId, Collection<Integer> activityStatuses) {
return this.getPromotionActivityListBySpuIds(Collections.singleton(spuId), activityStatuses);
}
public List<PromotionActivityDO> getPromotionActivityListBySpuIds(Collection<Integer> spuIds, Collection<Integer> activityStatuses) {
if (spuIds.isEmpty() || activityStatuses.isEmpty()) {
return Collections.emptyList();
}
// 查询指定状态的促销活动
List<PromotionActivityDO> activityList = promotionActivityMapper.selectListByStatus(activityStatuses);
if (activityList.isEmpty()) {
return Collections.emptyList();
}
// 匹配商品
for (Iterator<PromotionActivityDO> iterator = activityList.iterator(); iterator.hasNext();) {
PromotionActivityDO activity = iterator.next();
boolean matched = false;
for (Integer spuId : spuIds) {
if (PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT.getValue().equals(activity.getActivityType())) {
matched = isSpuMatchTimeLimitDiscount(spuId, activity);
} else if (PromotionActivityTypeEnum.FULL_PRIVILEGE.getValue().equals(activity.getActivityType())) {
matched = isSpuMatchFullPrivilege(spuId, activity);
}
if (matched) {
break;
}
}
// 不匹配,则进行移除
if (!matched) {
iterator.remove();
} else { // 匹配,则做一些后续的处理
// 如果是限时折扣,移除不在 spuId 数组中的折扣规则
if (PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT.getValue().equals(activity.getActivityType())) {
activity.getTimeLimitedDiscount().getItems().removeIf(item -> !spuIds.contains(item.getSpuId()));
}
}
}
// 返回最终结果
return activityList;
}
public PromotionActivityPageBO getPromotionActivityPage(Integer pageNo,Integer pageSize,String title,Integer activityType,Collection<Integer> statuses) {
PromotionActivityPageBO promotionActivityPageBO = new PromotionActivityPageBO();
// 查询分页数据
int offset = (pageNo - 1) * pageSize;
promotionActivityPageBO.setList(PromotionActivityConvert.INSTANCE.convertToRespDTO(promotionActivityMapper.selectListByPage(
title, activityType,statuses, offset, pageSize)));
// 查询分页总数
promotionActivityPageBO.setTotal(promotionActivityMapper.selectCountByPage(
title,activityType,statuses));
return promotionActivityPageBO;
}
private boolean isSpuMatchTimeLimitDiscount(Integer spuId, PromotionActivityDO activity) {
Assert.isTrue(PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT.getValue().equals(activity.getActivityType()),
"传入的必须的促销活动必须是限时折扣");
return activity.getTimeLimitedDiscount().getItems().stream()
.anyMatch(item -> spuId.equals(item.getSpuId()));
}
private boolean isSpuMatchFullPrivilege(Integer spuId, PromotionActivityDO activity) {
Assert.isTrue(PromotionActivityTypeEnum.FULL_PRIVILEGE.getValue().equals(activity.getActivityType()),
"传入的必须的促销活动必须是满减送");
PromotionActivityDO.FullPrivilege fullPrivilege = activity.getFullPrivilege();
if (RangeTypeEnum.ALL.getValue().equals(fullPrivilege.getRangeType())) {
return true;
} else if (RangeTypeEnum.PRODUCT_INCLUDE_PART.getValue().equals(fullPrivilege.getRangeType())) {
return fullPrivilege.getRangeValues().contains(spuId);
} else {
throw new IllegalArgumentException(String.format("促销活动(%s) 可用范围的类型是不正确", activity.toString()));
}
}
}

View File

@ -0,0 +1,151 @@
package cn.iocoder.mall.promotionservice.service.activity.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
@Accessors(chain = true)
public class PromotionActivityBO implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private String title;
/**
*
*
* {@link cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum}
*/
private Integer activityType;
/**
*
*
* {@link cn.iocoder.mall.promotion.api.enums.PromotionActivityStatusEnum}
*/
private Integer status;
/**
*
*/
private Date startTime;
/**
*
*/
private Date endTime;
/**
*
*/
private TimeLimitedDiscount timeLimitedDiscount;
/**
*
*/
private FullPrivilege fullPrivilege;
/**
*
*/
@Data
@Accessors(chain = true)
public static class TimeLimitedDiscount implements Serializable {
/**
*
*/
@Data
@Accessors(chain = true)
public static class Item implements Serializable {
/**
* SPU
*/
private Integer spuId;
/**
*
*/
private Integer preferentialType;
/**
*
*/
private Integer preferentialValue;
}
/**
*
*
* quota = 0
*/
private Integer quota;
/**
*
*/
private List<Item> items;
}
/**
*
*/
@Data
@Accessors(chain = true)
public static class FullPrivilege implements Serializable {
/**
*
*/
@Data
@Accessors(chain = true)
public static class Privilege implements Serializable {
/**
*
*
* 1 -
* 2 -
*/
private Integer meetType;
/**
*
*/
private Integer meetValue;
/**
*
*/
private Integer preferentialType;
/**
*
*/
private Integer preferentialValue;
}
/**
*
*
* {@link cn.iocoder.mall.promotion.api.enums.RangeTypeEnum}
* + PRODUCT_INCLUDE_PRT
*/
private Integer rangeType;
/**
*
*/
private List<Integer> rangeValues;
/**
*
*/
private Boolean cycled;
/**
*
*/
private List<Privilege> privileges;
}
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.mall.promotionservice.service.activity.bo;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
/**
* BO
*/
@Data
@Accessors(chain = true)
public class PromotionActivityPageBO {
/**
* PromotionActivityBO
*/
private List<PromotionActivityRespDTO> list;
/**
*
*/
private Integer total;
}