package com.sino.rrs.oper;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sino.publicclass.base.BaseBean;
import com.sino.publicclass.base.CException;
import com.sino.publicclass.sql.ConstructInsertSQL;
import com.sino.publicclass.sql.ConstructSQL;
import com.sino.rrs.entity.RcRescueCompanyPO;

public class RcRescueCompanyOper extends BaseBean{
	public static final String TABLENAME="RC_RESCUE_COMPANY";
	
	public RcRescueCompanyOper(Connection curConn) {
		super(curConn);
	}

	@Override
	protected String getTableName() {
		return TABLENAME;
	}

	@Override
	protected Object resultAdaptor() throws Exception {
		Map<String,String> entity=new HashMap<String, String>();
		entity.put("rescue_company_code",  getString("RESCUE_COMPANY_CODE"));
		entity.put("vehicleId", getString("VEHICLE_ID"));
		/*RcRescueCompanyPO entity = new RcRescueCompanyPO();
		entity.setRescueCompanyCode(getString("rescue_company_code"));
		entity.setWeixinUserId(getInt("weixinUserId"));*/
		return entity;
	}

	//查询服务商之前是否注册过
	public Map<String,String> queryModifyIdentity(String weixinUserId) throws CException{
		String sql="select a.RESCUE_COMPANY_CODE from RC_RESCUE_COMPANY a where a.WEIXIN_USER_ID="+weixinUserId;
		return (Map<String, String>) findOne(sql,"resultQueryModifyIdentity");
	}
	
	public Map<String,String> resultQueryModifyIdentity() throws SQLException{
		Map<String,String> map=new HashMap<String, String>();
		map.put("rescueCode", getString("RESCUE_COMPANY_CODE"));
		return map;
	}
	
	//查询司机之前是否注册过
		public Map<String,String> queryVehicleModifyIdentity(String weixinUserId) throws CException{
			String sql="select b.VEHICLE_ID from RC_RESCUE_VEHICLE b where b.WEIXIN_USER_ID="+weixinUserId;
			return (Map<String, String>) findOne(sql,"resultQueryVehicleModifyIdentity");
		}
		
		public Map<String,String> resultQueryVehicleModifyIdentity() throws SQLException{
			Map<String,String> map=new HashMap<String, String>();
			map.put("VEHICLE_ID", getString("VEHICLE_ID"));
			return map;
		}
	
	//添加服务商信息
		public int createPatch(RcRescueCompanyPO rcRescueCompanyPO) throws CException{
			ConstructSQL sql = new ConstructInsertSQL();
			sql.setTableName(TABLENAME);
			sql.setColumn("RESCUE_COMPANY_CODE",rcRescueCompanyPO.getRescueCompanyCode());
			sql.setColumn("WEIXIN_USER_ID",rcRescueCompanyPO.getWeixinUserId());
			sql.setColumn("COMPANYNAME",rcRescueCompanyPO.getCompanyName());
			sql.setColumn("DISPATCH_MODE", rcRescueCompanyPO.getDispatchMode());
			sql.setColumn("ACCEPT_FLAG", 0);
			sql.setColumnTimestamp("CREATE_TIME",new Date());
			return update(sql.getSQL());
		}
		
	//服务商更换用户时删除之前信息	
	public boolean deleteModifyUser(String weixinUserId) throws CException{
		String sql="delete from RC_RESCUE_COMPANY where WEIXIN_USER_ID="+weixinUserId;
		return deleteOne(sql);
	}
	
	//查看供应商名称
	public List<Map<String,String>> queryPrivinceCitySupplierName(String rescueCode) throws CException{
		String sql="SELECT RESCUE_COMPANY_CODE,COMPANYNAME from RC_RESCUE_COMPANY WHERE RESCUE_COMPANY_CODE IN "+rescueCode.replace("[", "(").replace("]", ")");
		return findAll(sql,"resultFindPrivinceCitySupplierName");
	}
	
	public Map<String,String> resultFindPrivinceCitySupplierName() throws SQLException{
		Map<String,String> map=new HashMap<String, String>();
		map.put("rescueCode", getString("RESCUE_COMPANY_CODE"));
		map.put("companyName", getString("COMPANYNAME"));
		return map;
	}
}
