private boolean isPeriodeCouranteConges(Date date) {
   Date dateFinPeriodeCourante =
       getDateFinPeriodeConges(DateUtils.truncate(new Date(), Calendar.DATE));
   // ajout d'1 jur car la comparaison des dates doit être <= et la méthode before n'a pas ce
   // comportement par défaut
   return date.before(DateUtils.addSeconds(dateFinPeriodeCourante, 1));
 }
  public String getBeforeHeartBeatTime() {

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = new Date();
    String result = formatter.format(DateUtils.addSeconds(date, -31));
    return result;
  }
  // 处理某个任务
  private void doOneTask0(Task task) {
    logger.error("doOneTask0...");

    try {
      Runnable runnable = (Runnable) Class.forName(task.getClz()).newInstance();
      if (runnable != null) {
        Thread thread = new Thread(runnable);
        task.setThread(thread);

        // 计算出此任务下一次的执行时间点
        String nextWorkTime = null;
        if (task.getUnit().equalsIgnoreCase("DAYS")) {
          nextWorkTime =
              sdf.format(DateUtils.addDays(new Date(), Integer.valueOf(task.getSleep())));
        } else if (task.getUnit().equalsIgnoreCase("HOURS")) {
          nextWorkTime =
              sdf.format(DateUtils.addHours(new Date(), Integer.valueOf(task.getSleep())));
        } else if (task.getUnit().equalsIgnoreCase("MINUTES")) {
          nextWorkTime =
              sdf.format(DateUtils.addMinutes(new Date(), Integer.valueOf(task.getSleep())));
        } else if (task.getUnit().equalsIgnoreCase("SECONDS")) {
          nextWorkTime =
              sdf.format(DateUtils.addSeconds(new Date(), Integer.valueOf(task.getSleep())));
        } else if (task.getUnit().equalsIgnoreCase("MILLISECONDS")) {
          nextWorkTime =
              sdf.format(DateUtils.addMilliseconds(new Date(), Integer.valueOf(task.getSleep())));
        }
        task.setNextWorkTime(nextWorkTime);
        task.setCurrentStatus(Task.task_currentStatus_wait);

        thread.setDaemon(true);
        thread.setName(task.getCode());
        thread.start();
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #4
0
  @Override
  public Order create(
      Cart cart,
      Receiver receiver,
      PaymentMethod paymentMethod,
      ShippingMethod shippingMethod,
      CouponCode couponCode,
      boolean isInvoice,
      String invoiceTitle,
      boolean useBalance,
      String memo,
      Admin operator) {
    Assert.notNull(cart);
    Assert.notNull(cart.getMember());
    Assert.notEmpty(cart.getCartItems());
    Assert.notNull(receiver);
    Assert.notNull(paymentMethod);
    Assert.notNull(shippingMethod);

    Order order =
        build(
            cart,
            receiver,
            paymentMethod,
            shippingMethod,
            couponCode,
            isInvoice,
            invoiceTitle,
            useBalance,
            memo);

    order.setSn(snDao.generate(Sn.Type.order));
    if (paymentMethod.getMethod() == PaymentMethod.Method.online) {
      order.setLockExpire(DateUtils.addSeconds(new Date(), 20));
      order.setOperator(operator);
    }

    if (order.getCouponCode() != null) {
      couponCode.setIsUsed(true);
      couponCode.setUsedDate(new Date());
      couponCodeDao.merge(couponCode);
    }

    for (Promotion promotion : cart.getPromotions()) {
      for (Coupon coupon : promotion.getCoupons()) {
        order.getCoupons().add(coupon);
      }
    }

    Setting setting = SettingUtils.get();
    if (setting.getStockAllocationTime() == StockAllocationTime.order
        || (setting.getStockAllocationTime() == StockAllocationTime.payment
            && (order.getPaymentStatus() == PaymentStatus.partialPayment
                || order.getPaymentStatus() == PaymentStatus.paid))) {
      order.setIsAllocatedStock(true);
    } else {
      order.setIsAllocatedStock(false);
    }

    orderDao.persist(order);

    OrderLog orderLog = new OrderLog();
    orderLog.setType(Type.create);
    orderLog.setOperator(operator != null ? operator.getUsername() : null);
    orderLog.setOrder(order);
    orderLogDao.persist(orderLog);

    Member member = cart.getMember();
    if (order.getAmountPaid().compareTo(new BigDecimal(0)) > 0) {
      memberDao.lock(member, LockModeType.PESSIMISTIC_WRITE);
      member.setBalance(member.getBalance().subtract(order.getAmountPaid()));
      memberDao.merge(member);

      Deposit deposit = new Deposit();
      deposit.setType(operator != null ? Deposit.Type.adminPayment : Deposit.Type.memberPayment);
      deposit.setCredit(new BigDecimal(0));
      deposit.setDebit(order.getAmountPaid());
      deposit.setBalance(member.getBalance());
      deposit.setOperator(operator != null ? operator.getUsername() : null);
      deposit.setMember(member);
      deposit.setOrder(order);
      depositDao.persist(deposit);
    }

    if (setting.getStockAllocationTime() == StockAllocationTime.order
        || (setting.getStockAllocationTime() == StockAllocationTime.payment
            && (order.getPaymentStatus() == PaymentStatus.partialPayment
                || order.getPaymentStatus() == PaymentStatus.paid))) {
      for (OrderItem orderItem : order.getOrderItems()) {
        if (orderItem != null) {
          Product product = orderItem.getProduct();
          productDao.lock(product, LockModeType.PESSIMISTIC_WRITE);
          if (product != null && product.getStock() != null) {
            product.setAllocatedStock(
                product.getAllocatedStock()
                    + (orderItem.getQuantity() - orderItem.getShippedQuantity()));
            productDao.merge(product);
            orderDao.flush();
            staticService.build(product);
          }
        }
      }
    }

    cartDao.remove(cart);
    return order;
  }