<pre name="code" class="java">Session session = sessionFactory.openSession();
获取session 解决了找不到session的问题。
/**
* @Title: batchUpdateOrder
* @Description: 未支付超过2小时,订单关闭
* @param: @return 设定文件
* @return: Integer 返回类型
* @throws
*/
public Integer batchUpdateOrder(){
Integer result=0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs=null;
//未支付订单集合
//超过2个小时未支付,订单自动关闭
String sql="update order_details d,order_master_info m set d.order_status=4,m.order_status=2 "+
" where d.order_master_id=m.id and d.id=0 ";
//遍历分销商,保存到分期账单表中
try{
Session session = sessionFactory.openSession();
conn = SessionFactoryUtils.getDataSource(sessionFactory).getConnection();
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(sql);
String sqls="select * from order_details where order_status=0";
List<OrderDetails> detailList=session.createSQLQuery(sqls).addEntity(OrderDetails.class).list();
for(OrderDetails order:detailList){
//现在时间 - 订单创建时间>=2
Date currentDate=new Date();
Long time1=currentDate.getTime()-order.getCreateDate().getTime();
long nh = 1000*60*60;//一小时的毫秒数
long hour = time1/nh;//计算差多少小时
conn.setAutoCommit(false); // 开始事务
//系统配置支付间隔数
Integer payInterval=SystemConfigUtil.getSystemConfig().getOrderPayInterval();
if(payInterval.equals(null) || payInterval==0){
payInterval=2;
}
if(hour>=payInterval){
pstmt.setInt(1, order.getId());
}
pstmt.addBatch();
}
pstmt.executeBatch();
conn.commit();
conn.setAutoCommit(true);
} catch (SQLException e) {
if (conn != null) {
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
} finally {
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return result;
}