trade:砍价记录的详情 50%

This commit is contained in:
YunaiV 2023-10-06 02:06:38 +08:00
parent aec8e853e4
commit 5f57cc6247
15 changed files with 236 additions and 44 deletions

View File

@ -10,7 +10,9 @@ import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.activity.AppB
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.enums.bargain.BargainRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import io.swagger.v3.oas.annotations.Operation;
@ -52,6 +54,9 @@ public class AppBargainActivityController {
@Resource
private BargainActivityService bargainActivityService;
@Resource
private BargainRecordService bargainRecordService;
@Resource
private ProductSpuApi spuApi;
@ -94,8 +99,9 @@ public class AppBargainActivityController {
return success(null);
}
// 拼接数据
Integer successUserCount = bargainRecordService.getBargainRecordUserCount(id, BargainRecordStatusEnum.SUCCESS.getStatus());
ProductSpuRespDTO spu = spuApi.getSpu(activity.getSpuId());
return success(BargainActivityConvert.INSTANCE.convert(activity, spu));
return success(BargainActivityConvert.INSTANCE.convert(activity, successUserCount, spu));
}
}

View File

@ -1,21 +1,27 @@
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.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBargainHelpCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBargainHelpRespVO;
import cn.iocoder.yudao.module.promotion.convert.bargain.BargainHelpConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainHelpService;
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.*;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "用户 App - 砍价助力")
@ -27,6 +33,9 @@ public class AppBargainHelpController {
@Resource
private BargainHelpService bargainHelpService;
@Resource
private MemberUserApi memberUserApi;
@PostMapping("/create")
@Operation(summary = "创建砍价助力", description = "给拼团记录砍一刀") // 返回结果为砍价金额单位
public CommonResult<Integer> createBargainHelp(@RequestBody AppBargainHelpCreateReqVO reqVO) {
@ -36,18 +45,18 @@ public class AppBargainHelpController {
@GetMapping("/list")
@Operation(summary = "获得砍价助力列表")
// TODO 芋艿swagger
@Parameter(name = "recordId", description = "砍价记录编号", required = true, example = "111")
public CommonResult<List<AppBargainHelpRespVO>> getBargainHelpList(@RequestParam("recordId") Long recordId) {
List<AppBargainHelpRespVO> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
AppBargainHelpRespVO vo = new AppBargainHelpRespVO();
vo.setNickname("用户" + i);
vo.setAvatar("https://www.iocoder.cn/avatar/" + i + ".jpg");
vo.setReducePrice((i + 1) * 100);
vo.setCreateTime(LocalDateTime.now());
list.add(vo);
List<BargainHelpDO> helps = bargainHelpService.getBargainHelpListByRecordId(recordId);
if (CollUtil.isEmpty(helps)) {
return success(Collections.emptyList());
}
return success(list);
helps.sort((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime())); // 倒序展示
// 拼接数据
Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(
convertSet(helps, BargainHelpDO::getUserId));
return success(BargainHelpConvert.INSTANCE.convertList(helps, userMap));
}
}

View File

@ -1,10 +1,10 @@
package cn.iocoder.yudao.module.promotion.controller.app.bargain;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
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.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
@ -19,16 +19,18 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityD
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO;
import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainHelpService;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService;
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -47,6 +49,8 @@ public class AppBargainRecordController {
private BargainRecordService bargainRecordService;
@Resource
private BargainActivityService bargainActivityService;
@Resource
private BargainHelpService bargainHelpService;
@Resource
private MemberUserApi memberUserApi;
@ -78,23 +82,67 @@ public class AppBargainRecordController {
@GetMapping("/get-detail")
@Operation(summary = "获得砍价记录的明细")
// TODO 芋艿swaggerid activityId 二选一
@Parameters({
@Parameter(name = "id", description = "砍价记录编号", example = "111"), // 场景一查看指定的砍价记录
@Parameter(name = "activityId", description = "砍价活动编号", example = "222") // 场景二查看指定的砍价活动
})
public CommonResult<AppBargainRecordDetailRespVO> getBargainRecordDetail(
@RequestParam(value = "id", required = false) Long id,
@RequestParam(value = "activityId", required = false) Long activityId) {
AppBargainRecordDetailRespVO detail = new AppBargainRecordDetailRespVO();
detail.setId(1L);
detail.setUserId(1L);
detail.setSpuId(1L);
detail.setSkuId(1L);
detail.setPrice(500);
detail.setActivityId(1L);
detail.setBargainPrice(150);
detail.setPrice(200);
detail.setPayPrice(180);
detail.setStatus(1);
detail.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2)));
return success(detail);
// 1. 查询砍价记录 + 砍价活动
Assert.isTrue(id != null || activityId != null, "砍价记录编号和活动编号不能同时为空");
BargainRecordDO record = id != null ? bargainRecordService.getBargainRecord(id)
: bargainRecordService.getInProgressBargainRecord(getLoginUserId(), activityId);
if (activityId == null || record != null) {
activityId = record.getActivityId();
}
// 2. 查询助力记录
Integer helpAction = getHelpAction(record, activityId);
// 3. 如果是自己的订单则查询订单信息
// TODO 继续查询别的字段
// 拼接返回
return success(BargainRecordConvert.INSTANCE.convert02(record, helpAction));
//
// AppBargainRecordDetailRespVO detail = new AppBargainRecordDetailRespVO();
// detail.setId(1L);
// detail.setUserId(1L);
// detail.setSpuId(1L);
// detail.setSkuId(1L);
// detail.setPrice(500);
// detail.setActivityId(1L);
// detail.setBargainPrice(150);
// detail.setPrice(200);
// detail.setPayPrice(180);
// detail.setStatus(1);
// detail.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2)));
// return success(detail);
}
private Integer getHelpAction(BargainRecordDO record, Long activityId) {
// 0.1 如果没有活动无法帮砍
if (activityId == null) {
return null;
}
// 0.2 如果是自己的砍价记录无法帮砍
Long userId = getLoginUserId();
if (record != null && record.getUserId().equals(userId)) {
return null;
}
// 1. 判断是否已经助力
if (record != null
&& bargainHelpService.getBargainHelp(record.getId(), userId) != null) {
return AppBargainRecordDetailRespVO.HELP_ACTION_SUCCESS;
}
// 2. 判断是否满助力
BargainActivityDO activity = bargainActivityService.getBargainActivity(activityId);
if (activity != null
&& bargainHelpService.getBargainHelpCountByActivity(activityId, userId) >= activity.getBargainCount()) {
return AppBargainRecordDetailRespVO.HELP_ACTION_FULL;
}
return AppBargainRecordDetailRespVO.HELP_ACTION_NONE;
}
@GetMapping("/page")

View File

@ -45,10 +45,13 @@ public class AppBargainActivityDetailRespVO {
@Schema(description = "商品单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "") // SPU unit 读取然后转换
private String unitName;
@Schema(description = "砍价起始价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
private Integer bargainFirstPrice;
@Schema(description = "砍价最低金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer bargainPrice;
private Integer bargainMinPrice;
@Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer successCount;
private Integer successUserCount;
}

View File

@ -9,6 +9,9 @@ import java.time.LocalDateTime;
@Data
public class AppBargainHelpRespVO {
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long userId;
@Schema(description = "助力用户的昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private String nickname;

View File

@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "用户 App - 砍价记录的明细 Response VO")
@Data
public class AppBargainRecordDetailRespVO {
@ -13,21 +11,44 @@ public class AppBargainRecordDetailRespVO {
public static final int HELP_ACTION_FULL = 2; // 帮砍动作 - 未帮砍无法帮砍可帮砍次数已满)
public static final int HELP_ACTION_SUCCESS = 3; // 帮砍动作 - 已帮砍
// ========== 砍价记录 ==========
@Schema(description = "砍价记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private Long userId;
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long spuId;
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long skuId;
@Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
private Long activityId;
@Schema(description = "砍价起始价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "23")
private Integer bargainFirstPrice;
@Schema(description = "当前砍价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "23")
private Integer bargainPrice;
private Integer price;
private Integer payPrice;
@Schema(description = "砍价记录状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
private LocalDateTime expireTime;
// ========== 订单相关 ========== 注意只有是自己的砍价记录才会返回保证隐私性
@Schema(description = "订单编号", example = "1024")
private Long orderId;
@Schema(description = "支付状态", example = "true")
private Boolean payStatus;
@Schema(description = "支付订单编号", example = "1024")
private Long payOrderId;
// ========== 助力记录 ==========
private Integer helpAction;
}

View File

@ -61,12 +61,11 @@ public interface BargainActivityConvert {
AppBargainActivityDetailRespVO convert1(BargainActivityDO bean);
default AppBargainActivityDetailRespVO convert(BargainActivityDO bean, ProductSpuRespDTO spu) {
AppBargainActivityDetailRespVO detail = convert1(bean);
default AppBargainActivityDetailRespVO convert(BargainActivityDO bean, Integer successUserCount, ProductSpuRespDTO spu) {
AppBargainActivityDetailRespVO detail = convert1(bean).setSuccessUserCount(successUserCount);
if (spu != null) {
detail.setPicUrl(spu.getPicUrl());
detail.setMarketPrice(spu.getMarketPrice());
detail.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
detail.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())
.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
}
return detail;
}

View File

@ -4,10 +4,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.help.BargainHelpRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBargainHelpRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
/**
@ -31,4 +33,14 @@ public interface BargainHelpConvert {
}
PageResult<BargainHelpRespVO> convertPage(PageResult<BargainHelpDO> page);
default List<AppBargainHelpRespVO> convertList(List<BargainHelpDO> helps,
Map<Long, MemberUserRespDTO> userMap) {
List<AppBargainHelpRespVO> helpVOs = convertList02(helps);
helpVOs.forEach(help ->
MapUtils.findAndThen(userMap, help.getUserId(),
user -> help.setNickname(user.getNickname()).setAvatar(user.getAvatar())));
return helpVOs;
}
List<AppBargainHelpRespVO> convertList02(List<BargainHelpDO> helps);
}

View File

@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.recrod.BargainRecordPageItemRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordDetailRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordSummaryRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
@ -82,4 +83,6 @@ public interface BargainRecordConvert {
return summary;
}
AppBargainRecordDetailRespVO convert02(BargainRecordDO record, Integer helpAction);
}

View File

@ -72,4 +72,9 @@ public interface BargainHelpMapper extends BaseMapperX<BargainHelpDO> {
.orderByDesc(BargainHelpDO::getId));
}
default List<BargainHelpDO> selectListByRecordId(Long recordId) {
return selectList(new LambdaQueryWrapperX<BargainHelpDO>()
.eq(BargainHelpDO::getRecordId, recordId));
}
}

View File

@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -71,9 +72,16 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> {
record -> MapUtil.getInt(record, "userCount" ));
}
@Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record WHERE status = #{status}")
@Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record " +
"WHERE status = #{status}")
Integer selectUserCountByStatus(@Param("status") Integer status);
@Select("SELECT COUNT(DISTINCT(user_id)) FROM promotion_bargain_record " +
"WHERE activity_id = #{activityId} " +
"AND status = #{status}")
Integer selectUserCountByActivityIdAndStatus(@Param("activityId") Long activityId,
@Param("status") Integer status);
default PageResult<BargainRecordDO> selectPage(BargainRecordPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<BargainRecordDO>()
.eqIfPresent(BargainRecordDO::getStatus, reqVO.getStatus())
@ -101,7 +109,7 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> {
* @return 更新数量
*/
default int updateOrderIdById(Long id, Long orderId) {
return update(new BargainRecordDO().setOrderId(orderId),
return update(new BargainRecordDO().setOrderId(orderId).setEndTime(LocalDateTime.now()),
new LambdaQueryWrapper<>(BargainRecordDO.class)
.eq(BargainRecordDO::getId, id)
.isNull(BargainRecordDO::getOrderId));

View File

@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBarga
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
@ -40,6 +41,15 @@ public interface BargainHelpService {
*/
Map<Long, Integer> getBargainHelpUserCountMapByRecord(Collection<Long> recordIds);
/**
* 砍价活动获得用户的助力次数
*
* @param activityId 活动编号
* @param userId 用户编号
* @return 助力次数
*/
Long getBargainHelpCountByActivity(Long activityId, Long userId);
/**
* 获得砍价助力分页
*
@ -48,4 +58,21 @@ public interface BargainHelpService {
*/
PageResult<BargainHelpDO> getBargainHelpPage(BargainHelpPageReqVO pageReqVO);
/**
* 获得指定砍价记录编号对应的砍价助力列表
*
* @param recordId 砍价记录编号
* @return 砍价助力列表
*/
List<BargainHelpDO> getBargainHelpListByRecordId(Long recordId);
/**
* 获得助力记录
*
* @param recordId 砍价记录编号
* @param userId 用户编号
* @return 助力记录
*/
BargainHelpDO getBargainHelp(Long recordId, Long userId);
}

View File

@ -18,6 +18,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -114,9 +115,24 @@ public class BargainHelpServiceImpl implements BargainHelpService {
return bargainHelpMapper.selectUserCountMapByRecordId(recordIds);
}
@Override
public Long getBargainHelpCountByActivity(Long activityId, Long userId) {
return bargainHelpMapper.selectCountByUserIdAndActivityId(userId, activityId);
}
@Override
public PageResult<BargainHelpDO> getBargainHelpPage(BargainHelpPageReqVO pageReqVO) {
return bargainHelpMapper.selectPage(pageReqVO);
}
@Override
public List<BargainHelpDO> getBargainHelpListByRecordId(Long recordId) {
return bargainHelpMapper.selectListByRecordId(recordId);
}
@Override
public BargainHelpDO getBargainHelp(Long recordId, Long userId) {
return bargainHelpMapper.selectByUserIdAndRecordId(userId, recordId);
}
}

View File

@ -73,6 +73,17 @@ public interface BargainRecordService {
*/
BargainRecordDO getBargainRecord(Long id);
/**
* 获得用户当前正在砍价中+ 指定活动的砍价记录
*
* 因为一个用户在一个砍价活动砍价中只存在一条
*
* @param userId 用户编号
* @param activityId 砍价记录编号
* @return 砍价记录
*/
BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId);
/**
* 获得砍价人数 Map
*
@ -83,13 +94,22 @@ public interface BargainRecordService {
Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status);
/**
* 获得砍价人数 Map
* 获得砍价人数
*
* @param status 砍价记录状态
* @return 砍价人数
*/
Integer getBargainRecordUserCount(Integer status);
/**
* 获得砍价人数
*
* @param activityId 砍价活动编号
* @param status 砍价记录状态
* @return 砍价人数
*/
Integer getBargainRecordUserCount(Long activityId, Integer status);
/**
* 管理员获得砍价记录分页
*

View File

@ -114,6 +114,13 @@ public class BargainRecordServiceImpl implements BargainRecordService {
return bargainRecordMapper.selectById(id);
}
@Override
public BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId) {
List<BargainRecordDO> list = bargainRecordMapper.selectListByUserIdAndActivityIdAndStatus(
userId, activityId, BargainRecordStatusEnum.IN_PROGRESS.getStatus());
return CollUtil.getFirst(list);
}
@Override
public Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status) {
return bargainRecordMapper.selectUserCountByActivityIdsAndStatus(activityIds, status);
@ -124,6 +131,11 @@ public class BargainRecordServiceImpl implements BargainRecordService {
return bargainRecordMapper.selectUserCountByStatus(status);
}
@Override
public Integer getBargainRecordUserCount(Long activityId, Integer status) {
return bargainRecordMapper.selectUserCountByActivityIdAndStatus(activityId, status);
}
@Override
public PageResult<BargainRecordDO> getBargainRecordPage(BargainRecordPageReqVO pageReqVO) {
return bargainRecordMapper.selectPage(pageReqVO);