砍价活动: 完善 app 端获取活动分页、列表、详情接口

This commit is contained in:
puhui999 2023-09-19 16:35:21 +08:00
parent a10d77cdfe
commit af6016bba5
11 changed files with 170 additions and 74 deletions

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.product.api.spu.dto;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import lombok.Data;
@ -31,6 +30,12 @@ public class ProductSpuRespDTO {
* 关键字
*/
private String keyword;
/**
* 单位
*
* 对应 product_unit 数据字典
*/
private Integer unit;
/**
* 商品简介
*/

View File

@ -77,6 +77,10 @@
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-excel</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-dict</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -3,6 +3,9 @@ package cn.iocoder.yudao.module.promotion.controller.admin.bargain;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityRespVO;
@ -19,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -30,6 +34,8 @@ public class BargainActivityController {
@Resource
private BargainActivityService activityService;
@Resource
private ProductSpuApi spuApi;
@PostMapping("/create")
@Operation(summary = "创建砍价活动")
@ -73,7 +79,8 @@ public class BargainActivityController {
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty(pageResult.getTotal()));
}
return success(BargainActivityConvert.INSTANCE.convertPage(activityService.getBargainActivityPage(pageVO)));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(CollectionUtils.convertList(pageResult.getList(), BargainActivityDO::getSpuId));
return success(BargainActivityConvert.INSTANCE.convertPage(pageResult, spuList));
}
}

View File

@ -1,12 +1,19 @@
package cn.iocoder.yudao.module.promotion.controller.app.bargain;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppBargainActivityDetailRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppBargainActivityRespVO;
import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
@ -14,8 +21,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.Duration;
import java.util.ArrayList;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -25,86 +31,49 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@RequestMapping("/promotion/bargain-activity")
@Validated
public class AppBargainActivityController {
@Resource
private BargainActivityService bargainActivityService;
@Resource
private ProductSpuApi spuApi;
@GetMapping("/page")
@Operation(summary = "获得砍价活动活动") // TODO 芋艿只查询进行中且在时间范围内的
// TODO 芋艿缺少 swagger 注解
@Operation(summary = "获得砍价活动分页")
public CommonResult<PageResult<AppBargainActivityRespVO>> getBargainActivityPage(PageParam pageReqVO) {
List<AppBargainActivityRespVO> activityList = new ArrayList<>();
AppBargainActivityRespVO activity1 = new AppBargainActivityRespVO();
activity1.setId(1L);
activity1.setName("618 大砍价");
activity1.setSpuId(2048L);
activity1.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
activity1.setMarketPrice(50);
activity1.setBargainPrice(100);
activity1.setStartTime(LocalDateTimeUtils.addTime(Duration.ofDays(-2)));
activity1.setEndTime(LocalDateTimeUtils.addTime(Duration.ofDays(1)));
activity1.setStock(10);
activityList.add(activity1);
PageResult<BargainActivityDO> result = bargainActivityService.getBargainActivityAppPage(pageReqVO);
if (CollUtil.isEmpty(result.getList())) {
return success(PageResult.empty(result.getTotal()));
}
AppBargainActivityRespVO activity2 = new AppBargainActivityRespVO();
activity2.setId(2L);
activity2.setName("双十一砍价");
activity2.setSpuId(4096L);
activity2.setPicUrl("https://static.iocoder.cn/mall/132.jpeg");
activity2.setMarketPrice(100);
activity2.setBargainPrice(200);
activity2.setStartTime(LocalDateTimeUtils.addTime(Duration.ofDays(-2)));
activity2.setEndTime(LocalDateTimeUtils.addTime(Duration.ofDays(1)));
activity2.setStock(0);
activityList.add(activity2);
return success(new PageResult<>(activityList, 10L));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(CollectionUtils.convertList(result.getList(), BargainActivityDO::getSpuId));
return success(BargainActivityConvert.INSTANCE.convertAppPage(result, spuList));
}
@GetMapping("/list")
@Operation(summary = "获得砍价活动列表", description = "用于小程序首页")
// TODO 芋艿增加 Spring Cache
// TODO 芋艿缺少 swagger 注解
@Parameter(name = "count", description = "需要展示的数量", example = "6")
public CommonResult<List<AppBargainActivityRespVO>> getBargainActivityList(
@RequestParam(name = "count", defaultValue = "6") Integer count) {
List<AppBargainActivityRespVO> activityList = new ArrayList<>();
AppBargainActivityRespVO activity1 = new AppBargainActivityRespVO();
activity1.setId(1L);
activity1.setName("618 大砍价");
activity1.setSpuId(2048L);
activity1.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
activity1.setMarketPrice(50);
activity1.setBargainPrice(100);
activityList.add(activity1);
List<BargainActivityDO> list = bargainActivityService.getBargainActivityAppList(count);
if (CollUtil.isEmpty(list)) {
return success(BargainActivityConvert.INSTANCE.convertAppList(list));
}
AppBargainActivityRespVO activity2 = new AppBargainActivityRespVO();
activity2.setId(2L);
activity2.setName("双十一砍价");
activity2.setSpuId(4096L);
activity2.setPicUrl("https://static.iocoder.cn/mall/132.jpeg");
activity2.setMarketPrice(100);
activity2.setBargainPrice(200);
activityList.add(activity2);
return success(activityList);
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(CollectionUtils.convertList(list, BargainActivityDO::getSpuId));
// TODO 芋艿增加 Spring Cache
return success(BargainActivityConvert.INSTANCE.convertAppList(list, spuList));
}
@GetMapping("/get-detail")
@Operation(summary = "获得砍价活动详情")
// TODO 芋艿缺少 swagger 注解
@Parameter(name = "id", description = "活动编号", example = "1")
public CommonResult<AppBargainActivityDetailRespVO> getBargainActivityDetail(@RequestParam("id") Long id) {
AppBargainActivityDetailRespVO activity = new AppBargainActivityDetailRespVO();
activity.setId(2L);
activity.setName("618 大砍价");
activity.setSpuId(2048L);
activity.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
activity.setMarketPrice(50);
activity.setBargainPrice(100);
activity.setStock(10);
activity.setUnitName("");
activity.setPrice(40);
activity.setStartTime(LocalDateTimeUtils.addTime(Duration.ofDays(-2)));
activity.setEndTime(LocalDateTimeUtils.addTime(Duration.ofDays(-10)));
activity.setDescription("我吃西红柿");
activity.setSuccessCount(10);
return success(activity);
BargainActivityDO activity = bargainActivityService.getBargainActivity(id);
if (activity == null) {
return success(null);
}
ProductSpuRespDTO spu = spuApi.getSpu(activity.getSpuId());
return success(BargainActivityConvert.INSTANCE.convert1(activity, spu));
}
}

View File

@ -45,7 +45,7 @@ public class AppBargainActivityDetailRespVO {
@Schema(description = "商品单位", required = true, example = "") // SPU unit 读取然后转换
private String unitName;
@Schema(description = "砍价最低金额,单位:分", required = true, example = "100") // 从砍价商品里取最低价
@Schema(description = "砍价最低金额,单位:分", required = true, example = "100")
private Integer bargainPrice;
@Schema(description = "砍价成功数量", required = true, example = "100")

View File

@ -36,7 +36,7 @@ public class AppBargainActivityRespVO {
@Schema(description = "商品市场价,单位:分", required = true, example = "50") // SPU marketPrice 读取
private Integer marketPrice;
@Schema(description = "砍价最低金额,单位:分", required = true, example = "100") // 从砍价商品里取最低价
@Schema(description = "砍价最低金额,单位:分", required = true, example = "100")
private Integer bargainPrice;
}

View File

@ -1,14 +1,24 @@
package cn.iocoder.yudao.module.promotion.convert.bargain;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.product.enums.DictTypeConstants;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityBaseVO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppBargainActivityDetailRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppBargainActivityRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
/**
* 拼团活动 Convert
@ -30,4 +40,60 @@ public interface BargainActivityConvert {
PageResult<BargainActivityRespVO> convertPage(PageResult<BargainActivityDO> page);
default PageResult<BargainActivityRespVO> convertPage(PageResult<BargainActivityDO> page, List<ProductSpuRespDTO> spuList) {
PageResult<BargainActivityRespVO> result = convertPage(page);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
List<BargainActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
item.setPicUrl(spu.getPicUrl());
item.setSpuName(spu.getName());
});
return item;
});
result.setList(list);
return result;
}
AppBargainActivityDetailRespVO convert1(BargainActivityDO bean);
default AppBargainActivityDetailRespVO convert1(BargainActivityDO bean, ProductSpuRespDTO spu) {
AppBargainActivityDetailRespVO detail = convert1(bean);
if (spu != null) {
detail.setPicUrl(spu.getPicUrl());
detail.setMarketPrice(spu.getMarketPrice());
detail.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
}
return detail;
}
PageResult<AppBargainActivityRespVO> convertAppPage(PageResult<BargainActivityDO> page);
default PageResult<AppBargainActivityRespVO> convertAppPage(PageResult<BargainActivityDO> page, List<ProductSpuRespDTO> spuList) {
PageResult<AppBargainActivityRespVO> result = convertAppPage(page);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
List<AppBargainActivityRespVO> list = CollectionUtils.convertList(result.getList(), item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
item.setPicUrl(spu.getPicUrl());
item.setMarketPrice(spu.getMarketPrice());
});
return item;
});
result.setList(list);
return result;
}
List<AppBargainActivityRespVO> convertAppList(List<BargainActivityDO> list);
default List<AppBargainActivityRespVO> convertAppList(List<BargainActivityDO> list, List<ProductSpuRespDTO> spuList) {
List<AppBargainActivityRespVO> activityList = convertAppList(list);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
return CollectionUtils.convertList(activityList, item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
item.setPicUrl(spu.getPicUrl());
item.setMarketPrice(spu.getMarketPrice());
});
return item;
});
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.bargain;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
@ -8,6 +9,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityD
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -43,4 +45,11 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
.setSql("stock = stock - " + count));
}
default PageResult<BargainActivityDO> selectAppPage(PageParam pageReqVO, Integer status, LocalDateTime now) {
return selectPage(pageReqVO, new LambdaQueryWrapperX<BargainActivityDO>()
.eq(BargainActivityDO::getStatus, status)
.le(BargainActivityDO::getStartTime, now)
.ge(BargainActivityDO::getEndTime, now));
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.promotion.service.bargain;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO;
@ -7,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActi
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
import javax.validation.Valid;
import java.util.List;
/**
* 砍价活动 Service 接口
@ -61,4 +63,19 @@ public interface BargainActivityService {
*/
PageResult<BargainActivityDO> getBargainActivityPage(BargainActivityPageReqVO pageReqVO);
/**
* 获取 APP 端活动分页数据
*
* @param pageReqVO 分页请求
* @return 砍价活动分页
*/
PageResult<BargainActivityDO> getBargainActivityAppPage(PageParam pageReqVO);
/**
* 获取 APP 端活动展示数据
*
* @param count 需要的数量
* @return
*/
List<BargainActivityDO> getBargainActivityAppList(Integer count);
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.service.bargain;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
@ -16,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -113,9 +115,9 @@ public class BargainActivityServiceImpl implements BargainActivityService {
// 校验存在
BargainActivityDO activityDO = validateBargainActivityExists(id);
// 校验状态
if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
throw exception(BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END);
}
//if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
// throw exception(BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END);
//}
// 删除
bargainActivityMapper.deleteById(id);
@ -139,4 +141,20 @@ public class BargainActivityServiceImpl implements BargainActivityService {
return bargainActivityMapper.selectPage(pageReqVO);
}
@Override
public PageResult<BargainActivityDO> getBargainActivityAppPage(PageParam pageReqVO) {
// 只查询进行中且在时间范围内的
return bargainActivityMapper.selectAppPage(pageReqVO, CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
}
@Override
public List<BargainActivityDO> getBargainActivityAppList(Integer count) {
if (count == null) {
count = 6;
}
PageResult<BargainActivityDO> result = bargainActivityMapper.selectAppPage(new PageParam().setPageSize(count), CommonStatusEnum.ENABLE.getStatus(), LocalDateTime.now());
return result.getList();
}
}

View File

@ -38,6 +38,7 @@ import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
public class CombinationRecordServiceImpl implements CombinationRecordService {
@Resource
@Lazy
private CombinationActivityService combinationActivityService;
@Resource
private CombinationRecordMapper recordMapper;