Merge remote-tracking branch 'yudao/feature/mall_product' into feature/mall_product

# Conflicts:
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
This commit is contained in:
puhui999 2023-10-06 21:15:06 +08:00
commit 8b480c52cc
33 changed files with 412 additions and 105 deletions

View File

@ -5,14 +5,14 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.*;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -23,6 +23,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import static cn.hutool.core.collection.CollectionUtil.newArrayList; import static cn.hutool.core.collection.CollectionUtil.newArrayList;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -36,6 +38,8 @@ public class CombinationActivityController {
@Resource @Resource
private CombinationActivityService combinationActivityService; private CombinationActivityService combinationActivityService;
@Resource
private CombinationRecordService combinationRecordService;
@Resource @Resource
private ProductSpuApi productSpuApi; private ProductSpuApi productSpuApi;
@ -77,7 +81,7 @@ public class CombinationActivityController {
@GetMapping("/page") @GetMapping("/page")
@Operation(summary = "获得拼团活动分页") @Operation(summary = "获得拼团活动分页")
@PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')")
public CommonResult<PageResult<CombinationActivityRespVO>> getCombinationActivityPage( public CommonResult<PageResult<CombinationActivityPageItemRespVO>> getCombinationActivityPage(
@Valid CombinationActivityPageReqVO pageVO) { @Valid CombinationActivityPageReqVO pageVO) {
// 查询拼团活动 // 查询拼团活动
PageResult<CombinationActivityDO> pageResult = combinationActivityService.getCombinationActivityPage(pageVO); PageResult<CombinationActivityDO> pageResult = combinationActivityService.getCombinationActivityPage(pageVO);
@ -85,12 +89,21 @@ public class CombinationActivityController {
return success(PageResult.empty(pageResult.getTotal())); return success(PageResult.empty(pageResult.getTotal()));
} }
// 统计数据
Set<Long> activityIds = convertSet(pageResult.getList(), CombinationActivityDO::getId);
Map<Long, Integer> groupCountMap = combinationRecordService.getCombinationRecordCountMapByActivity(
activityIds, null, CombinationRecordDO.HEAD_ID_GROUP);
Map<Long, Integer> groupSuccessCountMap = combinationRecordService.getCombinationRecordCountMapByActivity(
activityIds, CombinationRecordStatusEnum.SUCCESS.getStatus(), CombinationRecordDO.HEAD_ID_GROUP);
Map<Long, Integer> recordCountMap = combinationRecordService.getCombinationRecordCountMapByActivity(
activityIds, null, null);
// 拼接数据 // 拼接数据
List<CombinationProductDO> products = combinationActivityService.getCombinationProductsByActivityIds( List<CombinationProductDO> products = combinationActivityService.getCombinationProductsByActivityIds(
convertSet(pageResult.getList(), CombinationActivityDO::getId)); convertSet(pageResult.getList(), CombinationActivityDO::getId));
List<ProductSpuRespDTO> spus = productSpuApi.getSpuList( List<ProductSpuRespDTO> spus = productSpuApi.getSpuList(
convertSet(pageResult.getList(), CombinationActivityDO::getSpuId)); convertSet(pageResult.getList(), CombinationActivityDO::getSpuId));
return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, products, spus)); return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, products,
groupCountMap, groupSuccessCountMap, recordCountMap, spus));
} }
} }

View File

@ -48,6 +48,9 @@ public class CombinationActivityBaseVO {
@NotNull(message = "开团人数不能为空") @NotNull(message = "开团人数不能为空")
private Integer userSize; private Integer userSize;
@Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
private Boolean virtualGroup = false; // TODO @puhui999这个字段界面没做呀
@Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "限制时长不能为空") @NotNull(message = "限制时长不能为空")
private Integer limitDuration; private Integer limitDuration;

View File

@ -0,0 +1,53 @@
package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 拼团活动的分页项 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CombinationActivityPageItemRespVO extends CombinationActivityBaseVO {
@Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
@Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
private Integer status;
@Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED)
private List<CombinationProductRespVO> products;
// ========== 商品字段 ==========
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // SPU name 读取
example = "618大促")
private String spuName;
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // SPU picUrl 读取
example = "https://www.iocoder.cn/xx.png")
private String picUrl;
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // SPU marketPrice 读取
example = "50")
private Integer marketPrice;
// ========== 统计字段 ==========
@Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "33")
private Integer groupCount;
@Schema(description = "成团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
private Integer groupSuccessCount;
@Schema(description = "购买次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer recordCount;
}

View File

@ -15,8 +15,7 @@ public class CombinationActivityPageReqVO extends PageParam {
@Schema(description = "拼团名称", example = "赵六") @Schema(description = "拼团名称", example = "赵六")
private String name; private String name;
@Schema(description = "活动状态0开启 1关闭", example = "0") @Schema(description = "活动状态", example = "0")
private Integer status; private Integer status;
} }

View File

@ -6,8 +6,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -20,30 +18,12 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO {
@Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901")
private Long id; private Long id;
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618 大促")
private String spuName;
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
private String picUrl;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime; private LocalDateTime createTime;
@Schema(description = "开团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") @Schema(description = "开团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private Integer userSize; private Integer userSize;
@Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "33")
private Integer totalCount;
@Schema(description = "成团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
private Integer successCount;
@Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
private Integer virtualGroup;
@Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
private Integer status;
@Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED)
private List<CombinationProductRespVO> products; private List<CombinationProductRespVO> products;

View File

@ -18,16 +18,6 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
@Schema(description = "秒杀活动 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "秒杀活动 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id; private Long id;
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // SPU name 读取
example = "618大促")
private String spuName;
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // SPU picUrl 读取
example = "https://www.iocoder.cn/xx.png")
private String picUrl;
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // SPU marketPrice 读取
example = "50")
private Integer marketPrice;
@Schema(description = "秒杀商品", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "秒杀商品", requiredMode = Schema.RequiredMode.REQUIRED)
private List<SeckillProductRespVO> products; private List<SeckillProductRespVO> products;
@ -52,4 +42,16 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime; private LocalDateTime createTime;
// ========== 商品字段 ==========
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // SPU name 读取
example = "618大促")
private String spuName;
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // SPU picUrl 读取
example = "https://www.iocoder.cn/xx.png")
private String picUrl;
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // SPU marketPrice 读取
example = "50")
private Integer marketPrice;
} }

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.controller.app.bargain.vo.activity.AppBargainActivityRespVO;
import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert; 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.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.BargainActivityService;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -52,6 +54,9 @@ public class AppBargainActivityController {
@Resource @Resource
private BargainActivityService bargainActivityService; private BargainActivityService bargainActivityService;
@Resource
private BargainRecordService bargainRecordService;
@Resource @Resource
private ProductSpuApi spuApi; private ProductSpuApi spuApi;
@ -94,8 +99,9 @@ public class AppBargainActivityController {
return success(null); return success(null);
} }
// 拼接数据 // 拼接数据
Integer successUserCount = bargainRecordService.getBargainRecordUserCount(id, BargainRecordStatusEnum.SUCCESS.getStatus());
ProductSpuRespDTO spu = spuApi.getSpu(activity.getSpuId()); 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; 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.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.AppBargainHelpCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.help.AppBargainHelpRespVO; 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.dal.dataobject.bargain.BargainHelpDO;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainHelpService; import cn.iocoder.yudao.module.promotion.service.bargain.BargainHelpService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.util.Collections;
import java.util.ArrayList;
import java.util.List; 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.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; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "用户 App - 砍价助力") @Tag(name = "用户 App - 砍价助力")
@ -27,6 +33,9 @@ public class AppBargainHelpController {
@Resource @Resource
private BargainHelpService bargainHelpService; private BargainHelpService bargainHelpService;
@Resource
private MemberUserApi memberUserApi;
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建砍价助力", description = "给拼团记录砍一刀") // 返回结果为砍价金额单位 @Operation(summary = "创建砍价助力", description = "给拼团记录砍一刀") // 返回结果为砍价金额单位
public CommonResult<Integer> createBargainHelp(@RequestBody AppBargainHelpCreateReqVO reqVO) { public CommonResult<Integer> createBargainHelp(@RequestBody AppBargainHelpCreateReqVO reqVO) {
@ -36,18 +45,18 @@ public class AppBargainHelpController {
@GetMapping("/list") @GetMapping("/list")
@Operation(summary = "获得砍价助力列表") @Operation(summary = "获得砍价助力列表")
// TODO 芋艿swagger @Parameter(name = "recordId", description = "砍价记录编号", required = true, example = "111")
public CommonResult<List<AppBargainHelpRespVO>> getBargainHelpList(@RequestParam("recordId") Long recordId) { public CommonResult<List<AppBargainHelpRespVO>> getBargainHelpList(@RequestParam("recordId") Long recordId) {
List<AppBargainHelpRespVO> list = new ArrayList<>(); List<BargainHelpDO> helps = bargainHelpService.getBargainHelpListByRecordId(recordId);
for (int i = 0; i < 10; i++) { if (CollUtil.isEmpty(helps)) {
AppBargainHelpRespVO vo = new AppBargainHelpRespVO(); return success(Collections.emptyList());
vo.setNickname("用户" + i);
vo.setAvatar("https://www.iocoder.cn/avatar/" + i + ".jpg");
vo.setReducePrice((i + 1) * 100);
vo.setCreateTime(LocalDateTime.now());
list.add(vo);
} }
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; package cn.iocoder.yudao.module.promotion.controller.app.bargain;
import cn.hutool.core.collection.CollUtil; 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.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; 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.dal.dataobject.bargain.BargainRecordDO;
import cn.iocoder.yudao.module.promotion.enums.bargain.BargainRecordStatusEnum; 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.BargainActivityService;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainHelpService;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService; 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.TradeOrderApi;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
import io.swagger.v3.oas.annotations.Operation; 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 io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Duration;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -47,6 +49,8 @@ public class AppBargainRecordController {
private BargainRecordService bargainRecordService; private BargainRecordService bargainRecordService;
@Resource @Resource
private BargainActivityService bargainActivityService; private BargainActivityService bargainActivityService;
@Resource
private BargainHelpService bargainHelpService;
@Resource @Resource
private MemberUserApi memberUserApi; private MemberUserApi memberUserApi;
@ -78,23 +82,55 @@ public class AppBargainRecordController {
@GetMapping("/get-detail") @GetMapping("/get-detail")
@Operation(summary = "获得砍价记录的明细") @Operation(summary = "获得砍价记录的明细")
// TODO 芋艿swaggerid activityId 二选一 @Parameters({
@Parameter(name = "id", description = "砍价记录编号", example = "111"), // 场景一查看指定的砍价记录
@Parameter(name = "activityId", description = "砍价活动编号", example = "222") // 场景二查看指定的砍价活动
})
public CommonResult<AppBargainRecordDetailRespVO> getBargainRecordDetail( public CommonResult<AppBargainRecordDetailRespVO> getBargainRecordDetail(
@RequestParam(value = "id", required = false) Long id, @RequestParam(value = "id", required = false) Long id,
@RequestParam(value = "activityId", required = false) Long activityId) { @RequestParam(value = "activityId", required = false) Long activityId) {
AppBargainRecordDetailRespVO detail = new AppBargainRecordDetailRespVO(); // 1. 查询砍价记录 + 砍价活动
detail.setId(1L); Assert.isTrue(id != null || activityId != null, "砍价记录编号和活动编号不能同时为空");
detail.setUserId(1L); BargainRecordDO record = id != null ? bargainRecordService.getBargainRecord(id)
detail.setSpuId(1L); : bargainRecordService.getLastBargainRecord(getLoginUserId(), activityId);
detail.setSkuId(1L); if (activityId == null || record != null) {
detail.setPrice(500); activityId = record.getActivityId();
detail.setActivityId(1L); }
detail.setBargainPrice(150); // 2. 查询助力记录
detail.setPrice(200); Long userId = getLoginUserId();
detail.setPayPrice(180); Integer helpAction = getHelpAction(userId, record, activityId);
detail.setStatus(1); // 3. 如果是自己的订单则查询订单信息
detail.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2))); TradeOrderRespDTO order = record != null && record.getOrderId() != null && record.getUserId().equals(getLoginUserId())
return success(detail); ? tradeOrderApi.getOrder(record.getOrderId()) : null;
// TODO 继续查询别的字段
// 拼接返回
return success(BargainRecordConvert.INSTANCE.convert02(record, helpAction, order));
}
private Integer getHelpAction(Long userId, BargainRecordDO record, Long activityId) {
// 0.1 如果没有活动无法帮砍
if (activityId == null) {
return null;
}
// 0.2 如果是自己的砍价记录无法帮砍
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;
}
// 3. 允许助力
return AppBargainRecordDetailRespVO.HELP_ACTION_NONE;
} }
@GetMapping("/page") @GetMapping("/page")

View File

@ -45,10 +45,13 @@ public class AppBargainActivityDetailRespVO {
@Schema(description = "商品单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "") // SPU unit 读取然后转换 @Schema(description = "商品单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "") // SPU unit 读取然后转换
private String unitName; private String unitName;
@Schema(description = "砍价起始价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
private Integer bargainFirstPrice;
@Schema(description = "砍价最低金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") @Schema(description = "砍价最低金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer bargainPrice; private Integer bargainMinPrice;
@Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") @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 @Data
public class AppBargainHelpRespVO { public class AppBargainHelpRespVO {
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long userId;
@Schema(description = "助力用户的昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @Schema(description = "助力用户的昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private String nickname; 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 io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "用户 App - 砍价记录的明细 Response VO") @Schema(description = "用户 App - 砍价记录的明细 Response VO")
@Data @Data
public class AppBargainRecordDetailRespVO { public class AppBargainRecordDetailRespVO {
@ -13,21 +11,44 @@ public class AppBargainRecordDetailRespVO {
public static final int HELP_ACTION_FULL = 2; // 帮砍动作 - 未帮砍无法帮砍可帮砍次数已满) public static final int HELP_ACTION_FULL = 2; // 帮砍动作 - 未帮砍无法帮砍可帮砍次数已满)
public static final int HELP_ACTION_SUCCESS = 3; // 帮砍动作 - 已帮砍 public static final int HELP_ACTION_SUCCESS = 3; // 帮砍动作 - 已帮砍
// ========== 砍价记录 ==========
@Schema(description = "砍价记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id; private Long id;
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private Long userId; private Long userId;
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long spuId; private Long spuId;
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long skuId; private Long skuId;
@Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
private Long activityId; 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 bargainPrice;
private Integer price;
private Integer payPrice; @Schema(description = "砍价记录状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status; private Integer status;
private LocalDateTime expireTime; // ========== 订单相关 ========== 注意只有是自己的砍价记录才会返回保证隐私性
@Schema(description = "订单编号", example = "1024")
private Long orderId; private Long orderId;
@Schema(description = "支付状态", example = "true")
private Boolean payStatus; private Boolean payStatus;
@Schema(description = "支付订单编号", example = "1024")
private Long payOrderId;
// ========== 助力记录 ==========
private Integer helpAction; private Integer helpAction;
} }

View File

@ -61,12 +61,11 @@ public interface BargainActivityConvert {
AppBargainActivityDetailRespVO convert1(BargainActivityDO bean); AppBargainActivityDetailRespVO convert1(BargainActivityDO bean);
default AppBargainActivityDetailRespVO convert(BargainActivityDO bean, ProductSpuRespDTO spu) { default AppBargainActivityDetailRespVO convert(BargainActivityDO bean, Integer successUserCount, ProductSpuRespDTO spu) {
AppBargainActivityDetailRespVO detail = convert1(bean); AppBargainActivityDetailRespVO detail = convert1(bean).setSuccessUserCount(successUserCount);
if (spu != null) { if (spu != null) {
detail.setPicUrl(spu.getPicUrl()); detail.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())
detail.setMarketPrice(spu.getMarketPrice()); .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
detail.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
} }
return detail; 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.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; 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.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 cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -31,4 +33,14 @@ public interface BargainHelpConvert {
} }
PageResult<BargainHelpRespVO> convertPage(PageResult<BargainHelpDO> page); 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,12 +6,14 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; 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.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.recrod.BargainRecordPageItemRespVO; 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.AppBargainRecordRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordSummaryRespVO; import cn.iocoder.yudao.module.promotion.controller.app.bargain.vo.record.AppBargainRecordSummaryRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.util.List; import java.util.List;
@ -82,4 +84,9 @@ public interface BargainRecordConvert {
return summary; return summary;
} }
@Mapping(source = "record.id", target = "id")
@Mapping(source = "record.userId", target = "userId")
@Mapping(source = "record.status", target = "status")
AppBargainRecordDetailRespVO convert02(BargainRecordDO record, Integer helpAction, TradeOrderRespDTO order);
} }

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageItemRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO;
@ -54,19 +55,27 @@ public interface CombinationActivityConvert {
List<CombinationActivityRespVO> convertList(List<CombinationActivityDO> list); List<CombinationActivityRespVO> convertList(List<CombinationActivityDO> list);
PageResult<CombinationActivityRespVO> convertPage(PageResult<CombinationActivityDO> page);
default PageResult<CombinationActivityRespVO> convertPage(PageResult<CombinationActivityDO> page, default PageResult<CombinationActivityPageItemRespVO> convertPage(PageResult<CombinationActivityDO> page,
List<CombinationProductDO> productList, List<CombinationProductDO> productList,
List<ProductSpuRespDTO> spuList) { Map<Long, Integer> groupCountMap,
Map<Long, Integer> groupSuccessCountMap,
Map<Long, Integer> recordCountMap,
List<ProductSpuRespDTO> spuList) {
PageResult<CombinationActivityPageItemRespVO> pageResult = convertPage(page);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
PageResult<CombinationActivityRespVO> pageResult = convertPage(page);
pageResult.getList().forEach(item -> { pageResult.getList().forEach(item -> {
MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl())); MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl())
.setMarketPrice(spu.getMarketPrice()));
item.setProducts(convertList2(productList)); item.setProducts(convertList2(productList));
// 设置统计字段
item.setGroupCount(groupCountMap.getOrDefault(item.getId(), 0))
.setGroupSuccessCount(groupSuccessCountMap.getOrDefault(item.getId(), 0))
.setRecordCount(recordCountMap.getOrDefault(item.getId(), 0));
}); });
return pageResult; return pageResult;
} }
PageResult<CombinationActivityPageItemRespVO> convertPage(PageResult<CombinationActivityDO> page);
List<CombinationProductRespVO> convertList2(List<CombinationProductDO> productDOs); List<CombinationProductRespVO> convertList2(List<CombinationProductDO> productDOs);

View File

@ -59,22 +59,10 @@ public class CombinationActivityDO extends BaseDO {
* 几人团 * 几人团
*/ */
private Integer userSize; private Integer userSize;
/**
* 开团组数
*/
private Integer totalCount;
/**
* 成团组数
*/
private Integer successCount;
/**
* 参与人数
*/
private Integer orderUserCount;
/** /**
* 虚拟成团 * 虚拟成团
*/ */
private Integer virtualGroup; private Boolean virtualGroup;
/** /**
* 活动状态 * 活动状态
* *

View File

@ -28,6 +28,11 @@ import java.time.LocalDateTime;
@AllArgsConstructor @AllArgsConstructor
public class CombinationRecordDO extends BaseDO { public class CombinationRecordDO extends BaseDO {
/**
* 团长编号 - 团长
*/
public static final Integer HEAD_ID_GROUP = 0;
/** /**
* 编号主键自增 * 编号主键自增
*/ */
@ -84,6 +89,8 @@ public class CombinationRecordDO extends BaseDO {
* 团长编号 * 团长编号
* *
* 关联 {@link CombinationRecordDO#getId()} * 关联 {@link CombinationRecordDO#getId()}
*
* 如果是团长则它的值是 {@link #HEAD_ID_GROUP}
*/ */
private Long headId; private Long headId;
/** /**

View File

@ -72,4 +72,9 @@ public interface BargainHelpMapper extends BaseMapperX<BargainHelpDO> {
.orderByDesc(BargainHelpDO::getId)); .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.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -41,6 +42,14 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> {
.eq(BargainRecordDO::getStatus, status)); .eq(BargainRecordDO::getStatus, status));
} }
default BargainRecordDO selectLastByUserIdAndActivityId(Long userId, Long activityId) {
return selectOne(new LambdaQueryWrapper<>(BargainRecordDO.class)
.eq(BargainRecordDO::getUserId, userId)
.eq(BargainRecordDO::getActivityId, activityId)
.orderByDesc(BargainRecordDO::getId)
.last("LIMIT 1"));
}
default Long selectCountByUserIdAndActivityIdAndStatus( default Long selectCountByUserIdAndActivityIdAndStatus(
Long userId, Long activityId, Integer status) { Long userId, Long activityId, Integer status) {
return selectCount(new LambdaQueryWrapper<>(BargainRecordDO.class) return selectCount(new LambdaQueryWrapper<>(BargainRecordDO.class)
@ -71,9 +80,16 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> {
record -> MapUtil.getInt(record, "userCount" )); 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); 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) { default PageResult<BargainRecordDO> selectPage(BargainRecordPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<BargainRecordDO>() return selectPage(reqVO, new LambdaQueryWrapperX<BargainRecordDO>()
.eqIfPresent(BargainRecordDO::getStatus, reqVO.getStatus()) .eqIfPresent(BargainRecordDO::getStatus, reqVO.getStatus())
@ -101,7 +117,7 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> {
* @return 更新数量 * @return 更新数量
*/ */
default int updateOrderIdById(Long id, Long orderId) { 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) new LambdaQueryWrapper<>(BargainRecordDO.class)
.eq(BargainRecordDO::getId, id) .eq(BargainRecordDO::getId, id)
.isNull(BargainRecordDO::getOrderId)); .isNull(BargainRecordDO::getOrderId));

View File

@ -1,16 +1,23 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.combination; package cn.iocoder.yudao.module.promotion.dal.mysql.combination;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 拼团记录 Mapper * 拼团记录 Mapper
@ -95,6 +102,24 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
.last("LIMIT " + count)); .last("LIMIT " + count));
} }
default Map<Long, Integer> selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(Collection<Long> activityIds,
Integer status, Integer headId) {
// SQL count 查询
List<Map<String, Object>> result = selectMaps(new QueryWrapper<CombinationRecordDO>()
.select("COUNT(DISTINCT(user_id)) AS recordCount, activity_id AS activityId")
.in("activity_id", activityIds)
.eq(status != null, "status", status)
.eq(headId != null, "head_id", headId)
.groupBy("activity_id"));
if (CollUtil.isEmpty(result)) {
return Collections.emptyMap();
}
// 转换数据
return CollectionUtils.convertMap(result,
record -> MapUtil.getLong(record, "activityId"),
record -> MapUtil.getInt(record, "recordCount" ));
}
static LocalDateTime[] builderQueryTime(Integer dateType) { static LocalDateTime[] builderQueryTime(Integer dateType) {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
LocalDateTime[] createTime = null; // 全部时间段 LocalDateTime[] createTime = null; // 全部时间段

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 cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainHelpDO;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -40,6 +41,15 @@ public interface BargainHelpService {
*/ */
Map<Long, Integer> getBargainHelpUserCountMapByRecord(Collection<Long> recordIds); 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); 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 javax.annotation.Resource;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -114,9 +115,24 @@ public class BargainHelpServiceImpl implements BargainHelpService {
return bargainHelpMapper.selectUserCountMapByRecordId(recordIds); return bargainHelpMapper.selectUserCountMapByRecordId(recordIds);
} }
@Override
public Long getBargainHelpCountByActivity(Long activityId, Long userId) {
return bargainHelpMapper.selectCountByUserIdAndActivityId(userId, activityId);
}
@Override @Override
public PageResult<BargainHelpDO> getBargainHelpPage(BargainHelpPageReqVO pageReqVO) { public PageResult<BargainHelpDO> getBargainHelpPage(BargainHelpPageReqVO pageReqVO) {
return bargainHelpMapper.selectPage(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,15 @@ public interface BargainRecordService {
*/ */
BargainRecordDO getBargainRecord(Long id); BargainRecordDO getBargainRecord(Long id);
/**
* 获得用户在当前砍价活动中的最后一条砍价记录
*
* @param userId 用户编号
* @param activityId 砍价记录编号
* @return 砍价记录
*/
BargainRecordDO getLastBargainRecord(Long userId, Long activityId);
/** /**
* 获得砍价人数 Map * 获得砍价人数 Map
* *
@ -83,13 +92,22 @@ public interface BargainRecordService {
Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status); Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status);
/** /**
* 获得砍价人数 Map * 获得砍价人数
* *
* @param status 砍价记录状态 * @param status 砍价记录状态
* @return 砍价人数 * @return 砍价人数
*/ */
Integer getBargainRecordUserCount(Integer status); Integer getBargainRecordUserCount(Integer status);
/**
* 获得砍价人数
*
* @param activityId 砍价活动编号
* @param status 砍价记录状态
* @return 砍价人数
*/
Integer getBargainRecordUserCount(Long activityId, Integer status);
/** /**
* 管理员获得砍价记录分页 * 管理员获得砍价记录分页
* *

View File

@ -114,6 +114,11 @@ public class BargainRecordServiceImpl implements BargainRecordService {
return bargainRecordMapper.selectById(id); return bargainRecordMapper.selectById(id);
} }
@Override
public BargainRecordDO getLastBargainRecord(Long userId, Long activityId) {
return bargainRecordMapper.selectLastByUserIdAndActivityId(userId, activityId);
}
@Override @Override
public Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status) { public Map<Long, Integer> getBargainRecordUserCountMap(Collection<Long> activityIds, @Nullable Integer status) {
return bargainRecordMapper.selectUserCountByActivityIdsAndStatus(activityIds, status); return bargainRecordMapper.selectUserCountByActivityIdsAndStatus(activityIds, status);
@ -124,6 +129,11 @@ public class BargainRecordServiceImpl implements BargainRecordService {
return bargainRecordMapper.selectUserCountByStatus(status); return bargainRecordMapper.selectUserCountByStatus(status);
} }
@Override
public Integer getBargainRecordUserCount(Long activityId, Integer status) {
return bargainRecordMapper.selectUserCountByActivityIdAndStatus(activityId, status);
}
@Override @Override
public PageResult<BargainRecordDO> getBargainRecordPage(BargainRecordPageReqVO pageReqVO) { public PageResult<BargainRecordDO> getBargainRecordPage(BargainRecordPageReqVO pageReqVO) {
return bargainRecordMapper.selectPage(pageReqVO); return bargainRecordMapper.selectPage(pageReqVO);

View File

@ -101,7 +101,7 @@ public interface CombinationActivityService {
PageResult<CombinationActivityDO> getCombinationActivityPage(PageParam pageParam); PageResult<CombinationActivityDO> getCombinationActivityPage(PageParam pageParam);
/** /**
* 获取指定活动指定 sku 编号的商品 * 获取指定活动指定 sku 编号的商品
* *
* @param activityId 活动编号 * @param activityId 活动编号
* @param skuId sku 编号 * @param skuId sku 编号

View File

@ -65,13 +65,11 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
// 插入拼团活动 // 插入拼团活动
CombinationActivityDO activity = CombinationActivityConvert.INSTANCE.convert(createReqVO) CombinationActivityDO activity = CombinationActivityConvert.INSTANCE.convert(createReqVO)
.setStatus(CommonStatusEnum.ENABLE.getStatus()) .setStatus(CommonStatusEnum.ENABLE.getStatus());
.setTotalCount(0).setSuccessCount(0).setOrderUserCount(0).setVirtualGroup(0);
combinationActivityMapper.insert(activity); combinationActivityMapper.insert(activity);
// 插入商品 // 插入商品
List<CombinationProductDO> products = CombinationActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activity); List<CombinationProductDO> products = CombinationActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activity);
combinationProductMapper.insertBatch(products); combinationProductMapper.insertBatch(products);
// 返回
return activity.getId(); return activity.getId();
} }

View File

@ -9,9 +9,13 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationA
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
import javax.annotation.Nullable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
// todo @PUHUI方法名还是带下 Combination
/** /**
* 拼团记录 Service 接口 * 拼团记录 Service 接口
* *
@ -159,4 +163,16 @@ public interface CombinationRecordService {
*/ */
PageResult<CombinationRecordDO> getBargainRecordPage(CombinationRecordReqPageVO pageVO); PageResult<CombinationRecordDO> getBargainRecordPage(CombinationRecordReqPageVO pageVO);
/**
* 拼团活动获得拼团记录数量 Map
*
* @param activityIds 活动记录编号数组
* @param status 拼团状态允许空
* @param headId 团长编号允许空目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 可以设置
* @return 拼团记录数量 Map
*/
Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds,
@Nullable Integer status,
@Nullable Integer headId);
} }

View File

@ -27,9 +27,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Nullable;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
@ -205,6 +208,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
@Override @Override
public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) { public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) {
// TODO puhui999:这里直接获得不适合调用校验的接口
return validateCombinationRecord(userId, orderId); return validateCombinationRecord(userId, orderId);
} }
@ -267,4 +271,10 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
return recordMapper.selectPage(pageVO); return recordMapper.selectPage(pageVO);
} }
@Override
public Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds,
@Nullable Integer status, @Nullable Integer headId) {
return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId);
}
} }

View File

@ -22,6 +22,14 @@ public interface TradeOrderApi {
*/ */
List<TradeOrderRespDTO> getOrderList(Collection<Long> ids); List<TradeOrderRespDTO> getOrderList(Collection<Long> ids);
/**
* 获得订单
*
* @param id 订单编号
* @return 订单
*/
TradeOrderRespDTO getOrder(Long id);
// TODO 芋艿看看是不是可以删除掉 // TODO 芋艿看看是不是可以删除掉
/** /**
* 获取订单状态 * 获取订单状态

View File

@ -34,6 +34,11 @@ public class TradeOrderApiImpl implements TradeOrderApi {
return TradeOrderConvert.INSTANCE.convertList04(tradeOrderQueryService.getOrderList(ids)); return TradeOrderConvert.INSTANCE.convertList04(tradeOrderQueryService.getOrderList(ids));
} }
@Override
public TradeOrderRespDTO getOrder(Long id) {
return TradeOrderConvert.INSTANCE.convert(tradeOrderQueryService.getOrder(id));
}
@Override @Override
public Integer getOrderStatus(Long id) { public Integer getOrderStatus(Long id) {
TradeOrderDO order = tradeOrderQueryService.getOrder(id); TradeOrderDO order = tradeOrderQueryService.getOrder(id);

View File

@ -39,6 +39,7 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.Mappings; import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.util.ArrayList; import java.util.ArrayList;
@ -262,6 +263,7 @@ public interface TradeOrderConvert {
return bo; return bo;
} }
@Named("convertList04")
List<TradeOrderRespDTO> convertList04(List<TradeOrderDO> list); List<TradeOrderRespDTO> convertList04(List<TradeOrderDO> list);
@Mappings({ @Mappings({

View File

@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
// TODO @puhui999单测可以后补下
/** /**
* 拼团活动的 {@link TradePriceCalculator} 实现类 * 拼团活动的 {@link TradePriceCalculator} 实现类
* *