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 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); } } } }