促销活动代码迁移
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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 芋艿 点击次数。&& 其他数据相关
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user