package com.sino.rrs.business;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import com.sino.publicclass.base.CException;
import com.sino.publicclass.database.ConnectionPool;
import com.sino.rrs.entity.CancelOrderMessage;
import com.sino.rrs.oper.RcRescueUpdateOper;
import com.sino.weixin.oauth.util.Constants;

/**
 * 给师傅发送订单消息改派通知
 * 1.纪录改派信息
 * 2.发送改派通知
 * 3.录入新派单信息
 * @author Administrator
 *
 */
public class ChangeOrderMessageDispatch implements Runnable{
	private CancelOrderMessage cancelOrder = new CancelOrderMessage();
	
	public String openId;
	public String orderCode;
	public int orderId;
	public String rescueCode;
	public int old_vehicle_id;
	
	public ChangeOrderMessageDispatch(String openId,String orderCode,int old_vehicle_id,int orderId,String rescueCode){
		this.openId=openId;
		this.orderCode=orderCode;
		this.orderId=orderId;
		this.rescueCode=rescueCode;
		this.old_vehicle_id=old_vehicle_id;
	}

	@Override
	public void run() {
		Connection conn=null;
		try {
			conn=ConnectionPool.getConnection();
			
			RcRescueUpdateOper updateOper=new RcRescueUpdateOper(conn);
			
			
			int result=updateOper.insertVehicleChangedMessage(orderId,1,old_vehicle_id,rescueCode,"订单改派"); //添加前一次司机调度信息到update表
			if (result>0){
				cancelOrder.cancel_template_message(Constants.AppId, Constants.AppSecret,openId,orderCode,new Date(System.currentTimeMillis()));
			}
			
			
		} catch (CException e) {
			e.printStackTrace();
		}finally{
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}
