licailing vor 5 Jahren
Ursprung
Commit
68a0eaef65

+ 1 - 0
src/main/java/com/izouma/jiashanxia/domain/OrderInfo.java

@@ -70,6 +70,7 @@ public class OrderInfo extends BaseEntity {
 
     private boolean isUse;
 
+    @ApiModelProperty(value = "分享此链接的用户")
     private Long parentUserId;
 
     @ApiModelProperty(value = "多次使用")

+ 45 - 0
src/main/java/com/izouma/jiashanxia/dto/DelayOrder.java

@@ -0,0 +1,45 @@
+package com.izouma.jiashanxia.dto;
+
+import lombok.Data;
+
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.concurrent.Delayed;
+import java.util.concurrent.TimeUnit;
+
+@Data
+public class DelayOrder implements Delayed {
+    /**
+     * 单号
+     */
+    private Long          orderInfoId;
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 过期时间(单位为毫秒,这里表示10秒)
+     */
+    private static final long expireTime = 3 * 60 * 1000;
+
+    @Override
+    public boolean equals(Object object) {
+        if (object instanceof DelayOrder) {
+            DelayOrder o = (DelayOrder) object;
+            return orderInfoId != null && o.orderInfoId != null && orderInfoId.equals(o.orderInfoId);
+        }
+        return false;
+    }
+
+    @Override
+    public long getDelay(TimeUnit unit) {
+        return unit.convert(this.createTime.toInstant(ZoneOffset.of("+8")).
+                toEpochMilli() + expireTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
+    }
+
+    @Override
+    public int compareTo(Delayed o) {
+        return this.getCreateTime().compareTo(((DelayOrder) o).getCreateTime());
+    }
+}

+ 4 - 0
src/main/java/com/izouma/jiashanxia/enums/Member.java

@@ -10,6 +10,10 @@ public enum Member {
      */
     EXPERT,
     /*
+    大团长,后台生成
+     */
+    BIG_EXPERT,
+    /*
     108将
      */
     GENERAL,

+ 2 - 2
src/main/java/com/izouma/jiashanxia/repo/OrderInfoRepo.java

@@ -24,11 +24,11 @@ public interface OrderInfoRepo extends JpaRepository<OrderInfo, Long>, JpaSpecif
 
     List<OrderInfo> findAllByPaidAtBetweenAndStatus(LocalDateTime paidAt, LocalDateTime paidAt2, OrderInfoStatus status);
 
-    List<OrderInfo> findAllByPaidAtBetweenAndStatusAndUserId(LocalDateTime paidAt, LocalDateTime paidAt2, OrderInfoStatus status, Long userId);
-
     long countByUserId(Long userId);
 
     OrderInfo findByTransactionId(String transactionId);
 
     List<OrderInfo> findAllByUserId(Long userId);
+
+    List<OrderInfo> findAllByStatus(OrderInfoStatus status);
 }

+ 40 - 0
src/main/java/com/izouma/jiashanxia/service/DisposeTimeoutOrderService.java

@@ -0,0 +1,40 @@
+package com.izouma.jiashanxia.service;
+
+import com.izouma.jiashanxia.domain.OrderInfo;
+import com.izouma.jiashanxia.enums.OrderInfoStatus;
+import com.izouma.jiashanxia.repo.OrderInfoRepo;
+import lombok.AllArgsConstructor;
+import org.springframework.beans.factory.InitializingBean;
+
+import java.util.List;
+
+@AllArgsConstructor
+public class DisposeTimeoutOrderService implements InitializingBean {
+    private final OrderInfoRepo     orderInfoRepo;
+    private final OrderDelayService orderDelayService;
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        DisposeThread thread = new DisposeThread();
+        // 使用多线程,避免占用服务器启动时间
+        new Thread(thread).start();
+    }
+
+    class DisposeThread implements Runnable {
+
+        @Override
+        public void run() {
+            try {
+                // 处理待支付且未超时订单
+                List<OrderInfo> waitPayList = orderInfoRepo.findAllByStatus(OrderInfoStatus.UNPAID);
+                if (!waitPayList.isEmpty()) {
+                    for (OrderInfo order : waitPayList) {
+                        orderDelayService.orderDelay(order.getId(), order.getCreatedAt());
+                    }
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}

+ 85 - 0
src/main/java/com/izouma/jiashanxia/service/OrderDelayService.java

@@ -0,0 +1,85 @@
+package com.izouma.jiashanxia.service;
+
+import com.izouma.jiashanxia.domain.OrderInfo;
+import com.izouma.jiashanxia.dto.DelayOrder;
+import com.izouma.jiashanxia.enums.OrderInfoStatus;
+import com.izouma.jiashanxia.exception.BusinessException;
+import com.izouma.jiashanxia.repo.OrderInfoRepo;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import java.time.LocalDateTime;
+import java.util.concurrent.DelayQueue;
+
+@Service
+public class OrderDelayService {
+
+    private final Log           logger = LogFactory.getLog(this.getClass());
+    private       Thread        takeOrder;
+    @Autowired
+    private       OrderInfoRepo orderInfoRepo;
+
+
+    private final static DelayQueue<DelayOrder> delayOrders = new DelayQueue<>();
+
+    public void orderDelay(Long orderInfoId, LocalDateTime createdAt) {
+        DelayOrder delayOrder = new DelayOrder();
+        delayOrder.setOrderInfoId(orderInfoId);
+        delayOrder.setCreateTime(createdAt);
+        delayOrders.put(delayOrder);
+    }
+
+    public void remove(Long orderInfoId, LocalDateTime createdAt) {
+        DelayOrder delayOrder = new DelayOrder();
+        delayOrder.setOrderInfoId(orderInfoId);
+        delayOrder.setCreateTime(createdAt);
+        delayOrders.remove(delayOrder);
+    }
+
+    private class TakeOrder implements Runnable {
+
+        public TakeOrder() {
+            super();
+        }
+
+        @Override
+        public void run() {
+            // 检查当前线程是否中断
+            while (!Thread.currentThread().isInterrupted()) {
+                try {
+                    // take():获取队列,在必要时阻塞等待,直到该队列上有一个具有过期延迟的元素可用。
+                    DelayOrder delayedOrder = delayOrders.take();
+                    // 处理待支付且支付超时订单
+//                    orderInfoService.cancelOrder(delayedOrder.getOrderInfoId());
+                    OrderInfo orderInfo = orderInfoRepo.findById(delayedOrder.getOrderInfoId())
+                            .orElseThrow(new BusinessException("无订单"));
+                    if (OrderInfoStatus.UNPAID.equals(orderInfo.getStatus())) {
+                        orderInfo.setStatus(OrderInfoStatus.CANCELLED);
+                        orderInfoRepo.save(orderInfo);
+                    }
+                    delayOrders.remove(delayedOrder);
+                } catch (Exception e) {
+                    logger.error("The thread is Interrupted!");
+                }
+            }
+        }
+    }
+
+    // @PostConstruct:当整个bean被初始化完成后执行
+    @PostConstruct
+    public void init() {
+        takeOrder = new Thread(new TakeOrder());
+        takeOrder.start();
+    }
+
+    // 销毁示例之前调用
+    @PreDestroy
+    public void close() {
+        takeOrder.interrupt();
+    }
+
+}

+ 111 - 58
src/main/java/com/izouma/jiashanxia/service/OrderInfoService.java

@@ -41,6 +41,7 @@ public class OrderInfoService {
     private final UserPackageFlowRepo  userPackageFlowRepo;
     private final UserService          userService;
     private final StockRepo            stockRepo;
+    private final OrderDelayService    orderDelayService;
 
     public Page<OrderInfo> all(PageQuery pageQuery) {
         pageQuery.setSort("createdAt,desc");
@@ -87,7 +88,7 @@ public class OrderInfoService {
     /*
    下订单
     */
-    public OrderInfo createOrder1(CreateOrder createOrder,Long userId) {
+    public OrderInfo createOrder1(CreateOrder createOrder, Long userId) {
         Package aPackage = packageRepo.findById(createOrder.getPackageId()).orElseThrow(new BusinessException("无套餐"));
         DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
         String localTime = df.format(LocalDateTime.now());
@@ -116,8 +117,9 @@ public class OrderInfoService {
             price = stock.getPrice();
         }
         order.setPrice(price.multiply(new BigDecimal(createOrder.getNum())));
-
-        return orderInfoRepo.save(order);
+        OrderInfo save = orderInfoRepo.save(order);
+        orderDelayService.orderDelay(save.getId(), save.getCreatedAt());
+        return save;
     }
 
     /*
@@ -183,35 +185,28 @@ public class OrderInfoService {
                 .content(goodsDTOS)
                 .build());
 
-        // 用户
-        User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
-//        if (!user.isVip()) {
-//            user.setVip(true);
-//            userRepo.save(user);
-//        }
-
-        Long parent = user.getParent();
         // 用户id和上级id相同
-        if (!userId.equals(parent)) {
-            // 如果是别人分享的链接购买的
-            if (ObjectUtil.isNotEmpty(order.getParentUserId())) {
-                parent = order.getParentUserId();
-                // 是否设为上级
-                if (ObjectUtil.isEmpty(user.getParent())) {
-                    List<OrderInfo> orderInfos = orderInfoRepo.findAllByUserId(userId);
-                    long count = orderInfos.stream()
-                            .filter(orderInfo -> !OrderInfoStatus.UNPAID.equals(orderInfo.getStatus()) || !OrderInfoStatus.CANCELLED
-                                    .equals(orderInfo.getStatus()))
-                            .count();
-                    if (count <= 0) {
-                        user.setParent(parent);
-                        userRepo.save(user);
-                    }
-                }
-            }
-            // 上级分销
-            this.distribution1(userId, parent, order);
-        }
+//        if (!userId.equals(parent)) {
+//            // 如果是别人分享的链接购买的
+//            if (ObjectUtil.isNotEmpty(order.getParentUserId())) {
+//                parent = order.getParentUserId();
+//                // 是否设为上级
+//                if (ObjectUtil.isEmpty(user.getParent())) {
+//                    List<OrderInfo> orderInfos = orderInfoRepo.findAllByUserId(userId);
+//                    long count = orderInfos.stream()
+//                            .filter(orderInfo -> !OrderInfoStatus.UNPAID.equals(orderInfo.getStatus()) || !OrderInfoStatus.CANCELLED
+//                                    .equals(orderInfo.getStatus()))
+//                            .count();
+//                    if (count <= 0) {
+//                        user.setParent(parent);
+//                        userRepo.save(user);
+//                    }
+//                }
+//            }
+//        }
+        // 上级分销
+        this.distribution2(order);
+        orderDelayService.remove(order.getId(), order.getCreatedAt());
     }
 
     /*
@@ -303,40 +298,98 @@ public class OrderInfoService {
         BigDecimal amount = orderInfo.getPrice();
 
         // 无限级找创客/108将/团长
-        this.makerGeneralDistribution(parentUser, amount, orderInfo.getId(), userId, aPackage);
-
-        // 不成为团长没有奖励
-//        if (Member.NORMAL.equals(parentUser.getMember())) {
-//            return;
-//        }
+//        this.makerGeneralDistribution(parentUser, amount, orderInfo.getId(), userId, aPackage);
 
         String transactionId = orderInfo.getId().toString();
 
-//        BigDecimal ratio = aPackage.getPersonalRatio0();
-//        if (ObjectUtil.isNull(ratio) || !aPackage.isSeparateDistribution()) {
-//            ratio = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
-//        }
-
-        // 钱和流水
-//        if (BigDecimal.ZERO.compareTo(ratio) < 0) {
-//            BigDecimal directPushAmount = amount.multiply(ratio);
-//            parentUser.setCacheAmount(directPushAmount.add(parentUser.getCacheAmount()));
-//            userRepo.save(parentUser);
-//            CommissionRecord commissionRecord1 = CommissionRecord.builder()
-//                    .userId(parent)
-//                    .amount(directPushAmount)
-//                    .payMethod(PayMethod.YUE)
-//                    .fromUserId(userId)
-//                    .transactionType(TransactionType.PROMOTE)
-//                    .transactionId(transactionId)
-//                    .build();
-//            commissionRecordRepo.save(commissionRecord1);
-//        }
-
         // 间推
         this.indirect(parentUser, aPackage, userId, transactionId, amount);
     }
 
+    public void distribution2(OrderInfo orderInfo) {
+        Long userId = orderInfo.getUserId();
+        // 别人分享的链接
+        Long parentUserId = orderInfo.getParentUserId();
+        if (ObjectUtil.isNull(parentUserId)) {
+            // 自己购买的链接
+            parentUserId = userId;
+        }
+        BigDecimal amount = orderInfo.getPrice();
+
+
+        Package aPackage = packageRepo.findById(orderInfo.getPackageId()).orElseThrow(new BusinessException("无套餐"));
+        //团长直推钱
+        BigDecimal headRatio = aPackage.getPersonalRatio0();
+        if (!aPackage.isSeparateDistribution() || ObjectUtil.isNull(headRatio)) {
+            headRatio = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
+        }
+        BigDecimal head = amount.multiply(headRatio);
+
+        // 团长或大团长
+        User user = null;
+        // 上级为空或上级为不为普通用户停止
+        Long parent1 = user.getParent();
+        while (ObjectUtil.isNotNull(parentUserId)) {
+            user = userRepo.findById(parentUserId).orElseThrow(new BusinessException("无用户"));
+            // 如果是团长/大团长 拿直推钱
+            if (!Member.NORMAL.equals(user.getMember())) {
+                user.setAmount(user.getCacheAmount().add(head));
+                userRepo.save(user);
+
+                // 个人佣金流水
+                CommissionRecord commissionRecord = CommissionRecord.builder()
+                        .userId(parentUserId)
+                        .amount(head)
+                        .payMethod(PayMethod.YUE)
+                        .fromUserId(userId)
+                        .transactionType(TransactionType.PROMOTE)
+                        .transactionId(orderInfo.getTransactionId())
+                        .build();
+                commissionRecordRepo.save(commissionRecord);
+                break;
+            }
+            parentUserId = parent1;
+        }
+
+        // 存在团长或大团长+团长或大团长上级不为空
+        if (ObjectUtil.isNotNull(user) && ObjectUtil.isNotNull(parent1)) {
+            // 控制间退找几级
+            int i = 2;
+            if (Member.EXPERT.equals(user.getMember())) {
+                i = 1;
+            }
+            while (i < 3) {
+                User parent = userRepo.findById(parent1).orElseThrow(new BusinessException("无用户"));
+                if (Member.BIG_EXPERT.equals(parent.getMember())) {
+                    String name = "PERSONAL_RATIO_" + i;
+                    BigDecimal percentage = sysConfigService.getBigDecimal(name);
+                    BigDecimal personalAmount = amount.multiply(percentage);
+
+                    parent.setAmount(parent.getCacheAmount().add(personalAmount));
+                    userRepo.save(parent);
+
+                    // 个人佣金流水
+                    CommissionRecord commissionRecord = CommissionRecord.builder()
+                            .userId(parent.getId())
+                            .amount(personalAmount)
+                            .payMethod(PayMethod.YUE)
+                            .fromUserId(userId)
+                            .transactionType(TransactionType.CHILD_PROMOTE)
+                            .transactionId(orderInfo.getTransactionId())
+                            .build();
+                    commissionRecordRepo.save(commissionRecord);
+                }
+                i++;
+                parent1 = parent.getParent();
+                if (ObjectUtil.isNull(parent1)) {
+                    return;
+                }
+            }
+
+        }
+
+    }
+
     /*
     间推
      */

+ 3 - 3
src/main/java/com/izouma/jiashanxia/service/StatisticService.java

@@ -204,7 +204,7 @@ public class StatisticService {
 //        LocalDateTime start = LocalDateTime.of(year, month, 1, 0, 0);
         LocalDateTime start = DateTimeUtils.toLocalDateTime(time, "yyyy-MM-dd HH:mm:ss");
         LocalDateTime end = start.plusMonths(1);
-        long day = end.toLocalDate().toEpochDay() - start.toLocalDate().toEpochDay() - 1;
+        long day = end.toLocalDate().toEpochDay() - start.toLocalDate().toEpochDay();
         List<CommissionRecord> recordList = commissionRecordRepo.findAllByUserIdAndCreatedAtBetween(userId, start, end);
         List<Withdraw> withdraws = withdrawRepo.findAllByStatusAndUserIdAndAuditTimeBetween(WithdrawStatus.SUCCESS, userId, start, end);
 
@@ -218,7 +218,7 @@ public class StatisticService {
                     .map(CommissionRecord::getAmount)
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
             BigDecimal withdraw = withdraws.stream()
-                    .filter(wxFee -> !finalStart.isAfter(wxFee.getAuditTime()) && end.isAfter(wxFee.getAuditTime()))
+                    .filter(wxFee -> !finalStart.isAfter(wxFee.getAuditTime()) && finalEnd.isAfter(wxFee.getAuditTime()))
                     .map(Withdraw::getAmount)
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
 
@@ -228,7 +228,7 @@ public class StatisticService {
                     .dayWithdraw(withdraw)
                     .build());
             day--;
-            start = end;
+            start = finalEnd;
         }
         return dtos;
     }

+ 6 - 3
src/main/vue/src/views/employee/EmployeeDashboard.vue

@@ -38,6 +38,7 @@ import CompanyWidget from '@/widgets/CompanyWidget';
 import FeeWidget from '@/widgets/FeeWidget';
 import RecentSalesEmployee from '@/widgets/RecentSalesEmployee';
 import RecentOrderEmployee from '@/widgets/RecentOrderEmployee';
+import RecentCommission from '@/widgets/RecentCommission';
 import { mapState } from 'vuex';
 
 export default {
@@ -57,8 +58,9 @@ export default {
                 // { x: 3, y: 0, w: 3, h: 3, i: '1', name: 'CompanyWidget', key: 'company' },
                 // { x: 6, y: 0, w: 3, h: 3, i: '2', name: 'OrderWidget', key: 'order' },
                 // { x: 9, y: 0, w: 3, h: 3, i: '3', name: 'FeeWidget', key: 'fee' },
-                { x: 0, y: 4, w: 12, h: 12, i: '0', name: 'RecentOrderEmployee' },
-                { x: 0, y: 10, w: 12, h: 12, i: '1', name: 'RecentSalesEmployee' }
+                { x: 0, y: 4, w: 6, h: 12, i: '0', name: 'RecentOrderEmployee' },
+                { x: 6, y: 4, w: 6, h: 12, i: '1', name: 'RecentSalesEmployee' },
+                { x: 0, y: 10, w: 12, h: 12, i: '2', name: 'RecentCommission' }
                 /*{ x: 6, y: 4, w: 6, h: 12, i: '6', name: 'PieChartWidget' }*/
             ],
             editable: false,
@@ -95,7 +97,8 @@ export default {
         // FeeWidget,
         // CompanyWidget,
         RecentSalesEmployee,
-        RecentOrderEmployee
+        RecentOrderEmployee,
+        RecentCommission
     }
 };
 </script>

+ 19 - 21
src/main/vue/src/widgets/RecentOrderEmployee copy.vue → src/main/vue/src/widgets/RecentCommission.vue

@@ -2,9 +2,6 @@
     <widget-card :bodyStyle="bodyStyle" ref="container">
         <div style="width:100%;min-height:80px;" :loading="loading">
             <div style="margin: 0 0 1px 15px">
-                <!-- <van-dropdown-menu class="van-width">
-                    <van-dropdown-item v-model="chooseDate" @change="changeDate" :options="dateList" />
-                </van-dropdown-menu> -->
                 <el-date-picker
                     v-model="chooseDate"
                     @change="changeDate"
@@ -14,24 +11,25 @@
                 >
                 </el-date-picker>
             </div>
-            <bar-chart :chart-data="chartData" v-if="chartData"> </bar-chart>
+            <line-chart :chart-data="chartData" v-if="chartData"> </line-chart>
         </div>
     </widget-card>
 </template>
 <script>
 import WidgetCard from './WidgetCard';
-import BarChart from '../components/BarChart';
+import LineChart from '../components/LineChart';
 import { parse, addYears, format, addMonths, addDays } from 'date-fns';
 
 export default {
     data() {
         return {
             bodyStyle: {
+                display: 'flex',
                 alignItems: 'center'
             },
+            chooseDate: '',
             chartData: null,
-            loading: false,
-            chooseDate: ''
+            loading: false
         };
     },
     // created() {
@@ -45,9 +43,6 @@ export default {
                 list.push({
                     text: format(time, 'yyyy年MM月'),
                     value: format(time, 'yyyy-MM') + '-01 00:00:00'
-                    // '-01 00:00:00,' +
-                    // format(addDays(addMonths(time, 1), 0 - 1), 'yyyy-MM-dd') +
-                    // ' 23:59:59'
                 });
             }
             return list;
@@ -68,7 +63,7 @@ export default {
         getData() {
             this.loading = true;
             this.$http
-                .get('/statistic/dayAddEmployee', {
+                .get('/statistic/dayAddEmployee2', {
                     start: this.chooseDate,
                     userId: this.$route.query.id
                 })
@@ -78,10 +73,17 @@ export default {
                         labels: res.map(i => format(parse(i.date, 'yyyy-MM-dd', new Date()), 'dd')),
                         datasets: [
                             {
-                                label: '订单数',
-                                data: res.map(i => i.dayOrder),
-                                backgroundColor: 'rgba(54, 162, 235, 0.2)',
-                                borderColor: 'rgba(54, 162, 235, 1)',
+                                label: '收益',
+                                data: res.map(i => i.dayFee),
+                                backgroundColor: ['rgba(54, 162, 235, 0.2)'],
+                                borderColor: ['rgba(54, 162, 235, 1)'],
+                                borderWidth: 1
+                            },
+                            {
+                                label: '提现',
+                                data: res.map(i => i.dayWithdraw),
+                                backgroundColor: ['rgba(245, 108, 108, 0.2)'],
+                                borderColor: ['rgba(245, 108, 108, 1)'],
                                 borderWidth: 1
                             }
                         ]
@@ -95,12 +97,8 @@ export default {
     },
     components: {
         WidgetCard,
-        BarChart
+        LineChart
     }
 };
 </script>
-<style lang="less" scoped>
-.van-width {
-    width: 200px;
-}
-</style>
+<style lang="less" scoped></style>

+ 1 - 8
src/main/vue/src/widgets/RecentSalesEmployee.vue

@@ -73,7 +73,7 @@ export default {
                 .then(res => {
                     this.loading = false;
                     this.chartData = {
-                        labels: res.map(i => i.date),
+                        labels: res.map(i => format(parse(i.date, 'yyyy-MM-dd', new Date()), 'dd')),
                         datasets: [
                             {
                                 label: '销售额',
@@ -82,13 +82,6 @@ export default {
                                 borderColor: ['rgba(54, 162, 235, 1)'],
                                 borderWidth: 1
                             },
-                            {
-                                label: '提现金额',
-                                data: res.map(i => i.dayWithdraw),
-                                backgroundColor: ['rgba(230, 162, 60, 0.2)'],
-                                borderColor: ['rgba(230, 162, 60, 1)'],
-                                borderWidth: 1
-                            },
                             {
                                 label: '退款额',
                                 data: res.map(i => i.dayRefund),

+ 28 - 1
src/test/java/com/izouma/jiashanxia/service/OrderInfoServiceTest.java

@@ -11,7 +11,10 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
 
 @SpringBootTest
 @RunWith(SpringRunner.class)
@@ -55,6 +58,30 @@ public class OrderInfoServiceTest {
                 .userId(916L)
                 .payMethod(PayMethod.WEIXIN)
                 .build();
-        System.out.println(orderInfoService.createOrder1(build,916L));
+        System.out.println(orderInfoService.createOrder1(build, 916L));
+    }
+
+    @Test
+    public void autoCancel() {
+        //开始时间
+        long start = System.currentTimeMillis();
+        //结束时间
+        final long end = start + 60 * 1000;
+
+        final Timer timer = new Timer();
+        //延迟0毫秒(即立即执行)开始,每隔1000毫秒执行一次
+        timer.schedule(new TimerTask() {
+            public void run() {
+                System.out.println(end);
+            }
+        }, 0, 1000);
+        //计时结束时候,停止全部timer计时计划任务
+        timer.schedule(new TimerTask() {
+            public void run() {
+                timer.cancel();
+                System.out.println("end");
+            }
+
+        }, new Date(end));
     }
 }