package com.cloudcross.ssp.service.impl;

import java.util.Date;
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.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.MapBuilder;
import com.cloudcross.ssp.common.utils.Pager;
import com.cloudcross.ssp.model.AdGroupPlace;
import com.cloudcross.ssp.model.AdgroupWifigroup;
import com.cloudcross.ssp.service.IAdGroupPlaceService;

@Service
public class AdGroupPlaceService implements IAdGroupPlaceService{

	@Autowired
	private GenericIBatisDao ibatisDao;
	
	@Override
	public AdGroupPlace findById(Long id) {
		return null;
	}
	
	public List<AdGroupPlace> findAll(Long adGroupId) {
		return ibatisDao.getList("adGroupPlaceSqlMapper.findAll", adGroupId);
	}

	@Override
	public int countByParams(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public boolean delete(Long adGroupId) {
		ibatisDao.delete("adGroupPlaceSqlMapper.delete", adGroupId);
		return true;
	}
	@Override
	public List<AdGroupPlace> findByParams(Map<String, Object> paramMap, Pager pager) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean add(AdGroupPlace t) {
		Long supdate = new Date().getTime()/1000;
		t.setSupdated(supdate);
		ibatisDao.save("adGroupPlaceSqlMapper.addPlace", t);
		return true;
	}

	@Override
	public boolean edit(AdGroupPlace 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<AdGroupPlace> findAllByAdGroupId(Long adGroupId) {
		return ibatisDao.getList("adGroupPlaceSqlMapper.findAllByAdGroupId", adGroupId);
	}

	@Override
	public boolean updatedPlaceSupdated(Long adGroupId) {
		Map<String,Object> condition = new HashMap<String,Object>();
		Long supdated = new Date().getTime()/1000;
		condition.put("adGroupId", adGroupId);
		condition.put("supdated", supdated);
		ibatisDao.save("adGroupPlaceSqlMapper.updatedSupdated", adGroupId);
		return true;
	}
	
	public void saveAdGroupPlace(AdGroupPlace adgroupPlace,List<Long>placeIdList){
		ibatisDao.save("adGroupPlaceSqlMapper.addAdGroupPlaceBatch",MapBuilder.create(HashMap.class)
				.add("placeIdList",placeIdList)
				.add("adgroupPlace",adgroupPlace)
				.map());
	}

}
