fix:完善拼团活动列表展示

This commit is contained in:
puhui999 2023-07-14 17:34:37 +08:00
parent 7cdb321fe4
commit 147cd271b8
8 changed files with 44 additions and 16 deletions

View File

@ -1,9 +1,13 @@
package cn.iocoder.yudao.module.promotion.controller.admin.combination;
import cn.hutool.core.collection.CollectionUtil;
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.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
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.combination.vo.activity.*;
import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationActivityDO;
@ -22,6 +26,7 @@ import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@ -34,6 +39,8 @@ public class CombinationActivityController {
@Resource
private CombinationActivityService combinationActivityService;
@Resource
private ProductSpuApi spuApi;
@PostMapping("/create")
@Operation(summary = "创建拼团活动")
@ -65,7 +72,7 @@ public class CombinationActivityController {
@PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')")
public CommonResult<CombinationActivityRespVO> getCombinationActivity(@RequestParam("id") Long id) {
CombinationActivityDO combinationActivity = combinationActivityService.getCombinationActivity(id);
List<CombinationProductDO> productDOs = combinationActivityService.getProductsByActivityId(id);
List<CombinationProductDO> productDOs = combinationActivityService.getProductsByActivityIds(CollectionUtil.newArrayList(id));
return success(CombinationActivityConvert.INSTANCE.convert(combinationActivity, productDOs));
}
@ -83,7 +90,11 @@ public class CombinationActivityController {
@PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')")
public CommonResult<PageResult<CombinationActivityRespVO>> getCombinationActivityPage(@Valid CombinationActivityPageReqVO pageVO) {
PageResult<CombinationActivityDO> pageResult = combinationActivityService.getCombinationActivityPage(pageVO);
return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult));
Set<Long> aIds = CollectionUtils.convertSet(pageResult.getList(), CombinationActivityDO::getId);
List<CombinationProductDO> productDOs = combinationActivityService.getProductsByActivityIds(aIds);
Set<Long> spuIds = CollectionUtils.convertSet(pageResult.getList(), CombinationActivityDO::getSpuId);
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(spuIds);
return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, productDOs, spuList));
}
@GetMapping("/export-excel")

View File

@ -17,6 +17,12 @@ import java.util.List;
@ToString(callSuper = true)
public class CombinationActivityRespVO extends CombinationActivityBaseVO {
@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, example = "22901")
private Long id;

View File

@ -18,7 +18,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促")
private String spuName;
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促")
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
private String picUrl;
@Schema(description = "秒杀活动id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.convert.combination;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
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.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.CombinationActivityExcelVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO;
@ -63,11 +64,7 @@ public interface CombinationActivityConvert {
default CombinationActivityRespVO convert(CombinationActivityDO bean, List<CombinationProductDO> productDOs) {
CombinationActivityRespVO respVO = convert(bean);
ArrayList<CombinationProductRespVO> vos = new ArrayList<>();
productDOs.forEach(item -> {
vos.add(convert(item));
});
respVO.setProducts(vos);
respVO.setProducts(convertList2(productDOs));
return respVO;
}
@ -75,6 +72,19 @@ public interface CombinationActivityConvert {
PageResult<CombinationActivityRespVO> convertPage(PageResult<CombinationActivityDO> page);
default PageResult<CombinationActivityRespVO> convertPage(PageResult<CombinationActivityDO> page, List<CombinationProductDO> productDOList, List<ProductSpuRespDTO> spuList) {
Map<Long, ProductSpuRespDTO> spuMap = CollectionUtils.convertMap(spuList, ProductSpuRespDTO::getId, c -> c);
PageResult<CombinationActivityRespVO> pageResult = convertPage(page);
pageResult.getList().forEach(item -> {
item.setSpuName(spuMap.get(item.getSpuId()).getName());
item.setPicUrl(spuMap.get(item.getSpuId()).getPicUrl());
item.setProducts(convertList2(productDOList));
});
return pageResult;
}
List<CombinationProductRespVO> convertList2(List<CombinationProductDO> productDOs);
List<CombinationActivityExcelVO> convertList02(List<CombinationActivityDO> list);
@Mappings({

View File

@ -62,7 +62,7 @@ public interface SeckillActivityConvert {
}
@Mappings({
@Mapping(target = "id", expression = "java(null)"),
@Mapping(target = "id", ignore = true),
@Mapping(target = "activityId", source = "activityDO.id"),
@Mapping(target = "configIds", source = "activityDO.configIds"),
@Mapping(target = "spuId", source = "activityDO.spuId"),

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.combinationactivity.CombinationProductDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
/**
@ -44,8 +45,8 @@ public interface CombinationProductMapper extends BaseMapperX<CombinationProduct
.orderByDesc(CombinationProductDO::getId));
}
default List<CombinationProductDO> selectListByActivityId(Long id) {
return selectList(CombinationProductDO::getActivityId, id);
default List<CombinationProductDO> selectListByActivityIds(Collection<Long> ids) {
return selectList(CombinationProductDO::getActivityId, ids);
}
}

View File

@ -76,8 +76,8 @@ public interface CombinationActivityService {
/**
* 获得拼团活动商品列表
*
* @param id 拼团活动 ID
* @param ids 拼团活动 ids
* @return 拼团活动的商品列表
*/
List<CombinationProductDO> getProductsByActivityId(Long id);
List<CombinationProductDO> getProductsByActivityIds(Collection<Long> ids);
}

View File

@ -129,7 +129,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
* @param products 商品配置
*/
private void updateCombinationProduct(CombinationActivityDO updateObj, List<CombinationProductUpdateReqVO> products) {
List<CombinationProductDO> combinationProductDOs = combinationProductMapper.selectListByActivityId(updateObj.getId());
List<CombinationProductDO> combinationProductDOs = combinationProductMapper.selectListByActivityIds(CollUtil.newArrayList(updateObj.getId()));
// 数据库中的活动商品
Set<Long> convertSet = CollectionUtils.convertSet(combinationProductDOs, CombinationProductDO::getSkuId);
// 前端传过来的活动商品
@ -197,8 +197,8 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
}
@Override
public List<CombinationProductDO> getProductsByActivityId(Long id) {
return combinationProductMapper.selectListByActivityId(id);
public List<CombinationProductDO> getProductsByActivityIds(Collection<Long> ids) {
return combinationProductMapper.selectListByActivityIds(ids);
}
}