code review 各种活动

This commit is contained in:
zhijiantianya@gmail.com 2023-08-07 19:30:26 +08:00
parent 0219e6d907
commit ba59ec85e0
23 changed files with 87 additions and 161 deletions

View File

@ -62,26 +62,6 @@ public class LocalDateTimeUtils {
return LocalDateTimeUtil.isIn(LocalDateTime.now(), startTime, endTime); return LocalDateTimeUtil.isIn(LocalDateTime.now(), startTime, endTime);
} }
/**
* 检查时间重叠 不包含日期
*
* @param startTime1 需要校验的开始时间
* @param endTime1 需要校验的结束时间
* @param startTime2 校验所需的开始时间
* @param endTime2 校验所需的结束时间
* @return 是否重叠
*/
@Deprecated
public static boolean checkTimeOverlap(LocalTime startTime1, LocalTime endTime1, LocalTime startTime2, LocalTime endTime2) {
// 判断时间是否重叠
// 开始时间在已配置时段的结束时间之前 结束时间在已配置时段的开始时间之后 []
return startTime1.isBefore(endTime2) && endTime1.isAfter(startTime2)
// 开始时间在已配置时段的开始时间之前 结束时间在已配置时段的开始时间之后 (] ()
|| startTime1.isBefore(startTime2) && endTime1.isAfter(startTime2)
// 开始时间在已配置时段的结束时间之前 结束时间在已配值时段的结束时间之后 [) ()
|| startTime1.isBefore(endTime2) && endTime1.isAfter(endTime2);
}
/** /**
* 判断时间段是否重叠 * 判断时间段是否重叠
* *
@ -92,7 +72,6 @@ public class LocalDateTimeUtils {
* @return 重叠true 不重叠false * @return 重叠true 不重叠false
*/ */
public static boolean isOverlap(LocalTime startTime1, LocalTime endTime1, LocalTime startTime2, LocalTime endTime2) { public static boolean isOverlap(LocalTime startTime1, LocalTime endTime1, LocalTime startTime2, LocalTime endTime2) {
// 日期部分使用了当前日期LocalDate.now()
LocalDate nowDate = LocalDate.now(); LocalDate nowDate = LocalDate.now();
return LocalDateTimeUtil.isOverlap(LocalDateTime.of(nowDate, startTime1), LocalDateTime.of(nowDate, endTime1), return LocalDateTimeUtil.isOverlap(LocalDateTime.of(nowDate, startTime1), LocalDateTime.of(nowDate, endTime1),
LocalDateTime.of(nowDate, startTime2), LocalDateTime.of(nowDate, endTime2)); LocalDateTime.of(nowDate, startTime2), LocalDateTime.of(nowDate, endTime2));

View File

@ -40,6 +40,7 @@ public class BargainRecordCreateReqDTO {
*/ */
@NotNull(message = "订单编号不能为空") @NotNull(message = "订单编号不能为空")
private Long orderId; private Long orderId;
// TODO @puhui999spuNamepicUrl 之类字段不用传递
/** /**
* 商品名字 * 商品名字
*/ */
@ -60,6 +61,7 @@ public class BargainRecordCreateReqDTO {
*/ */
@NotNull(message = "商品原价不能为空") @NotNull(message = "商品原价不能为空")
private Integer price; private Integer price;
// TODO @puhui999nicknameavatar 不用传递去查询
/** /**
* 用户昵称 * 用户昵称
*/ */

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.promotion.api.combination; package cn.iocoder.yudao.module.promotion.api.combination;
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.api.combination.dto.CombinationRecordUpdateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO;
import javax.validation.Valid; import javax.validation.Valid;
@ -18,7 +18,7 @@ public interface CombinationRecordApi {
* *
* @param reqDTO 请求 DTO * @param reqDTO 请求 DTO
*/ */
void createRecord(@Valid CombinationRecordCreateReqDTO reqDTO); void createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
/** /**
* 查询拼团记录是否成功 * 查询拼团记录是否成功
@ -27,13 +27,15 @@ public interface CombinationRecordApi {
* @param orderId 订单编号 * @param orderId 订单编号
* @return 拼团是否成功 * @return 拼团是否成功
*/ */
boolean isRecordSuccess(Long userId, Long orderId); boolean isCombinationRecordSuccess(Long userId, Long orderId);
// TODO @puhui999是不是搞成具体的方法拼团成功拼团失败这种方法
/** /**
* 更新开团记录状态 * 更新开团记录状态
* *
* @param reqDTO 请求 DTO * @param reqDTO 请求 DTO
*/ */
void updateRecordStatus(CombinationRecordUpdateReqDTO reqDTO); void updateCombinationRecordStatus(CombinationRecordUpdateStatusReqDTO reqDTO);
} }

View File

@ -6,12 +6,12 @@ import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
* 拼团记录的更新 Request DTO * 拼团记录的更新状态 Request DTO
* *
* @author HUIHUI * @author HUIHUI
*/ */
@Data @Data
public class CombinationRecordUpdateReqDTO { public class CombinationRecordUpdateStatusReqDTO {
/** /**
* 用户编号 * 用户编号

View File

@ -74,6 +74,9 @@ public interface ErrorCodeConstants {
ErrorCode BARGAIN_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013011001, "存在商品参加了其它砍价活动"); ErrorCode BARGAIN_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013011001, "存在商品参加了其它砍价活动");
ErrorCode BARGAIN_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013011002, "砍价活动已关闭不能修改"); ErrorCode BARGAIN_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013011002, "砍价活动已关闭不能修改");
ErrorCode BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013011003, "砍价活动未关闭或未结束,不能删除"); ErrorCode BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013011003, "砍价活动未关闭或未结束,不能删除");
// TODO @puhui999拆分成砍价记录
ErrorCode BARGAIN_RECORD_NOT_EXISTS = new ErrorCode(1013011004, "砍价不存在"); ErrorCode BARGAIN_RECORD_NOT_EXISTS = new ErrorCode(1013011004, "砍价不存在");
ErrorCode BARGAIN_RECORD_EXISTS = new ErrorCode(1013011005, "砍价失败,已参与过该砍价"); ErrorCode BARGAIN_RECORD_EXISTS = new ErrorCode(1013011005, "砍价失败,已参与过该砍价");
ErrorCode BARGAIN_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1013011006, "砍价失败,父砍价不存在"); ErrorCode BARGAIN_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1013011006, "砍价失败,父砍价不存在");

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.promotion.api.combination; package cn.iocoder.yudao.module.promotion.api.combination;
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.api.combination.dto.CombinationRecordUpdateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -20,17 +20,17 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
private CombinationRecordService recordService; private CombinationRecordService recordService;
@Override @Override
public void createRecord(CombinationRecordCreateReqDTO reqDTO) { public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
recordService.createCombinationRecord(reqDTO); recordService.createCombinationRecord(reqDTO);
} }
@Override @Override
public boolean isRecordSuccess(Long userId, Long orderId) { public boolean isCombinationRecordSuccess(Long userId, Long orderId) {
return CombinationRecordStatusEnum.isSuccess(recordService.getCombinationRecord(userId, orderId).getStatus()); return CombinationRecordStatusEnum.isSuccess(recordService.getCombinationRecord(userId, orderId).getStatus());
} }
@Override @Override
public void updateRecordStatus(CombinationRecordUpdateReqDTO reqDTO) { public void updateCombinationRecordStatus(CombinationRecordUpdateStatusReqDTO reqDTO) {
if (null == reqDTO.getStartTime()) { if (null == reqDTO.getStartTime()) {
recordService.updateCombinationRecordStatusByUserIdAndOrderId(reqDTO); recordService.updateCombinationRecordStatusByUserIdAndOrderId(reqDTO);
} else { } else {

View File

@ -17,6 +17,8 @@ import java.util.List;
@ToString(callSuper = true) @ToString(callSuper = true)
public class BargainActivityRespVO extends BargainActivityBaseVO { public class BargainActivityRespVO extends BargainActivityBaseVO {
// TODO @puhui999example 补全
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促")
private String spuName; private String spuName;

View File

@ -5,6 +5,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
// TODO @puhui999是不是应该把 BargainProductCreateReqVO BargainProductUpdateReqVO 合并在一起哈就是一个 SaveReqVO
@Schema(description = "管理后台 - 砍价商品创建 Request VO") @Schema(description = "管理后台 - 砍价商品创建 Request VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)

View File

@ -1,47 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 砍价商品分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BargainProductPageReqVO extends PageParam {
@Schema(description = "砍价活动编号", example = "6829")
private Long activityId;
@Schema(description = "商品 SPU 编号", example = "18731")
private Long spuId;
@Schema(description = "商品 SKU 编号", example = "31675")
private Long skuId;
@Schema(description = "砍价商品状态", example = "2")
private Integer activityStatus;
@Schema(description = "活动开始时间点")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] activityStartTime;
@Schema(description = "活动结束时间点")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] activityEndTime;
@Schema(description = "砍价价格,单位分", example = "27682")
private Integer activePrice;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -65,6 +65,7 @@ public interface BargainActivityConvert {
List<BargainProductRespVO> convertList2(List<BargainProductDO> productDOs); List<BargainProductRespVO> convertList2(List<BargainProductDO> productDOs);
// TODO @puhui999参数改成 activityproduct 会不会干净一点哈
@Mappings({ @Mappings({
@Mapping(target = "id", ignore = true), @Mapping(target = "id", ignore = true),
@Mapping(target = "activityId", source = "activityDO.id"), @Mapping(target = "activityId", source = "activityDO.id"),
@ -90,6 +91,4 @@ public interface BargainActivityConvert {
.setActivityStatus(activity.getStatus())); .setActivityStatus(activity.getStatus()));
} }
//BargainRecordDO convert(BargainRecordCreateReqDTO reqDTO);
} }

View File

@ -67,6 +67,7 @@ public interface CombinationActivityConvert {
List<CombinationProductRespVO> convertList2(List<CombinationProductDO> productDOs); List<CombinationProductRespVO> convertList2(List<CombinationProductDO> productDOs);
// TODO @puhui999参数改成 activityproduct 会不会干净一点哈
@Mappings({ @Mappings({
@Mapping(target = "id", ignore = true), @Mapping(target = "id", ignore = true),
@Mapping(target = "activityId", source = "activityDO.id"), @Mapping(target = "activityId", source = "activityDO.id"),

View File

@ -56,6 +56,7 @@ public interface SeckillActivityConvert {
return convert1(seckillActivity).setProducts(convertList2(seckillProducts)); return convert1(seckillActivity).setProducts(convertList2(seckillProducts));
} }
// TODO @puhui999参数改成 activityproduct 会不会干净一点哈
@Mappings({ @Mappings({
@Mapping(target = "id", ignore = true), @Mapping(target = "id", ignore = true),
@Mapping(target = "activityId", source = "activityDO.id"), @Mapping(target = "activityId", source = "activityDO.id"),

View File

@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*; import lombok.*;
/** /**
* 砍价助力 DO TODO * 砍价助力 DO TODO 芋艿表结构
* *
* @author HUIHUI * @author HUIHUI
*/ */

View File

@ -1,9 +1,6 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.bargain; package cn.iocoder.yudao.module.promotion.dal.mysql.bargain;
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.module.promotion.controller.admin.bargain.vo.product.BargainProductPageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -18,18 +15,6 @@ import java.util.List;
@Mapper @Mapper
public interface BargainProductMapper extends BaseMapperX<BargainProductDO> { public interface BargainProductMapper extends BaseMapperX<BargainProductDO> {
default PageResult<BargainProductDO> selectPage(BargainProductPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<BargainProductDO>()
.eqIfPresent(BargainProductDO::getActivityId, reqVO.getActivityId())
.eqIfPresent(BargainProductDO::getSpuId, reqVO.getSpuId())
.eqIfPresent(BargainProductDO::getSkuId, reqVO.getSkuId())
.eqIfPresent(BargainProductDO::getActivityStatus, reqVO.getActivityStatus())
.betweenIfPresent(BargainProductDO::getActivityStartTime, reqVO.getActivityStartTime())
.betweenIfPresent(BargainProductDO::getActivityEndTime, reqVO.getActivityEndTime())
.betweenIfPresent(BargainProductDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(BargainProductDO::getId));
}
default List<BargainProductDO> selectListByActivityIds(Collection<Long> ids) { default List<BargainProductDO> selectListByActivityIds(Collection<Long> ids) {
return selectList(BargainProductDO::getActivityId, ids); return selectList(BargainProductDO::getActivityId, ids);
} }

View File

@ -20,6 +20,7 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
CombinationRecordDO::getOrderId, orderId); CombinationRecordDO::getOrderId, orderId);
} }
// TODO @puhui999 selectByUserIdAndActivityId
/** /**
* 查询拼团记录 * 查询拼团记录
* *

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.promotion.service.combination; package cn.iocoder.yudao.module.promotion.service.combination;
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.api.combination.dto.CombinationRecordUpdateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
/** /**
@ -16,7 +16,7 @@ public interface CombinationRecordService {
* *
* @param reqDTO 请求 DTO * @param reqDTO 请求 DTO
*/ */
void updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordUpdateReqDTO reqDTO); void updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO);
/** /**
* 创建拼团记录 * 创建拼团记录
@ -30,7 +30,7 @@ public interface CombinationRecordService {
* *
* @param reqDTO 请求 DTO * @param reqDTO 请求 DTO
*/ */
void updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordUpdateReqDTO reqDTO); void updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO);
/** /**
* 获得拼团状态 * 获得拼团状态

View File

@ -11,7 +11,7 @@ import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
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.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO;
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.CombinationActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO;
@ -131,15 +131,14 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi
/** /**
* 更新拼团商品 * 更新拼团商品
* *
* @param updateObj 更新的活动 * @param activity 拼团活动
* @param products 商品配置 * @param products 该活动的最新商品配置
*/ */
private void updateCombinationProduct(CombinationActivityDO updateObj, List<CombinationProductUpdateReqVO> products) { private void updateCombinationProduct(CombinationActivityDO activity, List<CombinationProductUpdateReqVO> products) {
// 默认全部新增 // 第一步对比新老数据获得添加修改删除的列表
List<CombinationProductDO> defaultNewList = CombinationActivityConvert.INSTANCE.convertList(products, updateObj); List<CombinationProductDO> newList = CombinationActivityConvert.INSTANCE.convertList(products, activity);
// 数据库中的老数据 List<CombinationProductDO> oldList = combinationProductMapper.selectListByActivityIds(CollUtil.newArrayList(activity.getId()));
List<CombinationProductDO> oldList = combinationProductMapper.selectListByActivityIds(CollUtil.newArrayList(updateObj.getId())); List<List<CombinationProductDO>> diffList = CollectionUtils.diffList(oldList, newList, (oldVal, newVal) -> {
List<List<CombinationProductDO>> lists = CollectionUtils.diffList(oldList, defaultNewList, (oldVal, newVal) -> {
boolean same = ObjectUtil.equal(oldVal.getSkuId(), newVal.getSkuId()); boolean same = ObjectUtil.equal(oldVal.getSkuId(), newVal.getSkuId());
if (same) { if (same) {
newVal.setId(oldVal.getId()); newVal.setId(oldVal.getId());
@ -147,17 +146,15 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi
return same; return same;
}); });
// create // 第二步批量添加修改删除
if (CollUtil.isNotEmpty(lists.get(0))) { if (CollUtil.isNotEmpty(diffList.get(0))) {
combinationProductMapper.insertBatch(lists.get(0)); combinationProductMapper.insertBatch(diffList.get(0));
} }
// update if (CollUtil.isNotEmpty(diffList.get(1))) {
if (CollUtil.isNotEmpty(lists.get(1))) { combinationProductMapper.updateBatch(diffList.get(1));
combinationProductMapper.updateBatch(lists.get(1));
} }
// delete if (CollUtil.isNotEmpty(diffList.get(2))) {
if (CollUtil.isNotEmpty(lists.get(2))) { combinationProductMapper.deleteBatchIds(CollectionUtils.convertList(diffList.get(2), CombinationProductDO::getId));
combinationProductMapper.deleteBatchIds(CollectionUtils.convertList(lists.get(2), CombinationProductDO::getId));
} }
} }
@ -204,7 +201,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi
} }
@Override @Override
public void updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordUpdateReqDTO reqDTO) { public void updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO) {
// 校验拼团是否存在 // 校验拼团是否存在
CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId()); CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId());
@ -215,7 +212,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordUpdateReqDTO reqDTO) { public void updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO) {
CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId()); CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId());
// 更新状态 // 更新状态
recordDO.setStatus(reqDTO.getStatus()); recordDO.setStatus(reqDTO.getStatus());

View File

@ -137,16 +137,14 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
/** /**
* 更新秒杀商品 * 更新秒杀商品
* *
* @param updateObj 更新的活动 * @param activity 秒杀活动
* @param products 商品配置 * @param products 该活动的最新商品配置
*/ */
private void updateSeckillProduct(SeckillActivityDO updateObj, List<SeckillProductUpdateReqVO> products) { private void updateSeckillProduct(SeckillActivityDO activity, List<SeckillProductUpdateReqVO> products) {
// 默认全部新增 // 第一步对比新老数据获得添加修改删除的列表
List<SeckillProductDO> defaultNewList = SeckillActivityConvert.INSTANCE.convertList(products, updateObj); List<SeckillProductDO> newList = SeckillActivityConvert.INSTANCE.convertList(products, activity);
// 数据库中的活动商品 List<SeckillProductDO> oldList = seckillProductMapper.selectListByActivityId(activity.getId());
List<SeckillProductDO> oldList = seckillProductMapper.selectListByActivityId(updateObj.getId()); List<List<SeckillProductDO>> diffList = diffList(oldList, newList, (oldVal, newVal) -> {
// 对比老新两个列表找出新增修改删除的数据
List<List<SeckillProductDO>> lists = diffList(oldList, defaultNewList, (oldVal, newVal) -> {
boolean same = ObjectUtil.equal(oldVal.getSkuId(), newVal.getSkuId()); boolean same = ObjectUtil.equal(oldVal.getSkuId(), newVal.getSkuId());
if (same) { if (same) {
newVal.setId(oldVal.getId()); newVal.setId(oldVal.getId());
@ -154,17 +152,16 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
return same; return same;
}); });
// create // 第二步批量添加修改删除
if (isNotEmpty(lists.get(0))) { if (isNotEmpty(diffList.get(0))) {
seckillProductMapper.insertBatch(lists.get(0)); seckillProductMapper.insertBatch(diffList.get(0));
} }
// update if (isNotEmpty(diffList.get(1))) {
if (isNotEmpty(lists.get(1))) { seckillProductMapper.updateBatch(diffList.get(1));
seckillProductMapper.updateBatch(lists.get(1));
} }
// delete // delete
if (isNotEmpty(lists.get(2))) { if (isNotEmpty(diffList.get(2))) {
seckillProductMapper.deleteBatchIds(convertList(lists.get(2), SeckillProductDO::getId)); seckillProductMapper.deleteBatchIds(convertList(diffList.get(2), SeckillProductDO::getId));
} }
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.trade.enums; package cn.iocoder.yudao.module.trade.enums;
// TODO @芋艿枚举
/** /**
* 通知模板枚举类 * 通知模板枚举类
* *

View File

@ -1,4 +1,5 @@
package cn.iocoder.yudao.module.trade.enums.notify; package cn.iocoder.yudao.module.trade.enums.notify;
// TODO @芋艿这个枚举的作用
public interface TradeNotifyEnums { public interface TradeNotifyEnums {
} }

View File

@ -29,6 +29,7 @@ public class TradeMessageServiceImpl implements TradeMessageService {
Map<String, Object> msgMap = new HashMap<>(2); Map<String, Object> msgMap = new HashMap<>(2);
msgMap.put("orderId", reqBO.getOrderId()); msgMap.put("orderId", reqBO.getOrderId());
msgMap.put("deliveryMessage", reqBO.getMessage()); msgMap.put("deliveryMessage", reqBO.getMessage());
// TODO 芋艿看下模版
// 2发送站内信 // 2发送站内信
notifyMessageSendApi.sendSingleMessageToMember( notifyMessageSendApi.sendSingleMessageToMember(
new NotifySendSingleToUserReqDTO() new NotifySendSingleToUserReqDTO()

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.service.order;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
@ -22,7 +23,7 @@ import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDT
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO;
import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
@ -59,8 +60,6 @@ import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import static cn.hutool.core.util.ObjectUtil.equal;
import static cn.hutool.core.util.ObjectUtil.notEqual;
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.*;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -172,13 +171,13 @@ public class TradeOrderServiceImpl implements TradeOrderService {
afterCreateTradeOrder(userId, createReqVO, order, orderItems, calculateRespBO); afterCreateTradeOrder(userId, createReqVO, order, orderItems, calculateRespBO);
// 3.3 校验订单类型 // 3.3 校验订单类型
// 拼团 // 拼团
if (equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
MemberUserRespDTO user = memberUserApi.getUser(userId); MemberUserRespDTO user = memberUserApi.getUser(userId);
// TODO 拼团一次应该只能选择一种规格的商品 // TODO 拼团一次应该只能选择一种规格的商品
combinationRecordApi.createRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user)); combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user));
} }
// TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除 // TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除
if (equal(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) { if (Objects.equals(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) {
} }
@ -205,7 +204,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
TradePriceCalculateRespBO calculateRespBO) { TradePriceCalculateRespBO calculateRespBO) {
// 用户选择物流配送的时候才需要填写收货地址 // 用户选择物流配送的时候才需要填写收货地址
AddressRespDTO address = new AddressRespDTO(); AddressRespDTO address = new AddressRespDTO();
if (equal(createReqVO.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getMode())) { if (Objects.equals(createReqVO.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getMode())) {
// 用户收件地址的校验 // 用户收件地址的校验
address = validateAddress(userId, createReqVO.getAddressId()); address = validateAddress(userId, createReqVO.getAddressId());
} }
@ -309,9 +308,9 @@ public class TradeOrderServiceImpl implements TradeOrderService {
} }
// 校验活动 // 校验活动
// 1拼团活动 // 1拼团活动
if (equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
// 更新拼团状态 TODO puhui999订单支付失败或订单支付过期删除这条拼团记录 // 更新拼团状态 TODO puhui999订单支付失败或订单支付过期删除这条拼团记录
combinationRecordApi.updateRecordStatus(new CombinationRecordUpdateReqDTO().setUserId(order.getUserId()) combinationRecordApi.updateCombinationRecordStatus(new CombinationRecordUpdateStatusReqDTO().setUserId(order.getUserId())
.setOrderId(order.getId()).setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()).setStartTime(LocalDateTime.now())); .setOrderId(order.getId()).setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()).setStartTime(LocalDateTime.now()));
} }
// TODO 芋艿发送订单变化的消息 // TODO 芋艿发送订单变化的消息
@ -344,7 +343,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
throw exception(ORDER_UPDATE_PAID_STATUS_NOT_UNPAID); throw exception(ORDER_UPDATE_PAID_STATUS_NOT_UNPAID);
} }
// 校验支付订单匹配 // 校验支付订单匹配
if (notEqual(order.getPayOrderId(), payOrderId)) { // 支付单号 if (ObjectUtil.notEqual(order.getPayOrderId(), payOrderId)) { // 支付单号
log.error("[validateOrderPaid][order({}) 支付单不匹配({})请进行处理order 数据是:{}]", log.error("[validateOrderPaid][order({}) 支付单不匹配({})请进行处理order 数据是:{}]",
id, payOrderId, JsonUtils.toJsonString(order)); id, payOrderId, JsonUtils.toJsonString(order));
throw exception(ORDER_UPDATE_PAID_FAIL_PAY_ORDER_ID_ERROR); throw exception(ORDER_UPDATE_PAID_FAIL_PAY_ORDER_ID_ERROR);
@ -363,13 +362,13 @@ public class TradeOrderServiceImpl implements TradeOrderService {
throw exception(ORDER_UPDATE_PAID_FAIL_PAY_ORDER_STATUS_NOT_SUCCESS); throw exception(ORDER_UPDATE_PAID_FAIL_PAY_ORDER_STATUS_NOT_SUCCESS);
} }
// 校验支付金额一致 // 校验支付金额一致
if (notEqual(payOrder.getPrice(), order.getPayPrice())) { if (ObjectUtil.notEqual(payOrder.getPrice(), order.getPayPrice())) {
log.error("[validateOrderPaid][order({}) payOrder({}) 支付金额不匹配请进行处理order 数据是:{}payOrder 数据是:{}]", log.error("[validateOrderPaid][order({}) payOrder({}) 支付金额不匹配请进行处理order 数据是:{}payOrder 数据是:{}]",
id, payOrderId, JsonUtils.toJsonString(order), JsonUtils.toJsonString(payOrder)); id, payOrderId, JsonUtils.toJsonString(order), JsonUtils.toJsonString(payOrder));
throw exception(ORDER_UPDATE_PAID_FAIL_PAY_PRICE_NOT_MATCH); throw exception(ORDER_UPDATE_PAID_FAIL_PAY_PRICE_NOT_MATCH);
} }
// 校验支付订单匹配二次 // 校验支付订单匹配二次
if (notEqual(payOrder.getMerchantOrderId(), id.toString())) { if (ObjectUtil.notEqual(payOrder.getMerchantOrderId(), id.toString())) {
log.error("[validateOrderPaid][order({}) 支付单不匹配({})请进行处理payOrder 数据是:{}]", log.error("[validateOrderPaid][order({}) 支付单不匹配({})请进行处理payOrder 数据是:{}]",
id, payOrderId, JsonUtils.toJsonString(payOrder)); id, payOrderId, JsonUtils.toJsonString(payOrder));
throw exception(ORDER_UPDATE_PAID_FAIL_PAY_ORDER_ID_ERROR); throw exception(ORDER_UPDATE_PAID_FAIL_PAY_ORDER_ID_ERROR);
@ -393,19 +392,19 @@ public class TradeOrderServiceImpl implements TradeOrderService {
TradeOrderDO updateOrderObj = new TradeOrderDO(); TradeOrderDO updateOrderObj = new TradeOrderDO();
// 判断发货类型 // 判断发货类型
// 2.1 快递发货 // 2.1 快递发货
if (equal(deliveryReqVO.getType(), DeliveryTypeEnum.EXPRESS.getMode())) { if (Objects.equals(deliveryReqVO.getType(), DeliveryTypeEnum.EXPRESS.getMode())) {
// 校验快递公司 // 校验快递公司
validateDeliveryExpress(deliveryReqVO); validateDeliveryExpress(deliveryReqVO);
updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()); updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo());
} }
// 2.2 用户自提 // 2.2 用户自提
if (equal(deliveryReqVO.getType(), DeliveryTypeEnum.PICK_UP.getMode())) { if (Objects.equals(deliveryReqVO.getType(), DeliveryTypeEnum.PICK_UP.getMode())) {
// TODO 校验自提门店是否存在 // TODO 校验自提门店是否存在
// 重置一下确保快递公司和快递单号为空 // 重置一下确保快递公司和快递单号为空
updateOrderObj.setLogisticsId(null).setLogisticsNo(""); updateOrderObj.setLogisticsId(null).setLogisticsNo("");
} }
// 2.3 TODO 芋艿如果无需发货需要怎么存储回复需要把 deliverType 设置为 DeliveryTypeEnum.NULL // 2.3 TODO 芋艿如果无需发货需要怎么存储回复需要把 deliverType 设置为 DeliveryTypeEnum.NULL
if (equal(deliveryReqVO.getType(), DeliveryTypeEnum.NULL.getMode())) { if (Objects.equals(deliveryReqVO.getType(), DeliveryTypeEnum.NULL.getMode())) {
// TODO 情况一正常走发货逻辑和用户自提有点像 不同点不需要自提门店只需要用户确认收货 // TODO 情况一正常走发货逻辑和用户自提有点像 不同点不需要自提门店只需要用户确认收货
// TODO 情况二用户下单付款后直接确认收货或等待用户确认收货 // TODO 情况二用户下单付款后直接确认收货或等待用户确认收货
// 重置一下确保快递公司和快递单号为空 // 重置一下确保快递公司和快递单号为空
@ -455,17 +454,17 @@ public class TradeOrderServiceImpl implements TradeOrderService {
} }
// 校验订单是否是待发货状态 // 校验订单是否是待发货状态
if (!TradeOrderStatusEnum.isUndelivered(order.getStatus()) if (!TradeOrderStatusEnum.isUndelivered(order.getStatus())
|| notEqual(order.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus())) { || ObjectUtil.notEqual(order.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus())) {
throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED);
} }
// 校验订单是否退款 // 校验订单是否退款
if (notEqual(TradeOrderRefundStatusEnum.NONE.getStatus(), order.getRefundStatus())) { if (ObjectUtil.notEqual(TradeOrderRefundStatusEnum.NONE.getStatus(), order.getRefundStatus())) {
throw exception(ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE); throw exception(ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE);
} }
// 订单类型拼团 // 订单类型拼团
if (equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
// 校验订单拼团是否成功 // 校验订单拼团是否成功
if (combinationRecordApi.isRecordSuccess(order.getUserId(), order.getId())) { if (combinationRecordApi.isCombinationRecordSuccess(order.getUserId(), order.getId())) {
throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS);
} }
} }
@ -515,7 +514,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
} }
// 校验订单是否是待收货状态 // 校验订单是否是待收货状态
if (!TradeOrderStatusEnum.isDelivered(order.getStatus()) if (!TradeOrderStatusEnum.isDelivered(order.getStatus())
|| notEqual(order.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.DELIVERED.getStatus())) { || ObjectUtil.notEqual(order.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.DELIVERED.getStatus())) {
throw exception(ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED); throw exception(ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED);
} }
return order; return order;
@ -525,7 +524,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
public TradeOrderDO getOrder(Long userId, Long id) { public TradeOrderDO getOrder(Long userId, Long id) {
TradeOrderDO order = tradeOrderMapper.selectById(id); TradeOrderDO order = tradeOrderMapper.selectById(id);
if (order != null if (order != null
&& notEqual(order.getUserId(), userId)) { && ObjectUtil.notEqual(order.getUserId(), userId)) {
return null; return null;
} }
return order; return order;
@ -569,7 +568,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
public TradeOrderItemDO getOrderItem(Long userId, Long itemId) { public TradeOrderItemDO getOrderItem(Long userId, Long itemId) {
TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(itemId); TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(itemId);
if (orderItem != null if (orderItem != null
&& notEqual(orderItem.getUserId(), userId)) { && ObjectUtil.notEqual(orderItem.getUserId(), userId)) {
return null; return null;
} }
return orderItem; return orderItem;
@ -649,10 +648,10 @@ public class TradeOrderServiceImpl implements TradeOrderService {
if (order == null) { if (order == null) {
throw exception(ORDER_NOT_FOUND); throw exception(ORDER_NOT_FOUND);
} }
if (notEqual(order.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus())) { if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus())) {
throw exception(ORDER_COMMENT_FAIL_STATUS_NOT_COMPLETED); throw exception(ORDER_COMMENT_FAIL_STATUS_NOT_COMPLETED);
} }
if (notEqual(order.getCommentStatus(), Boolean.FALSE)) { if (ObjectUtil.notEqual(order.getCommentStatus(), Boolean.FALSE)) {
throw exception(ORDER_COMMENT_STATUS_NOT_FALSE); throw exception(ORDER_COMMENT_STATUS_NOT_FALSE);
} }
@ -662,7 +661,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
// 更新订单项评价状态 // 更新订单项评价状态
tradeOrderItemMapper.updateById(new TradeOrderItemDO().setId(orderItem.getId()).setCommentStatus(Boolean.TRUE)); tradeOrderItemMapper.updateById(new TradeOrderItemDO().setId(orderItem.getId()).setCommentStatus(Boolean.TRUE));
List<TradeOrderItemDO> orderItems = getOrderItemListByOrderId(CollUtil.newArrayList(order.getId())); List<TradeOrderItemDO> orderItems = getOrderItemListByOrderId(CollUtil.newArrayList(order.getId()));
if (!anyMatch(orderItems, item -> equal(item.getCommentStatus(), Boolean.FALSE))) { if (!anyMatch(orderItems, item -> Objects.equals(item.getCommentStatus(), Boolean.FALSE))) {
// 对于 order 来说就是评论完 order 更新完合理的 status 等字段 // 对于 order 来说就是评论完 order 更新完合理的 status 等字段
tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setCommentStatus(Boolean.TRUE)); tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setCommentStatus(Boolean.TRUE));
} }

View File

@ -252,6 +252,7 @@ public class PayNotifyServiceImpl implements PayNotifyService {
notifyTaskMapper.updateById(updateTask); notifyTaskMapper.updateById(updateTask);
return updateTask.getStatus(); return updateTask.getStatus();
} }
// 情况二调用失败调用异常 // 情况二调用失败调用异常
// 2.1 超过最大回调次数 // 2.1 超过最大回调次数
if (updateTask.getNotifyTimes() >= PayNotifyTaskDO.NOTIFY_FREQUENCY.length) { if (updateTask.getNotifyTimes() >= PayNotifyTaskDO.NOTIFY_FREQUENCY.length) {