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

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

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

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

/**
 * 删除城市某一日的小时数据
 */
@Service("HourDataDelete")
@SuppressWarnings({"rawtypes"})
public class HourDataDelete extends BaseBusinessService<Map> implements BusinessService {
	@Resource
	private HourRecordService hourDataService;
	
	
	@Override
	public void handle(Map dto, List content) throws Exception {
		// ALL，所有城市
		String cityId = (String) dto.get("cityId");
		
		// yyyy-MM-dd
		String dayDateStr = (String) dto.get("dayDate");
		
		if(cityId == null || dayDateStr == null) {
			throw new Exception(Const.ErrorTag.paramMis);
		}
		
		Date dayDate = DateUtils.str2Date(dayDateStr, DateUtils.SDF_DAY);
		
		if(cityId.equals("ALL")) {
			for(String city : ConfigUtil.getHourCitySet()) {
				hourDataService.deleteOneDayOfCity(city, dayDate);
			}
		}else {
			hourDataService.deleteOneDayOfCity(cityId, dayDate);
		}
	}
	
}
