mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-19 18:45:03 +08:00
判断目标时间是否在优惠时间段内
This commit is contained in:
@@ -866,6 +866,13 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(isInDiscountPeriod("20:00", "08:00", "00:35:58")); // true
|
||||||
|
System.out.println(isInDiscountPeriod("00:00", "00:00", "19:59:59")); // true
|
||||||
|
System.out.println(isInDiscountPeriod("20:00", "20:00", "08:00:00")); // true
|
||||||
|
System.out.println(isInDiscountPeriod("20:00", "08:00", "08:00:00")); // false
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前时间是否在时间指定范围内<br>
|
* 当前时间是否在时间指定范围内<br>
|
||||||
*
|
*
|
||||||
@@ -1157,6 +1164,10 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
|||||||
* @return 是否在优惠时段
|
* @return 是否在优惠时段
|
||||||
*/
|
*/
|
||||||
public static boolean isInDiscountPeriod(LocalTime start, LocalTime end, LocalTime target) {
|
public static boolean isInDiscountPeriod(LocalTime start, LocalTime end, LocalTime target) {
|
||||||
|
// 任意参数为空返回false
|
||||||
|
if (start == null || end == null || target == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// 开始时间等于结束时间即判定为全天
|
// 开始时间等于结束时间即判定为全天
|
||||||
if (start.equals(end)) {
|
if (start.equals(end)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -703,13 +703,11 @@ public class CommonService {
|
|||||||
log.info("站点:{}绑定停车券, 订单号:{}, 充电停车优惠信息:{}, 充电度数:{}, 充电时长:{}, 订单创建时间:{}",
|
log.info("站点:{}绑定停车券, 订单号:{}, 充电停车优惠信息:{}, 充电度数:{}, 充电时长:{}, 订单创建时间:{}",
|
||||||
orderBasicInfo.getStationId(), orderBasicInfo.getOrderCode(), JSON.toJSONString(chargeParkingDiscount),
|
orderBasicInfo.getStationId(), orderBasicInfo.getOrderCode(), JSON.toJSONString(chargeParkingDiscount),
|
||||||
chargingDegree, sumChargingTime, DateUtils.formatDateTime(orderBasicInfo.getCreateTime()));
|
chargingDegree, sumChargingTime, DateUtils.formatDateTime(orderBasicInfo.getCreateTime()));
|
||||||
// startTime等于endTime,则不需要判断, 如果startTime不等于endTime,则需要判断订单创建时间是否在优惠时间段内
|
|
||||||
if (!StringUtils.equals(startTime.toString(), endTime.toString())) {
|
if (!DateUtils.isInDiscountPeriod(startTime, endTime, createLocalTime)) {
|
||||||
if (createLocalTime.isBefore(startTime) || createLocalTime.isAfter(endTime)) {
|
// 不在优惠时间段内
|
||||||
// 不在优惠时间段内
|
log.info("{}该订单不在优惠时间段({}-{})内", orderBasicInfo.getOrderCode(), startTime, endTime);
|
||||||
log.info("{}该订单不在优惠时间段({}-{})内", orderBasicInfo.getOrderCode(), startTime, endTime);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果conditionType为1判断充电度数, 如果为2判断充电时长
|
// 如果conditionType为1判断充电度数, 如果为2判断充电时长
|
||||||
|
|||||||
Reference in New Issue
Block a user