Java Code Examples for java.time.LocalDateTime#isAfter()

The following examples show how to use java.time.LocalDateTime#isAfter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexSortTests.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "style")
public void testIndexPerformance(boolean parallel) {
    final LocalDateTime start = LocalDateTime.now();
    final LocalDateTime end = start.plusSeconds(1000000);
    final Array<LocalDateTime> dates = Range.of(start, end, Duration.ofSeconds(1)).toArray().shuffle(3);
    final Index<LocalDateTime> index = Index.of(dates);
    final long t1 = System.nanoTime();
    final Index<LocalDateTime> sorted = index.sort(parallel, true);
    final long t2 = System.nanoTime();
    System.out.println("Sorted Index in " + ((t2-t1)/1000000 + " millis"));
    for (int j=1; j<index.size(); ++j) {
        final LocalDateTime d1 = sorted.getKey(j-1);
        final LocalDateTime d2 = sorted.getKey(j);
        if (d1.isAfter(d2)) {
            throw new RuntimeException("Index keys are not sorted");
        } else {
            final int i1 = index.getIndexForKey(d1);
            final int i2 = sorted.getIndexForKey(d1);
            if (i1 != i2) {
                throw new RuntimeException("The indexes do not match between original and sorted");
            }
        }
    }
}
 
Example 2
Source File: OrderJob.java    From mall with MIT License 6 votes vote down vote up
/**
 * 可评价订单商品超期
 * <p>
 * 定时检查订单商品评价情况,如果确认商品超时七天则取消可评价状态
 * 定时时间是每天凌晨4点。
 */
@Scheduled(cron = "0 0 4 * * ?")
public void checkOrderComment() {
    logger.info("系统开启任务检查订单是否已经超期未评价");

    LocalDateTime now = LocalDateTime.now();
    List<LitemallOrder> orderList = orderService.queryComment();
    for (LitemallOrder order : orderList) {
        LocalDateTime confirm = order.getConfirmTime();
        LocalDateTime expired = confirm.plusDays(7);
        if (expired.isAfter(now)) {
            continue;
        }

        order.setComments((short) 0);
        orderService.updateWithOptimisticLocker(order);

        List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId());
        for (LitemallOrderGoods orderGoods : orderGoodsList) {
            orderGoods.setComment(-1);
            orderGoodsService.updateById(orderGoods);
        }
    }
}
 
Example 3
Source File: OrderJob.java    From mall with MIT License 6 votes vote down vote up
/**
 * 自动确认订单
 * <p>
 * 定时检查订单未确认情况,如果超时七天则自动确认订单
 * 定时时间是每天凌晨3点。
 * <p>
 * 注意,因为是相隔一天检查,因此导致有订单是超时八天以后才设置自动确认。
 * 这里可以进一步地配合用户订单查询时订单未确认检查,如果订单超时7天则自动确认。
 * 但是,这里可能不是非常必要。相比订单未付款检查中存在商品资源有限所以应该
 * 早点清理未付款情况,这里八天再确认是可以的。。
 */
@Scheduled(cron = "0 0 3 * * ?")
public void checkOrderUnconfirm() {
    logger.info("系统开启任务检查订单是否已经超期自动确认收货");

    List<LitemallOrder> orderList = orderService.queryUnconfirm();
    for (LitemallOrder order : orderList) {
        LocalDateTime ship = order.getShipTime();
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime expired = ship.plusDays(7);
        if (expired.isAfter(now)) {
            continue;
        }

        // 设置订单已取消状态
        order.setOrderStatus(OrderUtil.STATUS_AUTO_CONFIRM);
        order.setConfirmTime(now);
        if (orderService.updateWithOptimisticLocker(order) == 0) {
            logger.info("订单 ID=" + order.getId() + " 数据已经更新,放弃自动确认收货");
        } else {
            logger.info("订单 ID=" + order.getId() + " 已经超期自动确认收货");
        }
    }
}
 
Example 4
Source File: DomainApiUtils.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
/**
 * Check availability of an object.
 *
 * @param enabled flag for on/off switch
 * @param availableFrom availability start (or null)
 * @param availableTo availability finish (or null)
 * @param now time now
 *
 * @return true if object is available given provided settings
 */
public static boolean isObjectAvailableNow(final boolean enabled,
                                           final LocalDateTime availableFrom,
                                           final LocalDateTime availableTo,
                                           final LocalDateTime now) {

    if (!enabled) {
        return false;
    }

    if (availableFrom != null && now.isBefore(availableFrom)) {
        return false;
    }

    if (availableTo != null && now.isAfter(availableTo)) {
        return false;
    }

    return true;

}
 
Example 5
Source File: TimeframeInterval.java    From SmartApplianceEnabler with GNU General Public License v2.0 6 votes vote down vote up
public boolean isRemovable(LocalDateTime now) {
    return
    (
        (
            getState() == TimeframeIntervalState.EXPIRED
            || (
                    getState() == TimeframeIntervalState.QUEUED
                    && (now.isAfter(getInterval().getEnd()) || getRequest().isFinished(now))
            )
        )
        && ! getRequest().isControlOn()
        && (! (getRequest() instanceof OptionalEnergySocRequest) || getRequest().getMax(now) <= 0)
    )
    || (
            getRequest() instanceof OptionalEnergySocRequest
                    && ((ElectricVehicleCharger) ((OptionalEnergySocRequest) getRequest()).getControl())
                    .isVehicleNotConnected()
    );
}
 
Example 6
Source File: OffsetCommitter.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
public void recommitOffsets() {
    LocalDateTime now = LocalDateTime.now(clock);
    if (now.isAfter(lastUpdateTime.plus(IDLE_DURATION))) {
        for (TopicPartition tp : offsetData.keySet()) {
            OffsetAndTime offsetAndTime = offsetData.get(tp);
            if (now.isAfter(offsetAndTime.time.plus(IDLE_DURATION))) {
                try {
                    consumer.commitSync(Collections.singletonMap(tp,
                            new OffsetAndMetadata(offsetAndTime.offset)));
                } catch (CommitFailedException covfefe) {
                    logger.info("Caught CommitFailedException attempting to commit {} {}",
                            tp, offsetAndTime.offset);
                }
                offsetAndTime.time = now;
            }
        }
        lastUpdateTime = now;
    }
}
 
Example 7
Source File: WindowFunction.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object apply(LocalDateTime value) {
    LocalDateTime ndt = LocalDateTime.now();
    ChronoUnit cu = JDateUtil.getChronoUnit(this.period);
    switch (cu) {
        case SECONDS:
            ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), value.getDayOfMonth(),
                    value.getHour(), value.getMinute(), 0);
            break;
        case MINUTES:
            ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), value.getDayOfMonth(),
                    value.getHour(), 0, 0);
            break;
        case HOURS:
            ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), value.getDayOfMonth(),
                    0, 0, 0);
            break;
        case DAYS:
            ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), 1,
                    0, 0, 0);
            break;
        case MONTHS:
            ndt = LocalDateTime.of(value.getYear(), 1, 1, 0, 0, 0);
            break;
        case YEARS:
            int n = ((Period)period).getYears();
            ndt = LocalDateTime.of(value.getYear() - n, 1, 1, 0, 0, 0);
    }
    
    while (ndt.isBefore(value)){
        ndt = ndt.plus(period);
    }
    if (ndt.isAfter(value))
        ndt = ndt.minus(period);
    
    return ndt;
}
 
Example 8
Source File: GarmadonReader.java    From garmadon with Apache License 2.0 5 votes vote down vote up
public void run() {
    LocalDateTime current = LocalDateTime.now();
    if (current.isAfter(nextRunTimestamp)) {
        nextRunTimestamp = current.plus(period);
        action.run();
    }
}
 
Example 9
Source File: TimeframeInterval.java    From SmartApplianceEnabler with GNU General Public License v2.0 5 votes vote down vote up
public Integer getLatestEndSeconds(LocalDateTime now) {
    LocalDateTime nowBeforeEnd = LocalDateTime.from(now);
    if(now.isAfter(interval.getEnd())) {
        nowBeforeEnd = now.minusHours(24);
    }
    return Long.valueOf(Duration.between(nowBeforeEnd, interval.getEnd()).toSeconds()).intValue();
}
 
Example 10
Source File: MeteoDataInfo.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Interpolate data to a station point
 *
 * @param varNames Variable names
 * @param x X coordinate of the station
 * @param y Y coordinate of the station
 * @param z Z coordinate of the station
 * @param t Time coordinate of the station
 * @return Interpolated values
 */
public List<Double> toStation(List<String> varNames, double x, double y, double z, LocalDateTime t) {
    List<LocalDateTime> times = this.getDataInfo().getTimes();
    int tnum = times.size();
    if (t.isBefore(times.get(0)) || t.isAfter(times.get(tnum - 1))) {
        return null;
    }

    List<Double> ivalues = new ArrayList<>();
    double v_t1, v_t2;
    List<Double> v_t1s, v_t2s;
    for (int i = 0; i < tnum; i++) {
        if (t.equals(times.get(i))) {
            ivalues = this.toStation(varNames, x, y, z, i);
            break;
        }
        if (t.isBefore(times.get(i))) {
            v_t1s = this.toStation(varNames, x, y, z, i - 1);
            v_t2s = this.toStation(varNames, x, y, z, i);
            int h = (int)Duration.between(times.get(i - 1), t).toHours();
            int th = (int)Duration.between(times.get(i - 1), times.get(i)).toHours();
            for (int j = 0; j < v_t1s.size(); j++) {
                v_t1 = v_t1s.get(j);
                v_t2 = v_t2s.get(j);
                ivalues.add((v_t2 - v_t1) * h / th + v_t1);
            }
            break;
        }
    }

    return ivalues;
}
 
Example 11
Source File: DateUtil.java    From java-trader with Apache License 2.0 5 votes vote down vote up
public static Duration between(LocalDateTime datetime1, LocalDateTime datetime2) {
    if (datetime1.isAfter(datetime2)) {
        return between(datetime2, datetime1);
    }
    ZonedDateTime zonedTime1 = datetime1.atZone(defaultZoneId);
    ZonedDateTime zonedTime2 = datetime2.atZone(defaultZoneId);
    long seconds = zonedTime2.toEpochSecond() - zonedTime1.toEpochSecond();
    long nanoAdjustment = zonedTime2.get(ChronoField.NANO_OF_SECOND) - zonedTime1.get(ChronoField.NANO_OF_SECOND);
    return Duration.ofSeconds(seconds, nanoAdjustment);
}
 
Example 12
Source File: ZoneRules.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 13
Source File: OracleCDCSource.java    From datacollector with Apache License 2.0 4 votes vote down vote up
private boolean inSessionWindowCurrent(LocalDateTime startTime, LocalDateTime endTime) {
  LocalDateTime currentTime = nowAtDBTz();
  return (currentTime.isAfter(startTime) && currentTime.isBefore(endTime)) ||
      currentTime.isEqual(startTime) ||
      currentTime.isEqual(endTime);
}
 
Example 14
Source File: ZoneRules.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 15
Source File: ZoneRules.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 16
Source File: ZoneRules.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 17
Source File: ZoneRules.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 18
Source File: ZoneRules.java    From j2objc with Apache License 2.0 4 votes vote down vote up
private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0 &&
            dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
        ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
        Object info = null;
        for (ZoneOffsetTransition trans : transArray) {
            info = findOffsetInfo(dt, trans);
            if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
                return info;
            }
        }
        return info;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
        // before first transition
        return wallOffsets[0];
    }
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1 &&
            savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
        // handle overlap immediately following gap
        index++;
    }
    if ((index & 1) == 0) {
        // gap or overlap
        LocalDateTime dtBefore = savingsLocalTransitions[index];
        LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
        ZoneOffset offsetBefore = wallOffsets[index / 2];
        ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
        if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
            // gap
            return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
        } else {
            // overlap
            return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
        }
    } else {
        // normal (neither gap or overlap)
        return wallOffsets[index / 2 + 1];
    }
}
 
Example 19
Source File: CouponVerifyServiceImpl.java    From BigDataPlatform with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 检测优惠券是否适合
 *
 * @param userId
 * @param couponId
 * @param checkedGoodsPrice
 * @return
 */
public LitemallCoupon checkCoupon(Integer userId, Integer couponId, Integer userCouponId, BigDecimal checkedGoodsPrice) {
    LitemallCoupon coupon = couponService.findById(couponId);
    if (coupon == null) {
        return null;
    }

    LitemallCouponUser couponUser = couponUserService.findById(userCouponId);
    if (couponUser == null) {
        couponUser = couponUserService.queryOne(userId, couponId);
    } else if (!couponId.equals(couponUser.getCouponId())) {
        return null;
    }

    if (couponUser == null) {
        return null;
    }

    // 检查是否超期
    Short timeType = coupon.getTimeType();
    Short days = coupon.getDays();
    LocalDateTime now = LocalDateTime.now();
    if (timeType.equals(CouponConstant.TIME_TYPE_TIME)) {
        if (now.isBefore(coupon.getStartTime()) || now.isAfter(coupon.getEndTime())) {
            return null;
        }
    }
    else if(timeType.equals(CouponConstant.TIME_TYPE_DAYS)) {
        LocalDateTime expired = couponUser.getAddTime().plusDays(days);
        if (now.isAfter(expired)) {
            return null;
        }
    }
    else {
        return null;
    }

    // 检测商品是否符合
    // TODO 目前仅支持全平台商品,所以不需要检测
    Short goodType = coupon.getGoodsType();
    if (!goodType.equals(CouponConstant.GOODS_TYPE_ALL)) {
        return null;
    }

    // 检测订单状态
    Short status = coupon.getStatus();
    if (!status.equals(CouponConstant.STATUS_NORMAL)) {
        return null;
    }
    // 检测是否满足最低消费
    if (checkedGoodsPrice.compareTo(coupon.getMin()) == -1) {
        return null;
    }

    return coupon;
}
 
Example 20
Source File: TimeframeInterval.java    From SmartApplianceEnabler with GNU General Public License v2.0 4 votes vote down vote up
public boolean isActivatable(LocalDateTime now, boolean ignoreStartTime) {
    return getState() == TimeframeIntervalState.QUEUED
            && (ignoreStartTime || now.isEqual(getInterval().getStart()) || now.isAfter(getInterval().getStart()))
            && (!(request instanceof RuntimeRequest) || isIntervalSufficient(now)
    );
}