22
33import org .apache .commons .logging .Log ;
44import org .apache .commons .logging .LogFactory ;
5+ import org .linlinjava .litemall .core .system .SystemConfig ;
56import org .linlinjava .litemall .db .domain .LitemallGoodsProduct ;
67import org .linlinjava .litemall .db .domain .LitemallOrder ;
78import org .linlinjava .litemall .db .domain .LitemallOrderGoods ;
@@ -34,27 +35,19 @@ public class OrderJob {
3435 /**
3536 * 自动取消订单
3637 * <p>
37- * 定时检查订单未付款情况,如果超时半个小时则自动取消订单
38+ * 定时检查订单未付款情况,如果超时 LITEMALL_ORDER_UNPAID 分钟则自动取消订单
3839 * 定时时间是每次相隔半个小时。
3940 * <p>
40- * 注意,因为是相隔半小时检查,因此导致有订单是超时一个小时以后才设置取消状态。
4141 * TODO
42- * 这里可以进一步地配合用户订单查询时订单未付款检查,如果订单超时半小时则取消。
42+ * 注意,因为是相隔半小时检查,因此导致订单真正超时时间是 [LITEMALL_ORDER_UNPAID, 30 + LITEMALL_ORDER_UNPAID]
4343 */
4444 @ Scheduled (fixedDelay = 30 * 60 * 1000 )
4545 @ Transactional
4646 public void checkOrderUnpaid () {
4747 logger .info ("系统开启任务检查订单是否已经超期自动取消订单" );
4848
49- List <LitemallOrder > orderList = orderService .queryUnpaid ();
49+ List <LitemallOrder > orderList = orderService .queryUnpaid (SystemConfig . getOrderUnpaid () );
5050 for (LitemallOrder order : orderList ) {
51- LocalDateTime add = order .getAddTime ();
52- LocalDateTime now = LocalDateTime .now ();
53- LocalDateTime expired = add .plusMinutes (30 );
54- if (expired .isAfter (now )) {
55- continue ;
56- }
57-
5851 // 设置订单已取消状态
5952 order .setOrderStatus (OrderUtil .STATUS_AUTO_CANCEL );
6053 order .setEndTime (LocalDateTime .now ());
@@ -67,7 +60,6 @@ public void checkOrderUnpaid() {
6760 List <LitemallOrderGoods > orderGoodsList = orderGoodsService .queryByOid (orderId );
6861 for (LitemallOrderGoods orderGoods : orderGoodsList ) {
6962 Integer productId = orderGoods .getProductId ();
70- LitemallGoodsProduct product = productService .findById (productId );
7163 Short number = orderGoods .getNumber ();
7264 if (productService .addStock (productId , number ) == 0 ) {
7365 throw new RuntimeException ("商品货品库存增加失败" );
@@ -80,30 +72,22 @@ public void checkOrderUnpaid() {
8072 /**
8173 * 自动确认订单
8274 * <p>
83- * 定时检查订单未确认情况,如果超时七天则自动确认订单
75+ * 定时检查订单未确认情况,如果超时 LITEMALL_ORDER_UNCONFIRM 天则自动确认订单
8476 * 定时时间是每天凌晨3点。
8577 * <p>
86- * 注意,因为是相隔一天检查,因此导致有订单是超时八天以后才设置自动确认。
87- * 这里可以进一步地配合用户订单查询时订单未确认检查,如果订单超时7天则自动确认。
88- * 但是,这里可能不是非常必要。相比订单未付款检查中存在商品资源有限所以应该
89- * 早点清理未付款情况,这里八天再确认是可以的。。
78+ * TODO
79+ * 注意,因为是相隔一天检查,因此导致订单真正超时时间是 [LITEMALL_ORDER_UNCONFIRM, 1 + LITEMALL_ORDER_UNCONFIRM]
9080 */
9181 @ Scheduled (cron = "0 0 3 * * ?" )
9282 public void checkOrderUnconfirm () {
9383 logger .info ("系统开启任务检查订单是否已经超期自动确认收货" );
9484
95- List <LitemallOrder > orderList = orderService .queryUnconfirm ();
85+ List <LitemallOrder > orderList = orderService .queryUnconfirm (SystemConfig . getOrderUnconfirm () );
9686 for (LitemallOrder order : orderList ) {
97- LocalDateTime ship = order .getShipTime ();
98- LocalDateTime now = LocalDateTime .now ();
99- LocalDateTime expired = ship .plusDays (7 );
100- if (expired .isAfter (now )) {
101- continue ;
102- }
10387
10488 // 设置订单已取消状态
10589 order .setOrderStatus (OrderUtil .STATUS_AUTO_CONFIRM );
106- order .setConfirmTime (now );
90+ order .setConfirmTime (LocalDateTime . now () );
10791 if (orderService .updateWithOptimisticLocker (order ) == 0 ) {
10892 logger .info ("订单 ID=" + order .getId () + " 数据已经更新,放弃自动确认收货" );
10993 } else {
@@ -115,22 +99,19 @@ public void checkOrderUnconfirm() {
11599 /**
116100 * 可评价订单商品超期
117101 * <p>
118- * 定时检查订单商品评价情况,如果确认商品超时七天则取消可评价状态
102+ * 定时检查订单商品评价情况,如果确认商品超时 LITEMALL_ORDER_COMMENT 天则取消可评价状态
119103 * 定时时间是每天凌晨4点。
104+ * <p>
105+ * TODO
106+ * 注意,因为是相隔一天检查,因此导致订单真正超时时间是 [LITEMALL_ORDER_COMMENT, 1 + LITEMALL_ORDER_COMMENT]
120107 */
121108 @ Scheduled (cron = "0 0 4 * * ?" )
122109 public void checkOrderComment () {
123110 logger .info ("系统开启任务检查订单是否已经超期未评价" );
124111
125112 LocalDateTime now = LocalDateTime .now ();
126- List <LitemallOrder > orderList = orderService .queryComment ();
113+ List <LitemallOrder > orderList = orderService .queryComment (SystemConfig . getOrderComment () );
127114 for (LitemallOrder order : orderList ) {
128- LocalDateTime confirm = order .getConfirmTime ();
129- LocalDateTime expired = confirm .plusDays (7 );
130- if (expired .isAfter (now )) {
131- continue ;
132- }
133-
134115 order .setComments ((short ) 0 );
135116 orderService .updateWithOptimisticLocker (order );
136117
0 commit comments