Quartz关闭超时订单
生活随笔
收集整理的這篇文章主要介紹了
Quartz关闭超时订单
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
訂單服務(wù)
用戶(hù)下單之后會(huì)占用庫(kù)存
如果,用戶(hù)不處理訂單,需要系統(tǒng)自動(dòng)關(guān)閉已經(jīng)下單的訂單
比如,秒殺的時(shí)候,設(shè)置的時(shí)間可能非常短
下單之后,需要用戶(hù)馬上付款,否則,馬上就會(huì)關(guān)閉,釋放商品的庫(kù)存
否則,秒殺結(jié)束了,某個(gè)用戶(hù)還占用著庫(kù)存
這里,關(guān)閉超時(shí)2天的訂單
導(dǎo)入依賴(lài)
<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
/*** 掃描超過(guò)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類(lèi) --><property name="jobClass" value="com.taotao.store.order.job.PaymentOrderJob" /><!-- 指定job的名稱(chēng) --><property name="name" value="paymentOrder" /><!-- 指定job的分組 --><property name="group" value="Order" /><!-- 必須設(shè)置為true,如果為false,當(dāng)沒(méi)有活動(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完成
業(yè)務(wù)狀態(tài)
訂單狀態(tài)為6,表示關(guān)閉狀態(tài)
更新時(shí)間、關(guān)閉時(shí)間、結(jié)束時(shí)間等于當(dāng)前時(shí)間
付款狀態(tài)為1,表示未付款
支付方式為1,表示在線(xiàn)支付
創(chuàng)建時(shí)間小于等于傳入的時(shí)間
總結(jié)
以上是生活随笔為你收集整理的Quartz关闭超时订单的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Quartz整合Spring
- 下一篇: JSR303—Bean Validati