促销活动代码迁移

This commit is contained in:
YunaiV 2020-08-22 23:48:31 +08:00
parent 42c6389023
commit c94fae173e
29 changed files with 171 additions and 906 deletions

View File

@ -0,0 +1,36 @@
package cn.iocoder.mall.managementweb.controller.promotion.activity;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.activity.vo.PromotionActivityPageReqVO;
import cn.iocoder.mall.managementweb.manager.promotion.activity.PromotionActivityManager;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
import cn.iocoder.security.annotations.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("/promotion/activity")
@Api(tags = "促销活动 API")
@Validated
public class PromotionActivityController {
@Autowired
private PromotionActivityManager promotionActivityManager;
// TODO 芋艿DTO => VO
@GetMapping("/page")
@ApiOperation("获得促销活动分页")
@RequiresPermissions("promotion:activity:page")
public CommonResult<PageResult<PromotionActivityRespDTO>> pagePromotionActivity(PromotionActivityPageReqVO pageReqVO) {
return success(promotionActivityManager.pagePromotionActivity(pageReqVO));
}
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.mall.managementweb.controller.promotion.activity.vo;
import cn.iocoder.common.framework.vo.PageParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.Collection;
/**
* 促销活动分页 Request DTO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class PromotionActivityPageReqVO extends PageParam {
@ApiModelProperty(value = "标题", example = "优惠劵牛逼")
private String title;
@ApiModelProperty(value = "活动类型", example = "1", notes = "参见 PromotionActivityTypeEnum 枚举")
private Integer activityType;
@ApiModelProperty(value = "状态数组", example = "1,2", notes = "参考 PromotionActivityStatusEnum 枚举")
private Collection<Integer> statuses;
}

View File

@ -20,9 +20,6 @@ import javax.validation.Valid;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* 优惠劵模板 Controller
*/
@RestController
@RequestMapping("/promotion/coupon-template")
@Api(tags = "优惠劵(码)模板 API")

View File

@ -0,0 +1,15 @@
package cn.iocoder.mall.managementweb.convert.promotion.activity;
import cn.iocoder.mall.managementweb.controller.promotion.activity.vo.PromotionActivityPageReqVO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface PromotionActivityConvert {
PromotionActivityConvert INSTANCE = Mappers.getMapper(PromotionActivityConvert.class);
PromotionActivityPageReqDTO convert(PromotionActivityPageReqVO bean);
}

View File

@ -0,0 +1,30 @@
package cn.iocoder.mall.managementweb.manager.promotion.activity;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.promotion.activity.vo.PromotionActivityPageReqVO;
import cn.iocoder.mall.managementweb.convert.promotion.activity.PromotionActivityConvert;
import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityRpc;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
/**
* 促销活动 Manager
*/
@Service
@Validated
public class PromotionActivityManager {
@DubboReference(version = "${dubbo.consumer.PromotionActivityRpc.version}")
private PromotionActivityRpc promotionActivityRpc;
public PageResult<PromotionActivityRespDTO> pagePromotionActivity(PromotionActivityPageReqVO pageReqVO) {
CommonResult<PageResult<PromotionActivityRespDTO>> pagePromotionActivityResult = promotionActivityRpc.pagePromotionActivity(
PromotionActivityConvert.INSTANCE.convert(pageReqVO));
pagePromotionActivityResult.checkError();
return pagePromotionActivityResult.getData();
}
}

View File

@ -59,6 +59,8 @@ dubbo:
version: 1.0.0
CouponTemplateRpc:
version: 1.0.0
PromotionActivityRpc:
version: 1.0.0
# Swagger 配置项
swagger:

View File

@ -1,7 +1,7 @@
package cn.iocoder.mall.promotion.api.enums.activity;
/**
* 推广活动类型枚举
* 促销活动类型枚举
*/
public enum PromotionActivityTypeEnum {

View File

@ -1,20 +1,19 @@
package cn.iocoder.mall.promotion.api.rpc.activity;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
import java.util.List;
/**
* 促销活动 Rpc 接口
*/
public interface PromotionActivityRpc {
// List<PromotionActivityRespDTO> getPromotionActivityListBySpuId(Integer spuId,
// Collection<Integer> activityStatuses);
//
// List<PromotionActivityRespDTO> getPromotionActivityListBySpuIds(Collection<Integer> spuIds,
// Collection<Integer> activityStatuses);
//
// PromotionActivityPageReqDTO getPromotionActivityPage(PromotionActivityPageRespDTO promotionActivityPageDTO);
CommonResult<PageResult<PromotionActivityRespDTO>> pagePromotionActivity(PromotionActivityPageReqDTO pageReqDTO);
CommonResult<List<PromotionActivityRespDTO>> listPromotionActivities(PromotionActivityListReqDTO listReqDTO);

View File

@ -1,24 +1,33 @@
package cn.iocoder.mall.promotion.api.rpc.activity.dto;
import cn.iocoder.common.framework.vo.PageParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.List;
import java.util.Collection;
/**
* 促销活动分页 BO
* 促销活动分页 Request DTO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class PromotionActivityPageReqDTO {
public class PromotionActivityPageReqDTO extends PageParam {
/**
* PromotionActivityBO 数组
* 标题
*
* 模糊匹配
*/
private List<PromotionActivityRespDTO> list;
private String title;
/**
* 总量
* 活动类型
*/
private Integer total;
private Integer activityType;
/**
* 状态
*/
private Collection<Integer> statuses;
}

View File

@ -1,37 +0,0 @@
package cn.iocoder.mall.promotion.api.rpc.activity.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Collection;
/**
* 商品推荐分页 DTO
*/
@Data
@Accessors(chain = true)
public class PromotionActivityPageRespDTO implements Serializable {
/**
* 标题
*
* 模糊匹配
*/
private String title;
/**
* 活动类型
*/
private Integer activityType;
/**
* 状态
*/
private Collection<Integer> statuses;
@NotNull(message = "页码不能为空")
private Integer pageNo;
@NotNull(message = "每页条数不能为空")
private Integer pageSize;
}

View File

@ -52,6 +52,10 @@ public class PromotionActivityRespDTO implements Serializable {
* 满减送
*/
private FullPrivilege fullPrivilege;
/**
* 创建时间
*/
private Date createTime;
/**
* 限时折扣

View File

@ -1,10 +1,11 @@
package cn.iocoder.mall.promotionservice.convert.activity;
import cn.iocoder.common.framework.vo.PageResult;
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 com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@ -14,24 +15,9 @@ 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);
List<PromotionActivityRespDTO> convertList(List<PromotionActivityDO> list);
// @Mappings({})
// PromotionActivityDO convert(PromotionActivityAddDTO activityAddDTO);
//
// @Mappings({})
// PromotionActivityDO convert(PromotionActivityUpdateDTO activityUpdateDTO);
@Mapping(source = "records", target = "list")
PageResult<PromotionActivityRespDTO> convertPage(IPage<PromotionActivityDO> page);
}

View File

@ -2,10 +2,12 @@ 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.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO;
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;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Repository;
import java.util.Collection;
@ -14,19 +16,16 @@ import java.util.List;
@Repository
public interface PromotionActivityMapper extends BaseMapper<PromotionActivityDO> {
default List<PromotionActivityDO> selectListByStatus(@Param("statuses") Collection<Integer> statuses) {
default List<PromotionActivityDO> selectListByStatus(Collection<Integer> statuses) {
return selectList(new QueryWrapper<PromotionActivityDO>().in("status", statuses));
}
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);
default IPage<PromotionActivityDO> selectPage(PromotionActivityPageReqDTO pageReqDTO) {
return selectPage(new Page<>(pageReqDTO.getPageNo(), pageReqDTO.getPageSize()),
new QueryWrapperX<PromotionActivityDO>().likeIfPresent("title", pageReqDTO.getTitle())
.eqIfPresent("activity_type", pageReqDTO.getActivityType())
.inIfPresent("status", pageReqDTO.getStatuses()));
}
default List<PromotionActivityDO> selectList(PromotionActivityListReqDTO listReqDTO) {
return selectList(new QueryWrapperX<PromotionActivityDO>().inIfPresent("id", listReqDTO.getActiveIds()));

View File

@ -1,6 +1,8 @@
package cn.iocoder.mall.promotionservice.manager.activity;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO;
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;
@ -23,4 +25,8 @@ public class PromotionActivityManager {
return promotionActivityService.listPromotionActivities(listReqDTO);
}
public PageResult<PromotionActivityRespDTO> pagePromotionActivity(PromotionActivityPageReqDTO pageReqDTO) {
return promotionActivityService.pagePromotionActivity(pageReqDTO);
}
}

View File

@ -1,8 +1,10 @@
package cn.iocoder.mall.promotionservice.rpc.activity;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
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.PromotionActivityPageReqDTO;
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;
@ -18,6 +20,11 @@ public class PromotionActivityRpcImpl implements PromotionActivityRpc {
@Autowired
private PromotionActivityManager promotionActivityManager;
@Override
public CommonResult<PageResult<PromotionActivityRespDTO>> pagePromotionActivity(PromotionActivityPageReqDTO pageReqDTO) {
return success(promotionActivityManager.pagePromotionActivity(pageReqDTO));
}
@Override
public CommonResult<List<PromotionActivityRespDTO>> listPromotionActivities(PromotionActivityListReqDTO listReqDTO) {
return success(promotionActivityManager.listPromotionActivities(listReqDTO));

View File

@ -1,13 +1,15 @@
package cn.iocoder.mall.promotionservice.service.activity;
import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO;
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;
import cn.iocoder.mall.promotionservice.dal.mysql.mapper.activity.PromotionActivityMapper;
import cn.iocoder.mall.promotionservice.service.activity.bo.PromotionActivityPageBO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
@ -31,10 +33,6 @@ public class PromotionActivityService {
return PromotionActivityConvert.INSTANCE.convertList(activityList);
}
public List<PromotionActivityRespDTO> listPromotionActivitiesBySpuId(Integer spuId, Collection<Integer> activityStatuses) {
return this.listPromotionActivitiesBySpuIds(Collections.singleton(spuId), activityStatuses);
}
public List<PromotionActivityRespDTO> listPromotionActivitiesBySpuIds(Collection<Integer> spuIds, Collection<Integer> activityStatuses) {
if (spuIds.isEmpty() || activityStatuses.isEmpty()) {
return Collections.emptyList();
@ -72,16 +70,9 @@ public class PromotionActivityService {
return PromotionActivityConvert.INSTANCE.convertList(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;
public PageResult<PromotionActivityRespDTO> pagePromotionActivity(PromotionActivityPageReqDTO pageReqDTO) {
IPage<PromotionActivityDO> promotionActivityPage = promotionActivityMapper.selectPage(pageReqDTO);
return PromotionActivityConvert.INSTANCE.convertPage(promotionActivityPage);
}
private boolean isSpuMatchTimeLimitDiscount(Integer spuId, PromotionActivityDO activity) {

View File

@ -1,153 +0,0 @@
package cn.iocoder.mall.promotionservice.service.activity.bo;
import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityStatusEnum;
import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum;
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 PromotionActivityTypeEnum} 枚举
*/
private Integer activityType;
/**
* 活动状态
*
* 参见 {@link 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

@ -1,25 +0,0 @@
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;
}

View File

@ -1,118 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>promotion</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>promotion-service-impl</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>promotion-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>system-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>product-rpc-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- DB 相关 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<!-- RPC 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>
<!-- Registry 和 Config 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- Transaction 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-seata</artifactId>
</dependency>
<!-- Job 相关 -->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
</dependency>
<!-- 工具类相关 -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<!-- 测试相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-mybatis</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-mybatis</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 提供给 mapstruct 使用 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,28 +0,0 @@
package cn.iocoder.mall.promotion.biz.convert;
import cn.iocoder.mall.promotion.api.bo.PromotionActivityBO;
import cn.iocoder.mall.promotion.biz.dataobject.PromotionActivityDO;
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({})
// PromotionActivityDO convert(PromotionActivityAddDTO activityAddDTO);
//
// @Mappings({})
// PromotionActivityDO convert(PromotionActivityUpdateDTO activityUpdateDTO);
}

View File

@ -1,29 +0,0 @@
package cn.iocoder.mall.promotion.biz.dao;
import cn.iocoder.mall.promotion.biz.dataobject.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

@ -1,47 +0,0 @@
package cn.iocoder.mall.promotion.biz.dataobject;
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

@ -1,46 +0,0 @@
package cn.iocoder.mall.promotion.biz.dataobject;
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

@ -1,107 +0,0 @@
package cn.iocoder.mall.promotion.biz.service;
import cn.iocoder.mall.promotion.api.PromotionActivityService;
import cn.iocoder.mall.promotion.api.bo.PromotionActivityBO;
import cn.iocoder.mall.promotion.api.bo.PromotionActivityPageBO;
import cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum;
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
import cn.iocoder.mall.promotion.api.dto.PromotionActivityPageDTO;
import cn.iocoder.mall.promotion.biz.convert.PromotionActivityConvert;
import cn.iocoder.mall.promotion.biz.dao.PromotionActivityMapper;
import cn.iocoder.mall.promotion.biz.dataobject.PromotionActivityDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@Service // 实际上不用添加添加的原因是必须 Spring 报错提示
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.PromotionActivityService.version}")
public class PromotionActivityServiceImpl implements PromotionActivityService {
@Autowired
private PromotionActivityMapper promotionActivityMapper;
@Override
public List<PromotionActivityBO> getPromotionActivityListBySpuId(Integer spuId, Collection<Integer> activityStatuses) {
return this.getPromotionActivityListBySpuIds(Collections.singleton(spuId), activityStatuses);
}
@Override
public List<PromotionActivityBO> 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 PromotionActivityConvert.INSTANCE.convertToBO(activityList);
}
@Override
public PromotionActivityPageBO getPromotionActivityPage(PromotionActivityPageDTO promotionActivityPageDTO) {
PromotionActivityPageBO promotionActivityPageBO = new PromotionActivityPageBO();
// 查询分页数据
int offset = (promotionActivityPageDTO.getPageNo() - 1) * promotionActivityPageDTO.getPageSize();
promotionActivityPageBO.setList(PromotionActivityConvert.INSTANCE.convertToBO(promotionActivityMapper.selectListByPage(
promotionActivityPageDTO.getTitle(), promotionActivityPageDTO.getActivityType(),
promotionActivityPageDTO.getStatuses(),
offset, promotionActivityPageDTO.getPageSize())));
// 查询分页总数
promotionActivityPageBO.setTotal(promotionActivityMapper.selectCountByPage(
promotionActivityPageDTO.getTitle(), promotionActivityPageDTO.getActivityType(),
promotionActivityPageDTO.getStatuses()));
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

@ -1,135 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.iocoder.mall.promotion.biz.dao.PromotionActivityMapper">
<sql id="FIELDS">
id, title, activity_type, status, start_time,
end_time, invalid_time, delete_time, time_limited_discount, full_privilege,
create_time, update_time
</sql>
<resultMap id="PromotionActivityResultMap" type="PromotionActivityDO">
<result property="timeLimitedDiscount" column="time_limited_discount" javaType="cn.iocoder.mall.promotion.biz.dataobject.PromotionActivityDO$TimeLimitedDiscount" typeHandler="cn.iocoder.mall.mybatis.core.type.JSONTypeHandler"/>
<result property="fullPrivilege" column="full_privilege" javaType="cn.iocoder.mall.promotion.biz.dataobject.PromotionActivityDO$FullPrivilege" typeHandler="cn.iocoder.mall.mybatis.core.type.JSONTypeHandler"/>
</resultMap>
<!-- <select id="selectListByPidAndStatusOrderBySort" resultType="PromotionActivityDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM banner-->
<!-- WHERE pid = #{pid}-->
<!-- AND status = #{status}-->
<!-- AND deleted = 0-->
<!-- ORDER BY sort ASC-->
<!-- </select>-->
<!-- <select id="selectList" resultType="PromotionActivityDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM banner-->
<!-- WHERE deleted = 0-->
<!-- </select>-->
<select id="selectById" parameterType="Integer" resultMap="PromotionActivityResultMap">
SELECT
<include refid="FIELDS" />
FROM promotion_activity
WHERE id = #{id}
</select>
<select id="selectListByStatus" resultMap="PromotionActivityResultMap">
SELECT
<include refid="FIELDS" />
FROM promotion_activity
WHERE status IN
<foreach item="status" collection="statuses" separator="," open="(" close=")" index="">
#{status}
</foreach>
</select>
<!-- <select id="selectListByStatus" parameterType="Integer" resultType="PromotionActivityDO">-->
<!-- SELECT-->
<!-- <include refid="FIELDS" />-->
<!-- FROM banner-->
<!-- <where>-->
<!-- <if test="status != null">-->
<!-- status = #{status}-->
<!-- </if>-->
<!-- AND deleted = 0-->
<!-- </where>-->
<!-- </select>-->
<select id="selectListByPage" resultMap="PromotionActivityResultMap">
SELECT
<include refid="FIELDS" />
FROM promotion_activity
WHERE activity_type = #{activityType}
<if test="title != null">
AND title LIKE "%"#{title}"%"
</if>
AND status IN
<foreach item="status" collection="statuses" separator="," open="(" close=")" index="">
#{status}
</foreach>
LIMIT #{offset}, #{limit}
</select>
<select id="selectCountByPage" resultType="Integer">
SELECT
COUNT(1)
FROM promotion_activity
WHERE activity_type = #{activityType}
<if test="title != null">
AND title LIKE "%"#{title}"%"
</if>
AND status IN
<foreach item="status" collection="statuses" separator="," open="(" close=")" index="">
#{status}
</foreach>
</select>
<insert id="insert" parameterType="PromotionActivityDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO promotion_activity (
title, activity_type, status, start_time,
end_time, invalid_time, delete_time,
time_limited_discount,
full_privilege,
create_time
) VALUES (
#{title}, #{activityType}, #{status}, #{startTime},
#{endTime}, #{invalidTime}, #{deleteTime},
#{timeLimitedDiscount, typeHandler=cn.iocoder.common.framework.mybatis.JSONTypeHandler},
#{fullPrivilege, typeHandler=cn.iocoder.common.framework.mybatis.JSONTypeHandler},
#{createTime}
)
</insert>
<!-- <update id="update" parameterType="PromotionActivityDO">-->
<!-- UPDATE banner-->
<!-- <set>-->
<!-- <if test="title != null">-->
<!-- title = #{title},-->
<!-- </if>-->
<!-- <if test="url != null">-->
<!-- url = #{url},-->
<!-- </if>-->
<!-- <if test="picUrl != null">-->
<!-- pic_url = #{picUrl} ,-->
<!-- </if>-->
<!-- <if test="sort != null">-->
<!-- sort = #{sort},-->
<!-- </if>-->
<!-- <if test="status != null">-->
<!-- status = #{status},-->
<!-- </if>-->
<!-- <if test="memo != null">-->
<!-- memo = #{memo},-->
<!-- </if>-->
<!-- <if test="deleted != null">-->
<!-- deleted = #{deleted}-->
<!-- </if>-->
<!-- </set>-->
<!-- WHERE id = #{id}-->
<!-- </update>-->
</mapper>

View File

@ -1,58 +0,0 @@
package cn.iocoder.mall.promotion.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.PromotionActivityService;
import cn.iocoder.mall.promotion.api.bo.PromotionActivityPageBO;
import cn.iocoder.mall.promotion.api.enums.PromotionActivityStatusEnum;
import cn.iocoder.mall.promotion.api.dto.PromotionActivityPageDTO;
import io.swagger.annotations.Api;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.Collections;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("admins/promotion_activity")
@Api("促销活动模块")
public class AdminsPromotionActivityController {
@Reference(validation = "true", version = "${dubbo.provider.PromotionActivityService.version}")
private PromotionActivityService promotionActivityService;
@GetMapping("/page") // TODO 芋艿BO => VO
public CommonResult<PromotionActivityPageBO> page(@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "activityType") Integer activityType,
@RequestParam(value = "status") String status,
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
PromotionActivityPageDTO promotionActivityPageDTO = new PromotionActivityPageDTO()
.setTitle(title).setActivityType(activityType).setPageNo(pageNo).setPageSize(pageSize);
switch (status) {
case "WAIT":
promotionActivityPageDTO.setStatuses(Collections.singleton(PromotionActivityStatusEnum.WAIT.getValue()));
break;
case "RUN":
promotionActivityPageDTO.setStatuses(Collections.singleton(PromotionActivityStatusEnum.RUN.getValue()));
break;
case "END":
promotionActivityPageDTO.setStatuses(Collections.singleton(PromotionActivityStatusEnum.END.getValue()));
break;
case "INVALID":
promotionActivityPageDTO.setStatuses(Collections.singleton(PromotionActivityStatusEnum.INVALID.getValue()));
break;
default:
promotionActivityPageDTO.setStatuses(Arrays.asList(PromotionActivityStatusEnum.WAIT.getValue(),
PromotionActivityStatusEnum.RUN.getValue(), PromotionActivityStatusEnum.END.getValue(),
PromotionActivityStatusEnum.INVALID.getValue()));
}
// 执行查询
return success(promotionActivityService.getPromotionActivityPage(promotionActivityPageDTO));
}
}

View File

@ -1,20 +0,0 @@
package cn.iocoder.mall.promotion.application.vo.admins;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@ApiModel("Banner 分页 VO")
@Data
@Accessors(chain = true)
public class AdminsBannerPageVO {
@ApiModelProperty(value = "Banner 数组")
private List<AdminsBannerVO> list;
@ApiModelProperty(value = "Banner 总数")
private Integer total;
}

View File

@ -1,6 +0,0 @@
swagger:
enable: false
title: 营销子系统
description: 营销子系统
version: 1.0.0
base-package: cn.iocoder.mall.promotion.application.controller

View File

@ -1,33 +0,0 @@
spring:
application:
name: promotion-application
# Spring Cloud 配置项
cloud:
# Spring Cloud Sentinel 配置项
sentinel:
transport:
dashboard: s1.iocoder.cn:12088 # Sentinel Dashboard 服务地址
eager: true # 项目启动时,直接连接到 Sentinel
# server
server:
port: 18085
servlet:
context-path: /promotion-api/
swagger:
enable: true
title: 促销子系统
description: 促销子系统
version: 1.0.0
base-package: cn.iocoder.mall.promotion.application.controller
management:
endpoints:
web:
exposure:
include: health,info,env,metrics,prometheus
metrics:
enabled: true