package com.cloudcross.ssp.service.impl;

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.SqlHelper;
import com.cloudcross.ssp.model.DspAgent;
import com.cloudcross.ssp.service.IDspAgentService;

/**
 * 创建人：rongying
 * 创建时间：2015.12.11
 * dsp账户服务接口实现
 */

@Service
public class DspAgentService implements IDspAgentService{
	
	@Autowired
	private GenericIBatisDao myBatisDao;
	
	/**
	 * 获取所有dsp名称
	 * 
	 * @return 符合条件的列表记录
	 */
	@Override
	public DspAgent getDspAgentById(Long id){
		// TODO Auto-generated method stub
		return myBatisDao.get("dspAgentSqlMapper.selectDspAgentById", id);
	}
	
	/**
	 * 获取所有dsp名称
	 * @param paramMap
	 * 			dsp账户名称 
	 * @return 符合条件的列表记录
	 */
	@Override
	public List<DspAgent> getAllDspName(Map<String,Object> paramMap) {
		// TODO Auto-generated method stub
		String searchValue = SqlHelper.doLike(paramMap.get("dspName"));
		paramMap.put("value", searchValue);
		return myBatisDao.getList("dspAgentSqlMapper.selectAllDspName", paramMap);
	}
	
	/**
	 * 添加dsp账户
	 * 
	 * @param dspAgent
	 * 				实体对象
	 * @return
	 */
	public boolean addDspAgent(DspAgent dspAgent){
		myBatisDao.save("dspAgentSqlMapper.add", dspAgent);
		return true;
	}
	
	/**
	 * 编辑dsp账户
	 * 
	 * @param dspAgent
	 * 				实体对象
	 * @return
	 */
	public boolean editDspAgent(DspAgent dspAgent){
		myBatisDao.save("dspAgentSqlMapper.edit", dspAgent);
		return true;
	}

	/**
	 * 验证dsp账户是否符合
	 * 
	 * @param dspAgent
	 * 				实体对象
	 * @return 0代表不符合，否则代表符合。
	 */
	@Override
	public int isCheck(DspAgent dspAgent) {
		return myBatisDao.get("dspAgentSqlMapper.isCheck", dspAgent);
	}

	/**
	 * 查询最大的id - 插入时获取
	 * 
	 * @param paramMap
	 * 				名称和token
	 * @return 下一个id的值
	 */
	@Override
	public Long selectMaxId(Map<String,Object> paramMap) {
		// TODO Auto-generated method stub
		return myBatisDao.get("dspAgentSqlMapper.selectMaxId",paramMap);
	}
	
	@Override
	public List<DspAgent> findAllAgent() {
		
		return myBatisDao.getList("dspAgentSqlMapper.findAllAgent");
	}

	/**
	 * 校验身份
	 * 
	 * @param paramMap
	 * 				dspId和token
	 * @return 下一个id的值
	 */
	@Override
	public Long checkIdentity(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return myBatisDao.get("dspAgentSqlMapper.checkIdentity",paramMap);
	}
}
