package org.cs.mgr.sys.dao.impl;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.cs.core.dao.impl.BaseDao;
import org.cs.mgr.sys.dao.IAreaDao;
import org.cs.mgr.sys.model.Area;
import org.springframework.stereotype.Repository;

@Repository
public class AreaDao extends BaseDao<Area> implements IAreaDao {

	@Override
	public List<Area> getProvice() {
		// TODO Auto-generated method stub
		return (List<Area>) this.findByHql("from Area where pid = 0 order by code", null);
	}

	@Override
	public List<Area> getCityOrCountry(String code) {
		// TODO Auto-generated method stub
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("code", Integer.valueOf(code));
		return (List<Area>) this.findByHql("from Area where pid =:code  order by code", params);
		
	}
	
	

	@Override
	public List<Area> getCityOrCountryByName(String name) {
		// TODO Auto-generated method stub
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("name", name);
		Area area = this.findOneByHql("from Area where name =:name", params);
		if(area != null){
			return (List<Area>) this.findByHql("from Area where pid = " + area.getCode()+" order by code", params);
		}
		
		return null;
	}
	
	
	
}
