**
* 订单超时处理
*/
public void orderTimeOutLogic() {
//订单超时未付款 自动关闭
//查询超时时间
OrderConfig orderConfig = orderConfigMapper.selectByPrimaryKey(1);
Integer orderTimeout = orderConfig.getOrderTimeout(); //超时时间(分) 60
LocalDateTime localDateTime = LocalDateTime.now().minusMinutes(orderTimeout); //得到超时的时间点
//设置查询条件
Example example=new Example(Order.class);
Example.Criteria criteria = example.createCriteria();
criteria.andLessThan("createTime",localDateTime);//创建时间小于超时时间
criteria.andEqualTo("orderStatus","0");//未付款的
criteria.andEqualTo("isDelete","0");//未删除的
//查询超时订单
List<Order> orders = orderMapper.selectByExample(example);
for(Order order :orders){
//记录订单变动日志
OrderLog orderLog=new OrderLog();
orderLog.setOperater("system");// 系统
orderLog.setOperateTime(new Date());//当前日期
orderLog.setOrderStatus("4");
orderLog.setPayStatus(order.getPayStatus());
orderLog.setConsignStatus(order.getConsignStatus());
orderLog.setRemarks("超时订单,系统自动关闭");
orderLog.setOrderId(order.getId());
orderLogMapper.insert(orderLog);
//更改订单状态
order.setOrderStatus("4");
order.setCloseTime(new Date());//关闭日期
orderMapper.updateByPrimaryKeySelective(order);
}
} |
|