package com.sino.rrs.business;

import java.sql.Connection;
import java.sql.SQLException;

import com.sino.publicclass.database.ConnectionPool;
import com.sino.rrs.entity.RcWeixinUserPO;
import com.sino.rrs.oper.RcWeixinUserOper;

public class SnsVehicleUserManager {
	

	
	//WeixinUserDispatcher
	public static RcWeixinUserPO getWeixinDispatcherUserByOpenId(String openId){
		Connection conn = null;
		try{
		    conn = ConnectionPool.getConnection();
		  //查询该车的当前救援任务信息
		    RcWeixinUserOper userOper = new RcWeixinUserOper(conn);
		    RcWeixinUserPO snsUser = userOper.findByOpenId(openId);
		    return snsUser;
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
			if (conn != null)
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
		}
		return null;
	}
	

	//WeixinUserDispatch
	public static int createWeixinUserDispatch(RcWeixinUserPO snsUser){
		Connection conn = null;
		try{
		    conn = ConnectionPool.getConnection();
		 //   conn.setAutoCommit(false);
		  //查询该车的当前救援任务信息
		    RcWeixinUserOper dispatchOper = new RcWeixinUserOper(conn);
		    return dispatchOper.create(snsUser);
		}catch (Exception e) {
			try {
				conn.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		}finally {
			if (conn != null)
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
		}
		return 0;
	}
	
}
