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.rrs.entity.RcNewAreaPO;

public class RcNewAreaOper extends BaseBean{
	public static final String TABLENAME="RC_NEW_AREA";

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

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

	@Override
	public Object resultAdaptor() throws Exception {
		RcNewAreaPO areaPO=new RcNewAreaPO();
		areaPO.setAreaid(getInt("AREAID"));
		areaPO.setAreaname(getString("AREANAME"));
		areaPO.setParentid(getInt("PARENTID"));
		return areaPO;
	}
	
	//查看所有省
	public List<RcNewAreaPO> queryPrivince(String areaCode) throws CException{
		String sql="select * from RC_NEW_AREA where PARENTID=0 and AREAID in ("+areaCode+")";
		return findAll(sql);
	}
	
	//查看省--市
	public List<RcNewAreaPO> queryPrivinceCity(int parentid) throws CException{
		String sql="select * from RC_NEW_AREA where PARENTID="+parentid;
		return findAll(sql);
	}
	
	//查看省--》市--》供应商 (或者省--》供应商open id)
	public List<Map<String,String>> queryPrivinceCitySupplier(String rescueCode) throws CException{
		String sql="select a.open_id,b.COMPANYNAME from RC_WEIXIN_USER a LEFT JOIN RC_RESCUE_COMPANY b ON a.ID=b.WEIXIN_USER_ID where b.RESCUE_COMPANY_CODE in"+rescueCode.replace("[", "(").replace("]", ")");
		return findAll(sql,"resultFindPrivinceCitySupplier");
	}
	
	public Map<String,String> resultFindPrivinceCitySupplier() throws SQLException{
		Map<String,String> map=new HashMap<String, String>();
		map.put("open_id", getString("open_id"));
		map.put("companyName", getString("COMPANYNAME"));
		return map;
	}
	
	//添加
	/*public void insertNewArea(List<String> data) throws CException{
		ConstructSQL sql=new ConstructInsertSQL();
		sql.setTableName(TABLENAME);
		sql.setColumn("AREAID", data.get(0).trim());
		sql.setColumn("AREANAME", data.get(1).trim());
		sql.setColumn("PARENTID", data.get(2).trim());
		update(sql.getSQL());
	}*/
}
