package com.sino.rrs.oper;

import java.sql.Connection;
import java.sql.SQLException;
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 RcRescueManagerOper extends BaseBean{
	public static final String TABLENAME="RC_RESCUE_MANAGER";

	public RcRescueManagerOper(Connection curConn) {
		super(curConn);
	}

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

	@Override
	protected Object resultAdaptor() throws Exception {
		Map<String,String> map=new HashMap<String,String>();
		map.put("id", getString("id"));
		map.put("login_name", getString("login_name"));
		map.put("password", getString("password"));
		map.put("rescue_company_code", getString("rescue_company_code"));
		return map;
	}
	
	//查询大区经理是否登陆过
	public Map<String,String> queryManagerByWeixinId(String weixinUserId) throws CException{
		String sql="select id,login_name,password,rescue_company_code from rc_rescue_manager where weixin_user_id="+weixinUserId;
		return (Map<String, String>) findOne(sql);
	}
	
	//添加大区经理信息
	public int insertAreaManager(String loginName,String password,RcRescueCompanyPO rcRescueCompanyPO) throws CException{
		ConstructSQL sql=new ConstructInsertSQL();
		sql.setTableName(TABLENAME);
		sql.setColumn("LOGIN_NAME", loginName);
		sql.setColumn("PASSWORD", password);
		sql.setColumn("WEIXIN_USER_ID", rcRescueCompanyPO.getWeixinUserId());
		sql.setColumn("RESCUE_COMPANY_CODE", rcRescueCompanyPO.getRescueCompanyCode());
		return update(sql.getSQL());
	}

	//查看供应商对应的大区经理
	public List<String> queryManager(String loginName) throws CException{
		String sql="select a.open_id from rc_weixin_user a LEFT JOIN rc_rescue_manager b on a.ID=b.WEIXIN_USER_ID where b.LOGIN_NAME='"+loginName+"'";
		return findAll(sql,"resultQueryManager");
	}
	
	public String resultQueryManager() throws SQLException{
		return getString("open_id");
	}
}
