zhaowenxuan
2024-10-14 0767d514fbfa1612928953ef9757e65abeecf400
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.ltkj.web.config.task;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.task.Task;
import com.ltkj.common.utils.bean.BeanUtil;
import com.ltkj.hosp.domain.TjCustomer;
import com.ltkj.hosp.domain.TjReservation;
import com.ltkj.hosp.service.ITbTransitionService;
import com.ltkj.hosp.service.ITjCustomerService;
import com.ltkj.hosp.service.ITjReservationService;
import com.ltkj.mall.domain.MallOrder;
import com.ltkj.mall.domain.MallTimeConfig;
import com.ltkj.mall.mallOrderUtils.OrderHandleOption;
import com.ltkj.mall.mallOrderUtils.OrderUtil;
import com.ltkj.mall.service.IMallOrderService;
import com.ltkj.mall.service.IMallTimeConfigService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
import java.util.Date;
 
/**
 * @Company: 西安路泰科技有限公司
 * @Author: zjh
 * @Date: 2024/1/11 0011 16:19
 */
public class MallOrderTask extends Task {
 
    private final Log log = LogFactory.getLog(MallOrderTask.class);
    private String orderId = "-1";
 
    public MallOrderTask(String orderId, long delayInMilliseconds) {
        super("MallOrderTask-" + orderId, delayInMilliseconds);
        this.orderId = orderId;
    }
 
    public MallOrderTask(String orderId) {
 
        super("MallOrderTask-" + orderId, 30 * 60 * 1000);
        this.orderId = orderId;
    }
 
    @Override
    public void run() {
        IMallOrderService orderService = BeanUtil.getBean(IMallOrderService.class);
        ITjReservationService reservationService = BeanUtil.getBean(ITjReservationService.class);
        ITbTransitionService transitionService = BeanUtil.getBean(ITbTransitionService.class);
        IMallTimeConfigService mallTimeConfigService = BeanUtil.getBean(IMallTimeConfigService.class);
        ITjCustomerService tjCustomerService = BeanUtil.getBean(ITjCustomerService.class);
        MallOrder order = orderService.getById(orderId);
        //这里根据orderSerialNo去检查用户是否完成了订单支付
        //如果用户没有支付订单,去执行订单关闭的操作
 
        if (order == null) {
            log.info("订单" + orderId + "不存在 被自动关闭");
        }else {
            // 检测是否能够取消
            OrderHandleOption handleOption = OrderUtil.build(order);
            if (!handleOption.isCancel()) {
                log.info("订单" + orderId + "不能取消 被自动关闭");
            }else {
                // 设置订单已取消状态
                order.setOrderStatus(OrderUtil.STATUS_CANCEL.longValue());
                order.setCloseTime(new Date());
                order.setUpdateTime(new Date());
                orderService.updateById(order);
                //对应预约时间数量+1
                final TjReservation byId = reservationService.getById(order.getReservationId());
                final Date reservationTime = byId.getReservationTime();
                LambdaQueryWrapper<MallTimeConfig> wq=new LambdaQueryWrapper<>();
                wq.eq(MallTimeConfig::getTime,reservationTime);
                final MallTimeConfig one = mallTimeConfigService.getOne(wq);
                one.setNowNum(one.getNowNum()+1);
                mallTimeConfigService.updateById(one);
                byId.setIsExpire(1);
                reservationService.updateById(byId);
                TjCustomer tjCustomer = tjCustomerService.getTjCustomerByCusIdCard(byId.getIdCard());
                String cardId ="0";
                if(null !=tjCustomer){
                    cardId = tjCustomer.getCardId();
                }
                transitionService.deletedTbTransitionListByCusIdAndTjNum(byId.getIdCard(),cardId);
            }
        }
    }
}