package com.cloudcross.ssp.service.impl;

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

import org.apache.commons.lang.ArrayUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloudcross.ssp.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.MapBuilder;
import com.cloudcross.ssp.common.utils.Pager;
import com.cloudcross.ssp.model.PlaceClassInformation;
import com.cloudcross.ssp.service.IAdGroupPlaceService;
import com.cloudcross.ssp.service.IPlaceClassInformationService;
import com.cloudcross.ssp.web.widget.SelectorController.ISelector;
import com.cloudcross.ssp.web.widget.SelectorController.ISelectorProvider;

@Service
public class PlaceClassInformationService implements IPlaceClassInformationService, ISelectorProvider {
	private static final Logger LOG = Logger.getLogger(PlaceClassInformationService.class);
	@Autowired
	private IAdGroupPlaceService adGroupPlaceService;
	@Autowired
	private GenericIBatisDao myBatisDao;
	
	@Override
	public PlaceClassInformation findById(Long id) {
		return myBatisDao.get("placeClassInformationSqlMapper.findById", id);
	}

	@Override
	public int countByParams(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<PlaceClassInformation> findByParams(
			Map<String, Object> paramMap, Pager pager) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean add(PlaceClassInformation t) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean edit(PlaceClassInformation t) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateStatus(List<Long> idList, int status) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public List<PlaceClassInformation> findPlaceClassByOperatorId() {
		return myBatisDao.getList("placeClassInformationSqlMapper.findPlaceClassByOperatorId");
	}

	@Override
	public List<PlaceClassInformation> findAll() {
		return myBatisDao.getList("placeClassInformationSqlMapper.findAll");
	}

	@Override
	public Map<String, List<? extends ISelector>> provideData(String[] parentId) {
		List<PlaceClassInformation> placeClassInformationList = findAll();
		return MapBuilder.create(HashMap.class).add("placeClassInformationList", placeClassInformationList)
				.map();
	}

	@Override
	public List<PlaceClassInformation> queryPlaceClassInformationByAdgroupId(Long adgroupId) {
		//场景小类ID
		
		List<Long> placeIdList = adGroupPlaceService.queryPlaceByAdgroupId(adgroupId);
		if(placeIdList != null && placeIdList.size()>0){
			Map<String,Object> condition = new HashMap<String,Object>();
			condition.put("placeIdList", placeIdList);
			return myBatisDao.getList("placeClassInformationSqlMapper.queryPlaceClassInfoByplaceId", condition);
		}else{
			return new ArrayList<PlaceClassInformation>();
		}
		
	}
	public List<Long>queryPlaceClassIndfoIdByAdgroupId(Long adgroupId){
		return myBatisDao.getList("placeClassInformationSqlMapper.queryClassIdByAdgroupId", adgroupId);
	}

	@Override
	public Integer queryPlaceClassCount() {
		return myBatisDao.get("placeClassInformationSqlMapper.queryPlaceClassCount", null);
	}

	@Override
	public List<PlaceClassInformation> queryPlaceClass(Map<String, Object> condition) {
		return myBatisDao.getList("placeClassInformationSqlMapper.queryPlaceClass", condition);
	}

}
