mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-13 01:31:53 +08:00
code review:积分、优惠劵、佣金等逻辑
This commit is contained in:
@@ -22,12 +22,16 @@ public interface ProductSpuApi {
|
||||
List<ProductSpuRespDTO> getSpuList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 批量查询 SPU 数组,并且校验是否 SPU 是否有效
|
||||
* 批量查询 SPU 数组,并且校验是否 SPU 是否有效。
|
||||
*
|
||||
* 如下情况,视为无效:
|
||||
* 1. 商品编号不存在
|
||||
* 2. 商品被禁用
|
||||
*
|
||||
* @param ids SPU 编号列表
|
||||
* @return SPU 数组
|
||||
*/
|
||||
List<ProductSpuRespDTO> getSpuListAndValidate(Collection<Long> ids);
|
||||
List<ProductSpuRespDTO> validateSpuList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得 SPU
|
||||
@@ -36,12 +40,4 @@ public interface ProductSpuApi {
|
||||
*/
|
||||
ProductSpuRespDTO getSpu(Long id);
|
||||
|
||||
/**
|
||||
* 校验商品是否有效。如下情况,视为无效:
|
||||
* 1. 商品编号不存在
|
||||
* 2. 商品被禁用
|
||||
*
|
||||
* @param ids 商品编号数组
|
||||
*/
|
||||
void validateSpuList(Collection<Long> ids);
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ public interface ErrorCodeConstants {
|
||||
// ========== 商品 SPU 1-008-005-000 ==========
|
||||
ErrorCode SPU_NOT_EXISTS = new ErrorCode(1_008_005_000, "商品 SPU 不存在");
|
||||
ErrorCode SPU_SAVE_FAIL_CATEGORY_LEVEL_ERROR = new ErrorCode(1_008_005_001, "商品分类不正确,原因:必须使用第二级的商品分类及以下");
|
||||
ErrorCode SPU_NOT_ENABLE = new ErrorCode(1_008_005_002, "商品 SPU【[]】不处于上架状态");
|
||||
ErrorCode SPU_NOT_ENABLE = new ErrorCode(1_008_005_002, "商品 SPU【{}】不处于上架状态");
|
||||
ErrorCode SPU_NOT_RECYCLE = new ErrorCode(1_008_005_003, "商品 SPU 不处于回收站状态");
|
||||
|
||||
// ========== 商品 SKU 1-008-006-000 ==========
|
||||
|
@@ -34,7 +34,7 @@ public class ProductSpuApiImpl implements ProductSpuApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductSpuRespDTO> getSpuListAndValidate(Collection<Long> ids) {
|
||||
public List<ProductSpuRespDTO> validateSpuList(Collection<Long> ids) {
|
||||
return ProductSpuConvert.INSTANCE.convertList2(spuService.validateSpuList(ids));
|
||||
}
|
||||
|
||||
@@ -43,9 +43,4 @@ public class ProductSpuApiImpl implements ProductSpuApi {
|
||||
return ProductSpuConvert.INSTANCE.convert02(spuService.getSpu(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateSpuList(Collection<Long> ids) {
|
||||
spuService.validateSpuList(ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -109,8 +109,8 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
return;
|
||||
}
|
||||
// 获得商品分类信息
|
||||
List<ProductCategoryDO> categoryList = productCategoryMapper.selectBatchIds(ids);
|
||||
Map<Long, ProductCategoryDO> categoryMap = CollectionUtils.convertMap(categoryList, ProductCategoryDO::getId);
|
||||
List<ProductCategoryDO> list = productCategoryMapper.selectBatchIds(ids);
|
||||
Map<Long, ProductCategoryDO> categoryMap = CollectionUtils.convertMap(list, ProductCategoryDO::getId);
|
||||
// 校验
|
||||
ids.forEach(id -> {
|
||||
ProductCategoryDO category = categoryMap.get(id);
|
||||
|
@@ -146,8 +146,8 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 获得商品信息
|
||||
List<ProductSpuDO> spuList = productSpuMapper.selectBatchIds(ids);
|
||||
Map<Long, ProductSpuDO> spuMap = CollectionUtils.convertMap(spuList, ProductSpuDO::getId);
|
||||
List<ProductSpuDO> list = productSpuMapper.selectBatchIds(ids);
|
||||
Map<Long, ProductSpuDO> spuMap = CollectionUtils.convertMap(list, ProductSpuDO::getId);
|
||||
// 校验
|
||||
ids.forEach(id -> {
|
||||
ProductSpuDO spu = spuMap.get(id);
|
||||
@@ -158,8 +158,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||
throw exception(SPU_NOT_ENABLE, spu.getName());
|
||||
}
|
||||
});
|
||||
|
||||
return spuList;
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -178,8 +178,9 @@ public class CouponServiceImpl implements CouponService {
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO @疯狂:搞个事务;
|
||||
public void takeCouponByRegister(Long userId) {
|
||||
List<CouponTemplateDO> templates = couponTemplateService.getCouponTemplateByTakeType(CouponTakeTypeEnum.REGISTER);
|
||||
List<CouponTemplateDO> templates = couponTemplateService.getCouponTemplateListByTakeType(CouponTakeTypeEnum.REGISTER);
|
||||
for (CouponTemplateDO template : templates) {
|
||||
takeCoupon(template.getId(), CollUtil.newHashSet(userId), CouponTakeTypeEnum.REGISTER);
|
||||
}
|
||||
@@ -226,16 +227,15 @@ public class CouponServiceImpl implements CouponService {
|
||||
|
||||
@Override
|
||||
public Map<Long, Boolean> getUserCanCanTakeMap(Long userId, List<CouponTemplateDO> templates) {
|
||||
// 1. 未登录时,都显示可以领取
|
||||
Map<Long, Boolean> userCanTakeMap = convertMap(templates, CouponTemplateDO::getId, templateId -> true);
|
||||
// 未登录时,都显示可以领取
|
||||
if (userId == null) {
|
||||
return userCanTakeMap;
|
||||
}
|
||||
|
||||
// 过滤领取数量无限制的
|
||||
// 2.1 过滤领取数量无限制的
|
||||
Set<Long> templateIds = convertSet(templates, CouponTemplateDO::getId, template -> template.getTakeLimitCount() != -1);
|
||||
|
||||
// 检查用户领取的数量是否超过限制
|
||||
// 2.2 检查用户领取的数量是否超过限制
|
||||
if (CollUtil.isNotEmpty(templateIds)) {
|
||||
Map<Long, Integer> couponTakeCountMap = this.getTakeCountMapByTemplateIds(templateIds, userId);
|
||||
for (CouponTemplateDO template : templates) {
|
||||
@@ -243,7 +243,6 @@ public class CouponServiceImpl implements CouponService {
|
||||
userCanTakeMap.put(template.getId(), takeCount == null || takeCount < template.getTakeLimitCount());
|
||||
}
|
||||
}
|
||||
|
||||
return userCanTakeMap;
|
||||
}
|
||||
|
||||
|
@@ -77,7 +77,7 @@ public interface CouponTemplateService {
|
||||
* @param takeType 领取方式
|
||||
* @return 优惠券模板列表
|
||||
*/
|
||||
List<CouponTemplateDO> getCouponTemplateByTakeType(CouponTakeTypeEnum takeType);
|
||||
List<CouponTemplateDO> getCouponTemplateListByTakeType(CouponTakeTypeEnum takeType);
|
||||
|
||||
/**
|
||||
* 获得优惠券模板列表
|
||||
|
@@ -116,7 +116,7 @@ public class CouponTemplateServiceImpl implements CouponTemplateService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CouponTemplateDO> getCouponTemplateByTakeType(CouponTakeTypeEnum takeType) {
|
||||
public List<CouponTemplateDO> getCouponTemplateListByTakeType(CouponTakeTypeEnum takeType) {
|
||||
return couponTemplateMapper.selectListByTakeType(takeType.getValue());
|
||||
}
|
||||
|
||||
|
@@ -109,8 +109,8 @@ public class TradeOrderDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 推广人编号
|
||||
* {@link BrokerageUserDO#getId()}
|
||||
* {@link MemberUserRespDTO#getId()}
|
||||
*
|
||||
* 关联 {@link BrokerageUserDO#getId()} 字段,即 {@link MemberUserRespDTO#getId()} 字段
|
||||
*/
|
||||
private Long brokerageUserId;
|
||||
|
||||
|
@@ -229,6 +229,10 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
|
||||
// 生成推广员编号列表
|
||||
List<Long> bindUserIds = buildBindUserIdsByLevel(userId, pageReqVO.getLevel());
|
||||
|
||||
// TODO @疯狂:情况一和情况二,可以合并哈;
|
||||
// 如果有 nickname 的时候,相当于提前查询 users,然后 nickname 过滤掉 bindUserIds;
|
||||
// 之后,继续使用 selectSummaryPageByUserId 里面 in bindUserIds 查询;
|
||||
|
||||
// 情况一:没有昵称过滤条件时,直接使用数据库的分页查询
|
||||
if (StrUtil.isBlank(pageReqVO.getNickname())) {
|
||||
// 1.1 分页查询
|
||||
|
@@ -236,6 +236,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
order.setReceiverName(createReqVO.getReceiverName()).setReceiverMobile(createReqVO.getReceiverMobile());
|
||||
order.setPickUpVerifyCode(RandomUtil.randomNumbers(8)); // 随机一个核销码,长度为 8 位
|
||||
}
|
||||
// TODO @疯狂:是不是可以在这里设置下推广人哈;
|
||||
tradeOrderMapper.insert(order);
|
||||
return order;
|
||||
}
|
||||
|
@@ -82,7 +82,7 @@ public class TradePriceServiceImpl implements TradePriceService {
|
||||
|
||||
private List<ProductSpuRespDTO> checkSpuList(List<ProductSkuRespDTO> skuList) {
|
||||
// 获得商品 SPU 数组
|
||||
return productSpuApi.getSpuListAndValidate(convertSet(skuList, ProductSkuRespDTO::getSpuId));
|
||||
return productSpuApi.validateSpuList(convertSet(skuList, ProductSkuRespDTO::getSpuId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
// TODO 芋艿:晚点 review
|
||||
/**
|
||||
* {@link TradePointGiveCalculator} 的单元测试类
|
||||
*
|
||||
@@ -95,4 +96,4 @@ public class TradePointGiveCalculatorTest extends BaseMockitoUnitTest {
|
||||
assertEquals(orderItem04.getPrice(), 60);
|
||||
assertEquals(orderItem04.getGivePoint(), 100); // 全局积分 + SKU 积分,但是未选中
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
// TODO 芋艿:晚点 review
|
||||
/**
|
||||
* {@link TradePointUsePriceCalculator } 的单元测试类
|
||||
*
|
||||
@@ -329,4 +330,4 @@ public class TradePointUsePriceCalculatorTest extends BaseMockitoUnitTest {
|
||||
// 断言:Promotion 部分
|
||||
assertEquals(result.getPromotions().size(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user