将 mall 使用到 Date 的部分,迁移到 LocalDateTime 中

This commit is contained in:
YunaiV 2022-11-13 21:23:38 +08:00
parent 12d045ea58
commit 38f67d4130
21 changed files with 123 additions and 115 deletions

View File

@ -1,13 +1,8 @@
package cn.iocoder.yudao.framework.common.util.date; package cn.iocoder.yudao.framework.common.util.date;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.date.LocalDateTimeUtil;
import java.time.Duration; import java.time.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@ -58,6 +53,7 @@ public class DateUtils {
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
} }
@Deprecated
public static Date addTime(Duration duration) { public static Date addTime(Duration duration) {
return new Date(System.currentTimeMillis() + duration.toMillis()); return new Date(System.currentTimeMillis() + duration.toMillis());
} }
@ -87,6 +83,7 @@ public class DateUtils {
return buildTime(year, mouth, day, 0, 0, 0); return buildTime(year, mouth, day, 0, 0, 0);
} }
@Deprecated
public static LocalDateTime buildLocalDateTime(int year, int mouth, int day) { public static LocalDateTime buildLocalDateTime(int year, int mouth, int day) {
return LocalDateTime.of(year, mouth, day, 0, 0, 0); return LocalDateTime.of(year, mouth, day, 0, 0, 0);
} }
@ -135,14 +132,7 @@ public class DateUtils {
return a.isAfter(b) ? a : b; return a.isAfter(b) ? a : b;
} }
public static boolean beforeNow(Date date) { @Deprecated
return date.getTime() < System.currentTimeMillis();
}
public static boolean afterNow(Date date) {
return date.getTime() >= System.currentTimeMillis();
}
public static boolean afterNow(LocalDateTime localDateTime) { public static boolean afterNow(LocalDateTime localDateTime) {
return localDateTime.isAfter(LocalDateTime.now()); return localDateTime.isAfter(LocalDateTime.now());
} }
@ -178,19 +168,6 @@ public class DateUtils {
return c.getTime(); return c.getTime();
} }
/**
* 是否今天
*
* @param date 日期
* @return 是否
*/
public static boolean isToday(Date date) {
if (date == null) {
return false;
}
return DateUtil.isSameDay(date, new Date());
}
/** /**
* 是否今天 * 是否今天
* *
@ -201,19 +178,4 @@ public class DateUtils {
return LocalDateTimeUtil.isSameDay(date, LocalDateTime.now()); return LocalDateTimeUtil.isSameDay(date, LocalDateTime.now());
} }
/**
* 判断当前时间是否在该时间范围内
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 是否
*/
public static boolean isBetween(Date startTime, Date endTime) {
if (startTime == null || endTime == null) {
return false;
}
return startTime.getTime() <= System.currentTimeMillis()
&& endTime.getTime() >= System.currentTimeMillis();
}
} }

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.framework.common.util.date; package cn.iocoder.yudao.framework.common.util.date;
import cn.hutool.core.date.LocalDateTimeUtil;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -14,4 +16,38 @@ public class LocalDateTimeUtils {
return LocalDateTime.now().plus(duration); return LocalDateTime.now().plus(duration);
} }
public static boolean beforeNow(LocalDateTime date) {
return date.isBefore(LocalDateTime.now());
}
public static boolean afterNow(LocalDateTime date) {
return date.isAfter(LocalDateTime.now());
}
/**
* 创建指定时间
*
* @param year
* @param mouth
* @param day
* @return 指定时间
*/
public static LocalDateTime buildTime(int year, int mouth, int day) {
return LocalDateTime.of(year, mouth, day, 0, 0, 0);
}
/**
* 判断当前时间是否在该时间范围内
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 是否
*/
public static boolean isBetween(LocalDateTime startTime, LocalDateTime endTime) {
if (startTime == null || endTime == null) {
return false;
}
return LocalDateTimeUtil.isIn(LocalDateTime.now(), startTime, endTime);
}
} }

View File

@ -6,7 +6,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import java.util.Date; import java.time.LocalDateTime;
@ApiModel("管理后台 - 规格 + 规格值 Response VO") @ApiModel("管理后台 - 规格 + 规格值 Response VO")
@Data @Data
@ -18,6 +18,6 @@ public class ProductPropertyRespVO extends ProductPropertyBaseVO {
private Long id; private Long id;
@ApiModelProperty(value = "创建时间", required = true) @ApiModelProperty(value = "创建时间", required = true)
private Date createTime; private LocalDateTime createTime;
} }

View File

@ -10,7 +10,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.Date; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -55,12 +55,12 @@ public class CouponBaseVO {
@ApiModelProperty(value = "固定日期 - 生效开始时间") @ApiModelProperty(value = "固定日期 - 生效开始时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
private Date validStartTime; private LocalDateTime validStartTime;
@ApiModelProperty(value = "固定日期 - 生效结束时间") @ApiModelProperty(value = "固定日期 - 生效结束时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
private Date validEndTime; private LocalDateTime validEndTime;
@ApiModelProperty(value = "商品范围", required = true, example = "1", notes = "参见 PromotionProductScopeEnum 枚举类") @ApiModelProperty(value = "商品范围", required = true, example = "1", notes = "参见 PromotionProductScopeEnum 枚举类")
@NotNull(message = "商品范围不能为空") @NotNull(message = "商品范围不能为空")
@ -96,7 +96,7 @@ public class CouponBaseVO {
@ApiModelProperty(value = "使用时间") @ApiModelProperty(value = "使用时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
private Date useTime; private LocalDateTime useTime;
// ========== 使用情况 END ========== // ========== 使用情况 END ==========

View File

@ -6,7 +6,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import java.util.Date; import java.time.LocalDateTime;
@ApiModel("管理后台 - 优惠劵 Response VO") @ApiModel("管理后台 - 优惠劵 Response VO")
@Data @Data
@ -18,6 +18,6 @@ public class CouponRespVO extends CouponBaseVO {
private Long id; private Long id;
@ApiModelProperty(value = "创建时间", required = true) @ApiModelProperty(value = "创建时间", required = true)
private Date createTime; private LocalDateTime createTime;
} }

View File

@ -15,7 +15,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.AssertTrue; import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.Date; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -65,12 +65,12 @@ public class CouponTemplateBaseVO {
@ApiModelProperty(value = "固定日期 - 生效开始时间") @ApiModelProperty(value = "固定日期 - 生效开始时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
private Date validStartTime; private LocalDateTime validStartTime;
@ApiModelProperty(value = "固定日期 - 生效结束时间") @ApiModelProperty(value = "固定日期 - 生效结束时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
private Date validEndTime; private LocalDateTime validEndTime;
@ApiModelProperty(value = "领取日期 - 开始天数") @ApiModelProperty(value = "领取日期 - 开始天数")
@Min(value = 0L, message = "开始天数必须大于 0") @Min(value = 0L, message = "开始天数必须大于 0")

View File

@ -8,7 +8,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import java.util.Date; import java.time.LocalDateTime;
@ApiModel("管理后台 - 优惠劵模板 Response VO") @ApiModel("管理后台 - 优惠劵模板 Response VO")
@Data @Data
@ -30,6 +30,6 @@ public class CouponTemplateRespVO extends CouponTemplateBaseVO {
private Integer useCount; private Integer useCount;
@ApiModelProperty(value = "创建时间", required = true) @ApiModelProperty(value = "创建时间", required = true)
private Date createTime; private LocalDateTime createTime;
} }

View File

@ -12,7 +12,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.AssertTrue; import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.Date; import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -30,12 +30,12 @@ public class DiscountActivityBaseVO {
@ApiModelProperty(value = "开始时间", required = true) @ApiModelProperty(value = "开始时间", required = true)
@NotNull(message = "开始时间不能为空") @NotNull(message = "开始时间不能为空")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date startTime; private LocalDateTime startTime;
@ApiModelProperty(value = "结束时间", required = true) @ApiModelProperty(value = "结束时间", required = true)
@NotNull(message = "结束时间不能为空") @NotNull(message = "结束时间不能为空")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date endTime; private LocalDateTime endTime;
@ApiModelProperty(value = "备注", example = "我是备注") @ApiModelProperty(value = "备注", example = "我是备注")
private String remark; private String remark;

View File

@ -1,11 +1,15 @@
package cn.iocoder.yudao.module.promotion.controller.admin.discount.vo; package cn.iocoder.yudao.module.promotion.controller.admin.discount.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat; 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; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel("管理后台 - 限时折扣活动分页 Request VO") @ApiModel("管理后台 - 限时折扣活动分页 Request VO")
@ -22,6 +26,6 @@ public class DiscountActivityPageReqVO extends PageParam {
@ApiModelProperty(value = "创建时间") @ApiModelProperty(value = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date[] createTime; private LocalDateTime[] createTime;
} }

View File

@ -7,7 +7,7 @@ import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.Date; import java.time.LocalDateTime;
@ApiModel("管理后台 - 限时折扣活动 Response VO") @ApiModel("管理后台 - 限时折扣活动 Response VO")
@Data @Data
@ -23,6 +23,6 @@ public class DiscountActivityRespVO extends DiscountActivityBaseVO {
private Integer status; private Integer status;
@ApiModelProperty(value = "创建时间", required = true) @ApiModelProperty(value = "创建时间", required = true)
private Date createTime; private LocalDateTime createTime;
} }

View File

@ -14,7 +14,7 @@ import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.Future; import javax.validation.constraints.Future;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.Date; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -33,13 +33,13 @@ public class RewardActivityBaseVO {
@ApiModelProperty(value = "开始时间", required = true) @ApiModelProperty(value = "开始时间", required = true)
@NotNull(message = "开始时间不能为空") @NotNull(message = "开始时间不能为空")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date startTime; private LocalDateTime startTime;
@ApiModelProperty(value = "结束时间", required = true) @ApiModelProperty(value = "结束时间", required = true)
@NotNull(message = "结束时间不能为空") @NotNull(message = "结束时间不能为空")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@Future(message = "结束时间必须大于当前时间") @Future(message = "结束时间必须大于当前时间")
private Date endTime; private LocalDateTime endTime;
@ApiModelProperty(value = "备注", example = "biubiubiu") @ApiModelProperty(value = "备注", example = "biubiubiu")
private String remark; private String remark;

View File

@ -1,8 +1,12 @@
package cn.iocoder.yudao.module.promotion.controller.admin.reward.vo; package cn.iocoder.yudao.module.promotion.controller.admin.reward.vo;
import lombok.*; import io.swagger.annotations.ApiModel;
import java.util.*; import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.*; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@ApiModel("管理后台 - 满减送活动 Response VO") @ApiModel("管理后台 - 满减送活动 Response VO")
@Data @Data
@ -17,6 +21,6 @@ public class RewardActivityRespVO extends RewardActivityBaseVO {
private Integer status; private Integer status;
@ApiModelProperty(value = "创建时间", required = true) @ApiModelProperty(value = "创建时间", required = true)
private Date createTime; private LocalDateTime createTime;
} }

View File

@ -12,7 +12,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.Date; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -77,11 +77,11 @@ public class CouponDO extends BaseDO {
/** /**
* 生效开始时间 * 生效开始时间
*/ */
private Date validStartTime; private LocalDateTime validStartTime;
/** /**
* 生效结束时间 * 生效结束时间
*/ */
private Date validEndTime; private LocalDateTime validEndTime;
/** /**
* 商品范围 * 商品范围
* *
@ -132,7 +132,7 @@ public class CouponDO extends BaseDO {
/** /**
* 使用时间 * 使用时间
*/ */
private Date useTime; private LocalDateTime useTime;
// ========== 使用情况 END ========== // ========== 使用情况 END ==========

View File

@ -14,7 +14,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.Date; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -100,13 +100,13 @@ public class CouponTemplateDO extends BaseDO {
* *
* {@link #validityType} {@link CouponTemplateValidityTypeEnum#DATE} * {@link #validityType} {@link CouponTemplateValidityTypeEnum#DATE}
*/ */
private Date validStartTime; private LocalDateTime validStartTime;
/** /**
* 固定日期 - 生效结束时间 * 固定日期 - 生效结束时间
* *
* {@link #validityType} {@link CouponTemplateValidityTypeEnum#DATE} * {@link #validityType} {@link CouponTemplateValidityTypeEnum#DATE}
*/ */
private Date validEndTime; private LocalDateTime validEndTime;
/** /**
* 领取日期 - 开始天数 * 领取日期 - 开始天数
* *

View File

@ -5,7 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
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.UserRespDTO; import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO;
@ -17,7 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -60,7 +60,7 @@ public class CouponServiceImpl implements CouponService {
throw exception(COUPON_STATUS_NOT_UNUSED); throw exception(COUPON_STATUS_NOT_UNUSED);
} }
// 校验有效期为避免定时器没跑实际优惠劵已经过期 // 校验有效期为避免定时器没跑实际优惠劵已经过期
if (DateUtils.isBetween(coupon.getValidStartTime(), coupon.getValidEndTime())) { if (LocalDateTimeUtils.isBetween(coupon.getValidStartTime(), coupon.getValidEndTime())) {
throw exception(COUPON_VALID_TIME_NOT_NOW); throw exception(COUPON_VALID_TIME_NOT_NOW);
} }
} }
@ -87,7 +87,7 @@ public class CouponServiceImpl implements CouponService {
// 更新状态 // 更新状态
int updateCount = couponMapper.updateByIdAndStatus(id, CouponStatusEnum.UNUSED.getStatus(), int updateCount = couponMapper.updateByIdAndStatus(id, CouponStatusEnum.UNUSED.getStatus(),
new CouponDO().setStatus(CouponStatusEnum.USED.getStatus()) new CouponDO().setStatus(CouponStatusEnum.USED.getStatus())
.setUseOrderId(orderId).setUseTime(new Date())); .setUseOrderId(orderId).setUseTime(LocalDateTime.now()));
if (updateCount == 0) { if (updateCount == 0) {
throw exception(COUPON_STATUS_NOT_UNUSED); throw exception(COUPON_STATUS_NOT_UNUSED);
} }

View File

@ -1,9 +1,9 @@
package cn.iocoder.yudao.module.promotion.util; package cn.iocoder.yudao.module.promotion.util;
import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum;
import java.util.Date; import java.time.LocalDateTime;
/** /**
* 活动工具类 * 活动工具类
@ -19,11 +19,11 @@ public class PromotionUtils {
* @param endTime 结束时间 * @param endTime 结束时间
* @return 活动状态 * @return 活动状态
*/ */
public static Integer calculateActivityStatus(Date startTime, Date endTime) { public static Integer calculateActivityStatus(LocalDateTime startTime, LocalDateTime endTime) {
if (DateUtils.beforeNow(endTime)) { if (LocalDateTimeUtils.beforeNow(endTime)) {
return PromotionActivityStatusEnum.END.getStatus(); return PromotionActivityStatusEnum.END.getStatus();
} }
if (DateUtils.afterNow(startTime)) { if (LocalDateTimeUtils.afterNow(startTime)) {
return PromotionActivityStatusEnum.WAIT.getStatus(); return PromotionActivityStatusEnum.WAIT.getStatus();
} }
return PromotionActivityStatusEnum.RUN.getStatus(); return PromotionActivityStatusEnum.RUN.getStatus();

View File

@ -17,10 +17,12 @@ import org.springframework.context.annotation.Import;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
@ -182,7 +184,7 @@ public class DiscountActivityServiceImplTest extends BaseDbUnitTest {
DiscountActivityDO dbDiscountActivity = randomPojo(DiscountActivityDO.class, o -> { // 等会查询到 DiscountActivityDO dbDiscountActivity = randomPojo(DiscountActivityDO.class, o -> { // 等会查询到
o.setName("芋艿"); o.setName("芋艿");
o.setStatus(PromotionActivityStatusEnum.WAIT.getStatus()); o.setStatus(PromotionActivityStatusEnum.WAIT.getStatus());
o.setCreateTime(buildLocalDateTime(2021, 1, 15)); o.setCreateTime(buildTime(2021, 1, 15));
}); });
discountActivityMapper.insert(dbDiscountActivity); discountActivityMapper.insert(dbDiscountActivity);
// 测试 name 不匹配 // 测试 name 不匹配
@ -190,12 +192,12 @@ public class DiscountActivityServiceImplTest extends BaseDbUnitTest {
// 测试 status 不匹配 // 测试 status 不匹配
discountActivityMapper.insert(cloneIgnoreId(dbDiscountActivity, o -> o.setStatus(PromotionActivityStatusEnum.END.getStatus()))); discountActivityMapper.insert(cloneIgnoreId(dbDiscountActivity, o -> o.setStatus(PromotionActivityStatusEnum.END.getStatus())));
// 测试 createTime 不匹配 // 测试 createTime 不匹配
discountActivityMapper.insert(cloneIgnoreId(dbDiscountActivity, o -> o.setCreateTime(buildLocalDateTime(2021, 2, 10)))); discountActivityMapper.insert(cloneIgnoreId(dbDiscountActivity, o -> o.setCreateTime(buildTime(2021, 2, 10))));
// 准备参数 // 准备参数
DiscountActivityPageReqVO reqVO = new DiscountActivityPageReqVO(); DiscountActivityPageReqVO reqVO = new DiscountActivityPageReqVO();
reqVO.setName("芋艿"); reqVO.setName("芋艿");
reqVO.setStatus(PromotionActivityStatusEnum.WAIT.getStatus()); reqVO.setStatus(PromotionActivityStatusEnum.WAIT.getStatus());
reqVO.setCreateTime((new Date[]{buildTime(2021, 1, 1), buildTime(2021, 1, 31)})); reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 1), buildTime(2021, 1, 31)}));
// 调用 // 调用
PageResult<DiscountActivityDO> pageResult = discountActivityService.getDiscountActivityPage(reqVO); PageResult<DiscountActivityDO> pageResult = discountActivityService.getDiscountActivityPage(reqVO);

View File

@ -495,7 +495,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
CouponMeetRespDTO couponMeetRespDTO03 = list.get(2); CouponMeetRespDTO couponMeetRespDTO03 = list.get(2);
assertPojoEquals(couponMeetRespDTO03, coupon03); assertPojoEquals(couponMeetRespDTO03, coupon03);
assertFalse(couponMeetRespDTO03.getMeet()); assertFalse(couponMeetRespDTO03.getMeet());
assertEquals(couponMeetRespDTO03.getMeetTip(), "差 1.00 元可用优惠劵"); assertEquals(couponMeetRespDTO03.getMeetTip(), "所结算的商品中未满足使用的金额");
// 断言情况四满足条件 // 断言情况四满足条件
CouponMeetRespDTO couponMeetRespDTO04 = list.get(3); CouponMeetRespDTO couponMeetRespDTO04 = list.get(3);
assertPojoEquals(couponMeetRespDTO04, coupon04); assertPojoEquals(couponMeetRespDTO04, coupon04);

View File

@ -20,7 +20,7 @@ import java.util.Set;
import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.hutool.core.util.RandomUtil.randomEle;
import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.addTime; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;

View File

@ -41,21 +41,21 @@
<artifactId>yudao-module-pay-biz</artifactId> <artifactId>yudao-module-pay-biz</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>cn.iocoder.boot</groupId>--> <groupId>cn.iocoder.boot</groupId>
<!-- <artifactId>yudao-module-promotion-biz</artifactId>--> <artifactId>yudao-module-promotion-biz</artifactId>
<!-- <version>${revision}</version>--> <version>${revision}</version>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>cn.iocoder.boot</groupId>--> <groupId>cn.iocoder.boot</groupId>
<!-- <artifactId>yudao-module-product-biz</artifactId>--> <artifactId>yudao-module-product-biz</artifactId>
<!-- <version>${revision}</version>--> <version>${revision}</version>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>cn.iocoder.boot</groupId>--> <groupId>cn.iocoder.boot</groupId>
<!-- <artifactId>yudao-module-trade-biz</artifactId>--> <artifactId>yudao-module-trade-biz</artifactId>
<!-- <version>${revision}</version>--> <version>${revision}</version>
<!-- </dependency>--> </dependency>
<!-- 数据报表 --> <!-- 数据报表 -->
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>cn.iocoder.boot</groupId>--> <!-- <groupId>cn.iocoder.boot</groupId>-->

View File

@ -30,7 +30,7 @@ spring:
multi-statement-allow: true multi-statement-allow: true
dynamic: # 多数据源配置 dynamic: # 多数据源配置
druid: # Druid 【连接池】相关的全局配置 druid: # Druid 【连接池】相关的全局配置
initial-size: 1 # 初始连接数 initial-size: 5 # 初始连接数
min-idle: 10 # 最小连接池数量 min-idle: 10 # 最小连接池数量
max-active: 20 # 最大连接池数量 max-active: 20 # 最大连接池数量
max-wait: 600000 # 配置获取连接等待超时的时间,单位:毫秒 max-wait: 600000 # 配置获取连接等待超时的时间,单位:毫秒
@ -45,33 +45,33 @@ spring:
datasource: datasource:
master: master:
name: ruoyi-vue-pro name: ruoyi-vue-pro
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 url: jdbc:mysql://139.9.196.247:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例 # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例
username: root username: root
password: 123456 password: ${RUOYI_VUE_PRO}
# username: sa # username: sa
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
slave: # 模拟从库,可根据自己需要修改 slave: # 模拟从库,可根据自己需要修改
name: ruoyi-vue-pro name: ruoyi-vue-pro
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 url: jdbc:mysql://139.9.196.247:3306/${spring.datasource.dynamic.datasource.master.name}?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例 # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例
username: root username: root
password: 123456 password: ${RUOYI_VUE_PRO}
# username: sa # username: sa
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
redis: redis:
host: 127.0.0.1 # 地址 host: 139.9.196.247 # 地址
port: 6379 # 端口 port: 6379 # 端口
database: 0 # 数据库索引 database: 0 # 数据库索引
# password: 123456 # 密码,建议生产环境开启 password: 123456 # 密码,建议生产环境开启
--- #################### 定时任务相关配置 #################### --- #################### 定时任务相关配置 ####################