mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-02-20 19:20:32 +08:00
code review:营销活动+订单
This commit is contained in:
parent
5235aff8ad
commit
87c55784c4
@ -68,14 +68,6 @@ public class CommonResult<T> implements Serializable {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> CommonResult<T> success(T data, String msg) {
|
||||
CommonResult<T> result = new CommonResult<>();
|
||||
result.code = GlobalErrorCodeConstants.SUCCESS.getCode();
|
||||
result.data = data;
|
||||
result.msg = msg;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isSuccess(Integer code) {
|
||||
return Objects.equals(code, GlobalErrorCodeConstants.SUCCESS.getCode());
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public interface CombinationRecordApi {
|
||||
void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount);
|
||||
|
||||
/**
|
||||
* 更新拼团状态为 成功
|
||||
* 更新拼团状态为成功
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param orderId 订单编号
|
||||
@ -60,7 +60,7 @@ public interface CombinationRecordApi {
|
||||
void updateRecordStatusToSuccess(Long userId, Long orderId);
|
||||
|
||||
/**
|
||||
* 更新拼团状态为 失败
|
||||
* 更新拼团状态为失败
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param orderId 订单编号
|
||||
|
@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillActivityUpdateSt
|
||||
*/
|
||||
public interface SeckillActivityApi {
|
||||
|
||||
|
||||
/**
|
||||
* 更新秒杀库存
|
||||
*
|
||||
|
@ -12,6 +12,10 @@ import java.util.List;
|
||||
@Data
|
||||
public class SeckillActivityUpdateStockReqDTO {
|
||||
|
||||
// TODO @puhui999:参数校验
|
||||
|
||||
// TODO @puhui999:秒杀的话,一次只能购买一种商品哈;不能多个哈;
|
||||
|
||||
/**
|
||||
* 活动编号
|
||||
*/
|
||||
|
@ -23,6 +23,7 @@ public class BargainActivityApiImpl implements BargainActivityApi {
|
||||
|
||||
@Override
|
||||
public void updateBargainActivityStock(Long activityId, Integer count) {
|
||||
// TODO @puhui999:可以整个实现到 bargainActivityService 中
|
||||
// 查询砍价活动
|
||||
BargainActivityDO activity = bargainActivityService.getBargainActivity(activityId);
|
||||
if (activity == null) {
|
||||
@ -30,6 +31,7 @@ public class BargainActivityApiImpl implements BargainActivityApi {
|
||||
}
|
||||
|
||||
// 更新砍价库存
|
||||
// TODO @puhui999:考虑下并发更新问题
|
||||
BargainActivityUpdateReqVO reqVO = new BargainActivityUpdateReqVO();
|
||||
reqVO.setId(activityId);
|
||||
reqVO.setStock(activity.getStock() - count);
|
||||
|
@ -27,14 +27,19 @@ public class SeckillActivityApiImpl implements SeckillActivityApi {
|
||||
@Resource
|
||||
private SeckillActivityService activityService;
|
||||
|
||||
// TODO @puhui:建议这块弄到 activityService 实现哈;
|
||||
// TODO @puhui:这个方法,要考虑事务性
|
||||
@Override
|
||||
public void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO) {
|
||||
// TODO @puhui999:长方法,最好有 1.1 1.2 2.1 这种步骤哈;
|
||||
SeckillActivityDO seckillActivity = activityService.getSeckillActivity(updateStockReqDTO.getActivityId());
|
||||
if (seckillActivity.getStock() < updateStockReqDTO.getCount()) {
|
||||
throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
|
||||
}
|
||||
// 获取活动商品
|
||||
// TODO @puhui999:在一个方法里,dos 和 dolist 最好保持一致,要么用 s,要么用 list 哈;
|
||||
List<SeckillProductDO> productDOs = activityService.getSeckillProductListByActivityId(updateStockReqDTO.getActivityId());
|
||||
// TODO @puhui999:这个是不是搞成 CollectionUtils.convertMultiMap()
|
||||
List<SeckillActivityUpdateStockReqDTO.Item> items = updateStockReqDTO.getItems();
|
||||
Map<Long, List<Long>> map = new HashMap<>();
|
||||
items.forEach(item -> {
|
||||
@ -49,9 +54,11 @@ public class SeckillActivityApiImpl implements SeckillActivityApi {
|
||||
}
|
||||
});
|
||||
// 过滤出购买的商品
|
||||
// TODO @puhui999:productDOList 可以简化成 productList;一般来说,do 之类不用带着哈,在变量里;
|
||||
List<SeckillProductDO> productDOList = CollectionUtils.filterList(productDOs, item -> map.get(item.getSpuId()).contains(item.getSkuId()));
|
||||
Map<Long, SeckillActivityUpdateStockReqDTO.Item> productDOMap = CollectionUtils.convertMap(items, SeckillActivityUpdateStockReqDTO.Item::getSkuId, p -> p);
|
||||
// 检查活动商品库存是否充足
|
||||
// TODO @puhui999:避免 b 这种无业务含义的变量;
|
||||
boolean b = CollectionUtils.anyMatch(productDOList, item -> {
|
||||
SeckillActivityUpdateStockReqDTO.Item item1 = productDOMap.get(item.getSkuId());
|
||||
return (item.getStock() < item1.getCount()) || (item.getStock() - item1.getCount()) < 0;
|
||||
@ -59,17 +66,19 @@ public class SeckillActivityApiImpl implements SeckillActivityApi {
|
||||
if (b) {
|
||||
throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
|
||||
}
|
||||
// TODO @puhui999:类似 doList,应该和下面的 update 逻辑粘的更紧密一点;so 在空行的时候,应该挪到 74 之后里去;甚至更合理,应该是 79 之后;说白了,逻辑要分块,每个模块涉及的代码要紧密在一起;
|
||||
List<SeckillProductDO> doList = CollectionUtils.convertList(productDOList, item -> {
|
||||
item.setStock(item.getStock() - productDOMap.get(item.getSkuId()).getCount());
|
||||
return item;
|
||||
});
|
||||
|
||||
// 更新活动库存
|
||||
// TODO @puhui999:考虑下并发更新
|
||||
seckillActivity.setStock(seckillActivity.getStock() + updateStockReqDTO.getCount());
|
||||
seckillActivity.setTotalStock(seckillActivity.getTotalStock() - updateStockReqDTO.getCount());
|
||||
activityService.updateSeckillActivity(seckillActivity);
|
||||
// 更新活动商品库存
|
||||
activityService.updateSeckillActivityProductByList(doList);
|
||||
activityService.updateSeckillActivityProductList(doList);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
// TODO 芋艿:把字段的顺序,和 do 顺序对齐下
|
||||
/**
|
||||
* 拼团记录 DO
|
||||
*
|
||||
@ -27,34 +28,28 @@ import java.time.LocalDateTime;
|
||||
@AllArgsConstructor
|
||||
public class CombinationRecordDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号,主键自增
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 拼团活动编号
|
||||
*
|
||||
* 关联 {@link CombinationActivityDO#getId()}
|
||||
*/
|
||||
private Long activityId;
|
||||
/**
|
||||
* 拼团商品单价
|
||||
*
|
||||
* 冗余 {@link CombinationProductDO#getCombinationPrice()}
|
||||
*/
|
||||
private Integer combinationPrice;
|
||||
/**
|
||||
* SPU 编号
|
||||
*/
|
||||
private Long spuId;
|
||||
/**
|
||||
* SKU 编号
|
||||
*/
|
||||
private Long skuId;
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 订单编号
|
||||
*/
|
||||
private Long orderId;
|
||||
/**
|
||||
* 团长编号
|
||||
*
|
||||
* 关联 {@link CombinationRecordDO#getId()}
|
||||
*/
|
||||
private Long headId;
|
||||
/**
|
||||
* 商品名字
|
||||
*/
|
||||
@ -64,9 +59,14 @@ public class CombinationRecordDO extends BaseDO {
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 拼团商品单价
|
||||
* SKU 编号
|
||||
*/
|
||||
private Integer combinationPrice;
|
||||
private Long skuId;
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@ -75,6 +75,13 @@ public class CombinationRecordDO extends BaseDO {
|
||||
* 用户头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 团长编号
|
||||
*
|
||||
* 关联 {@link CombinationRecordDO#getId()}
|
||||
*/
|
||||
private Long headId;
|
||||
/**
|
||||
* 开团状态
|
||||
*
|
||||
@ -82,23 +89,9 @@ public class CombinationRecordDO extends BaseDO {
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 是否虚拟成团
|
||||
* 订单编号
|
||||
*/
|
||||
private Boolean virtualGroup;
|
||||
/**
|
||||
* 过期时间
|
||||
*
|
||||
* {@link CombinationRecordDO#getStartTime()} + {@link CombinationActivityDO#getLimitDuration()} 计算
|
||||
*/
|
||||
private LocalDateTime expireTime;
|
||||
/**
|
||||
* 开始时间 (订单付款后开始的时间)
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
/**
|
||||
* 结束时间(成团时间/失败时间)
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
private Long orderId;
|
||||
/**
|
||||
* 开团需要人数
|
||||
*
|
||||
@ -109,5 +102,24 @@ public class CombinationRecordDO extends BaseDO {
|
||||
* 已加入拼团人数
|
||||
*/
|
||||
private Integer userCount;
|
||||
/**
|
||||
* 是否虚拟成团
|
||||
*/
|
||||
private Boolean virtualGroup;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*
|
||||
* 基于 {@link CombinationRecordDO#getStartTime()} + {@link CombinationActivityDO#getLimitDuration()} 计算
|
||||
*/
|
||||
private LocalDateTime expireTime;
|
||||
/**
|
||||
* 开始时间 (订单付款后开始的时间)
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
/**
|
||||
* 结束时间(成团时间/失败时间)
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ public interface SeckillActivityService {
|
||||
/**
|
||||
* 更新秒杀活动商品
|
||||
*
|
||||
* @param productDOList 活动商品列表
|
||||
* @param productList 活动商品列表
|
||||
*/
|
||||
void updateSeckillActivityProductByList(List<SeckillProductDO> productDOList);
|
||||
void updateSeckillActivityProductList(List<SeckillProductDO> productList);
|
||||
|
||||
/**
|
||||
* 关闭秒杀活动
|
||||
|
@ -93,8 +93,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
activityList.removeIf(item -> ObjectUtil.equal(item.getId(), activityId));
|
||||
}
|
||||
// 2.2 过滤出所有 configIds 有交集的活动,判断是否存在重叠
|
||||
List<SeckillActivityDO> activityDOs = filterList(activityList, s -> containsAny(s.getConfigIds(), configIds));
|
||||
if (isNotEmpty(activityDOs)) {
|
||||
List<SeckillActivityDO> conflictActivityList = filterList(activityList, s -> containsAny(s.getConfigIds(), configIds));
|
||||
if (isNotEmpty(conflictActivityList)) {
|
||||
throw exception(SECKILL_ACTIVITY_SPU_CONFLICTS);
|
||||
}
|
||||
}
|
||||
@ -150,8 +150,8 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSeckillActivityProductByList(List<SeckillProductDO> productDOList) {
|
||||
seckillProductMapper.updateBatch(productDOList);
|
||||
public void updateSeckillActivityProductList(List<SeckillProductDO> productList) {
|
||||
seckillProductMapper.updateBatch(productList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,6 @@ 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.common.util.servlet.ServletUtils.getClientIP;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.AFTER_SALE_NOT_FOUND;
|
||||
|
||||
@Tag(name = "管理后台 - 售后订单")
|
||||
@RestController
|
||||
@ -77,9 +76,11 @@ public class TradeAfterSaleController {
|
||||
public CommonResult<TradeAfterSaleDetailRespVO> getOrderDetail(@RequestParam("id") Long id) {
|
||||
// 查询订单
|
||||
TradeAfterSaleDO afterSale = afterSaleService.getAfterSale(id);
|
||||
if (afterSale == null) {
|
||||
return success(null, AFTER_SALE_NOT_FOUND.getMsg());
|
||||
}
|
||||
// TODO @puhui999:这里建议改成,如果为 null,直接返回 success null;主要查询操作,尽量不要有非空的提示哈;交给前端处理;
|
||||
// if (afterSale == null) {
|
||||
// return success(null, AFTER_SALE_NOT_FOUND.getMsg());
|
||||
// }
|
||||
|
||||
// 查询订单
|
||||
TradeOrderDO order = tradeOrderQueryService.getOrder(afterSale.getOrderId());
|
||||
// 查询订单项
|
||||
|
@ -25,7 +25,6 @@ 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.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
|
||||
|
||||
@Tag(name = "管理后台 - 交易订单")
|
||||
@RestController
|
||||
@ -68,9 +67,11 @@ public class TradeOrderController {
|
||||
public CommonResult<TradeOrderDetailRespVO> getOrderDetail(@RequestParam("id") Long id) {
|
||||
// 查询订单
|
||||
TradeOrderDO order = tradeOrderQueryService.getOrder(id);
|
||||
if (order == null) {
|
||||
return success(null, ORDER_NOT_FOUND.getMsg());
|
||||
}
|
||||
// TODO @puhui999:这里建议改成,如果为 null,直接返回 success null;主要查询操作,尽量不要有非空的提示哈;交给前端处理;
|
||||
// if (order == null) {
|
||||
// return success(null, ORDER_NOT_FOUND.getMsg());
|
||||
// }
|
||||
|
||||
// 查询订单项
|
||||
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id);
|
||||
// orderLog
|
||||
|
@ -33,7 +33,6 @@ 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.common.util.servlet.ServletUtils.getClientIP;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
|
||||
|
||||
@Tag(name = "用户 App - 交易订单")
|
||||
@RestController
|
||||
@ -82,9 +81,10 @@ public class AppTradeOrderController {
|
||||
public CommonResult<AppTradeOrderDetailRespVO> getOrder(@RequestParam("id") Long id) {
|
||||
// 查询订单
|
||||
TradeOrderDO order = tradeOrderQueryService.getOrder(getLoginUserId(), id);
|
||||
if (order == null) {
|
||||
return success(null, ORDER_NOT_FOUND.getMsg());
|
||||
}
|
||||
// TODO @puhui999:这里建议改成,如果为 null,直接返回 success null;主要查询操作,尽量不要有非空的提示哈;交给前端处理;
|
||||
// if (order == null) {
|
||||
// return success(null, ORDER_NOT_FOUND.getMsg());
|
||||
// }
|
||||
|
||||
// 查询订单项
|
||||
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(order.getId());
|
||||
|
@ -50,6 +50,7 @@ public class AppTradeOrderSettlementReqVO {
|
||||
private Long seckillActivityId;
|
||||
|
||||
// ========== 拼团活动相关字段 ==========
|
||||
// TODO @puhui999:是不是拼团记录的编号哈?
|
||||
@Schema(description = "拼团活动编号", example = "1024")
|
||||
private Long combinationActivityId;
|
||||
|
||||
@ -57,6 +58,7 @@ public class AppTradeOrderSettlementReqVO {
|
||||
private Long combinationHeadId;
|
||||
|
||||
// ========== 砍价活动相关字段 ==========
|
||||
// TODO @puhui999:是不是砍价记录的编号哈?
|
||||
@Schema(description = "砍价活动编号", example = "123")
|
||||
private Long bargainActivityId;
|
||||
|
||||
|
@ -15,6 +15,7 @@ import java.time.LocalDateTime;
|
||||
*/
|
||||
@Repository
|
||||
public class TradeOrderNoRedisDAO {
|
||||
|
||||
public static final String TRADE_ORDER_NO_PREFIX = "O";
|
||||
|
||||
@Resource
|
||||
|
@ -561,6 +561,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO @puhui999:考虑事务性
|
||||
public void updateOrderPrice(TradeOrderUpdatePriceReqVO reqVO) {
|
||||
// 校验交易订单
|
||||
TradeOrderDO order = validateOrderExists(reqVO.getId());
|
||||
@ -571,6 +572,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
throw exception(ORDER_UPDATE_PRICE_FAIL_EQUAL);
|
||||
}
|
||||
|
||||
// TODO @puhui999:应该是按照 payPrice 分配;并且要考虑取余问题;payPrice 也要考虑,item 里的
|
||||
List<TradeOrderItemDO> itemDOs = tradeOrderItemMapper.selectListByOrderId(order.getId());
|
||||
// TradeOrderItemDO 需要做 adjustPrice 的分摊
|
||||
int price = reqVO.getAdjustPrice() / itemDOs.size();
|
||||
@ -578,8 +580,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
item.setAdjustPrice(price);
|
||||
});
|
||||
// 更新 TradeOrderItem
|
||||
// TODO @puhui999:不要整个对象去更新哈;应该 new 一下;
|
||||
tradeOrderItemMapper.updateBatch(itemDOs);
|
||||
// 更新订单
|
||||
// TODO @puhui999:要考虑多次修改价格,不能单单的 payPrice + 价格;
|
||||
TradeOrderDO update = TradeOrderConvert.INSTANCE.convert(reqVO);
|
||||
update.setPayPrice(update.getPayPrice() + update.getAdjustPrice());
|
||||
// TODO @芋艿:改价时,赠送的积分,要不要做改动???
|
||||
|
@ -29,6 +29,7 @@ public interface PayOrderApi {
|
||||
*/
|
||||
PayOrderRespDTO getOrder(Long id);
|
||||
|
||||
// TODO @puhui999:可以去掉 byId;然后 payOrderId 参数改成 id;
|
||||
/**
|
||||
* 更新支付订单价格
|
||||
*
|
||||
@ -36,4 +37,5 @@ public interface PayOrderApi {
|
||||
* @param payPrice 支付单价格
|
||||
*/
|
||||
void updatePayOrderPriceById(Long payOrderId, Integer payPrice);
|
||||
|
||||
}
|
||||
|
@ -36,5 +36,4 @@ public class PayOrderApiImpl implements PayOrderApi {
|
||||
payOrderService.updatePayOrderPriceById(payOrderId, payPrice);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -413,6 +413,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
||||
|
||||
@Override
|
||||
public void updatePayOrderPriceById(Long payOrderId, Integer payPrice) {
|
||||
// TODO @puhui999:不能直接这样修改哈;应该只有未支付状态的订单才可以改;另外,如果价格如果没变,可以直接 return 哈;
|
||||
PayOrderDO order = orderMapper.selectById(payOrderId);
|
||||
if (order == null) {
|
||||
throw exception(ORDER_NOT_FOUND);
|
||||
|
Loading…
Reference in New Issue
Block a user