日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Quartz关闭超时订单

發(fā)布時(shí)間:2025/3/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Quartz关闭超时订单 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

訂單服務(wù)

用戶下單之后會(huì)占用庫(kù)存
如果,用戶不處理訂單,需要系統(tǒng)自動(dòng)關(guān)閉已經(jīng)下單的訂單

比如,秒殺的時(shí)候,設(shè)置的時(shí)間可能非常短
下單之后,需要用戶馬上付款,否則,馬上就會(huì)關(guān)閉,釋放商品的庫(kù)存
否則,秒殺結(jié)束了,某個(gè)用戶還占用著庫(kù)存

這里,關(guān)閉超時(shí)2天的訂單

導(dǎo)入依賴

<dependency><groupId>org.quartz-scheduler</groupId><artifactId>quartz</artifactId><version>2.2.2</version> </dependency> <dependency><groupId>org.springframework</groupId><artifactId>spring-context-support</artifactId><version>4.1.3.RELEASE</version> </dependency>

創(chuàng)建Job

/*** 掃描超過2天未付款的訂單關(guān)閉*/ public class PaymentOrderJob extends QuartzJobBean {@Overrideprotected void executeInternal(JobExecutionContext context) throws JobExecutionException {ApplicationContext applicationContext = (ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");//時(shí)間參數(shù),當(dāng)前時(shí)間向前推2天applicationContext.getBean(OrderMapper.class).paymentOrderScan(new DateTime().minusDays(2).toDate());}}

添加配置

applicationContext-scheduler.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"><!-- 定義任務(wù)bean --><bean name="paymentOrderJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"><!-- 指定具體的job類 --><property name="jobClass" value="com.taotao.store.order.job.PaymentOrderJob" /><!-- 指定job的名稱 --><property name="name" value="paymentOrder" /><!-- 指定job的分組 --><property name="group" value="Order" /><!-- 必須設(shè)置為true,如果為false,當(dāng)沒有活動(dòng)的觸發(fā)器與之關(guān)聯(lián)時(shí)會(huì)在調(diào)度器中刪除該任務(wù) --><property name="durability" value="true"/><!-- 指定spring容器的key,如果不設(shè)定在job中的jobmap中是獲取不到spring容器的 --><property name="applicationContextJobDataKey" value="applicationContext"/></bean><!-- 定義觸發(fā)器 --><bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"><property name="jobDetail" ref="paymentOrderJobDetail" /><!-- 每一分鐘執(zhí)行一次 --><property name="cronExpression" value="0 0/1 * * * ?" /></bean><!-- 定義調(diào)度器 --><bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers"><list><ref bean="cronTrigger" /></list></property></bean></beans>

OrderMapper

掃描超時(shí)訂單并關(guān)閉
定時(shí)的做一個(gè)update操作,觸發(fā)由quartz完成

<update id="paymentOrderScan" parameterType="Date">UPDATE tb_order SETstatus = 6,update_time = NOW(),close_time = NOW(),end_time = NOW()WHERE status = 1 AND payment_type = 1 AND create_time &lt;= #{date} </update>

業(yè)務(wù)狀態(tài)
訂單狀態(tài)為6,表示關(guān)閉狀態(tài)
更新時(shí)間、關(guān)閉時(shí)間、結(jié)束時(shí)間等于當(dāng)前時(shí)間

付款狀態(tài)為1,表示未付款
支付方式為1,表示在線支付
創(chuàng)建時(shí)間小于等于傳入的時(shí)間

總結(jié)

以上是生活随笔為你收集整理的Quartz关闭超时订单的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。