You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.xmomen.module.schedule;
import com.xmomen.framework.support.SpringContextUtil;
import com.xmomen.module.order.model.CreatePurchase;
import com.xmomen.module.order.service.PurchaseService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by Jeng on 2016/2/23.
*/
@Component(value = "itemPurchaseJob")
public class ItemPurchaseJob implements Job {
// 注入PurchaseService
@Autowired
PurchaseService purchaseService;
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
// 如果purchaseService为空则从Spring上下文中获取
if(purchaseService == null){
purchaseService = (PurchaseService) SpringContextUtil.getApplicationContext().getBean(PurchaseService.class);
// 创建一个CreatePurchase对象
CreatePurchase createPurchase = new CreatePurchase();
// 设置订单日期为当前日期
createPurchase.setOrderDate(new Date());
// 调用PurchaseService的createPurchase方法创建采购订单
purchaseService.createPurchase(createPurchase);
}
}
}