- 后端:增加促销活动分页接口
parent
d39a416080
commit
f44a6d49d7
|
@ -158,13 +158,9 @@ public class CartServiceImpl implements CartService {
|
|||
}
|
||||
// TODO 库存相关
|
||||
// 查询促销活动
|
||||
CommonResult<List<PromotionActivityBO>> activityListResult = promotionActivityService.getPromotionActivityListBySpuIds(
|
||||
List<PromotionActivityBO> activityList = promotionActivityService.getPromotionActivityListBySpuIds(
|
||||
skus.stream().map(sku -> sku.getSpu().getId()).collect(Collectors.toSet()),
|
||||
Collections.singletonList(PromotionActivityStatusEnum.RUN.getValue()));
|
||||
if (activityListResult.isError()) {
|
||||
return CommonResult.error(activityListResult);
|
||||
}
|
||||
List<PromotionActivityBO> activityList = activityListResult.getData();
|
||||
// 拼装结果(主要是计算价格)
|
||||
CalcOrderPriceBO calcOrderPriceBO = new CalcOrderPriceBO();
|
||||
// 1. 创建初始的每一项的数组
|
||||
|
@ -208,14 +204,9 @@ public class CartServiceImpl implements CartService {
|
|||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode());
|
||||
}
|
||||
// 查询促销活动
|
||||
CommonResult<List<PromotionActivityBO>> activityListResult = promotionActivityService.getPromotionActivityListBySpuId(sku.getSpuId(),
|
||||
List<PromotionActivityBO> activityList = promotionActivityService.getPromotionActivityListBySpuId(sku.getSpuId(),
|
||||
Arrays.asList(PromotionActivityStatusEnum.WAIT.getValue(), PromotionActivityStatusEnum.RUN.getValue()));
|
||||
if (activityListResult.isError()) {
|
||||
return CommonResult.error(activityListResult);
|
||||
}
|
||||
// 如果无促销活动,则直接返回默认结果即可
|
||||
List<PromotionActivityBO> activityList = activityListResult.getData();
|
||||
if (activityList.isEmpty()) {
|
||||
if (activityList.isEmpty()) { // 如果无促销活动,则直接返回默认结果即可
|
||||
return CommonResult.success(new CalcSkuPriceBO().setOriginalPrice(sku.getPrice()).setBuyPrice(sku.getPrice()));
|
||||
}
|
||||
// 如果有促销活动,则开始做计算 TODO 芋艿,因为现在暂时只有限时折扣 + 满减送。所以写的比较简单先
|
||||
|
|
|
@ -44,8 +44,8 @@ public class AdminsProductRecommendController {
|
|||
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"),
|
||||
})
|
||||
public CommonResult<AdminsProductRecommendPageVO> page(@RequestParam(value = "type", required = false) Integer type,
|
||||
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
ProductRecommendPageBO result = productRecommendService.getProductRecommendPage(new ProductRecommendPageDTO().setType(type).setPageNo(pageNo).setPageSize(pageSize));
|
||||
// 获得商品集合
|
||||
List<ProductSpuBO> spus = productSpuService.getProductSpuList(
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
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.constant.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("title") String title,
|
||||
@RequestParam("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));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,20 @@
|
|||
package cn.iocoder.mall.promotion.api;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.api.bo.PromotionActivityBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.PromotionActivityPageBO;
|
||||
import cn.iocoder.mall.promotion.api.dto.PromotionActivityPageDTO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface PromotionActivityService {
|
||||
|
||||
CommonResult<List<PromotionActivityBO>> getPromotionActivityListBySpuId(Integer spuId,
|
||||
List<PromotionActivityBO> getPromotionActivityListBySpuId(Integer spuId,
|
||||
Collection<Integer> activityStatuses);
|
||||
|
||||
CommonResult<List<PromotionActivityBO>> getPromotionActivityListBySpuIds(Collection<Integer> spuIds,
|
||||
Collection<Integer> activityStatuses);
|
||||
List<PromotionActivityBO> getPromotionActivityListBySpuIds(Collection<Integer> spuIds,
|
||||
Collection<Integer> activityStatuses);
|
||||
|
||||
PromotionActivityPageBO getPromotionActivityPage(PromotionActivityPageDTO promotionActivityPageDTO);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package cn.iocoder.mall.promotion.api.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 促销活动分页 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class PromotionActivityPageBO {
|
||||
|
||||
/**
|
||||
* PromotionActivityBO 数组
|
||||
*/
|
||||
private List<PromotionActivityBO> list;
|
||||
/**
|
||||
* 总量
|
||||
*/
|
||||
private Integer total;
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package cn.iocoder.mall.promotion.api.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 PromotionActivityPageDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*
|
||||
* 模糊匹配
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
private Integer activityType;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Collection<Integer> statuses;
|
||||
|
||||
@NotNull(message = "页码不能为空")
|
||||
private Integer pageNo;
|
||||
@NotNull(message = "每页条数不能为空")
|
||||
private Integer pageSize;
|
||||
|
||||
}
|
|
@ -12,8 +12,18 @@ public interface PromotionActivityMapper {
|
|||
|
||||
PromotionActivityDO selectById(@Param("id") Integer id);
|
||||
|
||||
List<PromotionActivityDO> selectListByStatus(@Param("statuses")Collection<Integer> statuses);
|
||||
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,10 +1,11 @@
|
|||
package cn.iocoder.mall.promotion.biz.service;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
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.constant.PromotionActivityTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.constant.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;
|
||||
|
@ -25,19 +26,19 @@ public class PromotionActivityServiceImpl implements PromotionActivityService {
|
|||
private PromotionActivityMapper promotionActivityMapper;
|
||||
|
||||
@Override
|
||||
public CommonResult<List<PromotionActivityBO>> getPromotionActivityListBySpuId(Integer spuId, Collection<Integer> activityStatuses) {
|
||||
public List<PromotionActivityBO> getPromotionActivityListBySpuId(Integer spuId, Collection<Integer> activityStatuses) {
|
||||
return this.getPromotionActivityListBySpuIds(Collections.singleton(spuId), activityStatuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<PromotionActivityBO>> getPromotionActivityListBySpuIds(Collection<Integer> spuIds, Collection<Integer> activityStatuses) {
|
||||
public List<PromotionActivityBO> getPromotionActivityListBySpuIds(Collection<Integer> spuIds, Collection<Integer> activityStatuses) {
|
||||
if (spuIds.isEmpty() || activityStatuses.isEmpty()) {
|
||||
return CommonResult.success(Collections.emptyList());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 查询指定状态的促销活动
|
||||
List<PromotionActivityDO> activityList = promotionActivityMapper.selectListByStatus(activityStatuses);
|
||||
if (activityList.isEmpty()) {
|
||||
return CommonResult.success(Collections.emptyList());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 匹配商品
|
||||
for (Iterator<PromotionActivityDO> iterator = activityList.iterator(); iterator.hasNext();) {
|
||||
|
@ -64,7 +65,23 @@ public class PromotionActivityServiceImpl implements PromotionActivityService {
|
|||
}
|
||||
}
|
||||
// 返回最终结果
|
||||
return CommonResult.success(PromotionActivityConvert.INSTANCE.convertToBO(activityList));
|
||||
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) {
|
||||
|
|
|
@ -59,30 +59,34 @@
|
|||
<!-- </where>-->
|
||||
<!-- </select>-->
|
||||
|
||||
<!-- <select id="selectListByTitleLike" resultType="PromotionActivityDO">-->
|
||||
<!-- SELECT-->
|
||||
<!-- <include refid="FIELDS" />-->
|
||||
<!-- FROM banner-->
|
||||
<!-- <where>-->
|
||||
<!-- <if test="title != null">-->
|
||||
<!-- title LIKE "%"#{title}"%"-->
|
||||
<!-- </if>-->
|
||||
<!-- AND deleted = 0-->
|
||||
<!-- </where>-->
|
||||
<!-- LIMIT #{offset}, #{limit}-->
|
||||
<!-- </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="selectCountByTitleLike" resultType="Integer">-->
|
||||
<!-- SELECT-->
|
||||
<!-- COUNT(1)-->
|
||||
<!-- FROM banner-->
|
||||
<!-- <where>-->
|
||||
<!-- <if test="title != null">-->
|
||||
<!-- title LIKE "%"#{title}"%"-->
|
||||
<!-- </if>-->
|
||||
<!-- AND deleted = 0-->
|
||||
<!-- </where>-->
|
||||
<!-- </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 (
|
||||
|
|
Loading…
Reference in New Issue