package com.persagy.functions.weather.business.v2020.discard;

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

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.persagy.core.service.BaseBusinessService;
import com.persagy.core.service.BusinessService;
import com.persagy.framework.util.ConfigUtil;
import com.persagy.framework.util.WServiceUtil;
import com.persagy.functions.weather.constant.Const;

@Service("HourWeatherForecast")
@SuppressWarnings({ "unchecked", "rawtypes" })
public class HourWeatherForecastService extends BaseBusinessService<Map> implements BusinessService {

	@Override
	public void handle(Map dto, List content) throws Exception {
		String name = (String) dto.get("name");
		String projectId = (String) dto.get("projectId");
		String cityCode = (String) dto.get("cityCode");
		if ((StringUtils.isEmpty(projectId)) && (StringUtils.isEmpty(cityCode)) && (StringUtils.isEmpty(name))) {
			throw new Exception(Const.ErrorTag.paramMis);
		}
		String location = ConfigUtil.getLocation(name, cityCode, projectId);
		
		if(null == location) {
			throw new Exception(Const.ErrorTag.cityNotFound);
		}
		
		try {
			Map<String, Object> dataMap = WServiceUtil.getHour24PredictWithLocation(location);
			if (!dataMap.isEmpty()) {
				content.add(dataMap);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
