📄 auctionschedulerunit.java
字号:
package com.redmoon.forum.plugin.auction;
import cn.js.fan.kernal.BaseSchedulerUnit;
import cn.js.fan.kernal.Scheduler;
import cn.js.fan.util.ErrMsgException;
import cn.js.fan.util.ResKeyException;
import cn.js.fan.db.Conn;
import cn.js.fan.web.Global;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.log4j.Logger;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class AuctionSchedulerUnit extends BaseSchedulerUnit {
static Logger logger = Logger.getLogger(AuctionSchedulerUnit.class.getName());
static {
name = "拍卖调度器";
}
public AuctionSchedulerUnit() {
lastTime = System.currentTimeMillis();
interval = 60000; // 每隔1分钟刷新一次
}
/**
* OnTimer
*
* @param currentTime long
* @todo Implement this cn.js.fan.kernal.ISchedulerUnit method
*/
public void OnTimer(long curTime) {
// logger.info("curTime=" + curTime);
if (curTime-lastTime>=interval) {
action();
lastTime = curTime;
}
}
public synchronized void action() {
// 查找已到期且未生成订单的拍卖
AuctionDb ad = new AuctionDb();
String sql = "select msgRootId from " + ad.getTableName() + " where orderId=? and endDate<?" + " and sellType=?";
// 如果已到期或者订单已生成
Conn conn = new Conn(Global.defaultDB);
ResultSet rs = null;
try {
// System.out.println(sql);
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, ad.NONE_ORDER);
ps.setString(2, "" + System.currentTimeMillis());
ps.setInt(3, ad.SELL_TYPE_AUCTION);
rs = conn.executePreQuery();
while (rs.next()) {
int msgRootId = rs.getInt(1);
// logger.info("msgRootId=" + msgRootId);
ad = ad.getAuctionDb(msgRootId);
if (ad.getOrderId() == ad.NONE_ORDER) {
// 如果订单未成生,则生成订单
AuctionOrderDb ao = new AuctionOrderDb();
try {
if (!ao.makeOrderForAuction(ad)) {
// logger.error("action1: 生成 " + ad.getName() +
// " 的订单失败,可能因为无人出价!");
}
else
;// logger.info("action1:生成" + ad.getName() + "的订单成功!");;
} catch (ErrMsgException e) {
logger.error("action2:" + e.getMessage());
} catch (ResKeyException e) {
logger.error("action3:" + e.getMessage());
}
}
}
// logger.info("调度生成订单成功!此次生成了" + count + "个订单!");
}
catch (SQLException e) {
logger.error("action:" + e.getMessage());
}
finally {
if (conn!=null) {
conn.close();
conn = null;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -