0

我有一个需要以下调度模式的业务需求

----t1--------ta--------tb---------t2

t1 和 t2之间,对产品 A 给予 10% 的折扣 但是,对于嵌套时间窗口ta - tb,给予 20% 的折扣。当达到tb时,回到产品 A 的 10% 折扣直到 t2。

Quartz 作业调度可以开箱即用地实现这个吗?
我想避免在这里安排 3 个作业 - 间隔(t1, ta) (ta, tb) 和 (tb, t2)。

4

1 回答 1

0

Quartz is a generic Java scheduling API and as such it does not come with any application-specific business logic "out of the box". The way I would solve the above requirement with Quartz is like so:

  1. Create a generic ProductPriceUpdaterJob Quartz job that will simply update the product price stored in your product store (typically a database). The job would expect a single job data map parameter "discount" with the discount percentage figure (i.e. 0, 10, 20).

  2. Associate the job with 4 Quartz triggers (T1, Ta, Tb, T2) that start your job at t1, ta, tb and t2 respectively. These triggers would specify the desired discount amount in their job data map (T1 has discount=10, Ta has discount=20, Tb has discount=10, T2 has discount=0).

  3. Start Quartz and register the job and triggers with it and you are done.

At t1, Quartz starts your job using trigger T1 and the job applies the 10% discount to the product price. At ta, Quartz starts your job using trigger Ta and your job applies the 20% discount to the product price etc.

Quartz supports 4 different trigger types and I think you can safely use the CronTrigger type for your triggers.

You will probably want to use another job data map parameter in your triggers where you can specify the ID (or IDs) of the product(s) to apply the discount to. This way, your job will be truly generic and usable with all your products.

于 2016-12-08T10:53:44.777 回答