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.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.MapBuilder;
import com.cloudcross.ssp.model.DspAdvertiser;
import com.cloudcross.ssp.service.IDspAdvertiserService;

/**
 * 创建人：rongying
 * 创建时间：2015.12.11
 * dsp-广告主服务接口实现
 */

@Service
public class DspAdvertiserService implements IDspAdvertiserService{
	
	@Autowired
	private GenericIBatisDao myBatisDao;

	/**
	 * 添加dsp对应的广告主
	 * 
	 * @param list
	 *            实体对象
	 * @return <code>true</code>代表成功，否则代表失败。
	 */
	@Override
	public boolean add(List<DspAdvertiser> list) {
		myBatisDao.save("dspAdvertiserSqlMapper.add", MapBuilder.create(HashMap.class)
				.add("dspAdvertiserList",list).map());
		return true;
	}

	/**
	 * 编辑dsp对应的广告主
	 * 
	 * @param list
	 *            实体对象
	 * @return <code>true</code>代表成功，否则代表失败。
	 */
	@Override
	public boolean update(List<DspAdvertiser> list) {
		myBatisDao.save("dspAdvertiserSqlMapper.update", MapBuilder.create(HashMap.class)
				.add("dspAdvertiserList",list).map());
		return true;
	}

	/**
	 * 获取dsp对应的所有广告主
	 * 
	 * @param map
	 *            实体对象
	 * @return 符合条件的列表记录
	 */
	@Override
	public List<DspAdvertiser> getAll(Map<String, Object> map) {
		return myBatisDao.getList("dspAdvertiserSqlMapper.getAll", map);
	}

	/**
	 * 根据条件获取对应的广告主
	 * 
	 * @param map
	 *            实体对象
	 * @return 符合条件的列表记录
	 */
	@Override
	public List<DspAdvertiser> get(Map<String, Object> map) {
		return myBatisDao.getList("dspAdvertiserSqlMapper.get", map);
	}

	/**
	 * 查询最大的id - 插入时获取
	 * 
	 * @param paramMap
	 * 				dspId和advertiserId
	 * @return 下一个id的值
	 */
	@Override
	public Long isRepeat(Map<String, Long> paramMap) {
		// TODO Auto-generated method stub
		return myBatisDao.get("dspAdvertiserSqlMapper.isRepeat",paramMap);
	}
	
	/**
	 * 批量查询广告主资质审核状态
	 * 
	 * @param paramMap
	 * 				dspId和advertiserIds
	 * @return 符合条件的记录
	 */
	public List<Map<String,Object>> queryState(Map<String,Object> paramMap){
		return myBatisDao.getList("dspAdvertiserSqlMapper.queryState",paramMap);
	}

}
