package com.cloudcross.ssp.service.impl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloudcross.ssp.model.Location;
import com.cloudcross.ssp.service.ILocationService;
import com.cloudcross.ssp.base.dao.GenericIBatisDao;

@Service
public class LocationService implements ILocationService{

	
	@Autowired
	private GenericIBatisDao ibatisDao;

	@Override
	public List<Location> findAll(String country) {
	 
		return ibatisDao.getList("locationSqlMapper.findAll",country);
	}
	
	@Override
	public List<Location> findByProvince(String str) {
		// TODO Auto-generated method stub
		str = str.toUpperCase();
		if(str.length()==4){
			HashMap <String ,String > hashMap = new HashMap<String ,String> ();
			hashMap.put("location1", str.substring(0,2));
			hashMap.put("location2", str.substring(2,4));
			System.out.println(hashMap.toString());
			return 	ibatisDao.getList("locationSqlMapper.findByProvince",hashMap);	
		}
		return null;
	}	
	
	@Override
	public Location findByLocationT(String locationT) {
		return ibatisDao.get("locationSqlMapper.findByLocationT", locationT);
		
	}	
	
	public Location findByCnAndCnCity(Map<String, String> paramMap) {
		return ibatisDao.get("locationSqlMapper.findByCnAndCnCity", paramMap);
	}

	public List<String> findCityByProvince(String province) {
		return ibatisDao.getList("locationSqlMapper.findCityByProvince", province);
	}

	public List<String> findAllProvince() {
		return ibatisDao.getList("locationSqlMapper.findAllProvince");
	}	
}